Line data Source code
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" 23 : #include "simulation2/helpers/Position.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 : */ 33 11030 : class PathGoal 34 : { 35 : public: 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 42 : } type; 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 : */ 71 : bool RectContainsGoal(entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1) const; 72 : 73 : /** 74 : * Returns the minimum distance from the point pos to any point on the goal shape. 75 : */ 76 : fixed DistanceToPoint(CFixedVector2D pos) const; 77 : 78 : /** 79 : * Returns the coordinates of the point on the goal that is closest to the point pos. 80 : */ 81 : CFixedVector2D NearestPointOnGoal(CFixedVector2D pos) const; 82 : }; 83 : 84 : #endif // INCLUDED_PATHGOAL