initial commit, lordsawar source, slightly modified
[lordsawar] / src / shieldset.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 SHIELDSET_H
19 #define SHIELDSET_H
20
21 #include <gtkmm.h>
22 #include <string>
23 #include <map>
24 #include <vector>
25 #include <sigc++/trackable.h>
26
27 #include "xmlhelper.h"
28 #include "shield.h"
29 #include "set.h"
30
31 #include "defs.h"
32
33 //! A list of Shield graphic objects in a shield theme.
34 /**
35  * Every scenario has a shield set; it is the theme of the shield graphics 
36  * within the game.  Shields come in three sizes -- small, medium and large.  
37  * Small shields appear on the OverviewMap.  Medium shields appear in the turn 
38  * indicator in the top right of the GameWindow.  Large shields appear in many 
39  * dialogs, chiefly the FightWindow, and DiplomacyDialog.
40  * Every shield belongs to one of 9 players (the ninth is the Neutral player).
41  * The players aren't Player objects in this case; instead it refers to a 
42  * Shield::ShieldColour.  e.g. Not `The Sirians' but rather the `White player'
43  * of the scenario.
44  *
45  * The Shieldset dictates the dimensions of these three sizes of shields.
46  *
47  * Shieldsets are referred to by their subdirectory name.
48  *
49  * The shieldset configuration file is a same named XML file inside the 
50  * Shieldset's directory.  
51  * E.g. shield/${Shieldset::d_subdir}/${Shieldset::d_subdir}.xml.
52  */
53 class Shieldset: public std::list<Shield *>, public sigc::trackable, public Set
54 {
55     public:
56
57         //! The xml tag of this object in a shieldset configuration file.
58         static std::string d_tag; 
59
60         //! The file extension for shieldset files.  It includes the dot.
61         static std::string file_extension;
62
63
64         //! Default constructor.
65         /**
66          * Make a new shieldset given a unique id and a subdir name.
67          */
68         Shieldset(guint32 id, std::string name);
69
70         //! Load a Shieldset from a shieldset configuration file.
71         /**
72          * Make a new Shieldset object by reading it in from the shieldset
73          * configuration file.
74          *
75          * @param helper  The opened shieldset configuration file to load the
76          *                Shieldset from.
77          */
78         Shieldset(XML_Helper* helper, std::string directory);
79
80         //! Destructor.
81         ~Shieldset();
82
83         // Get Methods
84
85         //! Get the unique identifier for this shieldset.
86         /**
87          * Analagous to the shieldset.d_id XML entity in the shieldset
88          * configuration file.
89          */
90         guint32 getId() const {return d_id;}
91
92         //! Get the directory in which the shieldset configuration file resides.
93         std::string getSubDir() const {return d_subdir;}
94
95         //! Return the mask colour for the given player.
96         Gdk::Color getColor(guint32 owner) const;
97
98         //! Return the number of pixels high the small shields are.
99         guint32 getSmallHeight() const {return d_small_height;}
100
101         //! Return the number of pixels wide the small shields are.
102         guint32 getSmallWidth() const {return d_small_width;}
103
104         //! Return the number of pixels high the medium shields are.
105         guint32 getMediumHeight() const {return d_medium_height;}
106
107         //! Return the number of pixels wide the medium shields are.
108         guint32 getMediumWidth() const {return d_medium_width;}
109
110         //! Return the number of pixels the large shields are.
111         guint32 getLargeHeight() const {return d_large_height;}
112
113         //! Return the number of pixels wide the large shields are.
114         guint32 getLargeWidth() const {return d_large_width;}
115
116         //! Return the total number of shields in this shieldset.
117         guint32 getSize() const {return size();}
118
119         //! Return the name of the Shieldset.
120         std::string getName() const {return _(d_name.c_str());}
121
122         //! Return the copyright holders of the shieldset.
123         std::string getCopyright() const {return d_copyright;};
124
125         //! Return the license of the shieldset.
126         std::string getLicense() const {return d_license;};
127
128         //! Returns the description of the shieldset.
129         std::string getInfo() const {return _(d_info.c_str());}
130
131
132         // Set Methods
133
134         //! Set the unique identifier for this shieldset.
135         void setId(guint32 id) {d_id = id;}
136
137         //! Set the name of the Shieldset.
138         void setName(std::string name) {d_name = name;}
139
140         //! Sets the description of the shieldset.
141         void setInfo(std::string description) {d_info = description;};
142
143         //! Set the copyright holders of the shieldset.
144         void setCopyright(std::string copy) {d_copyright = copy;};
145
146         //! Set the license of this shieldset.
147         void setLicense(std::string license) {d_license = license;};
148
149         //! Set the direction where the shieldset configuration file resides.
150         void setSubDir(std::string dir) {d_subdir = dir;}
151
152
153         // Methods that operate on the class data but do not modify the class.
154
155         bool save(XML_Helper *helper) const;
156
157
158         //! Find the shield of a given size and colour in this Shieldset.
159         /**
160          * Scan through all Shield objects in this set for first one that is 
161          * the desired size, and for the desired player.
162          *
163          * @param type    One of the values in Shield::ShieldType.
164          * @param colour  One of the values in Shield::ShieldColour.
165          *
166          * @return A pointer to the shield that matches the size and player.
167          *         If no Shield object could be found that matches the given
168          *         parameters, NULL is returned.
169          */
170         ShieldStyle * lookupShieldByTypeAndColour(guint32 type, guint32 colour) const;
171
172         //! Get filenames in this shieldset, excepting the configuration file.
173         void getFilenames(std::list<std::string> &filenames) const;
174
175         //! Return the name of this shieldset's configuration file.
176         std::string getConfigurationFile() const;
177         
178         //! Check to see if this shieldset can be used in the game.
179         bool validate() const;
180
181         //! Check to see if the number of shields is sufficient.
182         bool validateNumberOfShields() const;
183
184         //! Check to see if the images for the shieldset are supplied.
185         bool validateShieldImages(Shield::Colour c) const;
186
187
188         // Methods that operate on the class data and also modify the class.
189
190         //! Load images associated with this shieldset.
191         void instantiateImages();
192
193         //! Destroy images associated with this shieldset.
194         void uninstantiateImages();
195
196
197         // Static Methods
198
199         //! Create a shieldset from the given shieldset configuration file.
200         static Shieldset *create(std::string filename);
201
202         //! Return a list of shieldset subdirs in the system collection.
203         static std::list<std::string> scanSystemCollection();
204
205         //! Return a list of shieldset subdirs in the users personal collection.
206         static std::list<std::string> scanUserCollection();
207
208     private:
209
210         //! Callback function to load Shield objects into the Shieldset.
211         bool loadShield(std::string tag, XML_Helper* helper);
212
213         // DATA
214
215         //! A unique numeric identifier among all shieldset.
216         guint32 d_id;
217
218         //! The name of the Shieldset.
219         /**
220          * This equates to the shieldset.d_name XML entity in the shieldset
221          * configuration file.
222          * This name appears in the dialogs where the user is asked to 
223          * select a particular Shieldset.
224          */
225         std::string d_name;
226
227         //! The copyright holders of the shieldset.
228         std::string d_copyright;
229
230         //! The license of the shieldset.
231         std::string d_license;
232
233         //! The description of the shieldset.
234         /**
235          * Equates to the shieldset.d_info XML entity in the shieldset 
236          * configuration file.
237          */
238         std::string d_info;
239
240         //! The subdirectory of the Shieldset.
241         /**
242          * This is the name of the subdirectory that the Shieldset files are
243          * residing in.  It does not contain a path (e.g. no slashes).
244          * Shieldset directories sit in the shield/ directory.
245          */
246         std::string d_subdir;
247
248         //! The number of pixels high the small shield occupies onscreen.
249         /**
250          * Equates to the shieldset.d_small_height XML entity in the shieldset 
251          * configuration file.
252          */
253         guint32 d_small_height;
254
255         //! The number of pixels wide the small shield occupies onscreen.
256         /**
257          * Equates to the shieldset.d_small_width XML entity in the shieldset 
258          * configuration file.
259          */
260         guint32 d_small_width;
261
262         //! The number of pixels high the medium shield occupies onscreen.
263         /**
264          * Equates to the shieldset.d_medium_height XML entity in the shieldset 
265          * configuration file.
266          */
267         guint32 d_medium_height;
268
269         //! The number of pixels wide the medium shield occupies onscreen.
270         /**
271          * Equates to the shieldset.d_medium_width XML entity in the shieldset 
272          * configuration file.
273          */
274         guint32 d_medium_width;
275
276         //! The number of pixels high the large shield occupies onscreen.
277         /**
278          * Equates to the shieldset.d_large_height XML entity in the shieldset 
279          * configuration file.
280          */
281         guint32 d_large_height;
282
283         //! The number of pixels wide the large shield occupies onscreen.
284         /**
285          * Equates to the shieldset.d_large_width XML entity in the shieldset 
286          * configuration file.
287          */
288         guint32 d_large_width;
289 };
290
291 #endif // SHIELDSET_H
292