1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 23:49:55 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/aiwander.hpp

146 lines
4.7 KiB
C++
Raw Normal View History

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"
2012-11-14 17:42:04 +00:00
#include <vector>
#include "pathfinding.hpp"
#include "obstacle.hpp"
#include "../mwworld/timestamp.hpp"
#include "aistate.hpp"
2014-06-12 21:27:04 +00:00
namespace ESM
{
struct Cell;
2014-06-12 21:27:04 +00:00
namespace AiSequence
{
struct AiWander;
}
}
2012-11-14 17:42:04 +00:00
namespace MWMechanics
{
struct AiWanderStorage;
/// \brief Causes the Actor to wander within a specified range
2012-11-16 17:38:15 +00:00
class AiWander : public AiPackage
{
public:
/// 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);
virtual AiPackage *clone() const;
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration);
virtual int getTypeId() const;
2012-11-14 17:42:04 +00: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 17:41:19 +00:00
void setReturnPosition (const osg::Vec3f& position);
2014-06-12 21:27:04 +00:00
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const;
virtual void fastForward(const MWWorld::Ptr& actor, AiState& state);
enum GreetingState {
Greet_None,
Greet_InProgress,
Greet_Done
};
private:
// NOTE: mDistance and mDuration must be set already
void init();
void stopWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
void playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
void getRandomIdle(unsigned short& playedIdle);
int mDistance; // how far the actor can wander from the spawn point
int mDuration;
int mTimeOfDay;
2014-06-12 21:27:04 +00:00
std::vector<unsigned char> mIdle;
bool mRepeat;
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 17:41:19 +00:00
osg::Vec3f mReturnPosition;
2015-06-03 17:41:19 +00:00
osg::Vec3f mInitialActorPosition;
bool mStoredInitialActorPosition;
// if false triggers calculating allowed nodes based on mDistance
bool mStoredAvailableNodes;
MWWorld::TimeStamp mStartTime;
// allowed pathgrid nodes based on mDistance from the spawn point
std::vector<ESM::Pathgrid::Point> mAllowedNodes;
void getAllowedNodes(const MWWorld::Ptr& actor, const ESM::Cell* cell);
ESM::Pathgrid::Point mCurrentNode;
bool mTrimCurrentNode;
void trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes,
const PathFinder& pathfinder);
// ObstacleCheck mObstacleCheck;
float mDoorCheckDuration;
int mStuckCount;
2015-03-23 07:57:36 +00:00
// constants for converting idleSelect values into groupNames
enum GroupIndex
{
GroupIndex_MinIdle = 2,
GroupIndex_MaxIdle = 9
};
// to prevent overcrowding
static const int DestinationTolerance = 64;
// distance must be long enough that NPC will need to move to get there.
static const int MinimumWanderDistance = DestinationTolerance * 2;
2015-07-05 06:07:14 +00:00
/// convert point from local (i.e. cell) to world co-ordinates
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::Cell * cell);
void SetCurrentNodeToClosestAllowedNode(osg::Vec3f npcPos);
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 07:57:36 +00:00
/// lookup table for converting idleSelect value to groupName
static const std::string sIdleSelectToGroupName[GroupIndex_MaxIdle - GroupIndex_MinIdle + 1];
static int OffsetToPreventOvercrowding();
2012-11-16 17:38:15 +00:00
};
}
2012-11-14 17:42:04 +00:00
2012-11-16 19:28:20 +00:00
#endif