Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ICmpObstructionManager.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_ICMPOBSTRUCTIONMANAGER
19#define INCLUDED_ICMPOBSTRUCTIONMANAGER
20
21#include "lib/debug.h"
22#include "maths/Fixed.h"
23#include "maths/FixedVector2D.h"
28
29#include <js/Value.h>
30#include <vector>
31
35template<typename T> class Grid;
36
37using NavcellData = std::uint16_t;
38
39/**
40 * Obstruction manager: provides efficient spatial queries over objects in the world.
41 *
42 * The class deals with two types of shape:
43 * "static" shapes, typically representing buildings, which are rectangles with a given
44 * width and height and angle;
45 * and "unit" shapes, representing units that can move around the world, which have a
46 * radius and no rotation. (Units sometimes act as axis-aligned squares, sometimes
47 * as approximately circles, due to the algorithm used by the short pathfinder.)
48 *
49 * Other classes (particularly ICmpObstruction) register shapes with this interface
50 * and keep them updated.
51 *
52 * The @c Test functions provide exact collision tests.
53 * The edge of a shape counts as 'inside' the shape, for the purpose of collisions.
54 * The functions accept an IObstructionTestFilter argument, which can restrict the
55 * set of shapes that are counted as collisions.
56 *
57 * Units can be marked as either moving or stationary, which simply determines whether
58 * certain filters include or exclude them.
59 *
60 * The @c Rasterize function approximates the current set of shapes onto a 2D grid,
61 * for use with tile-based pathfinding.
62 */
64{
65public:
66 /**
67 * Standard representation for all types of shapes, for use with geometry processing code.
68 */
70 {
71 entity_pos_t x, z; // position of center
72 CFixedVector2D u, v; // 'horizontal' and 'vertical' orthogonal unit vectors, representing orientation
73 entity_pos_t hw, hh; // half width, half height of square
74 };
75
76 /**
77 * External identifiers for shapes.
78 * (This is a struct rather than a raw std::uint32_t for type-safety.)
79 */
80 struct tag_t
81 {
82 tag_t() : n(0) {}
83 explicit tag_t(std::uint32_t n) : n(n) {}
84 bool valid() const { return n != 0; }
85
86 std::uint32_t n;
87 };
88
89 /**
90 * Boolean flags affecting the obstruction behaviour of a shape.
91 */
92 enum EFlags
93 {
94 FLAG_BLOCK_MOVEMENT = (1 << 0), // prevents units moving through this shape
95 FLAG_BLOCK_FOUNDATION = (1 << 1), // prevents foundations being placed on this shape
96 FLAG_BLOCK_CONSTRUCTION = (1 << 2), // prevents buildings being constructed on this shape
97 FLAG_BLOCK_PATHFINDING = (1 << 3), // prevents the tile pathfinder choosing paths through this shape
98 FLAG_MOVING = (1 << 4), // reserved for unitMotion - see usage there.
99 FLAG_DELETE_UPON_CONSTRUCTION = (1 << 5) // this entity is deleted when construction of a building placed on top of this entity starts
100 };
101
102 /**
103 * Bitmask of EFlag values.
104 */
105 typedef std::uint8_t flags_t;
106
107 /**
108 * Set the bounds of the world.
109 * Any point outside the bounds is considered obstructed.
110 * @param x0,z0,x1,z1 Coordinates of the corners of the world
111 */
113
114 /**
115 * Register a static shape.
116 *
117 * @param ent entity ID associated with this shape (or INVALID_ENTITY if none)
118 * @param x,z coordinates of center, in world space
119 * @param a angle of rotation (clockwise from +Z direction)
120 * @param w width (size along X axis)
121 * @param h height (size along Z axis)
122 * @param flags a set of EFlags values
123 * @param group primary control group of the shape. Must be a valid control group ID.
124 * @param group2 Optional; secondary control group of the shape. Defaults to INVALID_ENTITY.
125 * @return a valid tag for manipulating the shape
126 * @see StaticShape
127 */
129 entity_pos_t w, entity_pos_t h, flags_t flags, entity_id_t group, entity_id_t group2 = INVALID_ENTITY) = 0;
130
131 /**
132 * Register a unit shape.
133 *
134 * @param ent entity ID associated with this shape (or INVALID_ENTITY if none)
135 * @param x,z coordinates of center, in world space
136 * @param clearance pathfinding clearance of the unit (works as a radius)
137 * @param flags a set of EFlags values
138 * @param group control group (typically the owner entity, or a formation controller entity
139 * - units ignore collisions with others in the same group)
140 * @return a valid tag for manipulating the shape
141 * @see UnitShape
142 */
144 flags_t flags, entity_id_t group) = 0;
145
146 /**
147 * Adjust the position and angle of an existing shape.
148 * @param tag tag of shape (must be valid)
149 * @param x X coordinate of center, in world space
150 * @param z Z coordinate of center, in world space
151 * @param a angle of rotation (clockwise from +Z direction); ignored for unit shapes
152 */
154
155 /**
156 * Set whether a unit shape is moving or stationary.
157 * @param tag tag of shape (must be valid and a unit shape)
158 * @param moving whether the unit is currently moving through the world or is stationary
159 */
160 virtual void SetUnitMovingFlag(tag_t tag, bool moving) = 0;
161
162 /**
163 * Set the control group of a unit shape.
164 * @param tag tag of shape (must be valid and a unit shape)
165 * @param group control group entity ID
166 */
167 virtual void SetUnitControlGroup(tag_t tag, entity_id_t group) = 0;
168
169 /**
170 * Sets the control group of a static shape.
171 * @param tag Tag of the shape to set the control group for. Must be a valid and static shape tag.
172 * @param group Control group entity ID.
173 */
174 virtual void SetStaticControlGroup(tag_t tag, entity_id_t group, entity_id_t group2) = 0;
175
176 /**
177 * Remove an existing shape. The tag will be made invalid and must not be used after this.
178 * @param tag tag of shape (must be valid)
179 */
180 virtual void RemoveShape(tag_t tag) = 0;
181
182 /**
183 * Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the world.
184 */
186
187 /**
188 * Calculate the largest straight line distance between the entity and the point.
189 */
191
192 /**
193 * Calculate the shortest distance between the entity and the target.
194 */
195 virtual fixed DistanceToTarget(entity_id_t ent, entity_id_t target) const = 0;
196
197 /**
198 * Calculate the largest straight line distance between the entity and the target.
199 */
200 virtual fixed MaxDistanceToTarget(entity_id_t ent, entity_id_t target) const = 0;
201
202 /**
203 * Calculate the shortest straight line distance between the source and the target
204 */
205 virtual fixed DistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const = 0;
206
207 /**
208 * Calculate the largest straight line distance between the source and the target
209 */
210 virtual fixed MaxDistanceBetweenShapes(const ObstructionSquare& source, const ObstructionSquare& target) const = 0;
211
212 /**
213 * Check if the given entity is in range of the other point given those parameters.
214 * @param maxRange - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE.
215 */
216 virtual bool IsInPointRange(entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const = 0;
217
218 /**
219 * Check if the given entity is in range of the target given those parameters.
220 * @param maxRange - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE.
221 */
222 virtual bool IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const = 0;
223
224 /**
225 * Check if the given entity is in parabolic range of the target given those parameters.
226 * @param maxRange - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE.
227 */
228 virtual bool IsInTargetParabolicRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t yOrigin, bool opposite) const = 0;
229
230 /**
231 * Check if the given point is in range of the other point given those parameters.
232 * @param maxRange - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE.
233 */
234 virtual bool IsPointInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const = 0;
235
236 /**
237 * Check if the given shape is in range of the target shape given those parameters.
238 * @param maxRange - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE.
239 */
240 virtual bool AreShapesInRange(const ObstructionSquare& source, const ObstructionSquare& target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const = 0;
241
242 /**
243 * Collision test a flat-ended thick line against the current set of shapes.
244 * The line caps extend by @p r beyond the end points.
245 * Only intersections going from outside to inside a shape are counted.
246 * @param filter filter to restrict the shapes that are counted
247 * @param x0 X coordinate of line's first point
248 * @param z0 Z coordinate of line's first point
249 * @param x1 X coordinate of line's second point
250 * @param z1 Z coordinate of line's second point
251 * @param r radius (half width) of line
252 * @param relaxClearanceForUnits whether unit-unit collisions should be more permissive.
253 * @return true if there is a collision
254 */
255 virtual bool TestLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, bool relaxClearanceForUnits) const = 0;
256
257 virtual bool TestUnitLine(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, bool relaxClearanceForUnits) const = 0;
258
259 /**
260 * Collision test a static square shape against the current set of shapes.
261 * @param filter filter to restrict the shapes that are being tested against
262 * @param x X coordinate of center
263 * @param z Z coordinate of center
264 * @param a angle of rotation (clockwise from +Z direction)
265 * @param w width (size along X axis)
266 * @param h height (size along Z axis)
267 * @param out if non-NULL, all colliding shapes' entities will be added to this list
268 * @return true if there is a collision
269 */
270 virtual bool TestStaticShape(const IObstructionTestFilter& filter,
272 std::vector<entity_id_t>* out) const = 0;
273
274 /**
275 * Collision test a unit shape against the current set of registered shapes, and optionally writes a list of the colliding
276 * shapes' entities to an output list.
277 *
278 * @param filter filter to restrict the shapes that are being tested against
279 * @param x X coordinate of shape's center
280 * @param z Z coordinate of shape's center
281 * @param clearance clearance of the shape's unit
282 * @param out if non-NULL, all colliding shapes' entities will be added to this list
283 *
284 * @return true if there is a collision
285 */
286 virtual bool TestUnitShape(const IObstructionTestFilter& filter,
287 entity_pos_t x, entity_pos_t z, entity_pos_t clearance,
288 std::vector<entity_id_t>* out) const = 0;
289
290 /**
291 * Convert the current set of shapes onto a navcell grid, for all passability classes contained in @p passClasses.
292 * If @p fullUpdate is false, the function will only go through dirty shapes.
293 * Shapes are expanded by the @p passClasses clearances, by ORing their masks onto the @p grid.
294 */
295 virtual void Rasterize(Grid<NavcellData>& grid, const std::vector<PathfinderPassability>& passClasses, bool fullUpdate) = 0;
296
297 /**
298 * Gets dirtiness information and resets it afterwards. Then it's the role of CCmpPathfinder
299 * to pass the information to other components if needed. (AIs, etc.)
300 * The return value is false if an update is unnecessary.
301 */
302 virtual void UpdateInformations(GridUpdateInformation& informations) = 0;
303
304 /**
305 * Find all the obstructions that are inside (or partially inside) the given range.
306 * @param filter filter to restrict the shapes that are counted
307 * @param x0 X coordinate of left edge of range
308 * @param z0 Z coordinate of bottom edge of range
309 * @param x1 X coordinate of right edge of range
310 * @param z1 Z coordinate of top edge of range
311 * @param squares output list of obstructions
312 */
313 virtual void GetObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const = 0;
314 virtual void GetStaticObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const = 0;
315 virtual void GetUnitObstructionsInRange(const IObstructionTestFilter& filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector<ObstructionSquare>& squares) const = 0;
316 virtual void GetStaticObstructionsOnObstruction(const ObstructionSquare& square, std::vector<entity_id_t>& out, const IObstructionTestFilter& filter) const = 0;
317
318 /**
319 * Returns the entity IDs of all unit shapes that intersect the given
320 * obstruction square, filtering out using the given filter.
321 * @param square the Obstruction squre we want to compare with.
322 * @param out output list of obstructions
323 * @param filter filter for the obstructing units
324 * @param strict whether to be strict in the check or more permissive (ie rasterize more or less). Default false.
325 */
326 virtual void GetUnitsOnObstruction(const ObstructionSquare& square, std::vector<entity_id_t>& out, const IObstructionTestFilter& filter, bool strict = false) const = 0;
327
328 /**
329 * Get the obstruction square representing the given shape.
330 * @param tag tag of shape (must be valid)
331 */
332 virtual ObstructionSquare GetObstruction(tag_t tag) const = 0;
333
335
337
338 /**
339 * Set the passability to be restricted to a circular map.
340 */
341 virtual void SetPassabilityCircular(bool enabled) = 0;
342
343 virtual bool GetPassabilityCircular() const = 0;
344
345 /**
346 * Toggle the rendering of debug info.
347 */
348 virtual void SetDebugOverlay(bool enabled) = 0;
349
350 DECLARE_INTERFACE_TYPE(ObstructionManager)
351};
352
353/**
354 * Interface for ICmpObstructionManager @c Test functions to filter out unwanted shapes.
355 */
357{
358public:
361
363
364 /**
365 * Return true if the shape with the specified parameters should be tested for collisions.
366 * This is called for all shapes that would collide, and also for some that wouldn't.
367 *
368 * @param tag tag of shape being tested
369 * @param flags set of EFlags for the shape
370 * @param group the control group of the shape (typically the shape's unit, or the unit's formation controller, or 0)
371 * @param group2 an optional secondary control group of the shape, or INVALID_ENTITY if none specified. Currently
372 * exists only for static shapes.
373 */
374 virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const = 0;
375};
376
377/**
378 * Obstruction test filter that will test against all shapes.
379 */
381{
382public:
383 virtual bool TestShape(tag_t, flags_t /*flags*/, entity_id_t /*group*/, entity_id_t /*group2*/) const
384 {
385 return true;
386 }
387};
388
389/**
390 * Obstruction test filter that will test only against stationary (i.e. non-moving) shapes.
391 */
393{
394public:
395 virtual bool TestShape(tag_t, flags_t flags, entity_id_t /*group*/, entity_id_t /*group2*/) const
396 {
397 return !(flags & ICmpObstructionManager::FLAG_MOVING);
398 }
399};
400
401/**
402 * Obstruction test filter that reject shapes in a given control group,
403 * and rejects shapes that don't block unit movement, and optionally rejects moving shapes.
404 */
406{
409
410public:
412 m_AvoidMoving(avoidMoving), m_Group(group)
413 {}
414
415 virtual bool TestShape(tag_t, flags_t flags, entity_id_t group, entity_id_t group2) const
416 {
417 if (group == m_Group || (group2 != INVALID_ENTITY && group2 == m_Group))
418 return false;
419
421 return false;
422
424 return false;
425
426 return true;
427 }
428};
429
430/**
431 * Obstruction test filter that will test only against shapes that:
432 * - are part of neither one of the specified control groups
433 * - AND, depending on the value of the 'exclude' argument:
434 * - have at least one of the specified flags set.
435 * - OR have none of the specified flags set.
436 *
437 * The first (primary) control group to reject shapes from must be specified and valid. The secondary
438 * control group to reject entities from may be set to INVALID_ENTITY to not use it.
439 *
440 * This filter is useful to e.g. allow foundations within the same control group to be placed and
441 * constructed arbitrarily close together (e.g. for wall pieces that need to link up tightly).
442 */
444{
449
450public:
452 m_Exclude(exclude), m_Group(group1), m_Group2(group2), m_Mask(mask)
453 {
454 Init();
455 }
456
458 m_Exclude(false), m_Group(group1), m_Group2(group2), m_Mask(mask)
459 {
460 Init();
461 }
462
463 virtual bool TestShape(tag_t, flags_t flags, entity_id_t group, entity_id_t group2) const
464 {
465 // Don't test shapes that share one or more of our control groups.
466 if (group == m_Group || group == m_Group2 || (group2 != INVALID_ENTITY &&
467 (group2 == m_Group || group2 == m_Group2)))
468 return false;
469
470 // If m_Exclude is true, don't test against shapes that have any of the
471 // obstruction flags specified in m_Mask.
472 if (m_Exclude)
473 return (flags & m_Mask) == 0;
474
475 // Otherwise, only include shapes that match at least one flag in m_Mask.
476 return (flags & m_Mask) != 0;
477 }
478private:
479 void Init()
480 {
481 // the primary control group to filter out must be valid
483
484 // for simplicity, if m_Group2 is INVALID_ENTITY (i.e. not used), then set it equal to m_Group
485 // so that we have fewer special cases to consider in TestShape().
488 }
489};
490
491/**
492 * Obstruction test filter that will test only against shapes that:
493 * - are part of both of the specified control groups
494 * - AND have at least one of the specified flags set.
495 *
496 * The first (primary) control group to include shapes from must be specified and valid.
497 *
498 * This filter is useful for preventing entities with identical control groups
499 * from colliding e.g. building a new wall segment on top of an existing wall)
500 *
501 * @todo This filter needs test cases.
502 */
504{
509
510public:
512 m_Tag(tag), m_Group(group1), m_Group2(group2), m_Mask(mask)
513 {
515 }
516
517 virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const
518 {
519 // To be included in testing, a shape must not have the specified tag, and must
520 // match at least one of the flags in m_Mask, as well as both control groups.
521 return (tag.n != m_Tag.n && (flags & m_Mask) != 0 && ((group == m_Group
522 && group2 == m_Group2) || (group2 == m_Group && group == m_Group2)));
523 }
524};
525
526/**
527 * Obstruction test filter that will test only against shapes that do not have the specified tag set.
528 */
530{
532public:
534 {
535 }
536
537 virtual bool TestShape(tag_t tag, flags_t, entity_id_t /*group*/, entity_id_t /*group2*/) const
538 {
539 return tag.n != m_Tag.n;
540 }
541};
542
543/**
544 * Similar to ControlGroupMovementObstructionFilter, but also ignoring a specific tag. See D3482 for why this exists.
545 */
547{
551
552public:
554 m_Tag(tag), m_Group(group), m_AvoidMoving(avoidMoving)
555 {}
556
557 virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const
558 {
559 if (tag.n == m_Tag.n)
560 return false;
561
562 if (group == m_Group || (group2 != INVALID_ENTITY && group2 == m_Group))
563 return false;
564
566 return false;
567
569 return false;
570
571 return true;
572 }
573};
574
575
576/**
577 * Obstruction test filter that will test only against shapes that:
578 * - do not have the specified tag
579 * - AND have at least one of the specified flags set.
580 */
582{
585public:
587 {
588 }
589
590 virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t /*group*/, entity_id_t /*group2*/) const
591 {
592 return (tag.n != m_Tag.n && (flags & m_Mask) != 0);
593 }
594};
595
596#endif // INCLUDED_ICMPOBSTRUCTIONMANAGER
std::uint16_t NavcellData
Definition: ICmpObstructionManager.h:37
Entity coordinate types.
Definition: FixedVector2D.h:25
A simple fixed-point number class.
Definition: Fixed.h:129
Obstruction test filter that reject shapes in a given control group, and rejects shapes that don't bl...
Definition: ICmpObstructionManager.h:406
ControlGroupMovementObstructionFilter(bool avoidMoving, entity_id_t group)
Definition: ICmpObstructionManager.h:411
virtual bool TestShape(tag_t, flags_t flags, entity_id_t group, entity_id_t group2) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:415
entity_id_t m_Group
Definition: ICmpObstructionManager.h:408
bool m_AvoidMoving
Definition: ICmpObstructionManager.h:407
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: Grid.h:46
Obstruction manager: provides efficient spatial queries over objects in the world.
Definition: ICmpObstructionManager.h:64
virtual void SetDebugOverlay(bool enabled)=0
Toggle the rendering of debug info.
virtual bool IsPointInPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const =0
Check if the given point is in range of the other point given those parameters.
virtual void GetStaticObstructionsInRange(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares) const =0
virtual void Rasterize(Grid< NavcellData > &grid, const std::vector< PathfinderPassability > &passClasses, bool fullUpdate)=0
Convert the current set of shapes onto a navcell grid, for all passability classes contained in passC...
EFlags
Boolean flags affecting the obstruction behaviour of a shape.
Definition: ICmpObstructionManager.h:93
@ FLAG_BLOCK_CONSTRUCTION
Definition: ICmpObstructionManager.h:96
@ FLAG_BLOCK_FOUNDATION
Definition: ICmpObstructionManager.h:95
@ FLAG_BLOCK_PATHFINDING
Definition: ICmpObstructionManager.h:97
@ FLAG_BLOCK_MOVEMENT
Definition: ICmpObstructionManager.h:94
@ FLAG_MOVING
Definition: ICmpObstructionManager.h:98
@ FLAG_DELETE_UPON_CONSTRUCTION
Definition: ICmpObstructionManager.h:99
virtual fixed DistanceToTarget(entity_id_t ent, entity_id_t target) const =0
Calculate the shortest distance between the entity and the target.
virtual bool IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given entity is in range of the target given those parameters.
std::uint8_t flags_t
Bitmask of EFlag values.
Definition: ICmpObstructionManager.h:105
virtual void RemoveShape(tag_t tag)=0
Remove an existing shape.
virtual ObstructionSquare GetUnitShapeObstruction(entity_pos_t x, entity_pos_t z, entity_pos_t clearance) const =0
virtual void GetObstructionsInRange(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares) const =0
Find all the obstructions that are inside (or partially inside) the given range.
virtual fixed MaxDistanceBetweenShapes(const ObstructionSquare &source, const ObstructionSquare &target) const =0
Calculate the largest straight line distance between the source and the target.
virtual void SetUnitMovingFlag(tag_t tag, bool moving)=0
Set whether a unit shape is moving or stationary.
virtual void MoveShape(tag_t tag, entity_pos_t x, entity_pos_t z, entity_angle_t a)=0
Adjust the position and angle of an existing shape.
virtual bool IsInPointRange(entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given entity is in range of the other point given those parameters.
virtual bool TestStaticShape(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, std::vector< entity_id_t > *out) const =0
Collision test a static square shape against the current set of shapes.
virtual bool TestUnitLine(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, bool relaxClearanceForUnits) const =0
virtual void SetPassabilityCircular(bool enabled)=0
Set the passability to be restricted to a circular map.
virtual void UpdateInformations(GridUpdateInformation &informations)=0
Gets dirtiness information and resets it afterwards.
virtual void GetUnitsOnObstruction(const ObstructionSquare &square, std::vector< entity_id_t > &out, const IObstructionTestFilter &filter, bool strict=false) const =0
Returns the entity IDs of all unit shapes that intersect the given obstruction square,...
virtual void SetStaticControlGroup(tag_t tag, entity_id_t group, entity_id_t group2)=0
Sets the control group of a static shape.
virtual ObstructionSquare GetObstruction(tag_t tag) const =0
Get the obstruction square representing the given shape.
virtual bool AreShapesInRange(const ObstructionSquare &source, const ObstructionSquare &target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given shape is in range of the target shape given those parameters.
virtual void GetUnitObstructionsInRange(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares) const =0
virtual tag_t AddUnitShape(entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_pos_t clearance, flags_t flags, entity_id_t group)=0
Register a unit shape.
virtual tag_t AddStaticShape(entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h, flags_t flags, entity_id_t group, entity_id_t group2=INVALID_ENTITY)=0
Register a static shape.
virtual bool TestLine(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, bool relaxClearanceForUnits) const =0
Collision test a flat-ended thick line against the current set of shapes.
virtual void SetBounds(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1)=0
Set the bounds of the world.
virtual void SetUnitControlGroup(tag_t tag, entity_id_t group)=0
Set the control group of a unit shape.
virtual bool IsInTargetParabolicRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t yOrigin, bool opposite) const =0
Check if the given entity is in parabolic range of the target given those parameters.
virtual fixed DistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const =0
Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the wo...
virtual fixed MaxDistanceToTarget(entity_id_t ent, entity_id_t target) const =0
Calculate the largest straight line distance between the entity and the target.
virtual bool TestUnitShape(const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t clearance, std::vector< entity_id_t > *out) const =0
Collision test a unit shape against the current set of registered shapes, and optionally writes a lis...
virtual fixed MaxDistanceToPoint(entity_id_t ent, entity_pos_t px, entity_pos_t pz) const =0
Calculate the largest straight line distance between the entity and the point.
virtual ObstructionSquare GetStaticShapeObstruction(entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h) const =0
virtual fixed DistanceBetweenShapes(const ObstructionSquare &source, const ObstructionSquare &target) const =0
Calculate the shortest straight line distance between the source and the target.
virtual void GetStaticObstructionsOnObstruction(const ObstructionSquare &square, std::vector< entity_id_t > &out, const IObstructionTestFilter &filter) const =0
virtual bool GetPassabilityCircular() const =0
Definition: IComponent.h:33
Interface for ICmpObstructionManager Test functions to filter out unwanted shapes.
Definition: ICmpObstructionManager.h:357
ICmpObstructionManager::tag_t tag_t
Definition: ICmpObstructionManager.h:359
virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const =0
Return true if the shape with the specified parameters should be tested for collisions.
ICmpObstructionManager::flags_t flags_t
Definition: ICmpObstructionManager.h:360
virtual ~IObstructionTestFilter()
Definition: ICmpObstructionManager.h:362
Obstruction test filter that will test against all shapes.
Definition: ICmpObstructionManager.h:381
virtual bool TestShape(tag_t, flags_t, entity_id_t, entity_id_t) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:383
Definition: Pathfinding.h:219
Obstruction test filter that will test only against shapes that:
Definition: ICmpObstructionManager.h:444
void Init()
Definition: ICmpObstructionManager.h:479
bool m_Exclude
Definition: ICmpObstructionManager.h:445
SkipControlGroupsRequireFlagObstructionFilter(bool exclude, entity_id_t group1, entity_id_t group2, flags_t mask)
Definition: ICmpObstructionManager.h:451
flags_t m_Mask
Definition: ICmpObstructionManager.h:448
virtual bool TestShape(tag_t, flags_t flags, entity_id_t group, entity_id_t group2) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:463
SkipControlGroupsRequireFlagObstructionFilter(entity_id_t group1, entity_id_t group2, flags_t mask)
Definition: ICmpObstructionManager.h:457
entity_id_t m_Group2
Definition: ICmpObstructionManager.h:447
entity_id_t m_Group
Definition: ICmpObstructionManager.h:446
Similar to ControlGroupMovementObstructionFilter, but also ignoring a specific tag.
Definition: ICmpObstructionManager.h:547
SkipTagAndControlGroupObstructionFilter(tag_t tag, bool avoidMoving, entity_id_t group)
Definition: ICmpObstructionManager.h:553
bool m_AvoidMoving
Definition: ICmpObstructionManager.h:550
virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:557
tag_t m_Tag
Definition: ICmpObstructionManager.h:549
entity_id_t m_Group
Definition: ICmpObstructionManager.h:548
Obstruction test filter that will test only against shapes that do not have the specified tag set.
Definition: ICmpObstructionManager.h:530
virtual bool TestShape(tag_t tag, flags_t, entity_id_t, entity_id_t) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:537
SkipTagObstructionFilter(tag_t tag)
Definition: ICmpObstructionManager.h:533
tag_t m_Tag
Definition: ICmpObstructionManager.h:531
Obstruction test filter that will test only against shapes that:
Definition: ICmpObstructionManager.h:504
flags_t m_Mask
Definition: ICmpObstructionManager.h:508
entity_id_t m_Group2
Definition: ICmpObstructionManager.h:507
SkipTagRequireControlGroupsAndFlagObstructionFilter(tag_t tag, entity_id_t group1, entity_id_t group2, flags_t mask)
Definition: ICmpObstructionManager.h:511
entity_id_t m_Group
Definition: ICmpObstructionManager.h:506
tag_t m_Tag
Definition: ICmpObstructionManager.h:505
virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t group, entity_id_t group2) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:517
Obstruction test filter that will test only against shapes that:
Definition: ICmpObstructionManager.h:582
virtual bool TestShape(tag_t tag, flags_t flags, entity_id_t, entity_id_t) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:590
SkipTagRequireFlagsObstructionFilter(tag_t tag, flags_t mask)
Definition: ICmpObstructionManager.h:586
flags_t m_Mask
Definition: ICmpObstructionManager.h:584
tag_t m_Tag
Definition: ICmpObstructionManager.h:583
Obstruction test filter that will test only against stationary (i.e.
Definition: ICmpObstructionManager.h:393
virtual bool TestShape(tag_t, flags_t flags, entity_id_t, entity_id_t) const
Return true if the shape with the specified parameters should be tested for collisions.
Definition: ICmpObstructionManager.h:395
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:222
const entity_id_t INVALID_ENTITY
Invalid entity ID.
Definition: Entity.h:35
std::uint32_t entity_id_t
Entity ID type.
Definition: Entity.h:29
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
Structure holding grid dirtiness informations, for clever updates.
Definition: Grid.h:372
Standard representation for all types of shapes, for use with geometry processing code.
Definition: ICmpObstructionManager.h:70
CFixedVector2D u
Definition: ICmpObstructionManager.h:72
entity_pos_t z
Definition: ICmpObstructionManager.h:71
entity_pos_t hw
Definition: ICmpObstructionManager.h:73
entity_pos_t hh
Definition: ICmpObstructionManager.h:73
entity_pos_t x
Definition: ICmpObstructionManager.h:71
CFixedVector2D v
Definition: ICmpObstructionManager.h:72
External identifiers for shapes.
Definition: ICmpObstructionManager.h:81
tag_t(std::uint32_t n)
Definition: ICmpObstructionManager.h:83
std::uint32_t n
Definition: ICmpObstructionManager.h:86
bool valid() const
Definition: ICmpObstructionManager.h:84
tag_t()
Definition: ICmpObstructionManager.h:82
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:407