diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 64347f161..82a2e2c3d 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -121,6 +121,16 @@ bool AiSequence::isInCombat() const return false; } +bool AiSequence::hasPackage(int typeId) const +{ + for (std::list::const_iterator it = mPackages.begin(); it != mPackages.end(); ++it) + { + if ((*it)->getTypeId() == typeId) + return true; + } + return false; +} + bool AiSequence::isInCombat(const MWWorld::Ptr &actor) const { for(std::list::const_iterator it = mPackages.begin(); it != mPackages.end(); ++it) diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 4b6ec156a..41d204ee2 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -85,6 +85,9 @@ namespace MWMechanics /// Is there any combat package? bool isInCombat () const; + /// Does this AI sequence have the given package type? + bool hasPackage(int typeId) const; + /// Are we in combat with this particular actor? bool isInCombat (const MWWorld::Ptr& actor) const; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 930049ba0..62ac9bd40 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1042,7 +1042,13 @@ namespace MWMechanics if (crimeSeen) reportCrime(player, victim, type, arg); else if (type == OT_Assault && !victim.isEmpty()) - startCombat(victim, player); // TODO: combat should be started with an "unaware" flag, which makes the victim flee? + { + if (victim.getClass().isClass(victim, "guard") + && !victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + reportCrime(player, victim, type, arg); + else + startCombat(victim, player); // TODO: combat should be started with an "unaware" flag, which makes the victim flee? + } return crimeSeen; } @@ -1145,7 +1151,8 @@ namespace MWMechanics // once the bounty has been paid. it->getClass().getNpcStats(*it).setCrimeId(id); - it->getClass().getCreatureStats(*it).getAiSequence().stack(AiPursue(player), *it); + if (!it->getClass().getCreatureStats(*it).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + it->getClass().getCreatureStats(*it).getAiSequence().stack(AiPursue(player), *it); } else { @@ -1213,7 +1220,8 @@ namespace MWMechanics { // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back. // Note: accidental or collateral damage attacks are ignored. - startCombat(victim, player); + if (!victim.getClass().getCreatureStats(victim).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + startCombat(victim, player); // Set the crime ID, which we will use to calm down participants // once the bounty has been paid. @@ -1256,7 +1264,8 @@ namespace MWMechanics } if (target.getClass().isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker) - && !isAggressive(target, attacker) && !isFightingNpc) + && !isAggressive(target, attacker) && !isFightingNpc + && !target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) commitCrime(attacker, target, MWBase::MechanicsManager::OT_Assault); if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(target) @@ -1265,7 +1274,8 @@ namespace MWMechanics { // Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back. // Note: accidental or collateral damage attacks are ignored. - startCombat(target, attacker); + if (!target.getClass().getCreatureStats(target).getAiSequence().hasPackage(AiPackage::TypeIdPursue)) + startCombat(target, attacker); } return true;