33
33
//#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
36
//=======================================================================
37
36
QuestCitySack::QuestCitySack (QuestsManager& mgr, guint32 hero)
38
: Quest(mgr, hero, Quest::CITYSACK)
37
: Quest(mgr, hero, Quest::CITYSACK)
41
City* c = chooseToSack(getHero()->getOwner());
42
assert(c); // should never fail because isFeasible is checked first
40
City* c = chooseToSack(getHero()->getOwner());
41
assert(c); // should never fail because isFeasible is checked first
45
d_targets.push_back(c->getPos());
46
debug("city_id = " << d_city);
44
d_targets.push_back(c->getPos());
45
debug("city_id = " << d_city);
49
//=======================================================================
50
49
QuestCitySack::QuestCitySack (QuestsManager& q_mgr, XML_Helper* helper)
51
: Quest(q_mgr, helper)
50
: Quest(q_mgr, helper)
53
// let us stay in touch with the world...
54
helper->getData(d_city, "city");
55
d_targets.push_back(getCity()->getPos());
52
// let us stay in touch with the world...
53
helper->getData(d_city, "city");
54
d_targets.push_back(getCity()->getPos());
58
//=======================================================================
59
58
QuestCitySack::QuestCitySack (QuestsManager& mgr, guint32 hero, guint32 target)
60
: Quest(mgr, hero, Quest::CITYSACK)
59
: Quest(mgr, hero, Quest::CITYSACK)
63
d_targets.push_back(getCity()->getPos());
62
d_targets.push_back(getCity()->getPos());
66
//=======================================================================
67
66
bool QuestCitySack::isFeasible(guint32 heroId)
69
68
if (QuestCitySack::chooseToSack(getHeroById(heroId)->getOwner()))
73
//=======================================================================
74
73
bool QuestCitySack::save(XML_Helper* helper) const
78
retval &= helper->openTag(Quest::d_tag);
79
retval &= Quest::save(helper);
80
retval &= helper->saveData("city", d_city);
81
retval &= helper->closeTag();
77
retval &= helper->openTag(Quest::d_tag);
78
retval &= Quest::save(helper);
79
retval &= helper->saveData("city", d_city);
80
retval &= helper->closeTag();
85
//=======================================================================
86
85
std::string QuestCitySack::getProgress() const
88
return _("You aren't afraid of doing it, are you?");
87
return _("You aren't afraid of doing it, are you?");
90
//=======================================================================
91
90
void QuestCitySack::getSuccessMsg(std::queue<std::string>& msgs) const
93
msgs.push(_("The priests thank you for sacking this evil place."));
92
msgs.push(_("The priests thank you for sacking this evil place."));
95
//=======================================================================
96
95
void QuestCitySack::getExpiredMsg(std::queue<std::string>& msgs) const
98
const City* c = getCity();
99
msgs.push(String::ucompose(_("The sacking of \"%1\" could not be accomplished."),
97
const City* c = getCity();
98
msgs.push(String::ucompose(_("The sacking of \"%1\" could not be accomplished."),
102
//=======================================================================
103
102
City* QuestCitySack::getCity() const
105
Citylist* cl = Citylist::getInstance();
106
for (Citylist::iterator it = cl->begin(); it != cl->end(); it++)
107
if ((*it)->getId() == d_city)
104
Citylist* cl = Citylist::getInstance();
105
for (Citylist::iterator it = cl->begin(); it != cl->end(); it++)
106
if ((*it)->getId() == d_city)
112
//=======================================================================
113
112
void QuestCitySack::initDescription()
115
const City* c = getCity();
116
d_description = String::ucompose (_("You must take over and sack the city of \"%1\"."), c->getName());
114
const City* c = getCity();
115
d_description = String::ucompose (_("You must take over and sack the city of \"%1\"."), c->getName());
118
//=======================================================================
119
118
City * QuestCitySack::chooseToSack(Player *p)
121
std::vector<City*> cities;
123
// Collect all cities
124
Citylist* cl = Citylist::getInstance();
125
for (Citylist::iterator it = cl->begin(); it != cl->end(); ++it)
126
if (!(*it)->isBurnt() && (*it)->getOwner() != p &&
127
(*it)->getNoOfProductionBases() > 1 &&
128
(*it)->getOwner() != Playerlist::getInstance()->getNeutral())
129
cities.push_back((*it));
131
// Find a suitable city for us to sack
135
return cities[rand() % cities.size()];
120
std::vector<City*> cities;
122
// Collect all cities
123
Citylist* cl = Citylist::getInstance();
124
for (Citylist::iterator it = cl->begin(); it != cl->end(); ++it)
125
if (!(*it)->isBurnt() && (*it)->getOwner() != p &&
126
(*it)->getNoOfProductionBases() > 1 &&
127
(*it)->getOwner() != Playerlist::getInstance()->getNeutral())
128
cities.push_back((*it));
130
// Find a suitable city for us to sack
134
return cities[rand() % cities.size()];
138
137
void QuestCitySack::armyDied(Army *a, bool heroIsCulprit)