18 #ifndef INCLUDED_PATHFINDING 19 #define INCLUDED_PATHFINDING 56 : data(hv * 65536 + d * 92682)
101 #define IS_PASSABLE(item, classmask) (((item) & (classmask)) == 0) 102 #define PASS_CLASS_MASK_FROM_INDEX(id) ((pass_class_t)(1u << id)) 103 #define SPECIAL_PASS_CLASS PASS_CLASS_MASK_FROM_INDEX((PASS_CLASS_BITS-1)) // 16th bit, used for special in-place computations 148 i = (
u16)
clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1);
149 j = (
u16)
clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1);
194 int di = (i0 < i1 ? +1 : i1 < i0 ? -1 : 0);
195 int dj = (j0 < j1 ? +1 : j1 < j0 ? -1 : 0);
200 bool currentlyOnImpassable = !
IS_PASSABLE(grid.
get(i0, j0), passClass);
206 ((di > 0 && i0 <= i && i <= i1) || (di < 0 && i1 <= i && i <= i0) || (di == 0 && i == i0)) &&
207 ((dj > 0 && j0 <= j && j <= j1) || (dj < 0 && j1 <= j && j <= j0) || (dj == 0 && j == j0)));
212 currentlyOnImpassable =
false;
213 else if (!currentlyOnImpassable)
217 if (i == i1 && j == j1)
222 if (di == 0 || i == i1)
227 else if (dj == 0 || j == j1)
296 m_MinDepth = std::numeric_limits<fixed>::min();
301 m_MaxDepth = std::numeric_limits<fixed>::max();
306 m_MaxSlope = std::numeric_limits<fixed>::max();
311 m_MinShore = std::numeric_limits<fixed>::min();
316 m_MaxShore = std::numeric_limits<fixed>::max();
343 if (obstructions == L
"none")
344 m_Obstructions = NONE;
345 else if (obstructions == L
"pathfinding")
346 m_Obstructions = PATHFINDING;
347 else if (obstructions == L
"foundation")
348 m_Obstructions = FOUNDATION;
351 LOGERROR(
"Invalid value for Obstructions in pathfinder.xml for pass class %d", mask);
352 m_Obstructions = NONE;
356 m_Obstructions = NONE;
361 return ((m_MinDepth <= waterdepth && waterdepth <= m_MaxDepth) && (steepness < m_MaxSlope) && (m_MinShore <= shoredist && shoredist <= m_MaxShore));
384 #endif // INCLUDED_PATHFINDING An entity initialisation parameter node.
Definition: ParamNode.h:148
A simple fixed-point number class.
Definition: Fixed.h:115
#define LOGERROR(...)
Definition: CLogger.h:36
Definition: FixedVector2D.h:24
u16 pass_class_t
Definition: Pathfinding.h:29
const entity_pos_t CLEARANCE_EXTENSION_RADIUS
To make sure the long-range pathfinder is more strict than the short-range one, we need to slightly o...
Definition: Pathfinding.h:139
static CFixed Zero()
Definition: Fixed.h:127
Definition: Pathfinding.h:105
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
Definition: Terrain.h:40
const std::wstring & ToString() const
Returns the content of this node as a string.
Definition: ParamNode.cpp:237
Definition: Pathfinding.h:287
Returned path.
Definition: Pathfinding.h:40
static PathCost diag(u16 n)
Construct for diagonal movement of given number of steps.
Definition: Pathfinding.h:67
Definition: Pathfinding.h:371
uint16_t u16
Definition: types.h:38
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
Definition: ParamNode.cpp:232
bool operator>=(const PathCost &b) const
Definition: Pathfinding.h:87
u16 m_H
Definition: Grid.h:125
fixed m_MaxSlope
Definition: Pathfinding.h:379
bool operator>(const PathCost &b) const
Definition: Pathfinding.h:88
#define IS_PASSABLE(item, classmask)
Definition: Pathfinding.h:101
PathfinderPassability(pass_class_t mask, const CParamNode &node)
Definition: Pathfinding.h:290
std::vector< Waypoint > m_Waypoints
Definition: Pathfinding.h:42
Definition: Pathfinding.h:31
static PathCost horizvert(u16 n)
Construct for horizontal/vertical movement of given number of steps.
Definition: Pathfinding.h:61
const fixed NAVCELL_SIZE
Size of a navcell in metres ( = TERRAIN_TILE_SIZE / NAVCELLS_PER_TILE)
Definition: Pathfinding.h:122
PathCost operator+(const PathCost &a) const
Definition: Pathfinding.h:72
fixed m_MaxShore
Definition: Pathfinding.h:381
ObstructionHandling m_Obstructions
Definition: Pathfinding.h:374
entity_pos_t z
Definition: Pathfinding.h:33
fixed ToFixed() const
Parses the content of this node as a fixed-point number.
Definition: ParamNode.cpp:261
void NavcellCenter(u16 i, u16 j, entity_pos_t &x, entity_pos_t &z)
Definition: Pathfinding.h:162
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:287
uint32_t u32
Definition: types.h:39
const int NAVCELLS_PER_TILE
The long-range pathfinder operates primarily over a navigation grid (a uniform-cost 2D passability gr...
Definition: Pathfinding.h:117
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:224
ObstructionHandling
Definition: Pathfinding.h:368
fixed m_Clearance
Definition: Pathfinding.h:366
CFixed Multiply(CFixed n) const
Multiply by a CFixed.
Definition: Fixed.h:311
CFixedVector2D Perpendicular() const
Definition: FixedVector2D.h:215
PathCost & operator+=(const PathCost &a)
Definition: Pathfinding.h:79
fixed m_MinShore
Definition: Pathfinding.h:380
bool CheckLineMovement(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, pass_class_t passClass, const Grid< NavcellData > &grid)
Definition: Pathfinding.h:171
const int NAVCELL_SIZE_LOG2
Definition: Pathfinding.h:124
static const int PASS_CLASS_BITS
Definition: Pathfinding.h:99
pass_class_t m_Mask
Definition: Pathfinding.h:364
static CFixed FromInt(int n)
Definition: Fixed.h:136
u16 NavcellData
Definition: Pathfinding.h:100
void TileCenter(u16 i, u16 j, entity_pos_t &x, entity_pos_t &z)
Returns the position of the center of the given tile.
Definition: Pathfinding.h:155
T & get(int i, int j) const
Definition: Grid.h:117
bool IsPassable(fixed waterdepth, fixed steepness, fixed shoredist)
Definition: Pathfinding.h:359
bool operator<=(const PathCost &b) const
Definition: Pathfinding.h:85
PathCost()
Definition: Pathfinding.h:52
u32 data
Definition: Pathfinding.h:96
void NearestNavcell(entity_pos_t x, entity_pos_t z, u16 &i, u16 &j, u16 w, u16 h)
Compute the navcell indexes on the grid nearest to a given point w, h are the grid dimensions...
Definition: Pathfinding.h:145
fixed m_MaxDepth
Definition: Pathfinding.h:378
const int NAVCELL_SIZE_INT
Definition: Pathfinding.h:123
u32 ToInt()
Definition: Pathfinding.h:90
entity_pos_t x
Definition: Pathfinding.h:33
u16 m_W
Definition: Grid.h:125
#define cassert(expr)
Compile-time assertion.
Definition: code_annotation.h:197
Definition: Pathfinding.h:370
Represents the cost of a path consisting of horizontal/vertical and diagonal movements over a uniform...
Definition: Pathfinding.h:50
const entity_pos_t GOAL_DELTA
For extending the goal outwards/inwards a little bit NOTE: keep next to the definition of NAVCELL_SIZ...
Definition: Pathfinding.h:133
fixed m_MinDepth
Definition: Pathfinding.h:377
PathCost(u16 hv, u16 d)
Construct from a number of horizontal/vertical and diagonal steps.
Definition: Pathfinding.h:55
T clamp(T value, T min, T max)
Definition: MathUtil.h:32
bool operator<(const FCDJointWeightPair &a, const FCDJointWeightPair &b)
Definition: GeomReindex.cpp:64