1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00
OpenMW/apps/openmw/mwmechanics/pathfinding.hpp

94 lines
2.5 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/loadpgrd.hpp>
#include <list>
#include <OgreMath.h>
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 float sgn(Ogre::Radian a)
{
if(a.valueRadians() > 0)
return 1.0;
return -1.0;
}
static float sgn(float a)
{
if(a > 0)
return 1.0;
return -1.0;
}
void clearPath();
2013-08-30 02:17:27 +00:00
void buildPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint,
const MWWorld::CellStore* cell, bool allowShortcuts = true);
2013-03-31 17:30:03 +00:00
bool checkPathCompleted(float x, float y, float z);
///< \Returns true if the last point of the path has been reached.
2014-01-29 19:29:07 +00:00
2013-10-07 08:20:02 +00:00
bool checkWaypoint(float x, float y, float z);
///< \Returns true if a way point was reached
2014-01-29 19:29:07 +00:00
2013-08-30 02:17:27 +00:00
float getZAngleToNext(float x, float y) const;
2013-03-31 17:30:03 +00:00
2014-01-23 21:14:20 +00:00
float getDistToNext(float x, float y, float z);
2013-08-30 02:17:27 +00:00
bool isPathConstructed() const
{
return mIsPathConstructed;
}
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
If the first point is chosen as the nearest one
the situation can occur when the 1st point of the new path is undesirable
2014-04-20 16:35:07 +00:00
(i.e. the 2nd point of new path == the 1st point of old path).
@param path - old path
@return true if such point was found and deleted
*/
bool syncStart(const std::list<ESM::Pathgrid::Point> &path);
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);
}
private:
2014-01-26 20:53:55 +00:00
bool mIsPathConstructed;
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