1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00
OpenMW/apps/openmw/mwmechanics/obstacle.hpp
elsid b92d80249e
Adjust initial distance when destination is changed for obstacle check
Changed destination may create a situation when the distance actor moved between
2 update calls is less than initial distance because destination has been changed.
This forces actor to take evasive action when there is no actual obstacle.
2022-09-28 22:01:29 +02:00

71 lines
1.8 KiB
C++

#ifndef OPENMW_MECHANICS_OBSTACLE_H
#define OPENMW_MECHANICS_OBSTACLE_H
#include <osg/Vec3f>
#include <vector>
namespace MWWorld
{
class Ptr;
class ConstPtr;
}
namespace MWMechanics
{
struct Movement;
static constexpr int NUM_EVADE_DIRECTIONS = 4;
/// tests actor's proximity to a closed door by default
bool proximityToDoor(const MWWorld::Ptr& actor, float minDist);
/// Returns door pointer within range. No guarantee is given as to which one
/** \return Pointer to the door, or empty pointer if none exists **/
const MWWorld::Ptr getNearbyDoor(const MWWorld::Ptr& actor, float minDist);
bool isAreaOccupiedByOtherActor(const MWWorld::ConstPtr& actor, const osg::Vec3f& destination,
bool ignorePlayer = false, std::vector<MWWorld::Ptr>* occupyingActors = nullptr);
class ObstacleCheck
{
public:
ObstacleCheck();
// Clear the timers and set the state machine to default
void clear();
bool isEvading() const;
// Updates internal state, call each frame for moving actor
void update(const MWWorld::Ptr& actor, const osg::Vec3f& destination, float duration);
// change direction to try to fix "stuck" actor
void takeEvasiveAction(MWMechanics::Movement& actorMovement) const;
private:
osg::Vec3f mPrev;
osg::Vec3f mDestination;
// directions to try moving in when get stuck
static const float evadeDirections[NUM_EVADE_DIRECTIONS][2];
enum class WalkState
{
Initial,
Norm,
CheckStuck,
Evade
};
WalkState mWalkState;
float mStateDuration;
int mEvadeDirectionIndex;
float mInitialDistance = 0;
void chooseEvasionDirection();
};
}
#endif