1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005 Andrea Paternesi
4 // Copyright (C) 2004 John Farrell
5 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
6 // Copyright (C) 2008 Ole Laursen
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Library General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 //! A list of waypoint coordinates (Vector<int>) on the GameMap.
36 * The path class is used to store movement paths, determine new movement
37 * paths, and to query existing movement paths.
40 class Path : public std::list<Vector<int> >
43 //! The xml tag of this object in a saved-game file.
44 static std::string d_tag;
46 //! Default constructor.
52 //! Make a new path by loading it from an opened saved-game file.
53 Path(XML_Helper* helper);
57 //! Save the path to an opened saved-game file.
58 bool save(XML_Helper* helper) const;
61 * Check if the path is blocked for some reason, and recalculate it
64 * @param stack The Stack whose path we validate.
65 * @param enemy_city_avoidance Return false if a path's point is on an
66 * enemy city, or not if this value is non-negative.
67 * @param enemy_stack_avoidance Return false if a path's point is on an
68 * enemy stack, or not if this value is non-negative.
70 * @return True if path is valid, False if path is blocked and could
71 * not be recalculated, True if the path was invalid but was
72 * recalculated succesfully.
74 //! Validate an existing path.
75 bool checkPath(Stack* stack, int enemy_city_avoidance = -1, int enemy_stack_avoidance = -1);
78 * Calculates the path from the stack's position to a destination.
80 * The calculated path is stored within the instance (remember: each
81 * stack has a path instance). During calculation, bonuses and other
82 * specialities are taken into account.
84 * @param stack The stack whose path we calculate.
85 * @param dest The destination point to calculate for.
86 * @param zigzag Whether we're using the normal way to
87 * calculate paths or not. False means we never
88 * go diagonally. True means we do.
89 * @param turns This variable gets filled up with the number of
90 * turns it takes to get to the destination. If
91 * the destination can be reached in this turn,
92 * the value returned is 0.
94 * @return The number of movement points needed to destination or 0
95 * if no path is possible.
97 //! Calculate a Stack object's Path to a destination on the GameMap.
98 guint32 calculate(Stack* stack, Vector<int> dest, guint32 &turns, bool zigzag = true);
99 guint32 calculate(Stack* stack, Vector<int> dest, bool zigzag = true);
101 //! Recalculate a Stack object's Path.
102 void recalculate (Stack* s);
104 //! Return the number of points the stack can move along it's path.
105 guint32 getMovesExhaustedAtPoint() {return d_moves_exhausted_at_point;}
108 * Set the point at which the stack can't move along it's path.
109 * If the first point in the stack's path cannot be moved to,
110 * this method should return 0. If the second point can't be moved
111 * to, then this method should return 1, etc.
113 * The purpose of this method is to assist in drawing the waypoint
116 * @param index The index of the point in the stack's path that
117 * cannot be moved to.
119 //! Set the number of points the stack can move along it's path.
120 void setMovesExhaustedAtPoint(guint32 index)
121 {d_moves_exhausted_at_point = index;}
123 void eraseFirstPoint();
125 //! find which tile in the city is quickest to move to.
126 guint32 calculateToCity (Stack *s, City *c, bool zigzag = true);
130 int pointsToMoveTo(const Stack *s, int x, int y, int destx, int desty) const;
132 void calculate (Stack* s, Vector<int> dest, guint32 &mp, guint32 &turns, bool zigzag);
133 bool load_or_unload(Stack *s, Vector<int> src, Vector<int> dest, bool &on_ship);
137 //! A cached copy of a Stack object's movement bonus.
140 //! The point in the path that can't be reached.
141 guint32 d_moves_exhausted_at_point;