Skip to content

Commit

Permalink
Merge branch 'hoteltransylvania' into 'master'
Browse files Browse the repository at this point in the history
Outlaw vampires and werewolves (bugs #7723, #7724)

Closes #7723 and #7724

See merge request OpenMW/openmw!3661
  • Loading branch information
jvoisin committed Dec 17, 2023
2 parents ec480db + 82982bb commit 2c1810c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
Bug #7679: Scene luminance value flashes when toggling shaders
Bug #7685: Corky sometimes doesn't follow Llovyn Andus
Bug #7712: Casting doesn't support spells and enchantments with no effects
Bug #7723: Assaulting vampires and werewolves shouldn't be a crime
Bug #7724: Guards don't help vs werewolves
Feature #3537: Shader-based water ripples
Feature #5173: Support for NiFogProperty
Feature #5492: Let rain and snow collide with statics
Expand Down
35 changes: 22 additions & 13 deletions apps/openmw/mwmechanics/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,31 +707,40 @@ namespace MWMechanics
}
}

// Make guards go aggressive with creatures that are in combat, unless the creature is a follower or escorter
// Make guards go aggressive with creatures and werewolves that are in combat
const auto world = MWBase::Environment::get().getWorld();
if (!aggressive && actor1.getClass().isClass(actor1, "Guard") && !actor2.getClass().isNpc()
&& creatureStats2.getAiSequence().isInCombat())
if (!aggressive && actor1.getClass().isClass(actor1, "Guard") && creatureStats2.getAiSequence().isInCombat())
{
// Check if the creature is too far
static const float fAlarmRadius
= world->getStore().get<ESM::GameSetting>().find("fAlarmRadius")->mValue.getFloat();
if (sqrDist > fAlarmRadius * fAlarmRadius)
return;

bool followerOrEscorter = false;
for (const auto& package : creatureStats2.getAiSequence())
bool targetIsCreature = !actor2.getClass().isNpc();
if (targetIsCreature || actor2.getClass().getNpcStats(actor2).isWerewolf())
{
// The follow package must be first or have nothing but combat before it
if (package->sideWithTarget())
bool followerOrEscorter = false;
// ...unless the creature has allies
if (targetIsCreature)
{
followerOrEscorter = true;
break;
for (const auto& package : creatureStats2.getAiSequence())
{
// The follow package must be first or have nothing but combat before it
if (package->sideWithTarget())
{
followerOrEscorter = true;
break;
}
else if (package->getTypeId() != MWMechanics::AiPackageTypeId::Combat)
break;
}
}
else if (package->getTypeId() != MWMechanics::AiPackageTypeId::Combat)
break;
// Morrowind also checks "known werewolf" flag, but the player is never in combat
// so this code is unreachable for the player
if (!followerOrEscorter)
aggressive = true;
}
if (!followerOrEscorter)
aggressive = true;
}

// If any of the above conditions turned actor1 aggressive towards actor2, do an awareness check. If it passes,
Expand Down
11 changes: 7 additions & 4 deletions apps/openmw/mwmechanics/mechanicsmanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,13 @@ namespace MWMechanics

bool MechanicsManager::canCommitCrimeAgainst(const MWWorld::Ptr& target, const MWWorld::Ptr& attacker)
{
const MWMechanics::AiSequence& seq = target.getClass().getCreatureStats(target).getAiSequence();
return target.getClass().isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker)
&& !isAggressive(target, attacker) && !seq.isEngagedWithActor()
&& !target.getClass().getCreatureStats(target).getAiSequence().isInPursuit();
const MWWorld::Class& cls = target.getClass();
const MWMechanics::CreatureStats& stats = cls.getCreatureStats(target);
const MWMechanics::AiSequence& seq = stats.getAiSequence();
return cls.isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker) && !isAggressive(target, attacker)
&& !seq.isEngagedWithActor() && !stats.getAiSequence().isInPursuit()
&& !cls.getNpcStats(target).isWerewolf()
&& stats.getMagicEffects().getOrDefault(ESM::MagicEffect::Vampirism).getMagnitude() <= 0;
}

void MechanicsManager::actorKilled(const MWWorld::Ptr& victim, const MWWorld::Ptr& attacker)
Expand Down

0 comments on commit 2c1810c

Please sign in to comment.