initial commit, lordsawar source, slightly modified
[lordsawar] / src / heroproto.cpp
1 // Copyright (C) 2008 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 #include <iostream>
19 #include <sstream>
20 #include <algorithm>
21 #include "armyproto.h"
22 #include "heroproto.h"
23 #include "xmlhelper.h"
24
25 std::string HeroProto::d_tag = "heroproto";
26
27 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
28 #define debug(x)
29
30 HeroProto::HeroProto(const HeroProto& a)
31     :ArmyProto(a), OwnerId(a), d_gender(a.d_gender)
32 {
33 }
34
35 HeroProto::HeroProto(const ArmyProto& a)
36     :ArmyProto(a), OwnerId()
37 {
38   d_gender = a.getGender();
39 }
40
41 HeroProto::HeroProto()
42   :ArmyProto(), OwnerId(), d_gender(Hero::FEMALE)
43 {
44 }
45
46 HeroProto::~HeroProto()
47 {
48 }
49
50 HeroProto::HeroProto(XML_Helper* helper)
51   :ArmyProto(helper), OwnerId(helper)
52 {
53   std::string gender_str;
54   if (!helper->getData(gender_str, "gender"))
55     d_gender = Hero::NONE;
56   else
57     d_gender = Hero::genderFromString(gender_str);
58   helper->getData(d_type_id, "type");
59   helper->getData(d_armyset, "armyset");
60 }
61
62 bool HeroProto::save(XML_Helper* helper) const
63 {
64   bool retval = true;
65
66   retval &= helper->openTag(HeroProto::d_tag);
67
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);
74
75   retval &= helper->closeTag();
76
77   return retval;
78 }
79