1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-27 10:41:34 +00:00

Restructure function updateCrimePursuit

This commit is contained in:
ζeh Matt 2022-03-28 17:25:22 +03:00
parent 9821982944
commit 33706923a3
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0

View file

@ -958,37 +958,47 @@ namespace MWMechanics
void Actors::updateCrimePursuit(const MWWorld::Ptr& ptr, float duration) void Actors::updateCrimePursuit(const MWWorld::Ptr& ptr, float duration)
{ {
MWWorld::Ptr player = getPlayer(); MWWorld::Ptr player = getPlayer();
if (ptr != player && ptr.getClass().isNpc()) if (ptr == player)
{ return;
auto& actorClass = ptr.getClass();
if (!actorClass.isNpc())
return;
// get stats of witness // get stats of witness
CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr);
NpcStats& npcStats = ptr.getClass().getNpcStats(ptr); NpcStats& npcStats = ptr.getClass().getNpcStats(ptr);
if (player.getClass().getNpcStats(player).isWerewolf()) const auto& playerClass = player.getClass();
const auto& playerStats = playerClass.getNpcStats(player);
if (playerStats.isWerewolf())
return; return;
if (ptr.getClass().isClass(ptr, "Guard") && creatureStats.getAiSequence().getTypeId() != AiPackageTypeId::Pursue && !creatureStats.getAiSequence().isInCombat() auto* mechanicsManager = MWBase::Environment::get().getMechanicsManager();
auto* world = MWBase::Environment::get().getWorld();
if (actorClass.isClass(ptr, "Guard") && creatureStats.getAiSequence().isInPursuit() && !creatureStats.getAiSequence().isInCombat()
&& creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() == 0) && creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() == 0)
{ {
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& esmStore = world->getStore();
static const int cutoff = esmStore.get<ESM::GameSetting>().find("iCrimeThreshold")->mValue.getInteger(); static const int cutoff = esmStore.get<ESM::GameSetting>().find("iCrimeThreshold")->mValue.getInteger();
// Force dialogue on sight if bounty is greater than the cutoff // Force dialogue on sight if bounty is greater than the cutoff
// In vanilla morrowind, the greeting dialogue is scripted to either arrest the player (< 5000 bounty) or attack (>= 5000 bounty) // In vanilla morrowind, the greeting dialogue is scripted to either arrest the player (< 5000 bounty) or attack (>= 5000 bounty)
if ( player.getClass().getNpcStats(player).getBounty() >= cutoff if (playerStats.getBounty() >= cutoff
// TODO: do not run these two every frame. keep an Aware state for each actor and update it every 0.2 s or so? // TODO: do not run these two every frame. keep an Aware state for each actor and update it every 0.2 s or so?
&& MWBase::Environment::get().getWorld()->getLOS(ptr, player) && world->getLOS(ptr, player)
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, ptr)) && mechanicsManager->awarenessCheck(player, ptr))
{ {
static const int iCrimeThresholdMultiplier = esmStore.get<ESM::GameSetting>().find("iCrimeThresholdMultiplier")->mValue.getInteger(); static const int iCrimeThresholdMultiplier = esmStore.get<ESM::GameSetting>().find("iCrimeThresholdMultiplier")->mValue.getInteger();
if (player.getClass().getNpcStats(player).getBounty() >= cutoff * iCrimeThresholdMultiplier) if (playerStats.getBounty() >= cutoff * iCrimeThresholdMultiplier)
{ {
MWBase::Environment::get().getMechanicsManager()->startCombat(ptr, player); mechanicsManager->startCombat(ptr, player);
creatureStats.setHitAttemptActorId(player.getClass().getCreatureStats(player).getActorId()); // Stops the guard from quitting combat if player is unreachable creatureStats.setHitAttemptActorId(playerClass.getCreatureStats(player).getActorId()); // Stops the guard from quitting combat if player is unreachable
} }
else else
creatureStats.getAiSequence().stack(AiPursue(player), ptr); creatureStats.getAiSequence().stack(AiPursue(player), ptr);
creatureStats.setAlarmed(true); creatureStats.setAlarmed(true);
npcStats.setCrimeId(MWBase::Environment::get().getWorld()->getPlayer().getNewCrimeId()); npcStats.setCrimeId(world->getPlayer().getNewCrimeId());
} }
} }
@ -996,7 +1006,7 @@ namespace MWMechanics
if (npcStats.getCrimeId() != -1) if (npcStats.getCrimeId() != -1)
{ {
// if you've paid for your crimes and I havent noticed // if you've paid for your crimes and I havent noticed
if( npcStats.getCrimeId() <= MWBase::Environment::get().getWorld()->getPlayer().getCrimeId() ) if (npcStats.getCrimeId() <= world->getPlayer().getCrimeId())
{ {
// Calm witness down // Calm witness down
if (ptr.getClass().isClass(ptr, "Guard")) if (ptr.getClass().isClass(ptr, "Guard"))
@ -1013,7 +1023,6 @@ namespace MWMechanics
} }
} }
} }
}
Actors::Actors() : mSmoothMovement(Settings::Manager::getBool("smooth movement", "Game")) Actors::Actors() : mSmoothMovement(Settings::Manager::getBool("smooth movement", "Game"))
{ {