2012-11-15 21:15:20 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_AIWANDER_H
|
|
|
|
#define GAME_MWMECHANICS_AIWANDER_H
|
2012-11-14 17:42:04 +00:00
|
|
|
|
|
|
|
#include "aipackage.hpp"
|
2014-04-29 07:09:51 +00:00
|
|
|
|
2012-11-14 17:42:04 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-04-29 07:09:51 +00:00
|
|
|
#include <OgreVector3.h>
|
|
|
|
|
2013-05-26 15:49:44 +00:00
|
|
|
#include "pathfinding.hpp"
|
2014-04-17 23:03:36 +00:00
|
|
|
#include "obstacle.hpp"
|
2013-05-26 15:49:44 +00:00
|
|
|
|
|
|
|
#include "../mwworld/timestamp.hpp"
|
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
namespace AiSequence
|
|
|
|
{
|
|
|
|
struct AiWander;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 17:42:04 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2014-04-30 03:40:59 +00:00
|
|
|
/// \brief Causes the Actor to wander within a specified range
|
2012-11-16 17:38:15 +00:00
|
|
|
class AiWander : public AiPackage
|
|
|
|
{
|
2013-05-24 11:49:20 +00:00
|
|
|
public:
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Constructor
|
|
|
|
/** \param distance Max distance the ACtor will wander
|
|
|
|
\param duration Time, in hours, that this package will be preformed
|
|
|
|
\param timeOfDay Start time of the package, if it has a duration. Currently unimplemented
|
|
|
|
\param idle Chances of each idle to play (9 in total)
|
|
|
|
\param repeat Repeat wander or not **/
|
2014-06-12 21:27:04 +00:00
|
|
|
AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat);
|
|
|
|
|
|
|
|
AiWander (const ESM::AiSequence::AiWander* wander);
|
|
|
|
|
|
|
|
void init();
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2013-05-24 11:49:20 +00:00
|
|
|
virtual AiPackage *clone() const;
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2013-10-30 19:42:50 +00:00
|
|
|
virtual bool execute (const MWWorld::Ptr& actor,float duration);
|
2014-04-30 03:40:59 +00:00
|
|
|
|
2013-05-24 11:49:20 +00:00
|
|
|
virtual int getTypeId() const;
|
2012-11-14 17:42:04 +00:00
|
|
|
|
2014-04-30 03:40:59 +00:00
|
|
|
/// Set the position to return to for a stationary (non-wandering) actor
|
|
|
|
/** In case another AI package moved the actor elsewhere **/
|
2014-04-29 07:09:51 +00:00
|
|
|
void setReturnPosition (const Ogre::Vector3& position);
|
|
|
|
|
2014-06-12 21:27:04 +00:00
|
|
|
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
|
|
|
|
|
2013-05-24 11:49:20 +00:00
|
|
|
private:
|
2013-05-30 02:26:45 +00:00
|
|
|
void stopWalking(const MWWorld::Ptr& actor);
|
2013-05-26 15:49:44 +00:00
|
|
|
void playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
|
|
|
|
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
|
2014-04-26 09:47:47 +00:00
|
|
|
void getRandomIdle();
|
2013-05-26 15:49:44 +00:00
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
int mDistance; // how far the actor can wander from the spawn point
|
2013-05-24 11:49:20 +00:00
|
|
|
int mDuration;
|
|
|
|
int mTimeOfDay;
|
2014-06-12 21:27:04 +00:00
|
|
|
std::vector<unsigned char> mIdle;
|
2013-05-24 11:49:20 +00:00
|
|
|
bool mRepeat;
|
2013-05-26 15:49:44 +00:00
|
|
|
|
2014-07-28 22:16:24 +00:00
|
|
|
enum GreetingState {
|
|
|
|
Greet_None,
|
|
|
|
Greet_InProgress,
|
|
|
|
Greet_Done
|
|
|
|
};
|
|
|
|
GreetingState mSaidGreeting;
|
2014-07-28 22:41:37 +00:00
|
|
|
int greetingTimer;
|
2014-01-19 16:03:25 +00:00
|
|
|
|
2014-04-29 07:09:51 +00:00
|
|
|
bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position,
|
|
|
|
// if we had the actor in the AiWander constructor...
|
|
|
|
Ogre::Vector3 mReturnPosition;
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
// Cached current cell location
|
2013-05-26 15:49:44 +00:00
|
|
|
int mCellX;
|
|
|
|
int mCellY;
|
2014-03-29 09:17:04 +00:00
|
|
|
// Cell location multiplied by ESM::Land::REAL_SIZE
|
2013-05-26 15:49:44 +00:00
|
|
|
float mXCell;
|
|
|
|
float mYCell;
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
const MWWorld::CellStore* mCell; // for detecting cell change
|
2014-03-13 12:44:52 +00:00
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
// if false triggers calculating allowed nodes based on mDistance
|
2013-05-26 15:49:44 +00:00
|
|
|
bool mStoredAvailableNodes;
|
2014-04-17 23:03:36 +00:00
|
|
|
// AiWander states
|
2013-05-26 15:49:44 +00:00
|
|
|
bool mChooseAction;
|
|
|
|
bool mIdleNow;
|
|
|
|
bool mMoveNow;
|
|
|
|
bool mWalking;
|
|
|
|
|
|
|
|
unsigned short mPlayedIdle;
|
|
|
|
|
|
|
|
MWWorld::TimeStamp mStartTime;
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
// allowed pathgrid nodes based on mDistance from the spawn point
|
2013-05-26 15:49:44 +00:00
|
|
|
std::vector<ESM::Pathgrid::Point> mAllowedNodes;
|
|
|
|
ESM::Pathgrid::Point mCurrentNode;
|
2014-04-17 23:03:36 +00:00
|
|
|
bool mTrimCurrentNode;
|
|
|
|
void trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes,
|
|
|
|
const PathFinder& pathfinder);
|
2013-05-26 15:49:44 +00:00
|
|
|
|
|
|
|
PathFinder mPathFinder;
|
2014-04-17 23:03:36 +00:00
|
|
|
|
|
|
|
ObstacleCheck mObstacleCheck;
|
|
|
|
float mDoorCheckDuration;
|
|
|
|
int mStuckCount;
|
2014-04-20 00:06:03 +00:00
|
|
|
|
2014-04-20 01:59:47 +00:00
|
|
|
// the z rotation angle (degrees) we want to reach
|
|
|
|
// used every frame when mRotate is true
|
|
|
|
float mTargetAngle;
|
|
|
|
bool mRotate;
|
2014-04-20 00:06:03 +00:00
|
|
|
float mReaction; // update some actions infrequently
|
2012-11-16 17:38:15 +00:00
|
|
|
};
|
2013-05-24 11:49:20 +00:00
|
|
|
}
|
2012-11-14 17:42:04 +00:00
|
|
|
|
2012-11-16 19:28:20 +00:00
|
|
|
#endif
|