2012-11-15 22:15:20 +01:00
|
|
|
#ifndef GAME_MWMECHANICS_AIWANDER_H
|
|
|
|
#define GAME_MWMECHANICS_AIWANDER_H
|
2012-11-14 18:42:04 +01:00
|
|
|
|
|
|
|
#include "aipackage.hpp"
|
2014-04-29 09:09:51 +02:00
|
|
|
|
2012-11-14 18:42:04 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2013-05-26 08:49:44 -07:00
|
|
|
#include "pathfinding.hpp"
|
2014-04-18 09:03:36 +10:00
|
|
|
#include "obstacle.hpp"
|
2013-05-26 08:49:44 -07:00
|
|
|
|
|
|
|
#include "../mwworld/timestamp.hpp"
|
|
|
|
|
2014-10-08 10:58:52 +02:00
|
|
|
|
|
|
|
#include "aistate.hpp"
|
|
|
|
|
2014-06-12 23:27:04 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
2015-03-06 21:36:42 +13:00
|
|
|
struct Cell;
|
2014-06-12 23:27:04 +02:00
|
|
|
namespace AiSequence
|
|
|
|
{
|
|
|
|
struct AiWander;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-14 18:42:04 +01:00
|
|
|
namespace MWMechanics
|
2014-10-08 22:11:45 +02:00
|
|
|
{
|
|
|
|
|
2014-10-08 10:58:52 +02:00
|
|
|
|
2014-12-01 13:34:42 +01:00
|
|
|
struct AiWanderStorage;
|
|
|
|
|
2014-04-29 23:40:59 -04:00
|
|
|
/// \brief Causes the Actor to wander within a specified range
|
2012-11-16 18:38:15 +01:00
|
|
|
class AiWander : public AiPackage
|
|
|
|
{
|
2013-05-24 04:49:20 -07:00
|
|
|
public:
|
2014-04-29 23:40:59 -04: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 23:27:04 +02:00
|
|
|
AiWander(int distance, int duration, int timeOfDay, const std::vector<unsigned char>& idle, bool repeat);
|
|
|
|
|
|
|
|
AiWander (const ESM::AiSequence::AiWander* wander);
|
|
|
|
|
2014-10-08 22:11:45 +02:00
|
|
|
|
2014-04-29 23:40:59 -04:00
|
|
|
|
2013-05-24 04:49:20 -07:00
|
|
|
virtual AiPackage *clone() const;
|
2014-04-29 23:40:59 -04:00
|
|
|
|
2015-06-26 17:47:04 +02:00
|
|
|
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration);
|
2014-04-29 23:40:59 -04:00
|
|
|
|
2013-05-24 04:49:20 -07:00
|
|
|
virtual int getTypeId() const;
|
2012-11-14 18:42:04 +01:00
|
|
|
|
2014-04-29 23:40:59 -04:00
|
|
|
/// Set the position to return to for a stationary (non-wandering) actor
|
|
|
|
/** In case another AI package moved the actor elsewhere **/
|
2015-06-03 19:41:19 +02:00
|
|
|
void setReturnPosition (const osg::Vec3f& position);
|
2014-04-29 09:09:51 +02:00
|
|
|
|
2014-06-12 23:27:04 +02:00
|
|
|
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
|
|
|
|
|
2014-12-31 18:41:57 +01:00
|
|
|
virtual void fastForward(const MWWorld::Ptr& actor, AiState& state);
|
2014-10-08 22:11:45 +02:00
|
|
|
|
|
|
|
enum GreetingState {
|
|
|
|
Greet_None,
|
|
|
|
Greet_InProgress,
|
|
|
|
Greet_Done
|
|
|
|
};
|
2013-05-24 04:49:20 -07:00
|
|
|
private:
|
2014-10-08 22:11:45 +02:00
|
|
|
// NOTE: mDistance and mDuration must be set already
|
|
|
|
void init();
|
|
|
|
|
2014-12-01 13:34:42 +01:00
|
|
|
void stopWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
|
2013-05-26 08:49:44 -07:00
|
|
|
void playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
|
|
|
|
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
|
2014-10-09 23:11:10 +02:00
|
|
|
void getRandomIdle(unsigned short& playedIdle);
|
2015-07-12 16:35:15 +12:00
|
|
|
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
|
2013-05-26 08:49:44 -07:00
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
int mDistance; // how far the actor can wander from the spawn point
|
2013-05-24 04:49:20 -07:00
|
|
|
int mDuration;
|
|
|
|
int mTimeOfDay;
|
2014-06-12 23:27:04 +02:00
|
|
|
std::vector<unsigned char> mIdle;
|
2013-05-24 04:49:20 -07:00
|
|
|
bool mRepeat;
|
2014-10-08 22:11:45 +02:00
|
|
|
|
2014-01-19 17:03:25 +01:00
|
|
|
|
2014-04-29 09:09:51 +02:00
|
|
|
bool mHasReturnPosition; // NOTE: Could be removed if mReturnPosition was initialized to actor position,
|
|
|
|
// if we had the actor in the AiWander constructor...
|
2015-06-03 19:41:19 +02:00
|
|
|
osg::Vec3f mReturnPosition;
|
2014-04-29 09:09:51 +02:00
|
|
|
|
2015-06-03 19:41:19 +02:00
|
|
|
osg::Vec3f mInitialActorPosition;
|
2014-12-31 21:27:19 +01:00
|
|
|
bool mStoredInitialActorPosition;
|
2014-10-08 22:11:45 +02:00
|
|
|
|
|
|
|
|
2014-03-13 23:44:52 +11:00
|
|
|
|
2015-07-12 16:32:48 +12:00
|
|
|
// do we need to calculate allowed nodes based on mDistance
|
|
|
|
bool mPopulateAvailableNodes;
|
2013-05-26 08:49:44 -07:00
|
|
|
|
2014-10-09 23:11:10 +02:00
|
|
|
|
|
|
|
|
2013-05-26 08:49:44 -07:00
|
|
|
|
|
|
|
MWWorld::TimeStamp mStartTime;
|
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
// allowed pathgrid nodes based on mDistance from the spawn point
|
2013-05-26 08:49:44 -07:00
|
|
|
std::vector<ESM::Pathgrid::Point> mAllowedNodes;
|
2014-12-31 18:41:57 +01:00
|
|
|
|
|
|
|
void getAllowedNodes(const MWWorld::Ptr& actor, const ESM::Cell* cell);
|
|
|
|
|
2013-05-26 08:49:44 -07:00
|
|
|
ESM::Pathgrid::Point mCurrentNode;
|
2014-04-18 09:03:36 +10:00
|
|
|
bool mTrimCurrentNode;
|
|
|
|
void trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes,
|
|
|
|
const PathFinder& pathfinder);
|
2013-05-26 08:49:44 -07:00
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2014-10-09 23:11:10 +02:00
|
|
|
// ObstacleCheck mObstacleCheck;
|
2014-04-18 09:03:36 +10:00
|
|
|
float mDoorCheckDuration;
|
|
|
|
int mStuckCount;
|
2014-04-20 10:06:03 +10:00
|
|
|
|
2015-03-23 20:57:36 +13:00
|
|
|
// constants for converting idleSelect values into groupNames
|
|
|
|
enum GroupIndex
|
|
|
|
{
|
|
|
|
GroupIndex_MinIdle = 2,
|
|
|
|
GroupIndex_MaxIdle = 9
|
|
|
|
};
|
2014-10-08 10:58:52 +02:00
|
|
|
|
2015-07-05 18:07:14 +12:00
|
|
|
/// convert point from local (i.e. cell) to world co-ordinates
|
|
|
|
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
|
|
|
|
|
2015-07-05 18:17:18 +12:00
|
|
|
void SetCurrentNodeToClosestAllowedNode(osg::Vec3f npcPos);
|
|
|
|
|
2015-07-05 18:21:35 +12:00
|
|
|
void AddNonPathGridAllowedPoints(osg::Vec3f npcPos, const ESM::Pathgrid * pathGrid, int pointIndex);
|
|
|
|
|
|
|
|
void AddPointBetweenPathGridPoints(const ESM::Pathgrid::Point& start, const ESM::Pathgrid::Point& end);
|
|
|
|
|
2015-03-23 20:57:36 +13:00
|
|
|
/// lookup table for converting idleSelect value to groupName
|
|
|
|
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
|
2015-07-08 18:41:03 +12:00
|
|
|
|
|
|
|
static int OffsetToPreventOvercrowding();
|
2012-11-16 18:38:15 +01:00
|
|
|
};
|
2014-10-08 22:11:45 +02:00
|
|
|
|
2014-10-09 23:11:10 +02:00
|
|
|
|
2013-05-24 04:49:20 -07:00
|
|
|
}
|
2012-11-14 18:42:04 +01:00
|
|
|
|
2012-11-16 20:28:20 +01:00
|
|
|
#endif
|