initial commit, lordsawar source, slightly modified
[lordsawar] / src / history.cpp
1 //  Copyright (C) 2007, 2008 Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include <stdlib.h>
19 #include <sstream>
20 #include <sigc++/functors/mem_fun.h>
21
22 #include "history.h"
23 #include "hero.h"
24 #include "heroproto.h"
25 #include "city.h"
26 #include "xmlhelper.h"
27 #include "ruin.h"
28
29 std::string History::d_tag = "history";
30 using namespace std;
31
32 #define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<< x << endl<<flush;}
33 //#define debug(x)
34
35 History::History(Type type)
36 :d_type(type)
37 {
38 }
39
40 History::~History()
41 {
42 }
43
44 History* History::handle_load(XML_Helper* helper)
45 {
46   std::string type_str;
47   helper->getData(type_str, "type");
48   History::Type t = historyTypeFromString(type_str);
49
50   switch (t)
51     {
52     case START_TURN:
53       return (new History_StartTurn(helper));
54     case FOUND_SAGE:
55       return (new History_FoundSage(helper));
56     case GOLD_TOTAL:
57       return (new History_GoldTotal(helper));
58     case HERO_EMERGES:
59       return (new History_HeroEmerges(helper));
60     case CITY_WON:
61       return (new History_CityWon(helper));
62     case HERO_CITY_WON:
63       return (new History_HeroCityWon(helper));
64     case CITY_RAZED:
65       return (new History_CityRazed(helper));
66     case HERO_QUEST_STARTED:
67       return (new History_HeroQuestStarted(helper));
68     case HERO_QUEST_COMPLETED:
69       return (new History_HeroQuestCompleted(helper));
70     case HERO_KILLED_IN_CITY:
71       return (new History_HeroKilledInCity(helper));
72     case HERO_KILLED_IN_BATTLE:
73       return (new History_HeroKilledInBattle(helper));
74     case HERO_KILLED_SEARCHING:
75       return (new History_HeroKilledSearching(helper));
76     case SCORE:
77       return (new History_Score(helper));
78     case PLAYER_VANQUISHED:
79       return (new History_PlayerVanquished(helper));
80     case DIPLOMATIC_PEACE:
81       return (new History_DiplomacyPeace(helper));
82     case DIPLOMATIC_WAR:
83       return (new History_DiplomacyWar(helper));
84     case DIPLOMATIC_TREACHERY:
85       return (new History_DiplomacyTreachery(helper));
86     case HERO_FINDS_ALLIES:
87       return (new History_HeroFindsAllies(helper));
88     case END_TURN:
89       return (new History_EndTurn(helper));
90     case HERO_RUIN_EXPLORED:
91       return (new History_HeroRuinExplored(helper));
92     case HERO_REWARD_RUIN:
93       return (new History_HeroRewardRuin(helper));
94     }
95
96   return 0;
97 }
98
99 History* History::copy(const History* a)
100 {
101   switch(a->getType())
102     {
103     case START_TURN:
104       return 
105         (new History_StartTurn(*dynamic_cast<const History_StartTurn*>(a)));
106     case FOUND_SAGE:
107       return 
108         (new History_FoundSage(*dynamic_cast<const History_FoundSage*>(a)));
109     case GOLD_TOTAL:
110       return 
111         (new History_GoldTotal(*dynamic_cast<const History_GoldTotal*>(a)));
112     case HERO_EMERGES:
113       return 
114         (new History_HeroEmerges(*dynamic_cast<const History_HeroEmerges*>(a)));
115     case CITY_WON:
116       return 
117         (new History_CityWon(*dynamic_cast<const History_CityWon*>(a)));
118     case HERO_CITY_WON:
119       return 
120         (new History_HeroCityWon(*dynamic_cast<const History_HeroCityWon*>(a)));
121     case CITY_RAZED:
122       return 
123         (new History_CityRazed(*dynamic_cast<const History_CityRazed*>(a)));
124     case HERO_QUEST_STARTED:
125       return 
126         (new History_HeroQuestStarted
127           (*dynamic_cast<const History_HeroQuestStarted*>(a)));
128     case HERO_QUEST_COMPLETED:
129       return 
130         (new History_HeroQuestCompleted
131           (*dynamic_cast<const History_HeroQuestCompleted*>(a)));
132     case HERO_KILLED_IN_CITY:
133       return 
134         (new History_HeroKilledInCity
135           (*dynamic_cast<const History_HeroKilledInCity*>(a)));
136     case HERO_KILLED_IN_BATTLE:
137       return 
138         (new History_HeroKilledInBattle
139           (*dynamic_cast<const History_HeroKilledInBattle*>(a)));
140     case HERO_KILLED_SEARCHING:
141       return 
142         (new History_HeroKilledSearching
143           (*dynamic_cast<const History_HeroKilledSearching*>(a)));
144     case SCORE:
145       return 
146         (new History_Score(*dynamic_cast<const History_Score*>(a)));
147     case PLAYER_VANQUISHED:
148       return 
149         (new History_PlayerVanquished
150          (*dynamic_cast<const History_PlayerVanquished*>(a)));
151     case DIPLOMATIC_PEACE:
152       return 
153         (new History_DiplomacyPeace
154          (*dynamic_cast<const History_DiplomacyPeace*>(a)));
155     case DIPLOMATIC_WAR:
156       return 
157         (new History_DiplomacyWar
158          (*dynamic_cast<const History_DiplomacyWar*>(a)));
159     case DIPLOMATIC_TREACHERY:
160       return 
161         (new History_DiplomacyTreachery
162          (*dynamic_cast<const History_DiplomacyTreachery*>(a)));
163     case HERO_FINDS_ALLIES:
164       return 
165         (new History_HeroFindsAllies
166           (*dynamic_cast<const History_HeroFindsAllies*>(a)));
167     case END_TURN:
168       return 
169         (new History_EndTurn(*dynamic_cast<const History_EndTurn*>(a)));
170     case HERO_RUIN_EXPLORED:
171       return 
172         (new History_HeroRuinExplored
173          (*dynamic_cast<const History_HeroRuinExplored*>(a)));
174     case HERO_REWARD_RUIN:
175       return 
176         (new History_HeroRewardRuin
177          (*dynamic_cast<const History_HeroRewardRuin*>(a)));
178     }
179
180   return 0;
181 }
182
183 History::History (XML_Helper *helper)
184 {
185   std::string type_str;
186   helper->getData(type_str, "type");
187   d_type = historyTypeFromString(type_str);
188 }
189
190 bool History::save(XML_Helper* helper) const
191 {
192     bool retval = true;
193
194     retval &= helper->openTag(History::d_tag);
195     retval &= saveContents(helper);
196     retval &= helper->closeTag();
197
198     return retval;
199 }
200
201 bool History::saveContents(XML_Helper* helper) const
202 {
203     bool retval = true;
204
205     std::string type_str = historyTypeToString(History::Type(d_type));
206     retval &= helper->saveData("type", type_str);
207     retval &= doSave(helper);
208
209     return retval;
210 }
211
212 //-----------------------------------------------------------------------------
213 //History_StartTurn
214
215 History_StartTurn::History_StartTurn()
216 :History(History::START_TURN)
217 {
218 }
219
220 History_StartTurn::History_StartTurn(const History_StartTurn &history)
221 :History(history)
222 {
223 }
224
225 History_StartTurn::History_StartTurn(XML_Helper* helper)
226 :History(helper)
227 {
228 }
229
230 History_StartTurn::~History_StartTurn()
231 {
232 }
233
234 std::string History_StartTurn::dump() const
235 {
236   std::stringstream s;
237
238   s <<"player starts a turn" << "\n";
239
240   return s.str();
241 }
242
243 bool History_StartTurn::doSave(XML_Helper* helper) const
244 {
245   bool retval = true;
246
247   return retval;
248 }
249
250 bool History_StartTurn::fillData()
251 {
252   return true;
253 }
254
255 //-----------------------------------------------------------------------------
256 //History_FoundSage
257
258 History_FoundSage::History_FoundSage()
259 :History(History::FOUND_SAGE), d_hero("")
260 {
261 }
262
263 History_FoundSage::History_FoundSage(const History_FoundSage &history)
264 :History(history), d_hero(history.d_hero)
265 {
266 }
267
268 History_FoundSage::History_FoundSage(XML_Helper* helper)
269 :History(helper)
270 {
271   helper->getData(d_hero, "hero");
272 }
273
274 History_FoundSage::~History_FoundSage()
275 {
276 }
277
278 std::string History_FoundSage::dump() const
279 {
280   std::stringstream s;
281
282   s <<"player found a sage with hero " << d_hero<< "\n";
283
284   return s.str();
285 }
286
287 bool History_FoundSage::doSave(XML_Helper* helper) const
288 {
289   bool retval = true;
290
291   retval &= helper->saveData("hero", d_hero);
292
293   return retval;
294 }
295
296 bool History_FoundSage::fillData(Hero *hero)
297 {
298   d_hero = hero->getName();
299   return true;
300 }
301
302 //-----------------------------------------------------------------------------
303 //History_GoldTotal
304
305 History_GoldTotal::History_GoldTotal()
306 :History(History::GOLD_TOTAL), d_gold(0)
307 {
308 }
309
310 History_GoldTotal::History_GoldTotal(const History_GoldTotal &history)
311 :History(history), d_gold(history.d_gold)
312 {
313 }
314
315 History_GoldTotal::History_GoldTotal(XML_Helper* helper)
316 :History(helper)
317 {
318   helper->getData(d_gold, "gold");
319 }
320
321 History_GoldTotal::~History_GoldTotal()
322 {
323 }
324
325 std::string History_GoldTotal::dump() const
326 {
327   std::stringstream s;
328
329   s <<"player has " << d_gold<< " gold pieces in total\n";
330
331   return s.str();
332 }
333
334 bool History_GoldTotal::doSave(XML_Helper* helper) const
335 {
336   bool retval = true;
337
338   retval &= helper->saveData("gold", d_gold);
339
340   return retval;
341 }
342
343 bool History_GoldTotal::fillData(int gold)
344 {
345   d_gold = gold;
346   return true;
347 }
348
349 //-----------------------------------------------------------------------------
350 //History_HeroEmerges
351
352 History_HeroEmerges::History_HeroEmerges()
353 :History(History::HERO_EMERGES), d_hero(""), d_hero_id(0), d_city("")
354 {
355 }
356
357 History_HeroEmerges::History_HeroEmerges(const History_HeroEmerges &history)
358 :History(history), d_hero(history.d_hero), d_hero_id(history.d_hero_id), 
359     d_city(history.d_city)
360 {
361 }
362
363 History_HeroEmerges::History_HeroEmerges(XML_Helper* helper)
364 :History(helper)
365 {
366   helper->getData(d_hero, "hero");
367   helper->getData(d_city, "city");
368   helper->getData(d_hero_id, "hero_id");
369 }
370
371 History_HeroEmerges::~History_HeroEmerges()
372 {
373 }
374
375 std::string History_HeroEmerges::dump() const
376 {
377   std::stringstream s;
378
379   s <<"hero " << d_hero_id <<" (" << d_hero << ") emerges in " << d_city << "\n";
380
381   return s.str();
382 }
383
384 bool History_HeroEmerges::doSave(XML_Helper* helper) const
385 {
386   bool retval = true;
387
388   retval &= helper->saveData("hero", d_hero);
389   retval &= helper->saveData("city", d_city);
390   retval &= helper->saveData("hero_id", d_hero_id);
391
392   return retval;
393 }
394
395 bool History_HeroEmerges::fillData(Hero *hero, City *city)
396 {
397   d_hero = hero->getName();
398   d_city = city->getName();
399   d_hero_id = hero->getId();
400   return true;
401 }
402
403 //-----------------------------------------------------------------------------
404 //History_CityWon
405
406 History_CityWon::History_CityWon()
407 :History(History::CITY_WON), d_city(0)
408 {
409 }
410
411 History_CityWon::History_CityWon(const History_CityWon &history)
412 :History(history), d_city(history.d_city)
413 {
414 }
415
416 History_CityWon::History_CityWon(XML_Helper* helper)
417 :History(helper)
418 {
419   helper->getData(d_city, "city");
420 }
421
422 History_CityWon::~History_CityWon()
423 {
424 }
425
426 std::string History_CityWon::dump() const
427 {
428   std::stringstream s;
429
430   s <<"city " << d_city << " has been won";
431   s <<"\n";
432
433   return s.str();
434 }
435
436 bool History_CityWon::doSave(XML_Helper* helper) const
437 {
438   bool retval = true;
439
440   retval &= helper->saveData("city", d_city);
441
442   return retval;
443 }
444
445 bool History_CityWon::fillData(City *city)
446 {
447   d_city = city->getId();
448   return true;
449 }
450
451 //-----------------------------------------------------------------------------
452 //History_HeroCityWon
453
454 History_HeroCityWon::History_HeroCityWon()
455 :History(History::HERO_CITY_WON), d_hero(""), d_city("")
456 {
457 }
458
459 History_HeroCityWon::History_HeroCityWon(const History_HeroCityWon &history)
460 :History(history), d_hero(history.d_hero), d_city(history.d_city)
461 {
462 }
463
464 History_HeroCityWon::History_HeroCityWon(XML_Helper* helper)
465 :History(helper)
466 {
467   helper->getData(d_city, "city");
468   helper->getData(d_hero, "hero");
469 }
470
471 History_HeroCityWon::~History_HeroCityWon()
472 {
473 }
474
475 std::string History_HeroCityWon::dump() const
476 {
477   std::stringstream s;
478
479   s <<"city " << d_city << " has been won";
480   s <<"  by " << d_hero;
481   s <<"\n";
482
483   return s.str();
484 }
485
486 bool History_HeroCityWon::doSave(XML_Helper* helper) const
487 {
488   bool retval = true;
489
490   retval &= helper->saveData("city", d_city);
491   retval &= helper->saveData("hero", d_hero);
492
493   return retval;
494 }
495
496 bool History_HeroCityWon::fillData(Hero *hero, City *city)
497 {
498   d_city = city->getName();
499   d_hero = hero->getName();
500   return true;
501 }
502
503 //-----------------------------------------------------------------------------
504 //History_CityRazed
505
506 History_CityRazed::History_CityRazed()
507 :History(History::CITY_RAZED), d_city(0)
508 {
509 }
510
511 History_CityRazed::History_CityRazed(const History_CityRazed &history)
512 :History(history), d_city(history.d_city)
513 {
514 }
515
516 History_CityRazed::History_CityRazed(XML_Helper* helper)
517 :History(helper)
518 {
519   helper->getData(d_city, "city");
520 }
521
522 History_CityRazed::~History_CityRazed()
523 {
524 }
525
526 std::string History_CityRazed::dump() const
527 {
528   std::stringstream s;
529
530   s <<"city " << d_city << " has been razed\n";
531
532   return s.str();
533 }
534
535 bool History_CityRazed::doSave(XML_Helper* helper) const
536 {
537   bool retval = true;
538
539   retval &= helper->saveData("city", d_city);
540
541   return retval;
542 }
543
544 bool History_CityRazed::fillData(City *city)
545 {
546   d_city = city->getId();
547   return true;
548 }
549
550 //-----------------------------------------------------------------------------
551 //History_HeroQuestStarted
552
553 History_HeroQuestStarted::History_HeroQuestStarted()
554 :History(History::HERO_QUEST_STARTED), d_hero("")
555 {
556 }
557
558 History_HeroQuestStarted::History_HeroQuestStarted(const History_HeroQuestStarted &history)
559 :History(history), d_hero(history.d_hero)
560 {
561 }
562
563 History_HeroQuestStarted::History_HeroQuestStarted(XML_Helper* helper)
564 :History(helper)
565 {
566   helper->getData(d_hero, "hero");
567 }
568
569 History_HeroQuestStarted::~History_HeroQuestStarted()
570 {
571 }
572
573 std::string History_HeroQuestStarted::dump() const
574 {
575   std::stringstream s;
576
577   s <<"hero " << d_hero<< " gets a quest\n";
578
579   return s.str();
580 }
581
582 bool History_HeroQuestStarted::doSave(XML_Helper* helper) const
583 {
584   bool retval = true;
585
586   retval &= helper->saveData("hero", d_hero);
587
588   return retval;
589 }
590
591 bool History_HeroQuestStarted::fillData(Hero *hero)
592 {
593   d_hero = hero->getName();
594   return true;
595 }
596
597 //-----------------------------------------------------------------------------
598 //History_HeroQuestCompleted
599
600 History_HeroQuestCompleted::History_HeroQuestCompleted()
601 :History(History::HERO_QUEST_COMPLETED), d_hero("")
602 {
603 }
604
605 History_HeroQuestCompleted::History_HeroQuestCompleted(const History_HeroQuestCompleted &history)
606 :History(history), d_hero(history.d_hero)
607 {
608 }
609
610 History_HeroQuestCompleted::History_HeroQuestCompleted(XML_Helper* helper)
611 :History(helper)
612 {
613   helper->getData(d_hero, "hero");
614 }
615
616 History_HeroQuestCompleted::~History_HeroQuestCompleted()
617 {
618 }
619
620 std::string History_HeroQuestCompleted::dump() const
621 {
622   std::stringstream s;
623
624   s <<"hero " << d_hero<< " gets a quest\n";
625
626   return s.str();
627 }
628
629 bool History_HeroQuestCompleted::doSave(XML_Helper* helper) const
630 {
631   bool retval = true;
632
633   retval &= helper->saveData("hero", d_hero);
634
635   return retval;
636 }
637
638 bool History_HeroQuestCompleted::fillData(Hero *hero)
639 {
640   d_hero = hero->getName();
641   return true;
642 }
643
644 //-----------------------------------------------------------------------------
645 //History_HeroKilledInCity
646
647 History_HeroKilledInCity::History_HeroKilledInCity()
648 :History(History::HERO_KILLED_IN_CITY), d_hero(""), d_city("")
649 {
650 }
651
652 History_HeroKilledInCity::History_HeroKilledInCity(const History_HeroKilledInCity &history)
653 :History(history), d_hero(history.d_hero), d_city(history.d_city)
654 {
655 }
656
657 History_HeroKilledInCity::History_HeroKilledInCity(XML_Helper* helper)
658 :History(helper)
659 {
660   helper->getData(d_hero, "hero");
661   helper->getData(d_city, "city");
662 }
663
664 History_HeroKilledInCity::~History_HeroKilledInCity()
665 {
666 }
667
668 std::string History_HeroKilledInCity::dump() const
669 {
670   std::stringstream s;
671
672   s <<"hero " << d_hero << " died in city " << d_city << "\n";
673
674   return s.str();
675 }
676
677 bool History_HeroKilledInCity::doSave(XML_Helper* helper) const
678 {
679   bool retval = true;
680
681   retval &= helper->saveData("hero", d_hero);
682   retval &= helper->saveData("city", d_city);
683
684   return retval;
685 }
686
687 bool History_HeroKilledInCity::fillData(Hero *hero, City *city)
688 {
689   d_hero = hero->getName();
690   d_city = city->getName();
691   return true;
692 }
693
694 //-----------------------------------------------------------------------------
695 //History_HeroKilledInBattle
696
697 History_HeroKilledInBattle::History_HeroKilledInBattle()
698 :History(History::HERO_KILLED_IN_BATTLE), d_hero("")
699 {
700 }
701
702 History_HeroKilledInBattle::History_HeroKilledInBattle(const History_HeroKilledInBattle &history)
703 :History(history), d_hero(history.d_hero)
704 {
705 }
706
707 History_HeroKilledInBattle::History_HeroKilledInBattle(XML_Helper* helper)
708 :History(helper)
709 {
710   helper->getData(d_hero, "hero");
711 }
712
713 History_HeroKilledInBattle::~History_HeroKilledInBattle()
714 {
715 }
716
717 std::string History_HeroKilledInBattle::dump() const
718 {
719   std::stringstream s;
720
721   s <<"hero " << d_hero<< " was killed in battle\n";
722
723   return s.str();
724 }
725
726 bool History_HeroKilledInBattle::doSave(XML_Helper* helper) const
727 {
728   bool retval = true;
729
730   retval &= helper->saveData("hero", d_hero);
731
732   return retval;
733 }
734
735 bool History_HeroKilledInBattle::fillData(Hero *hero)
736 {
737   d_hero = hero->getName();
738   return true;
739 }
740
741 //-----------------------------------------------------------------------------
742 //History_Hero KilledSearching
743
744 History_HeroKilledSearching::History_HeroKilledSearching()
745 :History(History::HERO_KILLED_SEARCHING), d_hero("")
746 {
747 }
748
749 History_HeroKilledSearching::History_HeroKilledSearching(const History_HeroKilledSearching &history)
750 :History(history), d_hero(history.d_hero)
751 {
752 }
753
754 History_HeroKilledSearching::History_HeroKilledSearching(XML_Helper* helper)
755 :History(helper)
756 {
757   helper->getData(d_hero, "hero");
758 }
759
760 History_HeroKilledSearching::~History_HeroKilledSearching()
761 {
762 }
763
764 std::string History_HeroKilledSearching::dump() const
765 {
766   std::stringstream s;
767
768   s <<"hero " << d_hero<< " killed searching a ruin\n";
769
770   return s.str();
771 }
772
773 bool History_HeroKilledSearching::doSave(XML_Helper* helper) const
774 {
775   bool retval = true;
776
777   retval &= helper->saveData("hero", d_hero);
778
779   return retval;
780 }
781
782 bool History_HeroKilledSearching::fillData(Hero *hero)
783 {
784   d_hero = hero->getName();
785   return true;
786 }
787
788 //-----------------------------------------------------------------------------
789 //History_Score
790
791 History_Score::History_Score()
792 :History(History::SCORE), d_score(0)
793 {
794 }
795
796 History_Score::History_Score(const History_Score &history)
797 :History(history), d_score(history.d_score)
798 {
799 }
800
801 History_Score::History_Score(XML_Helper* helper)
802 :History(helper)
803 {
804   helper->getData(d_score, "score");
805 }
806
807 History_Score::~History_Score()
808 {
809 }
810
811 std::string History_Score::dump() const
812 {
813   std::stringstream s;
814
815   s <<"player has a score of " << d_score<< "\n";
816
817   return s.str();
818 }
819
820 bool History_Score::doSave(XML_Helper* helper) const
821 {
822   bool retval = true;
823
824   retval &= helper->saveData("score", d_score);
825
826   return retval;
827 }
828
829 bool History_Score::fillData(guint32 score)
830 {
831   d_score = score;
832   return true;
833 }
834
835 //-----------------------------------------------------------------------------
836 //History_PlayerVanquished
837
838 History_PlayerVanquished::History_PlayerVanquished()
839 :History(History::PLAYER_VANQUISHED)
840 {
841 }
842
843 History_PlayerVanquished::History_PlayerVanquished(const History_PlayerVanquished &history)
844 :History(history)
845 {
846 }
847
848 History_PlayerVanquished::History_PlayerVanquished(XML_Helper* helper)
849 :History(helper)
850 {
851 }
852
853 History_PlayerVanquished::~History_PlayerVanquished()
854 {
855 }
856
857 std::string History_PlayerVanquished::dump() const
858 {
859   std::stringstream s;
860
861   s <<"player has been vanquished!\n";
862
863   return s.str();
864 }
865
866 bool History_PlayerVanquished::doSave(XML_Helper* helper) const
867 {
868   bool retval = true;
869
870   return retval;
871 }
872
873 //-----------------------------------------------------------------------------
874 //History_DiplomacyPeace
875
876 History_DiplomacyPeace::History_DiplomacyPeace()
877 :History(History::DIPLOMATIC_PEACE), d_opponent_id(0)
878 {
879 }
880
881 History_DiplomacyPeace::History_DiplomacyPeace(const History_DiplomacyPeace &history)
882 :History(history), d_opponent_id(history.d_opponent_id)
883 {
884 }
885
886 History_DiplomacyPeace::History_DiplomacyPeace(XML_Helper* helper)
887 :History(helper)
888 {
889   helper->getData(d_opponent_id, "opponent_id");
890 }
891
892 History_DiplomacyPeace::~History_DiplomacyPeace()
893 {
894 }
895
896 std::string History_DiplomacyPeace::dump() const
897 {
898   std::stringstream s;
899
900   s <<"peace has been won with player " << d_opponent_id;
901   s <<"\n";
902
903   return s.str();
904 }
905
906 bool History_DiplomacyPeace::doSave(XML_Helper* helper) const
907 {
908   bool retval = true;
909
910   retval &= helper->saveData("opponent_id", d_opponent_id);
911
912   return retval;
913 }
914
915 bool History_DiplomacyPeace::fillData(Player *opponent)
916 {
917   d_opponent_id = opponent->getId();
918   return true;
919 }
920
921 //-----------------------------------------------------------------------------
922 //History_DiplomacyWar
923
924 History_DiplomacyWar::History_DiplomacyWar()
925 :History(History::DIPLOMATIC_WAR), d_opponent_id(0)
926 {
927 }
928
929 History_DiplomacyWar::History_DiplomacyWar(const History_DiplomacyWar &history)
930 :History(history), d_opponent_id(history.d_opponent_id)
931 {
932 }
933
934 History_DiplomacyWar::History_DiplomacyWar(XML_Helper* helper)
935 :History(helper)
936 {
937   helper->getData(d_opponent_id, "opponent_id");
938 }
939
940 History_DiplomacyWar::~History_DiplomacyWar()
941 {
942 }
943
944 std::string History_DiplomacyWar::dump() const
945 {
946   std::stringstream s;
947
948   s <<"war has been declared with player " << d_opponent_id;
949   s <<"\n";
950
951   return s.str();
952 }
953
954 bool History_DiplomacyWar::doSave(XML_Helper* helper) const
955 {
956   bool retval = true;
957
958   retval &= helper->saveData("opponent_id", d_opponent_id);
959
960   return retval;
961 }
962
963 bool History_DiplomacyWar::fillData(Player *opponent)
964 {
965   d_opponent_id = opponent->getId();
966   return true;
967 }
968
969 //-----------------------------------------------------------------------------
970 //History_DiplomacyTreachery
971
972 History_DiplomacyTreachery::History_DiplomacyTreachery()
973 :History(History::DIPLOMATIC_TREACHERY), d_opponent_id(0)
974 {
975 }
976
977 History_DiplomacyTreachery::History_DiplomacyTreachery(const History_DiplomacyTreachery &history)
978 :History(history), d_opponent_id(history.d_opponent_id)
979 {
980 }
981
982 History_DiplomacyTreachery::History_DiplomacyTreachery(XML_Helper* helper)
983 :History(helper)
984 {
985   helper->getData(d_opponent_id, "opponent_id");
986 }
987
988 History_DiplomacyTreachery::~History_DiplomacyTreachery()
989 {
990 }
991
992 std::string History_DiplomacyTreachery::dump() const
993 {
994   std::stringstream s;
995
996   s <<"treachery on player " << d_opponent_id;
997   s <<"\n";
998
999   return s.str();
1000 }
1001
1002 bool History_DiplomacyTreachery::doSave(XML_Helper* helper) const
1003 {
1004   bool retval = true;
1005
1006   retval &= helper->saveData("opponent_id", d_opponent_id);
1007
1008   return retval;
1009 }
1010
1011 bool History_DiplomacyTreachery::fillData(Player *opponent)
1012 {
1013   d_opponent_id = opponent->getId();
1014   return true;
1015 }
1016
1017 //-----------------------------------------------------------------------------
1018 //History_HeroFindsAllies
1019
1020 History_HeroFindsAllies::History_HeroFindsAllies()
1021 :History(History::HERO_FINDS_ALLIES), d_hero("")
1022 {
1023 }
1024
1025 History_HeroFindsAllies::History_HeroFindsAllies(const History_HeroFindsAllies &history)
1026 :History(history), d_hero(history.d_hero)
1027 {
1028 }
1029
1030 History_HeroFindsAllies::History_HeroFindsAllies(XML_Helper* helper)
1031 :History(helper)
1032 {
1033   helper->getData(d_hero, "hero");
1034 }
1035
1036 History_HeroFindsAllies::~History_HeroFindsAllies()
1037 {
1038 }
1039
1040 std::string History_HeroFindsAllies::dump() const
1041 {
1042   std::stringstream s;
1043
1044   s <<"hero " << d_hero<< " finds some allies\n";
1045
1046   return s.str();
1047 }
1048
1049 bool History_HeroFindsAllies::doSave(XML_Helper* helper) const
1050 {
1051   bool retval = true;
1052
1053   retval &= helper->saveData("hero", d_hero);
1054
1055   return retval;
1056 }
1057
1058 bool History_HeroFindsAllies::fillData(Hero *hero)
1059 {
1060   d_hero = hero->getName();
1061   return true;
1062 }
1063
1064 //-----------------------------------------------------------------------------
1065 //History_EndTurn
1066
1067 History_EndTurn::History_EndTurn()
1068 :History(History::END_TURN)
1069 {
1070 }
1071
1072 History_EndTurn::History_EndTurn(const History_EndTurn &history)
1073 :History(history)
1074 {
1075 }
1076
1077 History_EndTurn::History_EndTurn(XML_Helper* helper)
1078 :History(helper)
1079 {
1080 }
1081
1082 History_EndTurn::~History_EndTurn()
1083 {
1084 }
1085
1086 std::string History_EndTurn::dump() const
1087 {
1088   std::stringstream s;
1089
1090   s <<"player ends a turn" << "\n";
1091
1092   return s.str();
1093 }
1094
1095 bool History_EndTurn::doSave(XML_Helper* helper) const
1096 {
1097   bool retval = true;
1098
1099   return retval;
1100 }
1101
1102 bool History_EndTurn::fillData()
1103 {
1104   return true;
1105 }
1106 //-----------------------------------------------------------------------------
1107 //History_HeroRuinExplored
1108
1109 History_HeroRuinExplored::History_HeroRuinExplored()
1110 :History(History::HERO_RUIN_EXPLORED), d_hero(""), d_ruin(0)
1111 {
1112 }
1113
1114 History_HeroRuinExplored::History_HeroRuinExplored(const History_HeroRuinExplored &history)
1115 :History(history), d_hero(history.d_hero), d_ruin(history.d_ruin)
1116 {
1117 }
1118
1119 History_HeroRuinExplored::History_HeroRuinExplored(XML_Helper* helper)
1120 :History(helper)
1121 {
1122   helper->getData(d_ruin, "ruin");
1123   helper->getData(d_hero, "hero");
1124 }
1125
1126 History_HeroRuinExplored::~History_HeroRuinExplored()
1127 {
1128 }
1129
1130 std::string History_HeroRuinExplored::dump() const
1131 {
1132   std::stringstream s;
1133
1134   s <<"ruin " << d_ruin << " has been searched";
1135   s <<" by " << d_hero;
1136   s <<"\n";
1137
1138   return s.str();
1139 }
1140
1141 bool History_HeroRuinExplored::doSave(XML_Helper* helper) const
1142 {
1143   bool retval = true;
1144
1145   retval &= helper->saveData("ruin", d_ruin);
1146   retval &= helper->saveData("hero", d_hero);
1147
1148   return retval;
1149 }
1150
1151 bool History_HeroRuinExplored::fillData(Hero *hero, Ruin *ruin)
1152 {
1153   d_ruin = ruin->getId();
1154   d_hero = hero->getName();
1155   return true;
1156 }
1157
1158 //-----------------------------------------------------------------------------
1159 //History_HeroRewardRuin
1160
1161 History_HeroRewardRuin::History_HeroRewardRuin()
1162 :History(History::HERO_REWARD_RUIN), d_hero(""), d_ruin(0)
1163 {
1164 }
1165
1166 History_HeroRewardRuin::History_HeroRewardRuin(const History_HeroRewardRuin &history)
1167 :History(history), d_hero(history.d_hero), d_ruin(history.d_ruin)
1168 {
1169 }
1170
1171 History_HeroRewardRuin::History_HeroRewardRuin(XML_Helper* helper)
1172 :History(helper)
1173 {
1174   helper->getData(d_ruin, "ruin");
1175   helper->getData(d_hero, "hero");
1176 }
1177
1178 History_HeroRewardRuin::~History_HeroRewardRuin()
1179 {
1180 }
1181
1182 std::string History_HeroRewardRuin::dump() const
1183 {
1184   std::stringstream s;
1185
1186   s <<"the location of ruin " << d_ruin << " has been given ";
1187   s <<"to " << d_hero;
1188   s <<"\n";
1189
1190   return s.str();
1191 }
1192
1193 bool History_HeroRewardRuin::doSave(XML_Helper* helper) const
1194 {
1195   bool retval = true;
1196
1197   retval &= helper->saveData("ruin", d_ruin);
1198   retval &= helper->saveData("hero", d_hero);
1199
1200   return retval;
1201 }
1202
1203 bool History_HeroRewardRuin::fillData(Hero *hero, Ruin *ruin)
1204 {
1205   d_ruin = ruin->getId();
1206   d_hero = hero->getName();
1207   return true;
1208 }
1209
1210 std::string History::historyTypeToString(const History::Type type)
1211 {
1212   switch (type)
1213     {
1214     case History::START_TURN:
1215       return "History::START_TURN";
1216     case History::FOUND_SAGE:
1217       return "History::FOUND_SAGE";
1218     case History::GOLD_TOTAL:
1219       return "History::GOLD_TOTAL";
1220     case History::HERO_EMERGES:
1221       return "History::HERO_EMERGES";
1222     case History::CITY_WON:
1223       return "History::CITY_WON";
1224     case History::HERO_CITY_WON:
1225       return "History::HERO_CITY_WON";
1226     case History::CITY_RAZED:
1227       return "History::CITY_RAZED";
1228     case History::HERO_QUEST_STARTED:
1229       return "History::HERO_QUEST_STARTED";
1230     case History::HERO_QUEST_COMPLETED:
1231       return "History::HERO_QUEST_COMPLETED";
1232     case History::HERO_KILLED_IN_CITY:
1233       return "History::HERO_KILLED_IN_CITY";
1234     case History::HERO_KILLED_IN_BATTLE:
1235       return "History::HERO_KILLED_IN_BATTLE";
1236     case History::HERO_KILLED_SEARCHING:
1237       return "History::HERO_KILLED_SEARCHING";
1238     case History::SCORE:
1239       return "History::SCORE";
1240     case History::PLAYER_VANQUISHED:
1241       return "History::PLAYER_VANQUISHED";
1242     case History::DIPLOMATIC_PEACE:
1243       return "History::DIPLOMATIC_PEACE";
1244     case History::DIPLOMATIC_WAR:
1245       return "History::DIPLOMATIC_WAR";
1246     case History::DIPLOMATIC_TREACHERY:
1247       return "History::DIPLOMATIC_TREACHERY";
1248     case History::HERO_FINDS_ALLIES:
1249       return "History::HERO_FINDS_ALLIES";
1250     case History::END_TURN:
1251       return "History::END_TURN";
1252     case History::HERO_RUIN_EXPLORED:
1253       return "History::HERO_RUIN_EXPLORED";
1254     case History::HERO_REWARD_RUIN:
1255       return "History::HERO_REWARD_RUIN";
1256     }
1257   return "History::START_TURN";
1258 }
1259
1260 History::Type History::historyTypeFromString(const std::string str)
1261 {
1262   if (str.size() > 0 && isdigit(str.c_str()[0]))
1263     return History::Type(atoi(str.c_str()));
1264   if (str == "History::START_TURN")
1265     return History::START_TURN;
1266   else if (str == "History::FOUND_SAGE")
1267     return History::FOUND_SAGE;
1268   else if (str == "History::GOLD_TOTAL")
1269     return History::GOLD_TOTAL;
1270   else if (str == "History::HERO_EMERGES")
1271     return History::HERO_EMERGES;
1272   else if (str == "History::CITY_WON")
1273     return History::CITY_WON;
1274   else if (str== "History::HERO_CITY_WON")
1275     return History::HERO_CITY_WON;
1276   else if (str == "History::CITY_RAZED")
1277     return History::CITY_RAZED;
1278   else if (str == "History::HERO_QUEST_STARTED")
1279     return History::HERO_QUEST_STARTED;
1280   else if (str == "History::HERO_QUEST_COMPLETED")
1281     return History::HERO_QUEST_COMPLETED;
1282   else if (str == "History::HERO_KILLED_IN_CITY")
1283     return History::HERO_KILLED_IN_CITY;
1284   else if (str == "History::HERO_KILLED_IN_BATTLE")
1285     return History::HERO_KILLED_IN_BATTLE;
1286   else if (str == "History::HERO_KILLED_SEARCHING")
1287     return History::HERO_KILLED_SEARCHING;
1288   else if (str == "History::SCORE")
1289     return History::SCORE;
1290   else if (str == "History::PLAYER_VANQUISHED")
1291     return History::PLAYER_VANQUISHED;
1292   else if (str == "History::DIPLOMATIC_PEACE")
1293     return History::DIPLOMATIC_PEACE;
1294   else if (str == "History::DIPLOMATIC_WAR")
1295     return History::DIPLOMATIC_WAR;
1296   else if (str == "History::DIPLOMATIC_TREACHERY")
1297     return History::DIPLOMATIC_TREACHERY;
1298   else if (str == "History::HERO_FINDS_ALLIES")
1299     return History::HERO_FINDS_ALLIES;
1300   else if (str == "History::END_TURN")
1301     return History::END_TURN;
1302   else if (str == "History::HERO_RUIN_EXPLORED")
1303     return History::HERO_RUIN_EXPLORED;
1304   else if (str == "History::HERO_REWARD_RUIN")
1305     return History::HERO_REWARD_RUIN;
1306   return History::START_TURN;
1307 }