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