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