1 // Copyright (C) 2007, 2008, 2009 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
19 #include <sigc++/functors/mem_fun.h>
20 #include "ucompose.hpp"
22 #include "QPillageGold.h"
23 #include "QuestsManager.h"
24 #include "playerlist.h"
28 //#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
31 QuestPillageGold::QuestPillageGold(QuestsManager& q_mgr, guint32 hero)
32 : Quest(q_mgr, hero, Quest::PILLAGEGOLD), d_pillaged(0)
34 //pick an amount of gold to sack and pillage
35 d_to_pillage = 850 + (rand() % 630);
40 QuestPillageGold::QuestPillageGold(QuestsManager& q_mgr, XML_Helper* helper)
41 : Quest(q_mgr, helper)
43 helper->getData(d_to_pillage, "to_pillage");
44 helper->getData(d_pillaged, "pillaged");
49 QuestPillageGold::QuestPillageGold(QuestsManager& q_mgr, guint32 hero, guint32 gold)
50 : Quest(q_mgr, hero, Quest::PILLAGEGOLD), d_pillaged(0)
56 bool QuestPillageGold::save(XML_Helper *helper) const
60 retval &= helper->openTag(Quest::d_tag);
61 retval &= Quest::save(helper);
62 retval &= helper->saveData("to_pillage", d_to_pillage);
63 retval &= helper->saveData("pillaged", d_pillaged);
64 retval &= helper->closeTag();
69 std::string QuestPillageGold::getProgress() const
71 return String::ucompose(_("You have already stolen %1 gold."), d_pillaged);
74 void QuestPillageGold::getSuccessMsg(std::queue<std::string>& msgs) const
76 msgs.push(String::ucompose(_("You have managed to sack and pillage %1 gold."), d_pillaged));
77 msgs.push(_("Well done!"));
80 void QuestPillageGold::getExpiredMsg(std::queue<std::string>& msgs) const
82 // This quest should never expire, so this is just a dummy function
85 void QuestPillageGold::initDescription()
87 d_description = String::ucompose(_("You shall sack and pillage %1 gold from thy mighty foes."), d_to_pillage);
90 void QuestPillageGold::armyDied(Army *a, bool heroIsCulprit)
93 //this quest does nothing when an army dies
96 void QuestPillageGold::cityAction(City *c, CityDefeatedAction action,
97 bool heroIsCulprit, int gold)
99 if (isPendingDeletion())
102 if (!h || h->getHP() <= 0)
107 if (action == CITY_DEFEATED_SACK || action == CITY_DEFEATED_PILLAGE)
112 if (d_pillaged > d_to_pillage)
114 d_pillaged = d_to_pillage;
115 d_q_mgr.questCompleted(d_hero);