initial commit, lordsawar source, slightly modified
[lordsawar] / src / cityset.h
1 // Copyright (C) 2008, 2009 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 CITYSET_H
19 #define CITYSET_H
20
21 #include <string>
22 #include <vector>
23 #include <gtkmm.h>
24 #include <sigc++/trackable.h>
25 #include <gtkmm.h>
26 #include "PixMask.h"
27 #include "set.h"
28
29 #include "defs.h"
30
31 class XML_Helper;
32
33 //! A list of city graphic objects in a city theme.
34 /** 
35  * Every scenario has a city set; it is the theme of the city graphics 
36  * within the game. 
37  *
38  * The Cityset dictates the size of city images.
39  *
40  * Citysets are referred to by their subdirectory name.
41  *
42  * The cityset configuration file is a same named XML file inside the 
43  * cityset's directory.  E.g. cityset/${Cityset::d_subdir}/${Cityset::d_subdir}.xml.
44  */
45 class Cityset : public sigc::trackable, public Set
46 {
47     public:
48         //! The xml tag of this object in a cityset configuration file.
49         static std::string d_tag; 
50         static std::string file_extension; 
51
52         //! Default constructor.
53         /**
54          * Make a new Cityset.
55          *
56          * @param id    The unique Id of this Cityset among all other Cityset
57          *              objects.  Must be more than 0.  
58          * @param name  The name of the Cityset.  Analagous to Cityset::d_name.
59          */
60         Cityset(guint32 id, std::string name);
61
62         //! Loading constructor.
63         /**
64          * Make a new Cityset object by reading it in from the cityset
65          * configuration file.
66          *
67          * @param helper  The opened cityset configuration file to load the
68          *                Cityset from.
69          */
70         Cityset(XML_Helper* helper, std::string directory);
71
72         static Cityset *create(std::string file);
73         //! Destructor.
74         ~Cityset();
75
76         bool save(XML_Helper *helper);
77
78         //! Get the directory in which the cityset configuration file resides.
79         std::string getSubDir() const {return d_subdir;}
80
81         //! Set the direction where the shieldset configuration file resides.
82         void setSubDir(std::string dir) {d_subdir = dir;}
83
84         //! Returns the name of the cityset.
85         std::string getName() const {return _(d_name.c_str());}
86
87         //! Returns the copyright holders for the cityset.
88         std::string getCopyright() const {return d_copyright;};
89
90         //! Returns the license for the cityset.
91         std::string getLicense() const {return d_license;};
92
93         /**
94          * Analagous to the cityset.d_id XML entity in the cityset
95          * configuration file.
96          */
97         guint32 getId() const {return d_id;}
98
99         //! Set the unique identifier for this cityset.
100         void setId(guint32 id) {d_id = id;}
101
102         //! Set the name of the cityset.
103         /**
104          * @note This method is only used in the cityset editor.
105          */
106         void setName(std::string name) {d_name = name;}
107
108         //! Set the copyright holders on the cityset.
109         void setCopyright(std::string copy) {d_copyright = copy;};
110
111         //! Set the license for this cityset.
112         void setLicense(std::string license) {d_license = license;};
113
114         //! Returns the description of the cityset.
115         std::string getInfo() const {return _(d_info.c_str());}
116
117         //! Sets the description of the cityset.
118         void setInfo(std::string description) {d_info = description;};
119
120         //! Returns the width and height in pixels of the city images.
121         guint32 getTileSize() const {return d_tileSize;}
122
123         void setCitiesFilename(std::string s) {d_cities_filename = s;};
124         std::string getCitiesFilename() {return d_cities_filename;};
125         void setRazedCitiesFilename(std::string s) {d_razedcities_filename = s;};
126         std::string getRazedCitiesFilename() {return d_razedcities_filename;};
127         void setPortFilename(std::string s) {d_port_filename = s;};
128         std::string getPortFilename() {return d_port_filename;};
129         void setSignpostFilename(std::string s) {d_signpost_filename = s;};
130         std::string getSignpostFilename() {return d_signpost_filename;};
131         void setRuinsFilename(std::string s) {d_ruins_filename = s;};
132         std::string getRuinsFilename() {return d_ruins_filename;};
133         void setTemplesFilename(std::string s) {d_temples_filename = s;};
134         std::string getTemplesFilename() {return d_temples_filename;};
135         void setTowersFilename(std::string s) {d_towers_filename = s;};
136         std::string getTowersFilename() {return d_towers_filename;};
137
138         void setCityImage(guint32 i, PixMask *p) {citypics[i] = p;};
139         PixMask *getCityImage(guint32 i) {return citypics[i];};
140         void setRazedCityImage(guint32 i, PixMask *p) {razedcitypics[i] = p;};
141         PixMask *getRazedCityImage(guint32 i) {return razedcitypics[i];};
142         PixMask *getPortImage() {return port;};
143         void setPortImage(PixMask *p) {port = p;};
144         PixMask *getSignpostImage() {return signpost;};
145         void setSignpostImage(PixMask *p) {signpost = p;};
146         void setRuinImage(guint32 i, PixMask *p) {ruinpics[i] = p;};
147         PixMask *getRuinImage(guint32 i) {return ruinpics[i];};
148         void setTempleImage(guint32 i, PixMask *p) {templepics[i] = p;};
149         PixMask *getTempleImage(guint32 i) {return templepics[i];};
150         void setTowerImage(guint32 i, PixMask *p) {towerpics[i] = p;};
151         PixMask *getTowerImage(guint32 i) {return towerpics[i];};
152
153         //! get filenames in this cityset, excepting the configuration file.
154         void getFilenames(std::list<std::string> &files);
155
156         void instantiateImages();
157         void instantiateImages(std::string port_filename,
158                                std::string signpost_filename,
159                                std::string cities_filename,
160                                std::string razed_cities_filename,
161                                std::string towers_filename,
162                                std::string ruins_filename,
163                                std::string temples_filename);
164         void uninstantiateImages();
165
166         std::string getConfigurationFile();
167
168         static std::list<std::string> scanSystemCollection();
169         static std::list<std::string> scanUserCollection();
170
171         guint32 getCityTileWidth() {return d_city_tile_width;};
172         void setCityTileWidth(guint32 tiles) {d_city_tile_width = tiles;};
173         guint32 getTempleTileWidth() {return d_temple_tile_width;};
174         void setTempleTileWidth(guint32 tiles) {d_temple_tile_width = tiles;};
175         guint32 getRuinTileWidth() {return d_ruin_tile_width;};
176         void setRuinTileWidth(guint32 tiles) {d_ruin_tile_width = tiles;};
177         bool validate();
178         bool validateCitiesFilename();
179         bool validateRazedCitiesFilename();
180         bool validateSignpostFilename();
181         bool validatePortFilename();
182         bool validateRuinsFilename();
183         bool validateTemplesFilename();
184         bool validateTowersFilename();
185         bool validateCityTileWidth();
186         bool validateRuinTileWidth();
187         bool validateTempleTileWidth();
188         bool tileWidthsEqual(Cityset *cityset);
189
190     private:
191
192         // DATA
193         //! A unique numeric identifier among all citysets.
194         guint32 d_id;
195
196         //! The name of the cityset.
197         /**
198          * This equates to the cityset.d_name XML entity in the cityset
199          * configuration file.
200          * This name appears in the dialogs where the user is asked to 
201          * select a particular Cityset.
202          */
203         std::string d_name;
204
205         //! The copyright holders for this cityset.
206         std::string d_copyright;
207
208         //! The license of this cityset.
209         std::string d_license;
210
211         //! The description of the cityset.
212         /**
213          * Equates to the cityset.d_info XML entity in the cityset 
214          * configuration file.
215          * This value is not used.
216          */
217         std::string d_info;
218
219         //! The size of each city image onscreen.
220         /**
221          * Equates to the cityset.d_tilesize XML entity in the cityset
222          * configuration file.
223          * It represents the size in pixels of the width and height of city
224          * imagery onscreen.
225          */
226         guint32 d_tileSize;
227
228         //! The subdirectory of the cityset.
229         /**
230          * This is the name of the subdirectory that the Cityset files are
231          * residing in.  It does not contain a path (e.g. no slashes).
232          * Cityset directories sit in the citysets/ directory.
233          */
234         std::string d_subdir;
235
236
237         std::string d_cities_filename;
238         std::string d_razedcities_filename;
239         std::string d_port_filename;
240         std::string d_signpost_filename;
241         std::string d_ruins_filename;
242         std::string d_temples_filename;
243         std::string d_towers_filename;
244         PixMask *citypics[MAX_PLAYERS + 1];
245         PixMask *razedcitypics[MAX_PLAYERS];
246         PixMask *port;
247         PixMask *signpost;
248         PixMask *ruinpics[RUIN_TYPES];
249         PixMask *templepics[TEMPLE_TYPES];
250         PixMask *towerpics[MAX_PLAYERS];
251
252         guint32 d_city_tile_width;
253         guint32 d_temple_tile_width;
254         guint32 d_ruin_tile_width;
255 };
256
257 #endif // CITYSET_H
258
259 // End of file