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 
32  class AiPackage
33  {
34  public:
36  enum TypeId {
37  TypeIdNone = -1,
43 
44  // These 4 are not really handled as Ai Packages in the MW engine
45  // For compatibility do *not* return these in the getCurrentAiPackage script function..
50  };
51 
53  AiPackage();
54 
56  virtual ~AiPackage();
57 
59  virtual AiPackage *clone() const = 0;
60 
63  virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) = 0;
64 
67  virtual int getTypeId() const = 0;
68 
70  virtual unsigned int getPriority() const {return 0;}
71 
72  virtual void writeState (ESM::AiSequence::AiSequence& sequence) const {}
73 
75  virtual void fastForward(const MWWorld::Ptr& actor, AiState& state) {}
76 
78  virtual MWWorld::Ptr getTarget() const;
79 
81  virtual bool sideWithTarget() const;
82 
84  virtual bool followTargetThroughDoors() const;
85 
87  virtual bool canCancel() const;
88 
90  virtual bool shouldCancelPreviousAi() const;
91 
93  virtual bool getRepeat() const;
94 
96  void reset();
97 
98  bool isTargetMagicallyHidden(const MWWorld::Ptr& target);
99 
101  static bool isReachableRotatingOnTheRun(const MWWorld::Ptr& actor, const ESM::Pathgrid::Point& dest);
102 
103  protected:
105 
106  bool pathTo(const MWWorld::Ptr& actor, const ESM::Pathgrid::Point& dest, float duration, float destTolerance = 0.0f);
107 
112  bool shortcutPath(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor, bool *destInLOS);
113 
115  bool checkWayIsClearForActor(const ESM::Pathgrid::Point& startPoint, const ESM::Pathgrid::Point& endPoint, const MWWorld::Ptr& actor);
116 
117  virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point& newDest, const MWWorld::CellStore* currentCell);
118 
119  void evadeObstacles(const MWWorld::Ptr& actor, float duration, const ESM::Position& pos);
120 
121  // TODO: all this does not belong here, move into temporary storage
124 
125  float mTimer;
126 
127  osg::Vec3f mLastActorPos;
128 
129  short mRotateOnTheRunChecks; // attempts to check rotation to the pathpoint on the run possibility
130 
131  bool mIsShortcutting; // if shortcutting at the moment
132  bool mShortcutProhibited; // shortcutting may be prohibited after unsuccessful attempt
133  ESM::Pathgrid::Point mShortcutFailPos; // position of last shortcut fail
134 
135  private:
136  bool isNearInactiveCell(const ESM::Position& actorPos);
137  };
138 }
139 
140 #endif
141 
ObstacleCheck mObstacleCheck
Definition: aipackage.hpp:123
Definition: aipackage.hpp:47
bool isNearInactiveCell(const ESM::Position &actorPos)
Definition: aipackage.cpp:282
float mTimer
Definition: aipackage.hpp:125
void reset()
Reset pathfinding state.
Definition: aipackage.cpp:64
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:306
virtual AiPackage * clone() const =0
Clones the package.
Definition: aipackage.hpp:42
short mRotateOnTheRunChecks
Definition: aipackage.hpp:129
virtual int getTypeId() const =0
Definition: pathfinding.hpp:33
Base class for AI packages.
Definition: aipackage.hpp:32
Definition: aipackage.hpp:37
virtual bool doesPathNeedRecalc(const ESM::Pathgrid::Point &newDest, const MWWorld::CellStore *currentCell)
Definition: aipackage.cpp:270
Definition: obstacle.hpp:27
Definition: aipackage.hpp:39
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:233
Definition: character.hpp:145
virtual void writeState(ESM::AiSequence::AiSequence &sequence) const
Definition: aipackage.hpp:72
ESM::Pathgrid::Point mShortcutFailPos
Definition: aipackage.hpp:133
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:44
virtual ~AiPackage()
Default Deconstructor.
Definition: aipackage.cpp:24
Definition: aipackage.hpp:49
Definition: aipackage.hpp:48
bool mShortcutProhibited
Definition: aipackage.hpp:132
osg::Vec3f mLastActorPos
Definition: aipackage.hpp:127
Mutable state of a cell.
Definition: cellstore.hpp:53
virtual bool canCancel() const
Can this Ai package be canceled? (default true)
Definition: aipackage.cpp:49
virtual bool getRepeat() const
Return true if this package should repeat. Currently only used for Wander packages.
Definition: aipackage.cpp:59
void evadeObstacles(const MWWorld::Ptr &actor, float duration, const ESM::Position &pos)
Definition: aipackage.cpp:168
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:39
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:76
bool mIsShortcutting
Definition: aipackage.hpp:131
Definition: defs.hpp:38
Definition: aipackage.hpp:38
TypeId
Enumerates the various AITypes available.
Definition: aipackage.hpp:36
Definition: aisequence.hpp:148
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:34
PathFinder mPathFinder
Definition: aipackage.hpp:122
Definition: loadpgrd.hpp:30
bool isTargetMagicallyHidden(const MWWorld::Ptr &target)
Definition: aipackage.cpp:275
Definition: aipackage.hpp:41
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
Definition: aipackage.hpp:46
virtual unsigned int getPriority() const
Higher number is higher priority (0 being the lowest)
Definition: aipackage.hpp:70
bool shortcutPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::Ptr &actor, bool *destInLOS)
Definition: aipackage.cpp:194
AiPackage()
Default constructor.
Definition: aipackage.cpp:26
virtual void fastForward(const MWWorld::Ptr &actor, AiState &state)
Simulates the passing of time.
Definition: aipackage.hpp:75
virtual bool shouldCancelPreviousAi() const
Upon adding this Ai package, should the Ai Sequence attempt to cancel previous Ai packages (default t...
Definition: aipackage.cpp:54
Definition: aipackage.hpp:40