239
285
helper->getData(x, "x");
240
286
helper->getData(y, "y");
241
d_ruin = Ruinlist::getInstance()->getObjectAt(x, y);
287
d_ruin_pos = Vector<int>(x,y);
290
Reward_Ruin::Reward_Ruin (const Reward_Ruin& orig)
291
:Reward(orig), d_ruin_pos(orig.d_ruin_pos)
244
294
bool Reward_Ruin::save(XML_Helper* helper) const
246
296
bool retval = true;
247
297
retval &= helper->openTag("reward");
248
298
retval &= Reward::save(helper);
249
retval &= helper->saveData("x", d_ruin->getPos().x);
250
retval &= helper->saveData("y", d_ruin->getPos().y);
299
retval &= helper->saveData("x", getRuin()->getPos().x);
300
retval &= helper->saveData("y", getRuin()->getPos().y);
251
301
retval &= helper->closeTag();
305
Ruin *Reward_Ruin::getRandomHiddenRuin()
307
std::vector<Ruin *>hidden_ruins;
308
Ruinlist *rl = Ruinlist::getInstance();
309
Rewardlist *rw = Rewardlist::getInstance();
310
for (Ruinlist::iterator it = rl->begin(); it != rl->end(); it++)
312
if ((*it).isHidden())
313
if ((*it).getOwner() == NULL ||
314
(*it).getOwner() == Playerlist::getInstance()->getNeutral())
316
//is it already being pointed to by a reward in the rewardlist?
318
for (Rewardlist::iterator i = rw->begin(); i != rw->end(); i++)
320
if ((*i)->getType() == Reward::RUIN)
322
Ruin *r = static_cast<Reward_Ruin*>(*i)->getRuin();
325
if (r->getPos() == (*it).getPos())
334
hidden_ruins.push_back(&*it);
337
if (hidden_ruins.empty())
339
return hidden_ruins[rand() % hidden_ruins.size()];
255
342
Reward_Ruin::~Reward_Ruin()
259
Reward_Map::Reward_Map(Location *loc, Uint32 height, Uint32 width)
260
:Reward(Reward::MAP), d_loc(loc), d_height(height), d_width(width)
264
bool Reward_Map::loadLocation(std::string tag, XML_Helper* helper)
266
if (tag == "location")
268
d_loc = new Location(helper);
346
Reward_Map::Reward_Map(Vector<int> pos, std::string name,
347
Uint32 height, Uint32 width)
348
:Reward(Reward::MAP, name), Location(pos), d_height(height), d_width(width)
275
352
Reward_Map::Reward_Map(XML_Helper* helper)
353
:Reward(helper), Location(helper)
278
helper->registerTag("location", sigc::mem_fun(this,
279
&Reward_Map::loadLocation));
280
355
helper->getData(d_height, "height");
281
356
helper->getData(d_width, "width");
359
Reward_Map::Reward_Map (const Reward_Map& orig)
360
:Reward(orig), Location(orig),
361
d_height(orig.d_height), d_width(orig.d_width)
284
365
bool Reward_Map::save(XML_Helper* helper) const
286
367
bool retval = true;
287
368
retval &= helper->openTag("reward");
288
369
retval &= Reward::save(helper);
370
retval &= helper->saveData("id", getId());
371
retval &= helper->saveData("x", getPos().x);
372
retval &= helper->saveData("y", getPos().y);
373
retval &= helper->saveData("name", getName());
289
374
retval &= helper->saveData("height", d_height);
290
375
retval &= helper->saveData("width", d_width);
291
retval &= helper->openTag("location");
292
retval &= helper->saveData("id", d_loc->getId());
293
retval &= helper->saveData("name", d_loc->getName());
294
Vector<int> pos = d_loc->getPos();
295
retval &= helper->saveData("x", pos.x);
296
retval &= helper->saveData("y", pos.y);
297
retval &= helper->closeTag();
298
376
retval &= helper->closeTag();
380
void Reward_Map::getRandomMap(int *x, int *y, int *width, int *height)
382
int map_width = GameMap::getInstance()->getWidth();
383
*x = rand() % (map_width - (map_width / 10));
384
int map_height = GameMap::getInstance()->getHeight();
385
*y = rand() % (map_height - (map_height / 10));
386
*width = ((rand() % (map_width - *x)) + (map_width / 10));
387
*height = ((rand() % (map_height - *y)) + (map_height / 10));
303
390
Reward_Map::~Reward_Map()
394
std::string Reward::getDescription()
396
Glib::ustring s = "";
401
Reward_Gold *g = dynamic_cast<Reward_Gold*>(this);
402
s += String::ucompose(ngettext("%1 Gold Piece", "%1 Gold Pieces",
403
g->getGold()), g->getGold());
408
Reward_Allies *a = dynamic_cast<Reward_Allies *>(this);
410
s += String::ucompose(_("Allies: %1 x %2"), a->getArmy()->getName(),
416
Reward_Item *i = dynamic_cast<Reward_Item *>(this);
418
s += String::ucompose(_("Item: %1"), i->getItem()->getName());
423
Reward_Ruin *r = dynamic_cast<Reward_Ruin *>(this);
425
s += String::ucompose(_("Site: %1"), r->getRuin()->getName());
430
Reward_Map *m = dynamic_cast<Reward_Map *>(this);
431
s += String::ucompose(_("Map: %1,%2 %3x%4"),