Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
PathGoal.h
Go to the documentation of this file.
1/* Copyright (C) 2025 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_PATHGOAL
19#define INCLUDED_PATHGOAL
20
21#include "maths/Fixed.h"
22#include "maths/FixedVector2D.h"
24
25/**
26 * Pathfinder goal.
27 * The goal can be either a point, a circle, or a square (rectangle).
28 * For circles/squares, any point inside the shape is considered to be
29 * part of the goal.
30 * Also, it can be an 'inverted' circle/square, where any point outside
31 * the shape is part of the goal.
32 */
34{
35public:
36 enum Type {
37 POINT, // single point
38 CIRCLE, // the area inside a circle
39 INVERTED_CIRCLE, // the area outside a circle
40 SQUARE, // the area inside a square
41 INVERTED_SQUARE // the area outside a square
43
44 entity_pos_t x, z; // position of center
45
46 entity_pos_t hw, hh; // if [INVERTED_]SQUARE, then half width & height; if [INVERTED_]CIRCLE, then hw is radius
47
48 CFixedVector2D u, v; // if [INVERTED_]SQUARE, then orthogonal unit axes
49
50 entity_pos_t maxdist; // maximum distance wanted between two path waypoints
51
52 /**
53 * Returns true if the given navcell contains a part of the goal area.
54 */
55 bool NavcellContainsGoal(int i, int j) const;
56
57 /**
58 * Returns true if any navcell (i, j) where
59 * min(i0,i1) <= i <= max(i0,i1)
60 * min(j0,j1) <= j <= max(j0,j1),
61 * contains a part of the goal area.
62 * If so, arguments i and j (if not NULL) are set to the goal navcell nearest
63 * to (i0, j0), assuming the rect has either width or height = 1.
64 */
65 bool NavcellRectContainsGoal(int i0, int j0, int i1, int j1, int* i, int* j) const;
66
67 /**
68 * Returns true if the rectangle defined by (x0,z0)-(x1,z1) (inclusive)
69 * contains a part of the goal area.
70 */
72
73 /**
74 * Returns the minimum distance from the point pos to any point on the goal shape.
75 */
77
78 /**
79 * Returns the coordinates of the point on the goal that is closest to the point pos.
80 */
82};
83
84#endif // INCLUDED_PATHGOAL
Entity coordinate types.
Definition: FixedVector2D.h:25
A simple fixed-point number class.
Definition: Fixed.h:129
Pathfinder goal.
Definition: PathGoal.h:34
entity_pos_t hw
Definition: PathGoal.h:46
Type
Definition: PathGoal.h:36
@ SQUARE
Definition: PathGoal.h:40
@ CIRCLE
Definition: PathGoal.h:38
@ INVERTED_CIRCLE
Definition: PathGoal.h:39
@ INVERTED_SQUARE
Definition: PathGoal.h:41
@ POINT
Definition: PathGoal.h:37
bool RectContainsGoal(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) const
Returns true if the rectangle defined by (x0,z0)-(x1,z1) (inclusive) contains a part of the goal area...
Definition: PathGoal.cpp:251
bool NavcellRectContainsGoal(int i0, int j0, int i1, int j1, int *i, int *j) const
Returns true if any navcell (i, j) where min(i0,i1) <= i <= max(i0,i1) min(j0,j1) <= j <= max(j0,...
Definition: PathGoal.cpp:120
CFixedVector2D u
Definition: PathGoal.h:48
fixed DistanceToPoint(CFixedVector2D pos) const
Returns the minimum distance from the point pos to any point on the goal shape.
Definition: PathGoal.cpp:296
enum PathGoal::Type type
CFixedVector2D NearestPointOnGoal(CFixedVector2D pos) const
Returns the coordinates of the point on the goal that is closest to the point pos.
Definition: PathGoal.cpp:329
entity_pos_t hh
Definition: PathGoal.h:46
bool NavcellContainsGoal(int i, int j) const
Returns true if the given navcell contains a part of the goal area.
Definition: PathGoal.cpp:97
entity_pos_t z
Definition: PathGoal.h:44
entity_pos_t maxdist
Definition: PathGoal.h:50
CFixedVector2D v
Definition: PathGoal.h:48
entity_pos_t x
Definition: PathGoal.h:44