1 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2007, 2008, 2010, 2011, 2014, 2015, 2017 Ben Asselstine
4 // Copyright (C) 2008 Ole Laursen
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU Library General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 //  02110-1301, USA.
20 
21 #include <sstream>
22 #include <sigc++/functors/mem_fun.h>
23 
24 #include "action.h"
25 #include "stack.h"
26 #include "army.h"
27 #include "city.h"
28 #include "signpost.h"
29 #include "ruin.h"
30 #include "temple.h"
31 #include "Quest.h"
32 #include "QKillHero.h"
33 #include "QEnemyArmies.h"
34 #include "QEnemyArmytype.h"
35 #include "QCitySack.h"
36 #include "QCityRaze.h"
37 #include "QCityOccupy.h"
38 #include "QPillageGold.h"
39 #include "armysetlist.h"
40 #include "playerlist.h"
41 #include "player.h"
42 #include "armyprodbase.h"
43 #include "heroproto.h"
44 #include "Item.h"
45 #include "stacklist.h" //remove me
46 #include "ucompose.hpp"
47 #include "SightMap.h"
48 #include "reward.h"
49 #include "xmlhelper.h"
50 
51 Glib::ustring Action::d_tag = "action";
52 
53 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<< x << std::endl<<std::flush;}
54 #define debug(x)
55 
Action(Type type)56 Action::Action(Type type)
57     :d_type(type)
58 {
59 }
60 
Action(const Action & action)61 Action::Action(const Action &action)
62 :d_type(action.d_type)
63 {
64 
65 }
Action(XML_Helper * helper)66 Action::Action(XML_Helper *helper)
67 {
68   Glib::ustring type_str;
69   helper->getData(type_str, "type");
70   d_type = actionTypeFromString(type_str);
71 }
72 
save(XML_Helper * helper) const73 bool Action::save(XML_Helper* helper) const
74 {
75     bool retval = true;
76 
77     retval &= helper->openTag(Action::d_tag);
78     retval &= saveContents(helper);
79     retval &= helper->closeTag();
80 
81     return retval;
82 }
83 
saveContents(XML_Helper * helper) const84 bool Action::saveContents(XML_Helper* helper) const
85 {
86     bool retval = true;
87 
88     Glib::ustring type_str = actionTypeToString(Action::Type(d_type));
89     retval &= helper->saveData("type", type_str);
90     retval &= doSave(helper);
91 
92     return retval;
93 }
94 
handle_load(XML_Helper * helper)95 Action* Action::handle_load(XML_Helper* helper)
96 {
97   Glib::ustring type_str;
98 
99   helper->getData(type_str, "type");
100   Action::Type t = actionTypeFromString(type_str);
101 
102   switch (t)
103     {
104       case STACK_MOVE:
105           return (new Action_Move(helper));
106       case STACK_SPLIT:
107           return (new Action_Split(helper));
108       case STACK_FIGHT:
109           return (new Action_Fight(helper));
110       case STACK_JOIN:
111           return(new Action_Join(helper));
112       case RUIN_SEARCH:
113           return (new Action_Ruin(helper));
114       case TEMPLE_SEARCH:
115           return (new Action_Temple(helper));
116       case CITY_OCCUPY:
117           return (new Action_Occupy(helper));
118       case CITY_PILLAGE:
119           return (new Action_Pillage(helper));
120       case CITY_SACK:
121           return (new Action_Sack(helper));
122       case CITY_RAZE:
123           return (new Action_Raze(helper));
124       case CITY_UPGRADE:
125           return (new Action_Upgrade(helper));
126       case CITY_BUY:
127           return (new Action_Buy(helper));
128       case CITY_PROD:
129           return (new Action_Production(helper));
130       case REWARD:
131           return (new Action_Reward(helper));
132       case QUEST:
133           return (new Action_Quest(helper));
134       case HERO_EQUIP:
135           return (new Action_Equip(helper));
136       case UNIT_ADVANCE:
137           return (new Action_Level(helper));
138       case STACK_DISBAND:
139           return (new Action_Disband(helper));
140       case MODIFY_SIGNPOST:
141           return (new Action_ModifySignpost(helper));
142       case CITY_RENAME:
143           return (new Action_RenameCity(helper));
144       case CITY_VECTOR:
145           return (new Action_Vector(helper));
146       case FIGHT_ORDER:
147           return (new Action_FightOrder(helper));
148       case RESIGN:
149           return (new Action_Resign(helper));
150       case ITEM_PLANT:
151           return (new Action_Plant(helper));
152       case PRODUCE_UNIT:
153           return (new Action_Produce(helper));
154       case PRODUCE_VECTORED_UNIT:
155           return (new Action_ProduceVectored(helper));
156       case DIPLOMATIC_STATE:
157           return (new Action_DiplomacyState(helper));
158       case DIPLOMATIC_PROPOSAL:
159           return (new Action_DiplomacyProposal(helper));
160       case DIPLOMATIC_SCORE:
161           return (new Action_DiplomacyScore(helper));
162       case END_TURN:
163           return (new Action_EndTurn(helper));
164       case CITY_CONQUER:
165           return (new Action_ConquerCity(helper));
166       case RECRUIT_HERO:
167           return (new Action_RecruitHero(helper));
168       case PLAYER_RENAME:
169           return (new Action_RenamePlayer(helper));
170       case CITY_DESTITUTE:
171           return (new Action_CityTooPoorToProduce(helper));
172       case INIT_TURN:
173           return (new Action_InitTurn(helper));
174       case CITY_LOOT:
175           return (new Action_Loot(helper));
176       case USE_ITEM:
177           return (new Action_UseItem(helper));
178       case STACK_ORDER:
179           return (new Action_ReorderArmies(helper));
180       case STACKS_RESET:
181           return (new Action_ResetStacks(helper));
182       case RUINS_RESET:
183           return (new Action_ResetRuins(helper));
184       case COLLECT_TAXES_AND_PAY_UPKEEP:
185           return (new Action_CollectTaxesAndPayUpkeep(helper));
186       case KILL_PLAYER:
187           return (new Action_Kill(helper));
188       case STACK_DEFEND:
189           return (new Action_DefendStack(helper));
190       case STACK_UNDEFEND:
191           return (new Action_UndefendStack(helper));
192       case STACK_PARK:
193           return (new Action_ParkStack(helper));
194       case STACK_UNPARK:
195           return (new Action_UnparkStack(helper));
196       case STACK_SELECT:
197           return (new Action_SelectStack(helper));
198       case STACK_DESELECT:
199           return (new Action_DeselectStack(helper));
200     }
201 
202   return 0;
203 }
204 
205 
copy(const Action * a)206 Action* Action::copy(const Action* a)
207 {
208     switch(a->getType())
209     {
210         case STACK_MOVE:
211             return (new Action_Move(*dynamic_cast<const Action_Move*>(a)));
212         case STACK_SPLIT:
213             return (new Action_Split(*dynamic_cast<const Action_Split*>(a)));
214         case STACK_FIGHT:
215             return (new Action_Fight(*dynamic_cast<const Action_Fight*>(a)));
216         case STACK_JOIN:
217             return(new Action_Join(*dynamic_cast<const Action_Join*>(a)));
218         case RUIN_SEARCH:
219             return (new Action_Ruin(*dynamic_cast<const Action_Ruin*>(a)));
220         case TEMPLE_SEARCH:
221             return (new Action_Temple(*dynamic_cast<const Action_Temple*>(a)));
222         case CITY_OCCUPY:
223             return (new Action_Occupy(*dynamic_cast<const Action_Occupy*>(a)));
224         case CITY_PILLAGE:
225             return (new Action_Pillage(*dynamic_cast<const Action_Pillage*>(a)));
226         case CITY_SACK:
227             return (new Action_Sack(*dynamic_cast<const Action_Sack*>(a)));
228         case CITY_RAZE:
229             return (new Action_Raze(*dynamic_cast<const Action_Raze*>(a)));
230         case CITY_UPGRADE:
231             return (new Action_Upgrade(*dynamic_cast<const Action_Upgrade*>(a)));
232         case CITY_BUY:
233             return (new Action_Buy(*dynamic_cast<const Action_Buy*>(a)));
234         case CITY_PROD:
235             return (new Action_Production(*dynamic_cast<const Action_Production*>(a)));
236         case REWARD:
237             return (new Action_Reward(*dynamic_cast<const Action_Reward*>(a)));
238         case QUEST:
239             return (new Action_Quest(*dynamic_cast<const Action_Quest*>(a)));
240         case HERO_EQUIP:
241             return (new Action_Equip(*dynamic_cast<const Action_Equip*>(a)));
242         case UNIT_ADVANCE:
243             return (new Action_Level(*dynamic_cast<const Action_Level*>(a)));
244         case STACK_DISBAND:
245             return (new Action_Disband(*dynamic_cast<const Action_Disband*>(a)));
246         case MODIFY_SIGNPOST:
247             return (new Action_ModifySignpost(*dynamic_cast<const Action_ModifySignpost*>(a)));
248         case CITY_RENAME:
249             return (new Action_RenameCity(*dynamic_cast<const Action_RenameCity*>(a)));
250         case CITY_VECTOR:
251             return (new Action_Vector(*dynamic_cast<const Action_Vector*>(a)));
252         case FIGHT_ORDER:
253             return (new Action_FightOrder(*dynamic_cast<const Action_FightOrder*>(a)));
254         case RESIGN:
255             return (new Action_Resign(*dynamic_cast<const Action_Resign*>(a)));
256         case ITEM_PLANT:
257             return (new Action_Plant(*dynamic_cast<const Action_Plant*>(a)));
258         case PRODUCE_UNIT:
259             return (new Action_Produce(*dynamic_cast<const Action_Produce*>(a)));
260         case PRODUCE_VECTORED_UNIT:
261             return
262               (new Action_ProduceVectored
263                 (*dynamic_cast<const Action_ProduceVectored*>(a)));
264         case DIPLOMATIC_STATE:
265             return
266               (new Action_DiplomacyState
267                 (*dynamic_cast<const Action_DiplomacyState*>(a)));
268         case DIPLOMATIC_PROPOSAL:
269             return
270               (new Action_DiplomacyProposal
271                 (*dynamic_cast<const Action_DiplomacyProposal*>(a)));
272         case DIPLOMATIC_SCORE:
273             return
274               (new Action_DiplomacyScore
275                 (*dynamic_cast<const Action_DiplomacyScore*>(a)));
276         case END_TURN:
277             return
278               (new Action_EndTurn
279                 (*dynamic_cast<const Action_EndTurn*>(a)));
280         case CITY_CONQUER:
281             return
282               (new Action_ConquerCity
283                 (*dynamic_cast<const Action_ConquerCity*>(a)));
284         case RECRUIT_HERO:
285             return
286               (new Action_RecruitHero
287                 (*dynamic_cast<const Action_RecruitHero*>(a)));
288         case PLAYER_RENAME:
289             return
290               (new Action_RenamePlayer
291                 (*dynamic_cast<const Action_RenamePlayer*>(a)));
292         case CITY_DESTITUTE:
293             return
294               (new Action_CityTooPoorToProduce
295                 (*dynamic_cast<const Action_CityTooPoorToProduce*>(a)));
296         case INIT_TURN:
297             return
298               (new Action_InitTurn
299                 (*dynamic_cast<const Action_InitTurn*>(a)));
300         case CITY_LOOT:
301             return
302               (new Action_Loot
303                 (*dynamic_cast<const Action_Loot*>(a)));
304         case USE_ITEM:
305             return
306               (new Action_UseItem
307                 (*dynamic_cast<const Action_UseItem*>(a)));
308         case STACK_ORDER:
309             return
310               (new Action_ReorderArmies
311                 (*dynamic_cast<const Action_ReorderArmies*>(a)));
312         case STACKS_RESET:
313             return
314               (new Action_ResetStacks
315                 (*dynamic_cast<const Action_ResetStacks*>(a)));
316         case RUINS_RESET:
317             return
318               (new Action_ResetRuins
319                 (*dynamic_cast<const Action_ResetRuins*>(a)));
320         case COLLECT_TAXES_AND_PAY_UPKEEP:
321             return
322               (new Action_CollectTaxesAndPayUpkeep
323                 (*dynamic_cast<const Action_CollectTaxesAndPayUpkeep*>(a)));
324         case KILL_PLAYER:
325             return (new Action_Kill (*dynamic_cast<const Action_Kill*>(a)));
326         case STACK_DEFEND:
327             return (new Action_DefendStack
328                     (*dynamic_cast<const Action_DefendStack*>(a)));
329         case STACK_UNDEFEND:
330             return (new Action_UndefendStack
331                     (*dynamic_cast<const Action_UndefendStack*>(a)));
332         case STACK_PARK:
333             return (new Action_ParkStack
334                     (*dynamic_cast<const Action_ParkStack*>(a)));
335         case STACK_UNPARK:
336             return (new Action_UnparkStack
337                     (*dynamic_cast<const Action_UnparkStack*>(a)));
338         case STACK_SELECT:
339             return (new Action_SelectStack
340                     (*dynamic_cast<const Action_SelectStack*>(a)));
341         case STACK_DESELECT:
342             return (new Action_DeselectStack
343                     (*dynamic_cast<const Action_DeselectStack*>(a)));
344     }
345 
346     return 0;
347 }
348 
349 //-----------------------------------------------------------------------------
350 //Action_Move_Step
351 
Action_Move(Stack * s,Vector<int> dest)352 Action_Move::Action_Move(Stack* s, Vector<int> dest)
353     :Action(Action::STACK_MOVE), d_stack(s->getId()), d_dest(dest),
354     d_delta(dest - s->getPos()), d_moves_left(s->getMoves()),
355     d_has_ship(s->hasShip()), d_had_ship (s->hasShip())
356 {
357 }
358 
Action_Move(const Action_Move & a)359 Action_Move::Action_Move (const Action_Move &a)
360 :Action(a), d_stack(a.d_stack), d_dest(a.d_dest), d_delta(a.d_delta),
361     d_moves_left(a.d_moves_left), d_has_ship (a.d_has_ship),
362     d_had_ship (a.d_had_ship)
363 {
364 }
365 
Action_Move(XML_Helper * helper)366 Action_Move::Action_Move(XML_Helper* helper)
367     :Action(helper)
368 {
369     helper->getData(d_stack, "stack");
370     helper->getData(d_dest.x, "x");
371     helper->getData(d_dest.y, "y");
372     helper->getData(d_delta.x, "delta_x");
373     helper->getData(d_delta.y, "delta_y");
374     helper->getData(d_moves_left, "moves_left");
375     helper->getData(d_has_ship, "has_ship");
376     helper->getData(d_had_ship, "had_ship");
377 }
378 
dump() const379 Glib::ustring Action_Move::dump() const
380 {
381   return String::ucompose("Stack %1 moved to %2,%3 w/ %4 mp left, ship=%5 (was %6)\n",
382                           d_stack, d_dest.x, d_dest.y, d_moves_left,
383                           d_has_ship, d_had_ship);
384 }
385 
doSave(XML_Helper * helper) const386 bool Action_Move::doSave(XML_Helper* helper) const
387 {
388     bool retval = true;
389 
390     retval &= helper->saveData("stack", d_stack);
391     retval &= helper->saveData("x", d_dest.x);
392     retval &= helper->saveData("y", d_dest.y);
393     retval &= helper->saveData("delta_x", d_delta.x);
394     retval &= helper->saveData("delta_y", d_delta.y);
395     retval &= helper->saveData("moves_left", d_moves_left);
396     retval &= helper->saveData("has_ship", d_has_ship);
397     retval &= helper->saveData("had_ship", d_had_ship);
398 
399     return retval;
400 }
401 
402 //-----------------------------------------------------------------------------
403 //Action_Split
404 
Action_Split(Stack * orig,Stack * added)405 Action_Split::Action_Split(Stack* orig, Stack* added)
406     :Action(Action::STACK_SPLIT), d_orig(orig->getId()), d_added(added->getId())
407 {
408   if (orig->validate() == false || added->validate() == false)
409     {
410       std::cerr << String::ucompose("Action_Split: stacks don't validate!  orig has %1 units, and added has %2 units.", orig->size(), added->size()) << std::endl;
411       return;
412     }
413 
414   for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
415     d_armies_moved[i] = 0;
416   Stack::iterator it = added->begin();
417   for (unsigned int i = 0; it != added->end(); it++, i++)
418     d_armies_moved[i] = (*it)->getId();
419 }
420 
Action_Split(const Action_Split & action)421 Action_Split::Action_Split(const Action_Split &action)
422 : Action(action), d_orig(action.d_orig), d_added(action.d_added)
423 {
424   for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
425     d_armies_moved[i] = action.d_armies_moved[i];
426 }
427 
Action_Split(XML_Helper * helper)428 Action_Split::Action_Split(XML_Helper* helper)
429     :Action(helper)
430 {
431     helper->getData(d_orig, "orig_stack");
432     helper->getData(d_added, "new_stack");
433 
434     Glib::ustring s;
435     std::istringstream si;
436 
437     helper->getData(s, "moved");
438     si.str(s);
439     for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
440         si >>d_armies_moved[i];
441 }
442 
dump() const443 Glib::ustring Action_Split::dump() const
444 {
445   Glib::ustring s =
446     String::ucompose("Stack %1 split with new stack %2.\n", d_orig, d_added);
447   s += "moved these armies:";
448 
449   for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
450     s += String::ucompose("%1 ", d_armies_moved[i]);
451   s += "\n";
452 
453   return s;
454 }
455 
doSave(XML_Helper * helper) const456 bool Action_Split::doSave(XML_Helper* helper) const
457 {
458     Glib::ustring s;
459     bool retval = true;
460 
461     for (unsigned int i = 0; i < MAX_STACK_SIZE - 1; i++)
462       s += String::ucompose("%1 ", d_armies_moved[i]);
463     s += String::ucompose("%1 ", d_armies_moved[MAX_STACK_SIZE - 1]);
464 
465     retval &= helper->saveData("orig_stack", d_orig);
466     retval &= helper->saveData("new_stack", d_added);
467     retval &= helper->saveData("moved", s);
468 
469     return retval;
470 }
471 
472 //-----------------------------------------------------------------------------
473 //Action_Fight
474 
Action_Fight(const Fight * f)475 Action_Fight::Action_Fight(const Fight* f)
476     :Action(Action::STACK_FIGHT)
477 {
478   std::list<Stack*> list = f->getAttackers();
479   std::list<Stack*>::const_iterator it;
480 
481   for (it = list.begin(); it != list.end(); it++)
482     d_attackers.push_back((*it)->getId());
483 
484   list = f->getDefenders();
485 
486   for (it = list.begin(); it != list.end(); it++)
487     d_defenders.push_back((*it)->getId());
488 
489   for (auto fighter : f->getAttackerFighters())
490     d_attacker_army_ids.push_back(fighter->army->getId());
491   for (auto fighter : f->getDefenderFighters())
492     d_defender_army_ids.push_back(fighter->army->getId());
493   d_history = f->getCourseOfEvents();
494 }
495 
Action_Fight(const Action_Fight & a)496 Action_Fight::Action_Fight(const Action_Fight &a)
497 : Action(a), d_history(a.d_history), d_attackers(a.d_attackers),
498     d_defenders(a.d_defenders), d_attacker_army_ids(a.d_attacker_army_ids),
499     d_defender_army_ids(a.d_defender_army_ids)
500 {
501 }
502 
Action_Fight(XML_Helper * helper)503 Action_Fight::Action_Fight(XML_Helper* helper)
504     :Action(helper)
505 {
506     Glib::ustring s;
507     std::istringstream si;
508     int ival = -1;
509 
510     helper->registerTag(Item::d_tag,
511                         sigc::hide<0>(sigc::mem_fun(this, &Action_Fight::loadItem)));
512 
513     // get attacking and defending stacks
514     helper->getData(s, "attackers");
515     si.str(s);
516     while (si.eof() == false)
517       {
518         ival = -1;
519         si >> ival;
520         if (ival != -1)
521           d_attackers.push_back((guint32)ival);
522       }
523     si.clear();
524 
525     helper->getData(s, "defenders");
526     si.str(s);
527     while (si.eof() == false)
528       {
529         ival = -1;
530         si >> ival;
531         if (ival != -1)
532           d_defenders.push_back((guint32) ival);
533       }
534     // get attacking and defending army ids
535     si.clear();
536     helper->getData(s, "attacker_army_ids");
537     si.str(s);
538     while (si.eof() == false)
539       {
540         ival = -1;
541         si >> ival;
542         if (ival != -1)
543           d_attacker_army_ids.push_back((guint32)ival);
544       }
545     si.clear();
546     helper->getData(s, "defender_army_ids");
547     si.str(s);
548     while (si.eof() == false)
549       {
550         ival = -1;
551         si >> ival;
552         if (ival != -1)
553           d_defender_army_ids.push_back((guint32)ival);
554       }
555     si.clear();
556 }
557 
dump() const558 Glib::ustring Action_Fight::dump() const
559 {
560   Glib::ustring s = "Battle fought.\n Attacking stacks: ";
561   std::list<guint32>::const_iterator uit;
562   for (uit = d_attackers.begin(); uit != d_attackers.end(); uit++)
563     s += String::ucompose("%1 ", (*uit));
564   s += "\n Defending stacks: ";
565   for (uit = d_defenders.begin(); uit != d_defenders.end(); uit++)
566     s += String::ucompose("%1 ", (*uit));
567   s +="\n Attacking armies: ";
568   for (auto i : d_attacker_army_ids)
569     s += String::ucompose("%1 ", i);
570   s +="\n Defending armies: ";
571   for (auto i : d_defender_army_ids)
572     s += String::ucompose("%1 ", i);
573   s +="\n Armies hit: ";
574   for (auto h : d_history)
575     s += String::ucompose ("%1, ", h.id);
576   s +="\n";
577   return s;
578 }
579 
doSave(XML_Helper * helper) const580 bool Action_Fight::doSave(XML_Helper* helper) const
581 {
582   Glib::ustring s;
583     std::list<guint32>::const_iterator uit;
584     bool retval = true;
585 
586     // save the stack's ids
587     for (uit = d_attackers.begin(); uit != d_attackers.end(); uit++)
588       s += String::ucompose("%1 ", (*uit));
589     retval &= helper->saveData("attackers", s);
590 
591     s = "";
592     for (uit = d_defenders.begin(); uit != d_defenders.end(); uit++)
593       s += String::ucompose("%1 ", (*uit));
594     retval &= helper->saveData("defenders", s);
595 
596     s = "";
597     for (auto i : d_attacker_army_ids)
598       s += String::ucompose("%1 ", i);
599     retval &= helper->saveData("attacker_army_ids", s);
600 
601     s = "";
602     for (auto i : d_defender_army_ids)
603       s += String::ucompose("%1 ", i);
604     retval &= helper->saveData("defender_army_ids", s);
605 
606     // save what happened
607     for (std::list<FightItem>::const_iterator fit = d_history.begin();
608             fit != d_history.end(); fit++)
609     {
610         retval &= helper->openTag(Item::d_tag);
611         retval &= helper->saveData("turn", (*fit).turn);
612         retval &= helper->saveData("id", (*fit).id);
613         retval &= helper->saveData("damage", (*fit).damage);
614         retval &= helper->closeTag();
615     }
616 
617     return retval;
618 }
619 
stack_ids_to_stacks(std::list<guint32> stack_ids,std::list<Stack * > & stacks,guint32 & stack_id) const620 bool Action_Fight::stack_ids_to_stacks(std::list<guint32> stack_ids, std::list<Stack*> &stacks, guint32 &stack_id) const
621 {
622   for (std::list<guint32>::iterator i = stack_ids.begin(); i != stack_ids.end(); i++)
623     {
624       bool found = false;
625       for (Playerlist::iterator j = Playerlist::getInstance()->begin(), jend = Playerlist::getInstance()->end();
626            j != jend; ++j)
627         {
628           Stack *s = (*j)->getStacklist()->getStackById(*i);
629           if (s)
630             {
631               found = true;
632               stacks.push_back(s);
633               break;
634             }
635         }
636       if (found == false)
637         {
638           stack_id = *i;
639           return false;
640         }
641     }
642   return true;
643 }
644 
is_army_id_in_stacks(guint32 id,std::list<guint32> stack_ids) const645 bool Action_Fight::is_army_id_in_stacks(guint32 id, std::list<guint32> stack_ids) const
646 {
647   std::list<Stack*> stacks;
648   guint32 stack_id = 0;
649   bool success = stack_ids_to_stacks(stack_ids, stacks, stack_id);
650   if (!success)
651     return false;
652   bool found = false;
653   for (std::list<Stack*>::iterator i = stacks.begin(); i != stacks.end(); i++)
654     {
655       if ((*i)->getArmyById(id))
656         {
657           found = true;
658           break;
659         }
660     }
661   if (found)
662     return true;
663   else
664     return false;
665 }
666 
loadItem(XML_Helper * helper)667 bool Action_Fight::loadItem(XML_Helper* helper)
668 {
669     FightItem item;
670 
671     helper->getData(item.turn, "turn");
672     helper->getData(item.id, "id");
673     helper->getData(item.damage, "damage");
674 
675     d_history.push_back(item);
676 
677     return true;
678 }
679 
680 //-----------------------------------------------------------------------------
681 //Action_Join
682 
Action_Join(Stack * o,Stack * j)683 Action_Join::Action_Join(Stack* o, Stack* j)
684     :Action(Action::STACK_JOIN), d_orig_id(o->getId()), d_joining_id(j->getId())
685 {
686     if ((o->empty()) || (j->empty())
687         || (o->size() + j->size() > MAX_STACK_SIZE))
688     {
689       std::cerr << String::ucompose("Action_Join: wrong stack size.  expected %1, but got %2.", o->size(), j->size()) << std::endl;
690         return;
691     }
692 }
693 
Action_Join(const Action_Join & a)694 Action_Join::Action_Join(const Action_Join &a)
695 : Action(a), d_orig_id(a.d_orig_id), d_joining_id(a.d_joining_id)
696 {
697 }
698 
Action_Join(XML_Helper * helper)699 Action_Join::Action_Join(XML_Helper* helper)
700     :Action(helper)
701 {
702     helper->getData(d_orig_id, "receiver");
703     helper->getData(d_joining_id, "joining");
704 }
705 
dump() const706 Glib::ustring Action_Join::dump() const
707 {
708   return String::ucompose("Stack %1 joined stack %2\n", d_joining_id,
709                           d_orig_id);
710 }
711 
doSave(XML_Helper * helper) const712 bool Action_Join::doSave(XML_Helper* helper) const
713 {
714     bool retval = true;
715 
716     retval &= helper->saveData("receiver", d_orig_id);
717     retval &= helper->saveData("joining", d_joining_id);
718 
719     return retval;
720 }
721 
722 //-----------------------------------------------------------------------------
723 //Action_Ruin
724 
Action_Ruin(Ruin * r,Stack * explorers)725 Action_Ruin::Action_Ruin(Ruin *r, Stack *explorers)
726     :Action(Action::RUIN_SEARCH), d_ruin(r->getId()), d_stack(0),
727     d_searched(r->isSearched())
728 {
729   if (explorers)
730     d_stack = explorers->getId();
731 }
732 
Action_Ruin(const Action_Ruin & a)733 Action_Ruin::Action_Ruin(const Action_Ruin&a)
734 : Action(a), d_ruin(a.d_ruin), d_stack(a.d_stack), d_searched(a.d_searched)
735 {
736 }
737 
Action_Ruin(XML_Helper * helper)738 Action_Ruin::Action_Ruin(XML_Helper* helper)
739     :Action(helper)
740 {
741     helper->getData(d_ruin, "ruin");
742     helper->getData(d_stack, "seeker");
743     helper->getData(d_searched, "searched");
744 }
745 
dump() const746 Glib::ustring Action_Ruin::dump() const
747 {
748   Glib::ustring s = String::ucompose("Ruin %1 searched by stack %2.",
749                                      d_ruin, d_stack);
750   s + "  ";
751   if (d_searched)
752     s += "Ruin has been searched.\n";
753   else
754     s += "Ruin has not been searched.\n";
755 
756   return s;
757 }
758 
doSave(XML_Helper * helper) const759 bool Action_Ruin::doSave(XML_Helper* helper) const
760 {
761     bool retval = true;
762 
763     retval &= helper->saveData("ruin", d_ruin);
764     retval &= helper->saveData("seeker", d_stack);
765     retval &= helper->saveData("searched", d_searched);
766 
767     return retval;
768 }
769 
770 //-----------------------------------------------------------------------------
771 //Action_Temple
772 
Action_Temple(Temple * t,Stack * s)773 Action_Temple::Action_Temple(Temple* t, Stack* s)
774     :Action(Action::TEMPLE_SEARCH), d_temple(t->getId()), d_stack(s->getId())
775 {
776 }
777 
Action_Temple(const Action_Temple & action)778 Action_Temple::Action_Temple(const Action_Temple &action)
779 : Action(action), d_temple(action.d_temple), d_stack(action.d_stack)
780 {
781 }
782 
Action_Temple(XML_Helper * helper)783 Action_Temple::Action_Temple(XML_Helper* helper)
784     :Action(helper)
785 {
786     helper->getData(d_temple, "temple");
787     helper->getData(d_stack, "stack");
788 }
789 
dump() const790 Glib::ustring Action_Temple::dump() const
791 {
792   return
793     String::ucompose("Stack %1 visited temple %2.\n", d_stack, d_temple);
794 }
795 
doSave(XML_Helper * helper) const796 bool Action_Temple::doSave(XML_Helper* helper) const
797 {
798     bool retval = true;
799 
800     retval &= helper->saveData("temple", d_temple);
801     retval &= helper->saveData("stack", d_stack);
802 
803     return retval;
804 }
805 
806 //-----------------------------------------------------------------------------
807 //Action_Occupy
808 
Action_Occupy(City * c)809 Action_Occupy::Action_Occupy(City *c)
810     :Action(Action::CITY_OCCUPY), d_city(c->getId())
811 {
812 }
813 
Action_Occupy(const Action_Occupy & action)814 Action_Occupy::Action_Occupy(const Action_Occupy &action)
815 : Action(action), d_city(action.d_city)
816 {
817 }
818 
Action_Occupy(XML_Helper * helper)819 Action_Occupy::Action_Occupy(XML_Helper* helper)
820     :Action(helper)
821 {
822     helper->getData(d_city, "city");
823 }
824 
dump() const825 Glib::ustring Action_Occupy::dump() const
826 {
827   return String::ucompose("City %1 occupied.\n", d_city);
828 }
829 
doSave(XML_Helper * helper) const830 bool Action_Occupy::doSave(XML_Helper* helper) const
831 {
832     return helper->saveData("city", d_city);
833 }
834 
835 //-----------------------------------------------------------------------------
836 //Action_Pillage
837 
Action_Pillage(City * c)838 Action_Pillage::Action_Pillage(City *c)
839     :Action(Action::CITY_PILLAGE), d_city(c->getId())
840 {
841 }
842 
Action_Pillage(const Action_Pillage & action)843 Action_Pillage::Action_Pillage(const Action_Pillage &action)
844 : Action(action), d_city(action.d_city)
845 {
846 }
847 
Action_Pillage(XML_Helper * helper)848 Action_Pillage::Action_Pillage(XML_Helper* helper)
849     :Action(helper)
850 {
851     helper->getData(d_city, "city");
852 }
853 
dump() const854 Glib::ustring Action_Pillage::dump() const
855 {
856   return String::ucompose("City %1 pillaged.\n", d_city);
857 }
858 
doSave(XML_Helper * helper) const859 bool Action_Pillage::doSave(XML_Helper* helper) const
860 {
861     return helper->saveData("city", d_city);
862 }
863 
864 //-----------------------------------------------------------------------------
865 //Action_Sack
866 
Action_Sack(City * c)867 Action_Sack::Action_Sack(City *c)
868     :Action(Action::CITY_SACK), d_city(c->getId())
869 {
870 }
871 
Action_Sack(const Action_Sack & action)872 Action_Sack::Action_Sack(const Action_Sack &action)
873 : Action(action), d_city(action.d_city)
874 {
875 }
876 
Action_Sack(XML_Helper * helper)877 Action_Sack::Action_Sack(XML_Helper* helper)
878     :Action(helper)
879 {
880     helper->getData(d_city, "city");
881 }
882 
dump() const883 Glib::ustring Action_Sack::dump() const
884 {
885   return String::ucompose("City %1 sacked.\n", d_city);
886 }
887 
doSave(XML_Helper * helper) const888 bool Action_Sack::doSave(XML_Helper* helper) const
889 {
890     return helper->saveData("city", d_city);
891 }
892 
893 //-----------------------------------------------------------------------------
894 //Action_Raze
895 
Action_Raze(City * c)896 Action_Raze::Action_Raze(City *c)
897     :Action(Action::CITY_RAZE), d_city(c->getId())
898 {
899 }
900 
Action_Raze(const Action_Raze & action)901 Action_Raze::Action_Raze(const Action_Raze &action)
902 : Action(action), d_city(action.d_city)
903 {
904 }
905 
Action_Raze(XML_Helper * helper)906 Action_Raze::Action_Raze(XML_Helper* helper)
907     :Action(helper)
908 {
909     helper->getData(d_city, "city");
910 }
911 
dump() const912 Glib::ustring Action_Raze::dump() const
913 {
914   return String::ucompose("City %1 razed.\n", d_city);
915 }
916 
doSave(XML_Helper * helper) const917 bool Action_Raze::doSave(XML_Helper* helper) const
918 {
919     return helper->saveData("city", d_city);
920 }
921 
922 //-----------------------------------------------------------------------------
923 //Action_Upgrade
924 
Action_Upgrade(City * c)925 Action_Upgrade::Action_Upgrade(City *c)
926     :Action(Action::CITY_UPGRADE), d_city(c->getId())
927 {
928 }
929 
Action_Upgrade(const Action_Upgrade & action)930 Action_Upgrade::Action_Upgrade(const Action_Upgrade &action)
931 : Action(action), d_city(action.d_city)
932 {
933 }
934 
Action_Upgrade(XML_Helper * helper)935 Action_Upgrade::Action_Upgrade(XML_Helper* helper)
936     :Action(helper)
937 {
938     helper->getData(d_city, "city");
939 }
940 
dump() const941 Glib::ustring Action_Upgrade::dump() const
942 {
943   return String::ucompose("Defense of city %1 upgraded.\n", d_city);
944 }
945 
doSave(XML_Helper * helper) const946 bool Action_Upgrade::doSave(XML_Helper* helper) const
947 {
948     return helper->saveData("city", d_city);
949 }
950 
951 //-----------------------------------------------------------------------------
952 //Action_Buy
953 
Action_Buy(City * c,int s,const ArmyProto * p)954 Action_Buy::Action_Buy(City* c, int s, const ArmyProto *p)
955     :Action(Action::CITY_BUY), d_city(c->getId()), d_slot(s), d_prod(p->getId())
956 {
957 }
958 
Action_Buy(const Action_Buy & a)959 Action_Buy::Action_Buy(const Action_Buy &a)
960 : Action(a), d_city(a.d_city), d_slot(a.d_slot), d_prod(a.d_prod)
961 {
962 }
963 
Action_Buy(XML_Helper * helper)964 Action_Buy::Action_Buy(XML_Helper* helper)
965     :Action(helper)
966 {
967     helper->getData(d_city, "city");
968     helper->getData(d_slot, "slot");
969     helper->getData(d_prod, "production");
970 }
971 
dump() const972 Glib::ustring Action_Buy::dump() const
973 {
974   return String::ucompose("Production %1 bought in city %2 slot: %3.\n",
975                           d_prod, d_city, d_slot);
976 }
977 
doSave(XML_Helper * helper) const978 bool Action_Buy::doSave(XML_Helper* helper) const
979 {
980     bool retval = true;
981 
982     retval &= helper->saveData("city", d_city);
983     retval &= helper->saveData("slot", d_slot);
984     retval &= helper->saveData("production", d_prod);
985 
986     return retval;
987 }
988 
989 //-----------------------------------------------------------------------------
990 //Action_Change_Production
991 
Action_Production(City * c,int slot)992 Action_Production::Action_Production(City* c, int slot)
993     :Action(Action::CITY_PROD), d_city(c->getId()), d_prod(slot)
994 {
995 }
996 
Action_Production(const Action_Production & action)997 Action_Production::Action_Production (const Action_Production &action)
998 : Action(action), d_city(action.d_city), d_prod(action.d_prod)
999 {
1000 }
1001 
Action_Production(XML_Helper * helper)1002 Action_Production::Action_Production(XML_Helper* helper)
1003     :Action(helper)
1004 {
1005     helper->getData(d_city, "city");
1006     helper->getData(d_prod, "production");
1007 }
1008 
dump() const1009 Glib::ustring Action_Production::dump() const
1010 {
1011   return String::ucompose("Production in city %1 changed to %2.\n",
1012                           d_city, d_prod);
1013 }
1014 
doSave(XML_Helper * helper) const1015 bool Action_Production::doSave(XML_Helper* helper) const
1016 {
1017     bool retval = true;
1018 
1019     retval &= helper->saveData("city", d_city);
1020     retval &= helper->saveData("production", d_prod);
1021 
1022     return retval;
1023 }
1024 
1025 //-----------------------------------------------------------------------------
1026 //Action_Reward
1027 
Action_Reward(Stack * s,Reward * r)1028 Action_Reward::Action_Reward(Stack *s, Reward* r)
1029     :Action(Action::REWARD), d_stack(s->getId())
1030 {
1031   d_reward = Reward::copy (r);
1032 }
1033 
~Action_Reward()1034 Action_Reward::~Action_Reward()
1035 {
1036   delete d_reward;
1037 }
1038 
load(Glib::ustring tag,XML_Helper * helper)1039 bool Action_Reward::load(Glib::ustring tag, XML_Helper *helper)
1040 {
1041     if (tag == Reward::d_tag)
1042       {
1043 	guint32 t;
1044 	Glib::ustring type_str;
1045 	helper->getData(type_str, "type");
1046 	t = Reward::rewardTypeFromString(type_str);
1047 	switch (t)
1048 	  {
1049 	  case  Reward::GOLD:
1050 	    d_reward = new Reward_Gold(helper); break;
1051 	  case  Reward::ALLIES:
1052 	    d_reward = new Reward_Allies(helper); break;
1053 	  case Reward::ITEM:
1054 	    d_reward = new Reward_Item(helper); break;
1055 	  case Reward::RUIN:
1056 	    d_reward = new Reward_Ruin(helper); break;
1057 	  case Reward::MAP:
1058 	    d_reward = new Reward_Map(helper); break;
1059 	  }
1060 	return true;
1061       }
1062     return false;
1063 }
1064 
Action_Reward(const Action_Reward & action)1065 Action_Reward::Action_Reward (const Action_Reward &action)
1066 : Action(action), d_stack(action.d_stack)
1067 {
1068   const Reward *reward = action.d_reward;
1069   if (reward)
1070     d_reward = Reward::copy(reward);
1071   else
1072     d_reward = NULL;
1073 }
1074 
Action_Reward(XML_Helper * helper)1075 Action_Reward::Action_Reward(XML_Helper* helper)
1076 :Action(helper)
1077 {
1078   helper->getData(d_stack, "stack");
1079   d_reward = NULL;
1080   helper->registerTag(Reward::d_tag, sigc::mem_fun(this, &Action_Reward::load));
1081 }
1082 
dump() const1083 Glib::ustring Action_Reward::dump() const
1084 {
1085   if (d_reward->getType() == Reward::GOLD)
1086     {
1087       Reward_Gold *r = dynamic_cast<Reward_Gold*>(d_reward);
1088       return String::ucompose("Stack %1 got a reward of type %2: %3 gp.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()), r->getGold());
1089     }
1090   else if (d_reward->getType() == Reward::ALLIES)
1091     {
1092       Reward_Allies*r = dynamic_cast<Reward_Allies*>(d_reward);
1093       return String::ucompose("Stack %1 got a reward of type %2: %3 %4.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()), r->getNoOfAllies(), r->getArmy()->getName());
1094     }
1095   else if (d_reward->getType() == Reward::ITEM)
1096     {
1097       Reward_Item *r = dynamic_cast<Reward_Item*>(d_reward);
1098       return String::ucompose("Stack %1 got a reward of type %2: %3.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()), r->getItem()->getName());
1099     }
1100   else if (d_reward->getType() == Reward::RUIN)
1101     {
1102       Reward_Ruin *r = dynamic_cast<Reward_Ruin*>(d_reward);
1103       return String::ucompose("Stack %1 got a reward of type %2: %3,%4 %5.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()), r->getRuin()->getPos().x, r->getRuin()->getPos().y, r->getRuin()->getName());
1104     }
1105   else if (d_reward->getType() == Reward::MAP)
1106     {
1107       Reward_Map*r = dynamic_cast<Reward_Map*>(d_reward);
1108       return String::ucompose("Stack %1 got a reward of type %2: %3,%4 %5.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()), r->getLocation().x, r->getLocation().y, r->getMapName());
1109     }
1110   return String::ucompose("Stack %1 got a reward of type %2.\n", d_stack, Reward::rewardTypeToString(d_reward->getType()));
1111 }
1112 
doSave(XML_Helper * helper) const1113 bool Action_Reward::doSave(XML_Helper* helper) const
1114 {
1115   bool retval = true;
1116 
1117   retval &= helper->saveData("stack", d_stack);
1118   if (d_reward->getType() == Reward::GOLD)
1119     retval &= dynamic_cast<Reward_Gold*>(d_reward)->save(helper);
1120   else if (d_reward->getType() == Reward::ALLIES)
1121     retval &= dynamic_cast<Reward_Allies*>(d_reward)->save(helper);
1122   else if (d_reward->getType() == Reward::ITEM)
1123     retval &= dynamic_cast<Reward_Item*>(d_reward)->save(helper);
1124   else if (d_reward->getType() == Reward::RUIN)
1125     retval &= dynamic_cast<Reward_Ruin*>(d_reward)->save(helper);
1126   else if (d_reward->getType() == Reward::MAP)
1127     retval &= dynamic_cast<Reward_Map*>(d_reward)->save(helper);
1128 
1129   return retval;
1130 }
1131 
1132 //-----------------------------------------------------------------------------
1133 // Action_Quest
1134 
Action_Quest(Quest * q)1135 Action_Quest::Action_Quest(Quest* q)
1136 :Action(Action::QUEST), d_hero(q->getHeroId()), d_questtype(q->getType()),
1137     d_data(0), d_victim_player(0)
1138 {
1139   // fill the data depending on the quest's type
1140   switch (d_questtype)
1141     {
1142     case Quest::KILLHERO:
1143       d_data = dynamic_cast<QuestKillHero*>(q)->getVictim();
1144       break;
1145     case Quest::KILLARMIES:
1146       d_data = dynamic_cast<QuestEnemyArmies*>(q)->getArmiesToKill();
1147       d_victim_player = dynamic_cast<QuestEnemyArmies*>(q)->getVictimPlayerId();
1148       break;
1149     case Quest::CITYSACK:
1150       d_data = dynamic_cast<QuestCitySack*>(q)->getCityId();
1151       break;
1152     case Quest::CITYRAZE:
1153       d_data = dynamic_cast<QuestCityRaze*>(q)->getCityId();
1154       break;
1155     case Quest::CITYOCCUPY:
1156       d_data = dynamic_cast<QuestCityOccupy*>(q)->getCityId();
1157       break;
1158     case Quest::KILLARMYTYPE:
1159       d_data = dynamic_cast<QuestEnemyArmytype*>(q)->getArmytypeToKill();
1160       break;
1161     case Quest::PILLAGEGOLD:
1162       d_data = dynamic_cast<QuestPillageGold*>(q)->getGoldToPillage();
1163       break;
1164     }
1165 }
1166 
Action_Quest(const Action_Quest & a)1167 Action_Quest::Action_Quest (const Action_Quest &a)
1168 : Action(a), d_hero(a.d_hero), d_questtype(a.d_questtype), d_data(a.d_data),
1169     d_victim_player(a.d_victim_player)
1170 {
1171 }
1172 
Action_Quest(XML_Helper * helper)1173 Action_Quest::Action_Quest(XML_Helper* helper)
1174 :Action(helper)
1175 {
1176 
1177   helper->getData(d_hero, "hero");
1178   Glib::ustring s;
1179   helper->getData(s, "quest");
1180   d_questtype = Quest::questTypeFromString(s);
1181   helper->getData(d_data, "data");
1182   helper->getData(d_victim_player, "victim_player");
1183 }
1184 
dump() const1185 Glib::ustring Action_Quest::dump() const
1186 {
1187   return String::ucompose("Hero %1 has got quest of type %2 with data %3 to fulfill\n", d_hero, d_questtype, d_data);
1188 }
1189 
doSave(XML_Helper * helper) const1190 bool Action_Quest::doSave(XML_Helper* helper) const
1191 {
1192   bool retval = true;
1193 
1194   retval &= helper->saveData("hero", d_hero);
1195   Glib::ustring s = Quest::questTypeToString(Quest::Type(d_questtype));
1196   retval &= helper->saveData("quest", s);
1197   retval &= helper->saveData("data", d_data);
1198   retval &= helper->saveData("victim_player", d_victim_player);
1199 
1200   return retval;
1201 }
1202 
1203 //-----------------------------------------------------------------------------
1204 // Action_Equip
1205 
Action_Equip(Hero * h,Item * i,Action_Equip::Slot slot,Vector<int> pos)1206 Action_Equip::Action_Equip(Hero *h, Item *i, Action_Equip::Slot slot, Vector<int> pos)
1207 :Action(Action::HERO_EQUIP), d_hero(h->getId()), d_item(i->getId()),
1208     d_slot(slot), d_pos(pos)
1209 {
1210 }
1211 
Action_Equip(const Action_Equip & a)1212 Action_Equip::Action_Equip (const Action_Equip &a)
1213 : Action(a), d_hero(a.d_hero), d_item(a.d_item), d_slot(a.d_slot),
1214     d_pos(a.d_pos)
1215 {
1216 }
1217 
Action_Equip(XML_Helper * helper)1218 Action_Equip::Action_Equip(XML_Helper* helper)
1219 :Action(helper)
1220 {
1221   helper->getData(d_hero, "hero");
1222   helper->getData(d_item, "item");
1223   helper->getData(d_slot, "dest");
1224   int i;
1225   helper->getData(i, "x");
1226   d_pos.x = i;
1227   helper->getData(i, "y");
1228   d_pos.y = i;
1229 }
1230 
dump() const1231 Glib::ustring Action_Equip::dump() const
1232 {
1233   return String::ucompose("Hero %1 moved item %2 to slot %3 at tile %4,%5.\n",
1234                           d_hero, d_item, d_slot, d_pos.x, d_pos.y);
1235 }
1236 
doSave(XML_Helper * helper) const1237 bool Action_Equip::doSave(XML_Helper* helper) const
1238 {
1239   bool retval = true;
1240 
1241   retval &= helper->saveData("hero", d_hero);
1242   retval &= helper->saveData("item", d_item);
1243   retval &= helper->saveData("dest", d_slot);
1244   int i = d_pos.x;
1245   retval &= helper->saveData("x", i);
1246   i = d_pos.y;
1247   retval &= helper->saveData("y", i);
1248 
1249   return retval;
1250 }
1251 
1252 //-----------------------------------------------------------------------------
1253 // Action_Level
1254 
Action_Level(Army * unit,Army::Stat raised)1255 Action_Level::Action_Level(Army *unit, Army::Stat raised)
1256 :Action(Action::UNIT_ADVANCE), d_army(unit->getId()), d_stat(raised)
1257 {
1258 }
1259 
Action_Level(const Action_Level & action)1260 Action_Level::Action_Level (const Action_Level &action)
1261 : Action(action), d_army(action.d_army), d_stat(action.d_stat)
1262 {
1263 }
1264 
Action_Level(XML_Helper * helper)1265 Action_Level::Action_Level(XML_Helper* helper)
1266 :Action(helper)
1267 {
1268   helper->getData(d_army, "army");
1269   helper->getData(d_stat, "stat");
1270 }
1271 
dump() const1272 Glib::ustring Action_Level::dump() const
1273 {
1274   return String::ucompose("Army unit %1 advanced level and increased stat type %2", d_army, d_stat);
1275 }
1276 
doSave(XML_Helper * helper) const1277 bool Action_Level::doSave(XML_Helper* helper) const
1278 {
1279   bool retval = true;
1280 
1281   retval &= helper->saveData("army", d_army);
1282   retval &= helper->saveData("stat", d_stat);
1283 
1284   return retval;
1285 }
1286 
1287 //-----------------------------------------------------------------------------
1288 //Action_Disband
1289 
Action_Disband(Stack * s)1290 Action_Disband::Action_Disband(Stack *s)
1291 :Action(Action::STACK_DISBAND), d_stack(s->getId())
1292 {
1293 }
1294 
Action_Disband(const Action_Disband & action)1295 Action_Disband::Action_Disband(const Action_Disband &action)
1296 : Action(action), d_stack(action.d_stack)
1297 {
1298 }
1299 
Action_Disband(XML_Helper * helper)1300 Action_Disband::Action_Disband(XML_Helper* helper)
1301 :Action(helper)
1302 {
1303   helper->getData(d_stack, "stack");
1304 }
1305 
dump() const1306 Glib::ustring Action_Disband::dump() const
1307 {
1308   return String::ucompose("Stack %1 disbanded.\n", d_stack);
1309 }
1310 
doSave(XML_Helper * helper) const1311 bool Action_Disband::doSave(XML_Helper* helper) const
1312 {
1313   return helper->saveData("stack", d_stack);
1314 }
1315 
1316 //-----------------------------------------------------------------------------
1317 //Action_ModifySignpost
1318 
Action_ModifySignpost(Signpost * s,Glib::ustring message)1319 Action_ModifySignpost::Action_ModifySignpost(Signpost * s, Glib::ustring message)
1320 :Action(Action::MODIFY_SIGNPOST), d_signpost(s->getId()), d_message(message)
1321 {
1322 }
1323 
Action_ModifySignpost(const Action_ModifySignpost & a)1324 Action_ModifySignpost::Action_ModifySignpost(const Action_ModifySignpost &a)
1325 : Action(a), d_signpost(a.d_signpost), d_message(a.d_message)
1326 {
1327 }
1328 
Action_ModifySignpost(XML_Helper * helper)1329 Action_ModifySignpost::Action_ModifySignpost(XML_Helper* helper)
1330 :Action(helper)
1331 {
1332   helper->getData(d_signpost, "signpost");
1333   helper->getData(d_message, "message");
1334 }
1335 
dump() const1336 Glib::ustring Action_ModifySignpost::dump() const
1337 {
1338   return String::ucompose("Signpost %1 modified to read %2.\n", d_signpost, d_message);
1339 }
1340 
doSave(XML_Helper * helper) const1341 bool Action_ModifySignpost::doSave(XML_Helper* helper) const
1342 {
1343   bool retval = true;
1344 
1345   retval &= helper->saveData("signpost", d_signpost);
1346   retval &= helper->saveData("message", d_message);
1347 
1348   return retval;
1349 }
1350 
1351 //-----------------------------------------------------------------------------
1352 //Action_RenameCity
1353 
Action_RenameCity(City * c,Glib::ustring name)1354 Action_RenameCity::Action_RenameCity(City* c, Glib::ustring name)
1355 :Action(Action::CITY_RENAME), d_city(c->getId()), d_name(name)
1356 {
1357 }
1358 
Action_RenameCity(const Action_RenameCity & action)1359 Action_RenameCity::Action_RenameCity(const Action_RenameCity &action)
1360 : Action(action), d_city(action.d_city), d_name(action.d_name)
1361 {
1362 }
1363 
Action_RenameCity(XML_Helper * helper)1364 Action_RenameCity::Action_RenameCity(XML_Helper* helper)
1365 :Action(helper)
1366 {
1367   helper->getData(d_city, "city");
1368   helper->getData(d_name, "name");
1369 }
1370 
dump() const1371 Glib::ustring Action_RenameCity::dump() const
1372 {
1373   return String::ucompose("City %1 renamed to %2.\n", d_city, d_name);
1374 }
1375 
doSave(XML_Helper * helper) const1376 bool Action_RenameCity::doSave(XML_Helper* helper) const
1377 {
1378   bool retval = true;
1379 
1380   retval &= helper->saveData("city", d_city);
1381   retval &= helper->saveData("name", d_name);
1382 
1383   return retval;
1384 }
1385 
1386 //-----------------------------------------------------------------------------
1387 //Action_Vector
1388 
Action_Vector(City * src,Vector<int> dest)1389 Action_Vector::Action_Vector(City* src, Vector<int> dest)
1390 :Action(Action::CITY_VECTOR), d_city(src->getId()), d_dest(dest)
1391 {
1392 }
1393 
Action_Vector(const Action_Vector & action)1394 Action_Vector::Action_Vector(const Action_Vector &action)
1395 : Action(action), d_city(action.d_city), d_dest(action.d_dest)
1396 {
1397 }
1398 
Action_Vector(XML_Helper * helper)1399 Action_Vector::Action_Vector(XML_Helper* helper)
1400 :Action(helper)
1401 {
1402   helper->getData(d_city, "city");
1403   helper->getData(d_dest.x, "x");
1404   helper->getData(d_dest.y, "y");
1405 }
1406 
dump() const1407 Glib::ustring Action_Vector::dump() const
1408 {
1409   return String::ucompose("Vectoring new army units from city %1 to %2,%3.\n",
1410                           d_city, d_dest.x, d_dest.y);
1411 }
1412 
doSave(XML_Helper * helper) const1413 bool Action_Vector::doSave(XML_Helper* helper) const
1414 {
1415   bool retval = true;
1416 
1417   retval &= helper->saveData("city", d_city);
1418   retval &= helper->saveData("x", d_dest.x);
1419   retval &= helper->saveData("y", d_dest.y);
1420 
1421   return retval;
1422 }
1423 
1424 //-----------------------------------------------------------------------------
1425 //Action_FightOrder
1426 
Action_FightOrder(std::list<guint32> order)1427 Action_FightOrder::Action_FightOrder(std::list<guint32> order)
1428 :Action(Action::FIGHT_ORDER), d_order(order)
1429 {
1430 }
1431 
Action_FightOrder(const Action_FightOrder & action)1432 Action_FightOrder::Action_FightOrder(const Action_FightOrder &action)
1433 : Action(action), d_order(action.d_order)
1434 {
1435 }
1436 
Action_FightOrder(XML_Helper * helper)1437 Action_FightOrder::Action_FightOrder(XML_Helper* helper)
1438 :Action(helper)
1439 {
1440   Glib::ustring fight_order;
1441   std::stringstream sfight_order;
1442   guint32 val;
1443   helper->getData(fight_order, "order");
1444   sfight_order.str(fight_order);
1445   //XXX XXX XXX this business of looking up the first living seems wrong.
1446   Armyset *as = Armysetlist::getInstance()->get(Playerlist::getInstance()->getFirstLiving()->getArmyset());
1447   for (Armyset::iterator i = as->begin(); i != as->end(); i++)
1448     {
1449       sfight_order >> val;
1450       d_order.push_back(val);
1451     }
1452 }
1453 
dump() const1454 Glib::ustring Action_FightOrder::dump() const
1455 {
1456   Glib::ustring s = "Changed fight order to: ";
1457   for (std::list<guint32>::const_iterator it = d_order.begin();
1458        it != d_order.end(); ++it)
1459     s += String::ucompose("%1 ", (*it));
1460   s += "\n";
1461   return s;
1462 }
1463 
doSave(XML_Helper * helper) const1464 bool Action_FightOrder::doSave(XML_Helper* helper) const
1465 {
1466   bool retval = true;
1467 
1468   Glib::ustring s;
1469   for (std::list<guint32>::const_iterator it = d_order.begin();
1470        it != d_order.end(); it++)
1471     s += String::ucompose("%1 ", (*it));
1472   retval &= helper->saveData("order", s);
1473 
1474   return retval;
1475 }
1476 
1477 //-----------------------------------------------------------------------------
1478 //Action_Resign
1479 
Action_Resign()1480 Action_Resign::Action_Resign()
1481 :Action(Action::RESIGN)
1482 {
1483 }
1484 
Action_Resign(const Action_Resign & action)1485 Action_Resign::Action_Resign(const Action_Resign &action)
1486 : Action(action)
1487 {
1488 }
1489 
Action_Resign(XML_Helper * helper)1490 Action_Resign::Action_Resign(XML_Helper* helper)
1491 :Action(helper)
1492 {
1493 }
1494 
dump() const1495 Glib::ustring Action_Resign::dump() const
1496 {
1497   return "This player resigns.\n";
1498 }
1499 
doSave(XML_Helper * helper) const1500 bool Action_Resign::doSave(XML_Helper* helper) const
1501 {
1502   if (helper)
1503     return true;
1504   return false;
1505 }
1506 
1507 //-----------------------------------------------------------------------------
1508 //Action_Plant
1509 
Action_Plant(Hero * hero,Item * item)1510 Action_Plant::Action_Plant(Hero *hero, Item *item)
1511 :Action(Action::ITEM_PLANT), d_hero(hero->getId()), d_item(item->getId())
1512 {
1513 }
1514 
Action_Plant(const Action_Plant & action)1515 Action_Plant::Action_Plant(const Action_Plant &action)
1516 : Action(action), d_hero(action.d_hero), d_item(action.d_item)
1517 {
1518 }
1519 
Action_Plant(XML_Helper * helper)1520 Action_Plant::Action_Plant(XML_Helper* helper)
1521 :Action(helper)
1522 {
1523   helper->getData(d_hero, "hero");
1524   helper->getData(d_item, "item");
1525 }
1526 
dump() const1527 Glib::ustring Action_Plant::dump() const
1528 {
1529   return String::ucompose("Hero %1 plants item %2.\n", d_hero, d_item);
1530 }
1531 
doSave(XML_Helper * helper) const1532 bool Action_Plant::doSave(XML_Helper* helper) const
1533 {
1534   bool retval = true;
1535 
1536   retval &= helper->saveData("hero", d_hero);
1537   retval &= helper->saveData("item", d_item);
1538 
1539   return retval;
1540 }
1541 
1542 //-----------------------------------------------------------------------------
1543 //Action_Produce
1544 
Action_Produce(const ArmyProdBase * army,City * city,bool vectored,Vector<int> pos,guint32 army_id,guint32 stack_id)1545 Action_Produce::Action_Produce(const ArmyProdBase *army, City *city,
1546                                bool vectored, Vector<int> pos, guint32 army_id,
1547                                guint32 stack_id)
1548 :Action(Action::PRODUCE_UNIT), d_army(new ArmyProdBase(*army)),
1549     d_city(city->getId()), d_vectored(vectored), d_dest(pos),
1550     d_army_id(army_id), d_stack_id(stack_id)
1551 {
1552 }
1553 
Action_Produce(const Action_Produce & a)1554 Action_Produce::Action_Produce(const Action_Produce &a)
1555 : Action(a), d_city(a.d_city), d_vectored(a.d_vectored), d_dest(a.d_dest),
1556     d_army_id(a.d_army_id), d_stack_id(a.d_stack_id)
1557 {
1558   if (a.d_army)
1559     d_army = new ArmyProdBase (*a.d_army);
1560   else
1561     d_army = NULL;
1562 }
1563 
Action_Produce(XML_Helper * helper)1564 Action_Produce::Action_Produce(XML_Helper* helper)
1565 :Action(helper)
1566 {
1567   helper->getData(d_city, "city");
1568   helper->getData(d_vectored, "vectored");
1569   helper->getData(d_dest.x, "dest_x");
1570   helper->getData(d_dest.y, "dest_y");
1571   helper->getData(d_army_id, "army_id");
1572   helper->getData(d_stack_id, "stack_id");
1573   d_army = NULL;
1574   helper->registerTag(ArmyProdBase::d_tag, sigc::mem_fun(this, &Action_Produce::load));
1575 }
1576 
load(Glib::ustring tag,XML_Helper * helper)1577 bool Action_Produce::load(Glib::ustring tag, XML_Helper *helper)
1578 {
1579     if (tag == ArmyProdBase::d_tag)
1580       {
1581 	d_army = new ArmyProdBase(helper);
1582 
1583 	return true;
1584       }
1585     return false;
1586 }
1587 
~Action_Produce()1588 Action_Produce::~Action_Produce()
1589 {
1590   if (d_army)
1591     delete d_army;
1592 }
1593 
dump() const1594 Glib::ustring Action_Produce::dump() const
1595 {
1596   Glib::ustring s = String::ucompose("Army id %1 of type %2 shows up at city %3 ", d_army_id, d_army->getTypeId(), d_city);
1597   if (d_vectored)
1598     s += String::ucompose("but it is vectored to another city at %1,%2.", d_dest.x, d_dest.y);
1599   else
1600     s += String::ucompose("at position %1,%2 in stack %3.", d_dest.x, d_dest.y, d_stack_id);
1601   s+= "\n";
1602 
1603   return s;
1604 }
1605 
doSave(XML_Helper * helper) const1606 bool Action_Produce::doSave(XML_Helper* helper) const
1607 {
1608   bool retval = true;
1609 
1610   retval &= helper->saveData("city", d_city);
1611   retval &= helper->saveData("vectored", d_vectored);
1612   retval &= helper->saveData("dest_x", d_dest.x);
1613   retval &= helper->saveData("dest_y", d_dest.y);
1614   retval &= helper->saveData("army_id", d_army_id);
1615   retval &= helper->saveData("stack_id", d_stack_id);
1616   retval &= d_army->save(helper);
1617 
1618   return retval;
1619 }
1620 
1621 //-----------------------------------------------------------------------------
1622 //Action_ProduceVectored
1623 
Action_ProduceVectored(ArmyProdBase * army,Vector<int> dest,Vector<int> src,guint32 aid,guint32 sid)1624 Action_ProduceVectored::Action_ProduceVectored(ArmyProdBase *army,
1625                                                Vector<int> dest,
1626                                                Vector<int> src, guint32 aid,
1627                                                guint32 sid)
1628 :Action(Action::PRODUCE_VECTORED_UNIT), d_army(NULL), d_dest(dest), d_src(src),
1629     d_target_army_id (aid), d_target_stack_id (sid)
1630 {
1631   if (army)
1632     d_army = new ArmyProdBase(*army);
1633 }
1634 
Action_ProduceVectored(const Action_ProduceVectored & a)1635 Action_ProduceVectored::Action_ProduceVectored(const Action_ProduceVectored &a)
1636 : Action(a), d_dest(a.d_dest), d_src(a.d_src),
1637     d_target_army_id (a.d_target_army_id),
1638     d_target_stack_id (a.d_target_stack_id)
1639 {
1640   if (a.d_army)
1641     d_army = new ArmyProdBase(*a.d_army);
1642   else
1643     d_army = NULL;
1644 }
1645 
Action_ProduceVectored(XML_Helper * helper)1646 Action_ProduceVectored::Action_ProduceVectored(XML_Helper* helper)
1647 :Action(helper), d_army(NULL)
1648 {
1649   helper->getData(d_dest.x, "dest_x");
1650   helper->getData(d_dest.y, "dest_y");
1651   helper->getData(d_src.x, "src_x");
1652   helper->getData(d_src.y, "src_y");
1653   helper->getData(d_target_army_id, "target_army_id");
1654   helper->getData(d_target_stack_id, "target_stack_id");
1655   d_army = NULL;
1656   helper->registerTag(ArmyProdBase::d_tag, sigc::mem_fun(this, &Action_ProduceVectored::load));
1657 }
1658 
load(Glib::ustring tag,XML_Helper * helper)1659 bool Action_ProduceVectored::load(Glib::ustring tag, XML_Helper *helper)
1660 {
1661     if (tag == ArmyProdBase::d_tag)
1662       {
1663 	d_army = new ArmyProdBase(helper);
1664 
1665 	return true;
1666       }
1667     return false;
1668 }
1669 
~Action_ProduceVectored()1670 Action_ProduceVectored::~Action_ProduceVectored()
1671 {
1672   if (d_army)
1673     delete d_army;
1674 }
1675 
dump() const1676 Glib::ustring Action_ProduceVectored::dump() const
1677 {
1678   return String::ucompose("Vectored army of type %1 shows up at %2,%3 from %4,%5, as army id %6 in stack id %7.\n", d_army->getTypeId(), d_dest.x, d_dest.y, d_src.x, d_src.y, d_target_army_id, d_target_stack_id);
1679 }
1680 
doSave(XML_Helper * helper) const1681 bool Action_ProduceVectored::doSave(XML_Helper* helper) const
1682 {
1683   bool retval = true;
1684 
1685   retval &= helper->saveData("dest_x", d_dest.x);
1686   retval &= helper->saveData("dest_y", d_dest.y);
1687   retval &= helper->saveData("src_x", d_src.x);
1688   retval &= helper->saveData("src_y", d_src.y);
1689   retval &= helper->saveData("target_army_id", d_target_army_id);
1690   retval &= helper->saveData("target_stack_id", d_target_stack_id);
1691   retval &= d_army->save(helper);
1692 
1693   return retval;
1694 }
1695 
1696 //-----------------------------------------------------------------------------
1697 //Action_DiplomacyState
1698 
Action_DiplomacyState(Player * p,Player::DiplomaticState state)1699 Action_DiplomacyState::Action_DiplomacyState(Player *p,
1700                                              Player::DiplomaticState state)
1701 :Action(Action::DIPLOMATIC_STATE), d_opponent_id(p->getId()),
1702     d_diplomatic_state(state)
1703 {
1704 }
1705 
Action_DiplomacyState(const Action_DiplomacyState & a)1706 Action_DiplomacyState::Action_DiplomacyState(const Action_DiplomacyState &a)
1707 : Action(a), d_opponent_id(a.d_opponent_id),
1708     d_diplomatic_state(a.d_diplomatic_state)
1709 {
1710 }
1711 
Action_DiplomacyState(XML_Helper * helper)1712 Action_DiplomacyState::Action_DiplomacyState(XML_Helper* helper)
1713 :Action(helper)
1714 {
1715   guint32 diplomatic_state;
1716   helper->getData(d_opponent_id, "opponent_id");
1717   helper->getData(diplomatic_state, "state");
1718   d_diplomatic_state = Player::DiplomaticState(diplomatic_state);
1719 }
1720 
dump() const1721 Glib::ustring Action_DiplomacyState::dump() const
1722 {
1723   Glib::ustring s = "declaring ";
1724   switch (d_diplomatic_state)
1725     {
1726     case Player::AT_WAR: s+= "war"; break;
1727     case Player::AT_WAR_IN_FIELD: s += "war in the field"; break;
1728     case Player::AT_PEACE: s += "peace"; break;
1729     }
1730   s += String::ucompose(" with player %1.\n", d_opponent_id);
1731   return s;
1732 }
1733 
doSave(XML_Helper * helper) const1734 bool Action_DiplomacyState::doSave(XML_Helper* helper) const
1735 {
1736   bool retval = true;
1737 
1738   retval &= helper->saveData("opponent_id", d_opponent_id);
1739   retval &= helper->saveData("state", (guint32)d_diplomatic_state);
1740 
1741   return retval;
1742 }
1743 
1744 //-----------------------------------------------------------------------------
1745 //Action_DiplomacyProposal
1746 
Action_DiplomacyProposal(Player * p,Player::DiplomaticProposal proposal)1747 Action_DiplomacyProposal::Action_DiplomacyProposal(Player *p,
1748                                                    Player::DiplomaticProposal proposal)
1749 :Action(Action::DIPLOMATIC_PROPOSAL), d_opponent_id(p->getId()),
1750     d_diplomatic_proposal(proposal)
1751 {
1752 
1753 }
1754 
Action_DiplomacyProposal(const Action_DiplomacyProposal & a)1755 Action_DiplomacyProposal::Action_DiplomacyProposal(const Action_DiplomacyProposal &a)
1756 : Action(a), d_opponent_id(a.d_opponent_id),
1757     d_diplomatic_proposal(a.d_diplomatic_proposal)
1758 {
1759 }
1760 
Action_DiplomacyProposal(XML_Helper * helper)1761 Action_DiplomacyProposal::Action_DiplomacyProposal(XML_Helper* helper)
1762 :Action(helper)
1763 {
1764   guint32 diplomatic_proposal;
1765   helper->getData(d_opponent_id, "opponent_id");
1766   helper->getData(diplomatic_proposal, "proposal");
1767   d_diplomatic_proposal = Player::DiplomaticProposal(diplomatic_proposal);
1768 }
1769 
dump() const1770 Glib::ustring Action_DiplomacyProposal::dump() const
1771 {
1772   Glib::ustring s = "proposing ";
1773   switch (d_diplomatic_proposal)
1774     {
1775     case Player::NO_PROPOSAL: s +="nothing"; break;
1776     case Player::PROPOSE_WAR: s +="war"; break;
1777     case Player::PROPOSE_WAR_IN_FIELD: s +="war in the field"; break;
1778     case Player::PROPOSE_PEACE: s +="peace"; break;
1779     }
1780   s += String::ucompose(" with player %1.\n", d_opponent_id);
1781   return s;
1782 }
1783 
doSave(XML_Helper * helper) const1784 bool Action_DiplomacyProposal::doSave(XML_Helper* helper) const
1785 {
1786   bool retval = true;
1787 
1788   retval &= helper->saveData("opponent_id", d_opponent_id);
1789   retval &= helper->saveData("proposal", (guint32)d_diplomatic_proposal);
1790 
1791   return retval;
1792 }
1793 
1794 //-----------------------------------------------------------------------------
1795 //Action_DiplomacyScore
1796 
Action_DiplomacyScore(Player * p,int amount)1797 Action_DiplomacyScore::Action_DiplomacyScore(Player *p, int amount)
1798 :Action(Action::DIPLOMATIC_SCORE), d_opponent_id(p->getId()), d_amount(amount)
1799 {
1800 }
1801 
Action_DiplomacyScore(const Action_DiplomacyScore & a)1802 Action_DiplomacyScore::Action_DiplomacyScore(const Action_DiplomacyScore &a)
1803 : Action(a), d_opponent_id(a.d_opponent_id), d_amount(a.d_amount)
1804 {
1805 }
1806 
Action_DiplomacyScore(XML_Helper * helper)1807 Action_DiplomacyScore::Action_DiplomacyScore(XML_Helper* helper)
1808 :Action(helper)
1809 {
1810   helper->getData(d_opponent_id, "opponent_id");
1811   helper->getData(d_amount, "amount");
1812 }
1813 
dump() const1814 Glib::ustring Action_DiplomacyScore::dump() const
1815 {
1816   if (d_amount > 0)
1817     return String::ucompose("Adding %1 to player %2.\n", d_amount, d_opponent_id);
1818   else
1819     return String::ucompose("Subtracting %1 from player %2.\n", d_amount, d_opponent_id);
1820 }
1821 
doSave(XML_Helper * helper) const1822 bool Action_DiplomacyScore::doSave(XML_Helper* helper) const
1823 {
1824   bool retval = true;
1825 
1826   retval &= helper->saveData("opponent_id", d_opponent_id);
1827   retval &= helper->saveData("amount", d_amount);
1828 
1829   return retval;
1830 }
1831 
1832 //-----------------------------------------------------------------------------
1833 //Action_EndTurn
1834 
Action_EndTurn()1835 Action_EndTurn::Action_EndTurn()
1836 :Action(Action::END_TURN)
1837 {
1838 }
1839 
Action_EndTurn(const Action_EndTurn & action)1840 Action_EndTurn::Action_EndTurn(const Action_EndTurn &action)
1841 : Action(action)
1842 {
1843 }
1844 
Action_EndTurn(XML_Helper * helper)1845 Action_EndTurn::Action_EndTurn(XML_Helper* helper)
1846 :Action(helper)
1847 {
1848 }
1849 
dump() const1850 Glib::ustring Action_EndTurn::dump() const
1851 {
1852   return "ending turn\n";
1853 }
1854 
doSave(XML_Helper * helper) const1855 bool Action_EndTurn::doSave(XML_Helper* helper) const
1856 {
1857   if (helper)
1858     return true;
1859   return false;
1860 }
1861 
1862 //-----------------------------------------------------------------------------
1863 //Action_ConquerCity
1864 
Action_ConquerCity(City * c)1865 Action_ConquerCity::Action_ConquerCity(City* c)
1866   :Action(Action::CITY_CONQUER), d_city(c->getId())
1867 {
1868 }
1869 
Action_ConquerCity(const Action_ConquerCity & action)1870 Action_ConquerCity::Action_ConquerCity(const Action_ConquerCity &action)
1871 : Action(action), d_city(action.d_city)
1872 {
1873 }
1874 
Action_ConquerCity(XML_Helper * helper)1875 Action_ConquerCity::Action_ConquerCity(XML_Helper* helper)
1876   :Action(helper)
1877 {
1878     helper->getData(d_city, "city");
1879 }
1880 
dump() const1881 Glib::ustring Action_ConquerCity::dump() const
1882 {
1883   return String::ucompose("City %1 occupied.\n", d_city);
1884 }
1885 
doSave(XML_Helper * helper) const1886 bool Action_ConquerCity::doSave(XML_Helper* helper) const
1887 {
1888     return helper->saveData("city", d_city);
1889 }
1890 
1891 //-----------------------------------------------------------------------------
1892 //Action_RecruitHero
1893 
Action_RecruitHero(HeroProto * h,City * c,int cost,int alliesCount,const ArmyProto * ally)1894 Action_RecruitHero::Action_RecruitHero(HeroProto* h, City *c, int cost, int alliesCount, const ArmyProto *ally)
1895   :Action(Action::RECRUIT_HERO), d_hero(new HeroProto(*h)), d_city(c->getId()), d_cost(cost),
1896     d_allies(alliesCount)
1897 {
1898     if (d_allies > 0)
1899       d_ally_army_type = ally->getId();
1900     else
1901       d_ally_army_type = 0;
1902 }
1903 
Action_RecruitHero(XML_Helper * helper)1904 Action_RecruitHero::Action_RecruitHero(XML_Helper* helper)
1905   :Action(helper)
1906 {
1907     helper->getData(d_city, "city");
1908     helper->getData(d_cost, "cost");
1909     helper->getData(d_allies, "allies");
1910     helper->getData(d_ally_army_type, "ally_army_type");
1911     helper->registerTag(HeroProto::d_tag, sigc::mem_fun(this, &Action_RecruitHero::load));
1912 }
1913 
Action_RecruitHero(const Action_RecruitHero & a)1914 Action_RecruitHero::Action_RecruitHero(const Action_RecruitHero &a)
1915 : Action(a), d_city(a.d_city), d_cost(a.d_cost), d_allies(a.d_allies),
1916     d_ally_army_type(a.d_ally_army_type)
1917 {
1918   d_hero = new HeroProto(*a.d_hero);
1919 }
1920 
~Action_RecruitHero()1921 Action_RecruitHero::~Action_RecruitHero()
1922 {
1923   if (d_hero)
1924     delete d_hero;
1925   d_hero = NULL;
1926 }
1927 
load(Glib::ustring tag,XML_Helper * helper)1928 bool Action_RecruitHero::load(Glib::ustring tag, XML_Helper *helper)
1929 {
1930     if (tag == HeroProto::d_tag)
1931       {
1932 	d_hero = new HeroProto(helper);
1933 
1934 	return true;
1935       }
1936     return false;
1937 }
1938 
dump() const1939 Glib::ustring Action_RecruitHero::dump() const
1940 {
1941   return String::ucompose("Hero %1 recruited with %2 allies.\n", d_hero->getName(), d_allies);
1942 }
1943 
doSave(XML_Helper * helper) const1944 bool Action_RecruitHero::doSave(XML_Helper* helper) const
1945 {
1946     bool retval = true;
1947 
1948     retval &= helper->saveData("city", d_city);
1949     retval &= helper->saveData("cost", d_cost);
1950     retval &= helper->saveData("allies", d_allies);
1951     retval &= helper->saveData("ally_army_type", d_ally_army_type);
1952     retval &= d_hero->save(helper);
1953 
1954     return retval;
1955 }
1956 
1957 //-----------------------------------------------------------------------------
1958 //Action_RenamePlayer
1959 
Action_RenamePlayer(Glib::ustring name)1960 Action_RenamePlayer::Action_RenamePlayer(Glib::ustring name)
1961   :Action(Action::PLAYER_RENAME), d_name(name)
1962 {
1963 }
1964 
Action_RenamePlayer(const Action_RenamePlayer & action)1965 Action_RenamePlayer::Action_RenamePlayer(const Action_RenamePlayer &action)
1966 :Action(action), d_name(action.d_name)
1967 {
1968 }
1969 
Action_RenamePlayer(XML_Helper * helper)1970 Action_RenamePlayer::Action_RenamePlayer(XML_Helper* helper)
1971   :Action(helper)
1972 {
1973     helper->getData(d_name, "name");
1974 }
1975 
dump() const1976 Glib::ustring Action_RenamePlayer::dump() const
1977 {
1978   return String::ucompose("Player changes name to %1.\n", d_name);
1979 }
1980 
doSave(XML_Helper * helper) const1981 bool Action_RenamePlayer::doSave(XML_Helper* helper) const
1982 {
1983     return helper->saveData("name", d_name);
1984 }
1985 
1986 //-----------------------------------------------------------------------------
1987 //Action_CityTooPoorToProduce
1988 
Action_CityTooPoorToProduce(City * c,const ArmyProdBase * army)1989 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce(City* c, const ArmyProdBase *army)
1990     :Action(Action::CITY_DESTITUTE), d_city(c->getId()),
1991     d_army_type(army->getTypeId())
1992 {
1993 }
1994 
Action_CityTooPoorToProduce(const Action_CityTooPoorToProduce & action)1995 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce(const Action_CityTooPoorToProduce &action)
1996 : Action(action), d_city(action.d_city), d_army_type(action.d_army_type)
1997 {
1998 }
1999 
Action_CityTooPoorToProduce(XML_Helper * helper)2000 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce(XML_Helper* helper)
2001     :Action(helper)
2002 {
2003     helper->getData(d_city, "city");
2004     helper->getData(d_army_type, "army_type");
2005 }
2006 
dump() const2007 Glib::ustring Action_CityTooPoorToProduce::dump() const
2008 {
2009   return String::ucompose("City %1 is too poor to produce army type %2.\n",
2010                           d_city, d_army_type);
2011 }
2012 
doSave(XML_Helper * helper) const2013 bool Action_CityTooPoorToProduce::doSave(XML_Helper* helper) const
2014 {
2015     bool retval = true;
2016 
2017     retval &= helper->saveData("city", d_city);
2018     retval &= helper->saveData("army_type", d_army_type);
2019 
2020     return retval;
2021 }
2022 
2023 //-----------------------------------------------------------------------------
2024 //Action_InitTurn
2025 
Action_InitTurn(guint32 order)2026 Action_InitTurn::Action_InitTurn(guint32 order)
2027 :Action(Action::INIT_TURN), d_order(order)
2028 {
2029 }
2030 
Action_InitTurn(const Action_InitTurn & action)2031 Action_InitTurn::Action_InitTurn(const Action_InitTurn &action)
2032 : Action(action), d_order(action.d_order)
2033 {
2034 }
2035 
Action_InitTurn(XML_Helper * helper)2036 Action_InitTurn::Action_InitTurn(XML_Helper* helper)
2037 :Action(helper)
2038 {
2039   helper->getData(d_order, "order");
2040 }
2041 
dump() const2042 Glib::ustring Action_InitTurn::dump() const
2043 {
2044   return String::ucompose("Initializing turn!  order is %1.\n", d_order);
2045 }
2046 
doSave(XML_Helper * helper) const2047 bool Action_InitTurn::doSave(XML_Helper* helper) const
2048 {
2049   bool retval = true;
2050   retval &= helper->saveData("order", d_order);
2051   return retval;
2052 }
2053 
2054 //-----------------------------------------------------------------------------
2055 //Action_Loot
2056 
Action_Loot(Player * looting_player,Player * looted_player,guint32 amount_to_add,guint32 amount_to_subtract)2057 Action_Loot::Action_Loot(Player *looting_player, Player *looted_player,
2058                          guint32 amount_to_add, guint32 amount_to_subtract)
2059     :Action(Action::CITY_LOOT), d_looting_player_id(looting_player->getId()),
2060     d_looted_player_id(looted_player->getId()), d_gold_added(amount_to_add),
2061     d_gold_removed(amount_to_subtract)
2062 {
2063 }
2064 
Action_Loot(const Action_Loot & a)2065 Action_Loot::Action_Loot(const Action_Loot &a)
2066 : Action(a), d_looting_player_id(a.d_looting_player_id),
2067     d_looted_player_id(a.d_looted_player_id), d_gold_added(a.d_gold_added),
2068     d_gold_removed(a.d_gold_removed)
2069 {
2070 }
2071 
Action_Loot(XML_Helper * helper)2072 Action_Loot::Action_Loot(XML_Helper* helper)
2073     :Action(helper)
2074 {
2075     helper->getData(d_looting_player_id, "looting_player_id");
2076     helper->getData(d_looted_player_id, "looted_player_id");
2077     helper->getData(d_gold_added, "gold_added");
2078     helper->getData(d_gold_removed, "gold_removed");
2079 }
2080 
dump() const2081 Glib::ustring Action_Loot::dump() const
2082 {
2083   return
2084     String::ucompose("Player %1 took %2 gp from player %3 who lost %4 in total.\n",
2085                      d_looting_player_id, d_gold_added, d_looted_player_id,
2086                      d_gold_removed);
2087 }
2088 
doSave(XML_Helper * helper) const2089 bool Action_Loot::doSave(XML_Helper* helper) const
2090 {
2091     bool retval = true;
2092 
2093     retval &= helper->saveData("looting_player_id", d_looting_player_id);
2094     retval &= helper->saveData("looted_player_id", d_looted_player_id);
2095     retval &= helper->saveData("gold_added", d_gold_added);
2096     retval &= helper->saveData("gold_removed", d_gold_removed);
2097 
2098     return retval;
2099 }
2100 
2101 //-----------------------------------------------------------------------------
2102 // Action_UseItem
2103 
Action_UseItem(Hero * hero,Item * item,Player * victim,City * friendly_city,City * enemy_city,City * neutral_city,City * city)2104 Action_UseItem::Action_UseItem(Hero *hero, Item *item, Player *victim, City *friendly_city, City *enemy_city, City *neutral_city, City *city)
2105 :Action(Action::USE_ITEM), d_hero(hero->getId()), d_item(item->getId()),
2106     d_victim_player(0), d_friendly_city(0), d_enemy_city(0), d_neutral_city(0),
2107     d_city(0)
2108 {
2109   if (victim)
2110     d_victim_player = victim->getId();
2111   if (friendly_city)
2112     d_friendly_city = friendly_city->getId();
2113   if (enemy_city)
2114     d_enemy_city = enemy_city->getId();
2115   if (neutral_city)
2116     d_neutral_city = neutral_city->getId();
2117   if (city)
2118     d_city = city->getId();
2119 }
2120 
Action_UseItem(const Action_UseItem & a)2121 Action_UseItem::Action_UseItem(const Action_UseItem &a)
2122 : Action(a), d_hero(a.d_hero), d_item(a.d_item),
2123     d_victim_player(a.d_victim_player), d_friendly_city(a.d_friendly_city),
2124     d_enemy_city(a.d_enemy_city), d_neutral_city(a.d_neutral_city),
2125     d_city(a.d_city)
2126 {
2127 }
2128 
Action_UseItem(XML_Helper * helper)2129 Action_UseItem::Action_UseItem(XML_Helper* helper)
2130 :Action(helper)
2131 {
2132 
2133   helper->getData(d_hero, "hero");
2134   helper->getData(d_item, "item");
2135   helper->getData(d_victim_player, "victim_player");
2136   helper->getData(d_friendly_city, "friendly_city");
2137   helper->getData(d_enemy_city, "enemy_city");
2138   helper->getData(d_neutral_city, "neutral_city");
2139   helper->getData(d_city, "city");
2140 }
2141 
dump() const2142 Glib::ustring Action_UseItem::dump() const
2143 {
2144   return String::ucompose("Hero %1 uses item %2 and targets player id %3 friendly city %4, enemy city %5, neutral city %6, city %7.\n", d_hero, d_item, d_victim_player, d_friendly_city, d_enemy_city, d_neutral_city, d_city);
2145 }
2146 
doSave(XML_Helper * helper) const2147 bool Action_UseItem::doSave(XML_Helper* helper) const
2148 {
2149   bool retval = true;
2150 
2151   retval &= helper->saveData("hero", d_hero);
2152   retval &= helper->saveData("item", d_item);
2153   retval &= helper->saveData("victim_player", d_victim_player);
2154   retval &= helper->saveData("friendly_city", d_friendly_city);
2155   retval &= helper->saveData("enemy_city", d_enemy_city);
2156   retval &= helper->saveData("neutral_city", d_neutral_city);
2157   retval &= helper->saveData("city", d_city);
2158 
2159   return retval;
2160 }
2161 
2162 //-----------------------------------------------------------------------------
2163 // Action_ReorderArmies
2164 
Action_ReorderArmies(Stack * s)2165 Action_ReorderArmies::Action_ReorderArmies(Stack *s)
2166 :Action(Action::STACK_ORDER), d_stack_id(s->getId()),
2167     d_player_id(s->getOwner()->getId())
2168 {
2169   for (Stack::iterator i = s->begin(); i != s->end(); i++)
2170     d_army_ids.push_back((*i)->getId());
2171 }
2172 
Action_ReorderArmies(const Action_ReorderArmies & a)2173 Action_ReorderArmies::Action_ReorderArmies(const Action_ReorderArmies &a)
2174 : Action(a), d_stack_id(a.d_stack_id), d_player_id(a.d_player_id),
2175     d_army_ids(a.d_army_ids)
2176 {
2177 }
2178 
Action_ReorderArmies(XML_Helper * helper)2179 Action_ReorderArmies::Action_ReorderArmies(XML_Helper* helper)
2180 :Action(helper)
2181 {
2182 
2183   helper->getData(d_stack_id, "stack_id");
2184   helper->getData(d_player_id, "player_id");
2185   Glib::ustring armies;
2186   helper->getData(armies, "armies");
2187   std::stringstream sarmies;
2188   sarmies.str(armies);
2189   int ival = -1;
2190   while (sarmies.eof() == false)
2191     {
2192       ival = -1;
2193       sarmies >> ival;
2194       if (ival != -1)
2195         d_army_ids.push_back((guint32)ival);
2196     }
2197 }
2198 
dump() const2199 Glib::ustring Action_ReorderArmies::dump() const
2200 {
2201   Glib::ustring s = String::ucompose("Stack %1 belonging to player id %2 has a new order: ", d_stack_id, d_player_id);
2202   for (std::list<guint32>::const_iterator i = d_army_ids.begin();
2203        i != d_army_ids.end(); i++)
2204     s += String::ucompose("%1 ", (*i));
2205   s += "\n";
2206   return s;
2207 }
2208 
doSave(XML_Helper * helper) const2209 bool Action_ReorderArmies::doSave(XML_Helper* helper) const
2210 {
2211   bool retval = true;
2212 
2213   retval &= helper->saveData("stack_id", d_stack_id);
2214   retval &= helper->saveData("player_id", d_player_id);
2215 
2216   Glib::ustring s;
2217   for (auto it: d_army_ids)
2218     s += String::ucompose("%1 ", it);
2219   retval &= helper->saveData("armies", s);
2220   return retval;
2221 }
2222 
2223 //-----------------------------------------------------------------------------
2224 // Action_ResetStacks
2225 
Action_ResetStacks(Player * p)2226 Action_ResetStacks::Action_ResetStacks(Player *p)
2227 :Action(Action::STACKS_RESET), d_player_id(p->getId())
2228 {
2229 }
2230 
Action_ResetStacks(const Action_ResetStacks & action)2231 Action_ResetStacks::Action_ResetStacks(const Action_ResetStacks &action)
2232 : Action(action), d_player_id(action.d_player_id)
2233 {
2234 }
2235 
Action_ResetStacks(XML_Helper * helper)2236 Action_ResetStacks::Action_ResetStacks(XML_Helper* helper)
2237 :Action(helper)
2238 {
2239   helper->getData(d_player_id, "player_id");
2240 }
2241 
dump() const2242 Glib::ustring Action_ResetStacks::dump() const
2243 {
2244   return String::ucompose("Stacks for player id %1 are being recharged.\n",
2245                           d_player_id);
2246 }
2247 
doSave(XML_Helper * helper) const2248 bool Action_ResetStacks::doSave(XML_Helper* helper) const
2249 {
2250   return helper->saveData("player_id", d_player_id);
2251 }
2252 
2253 //-----------------------------------------------------------------------------
2254 // Action_ResetRuins
2255 
Action_ResetRuins()2256 Action_ResetRuins::Action_ResetRuins()
2257 :Action(Action::RUINS_RESET)
2258 {
2259 }
2260 
Action_ResetRuins(const Action_ResetRuins & action)2261 Action_ResetRuins::Action_ResetRuins(const Action_ResetRuins &action)
2262 : Action(action)
2263 {
2264 }
2265 
Action_ResetRuins(XML_Helper * helper)2266 Action_ResetRuins::Action_ResetRuins(XML_Helper* helper)
2267 :Action(helper)
2268 {
2269 }
2270 
dump() const2271 Glib::ustring Action_ResetRuins::dump() const
2272 {
2273   return "Ruins are being recharged.\n";
2274 }
2275 
doSave(XML_Helper * helper) const2276 bool Action_ResetRuins::doSave(XML_Helper* helper) const
2277 {
2278   if (helper)
2279     return true;
2280   return false;
2281 }
2282 
2283 //-----------------------------------------------------------------------------
2284 // Action_CollectTaxesAndPayUpkeep
2285 
Action_CollectTaxesAndPayUpkeep(int fromGold,int toGold)2286 Action_CollectTaxesAndPayUpkeep::Action_CollectTaxesAndPayUpkeep(int fromGold, int toGold)
2287 :Action(Action::COLLECT_TAXES_AND_PAY_UPKEEP), d_from_gold(fromGold),
2288     d_to_gold(toGold)
2289 {
2290 }
2291 
Action_CollectTaxesAndPayUpkeep(const Action_CollectTaxesAndPayUpkeep & action)2292 Action_CollectTaxesAndPayUpkeep::Action_CollectTaxesAndPayUpkeep(const Action_CollectTaxesAndPayUpkeep &action)
2293 : Action(action), d_from_gold(action.d_from_gold), d_to_gold(action.d_to_gold)
2294 {
2295 }
2296 
Action_CollectTaxesAndPayUpkeep(XML_Helper * helper)2297 Action_CollectTaxesAndPayUpkeep::Action_CollectTaxesAndPayUpkeep(XML_Helper* helper)
2298 :Action(helper)
2299 {
2300   helper->getData(d_from_gold, "from_gold");
2301   helper->getData(d_to_gold, "to_gold");
2302 }
2303 
dump() const2304 Glib::ustring Action_CollectTaxesAndPayUpkeep::dump() const
2305 {
2306   return String::ucompose("went from %1 to %2 gp after collecting taxes from cities and paying the troops.\n", d_from_gold, d_to_gold);
2307 }
2308 
doSave(XML_Helper * helper) const2309 bool Action_CollectTaxesAndPayUpkeep::doSave(XML_Helper* helper) const
2310 {
2311   bool retval = true;
2312   retval &= helper->saveData("from_gold", d_from_gold);
2313   retval &= helper->saveData("to_gold", d_to_gold);
2314   return retval;
2315 }
2316 
2317 //-----------------------------------------------------------------------------
2318 // Action_Kill
2319 
Action_Kill()2320 Action_Kill::Action_Kill()
2321 :Action(Action::KILL_PLAYER)
2322 {
2323 }
2324 
Action_Kill(const Action_Kill & action)2325 Action_Kill::Action_Kill(const Action_Kill &action)
2326 : Action(action)
2327 {
2328 }
2329 
Action_Kill(XML_Helper * helper)2330 Action_Kill::Action_Kill(XML_Helper* helper)
2331 :Action(helper)
2332 {
2333 }
2334 
dump() const2335 Glib::ustring Action_Kill::dump() const
2336 {
2337   return "player is vanquished.\n";
2338 }
2339 
doSave(XML_Helper * helper) const2340 bool Action_Kill::doSave(XML_Helper* helper) const
2341 {
2342   if (helper)
2343     return true;
2344   return false;
2345 }
2346 
2347 //-----------------------------------------------------------------------------
2348 // Action_DefendStack
2349 
Action_DefendStack(Stack * s)2350 Action_DefendStack::Action_DefendStack(Stack *s)
2351 :Action(Action::STACK_DEFEND), d_stack_id(s->getId())
2352 {
2353 }
2354 
Action_DefendStack(const Action_DefendStack & action)2355 Action_DefendStack::Action_DefendStack(const Action_DefendStack &action)
2356 : Action(action), d_stack_id(action.d_stack_id)
2357 {
2358 }
2359 
Action_DefendStack(XML_Helper * helper)2360 Action_DefendStack::Action_DefendStack(XML_Helper* helper)
2361 :Action(helper)
2362 {
2363   helper->getData(d_stack_id, "stack_id");
2364 }
2365 
dump() const2366 Glib::ustring Action_DefendStack::dump() const
2367 {
2368   return String::ucompose("Stack %1 is going into defend mode.\n", d_stack_id);
2369 }
2370 
doSave(XML_Helper * helper) const2371 bool Action_DefendStack::doSave(XML_Helper* helper) const
2372 {
2373   return helper->saveData("stack_id", d_stack_id);
2374 }
2375 
2376 //-----------------------------------------------------------------------------
2377 // Action_UndefendStack
2378 
Action_UndefendStack(Stack * s)2379 Action_UndefendStack::Action_UndefendStack(Stack *s)
2380 :Action(Action::STACK_UNDEFEND), d_stack_id(s->getId())
2381 {
2382 }
2383 
Action_UndefendStack(const Action_UndefendStack & action)2384 Action_UndefendStack::Action_UndefendStack(const Action_UndefendStack &action)
2385 : Action(action), d_stack_id(action.d_stack_id)
2386 {
2387 }
2388 
Action_UndefendStack(XML_Helper * helper)2389 Action_UndefendStack::Action_UndefendStack(XML_Helper* helper)
2390 :Action(helper)
2391 {
2392   helper->getData(d_stack_id, "stack_id");
2393 }
2394 
dump() const2395 Glib::ustring Action_UndefendStack::dump() const
2396 {
2397   return String::ucompose("Stack %1 is going out of defend mode.\n", d_stack_id);
2398 }
2399 
doSave(XML_Helper * helper) const2400 bool Action_UndefendStack::doSave(XML_Helper* helper) const
2401 {
2402   return helper->saveData("stack_id", d_stack_id);
2403 }
2404 
2405 //-----------------------------------------------------------------------------
2406 // Action_ParkStack
2407 
Action_ParkStack(Stack * s)2408 Action_ParkStack::Action_ParkStack(Stack *s)
2409 :Action(Action::STACK_PARK), d_stack_id(s->getId())
2410 {
2411 }
2412 
Action_ParkStack(const Action_ParkStack & action)2413 Action_ParkStack::Action_ParkStack(const Action_ParkStack &action)
2414 : Action(action), d_stack_id(action.d_stack_id)
2415 {
2416 }
2417 
Action_ParkStack(XML_Helper * helper)2418 Action_ParkStack::Action_ParkStack(XML_Helper* helper)
2419 :Action(helper)
2420 {
2421   helper->getData(d_stack_id, "stack_id");
2422 }
2423 
dump() const2424 Glib::ustring Action_ParkStack::dump() const
2425 {
2426   return String::ucompose("Stack %1 is going into parked mode.\n", d_stack_id);
2427 }
2428 
doSave(XML_Helper * helper) const2429 bool Action_ParkStack::doSave(XML_Helper* helper) const
2430 {
2431   return helper->saveData("stack_id", d_stack_id);
2432 }
2433 
2434 //-----------------------------------------------------------------------------
2435 // Action_UnparkStack
2436 
Action_UnparkStack(Stack * s)2437 Action_UnparkStack::Action_UnparkStack(Stack *s)
2438 :Action(Action::STACK_UNPARK), d_stack_id(s->getId())
2439 {
2440 }
2441 
Action_UnparkStack(const Action_UnparkStack & action)2442 Action_UnparkStack::Action_UnparkStack(const Action_UnparkStack &action)
2443 : Action(action), d_stack_id(action.d_stack_id)
2444 {
2445 }
2446 
Action_UnparkStack(XML_Helper * helper)2447 Action_UnparkStack::Action_UnparkStack(XML_Helper* helper)
2448 :Action(helper)
2449 {
2450   helper->getData(d_stack_id, "stack_id");
2451 }
2452 
dump() const2453 Glib::ustring Action_UnparkStack::dump() const
2454 {
2455   return String::ucompose("Stack %1 is going out of parked mode.\n", d_stack_id);
2456 }
2457 
doSave(XML_Helper * helper) const2458 bool Action_UnparkStack::doSave(XML_Helper* helper) const
2459 {
2460   return helper->saveData("stack_id", d_stack_id);
2461 }
2462 
2463 //-----------------------------------------------------------------------------
2464 // Action_SelectStack
2465 
Action_SelectStack(Stack * s)2466 Action_SelectStack::Action_SelectStack(Stack *s)
2467 :Action(Action::STACK_SELECT), d_stack_id(s->getId())
2468 {
2469 }
2470 
Action_SelectStack(const Action_SelectStack & action)2471 Action_SelectStack::Action_SelectStack(const Action_SelectStack &action)
2472 : Action(action), d_stack_id(action.d_stack_id)
2473 {
2474 }
2475 
Action_SelectStack(XML_Helper * helper)2476 Action_SelectStack::Action_SelectStack(XML_Helper* helper)
2477 :Action(helper)
2478 {
2479   helper->getData(d_stack_id, "stack_id");
2480 }
2481 
dump() const2482 Glib::ustring Action_SelectStack::dump() const
2483 {
2484   return String::ucompose("Stack %1 is selected.\n", d_stack_id);
2485 }
2486 
doSave(XML_Helper * helper) const2487 bool Action_SelectStack::doSave(XML_Helper* helper) const
2488 {
2489   return helper->saveData("stack_id", d_stack_id);
2490 }
2491 
2492 //-----------------------------------------------------------------------------
2493 // Action_DeselectStack
2494 
Action_DeselectStack()2495 Action_DeselectStack::Action_DeselectStack()
2496 :Action(Action::STACK_DESELECT)
2497 {
2498 }
2499 
Action_DeselectStack(const Action_DeselectStack & action)2500 Action_DeselectStack::Action_DeselectStack(const Action_DeselectStack &action)
2501 : Action(action)
2502 {
2503 }
2504 
Action_DeselectStack(XML_Helper * helper)2505 Action_DeselectStack::Action_DeselectStack(XML_Helper* helper)
2506 :Action(helper)
2507 {
2508 }
2509 
dump() const2510 Glib::ustring Action_DeselectStack::dump() const
2511 {
2512   return "Deselecting stack.\n";
2513 }
2514 
doSave(XML_Helper * helper) const2515 bool Action_DeselectStack::doSave(XML_Helper* helper) const
2516 {
2517   if (helper)
2518     return true;
2519   return false;
2520 }
2521 
actionTypeToString(Action::Type type)2522 Glib::ustring Action::actionTypeToString(Action::Type type)
2523 {
2524   switch (type)
2525     {
2526     case Action::STACK_MOVE: return "Action::STACK_MOVE";
2527     case Action::STACK_SPLIT: return "Action::STACK_SPLIT";
2528     case Action::STACK_FIGHT: return "Action::STACK_FIGHT";
2529     case Action::STACK_JOIN: return "Action::STACK_JOIN";
2530     case Action::RUIN_SEARCH: return "Action::RUIN_SEARCH";
2531     case Action::TEMPLE_SEARCH: return "Action::TEMPLE_SEARCH";
2532     case Action::CITY_OCCUPY: return "Action::CITY_OCCUPY";
2533     case Action::CITY_PILLAGE: return "Action::CITY_PILLAGE";
2534     case Action::CITY_SACK: return "Action::CITY_SACK";
2535     case Action::CITY_RAZE: return "Action::CITY_RAZE";
2536     case Action::CITY_UPGRADE: return "Action::CITY_UPGRADE";
2537     case Action::CITY_BUY: return "Action::CITY_BUY";
2538     case Action::CITY_PROD: return "Action::CITY_PROD";
2539     case Action::REWARD: return "Action::REWARD" ;
2540     case Action::QUEST: return "Action::QUEST";
2541     case Action::HERO_EQUIP: return "Action::HERO_EQUIP";
2542     case Action::UNIT_ADVANCE: return "Action::UNIT_ADVANCE";
2543     case Action::STACK_DISBAND: return "Action::STACK_DISBAND";
2544     case Action::MODIFY_SIGNPOST: return "Action::MODIFY_SIGNPOST";
2545     case Action::CITY_RENAME: return "Action::CITY_RENAME";
2546     case Action::CITY_VECTOR: return "Action::CITY_VECTOR";
2547     case Action::FIGHT_ORDER: return "Action::FIGHT_ORDER";
2548     case Action::RESIGN: return "Action::RESIGN";
2549     case Action::ITEM_PLANT: return "Action::ITEM_PLANT";
2550     case Action::PRODUCE_UNIT: return "Action::PRODUCE_UNIT";
2551     case Action::PRODUCE_VECTORED_UNIT: return "Action::PRODUCE_VECTORED_UNIT";
2552     case Action::DIPLOMATIC_STATE: return "Action::DIPLOMATIC_STATE";
2553     case Action::DIPLOMATIC_PROPOSAL: return "Action::DIPLOMATIC_PROPOSAL";
2554     case Action::DIPLOMATIC_SCORE: return "Action::DIPLOMATIC_SCORE";
2555     case Action::END_TURN: return "Action::END_TURN";
2556     case Action::CITY_CONQUER: return "Action::CITY_CONQUER";
2557     case Action::RECRUIT_HERO: return "Action::RECRUIT_HERO";
2558     case Action::PLAYER_RENAME: return "Action::PLAYER_RENAME";
2559     case Action::CITY_DESTITUTE: return "Action::CITY_DESTITUTE";
2560     case Action::INIT_TURN: return "Action::INIT_TURN";
2561     case Action::CITY_LOOT: return "Action::CITY_LOOT";
2562     case Action::USE_ITEM: return "Action::USE_ITEM";
2563     case Action::STACK_ORDER: return "Action::STACK_ORDER";
2564     case Action::STACKS_RESET: return "Action::STACKS_RESET";
2565     case Action::RUINS_RESET: return "Action::RUINS_RESET";
2566     case Action::COLLECT_TAXES_AND_PAY_UPKEEP: return "Action::COLLECT_TAXES_AND_PAY_UPKEEP";
2567     case Action::KILL_PLAYER: return "Action::KILL_PLAYER";
2568     case Action::STACK_DEFEND: return "Action::STACK_DEFEND";
2569     case Action::STACK_UNDEFEND: return "Action::STACK_UNDEFEND";
2570     case Action::STACK_PARK: return "Action::STACK_PARK";
2571     case Action::STACK_UNPARK: return "Action::STACK_UNPARK";
2572     case Action::STACK_SELECT: return "Action::STACK_SELECT";
2573     case Action::STACK_DESELECT: return "Action::STACK_DESELECT";
2574     }
2575 
2576   return "Action::MOVE";
2577 }
2578 
actionTypeFromString(Glib::ustring str)2579 Action::Type Action::actionTypeFromString(Glib::ustring str)
2580 {
2581   if (str.size() > 0 && isdigit(str.c_str()[0]))
2582     return Action::Type(atoi(str.c_str()));
2583   if (str == "Action::STACK_MOVE") return Action::STACK_MOVE;
2584   else if (str == "Action::STACK_SPLIT") return Action::STACK_SPLIT;
2585   else if (str == "Action::STACK_FIGHT") return Action::STACK_FIGHT;
2586   else if (str == "Action::STACK_JOIN") return Action::STACK_JOIN;
2587   else if (str == "Action::RUIN_SEARCH") return Action::RUIN_SEARCH;
2588   else if (str == "Action::TEMPLE_SEARCH") return Action::TEMPLE_SEARCH;
2589   else if (str == "Action::CITY_OCCUPY") return Action::CITY_OCCUPY;
2590   else if (str == "Action::CITY_PILLAGE") return Action::CITY_PILLAGE;
2591   else if (str == "Action::CITY_SACK") return Action::CITY_SACK;
2592   else if (str == "Action::CITY_RAZE") return Action::CITY_RAZE;
2593   else if (str == "Action::CITY_UPGRADE") return Action::CITY_UPGRADE;
2594   else if (str == "Action::CITY_BUY") return Action::CITY_BUY;
2595   else if (str == "Action::CITY_PROD") return Action::CITY_PROD;
2596   else if (str == "Action::REWARD" ) return Action::REWARD;
2597   else if (str == "Action::QUEST") return Action::QUEST;
2598   else if (str == "Action::HERO_EQUIP") return Action::HERO_EQUIP;
2599   else if (str == "Action::UNIT_ADVANCE") return Action::UNIT_ADVANCE;
2600   else if (str == "Action::STACK_DISBAND") return Action::STACK_DISBAND;
2601   else if (str == "Action::MODIFY_SIGNPOST") return Action::MODIFY_SIGNPOST;
2602   else if (str == "Action::CITY_RENAME") return Action::CITY_RENAME;
2603   else if (str == "Action::CITY_VECTOR") return Action::CITY_VECTOR;
2604   else if (str == "Action::FIGHT_ORDER") return Action::FIGHT_ORDER;
2605   else if (str == "Action::RESIGN") return Action::RESIGN;
2606   else if (str == "Action::ITEM_PLANT") return Action::ITEM_PLANT;
2607   else if (str == "Action::PRODUCE_UNIT") return Action::PRODUCE_UNIT;
2608   else if (str == "Action::PRODUCE_VECTORED_UNIT") return Action::PRODUCE_VECTORED_UNIT;
2609   else if (str == "Action::DIPLOMATIC_STATE") return Action::DIPLOMATIC_STATE;
2610   else if (str == "Action::DIPLOMATIC_PROPOSAL") return Action::DIPLOMATIC_PROPOSAL;
2611   else if (str == "Action::DIPLOMATIC_SCORE") return Action::DIPLOMATIC_SCORE;
2612   else if (str == "Action::END_TURN") return Action::END_TURN;
2613   else if (str == "Action::CITY_CONQUER") return Action::CITY_CONQUER;
2614   else if (str == "Action::RECRUIT_HERO") return Action::RECRUIT_HERO;
2615   else if (str == "Action::PLAYER_RENAME") return Action::PLAYER_RENAME;
2616   else if (str == "Action::CITY_DESTITUTE") return Action::CITY_DESTITUTE;
2617   else if (str == "Action::INIT_TURN") return Action::INIT_TURN;
2618   else if (str == "Action::CITY_LOOT") return Action::CITY_LOOT;
2619   else if (str == "Action::USE_ITEM") return Action::USE_ITEM;
2620   else if (str == "Action::STACK_ORDER") return Action::STACK_ORDER;
2621   else if (str == "Action::STACKS_RESET") return Action::STACKS_RESET;
2622   else if (str == "Action::RUINS_RESET") return Action::RUINS_RESET;
2623   else if (str == "Action::COLLECT_TAXES_AND_PAY_UPKEEP") return Action::COLLECT_TAXES_AND_PAY_UPKEEP;
2624   else if (str == "Action::KILL_PLAYER") return Action::KILL_PLAYER;
2625   else if (str == "Action::STACK_DEFEND") return Action::STACK_DEFEND;
2626   else if (str == "Action::STACK_UNDEFEND") return Action::STACK_UNDEFEND;
2627   else if (str == "Action::STACK_PARK") return Action::STACK_PARK;
2628   else if (str == "Action::STACK_UNPARK") return Action::STACK_UNPARK;
2629   else if (str == "Action::STACK_SELECT") return Action::STACK_SELECT;
2630   else if (str == "Action::STACK_DESELECT") return Action::STACK_DESELECT;
2631   return Action::STACK_MOVE;
2632 }
2633 
2634