AIWander - Added support for the Repeat parameter to mimic vanilla.

actorid
Torben Carrington 12 years ago
parent 681345dd15
commit 1cfe037d6b

@ -1,8 +1,8 @@
#include "aiwander.hpp" #include "aiwander.hpp"
#include <iostream> #include <iostream>
MWMechanics::AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<int>& idle): MWMechanics::AiWander::AiWander(int distance, int duration, int timeOfDay, const std::vector<int>& idle, bool repeat):
mDistance(distance), mDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle) mDistance(distance), mDuration(duration), mTimeOfDay(timeOfDay), mIdle(idle), mRepeat(repeat)
{ {
} }

@ -6,24 +6,24 @@
namespace MWMechanics namespace MWMechanics
{ {
class AiWander : public AiPackage class AiWander : public AiPackage
{ {
public: public:
AiWander(int distance, int duration, int timeOfDay, const std::vector<int>& idle); AiWander(int distance, int duration, int timeOfDay, const std::vector<int>& idle, bool repeat);
virtual AiPackage *clone() const; virtual AiPackage *clone() const;
virtual bool execute (const MWWorld::Ptr& actor); virtual bool execute (const MWWorld::Ptr& actor);
///< \return Package completed? ///< \return Package completed?
virtual int getTypeId() const; virtual int getTypeId() const;
///< 0: Wander ///< 0: Wander
private: private:
int mDistance; int mDistance;
int mDuration; int mDuration;
int mTimeOfDay; int mTimeOfDay;
std::vector<int> mIdle; std::vector<int> mIdle;
bool mRepeat;
}; };
} }
#endif #endif

@ -181,19 +181,29 @@ namespace MWScript
runtime.pop(); runtime.pop();
std::vector<int> idleList; std::vector<int> idleList;
bool repeat = false;
for (int i=2; i<10 && arg0; ++i) for(short i=1; i < 10 && arg0; ++i)
{ {
if(!repeat)
repeat = true;
Interpreter::Type_Integer idleValue = runtime[0].mInteger; Interpreter::Type_Integer idleValue = runtime[0].mInteger;
idleList.push_back(idleValue); idleList.push_back(idleValue);
runtime.pop(); runtime.pop();
--arg0; --arg0;
} }
if(arg0)
{
repeat = runtime[0].mInteger;
runtime.pop();
--arg0;
}
// discard additional arguments (reset), because we have no idea what they mean. // discard additional arguments (reset), because we have no idea what they mean.
for (unsigned int i=0; i<arg0; ++i) runtime.pop(); for (unsigned int i=0; i<arg0; ++i) runtime.pop();
MWMechanics::AiWander wanderPackage(range, duration, time, idleList); MWMechanics::AiWander wanderPackage(range, duration, time, idleList, repeat);
MWWorld::Class::get (ptr).getCreatureStats (ptr).getAiSequence().stack(wanderPackage); MWWorld::Class::get (ptr).getCreatureStats (ptr).getAiSequence().stack(wanderPackage);
} }
}; };

Loading…
Cancel
Save