2014-04-17 23:03:36 +00:00
|
|
|
#ifndef OPENMW_MECHANICS_OBSTACLE_H
|
2014-04-18 06:45:31 +00:00
|
|
|
#define OPENMW_MECHANICS_OBSTACLE_H
|
2014-04-17 23:03:36 +00:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2015-08-29 22:06:09 +00:00
|
|
|
struct Movement;
|
|
|
|
|
2014-05-13 07:58:32 +00:00
|
|
|
/// NOTE: determined empirically based on in-game behaviour
|
2014-04-17 23:03:36 +00:00
|
|
|
static const float MIN_DIST_TO_DOOR_SQUARED = 128*128;
|
|
|
|
|
2015-09-19 04:14:00 +00:00
|
|
|
static const int NUM_EVADE_DIRECTIONS = 4;
|
|
|
|
|
2014-05-13 07:58:32 +00:00
|
|
|
/// tests actor's proximity to a closed door by default
|
2014-04-17 23:03:36 +00:00
|
|
|
bool proximityToDoor(const MWWorld::Ptr& actor,
|
2015-11-11 23:58:29 +00:00
|
|
|
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
2014-05-13 07:58:32 +00:00
|
|
|
|
2016-12-14 15:39:33 +00:00
|
|
|
/// Returns door pointer within range. No guarantee is given as to which one
|
2014-05-13 07:58:32 +00:00
|
|
|
/** \return Pointer to the door, or NULL if none exists **/
|
2014-05-14 03:46:00 +00:00
|
|
|
MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor,
|
2015-11-11 23:58:29 +00:00
|
|
|
float minSqr = MIN_DIST_TO_DOOR_SQUARED);
|
2014-04-17 23:03:36 +00:00
|
|
|
|
|
|
|
class ObstacleCheck
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObstacleCheck();
|
|
|
|
|
|
|
|
// Clear the timers and set the state machine to default
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
bool isNormalState() const;
|
2016-08-19 19:15:26 +00:00
|
|
|
bool isEvading() const;
|
2014-04-17 23:03:36 +00:00
|
|
|
|
|
|
|
// Returns true if there is an obstacle and an evasive action
|
|
|
|
// should be taken
|
2016-04-16 17:14:00 +00:00
|
|
|
bool check(const MWWorld::Ptr& actor, float duration, float scaleMinimumDistance = 1.0f);
|
2014-04-17 23:03:36 +00:00
|
|
|
|
2015-08-29 22:06:09 +00:00
|
|
|
// change direction to try to fix "stuck" actor
|
|
|
|
void takeEvasiveAction(MWMechanics::Movement& actorMovement);
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// for checking if we're stuck (ignoring Z axis)
|
|
|
|
float mPrevX;
|
|
|
|
float mPrevY;
|
|
|
|
|
2015-09-19 04:14:00 +00:00
|
|
|
// directions to try moving in when get stuck
|
|
|
|
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
enum WalkState
|
|
|
|
{
|
|
|
|
State_Norm,
|
|
|
|
State_CheckStuck,
|
|
|
|
State_Evade
|
|
|
|
};
|
|
|
|
WalkState mWalkState;
|
|
|
|
|
|
|
|
float mStuckDuration; // accumulate time here while in same spot
|
|
|
|
float mEvadeDuration;
|
|
|
|
float mDistSameSpot; // take account of actor's speed
|
2015-09-19 04:14:00 +00:00
|
|
|
int mEvadeDirectionIndex;
|
2015-08-29 22:06:09 +00:00
|
|
|
|
2015-11-09 19:26:18 +00:00
|
|
|
void chooseEvasionDirection();
|
2014-04-17 23:03:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|