1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 06:19:55 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/pathfinding.hpp

105 lines
3.3 KiB
C++
Raw Normal View History

2013-03-31 17:30:03 +00:00
#ifndef GAME_MWMECHANICS_PATHFINDING_H
#define GAME_MWMECHANICS_PATHFINDING_H
#include <components/esm/defs.hpp>
2013-03-31 17:30:03 +00:00
#include <components/esm/loadpgrd.hpp>
#include <list>
namespace MWWorld
{
class CellStore;
}
2013-03-31 17:30:03 +00:00
namespace MWMechanics
{
float distance(ESM::Pathgrid::Point point, float x, float y, float);
float distance(ESM::Pathgrid::Point a, ESM::Pathgrid::Point b);
2013-03-31 17:30:03 +00:00
class PathFinder
{
public:
PathFinder();
2013-03-31 17:30:03 +00:00
static const int PathTolerance = 32;
2015-06-03 19:37:21 +00:00
static float sgn(float val)
{
2015-06-03 19:37:21 +00:00
if(val > 0)
return 1.0;
return -1.0;
}
static int sgn(int a)
{
if(a > 0)
return 1;
return -1;
}
void clearPath();
bool checkPathCompleted(float x, float y, float tolerance = PathTolerance);
///< \Returns true if we are within \a tolerance units of the last path point.
2014-01-29 19:29:07 +00:00
/// In radians
2013-08-30 02:17:27 +00:00
float getZAngleToNext(float x, float y) const;
2013-03-31 17:30:03 +00:00
2013-08-30 02:17:27 +00:00
bool isPathConstructed() const
{
return !mPath.empty();
2013-08-30 02:17:27 +00:00
}
2013-03-31 17:30:03 +00:00
2013-10-07 08:20:02 +00:00
int getPathSize() const
{
return mPath.size();
}
2014-05-01 07:41:25 +00:00
const std::list<ESM::Pathgrid::Point>& getPath() const
2013-10-07 08:20:02 +00:00
{
return mPath;
}
2014-04-20 16:35:07 +00:00
/** Synchronize new path with old one to avoid visiting 1 waypoint 2 times
@note
BuildPath() takes closest PathGrid point to NPC as first point of path.
This is undesireable if NPC has just passed a Pathgrid point, as this
makes the 2nd point of the new path == the 1st point of old path.
Which results in NPC "running in a circle" back to the just passed waypoint.
2014-04-20 16:35:07 +00:00
*/
void buildSyncedPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const MWWorld::CellStore* cell, bool allowShortcuts = true);
2014-01-19 20:09:51 +00:00
2014-01-07 20:10:57 +00:00
void addPointToPath(ESM::Pathgrid::Point &point)
{
mPath.push_back(point);
}
2015-06-03 17:41:19 +00:00
/// utility function to convert a osg::Vec3f to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const osg::Vec3f& v)
{
return ESM::Pathgrid::Point(static_cast<int>(v[0]), static_cast<int>(v[1]), static_cast<int>(v[2]));
}
/// utility function to convert an ESM::Position to a Pathgrid::Point
static ESM::Pathgrid::Point MakePathgridPoint(const ESM::Position& p)
{
return ESM::Pathgrid::Point(static_cast<int>(p.pos[0]), static_cast<int>(p.pos[1]), static_cast<int>(p.pos[2]));
}
2015-05-02 20:45:27 +00:00
static osg::Vec3f MakeOsgVec3(const ESM::Pathgrid::Point& p)
{
return osg::Vec3f(static_cast<float>(p.mX), static_cast<float>(p.mY), static_cast<float>(p.mZ));
}
private:
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const MWWorld::CellStore* cell, bool allowShortcuts = true);
2014-01-26 20:53:55 +00:00
std::list<ESM::Pathgrid::Point> mPath;
const ESM::Pathgrid *mPathgrid;
const MWWorld::CellStore* mCell;
2013-03-31 17:30:03 +00:00
};
}
#endif