Pyrogenesis  trunk
PathGoal.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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  */
32 class PathGoal
33 {
34 public:
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
41  } type;
42 
43  entity_pos_t x, z; // position of center
44 
45  CFixedVector2D u, v; // if [INVERTED_]SQUARE, then orthogonal unit axes
46 
47  entity_pos_t hw, hh; // if [INVERTED_]SQUARE, then half width & height; if [INVERTED_]CIRCLE, then hw is radius
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 with the given @p pos
74  * to any point on the outline of the goal shape.
75  */
77 
78  /**
79  * Returns the coordinates of the point on the goal that is closest to pos in a straight line.
80  */
82 };
83 
84 #endif // INCLUDED_PATHGOAL
A simple fixed-point number class.
Definition: Fixed.h:115
Definition: FixedVector2D.h:24
enum PathGoal::Type type
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
entity_pos_t hw
Definition: PathGoal.h:47
CFixedVector2D NearestPointOnGoal(CFixedVector2D pos) const
Returns the coordinates of the point on the goal that is closest to pos in a straight line...
Definition: PathGoal.cpp:317
Definition: PathGoal.h:37
Pathfinder goal.
Definition: PathGoal.h:32
bool NavcellContainsGoal(int i, int j) const
Returns true if the given navcell contains a part of the goal area.
Definition: PathGoal.cpp:95
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
fixed DistanceToPoint(CFixedVector2D pos) const
Returns the minimum distance from the point with the given pos to any point on the outline of the goa...
Definition: PathGoal.cpp:294
entity_pos_t hh
Definition: PathGoal.h:47
entity_pos_t x
Definition: PathGoal.h:43
Definition: PathGoal.h:40
Definition: PathGoal.h:39
CFixedVector2D v
Definition: PathGoal.h:45
CFixedVector2D u
Definition: PathGoal.h:45
Definition: PathGoal.h:38
Definition: PathGoal.h:36
entity_pos_t maxdist
Definition: PathGoal.h:49
Type
Definition: PathGoal.h:35
Entity coordinate types.
entity_pos_t z
Definition: PathGoal.h:43