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>
|
|
|
|
|
2021-09-29 00:42:29 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
class Ptr;
|
2021-09-29 00:42:29 +02:00
|
|
|
class ConstPtr;
|
2014-04-18 09:03:36 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
2015-08-30 10:06:09 +12:00
|
|
|
struct Movement;
|
|
|
|
|
2021-03-21 13:56:56 +01:00
|
|
|
static constexpr int NUM_EVADE_DIRECTIONS = 4;
|
2015-09-19 16:14:00 +12:00
|
|
|
|
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
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& destination,
|
|
|
|
bool ignorePlayer = false, std::vector<MWWorld::Ptr>* occupyingActors = nullptr);
|
2021-09-29 00:42:29 +02:00
|
|
|
|
2014-04-18 09:03:36 +10:00
|
|
|
class ObstacleCheck
|
|
|
|
{
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
|
|
|
ObstacleCheck();
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// Clear the timers and set the state machine to default
|
|
|
|
void clear();
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
bool isEvading() const;
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// Updates internal state, call each frame for moving actor
|
|
|
|
void update(const MWWorld::Ptr& actor, const osg::Vec3f& destination, float duration);
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// change direction to try to fix "stuck" actor
|
|
|
|
void takeEvasiveAction(MWMechanics::Movement& actorMovement) const;
|
2015-08-30 10:06:09 +12:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
private:
|
|
|
|
osg::Vec3f mPrev;
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
// directions to try moving in when get stuck
|
|
|
|
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
|
2015-09-19 16:14:00 +12:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
enum class WalkState
|
|
|
|
{
|
|
|
|
Initial,
|
|
|
|
Norm,
|
|
|
|
CheckStuck,
|
|
|
|
Evade
|
|
|
|
};
|
|
|
|
WalkState mWalkState;
|
2014-04-18 09:03:36 +10:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
float mStateDuration;
|
|
|
|
int mEvadeDirectionIndex;
|
|
|
|
float mInitialDistance = 0;
|
2015-08-30 10:06:09 +12:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
void chooseEvasionDirection();
|
2014-04-18 09:03:36 +10:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|