~ubuntu-branches/ubuntu/saucy/lordsawar/saucy

« back to all changes in this revision

Viewing changes to src/armysetlist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese
  • Date: 2008-12-20 13:52:12 UTC
  • mfrom: (1.1.6 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20081220135212-noeb2w3y98ebo7o9
Tags: 0.1.4-1
[ Barry deFreese ]
* New upstream release.
* Move 0.0.8-2.1 changelog entry to correct point in changelog.
* Make lordsawar-data suggest lordsawar.
* Update my e-mail address.
* Add build-depends on intltool, uuid-dev, and libboost-dev.
* Don't install locales since there are no translations currently.
* Add simple man page for new lordsawar-pbm binary.
* Drop gcc4.3 patches as they have been fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
//  02110-1301, USA.
20
20
 
21
21
#include <iostream>
 
22
#include <algorithm>
22
23
#include <expat.h>
23
24
#include <SDL_image.h>
24
25
#include <SDL.h>
29
30
#include "armyset.h"
30
31
#include "File.h"
31
32
#include "defs.h"
32
 
 
 
33
#include "ucompose.hpp"
33
34
 
34
35
 
35
36
using namespace std;
69
70
        for (Armyset::iterator ait = (*it)->begin(); ait != (*it)->end(); ait++)
70
71
          d_armies[(*it)->getId()].push_back(*ait);
71
72
        d_names[(*it)->getId()] = (*it)->getName();
72
 
        d_ids[(*it)->getName()] = (*it)->getId();
 
73
        d_ids[String::ucompose("%1 %2", (*it)->getName(), (*it)->getTileSize())] = (*it)->getId();
73
74
        (*it)->setSubDir(*i);
 
75
        d_armysets[*i] = *it;
74
76
      }
75
77
}
76
78
 
86
88
            delete ((*it).second)[0];
87
89
}
88
90
 
89
 
Army* Armysetlist::getArmy(Uint32 id, Uint32 index) const
 
91
ArmyProto* Armysetlist::getArmy(Uint32 id, Uint32 index) const
90
92
{
91
93
    // always use ArmyProtoMap::find for searching, else a default entry is 
92
94
    // created, which can produce really bad results!!
103
105
    return ((*it).second)[index];
104
106
}
105
107
 
106
 
Army* Armysetlist::getScout(Uint32 id) const
 
108
ArmyProto* Armysetlist::getScout(Uint32 id) const
107
109
{
108
110
    // always use ArmyProtoMap::find for searching, else a default entry is 
109
111
    // created, which can produce really bad results!!
135
137
  return names;
136
138
}
137
139
 
 
140
std::list<std::string> Armysetlist::getNames(Uint32 tilesize)
 
141
{
 
142
  std::list<std::string> names;
 
143
  for (iterator it = begin(); it != end(); it++)
 
144
    if ((*it)->getTileSize() == tilesize)
 
145
      names.push_back((*it)->getName());
 
146
  return names;
 
147
}
 
148
 
138
149
std::string Armysetlist::getName(Uint32 id) const
139
150
{
140
151
    NameMap::const_iterator it = d_names.find(id);
161
172
 
162
173
bool Armysetlist::load(std::string tag, XML_Helper *helper)
163
174
{
164
 
  if (tag == "armyset")
 
175
  if (tag == Armyset::d_tag)
165
176
    {
166
177
      Armyset *armyset = new Armyset(helper);
167
178
      push_back(armyset); 
176
187
 
177
188
  XML_Helper helper(File::getArmyset(name), ios::in, false);
178
189
 
179
 
  helper.registerTag("armyset", sigc::mem_fun((*this), &Armysetlist::load));
 
190
  helper.registerTag(Armyset::d_tag, sigc::mem_fun((*this), &Armysetlist::load));
180
191
 
181
192
  if (!helper.parse())
182
193
    {
183
 
      std::cerr <<_("Error, while loading an armyset. Armyset Name: ");
 
194
      std::cerr << "Error, while loading an armyset. Armyset Name: ";
184
195
      std::cerr <<name <<std::endl <<std::flush;
185
196
      exit(-1);
186
197
    }
187
198
 
188
199
  return true;
189
200
}
190
 
        
191
 
void Armysetlist::instantiatePixmaps()
192
 
{
193
 
  for (iterator it = begin(); it != end(); it++)
194
 
    (*it)->instantiatePixmaps();
195
 
}
196
201
        
197
202
SDL_Surface * Armysetlist::getShipPic (Uint32 id)
198
203
{
244
249
  return NULL;
245
250
}
246
251
 
 
252
Armyset *Armysetlist::getArmyset(Uint32 id)
 
253
{
 
254
  for (iterator it = begin(); it != end(); it++)
 
255
    {
 
256
      if ((*it)->getId() == id)
 
257
        return (*it);
 
258
    }
 
259
  return NULL;
 
260
}
 
261
 
 
262
void Armysetlist::getSizes(std::list<Uint32> &sizes)
 
263
{
 
264
  for (iterator i = begin(); i != end(); i++)
 
265
    {
 
266
      if (find (sizes.begin(), sizes.end(), (*i)->getTileSize()) == sizes.end())
 
267
        sizes.push_back((*i)->getTileSize());
 
268
    }
 
269
}
 
270
 
 
271
Uint32 Armysetlist::getArmysetId(std::string armyset, Uint32 tilesize)
 
272
{
 
273
  return d_ids[String::ucompose("%1 %2", armyset, tilesize)];
 
274
}
 
275
 
 
276
std::string Armysetlist::getArmysetDir(std::string name, Uint32 tilesize)
 
277
{
 
278
  return getArmyset(getArmysetId(name, tilesize))->getSubDir();
 
279
}