OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
obstacle.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MECHANICS_OBSTACLE_H
2 #define OPENMW_MECHANICS_OBSTACLE_H
3 
4 namespace MWWorld
5 {
6  class Ptr;
7 }
8 
9 namespace MWMechanics
10 {
11  struct Movement;
12 
14  static const float MIN_DIST_TO_DOOR_SQUARED = 128*128;
15 
16  static const int NUM_EVADE_DIRECTIONS = 4;
17 
19  bool proximityToDoor(const MWWorld::Ptr& actor,
20  float minSqr = MIN_DIST_TO_DOOR_SQUARED);
21 
23 
25  float minSqr = MIN_DIST_TO_DOOR_SQUARED);
26 
28  {
29  public:
30  ObstacleCheck();
31 
32  // Clear the timers and set the state machine to default
33  void clear();
34 
35  bool isNormalState() const;
36  bool isEvading() const;
37 
38  // Returns true if there is an obstacle and an evasive action
39  // should be taken
40  bool check(const MWWorld::Ptr& actor, float duration, float scaleMinimumDistance = 1.0f);
41 
42  // change direction to try to fix "stuck" actor
43  void takeEvasiveAction(MWMechanics::Movement& actorMovement);
44 
45  private:
46 
47  // for checking if we're stuck (ignoring Z axis)
48  float mPrevX;
49  float mPrevY;
50 
51  // directions to try moving in when get stuck
52  static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
53 
54  enum WalkState
55  {
59  };
61 
62  float mStuckDuration; // accumulate time here while in same spot
64  float mDistSameSpot; // take account of actor's speed
66 
68  };
69 }
70 
71 #endif
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2]
Definition: obstacle.hpp:52
bool isEvading() const
Definition: obstacle.cpp:96
WalkState
Definition: obstacle.hpp:54
float mPrevY
Definition: obstacle.hpp:49
Definition: obstacle.hpp:56
Definition: obstacle.hpp:27
static const int NUM_EVADE_DIRECTIONS
Definition: obstacle.hpp:16
void chooseEvasionDirection()
Definition: obstacle.cpp:195
void clear()
Definition: obstacle.cpp:84
ObstacleCheck()
Definition: obstacle.cpp:73
Desired movement for an actor.
Definition: movement.hpp:9
bool check(const MWWorld::Ptr &actor, float duration, float scaleMinimumDistance=1.0f)
Definition: obstacle.cpp:123
Definition: obstacle.hpp:58
float mEvadeDuration
Definition: obstacle.hpp:63
float mStuckDuration
Definition: obstacle.hpp:62
bool isNormalState() const
Definition: obstacle.cpp:91
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr &actor, float minSqr)
Returns door pointer within range. No guarantee is given as to which one.
Definition: obstacle.cpp:39
bool proximityToDoor(const MWWorld::Ptr &actor, float minSqr)
tests actor's proximity to a closed door by default
Definition: obstacle.cpp:31
int mEvadeDirectionIndex
Definition: obstacle.hpp:65
float mPrevX
Definition: obstacle.hpp:48
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
WalkState mWalkState
Definition: obstacle.hpp:60
static const float MIN_DIST_TO_DOOR_SQUARED
NOTE: determined empirically based on in-game behaviour.
Definition: obstacle.hpp:14
void takeEvasiveAction(MWMechanics::Movement &actorMovement)
Definition: obstacle.cpp:189
float mDistSameSpot
Definition: obstacle.hpp:64