2014-04-18 09:03:36 +10:00
|
|
|
#ifndef OPENMW_MECHANICS_OBSTACLE_H
|
2014-04-18 16:45:31 +10:00
|
|
|
#define OPENMW_MECHANICS_OBSTACLE_H
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2019-08-17 17:57:28 +02:00
|
|
|
#include <osg/Vec3f>
|
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2015-08-30 10:06:09 +12:00
|
|
|
struct Movement;
|
|
|
|
|
2015-09-19 16:14:00 +12:00
|
|
|
static const int NUM_EVADE_DIRECTIONS = 4;
|
|
|
|
|
2014-05-13 03:58:32 -04:00
|
|
|
/// tests actor's proximity to a closed door by default
|
2017-06-14 12:44:18 +04:00
|
|
|
bool proximityToDoor(const MWWorld::Ptr& actor, float minDist);
|
2014-05-13 03:58:32 -04:00
|
|
|
|
2016-12-14 16:39:33 +01:00
|
|
|
/// Returns door pointer within range. No guarantee is given as to which one
|
2018-10-09 10:21:12 +04:00
|
|
|
/** \return Pointer to the door, or empty pointer if none exists **/
|
2017-12-01 10:07:02 +04:00
|
|
|
const MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minDist);
|
2014-04-18 09:03:36 +10:00
|
|
|
|
|
|
|
class ObstacleCheck
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObstacleCheck();
|
|
|
|
|
|
|
|
// Clear the timers and set the state machine to default
|
|
|
|
void clear();
|
|
|
|
|
2016-08-19 22:15:26 +03:00
|
|
|
bool isEvading() const;
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2018-08-18 18:26:00 +03:00
|
|
|
// Updates internal state, call each frame for moving actor
|
2020-01-20 22:08:25 +01:00
|
|
|
void update(const MWWorld::Ptr& actor, const osg::Vec3f& destination, float duration);
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2015-08-30 10:06:09 +12:00
|
|
|
// change direction to try to fix "stuck" actor
|
2018-08-18 23:17:52 +03:00
|
|
|
void takeEvasiveAction(MWMechanics::Movement& actorMovement) const;
|
2015-08-30 10:06:09 +12:00
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
private:
|
2019-08-17 17:57:28 +02:00
|
|
|
osg::Vec3f mPrev;
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2015-09-19 16:14:00 +12:00
|
|
|
// directions to try moving in when get stuck
|
|
|
|
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
|
|
|
|
2020-01-20 22:08:25 +01:00
|
|
|
enum class WalkState
|
2014-04-18 09:03:36 +10:00
|
|
|
{
|
2020-01-20 22:08:25 +01:00
|
|
|
Initial,
|
|
|
|
Norm,
|
|
|
|
CheckStuck,
|
|
|
|
Evade
|
2014-04-18 09:03:36 +10:00
|
|
|
};
|
|
|
|
WalkState mWalkState;
|
|
|
|
|
2020-01-20 22:08:25 +01:00
|
|
|
float mStateDuration;
|
2015-09-19 16:14:00 +12:00
|
|
|
int mEvadeDirectionIndex;
|
2020-02-06 00:20:55 +01:00
|
|
|
float mInitialDistance = 0;
|
2015-08-30 10:06:09 +12:00
|
|
|
|
2015-11-09 20:26:18 +01:00
|
|
|
void chooseEvasionDirection();
|
2014-04-18 09:03:36 +10:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|