~ubuntu-branches/ubuntu/precise/lordsawar/precise

« back to all changes in this revision

Viewing changes to src/army.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2007-10-29 15:38:06 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071029153806-z2j47adhmdjc7wae
Tags: 0.0.4-1
* New upstream release
* Add desktop file and simple manpage for new binary lordsawar-army-editor
* Syntax fixes on manpages
* Move manpages to correct section (6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    }  
59
59
}
60
60
 
61
 
Army::Army(XML_Helper* helper, bool prototype)
 
61
Army::Army()
 
62
  :d_pixmap(0), d_mask(0), d_name("Untitled"), d_description(""),
 
63
    d_production(0), d_production_cost(0), d_upkeep(0), d_strength(0),
 
64
    d_max_hp(0), d_max_moves(0), d_sight(0), d_gender(NONE), d_level(1), 
 
65
   d_defends_ruins(false), d_awardable(false), d_hero(false), d_image("")
 
66
{
 
67
}
 
68
 
 
69
Army::Army(XML_Helper* helper, enum ArmyContents contents)
62
70
  :d_pixmap(0), d_mask(0), d_name(""), d_description(""), d_ship(false),
63
71
   d_gender(NONE), d_player(0), 
64
72
   d_id(0), d_xp(0), d_level(1), d_grouped(true),
75
83
    
76
84
    // now if we are a prototype, we have to load different data than
77
85
    // otherwise
78
 
    if (!prototype)
 
86
    if (contents == INSTANCE)
79
87
    {
80
88
        int ival = -1;
81
89
        //get the information which army we are
117
125
        if (ival != -1)
118
126
          d_visitedTemples.push_front(ival);
119
127
    }
120
 
    else
 
128
    else if (contents == TYPE || contents == PRODUCTION_BASE)
121
129
    {
122
130
        helper->getData(d_name, "name");
 
131
        helper->getData(d_image, "image");
123
132
        helper->getData(d_description, "description");
124
133
        helper->getData(d_production, "production");
125
134
        helper->getData(d_production_cost, "production_cost");
142
151
            d_medal_bonus[i] = false;
143
152
      helper->getData(d_hero,"hero");
144
153
    }
 
154
    if (contents == PRODUCTION_BASE)
 
155
      {
 
156
        helper->getData(d_type, "type");
 
157
        helper->getData(d_armyset, "armyset");
 
158
      }
145
159
}
146
160
 
147
161
Army::~Army()
195
209
    
196
210
    //use the GraphicsCache to get a picture of the army's armyset_army
197
211
    return GraphicsCache::getInstance()->getArmyPic(d_armyset, d_type,
198
 
                                         d_player, d_level, d_medal_bonus);
 
212
                                         d_player, d_medal_bonus);
199
213
}
200
214
 
201
215
Uint32 Army::getStat(Stat stat, bool modified) const
368
382
}
369
383
 
370
384
 
371
 
bool Army::save(XML_Helper* helper) const
 
385
bool Army::save(XML_Helper* helper, enum ArmyContents contents) const
372
386
{
373
387
    bool retval = true;
374
388
 
375
389
    retval &= helper->openTag("army");
376
 
    retval &= saveData(helper);
 
390
    retval &= saveData(helper, contents);
377
391
    retval &= helper->closeTag();
378
392
 
379
393
    return retval;
380
394
}
381
395
 
382
 
bool Army::saveData(XML_Helper* helper) const
 
396
bool Army::saveData(XML_Helper* helper, enum ArmyContents contents) const
383
397
{
384
398
    bool retval = true;
385
399
    
386
 
    retval &= helper->saveData("id", d_id);
387
 
    retval &= helper->saveData("armyset", d_armyset);
388
 
    retval &= helper->saveData("type", d_type);
 
400
    if (contents == TYPE || contents == PRODUCTION_BASE)
 
401
      {
 
402
        retval &= helper->saveData("name", d_name);
 
403
        retval &= helper->saveData("description", d_description);
 
404
        retval &= helper->saveData("image", d_image);
 
405
        retval &= helper->saveData("production", d_production);
 
406
        retval &= helper->saveData("production_cost", d_production_cost);
 
407
        retval &= helper->saveData("upkeep", d_upkeep);
 
408
        retval &= helper->saveData("gender", d_gender);
 
409
        retval &= helper->saveData("awardable", d_awardable);
 
410
        retval &= helper->saveData("defends_ruins", d_defends_ruins);
 
411
        retval &= helper->saveData("move_bonus", d_move_bonus);
 
412
        retval &= helper->saveData("army_bonus", d_army_bonus);
 
413
      }
 
414
    else if (contents == INSTANCE)
 
415
      {
 
416
        retval &= helper->saveData("id", d_id);
 
417
        retval &= helper->saveData("armyset", d_armyset);
 
418
        retval &= helper->saveData("type", d_type);
 
419
        retval &= helper->saveData("hp", d_hp);
 
420
        retval &= helper->saveData("ship", d_ship);
 
421
        retval &= helper->saveData("moves", d_moves);
 
422
        retval &= helper->saveData("xp", d_xp);
 
423
      }
 
424
 
 
425
    if (contents == PRODUCTION_BASE)
 
426
      {
 
427
        retval &= helper->saveData("type", d_type);
 
428
        retval &= helper->saveData("armyset", d_armyset);
 
429
      }
 
430
 
 
431
    retval &= helper->saveData("max_moves", d_max_moves);
389
432
    retval &= helper->saveData("hero", d_hero);
390
 
    retval &= helper->saveData("hp", d_hp);
391
433
    retval &= helper->saveData("strength", d_strength);
392
434
    retval &= helper->saveData("sight", d_sight);
393
 
    retval &= helper->saveData("moves", d_moves);
394
 
    retval &= helper->saveData("ship", d_ship);
395
 
    retval &= helper->saveData("max_moves", d_max_moves);
396
 
    retval &= helper->saveData("xp", d_xp);
397
435
    retval &= helper->saveData("expvalue", getXpReward());
398
436
    retval &= helper->saveData("level", d_level);
399
437
 
 
438
    if (contents == PRODUCTION_BASE || contents == TYPE)
 
439
      return retval;
 
440
 
400
441
    std::stringstream medals;
401
442
    for (int i=0;i<3;i++)
402
443
    {
492
533
  return (d_army_bonus & Army::FORTIFY) == Army::FORTIFY;
493
534
}
494
535
 
 
536
void Army::setPixmap(SDL_Surface* pixmap)
 
537
{
 
538
  if (d_pixmap)
 
539
    SDL_FreeSurface(d_pixmap);
 
540
  d_pixmap = pixmap;
 
541
}
 
542
        
 
543
void Army::setMask(SDL_Surface* mask)
 
544
{
 
545
  if (d_mask)
 
546
    SDL_FreeSurface(d_mask);
 
547
  d_mask = mask;
 
548
}