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
|
|
|
|
2019-08-17 15:57:28 +00:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2015-08-29 22:06:09 +00:00
|
|
|
struct Movement;
|
|
|
|
|
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
|
2017-06-14 08:44:18 +00:00
|
|
|
bool proximityToDoor(const MWWorld::Ptr& actor, float minDist);
|
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
|
2018-10-09 06:21:12 +00:00
|
|
|
/** \return Pointer to the door, or empty pointer if none exists **/
|
2017-12-01 06:07:02 +00:00
|
|
|
const MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minDist);
|
2014-04-17 23:03:36 +00:00
|
|
|
|
|
|
|
class ObstacleCheck
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObstacleCheck();
|
|
|
|
|
|
|
|
// Clear the timers and set the state machine to default
|
|
|
|
void clear();
|
|
|
|
|
2016-08-19 19:15:26 +00:00
|
|
|
bool isEvading() const;
|
2014-04-17 23:03:36 +00:00
|
|
|
|
2018-08-18 15:26:00 +00:00
|
|
|
// Updates internal state, call each frame for moving actor
|
2020-01-20 21:08:25 +00:00
|
|
|
void update(const MWWorld::Ptr& actor, const osg::Vec3f& destination, float duration);
|
2014-04-17 23:03:36 +00:00
|
|
|
|
2015-08-29 22:06:09 +00:00
|
|
|
// change direction to try to fix "stuck" actor
|
2018-08-18 20:17:52 +00:00
|
|
|
void takeEvasiveAction(MWMechanics::Movement& actorMovement) const;
|
2015-08-29 22:06:09 +00:00
|
|
|
|
2014-04-17 23:03:36 +00:00
|
|
|
private:
|
2019-08-17 15:57:28 +00:00
|
|
|
osg::Vec3f mPrev;
|
2014-04-17 23:03:36 +00:00
|
|
|
|
2015-09-19 04:14:00 +00:00
|
|
|
// directions to try moving in when get stuck
|
|
|
|
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
|
|
|
|
2020-01-20 21:08:25 +00:00
|
|
|
enum class WalkState
|
2014-04-17 23:03:36 +00:00
|
|
|
{
|
2020-01-20 21:08:25 +00:00
|
|
|
Initial,
|
|
|
|
Norm,
|
|
|
|
CheckStuck,
|
|
|
|
Evade
|
2014-04-17 23:03:36 +00:00
|
|
|
};
|
|
|
|
WalkState mWalkState;
|
|
|
|
|
2020-01-20 21:08:25 +00:00
|
|
|
float mStateDuration;
|
2015-09-19 04:14:00 +00:00
|
|
|
int mEvadeDirectionIndex;
|
2020-02-05 23:20:55 +00:00
|
|
|
float mInitialDistance = 0;
|
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
|