1 // Copyright (C) 2007, 2008 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
23 //! A single tile on the map that has a road on it.
25 * Stack objects move more efficently on roads, and they often interconnect
27 * A road object is built on a Tile with any terrain kind except Tile::WATER.
29 class Road: public Location
32 //! The xml tag of this object in a saved-game file.
33 static std::string d_tag;
36 CONNECTS_EAST_AND_WEST = 0,
37 CONNECTS_NORTH_AND_SOUTH = 1,
38 CONNECTS_ALL_DIRECTIONS = 2,
39 CONNECTS_NORTH_AND_WEST = 3,
40 CONNECTS_NORTH_AND_EAST = 4,
41 CONNECTS_SOUTH_AND_EAST = 5,
42 CONNECTS_WEST_AND_SOUTH = 6,
43 CONNECTS_NORTH_AND_SOUTH_AND_EAST = 7,
44 CONNECTS_EAST_WEST_AND_NORTH = 8,
45 CONNECTS_EAST_WEST_AND_SOUTH = 9,
46 CONNECTS_NORTH_SOUTH_AND_WEST = 10,
53 //! Default constructor.
55 * @param pos The location of the road.
56 * @param type The type of road.
58 Road(Vector<int> pos, int type = CONNECTS_ALL_DIRECTIONS);
63 //! Alternative copy constructor that changes the road's position.
64 Road(const Road&, Vector<int> pos);
66 //! Loading constructor.
68 * Make a new road object by reading lordsawar.roadlist.road XML
69 * entities from the saved-game file.
71 * @param helper The opened saved-game file to load the road from.
73 Road(XML_Helper* helper);
81 //! Returns the type of the road.
82 int getType() const {return d_type;};
87 //! Sets the type of the road.
88 void setType(int type) {d_type = type;};
91 // Methods that operate on class data but do not modify the class
93 //! Save the road data to an opened saved-game file.
94 bool save(XML_Helper* helper) const;
99 //! Convert a Road::Type enumerated value to a string.
100 static std::string roadTypeToString(const Road::Type type);
102 //! Convert a string containing a Road::Type to it's enumerated value.
103 static Road::Type roadTypeFromString(const std::string str);
109 //! The type of the road.
111 * The type of road refers to the look of the road on the map. It
112 * can be any one of the values found in Road::Type.
114 * The Roadlist::calculateType method can calculate this value.