initial commit, lordsawar source, slightly modified
[lordsawar] / src / road.h
1 //  Copyright (C) 2007, 2008 Ben Asselstine
2 //
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.
7 //
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.
12 //
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 
16 //  02110-1301, USA.
17
18 #ifndef ROAD_H
19 #define ROAD_H
20
21 #include "Location.h"
22
23 //! A single tile on the map that has a road on it.
24 /**
25  * Stack objects move more efficently on roads, and they often interconnect 
26  * many City objects.
27  * A road object is built on a Tile with any terrain kind except Tile::WATER.
28  */
29 class Road: public Location
30 {
31     public:
32         //! The xml tag of this object in a saved-game file.
33         static std::string d_tag; 
34
35         enum Type {
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,
47           CONNECTS_WEST = 11,
48           CONNECTS_NORTH = 12,
49           CONNECTS_EAST = 13,
50           CONNECTS_SOUTH = 14,
51         };
52
53         //! Default constructor.
54         /**
55           * @param pos          The location of the road.
56           * @param type         The type of road.
57           */
58         Road(Vector<int> pos, int type = CONNECTS_ALL_DIRECTIONS);
59
60         //! Copy constructor.
61         Road(const Road&);
62
63         //! Alternative copy constructor that changes the road's position.
64         Road(const Road&, Vector<int> pos);
65
66         //! Loading constructor.
67         /**
68          * Make a new road object by reading lordsawar.roadlist.road XML 
69          * entities from the saved-game file.
70          *
71          * @param helper  The opened saved-game file to load the road from.
72          */
73         Road(XML_Helper* helper);
74
75         //! Destructor.
76         ~Road();
77
78
79         // Get Methods
80
81         //! Returns the type of the road.
82         int getType() const {return d_type;};
83
84
85         // Set Methods
86
87         //! Sets the type of the road.
88         void setType(int type) {d_type = type;};
89
90
91         // Methods that operate on class data but do not modify the class
92
93         //! Save the road data to an opened saved-game file.
94         bool save(XML_Helper* helper) const;
95
96
97         // Static Methods
98
99         //! Convert a Road::Type enumerated value to a string.
100         static std::string roadTypeToString(const Road::Type type);
101
102         //! Convert a string containing a Road::Type to it's enumerated value.
103         static Road::Type roadTypeFromString(const std::string str);
104
105     protected:
106
107         // DATA
108
109         //! The type of the road.
110         /**
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.
113          *
114          * The Roadlist::calculateType method can calculate this value.
115          */
116         int d_type;
117
118 };
119
120 #endif // ROAD_H