From 065d6a391d8eab6d35baf87f42a15e37f109ff5e Mon Sep 17 00:00:00 2001 From: Allofich Date: Mon, 6 Jun 2016 01:14:17 +0900 Subject: [PATCH] Don't repeat sequences of only one non-wander AI --- apps/openmw/mwmechanics/aipackage.cpp | 2 +- apps/openmw/mwmechanics/aipackage.hpp | 3 +-- apps/openmw/mwmechanics/aisequence.cpp | 23 +++++++++++++++++++++-- apps/openmw/mwmechanics/aisequence.hpp | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/aipackage.cpp b/apps/openmw/mwmechanics/aipackage.cpp index b08f92276..aefb39f6b 100644 --- a/apps/openmw/mwmechanics/aipackage.cpp +++ b/apps/openmw/mwmechanics/aipackage.cpp @@ -47,7 +47,7 @@ bool MWMechanics::AiPackage::shouldCancelPreviousAi() const bool MWMechanics::AiPackage::getRepeat() const { - return true; + return false; } MWMechanics::AiPackage::AiPackage() : mTimer(0.26f), mStarted(false) { //mTimer starts at .26 to force initial pathbuild diff --git a/apps/openmw/mwmechanics/aipackage.hpp b/apps/openmw/mwmechanics/aipackage.hpp index 0cf285479..fb862189d 100644 --- a/apps/openmw/mwmechanics/aipackage.hpp +++ b/apps/openmw/mwmechanics/aipackage.hpp @@ -87,8 +87,7 @@ namespace MWMechanics /// Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default true)? virtual bool shouldCancelPreviousAi() const; - /// Return true if this package should repeat. Can only be false for AIWander, if AIWander is assigned - /// assigned through the console or script. + /// Return true if this package should repeat. Currently only used for Wander packages. virtual bool getRepeat() const; bool isTargetMagicallyHidden(const MWWorld::Ptr& target); diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 11f390854..412df3742 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -29,13 +29,14 @@ void AiSequence::copy (const AiSequence& sequence) mPackages.push_back ((*iter)->clone()); } -AiSequence::AiSequence() : mDone (false), mLastAiPackage(-1) {} +AiSequence::AiSequence() : mDone (false), mRepeat(false), mLastAiPackage(-1) {} AiSequence::AiSequence (const AiSequence& sequence) { copy (sequence); mDone = sequence.mDone; mLastAiPackage = sequence.mLastAiPackage; + mRepeat = sequence.mRepeat; } AiSequence& AiSequence::operator= (const AiSequence& sequence) @@ -231,7 +232,7 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac if (package->execute (actor,characterController,state,duration)) { // Put repeating noncombat AI packages on the end of the stack so they can be used again - if (isActualAiPackage(packageTypeId) && package->getRepeat()) + if (isActualAiPackage(packageTypeId) && (mRepeat || package->getRepeat())) { mPackages.push_back(package->clone()); } @@ -292,6 +293,7 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor) else ++it; } + mRepeat=false; } // insert new package in correct place depending on priority @@ -317,6 +319,10 @@ AiPackage* MWMechanics::AiSequence::getActivePackage() void AiSequence::fill(const ESM::AIPackageList &list) { + // If there is more than one package in the list, enable repeating + if (!list.mList.empty() && list.mList.begin() != (list.mList.end()-1)) + mRepeat = true; + for (std::vector::const_iterator it = list.mList.begin(); it != list.mList.end(); ++it) { MWMechanics::AiPackage* package; @@ -366,6 +372,19 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence) if (!sequence.mPackages.empty()) clear(); + // If there is more than one non-combat, non-pursue package in the list, enable repeating. + int count = 0; + for (std::vector::const_iterator it = sequence.mPackages.begin(); + it != sequence.mPackages.end(); ++it) + { + if (isActualAiPackage(it->mType)) + count++; + } + + if (count > 1) + mRepeat = true; + + // Load packages for (std::vector::const_iterator it = sequence.mPackages.begin(); it != sequence.mPackages.end(); ++it) { diff --git a/apps/openmw/mwmechanics/aisequence.hpp b/apps/openmw/mwmechanics/aisequence.hpp index 1eefe7c69..0c200c26b 100644 --- a/apps/openmw/mwmechanics/aisequence.hpp +++ b/apps/openmw/mwmechanics/aisequence.hpp @@ -40,6 +40,9 @@ namespace MWMechanics ///Finished with top AIPackage, set for one frame bool mDone; + ///Does this AI sequence repeat (repeating of Wander packages handled separately) + bool mRepeat; + ///Copy AiSequence void copy (const AiSequence& sequence);