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

« back to all changes in this revision

Viewing changes to src/QEnemyArmytype.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:
40
40
  for (Playerlist::const_iterator pit = pl->begin(); pit != pl->end(); pit++)
41
41
    {
42
42
      if ((*pit) == p)
43
 
        continue;
 
43
        continue;
44
44
      sl = (*pit)->getStacklist();
45
45
      for (sit = sl->begin(); sit != sl->end(); sit++)
46
 
        {
47
 
          //is this stack not in a city?  no?  it's a target.
48
 
          if (GameMap::getCity((*sit)->getPos()) == NULL)
49
 
            targets.push_back((*sit)->getPos());
50
 
          for (it = (*sit)->begin(); it != (*sit)->end(); it++)
51
 
            {
52
 
              if ((*it)->getAwardable())
53
 
                {
54
 
                  specials.push_back((*it));
55
 
                }
 
46
        {
 
47
          //is this stack not in a city?  no?  it's a target.
 
48
          if (GameMap::getCity((*sit)->getPos()) == NULL)
 
49
            targets.push_back((*sit)->getPos());
 
50
          for (it = (*sit)->begin(); it != (*sit)->end(); it++)
 
51
            {
 
52
              if ((*it)->getAwardable())
 
53
                {
 
54
                  specials.push_back((*it));
 
55
                }
56
56
            }
57
 
        }
 
57
        }
58
58
    }
59
59
  if (specials.size() == 0)
60
60
    return -1;
64
64
 
65
65
//#define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
66
66
#define debug(x)
67
 
//=======================================================================
68
67
QuestEnemyArmytype::QuestEnemyArmytype(QuestsManager& q_mgr, guint32 hero)
69
 
    : Quest(q_mgr, hero, Quest::KILLARMYTYPE)
 
68
  : Quest(q_mgr, hero, Quest::KILLARMYTYPE)
70
69
{
71
 
    Player *p = getHero()->getOwner();
72
 
    
73
 
    // pick a victim
74
 
    d_type_to_kill = getVictimArmytype (p, d_targets);
75
 
    
76
 
    initDescription();
 
70
  Player *p = getHero()->getOwner();
 
71
 
 
72
  // pick a victim
 
73
  d_type_to_kill = getVictimArmytype (p, d_targets);
 
74
 
 
75
  initDescription();
77
76
}
78
 
//=======================================================================
 
77
 
79
78
QuestEnemyArmytype::QuestEnemyArmytype(QuestsManager& q_mgr, XML_Helper* helper) 
80
 
    : Quest(q_mgr, helper)
 
79
  : Quest(q_mgr, helper)
81
80
{
82
 
    helper->getData(d_type_to_kill, "type_to_kill");
 
81
  helper->getData(d_type_to_kill, "type_to_kill");
83
82
 
84
 
    initDescription();
 
83
  initDescription();
85
84
}
86
 
//=======================================================================
 
85
 
87
86
QuestEnemyArmytype::QuestEnemyArmytype(QuestsManager& q_mgr, guint32 hero,
88
 
                                       guint32 type_to_kill)
89
 
    : Quest(q_mgr, hero, Quest::KILLARMYTYPE)
 
87
                                       guint32 type_to_kill)
 
88
  : Quest(q_mgr, hero, Quest::KILLARMYTYPE)
90
89
{
91
 
    // pick a victim
92
 
    d_type_to_kill = type_to_kill;
93
 
    
94
 
    initDescription();
 
90
  // pick a victim
 
91
  d_type_to_kill = type_to_kill;
 
92
 
 
93
  initDescription();
95
94
}
96
 
//=======================================================================
 
95
 
97
96
bool QuestEnemyArmytype::save(XML_Helper *helper) const
98
97
{
99
 
    bool retval = true;
100
 
 
101
 
    retval &= helper->openTag(Quest::d_tag);
102
 
    retval &= Quest::save(helper);
103
 
    retval &= helper->saveData("type_to_kill", d_type_to_kill);
104
 
    retval &= helper->closeTag();
105
 
 
106
 
    return retval;
 
98
  bool retval = true;
 
99
 
 
100
  retval &= helper->openTag(Quest::d_tag);
 
101
  retval &= Quest::save(helper);
 
102
  retval &= helper->saveData("type_to_kill", d_type_to_kill);
 
103
  retval &= helper->closeTag();
 
104
 
 
105
  return retval;
107
106
}
108
 
