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, 2010, 2011, 2014, 2015, 2020 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 #pragma once 23 #ifndef ARMY_PROTO_H 24 #define ARMY_PROTO_H 25 26 #include <gtkmm.h> 27 #include "PixMask.h" 28 #include "shield.h" 29 #include "armyprotobase.h" 30 #include "hero.h" 31 32 class XML_Helper; 33 class Tar_Helper; 34 35 //! An army prototype object. Appears in an armyset file. 36 class ArmyProto : public ArmyProtoBase 37 { 38 public: 39 //! The xml tag of this object in an armyset configuration file. 40 static Glib::ustring d_tag; 41 42 //! Copy constructor. 43 ArmyProto(const ArmyProto& armyproto); 44 45 //! Loading constructor. 46 ArmyProto(XML_Helper* helper); 47 48 //! Default constructor. Create an empty army prototype. 49 ArmyProto(); 50 51 //! Destructor. 52 ~ArmyProto(); 53 54 55 // Set Methods 56 57 //! Sets the Type Id of the Army. setId(guint32 id)58 void setId(guint32 id) {d_id = id;}; 59 60 //! Sets the filename of the image. setImageName(Shield::Colour c,Glib::ustring name)61 void setImageName(Shield::Colour c,Glib::ustring name) {d_image_name[c] = name;} 62 63 //! Set the basic image of the Army. setImage(Shield::Colour c,PixMask * image)64 void setImage(Shield::Colour c, PixMask* image) {d_image[c] = image;}; 65 66 //! Set the image mask of the unit type (for player colours). setMask(Shield::Colour c,PixMask * mask)67 void setMask(Shield::Colour c, PixMask* mask) {d_mask[c] = mask;}; 68 69 //! Clear the names, images and masks of the army. 70 void clearImage (Shield::Colour c, bool clear_name = true); 71 72 //! Sets whether or not this Army prototype can found in a ruin. setDefendsRuins(bool defends)73 void setDefendsRuins(bool defends) {d_defends_ruins = defends; } 74 75 /** 76 * Sets whether or not this Army prototype can be a reward for 77 * Quest, or if Army units of this kind can accompany a new 78 * Hero when one emerges in a City. 79 */ 80 //! Sets the awardable state of an Army prototype. setAwardable(bool awardable)81 void setAwardable (bool awardable) {d_awardable = awardable; } 82 83 //! Sets the gender of the army prototype. setGender(Hero::Gender g)84 void setGender(Hero::Gender g) {d_gender = g;}; 85 86 87 // Get Methods 88 89 //! Returns the Type Id of this Army prototype. getId()90 guint32 getId() const {return d_id;}; 91 92 //! Returns the basename of the picture's filename 93 /** 94 * Returns the filename that holds the image for this Army. 95 * The filename does not have a path, and the filename does 96 * not have an extension (e.g. .png). 97 */ getImageName(Shield::Colour c)98 Glib::ustring getImageName(Shield::Colour c) const {return d_image_name[c];} 99 100 //! Get the image of the army prototype. getImage(Shield::Colour c)101 PixMask* getImage(Shield::Colour c) const {return d_image[c];}; 102 103 //! Returns the mask (read-only) for player colors. getMask(Shield::Colour c)104 PixMask* getMask(Shield::Colour c) const {return d_mask[c];} 105 106 //! Gets whether or not this army type can found in a ruin. getDefendsRuins()107 bool getDefendsRuins() const {return d_defends_ruins; } 108 109 /** 110 * Gets whether or not this army can be a reward for completing a 111 * Quest, or if an Army unit of this type can accompany a new 112 * Hero when one emerges in a City. 113 */ 114 //! Gets the awardable state of the Army. getAwardable()115 bool getAwardable() const {return d_awardable; } 116 117 //! Returns whether or not the Army prototype is a Hero. isHero()118 bool isHero() const {return d_gender != Hero::NONE;}; 119 120 //! Returns the gender of the army prototype. getGender()121 Hero::Gender getGender() const {return d_gender;}; 122 123 // Methods that operate on class data and modify the class. 124 125 //! Load the pictures associated with this ArmyProto object. 126 void instantiateImages(guint32 tilesize, Tar_Helper *t, bool scale, 127 bool &broken); 128 129 //! Load the ArmyProto image in the given filename. 130 void loadImage(int tilesize, Shield::Colour c, Glib::ustring image_filename, bool scale, bool &broken); 131 132 //! Instantiate the image for the given colour from the lwa file. 133 bool instantiateImage (Glib::ustring cfgfile, guint32 ts, 134 Shield::Colour col); 135 136 //! Destroy the images associated with this ArmyProto object. 137 void uninstantiateImages(); 138 139 // Methods that operate on class data and do not modify the class. 140 141 //! Saves the Army prototype to an opened armyset file. 142 virtual bool save(XML_Helper* helper) const; 143 144 // Static Methods 145 146 //! Create an ArmyProto object that can walk well in hills and forest. 147 static ArmyProto * createScout(); 148 149 //! Create an ArmyProto object that can fly. 150 static ArmyProto * createBat(); 151 152 protected: 153 154 //! Callback to read this object from an opened file. 155 bool saveData(XML_Helper* helper) const; 156 157 private: 158 159 //! The Type Id of this Army prototype. 160 guint32 d_id; 161 162 //! The picture of the Army prototype. 163 /** 164 * There is an image for each player, plus the neutral player. 165 */ 166 PixMask* d_image[MAX_PLAYERS + 1]; 167 168 //! The mask portion of the Army prototype picture. 169 PixMask* d_mask[MAX_PLAYERS + 1]; 170 171 //! Whether or not the Army prototype can defend a Ruin. 172 /** 173 * Some Army unit can be the guardian of a Ruin. Hero units fight 174 * a single Army unit of this kind when they search a Ruin. 175 * d_defends_ruin indicates whether this Army unit can defend a Ruin 176 * or not. 177 * 178 * This value does not change during gameplay. 179 */ 180 bool d_defends_ruins; 181 182 //! The awardable status of the Army prototype. 183 /** 184 * Whether or not this Army prototype can be a reward for a Quest, 185 * or if Army units of this kind can accompany a new Hero when one 186 * emerges in a City. 187 * 188 * This value does not change during gameplay. 189 */ 190 bool d_awardable; 191 192 //! The basename of the file containing the image for this Army proto. 193 /** 194 * This value does not contain a path, and does not contain an 195 * extension (e.g. .png). 196 * 197 * There is an image filename for each player, plus the neutral player. 198 */ 199 Glib::ustring d_image_name[MAX_PLAYERS + 1]; 200 201 //! The gender of this object. 202 /** 203 * Heroes have genders, and regular armies do not. 204 */ 205 Hero::Gender d_gender; 206 }; 207 208 #endif // ARMY_PROTO_H 209