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, 2010 Ben Asselstine 6 // Copyright (C) 2008 Ole Laursen 7 // 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. 12 // 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. 17 // 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 21 // 02110-1301, USA. 22 23 #pragma once 24 #ifndef PATH_H 25 #define PATH_H 26 27 #include <gtkmm.h> 28 #include <list> 29 #include "vector.h" 30 31 class Stack; 32 class XML_Helper; 33 class City; 34 35 //! A list of waypoint coordinates (Vector<int>) on the GameMap. 36 /** 37 * The path class is used to store movement paths, determine new movement 38 * paths, and to query existing movement paths. 39 * 40 */ 41 class Path : public std::list<Vector<int> > 42 { 43 public: 44 //! The xml tag of this object in a saved-game file. 45 static Glib::ustring d_tag; 46 47 //! Default constructor. 48 Path(); 49 50 //! Copy constructor. 51 Path(const Path& p); 52 53 //! Make a new path by loading it from an opened saved-game file. 54 Path(XML_Helper* helper); 55 //! Destructor. 56 ~Path(); 57 58 //! Save the path to an opened saved-game file. 59 bool save(XML_Helper* helper) const; 60 61 /** 62 * Check if the path is blocked for some reason, and recalculate it 63 * if necessary. 64 * 65 * @param stack The Stack whose path we validate. 66 * @param enemy_city_avoidance Return false if a path's point is on an 67 * enemy city, or not if this value is non-negative. 68 * @param enemy_stack_avoidance Return false if a path's point is on an 69 * enemy stack, or not if this value is non-negative. 70 * 71 * @return True if path is valid, False if path is blocked and could 72 * not be recalculated, True if the path was invalid but was 73 * recalculated succesfully. 74 */ 75 //! Validate an existing path. 76 bool checkPath(Stack* stack, int enemy_city_avoidance = -1, int enemy_stack_avoidance = -1); 77 78 /** 79 * Calculates the path from the stack's position to a destination. 80 * 81 * The calculated path is stored within the instance (remember: each 82 * stack has a path instance). During calculation, bonuses and other 83 * specialities are taken into account. 84 * 85 * @param stack The stack whose path we calculate. 86 * @param dest The destination point to calculate for. 87 * @param zigzag Whether we're using the normal way to 88 * calculate paths or not. False means we never 89 * go diagonally. True means we do. 90 * @param turns This variable gets filled up with the number of 91 * turns it takes to get to the destination. If 92 * the destination can be reached in this turn, 93 * the value returned is 0. 94 * 95 * @return The number of movement points needed to destination or 0 96 * if no path is possible. 97 */ 98 //! Calculate a Stack object's Path to a destination on the GameMap. 99 guint32 calculate(Stack* stack, Vector<int> dest, guint32 &turns, bool zigzag = true); 100 guint32 calculate(Stack* stack, Vector<int> dest, bool zigzag = true); 101 102 //! Recalculate a Stack object's Path. 103 void recalculate (Stack* s); 104 105 //! Return the number of points the stack can move along it's path. getMovesExhaustedAtPoint()106 guint32 getMovesExhaustedAtPoint() {return d_moves_exhausted_at_point;} 107 108 /** 109 * Set the point at which the stack can't move along it's path. 110 * If the first point in the stack's path cannot be moved to, 111 * this method should return 0. If the second point can't be moved 112 * to, then this method should return 1, etc. 113 * 114 * The purpose of this method is to assist in drawing the waypoint 115 * graphics. 116 * 117 * @param index The index of the point in the stack's path that 118 * cannot be moved to. 119 */ 120 //! Set the number of points the stack can move along it's path. setMovesExhaustedAtPoint(guint32 index)121 void setMovesExhaustedAtPoint(guint32 index) 122 {d_moves_exhausted_at_point = index;} 123 124 void eraseFirstPoint(); 125 126 //! find which tile in the city is quickest to move to. 127 guint32 calculateToCity (Stack *s, City *c, bool zigzag = true); 128 void dump(); 129 void calculate (Stack* s, Vector<int> dest, guint32 &mp, guint32 &turns, guint32 &left, bool zigzag = true); 130 private: 131 132 int pointsToMoveTo(const Stack *s, int x, int y, int destx, int desty) const; 133 134 bool load_or_unload(Stack *s, Vector<int> src, Vector<int> dest, bool &on_ship); 135 136 // Data 137 138 //! The point in the path that can't be reached. 139 guint32 d_moves_exhausted_at_point; 140 141 }; 142 143 #endif // PATH_H 144