//=======================================================================
 
107
 
109
108
std::string QuestEnemyArmytype::getProgress() const
110
109
{
111
 
    Armysetlist *al = Armysetlist::getInstance();
112
 
    guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
113
 
    const ArmyProto *a = al->getArmy(set, d_type_to_kill);
114
 
    return String::ucompose(
115
 
             _("You have not killed a unit of enemy %1 yet."), a->getName());
 
110
  Armysetlist *al = Armysetlist::getInstance();
 
111
  guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
 
112
  const ArmyProto *a = al->getArmy(set, d_type_to_kill);
 
113
  return String::ucompose(
 
114
                          _("You have not killed a unit of enemy %1 yet."), a->getName());
116
115
}
117
 
//=======================================================================
 
116
 
118
117
void QuestEnemyArmytype::getSuccessMsg(std::queue<std::string>& msgs) const
119
118
{
120
 
    Armysetlist *al = Armysetlist::getInstance();
121
 
    guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
122
 
    const ArmyProto *a = al->getArmy(set, d_type_to_kill);
123
 
    msgs.push(String::ucompose(_("You have killed a unit of enemy %1."), a->getName()));
124
 
    msgs.push(_("Well done!"));
 
119
  Armysetlist *al = Armysetlist::getInstance();
 
120
  guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
 
121
  const ArmyProto *a = al->getArmy(set, d_type_to_kill);
 
122
  msgs.push(String::ucompose(_("You have killed a unit of enemy %1."), a->getName()));
 
123
  msgs.push(_("Well done!"));
125
124
}
126
 
//=======================================================================
 
125
 
127
126
void QuestEnemyArmytype::getExpiredMsg(std::queue<std::string>& msgs) const
128
127
{
129
 
    // This quest should never expire, so this is just a dummy function
 
128
  // This quest should never expire, so this is just a dummy function
130
129
}
131
 
//=======================================================================
 
130
 
132
131
void QuestEnemyArmytype::initDescription()
133
132
{
134
 
    Armysetlist *al = Armysetlist::getInstance();
135
 
    guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
136
 
    const ArmyProto *a = al->getArmy(set, d_type_to_kill);
137
 
    d_description = String::ucompose(_("You must destroy a unit of enemy %1."), 
138
 
             a->getName());
 
133
  Armysetlist *al = Armysetlist::getInstance();
 
134
  guint32 set = Playerlist::getInstance()->getActiveplayer()->getArmyset();
 
135
  const ArmyProto *a = al->getArmy(set, d_type_to_kill);
 
136
  d_description = String::ucompose(_("You must destroy a unit of enemy %1."), 
 
137
                                   a->getName());
139
138
}
140
 
//=======================================================================
 
139
 
141
140
bool QuestEnemyArmytype::isFeasible(guint32 heroId)
142
141
{
143
142
  std::list< Vector<int> >targets;
146
145
    return true;
147
146
  return false;
148
147
}
 
148
 
149
149
void QuestEnemyArmytype::armyDied(Army *a, bool heroIsCulprit)
150
150
{
151
151
  //was it the army type we were after?
152
 
    
 
152
 
153
153
  debug("QuestEnemyArmytype: armyDied - pending = " << (int)d_pending);
154
 
    
155
 
  if (!isActive())
 
154
 
 
155
  if (!isPendingDeletion())
156
156
    return;
157
 
    
 
157
  Hero *h = getHero();
 
158
  if (!h || h->getHP() <= 0)
 
159
    {
 
160
      deactivate();
 
161
      return;
 
162
    }
 
163
 
158
164
  if (a->getTypeId() == d_type_to_kill)
159
165
    {
160
166
      if (heroIsCulprit)
169
175
        }
170
176
    }
171
177
}
 
178
 
172
179
void QuestEnemyArmytype::cityAction(City *c, CityDefeatedAction action, 
173
180
                                    bool heroIsCulprit, int gold)
174
181
{