1 // Copyright (C) 2008, 2009 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
24 #include <sigc++/trackable.h>
33 //! A list of city graphic objects in a city theme.
35 * Every scenario has a city set; it is the theme of the city graphics
38 * The Cityset dictates the size of city images.
40 * Citysets are referred to by their subdirectory name.
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.
45 class Cityset : public sigc::trackable, public Set
48 //! The xml tag of this object in a cityset configuration file.
49 static std::string d_tag;
50 static std::string file_extension;
52 //! Default constructor.
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.
60 Cityset(guint32 id, std::string name);
62 //! Loading constructor.
64 * Make a new Cityset object by reading it in from the cityset
67 * @param helper The opened cityset configuration file to load the
70 Cityset(XML_Helper* helper, std::string directory);
72 static Cityset *create(std::string file);
76 bool save(XML_Helper *helper);
78 //! Get the directory in which the cityset configuration file resides.
79 std::string getSubDir() const {return d_subdir;}
81 //! Set the direction where the shieldset configuration file resides.
82 void setSubDir(std::string dir) {d_subdir = dir;}
84 //! Returns the name of the cityset.
85 std::string getName() const {return _(d_name.c_str());}
87 //! Returns the copyright holders for the cityset.
88 std::string getCopyright() const {return d_copyright;};
90 //! Returns the license for the cityset.
91 std::string getLicense() const {return d_license;};
94 * Analagous to the cityset.d_id XML entity in the cityset
97 guint32 getId() const {return d_id;}
99 //! Set the unique identifier for this cityset.
100 void setId(guint32 id) {d_id = id;}
102 //! Set the name of the cityset.
104 * @note This method is only used in the cityset editor.
106 void setName(std::string name) {d_name = name;}
108 //! Set the copyright holders on the cityset.
109 void setCopyright(std::string copy) {d_copyright = copy;};
111 //! Set the license for this cityset.
112 void setLicense(std::string license) {d_license = license;};
114 //! Returns the description of the cityset.
115 std::string getInfo() const {return _(d_info.c_str());}
117 //! Sets the description of the cityset.
118 void setInfo(std::string description) {d_info = description;};
120 //! Returns the width and height in pixels of the city images.
121 guint32 getTileSize() const {return d_tileSize;}
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;};
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];};
153 //! get filenames in this cityset, excepting the configuration file.
154 void getFilenames(std::list<std::string> &files);
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();
166 std::string getConfigurationFile();
168 static std::list<std::string> scanSystemCollection();
169 static std::list<std::string> scanUserCollection();
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;};
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);
193 //! A unique numeric identifier among all citysets.
196 //! The name of the cityset.
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.
205 //! The copyright holders for this cityset.
206 std::string d_copyright;
208 //! The license of this cityset.
209 std::string d_license;
211 //! The description of the cityset.
213 * Equates to the cityset.d_info XML entity in the cityset
214 * configuration file.
215 * This value is not used.
219 //! The size of each city image onscreen.
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
228 //! The subdirectory of the cityset.
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.
234 std::string d_subdir;
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];
248 PixMask *ruinpics[RUIN_TYPES];
249 PixMask *templepics[TEMPLE_TYPES];
250 PixMask *towerpics[MAX_PLAYERS];
252 guint32 d_city_tile_width;
253 guint32 d_temple_tile_width;
254 guint32 d_ruin_tile_width;