OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aipackage.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWMECHANICS_AIPACKAGE_H
2 #define GAME_MWMECHANICS_AIPACKAGE_H
3 
5 
6 #include "pathfinding.hpp"
7 #include "obstacle.hpp"
8 #include "aistate.hpp"
9 
10 namespace MWWorld
11 {
12  class Ptr;
13 }
14 
15 namespace ESM
16 {
17  struct Cell;
18  namespace AiSequence
19  {
20  struct AiSequence;
21  }
22 }
23 
24 
25 namespace MWMechanics
26 {
27  const float AI_REACTION_TIME = 0.25f;
28 
29  class CharacterController;
30  class PathgridGraph;
31 
33  class AiPackage
34  {
35  public:
37  enum TypeId {
38  TypeIdNone = -1,
44 
45  // These 5 are not really handled as Ai Packages in the MW engine
46  // For compatibility do *not* return these in the getCurrentAiPackage script function..
54  };
55 
57  AiPackage();
58 
60  virtual ~AiPackage();
61 
63  virtual AiPackage *clone() const = 0;
64 
67  virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) = 0;
68 
71  virtual int getTypeId() const = 0;
72 
74  virtual unsigned int getPriority() const {return 0;}
75 
76  virtual void writeState (ESM::AiSequence::AiSequence& sequence) const {}
77 
79  virtual void fastForward(const MWWorld::Ptr& actor, AiState& state) {}
80 
82  virtual MWWorld::Ptr getTarget() const;
83 
85  virtual osg::Vec3f getDestination(const MWWorld::Ptr& actor) const { return osg::Vec3f(0, 0, 0); };
86 
88  virtual bool sideWithTarget() const;
89 
91  virtual bool followTargetThroughDoors() const;
92 
94  virtual bool canCancel() const;
95 
97  virtual bool shouldCancelPreviousAi() const;
98 
100  virtual bool getRepeat() const;
101 
103  void reset();
104 
105  bool isTargetMagicallyHidden(const MWWorld::Ptr& target);
106 
108  static bool isReachableRotatingOnTheRun(const MWWorld::Ptr& actor, const ESM::Pathgrid::Point& dest);
109 
110  protected:
112 
113  bool pathTo(const MWWorld::Ptr& actor, const ESM::Pathgrid::Point& dest, float duration, float destTolerance = 0.0f);
114 
119  bool shortcutPath(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor, bool *destInLOS, bool isPathClear);
120 
122  bool checkWayIsClearForActor(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor);
123 
124  virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest, const MWWorld::CellStore* currentCell);
125 
126  void evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos);
127  void openDoors(const MWWorld::Ptr& actor);
128 
130 
131  // TODO: all this does not belong here, move into temporary storage
134 
135  float mTimer;
136 
137  std::string mTargetActorRefId;
138  mutable int mTargetActorId;
139 
140  osg::Vec3f mLastActorPos;
141 
142  short mRotateOnTheRunChecks; // attempts to check rotation to the pathpoint on the run possibility
143 
144  bool mIsShortcutting; // if shortcutting at the moment
145  bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt
146  ESM::Pathgrid::Point mShortcutFailPos; // position of last shortcut fail
147 
148  private:
149  bool isNearInactiveCell(const ESM::Position& actorPos);
150  };
151 }
152 
153 #endif
154 
ObstacleCheck mObstacleCheck
Definition: aipackage.hpp:133
Definition: aipackage.hpp:48
bool isNearInactiveCell(const ESM::Position &actorPos)
Definition: aipackage.cpp:346
float mTimer
Definition: aipackage.hpp:135
void reset()
Reset pathfinding state.
Definition: aipackage.cpp:87
static bool isReachableRotatingOnTheRun(const MWWorld::Ptr &actor, const ESM::Pathgrid::Point &dest)
Return if actor's rotation speed is sufficient to rotate to the destination pathpoint on the run...
Definition: aipackage.cpp:370
virtual AiPackage * clone() const =0
Clones the package.
Definition: aipackage.hpp:43
short mRotateOnTheRunChecks
Definition: aipackage.hpp:142
virtual int getTypeId() const =0
const PathgridGraph & getPathGridGraph(const MWWorld::CellStore *cell)
Definition: aipackage.cpp:255
Definition: pathfinding.hpp:35
Base class for AI packages.
Definition: aipackage.hpp:33
Definition: aipackage.hpp:38
virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point &newDest, const MWWorld::CellStore *currentCell)
Definition: aipackage.cpp:334
Definition: obstacle.hpp:22
Definition: aipackage.hpp:40
bool checkWayIsClearForActor(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::Ptr &actor)
Check if the way to the destination is clear, taking into account actor speed.
Definition: aipackage.cpp:297
int mTargetActorId
Definition: aipackage.hpp:138
Definition: character.hpp:154
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const
Definition: aipackage.hpp:76
ESM::Pathgrid::Point mShortcutFailPos
Definition: aipackage.hpp:146
virtual bool execute(const MWWorld::Ptr &actor, CharacterController &characterController, AiState &state, float duration)=0
virtual bool followTargetThroughDoors() const
Return true if the actor should follow the target through teleport doors (default false) ...
Definition: aipackage.cpp:67
virtual osg::Vec3f getDestination(const MWWorld::Ptr &actor) const
Get the destination point of the AI package (not applicable to all AI packages, default return (0...
Definition: aipackage.hpp:85
virtual ~AiPackage()
Default Deconstructor.
Definition: aipackage.cpp:26
Definition: aipackage.hpp:50
Definition: aipackage.hpp:49
bool mShortcutProhibited
Definition: aipackage.hpp:145
osg::Vec3f mLastActorPos
Definition: aipackage.hpp:140
Definition: aipackage.hpp:53
Mutable state of a cell.
Definition: cellstore.hpp:51
virtual bool canCancel() const
Can this Ai package be canceled? (default true)
Definition: aipackage.cpp:72
virtual bool getRepeat() const
Return true if this package should repeat. Currently only used for Wander packages.
Definition: aipackage.cpp:82
void evadeObstacles(const MWWorld::Ptr &actor, float duration, const ESM::Position &pos)
Definition: aipackage.cpp:203
const float AI_REACTION_TIME
Definition: aipackage.hpp:27
virtual bool sideWithTarget() const
Return true if having this AiPackage makes the actor side with the target in fights (default false) ...
Definition: aipackage.cpp:62
bool pathTo(const MWWorld::Ptr &actor, const ESM::Pathgrid::Point &dest, float duration, float destTolerance=0.0f)
Handles path building and shortcutting with obstacles avoiding.
Definition: aipackage.cpp:99
Definition: aipackage.hpp:51
void openDoors(const MWWorld::Ptr &actor)
Definition: aipackage.cpp:226
bool mIsShortcutting
Definition: aipackage.hpp:144
Definition: defs.hpp:38
Definition: aipackage.hpp:39
TypeId
Enumerates the various AITypes available.
Definition: aipackage.hpp:37
Definition: aisequence.hpp:151
virtual MWWorld::Ptr getTarget() const
Get the target actor the AI is targeted at (not applicable to all AI packages, default return empty P...
Definition: aipackage.cpp:39
bool shortcutPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::Ptr &actor, bool *destInLOS, bool isPathClear)
Definition: aipackage.cpp:269
Definition: pathgrid.hpp:20
PathFinder mPathFinder
Definition: aipackage.hpp:132
Definition: loadpgrd.hpp:30
bool isTargetMagicallyHidden(const MWWorld::Ptr &target)
Definition: aipackage.cpp:339
Definition: aipackage.hpp:42
std::string mTargetActorRefId
Definition: aipackage.hpp:137
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
Definition: aipackage.hpp:47
virtual unsigned int getPriority() const
Higher number is higher priority (0 being the lowest)
Definition: aipackage.hpp:74
AiPackage()
Default constructor.
Definition: aipackage.cpp:28
virtual void fastForward(const MWWorld::Ptr &actor, AiState &state)
Simulates the passing of time.
Definition: aipackage.hpp:79
virtual bool shouldCancelPreviousAi() const
Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default t...
Definition: aipackage.cpp:77
Definition: aipackage.hpp:41