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

141 lines
6.2 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 "../mwworld/timestamp.hpp"
2016-06-17 14:07:16 +00:00
#include "pathfinding.hpp"
#include "obstacle.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
2016-06-15 18:43:09 +00:00
{
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
2016-06-11 19:25:40 +00:00
\param timeOfDay Currently unimplemented. Not functional in the original engine.
\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);
bool getRepeat() const;
enum GreetingState {
Greet_None,
Greet_InProgress,
Greet_Done
};
enum WanderState {
Wander_ChooseAction,
Wander_IdleNow,
Wander_MoveNow,
Wander_Walking
};
2016-06-15 18:43:09 +00:00
private:
// NOTE: mDistance and mDuration must be set already
void init();
void stopWalking(const MWWorld::Ptr& actor, AiWanderStorage& storage);
/// Have the given actor play an idle animation
/// @return Success or error
bool playIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
bool checkIdle(const MWWorld::Ptr& actor, unsigned short idleSelect);
2015-07-19 06:04:42 +00:00
short unsigned getRandomIdle();
void setPathToAnAllowedNode(const MWWorld::Ptr& actor, AiWanderStorage& storage, const ESM::Position& actorPos);
void playGreetingIfPlayerGetsTooClose(const MWWorld::Ptr& actor, AiWanderStorage& storage);
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration, ESM::Position& pos);
void playIdleDialogueRandomly(const MWWorld::Ptr& actor);
void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage);
void doPerFrameActionsForState(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos);
void onIdleStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage);
void onWalkingStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage, ESM::Position& pos);
void onChooseActionStatePerFrameActions(const MWWorld::Ptr& actor, AiWanderStorage& storage);
bool reactionTimeActions(const MWWorld::Ptr& actor, AiWanderStorage& storage,
const MWWorld::CellStore*& currentCell, bool cellChange, ESM::Position& pos, float duration);
2015-07-26 05:29:01 +00:00
bool isPackageCompleted(const MWWorld::Ptr& actor, AiWanderStorage& storage);
void returnToStartLocation(const MWWorld::Ptr& actor, AiWanderStorage& storage, ESM::Position& pos);
void wanderNearStart(const MWWorld::Ptr &actor, AiWanderStorage &storage, int wanderDistance);
bool destinationIsAtWater(const MWWorld::Ptr &actor, const osg::Vec3f& destination);
bool destinationThroughGround(const osg::Vec3f& startPoint, const osg::Vec3f& destination);
void completeManualWalking(const MWWorld::Ptr &actor, AiWanderStorage &storage);
int mDistance; // how far the actor can wander from the spawn point
int mDuration;
float mRemainingDuration;
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;
osg::Vec3f mInitialActorPosition;
bool mStoredInitialActorPosition;
bool mIsWanderDestReady;
void getAllowedNodes(const MWWorld::Ptr& actor, const ESM::Cell* cell, AiWanderStorage& storage);
2016-06-15 18:43:09 +00:00
void trimAllowedNodes(std::vector<ESM::Pathgrid::Point>& nodes, const PathFinder& pathfinder);
2015-03-23 07:57:36 +00:00
// constants for converting idleSelect values into groupNames
enum GroupIndex
{
GroupIndex_MinIdle = 2,
GroupIndex_MaxIdle = 9
};
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);
2016-06-15 18:43:09 +00:00
void SetCurrentNodeToClosestAllowedNode(osg::Vec3f npcPos, AiWanderStorage& storage);
2016-06-15 18:43:09 +00:00
void AddNonPathGridAllowedPoints(osg::Vec3f npcPos, const ESM::Pathgrid * pathGrid, int pointIndex, AiWanderStorage& storage);
2016-06-15 18:43:09 +00:00
void AddPointBetweenPathGridPoints(const ESM::Pathgrid::Point& start, const ESM::Pathgrid::Point& end, AiWanderStorage& storage);
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();
2016-06-15 18:43:09 +00:00
};
}
2012-11-14 17:42:04 +00:00
2012-11-16 19:28:20 +00:00
#endif