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
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.
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.
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
25 #include "armyproto.h"
26 #include "xmlhelper.h"
28 #include "gui/image-helpers.h"
31 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
33 std::string ArmyProto::d_tag = "armyproto";
35 ArmyProto::ArmyProto(const ArmyProto& a)
37 d_defends_ruins(a.d_defends_ruins),
38 d_awardable(a.d_awardable), d_image_name(a.d_image_name),
41 for (unsigned int c = Shield::WHITE; c <= Shield::NEUTRAL; c++)
43 d_image_name[c] = a.d_image_name[c];
44 d_image[c] = a.d_image[c];
45 d_mask[c] = a.d_mask[c];
49 ArmyProto::ArmyProto()
51 d_defends_ruins(false), d_awardable(false), d_gender(Hero::NONE)
53 for (unsigned int c = Shield::WHITE; c <= Shield::NEUTRAL; c++)
61 ArmyProto::ArmyProto(XML_Helper* helper)
62 :ArmyProtoBase(helper), d_defends_ruins(false), d_awardable(false)
64 helper->getData(d_image_name[Shield::WHITE], "image_white");
65 helper->getData(d_image_name[Shield::GREEN], "image_green");
66 helper->getData(d_image_name[Shield::YELLOW], "image_yellow");
67 helper->getData(d_image_name[Shield::LIGHT_BLUE], "image_light_blue");
68 helper->getData(d_image_name[Shield::RED], "image_red");
69 helper->getData(d_image_name[Shield::DARK_BLUE], "image_dark_blue");
70 helper->getData(d_image_name[Shield::ORANGE], "image_orange");
71 helper->getData(d_image_name[Shield::BLACK], "image_black");
72 helper->getData(d_image_name[Shield::NEUTRAL], "image_neutral");
73 helper->getData(d_defends_ruins,"defends_ruins");
74 helper->getData(d_awardable,"awardable");
75 std::string gender_str;
76 if (!helper->getData(gender_str, "gender"))
77 d_gender = Hero::NONE;
79 d_gender = Hero::genderFromString(gender_str);
80 for (unsigned int c = Shield::WHITE; c <= Shield::NEUTRAL; c++)
87 ArmyProto::~ArmyProto()
91 bool ArmyProto::save(XML_Helper* helper) const
95 retval &= helper->openTag(d_tag);
97 retval &= saveData(helper);
99 retval &= helper->closeTag();
104 bool ArmyProto::saveData(XML_Helper* helper) const
108 retval &= ArmyProtoBase::saveData(helper);
109 retval &= helper->saveData("image_white", d_image_name[Shield::WHITE]);
110 retval &= helper->saveData("image_green", d_image_name[Shield::GREEN]);
111 retval &= helper->saveData("image_yellow", d_image_name[Shield::YELLOW]);
112 retval &= helper->saveData("image_light_blue",
113 d_image_name[Shield::LIGHT_BLUE]);
114 retval &= helper->saveData("image_red", d_image_name[Shield::RED]);
115 retval &= helper->saveData("image_dark_blue",
116 d_image_name[Shield::DARK_BLUE]);
117 retval &= helper->saveData("image_orange", d_image_name[Shield::ORANGE]);
118 retval &= helper->saveData("image_black", d_image_name[Shield::BLACK]);
119 retval &= helper->saveData("image_neutral", d_image_name[Shield::NEUTRAL]);
120 retval &= helper->saveData("awardable", d_awardable);
121 retval &= helper->saveData("defends_ruins", d_defends_ruins);
122 std::string gender_str = Hero::genderToString(Hero::Gender(d_gender));
123 retval &= helper->saveData("gender", gender_str);
128 bool ArmyProto::instantiateImages(int tilesize, Shield::Colour c, std::string image_filename)
132 if (image_filename == "")
134 // load the army picture. This is done here to avoid confusion
135 // since the armies are used as prototypes as well as actual units in the
137 // The army image consists of two halves. On the left is the army image,
138 // on the right the mask.
139 std::vector<PixMask*> half;
140 half = disassemble_row(image_filename, 2);
141 PixMask::scale(half[0], tilesize, tilesize);
142 PixMask::scale(half[1], tilesize, tilesize);
144 setImage(c, half[0]);
150 void ArmyProto::instantiateImages(Armyset *armyset)
152 for (unsigned int c = Shield::WHITE; c <= Shield::NEUTRAL; c++)
154 std::string file = "";
155 if (getImageName(Shield::Colour(c)).empty() == false)
156 file = armyset->getFile(getImageName(Shield::Colour(c)));
157 instantiateImages(armyset->getTileSize(), Shield::Colour(c), file);
161 void ArmyProto::uninstantiateImages()
163 for (unsigned int c = Shield::WHITE; c <= Shield::NEUTRAL; c++)
165 if (getImage(Shield::Colour(c)))
167 delete getImage(Shield::Colour(c));
168 setImage(Shield::Colour(c), NULL);
170 if (getMask(Shield::Colour(c)))
172 delete getMask(Shield::Colour(c));
173 setMask(Shield::Colour(c), NULL);
178 ArmyProto * ArmyProto::createScout()
180 ArmyProto *basearmy = new ArmyProto();
181 basearmy->setMoveBonus(Tile::FOREST | Tile::HILLS);
182 basearmy->setMaxMoves(50);
186 ArmyProto * ArmyProto::createBat()
188 //oh no, it's the bat!
189 ArmyProto *basearmy = new ArmyProto();
190 basearmy->setMoveBonus(Tile::FOREST | Tile::HILLS | Tile::SWAMP |
191 Tile::WATER | Tile::MOUNTAIN);
192 basearmy->setMaxMoves(50);