initial commit, lordsawar source, slightly modified
[lordsawar] / src / armyproto.h
1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007, 2008 Ole Laursen
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 3 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
20 //  02110-1301, USA.
21
22 #ifndef ARMY_PROTO_H
23 #define ARMY_PROTO_H
24
25 #include <gtkmm.h>
26 #include <string>
27 #include "PixMask.h"
28 #include "shield.h"
29 #include "hero.h"
30 #include "armyprotobase.h"
31
32 class XML_Helper;
33 class Armyset;
34
35 class ArmyProto : public ArmyProtoBase
36 {
37     public:
38         //! The xml tag of this object in an armyset configuration file.
39         static std::string d_tag; 
40
41         //! Copy constructor.
42         ArmyProto(const ArmyProto& armyproto);
43
44         //! Loading constructor.
45         ArmyProto(XML_Helper* helper);
46         
47         //! Default constructor.  Create an empty army prototype.
48         ArmyProto();
49
50         //! Destructor.
51         virtual ~ArmyProto();
52
53
54         // Set Methods
55         
56         //! Sets the filename of the image.
57         void setImageName(Shield::Colour c,std::string name) {d_image_name[c] = name;}
58
59         //! Set the basic image of the Army.
60         void setImage(Shield::Colour c, PixMask* image) {d_image[c] = image;};
61
62         //! Set the image mask of the unit type (for player colours).
63         void setMask(Shield::Colour c, PixMask* mask) {d_mask[c] = mask;};
64
65         //! Sets whether or not this Army prototype can found in a ruin.
66         void setDefendsRuins(bool defends) {d_defends_ruins = defends; }
67
68         /**
69          * Sets whether or not this Army prototype can be a reward for
70          * Quest, or if Army units of this kind can accompany a new
71          * Hero when one emerges in a City.
72          */
73         //! Sets the awardable state of an Army prototype.
74         void setAwardable (bool awardable) {d_awardable = awardable; }
75
76         //! Sets the gender of the army prototype.
77         void setGender(Hero::Gender g) {d_gender = g;};
78         
79
80         // Get Methods
81         
82         //! Returns the basename of the picture's filename
83         /**
84          * Returns the filename that holds the image for this Army.
85          * The filename does not have a path, and the filename does
86          * not have an extension (e.g. .png).
87          */
88         std::string getImageName(Shield::Colour c) const {return d_image_name[c];}
89
90         //! Get the image of the army prototype. 
91         PixMask* getImage(Shield::Colour c) const {return d_image[c];};
92
93         //! Returns the mask (read-only) for player colors.
94         PixMask* getMask(Shield::Colour c) const {return d_mask[c];}
95
96         //! Gets whether or not this army type can found in a ruin.
97         bool getDefendsRuins() const {return d_defends_ruins; }
98
99         /**
100          * Gets whether or not this army can be a reward for completing a 
101          * Quest, or if an Army unit of this type can accompany a new
102          * Hero when one emerges in a City.
103          */
104         //! Gets the awardable state of the Army.
105         bool getAwardable() const {return d_awardable; }
106
107         //! Returns whether or not the Army prototype is a Hero.
108         bool isHero() const {return d_gender != Hero::NONE;};
109         
110         //! Returns the gender of the army prototype.
111         Hero::Gender getGender() const {return d_gender;};
112
113         // Methods that operate on class data and modify the class.
114
115         //! Load the pictures associated with this ArmyProto object.
116         void instantiateImages(Armyset *armyset);
117
118         //! Load the ArmyProto image in the given filename.
119         bool instantiateImages(int tilesize, Shield::Colour c, std::string image_filename);
120
121         //! Destroy the images associated with this ArmyProto object.
122         void uninstantiateImages();
123
124         // Methods that operate on class data and do not modify the class.
125
126         //! Saves the Army prototype to an opened armyset file.
127         virtual bool save(XML_Helper* helper) const;
128         
129         // Static Methods
130         
131         //! Create an ArmyProto object that can walk well in hills and forest.
132         static ArmyProto * createScout();
133
134         //! Create an ArmyProto object that can fly.
135         static ArmyProto * createBat();
136
137     protected:
138
139         //! Callback to read this object from an opened file.
140         bool saveData(XML_Helper* helper) const;
141
142     private:
143
144         //! The picture of the Army prototype.
145         /**
146          * There is an image for each player, plus the neutral player.
147          */
148         PixMask* d_image[MAX_PLAYERS + 1];
149
150         //! The mask portion of the Army prototype picture.
151         PixMask* d_mask[MAX_PLAYERS + 1];
152         
153         //! Whether or not the Army prototype can defend a Ruin.
154         /**
155          * Some Army unit can be the guardian of a Ruin.  Hero units fight
156          * a single Army unit of this kind when they search a Ruin.  
157          * d_defends_ruin indicates whether this Army unit can defend a Ruin 
158          * or not.
159          *
160          * This value does not change during gameplay.
161          */
162         bool d_defends_ruins;
163
164         //! The awardable status of the Army prototype.
165         /**
166          * Whether or not this Army prototype can be a reward for a Quest, 
167          * or if Army units of this kind can accompany a new Hero when one 
168          * emerges in a City.
169          *
170          * This value does not change during gameplay.
171          */
172         bool d_awardable;
173
174         //! The basename of the file containing the image for this Army proto.
175         /**
176          * This value does not contain a path, and does not contain an
177          * extension (e.g. .png).
178          *
179          * There is an image filename for each player, plus the neutral player.
180          */
181         std::string d_image_name[MAX_PLAYERS + 1];
182
183         //! The gender of this object.
184         /**
185          * Heroes have genders, and regular armies do not.
186          */
187         Hero::Gender d_gender;
188 };
189
190 #endif // ARMY_PROTO_H