From 023d7072f921b34e68a8c2722ee4c30ff0cd2188 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 20 Sep 2014 13:55:57 +0200 Subject: [PATCH] Don't play battle music for enemies out of AI processing range --- apps/openmw/mwmechanics/actors.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 1ee498d84..36c71adeb 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1116,6 +1116,8 @@ namespace MWMechanics MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + int hostilesCount = 0; // need to know this to play Battle music + // AI and magic effects update for(PtrControllerMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) { @@ -1125,6 +1127,8 @@ namespace MWMechanics // AI processing is only done within distance of 7168 units to the player. Note the "AI distance" slider doesn't affect this // (it only does some throttling for targets beyond the "AI distance", so doesn't give any guarantees as to whether AI will be enabled or not) + // This distance could be made configurable later, but the setting must be marked with a big warning: + // using higher values will make a quest in Bloodmoon harder or impossible to complete (bug #1876) if (MWBase::Environment::get().getMechanicsManager()->isAIActive() && Ogre::Vector3(player.getRefData().getPosition().pos).squaredDistance(Ogre::Vector3(iter->first.getRefData().getPosition().pos)) <= 7168*7168) @@ -1147,6 +1151,12 @@ namespace MWMechanics if (iter->first != player) iter->first.getClass().getCreatureStats(iter->first).getAiSequence().execute(iter->first, duration); + + CreatureStats &stats = iter->first.getClass().getCreatureStats(iter->first); + if(!stats.isDead()) + { + if (stats.getAiSequence().isInCombat()) hostilesCount++; + } } if(iter->first.getTypeName() == typeid(ESM::NPC).name()) @@ -1192,19 +1202,6 @@ namespace MWMechanics } } - int hostilesCount = 0; // need to know this to play Battle music - - for(PtrControllerMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) - { - const MWWorld::Class &cls = iter->first.getClass(); - CreatureStats &stats = cls.getCreatureStats(iter->first); - - if(!stats.isDead()) - { - if (stats.getAiSequence().isInCombat()) hostilesCount++; - } - } - killDeadActors(); // check if we still have any player enemies to switch music