1 // Copyright (C) 2008 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
21 #include "armyproto.h"
22 #include "heroproto.h"
23 #include "xmlhelper.h"
25 std::string HeroProto::d_tag = "heroproto";
27 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
30 HeroProto::HeroProto(const HeroProto& a)
31 :ArmyProto(a), OwnerId(a), d_gender(a.d_gender)
35 HeroProto::HeroProto(const ArmyProto& a)
36 :ArmyProto(a), OwnerId()
38 d_gender = a.getGender();
41 HeroProto::HeroProto()
42 :ArmyProto(), OwnerId(), d_gender(Hero::FEMALE)
46 HeroProto::~HeroProto()
50 HeroProto::HeroProto(XML_Helper* helper)
51 :ArmyProto(helper), OwnerId(helper)
53 std::string gender_str;
54 if (!helper->getData(gender_str, "gender"))
55 d_gender = Hero::NONE;
57 d_gender = Hero::genderFromString(gender_str);
58 helper->getData(d_type_id, "type");
59 helper->getData(d_armyset, "armyset");
62 bool HeroProto::save(XML_Helper* helper) const
66 retval &= helper->openTag(HeroProto::d_tag);
68 retval &= ArmyProto::saveData(helper);
69 std::string gender_str = Hero::genderToString(Hero::Gender(d_gender));
70 retval &= helper->saveData("gender", gender_str);
71 retval &= OwnerId::save(helper);
72 retval &= helper->saveData("armyset", d_armyset);
73 retval &= helper->saveData("type", d_type_id);
75 retval &= helper->closeTag();