~ubuntu-branches/ubuntu/maverick/lordsawar/maverick

« back to all changes in this revision

Viewing changes to src/QCitySack.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2010-04-10 09:29:33 UTC
  • mfrom: (1.1.9 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100410092933-23uq4dxig30kmtcw
Tags: 0.1.8-1
* New upstream release.
* Add misc:Depends for -data package.
* Bump Standards Version to 3.8.4. (No changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
//#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
34
34
#define debug(x)
35
35
 
36
 
//=======================================================================
37
36
QuestCitySack::QuestCitySack (QuestsManager& mgr, guint32 hero) 
38
 
    : Quest(mgr, hero, Quest::CITYSACK)
 
37
  : Quest(mgr, hero, Quest::CITYSACK)
39
38
{
40
 
    // find us a victim
41
 
    City* c = chooseToSack(getHero()->getOwner());
42
 
    assert(c);      // should never fail because isFeasible is checked first
 
39
  // find us a victim
 
40
  City* c = chooseToSack(getHero()->getOwner());
 
41
  assert(c);      // should never fail because isFeasible is checked first
43
42
 
44
 
    d_city = c->getId();
45
 
    d_targets.push_back(c->getPos());
46
 
    debug("city_id = " << d_city);
47
 
    initDescription();
 
43
  d_city = c->getId();
 
44
  d_targets.push_back(c->getPos());
 
45
  debug("city_id = " << d_city);
 
46
  initDescription();
48
47
}
49
 
//=======================================================================
 
48
 
50
49
QuestCitySack::QuestCitySack (QuestsManager& q_mgr, XML_Helper* helper) 
51
 
     : Quest(q_mgr, helper)
 
50
  : Quest(q_mgr, helper)
52
51
{
53
 
    // let us stay in touch with the world...
54
 
    helper->getData(d_city, "city");
55
 
    d_targets.push_back(getCity()->getPos());
56
 
    initDescription();
 
52
  // let us stay in touch with the world...
 
53
  helper->getData(d_city, "city");
 
54
  d_targets.push_back(getCity()->getPos());
 
55
  initDescription();
57
56
}
58
 
//=======================================================================
 
57
 
59
58
QuestCitySack::QuestCitySack (QuestsManager& mgr, guint32 hero, guint32 target) 
60
 
    : Quest(mgr, hero, Quest::CITYSACK)
 
59
  : Quest(mgr, hero, Quest::CITYSACK)
61
60
{
62
 
    d_city = target;
63
 
    d_targets.push_back(getCity()->getPos());
64
 
    initDescription();
 
61
  d_city = target;
 
62
  d_targets.push_back(getCity()->getPos());
 
63
  initDescription();
65
64
}
66
 
//=======================================================================
 
65
 
67
66
bool QuestCitySack::isFeasible(guint32 heroId)
68
67
{
69
68
  if (QuestCitySack::chooseToSack(getHeroById(heroId)->getOwner()))
70
69
    return true;
71
70
  return false;
72
71
}
73
 
//=======================================================================
 
72
 
74
73
bool QuestCitySack::save(XML_Helper* helper) const
75
74
{
76
 
    bool retval = true;
77
 
 
78
 
    retval &= helper->openTag(Quest::d_tag);
79
 
    retval &= Quest::save(helper);
80
 
    retval &= helper->saveData("city", d_city);
81
 
    retval &= helper->closeTag();
82
 
 
83
 
    return retval;
 
75
  bool retval = true;
 
76
 
 
77
  retval &= helper->openTag(Quest::d_tag);
 
78
  retval &= Quest::save(helper);
 
79
  retval &= helper->saveData("city", d_city);
 
80
  retval &= helper->closeTag();
 
81
 
 
82
  return retval;
84
83
}
85
 
//=======================================================================
 
84
 
86
85
std::string QuestCitySack::getProgress() const
87
86
{
88
 
    return _("You aren't afraid of doing it, are you?");
 
87
  return _("You aren't afraid of doing it, are you?");
89
88
}
90
 
//=======================================================================
 
89
 
91
90
void QuestCitySack::getSuccessMsg(std::queue<std::string>& msgs) const
92
91
{
93
 
    msgs.push(_("The priests thank you for sacking this evil place."));
 
92
  msgs.push(_("The priests thank you for sacking this evil place."));
94
93
}
95
 
//=======================================================================
 
94
 
96
95
void QuestCitySack::getExpiredMsg(std::queue<std::string>& msgs) const
97
96
{
98
 
    const City* c = getCity();
99
 
    msgs.push(String::ucompose(_("The sacking of \"%1\" could not be accomplished."), 
100
 
                               c->getName()));
 
97
  const City* c = getCity();
 
98
  msgs.push(String::ucompose(_("The sacking of \"%1\" could not be accomplished."), 
 
99
                             c->getName()));
101
100
}
102
 
//=======================================================================
 
101
 
103
102
City* QuestCitySack::getCity() const
104
103
{
105
 
    Citylist* cl = Citylist::getInstance();
106
 
    for (Citylist::iterator it = cl->begin(); it != cl->end(); it++)
107
 
        if ((*it)->getId() == d_city)
108
 
            return (*it);
 
104
  Citylist* cl = Citylist::getInstance();
 
105
  for (Citylist::iterator it = cl->begin(); it != cl->end(); it++)
 
106
    if ((*it)->getId() == d_city)
 
107
      return (*it);
109
108
 
110
 
    return 0;
 
109
  return 0;
111
110
}
112
 
//=======================================================================
 
111
 
113
112
void QuestCitySack::initDescription()
114
113
{
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());
117
116
}
118
 
//=======================================================================
 
117
 
119
118
City * QuestCitySack::chooseToSack(Player *p)
120
119
{
121
 
    std::vector<City*> cities;
122
 
 
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));
130
 
 
131
 
    // Find a suitable city for us to sack
132
 
    if (cities.empty())
133
 
        return 0;
134
 
 
135
 
    return cities[rand() % cities.size()];
 
120
  std::vector<City*> cities;
 
121
 
 
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));
 
129
 
 
130
  // Find a suitable city for us to sack
 
131
  if (cities.empty())
 
132
    return 0;
 
133
 
 
134
  return cities[rand() % cities.size()];
136
135
}
137
 
         
 
136
 
138
137
void QuestCitySack::armyDied(Army *a, bool heroIsCulprit)
139
138
{
140
139
  ;
144
143
void QuestCitySack::cityAction(City *c, CityDefeatedAction action, 
145
144
                               bool heroIsCulprit, int gold)
146
145
{
147
 
  if (!isActive())
 
146
  if (isPendingDeletion())
148
147
    return;
 
148
  Hero *h = getHero();
 
149
  if (!h || h->getHP() <= 0)
 
150
    {
 
151
      deactivate();
 
152
      return;
 
153
    }
149
154
  if (!c)
150
155
    return;
151
156
  if (c->getId() != d_city)