1 // Copyright (C) 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 #ifndef PATH_CALCULATOR_H
18 #define PATH_CALCULATOR_H
29 //! An object that calculates shortest paths on a weighted grid.
36 //! Default constructor.
37 PathCalculator(const Stack *s, bool zigzag = true, int enemy_city_avoidance = -1, int enemy_stack_avoidance = -1);
39 //! Alternate constructor. calculate with a copy of the stack.
40 PathCalculator(const Stack &s, bool zigzag = true, int enemy_city_avoidance = -1, int enemy_stack_avoidance = -1);
42 //! Alternate constructor. calculate with a new stack of one army.
43 PathCalculator(Player *p, Vector<int> src, const ArmyProdBase *prodbase = NULL, bool zigzag = true, int enemy_city_avoidance = -1, int enemy_stack_avoidance = -1);
46 PathCalculator(const PathCalculator&);
51 bool isReachable(Vector<int> pos);
53 Path* calculate(Vector<int> dest, guint32 &moves, guint32 &turns, bool zigzag = true);
55 Path* calculateToCity (City *c, guint32 &moves, guint32 &turns, bool zigzag = true);
56 int calculate(Vector<int> dest, bool zigzag = true);
58 static bool isBlocked(const Stack *s, Vector<int> pos, bool enemy_cities_block, bool enemy_stacks_block);
60 //! Return the positions on the map that are reachable in MP or less.
61 std::list<Vector<int> > getReachablePositions(int mp = 0);
77 int enemy_city_avoidance;
78 int enemy_stack_avoidance;
81 * Checks how many movement points are needed to cross a tile from
84 * @param pos This is the origin point that the Stack is moving from.
86 * @param dest This is the destination point that we're checking if the
89 * @return The number of movement points required to traverse the
90 * destination tile, or -1 if movement not possible.
92 //! Calculates movement points to traverse an adjacent tile.
93 int pointsToMoveTo(Vector<int> pos, Vector<int> next) const;
95 bool load_or_unload(Vector<int> src, Vector<int> dest, bool &on_ship);
98 * The purpose of this method is to verify if the Stack can move
99 * onto the Tile of the given destination point.
101 * @note This method does not calculate a path and it does not
102 * consider the amount of movement points that the Stack has.
104 * This method uses two shortcuts to check if it is impossible for
105 * the given stack to travel to the given destination on the GameMap.
106 * Firstly it checks to see if the destination terrain Tile::Type is
107 * of a kind that the Stack can't travel on at all (e.g. Mountains,
108 * and the Stack can't fly). Secondly it checks to see if the tile
109 * is both adjacent and blocked from that direction.
111 * This method is primarily used to assist in mouse cursor display.
113 * @param dest The position on the map to see if the Stack can
116 * @return True if the Stack can move to the given position on the
117 * GameMap. Otherwise the return value is false.
119 //! Calculates if a Stack move to a position on the GameMap.
120 bool canMoveThere(Vector<int> dest);
122 std::list<Vector<int> > calcMoves(Vector<int> pos);
123 bool calcMoves(Vector<int> pos, Vector<int> next);
124 bool calcFinalMoves(Vector<int> pos);
125 bool calcFinalMoves(Vector<int> pos, Vector<int> next);
127 void populateNodeMap();
129 * Checks if the way to a given tile is blocked
131 * This function returns whether a unit can pass over a tile from
132 * another tile. The idea here is that the "sides" of certain tiles
133 * are blocked from entry. E.g. when trying to go from water to
134 * land, without going through a city.
136 * @param pos This is the origin point that the Stack is moving from.
138 * @param dest This is the destination point that we're checking if
139 * the Stack can move to.
141 * @note The movement capabilities of a Stack are not taken into
142 * account in this method. This method should only be called
143 * for Stack objects that are not flying.
145 * @return False if a non-flying stack may pass, true otherwise.
146 * False if the two points are not adjacent.
148 //! Checks if the way between adjacent tiles is blocked.
149 bool isBlockedDir(Vector<int> pos, Vector<int> next);
151 //this method involves checking for enemy stacks, cities in the way.
152 bool isBlocked(Vector<int> pos);
154 void dumpNodeMap(Vector<int> dest);
155 bool compareNodeMaps(void *map);