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
23 #include "playerlist.h"
25 #include "xmlhelper.h"
27 std::string Triumphs::d_tag = "triumphs";
31 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<flush;}
37 memset(d_triumph, 0, sizeof(d_triumph));
40 Triumphs::Triumphs(XML_Helper* helper)
42 for (unsigned int i = 0; i < 5; i++)
45 std::stringstream stally;
47 switch (TriumphType(i))
50 helper->getData(tally, "hero");
53 helper->getData(tally, "normal");
56 helper->getData(tally, "special");
59 helper->getData(tally, "ship");
62 helper->getData(tally, "flag");
66 for (unsigned int j = 0; j < MAX_PLAYERS; j++)
69 d_triumph[j][i] = val;
74 Triumphs::Triumphs(const Triumphs& triumphs)
76 memcpy (d_triumph, triumphs.d_triumph, sizeof (d_triumph));
83 bool Triumphs::save(XML_Helper* helper) const
87 retval &= helper->openTag(Triumphs::d_tag);
88 for (unsigned int i = 0; i < 5; i++)
90 std::stringstream tally;
91 for (unsigned int j = 0; j < MAX_PLAYERS; j++)
92 tally << d_triumph[j][i] << " ";
93 switch (TriumphType(i))
96 retval &= helper->saveData("hero", tally.str());
99 retval &= helper->saveData("normal", tally.str());
102 retval &= helper->saveData("special", tally.str());
105 retval &= helper->saveData("ship", tally.str());
108 retval &= helper->saveData("flag", tally.str());
113 retval &= helper->closeTag();
118 void Triumphs::tallyTriumph(Player *p, TriumphType type)
120 //ignore monsters in a ruin who aren't owned by a player
123 guint32 id = p->getId();
124 //let's not tally neutrals
125 if (p == Playerlist::getInstance()->getNeutral())
127 //we (this player) have killed P's army. it was of type TYPE.
128 d_triumph[id][type]++;