1 // Copyright (C) 2007, 2008 Ben Asselstine
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.
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.
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
23 #include <sigc++/trackable.h>
33 //! A permanent record of an accomplishment during gameplay.
35 * The purpose of the history classes is to keep track about what a
36 * player has accomplished. This list is retained for the duration of
39 * Each history item is derived from the abstract History class. It has to
40 * contain three functions; A loading constructor (which takes an XML_Helper
41 * parameter), a save function which saves the data, a fillData function
42 * which takes some parameters and with these stores the data about what
49 //! The xml tag of this object in a saved-game file.
50 static std::string d_tag;
52 //! A History can be one of the following kinds.
54 //! The player started a turn.
56 //! The player has searched a Ruin and found a sage.
58 //! The player has accrued a certain amount of gold in the treasury.
60 //! A hero has emerged.
62 //! A City has been taken.
64 //! A City has been razed.
66 //! A Hero has inititiated a Quest.
67 HERO_QUEST_STARTED = 7,
68 //! A Hero has completed a Quest.
69 HERO_QUEST_COMPLETED = 8,
70 //! A Hero was killed in battle at a City.
71 HERO_KILLED_IN_CITY = 9,
72 //! A Hero was killed in battle in the field.
73 HERO_KILLED_IN_BATTLE = 10,
74 //! A Hero was killed searching a Ruin.
75 HERO_KILLED_SEARCHING = 11,
76 //! A Hero was involved in taking a City.
78 //! The player has this score.
80 //! The player has been utterly defeated.
81 PLAYER_VANQUISHED = 14,
82 //! The player has achieved peace with an opponent.
83 DIPLOMATIC_PEACE = 15,
84 //! The player has started a war with an opponent.
86 //! The player has been treacherous towards an opponent.
87 DIPLOMATIC_TREACHERY = 17,
88 //! A Hero finds some powerful allies.
89 HERO_FINDS_ALLIES = 18,
90 //! The player has finished a turn.
92 //! The player has explored a ruin.
93 HERO_RUIN_EXPLORED = 20,
94 //! The player has been told of the location of a hidden ruin.
95 HERO_REWARD_RUIN = 21,
97 static std::string historyTypeToString(const History::Type type);
98 static History::Type historyTypeFromString(const std::string str);
100 //! Default constructor.
103 //! Loading from XML constructor.
104 History (XML_Helper *helper);
109 //! Returns debug information. Needs to be overwritten by derivatives
110 virtual std::string dump() const = 0;
113 * static load function (see XML_Helper)
115 * Whenever a History item is loaded, this function is called. It
116 * examines the stored History::Type and calls the constructor of
117 * the appropriate History class.
119 * @param helper The opened saved-game file to read from.
121 //! Load a History from an opened saved-game file.
122 static History* handle_load(XML_Helper* helper);
124 //! Copies a history into a new one.
125 static History* copy(const History* a);
127 //! Returns the id which identifies the type of History event.
128 Type getType() const {return d_type;}
130 bool save(XML_Helper* helper) const;
131 bool saveContents(XML_Helper* helper) const;
134 virtual bool doSave(XML_Helper* helper) const = 0;
138 //-----------------------------------------------------------------------------
140 //! A permanent record of a player starting a turn.
141 class History_StartTurn : public History
144 //! Default constructor.
146 //! Copy constructor.
147 History_StartTurn(const History_StartTurn &history);
148 //! Load the historical event from an opened saved-game file.
149 History_StartTurn(XML_Helper* helper);
151 ~History_StartTurn();
153 //! Return some debug information about this historical event.
154 std::string dump() const;
156 //! Save the historical event to an opened saved-game file.
157 virtual bool doSave(XML_Helper* helper) const;
159 //! This method doesn't need to be called for History_StartTurn.
165 //-----------------------------------------------------------------------------
167 //! A permanent record of a Hero searching a Ruin and finding a sage.
168 class History_FoundSage : public History
171 //! Default constructor.
173 //! Copy constructor.
174 History_FoundSage(const History_FoundSage &history);
175 //! Load the historical event from an opened saved-game file.
176 History_FoundSage(XML_Helper* helper);
178 ~History_FoundSage();
180 //! Return some debug information about this historical event.
181 std::string dump() const;
183 //! Save the historical event to an opened saved-game file.
184 virtual bool doSave(XML_Helper* helper) const;
186 //! Populate the event with the Hero who found the sage.
187 bool fillData(Hero *hero);
189 //! Get the name of the Hero who found the sage.
190 std::string getHeroName() const {return d_hero;}
193 //! The name of the Hero.
197 //-----------------------------------------------------------------------------
199 //! A permanent record of the amount of gold pieces a player has.
200 class History_GoldTotal : public History
203 //! Default constructor.
205 //! Copy constructor.
206 History_GoldTotal(const History_GoldTotal &history);
207 //! Load the historical event from an opened saved-game file.
208 History_GoldTotal(XML_Helper* helper);
210 ~History_GoldTotal();
212 //! Return some debug information about this historical event.
213 std::string dump() const;
215 //! Save the historical event to an opened saved-game file.
216 virtual bool doSave(XML_Helper* helper) const;
218 //! Populate the event with the amount of gold pieces the Player has.
219 bool fillData(int gold);
221 //! Get the amount of gold associated with this event.
222 int getGold() const {return d_gold;}
225 //! The amount of gold pieces the player has at a point in time.
229 //-----------------------------------------------------------------------------
231 //! A permanent record of a new Hero emerging in a City.
232 class History_HeroEmerges : public History
235 //! Default constructor.
236 History_HeroEmerges();
237 //! Copy constructor.
238 History_HeroEmerges(const History_HeroEmerges &history);
239 //! Load the historical event from an opened saved-game file.
240 History_HeroEmerges(XML_Helper* helper);
242 ~History_HeroEmerges();
244 //! Return some debug information about this historical event.
245 std::string dump() const;
247 //! Save the historical event to an opened saved-game file.
248 virtual bool doSave(XML_Helper* helper) const;
250 //! Populate the event with pertinent data.
252 * Populate the event with the new Hero who has showed up and
253 * the City where it has appeared.
255 * @param hero The Hero that has emergerd.
256 * @param city The City where the Hero has emerged.
258 bool fillData(Hero *hero, City *city);
260 //! Get the name of the Hero who appeared.
261 std::string getHeroName() const {return d_hero;}
263 guint32 getHeroId() const {return d_hero_id;};
265 //! Get the name of the City where the Hero has emerged.
266 std::string getCityName() const {return d_city;}
269 //! The name of the Hero who emerged.
272 //! The id of the hero
275 //! The name of the City where the Hero emerged.
279 //-----------------------------------------------------------------------------
281 //! A permanent record of an enemy city being defeated.
282 class History_CityWon : public History
285 //! Default constructor.
287 //! Copy constructor.
288 History_CityWon(const History_CityWon &history);
289 //! Load the historical event from an opened saved-game file.
290 History_CityWon(XML_Helper* helper);
294 //! Return some debug information about this historical event.
295 std::string dump() const;
297 //! Save the historical event to an opened saved-game file.
298 virtual bool doSave(XML_Helper* helper) const;
300 //! Populate the record with the City that the Player defeated.
301 bool fillData(City *city);
303 //! Get the Id of the City object that was defeated.
304 guint32 getCityId() const {return d_city;}
307 //! The Id of the City object that was defeated.
311 //-----------------------------------------------------------------------------
313 //! A permanent record of an enemy city being defeated by a Hero.
314 class History_HeroCityWon: public History
317 //! Default constructor.
318 History_HeroCityWon();
319 //! Copy constructor.
320 History_HeroCityWon(const History_HeroCityWon &history);
321 //! Load the historical event from an opened saved-game file.
322 History_HeroCityWon(XML_Helper* helper);
324 ~History_HeroCityWon();
326 //! Return some debug information about this historical event.
327 std::string dump() const;
329 //! Save the historical event to an opened saved-game file.
330 virtual bool doSave(XML_Helper* helper) const;
332 //! Populate the event with pertinent data.
334 * Populate the event with the City that was defeated and the
335 * Hero that assisted in the conquering.
337 * @param city The City that was conquered.
338 * @param hero The Hero who lead the conquering of the City.
340 bool fillData(Hero *hero, City *city);
342 //! Get the name of the Hero who conquered the City.
343 std::string getHeroName() const {return d_hero;}
345 //! Get the name of the City that was conquered.
346 std::string getCityName() const {return d_city;}
349 //! The name of the Hero who helped in conquering the City.
352 //! The name of the City that was conquered.
356 //-----------------------------------------------------------------------------
358 //! A permanent record of an enemy city being razed.
359 class History_CityRazed : public History
362 //! Default constructor.
364 //! Copy constructor.
365 History_CityRazed(const History_CityRazed &history);
366 //! Load the historical event from an opened saved-game file.
367 History_CityRazed(XML_Helper* helper);
369 ~History_CityRazed();
371 //! Return some debug information about this historical event.
372 std::string dump() const;
374 //! Save the historical event to an opened saved-game file.
375 virtual bool doSave(XML_Helper* helper) const;
377 //! Populate the event with the City that was razed.
378 bool fillData(City *city);
380 //! Get the Id of the City object that was razed.
381 guint32 getCityId() const {return d_city;}
384 //! The Id of the City that was razed.
388 //-----------------------------------------------------------------------------
390 //! A permanent record of a Hero initiating a Quest.
391 class History_HeroQuestStarted : public History
394 //! Default constructor.
395 History_HeroQuestStarted();
396 //! Copy constructor.
397 History_HeroQuestStarted(const History_HeroQuestStarted &history);
398 //! Load the historical event from an opened saved-game file.
399 History_HeroQuestStarted(XML_Helper* helper);
401 ~History_HeroQuestStarted();
403 //! Return some debug information about this historical event.
404 std::string dump() const;
406 //! Save the historical event to an opened saved-game file.
407 virtual bool doSave(XML_Helper* helper) const;
409 //! Populate the event with the Hero who initiated a new Quest.
410 bool fillData(Hero *hero);
412 //! Get the name of the Hero who started a Quest.
413 std::string getHeroName() const {return d_hero;}
416 //! The name of the Hero who started the Quest.
420 //-----------------------------------------------------------------------------
422 //! A permanent record of a Hero completing a Quest.
423 class History_HeroQuestCompleted: public History
426 //! Default constructor.
427 History_HeroQuestCompleted();
428 //! Copy constructor.
429 History_HeroQuestCompleted(const History_HeroQuestCompleted &history);
430 //! Load the historical event from an opened saved-game file.
431 History_HeroQuestCompleted(XML_Helper* helper);
433 ~History_HeroQuestCompleted();
435 //! Return some debug information about this historical event.
436 std::string dump() const;
438 //! Save the historical event to an opened saved-game file.
439 virtual bool doSave(XML_Helper* helper) const;
441 //! Populate the event with the Hero who finished a Quest.
442 bool fillData(Hero *hero);
444 //! Get the name of the Hero who finished a Quest.
445 std::string getHeroName() const {return d_hero;}
448 //! The name of the Hero who completed the Quest.
452 //-----------------------------------------------------------------------------
454 //! A permanent record of a Hero killed in the defense or attack of a City.
455 class History_HeroKilledInCity : public History
458 //! Default constructor.
459 History_HeroKilledInCity();
460 //! Copy constructor.
461 History_HeroKilledInCity(const History_HeroKilledInCity &history);
462 //! Load the historical event from an opened saved-game file.
463 History_HeroKilledInCity(XML_Helper* helper);
465 ~History_HeroKilledInCity();
467 //! Return some debug information about this historical event.
468 std::string dump() const;
470 //! Save the historical event to an opened saved-game file.
471 virtual bool doSave(XML_Helper* helper) const;
473 //! Populate the event with pertinent data.
475 * Populate the event with the Hero who was killed and the City where
478 * @param hero The Hero who died.
479 * @param city The City that houses the Hero's broken corpse.
481 bool fillData(Hero *hero, City *city);
483 //! Get the name of the Hero who died.
484 std::string getHeroName() const {return d_hero;}
486 //! Get the name of the City where the Hero died.
487 std::string getCityName() const {return d_city;}
490 //! Get the name of the Hero who was killed.
493 //! Get the name of the City where the Hero was killed.
497 //-----------------------------------------------------------------------------
499 //! A permanent record of a Hero killed in battle outside of a City.
500 class History_HeroKilledInBattle: public History
503 //! Default constructor.
504 History_HeroKilledInBattle();
505 //! Copy constructor.
506 History_HeroKilledInBattle(const History_HeroKilledInBattle &history);
507 //! Load the historical event from an opened saved-game file.
508 History_HeroKilledInBattle(XML_Helper* helper);
510 ~History_HeroKilledInBattle();
512 //! Return some debug information about this historical event.
513 std::string dump() const;
515 //! Save the historical event to an opened saved-game file.
516 virtual bool doSave(XML_Helper* helper) const;
518 //! Populate the event with the Hero who was killed in battle.
519 bool fillData(Hero *hero);
521 //! Get the name of the Hero who died in battle outside of a City.
522 std::string getHeroName() const {return d_hero;}
525 //! The name of the Hero who died in battle outside of a City.
529 //-----------------------------------------------------------------------------
531 //! A permanent record of a Hero killed while searching a Ruin.
532 class History_HeroKilledSearching: public History
535 //! Default constructor.
536 History_HeroKilledSearching();
537 //! Copy constructor.
538 History_HeroKilledSearching(const History_HeroKilledSearching &history);
539 //! Load the historical event from an opened saved-game file.
540 History_HeroKilledSearching(XML_Helper* helper);
542 ~History_HeroKilledSearching();
544 //! Return some debug information about this historical event.
545 std::string dump() const;
547 //! Save the historical event to an opened saved-game file.
548 virtual bool doSave(XML_Helper* helper) const;
550 //! Populate the event with the Hero who was killed while searching.
551 bool fillData(Hero *hero);
553 //! Get the name of the Hero who died while searching a Ruin.
554 std::string getHeroName() const {return d_hero;}
557 //! The name of the Hero who died while searching a Ruin.
561 //-----------------------------------------------------------------------------
563 //! A permanent record of the player's score.
564 class History_Score: public History
567 //! Default constructor.
569 //! Copy constructor.
570 History_Score(const History_Score &history);
571 //! Load the historical event from an opened saved-game file.
572 History_Score(XML_Helper* helper);
576 //! Return some debug information about this historical event.
577 std::string dump() const;
579 //! Save the historical event to an opened saved-game file.
580 virtual bool doSave(XML_Helper* helper) const;
582 //! Populate the event with the player's score for this turn.
583 bool fillData(guint32 score);
585 //! Get the player's score for this turn.
586 guint32 getScore() const {return d_score;}
589 //! The player's score.
593 //-----------------------------------------------------------------------------
595 //! A permanent record of the player being utterly defeated.
596 class History_PlayerVanquished: public History
599 //! Default constructor.
600 History_PlayerVanquished();
601 //! Copy constructor.
602 History_PlayerVanquished(const History_PlayerVanquished &history);
603 //! Load the historical event from an opened saved-game file.
604 History_PlayerVanquished(XML_Helper* helper);
606 ~History_PlayerVanquished();
608 //! Return some debug information about this historical event.
609 std::string dump() const;
611 //! Save the historical event to an opened saved-game file.
612 virtual bool doSave(XML_Helper* helper) const;
616 //-----------------------------------------------------------------------------
618 //! A permanent record of the player making peace with an opponent.
619 class History_DiplomacyPeace : public History
622 //! Default constructor.
623 History_DiplomacyPeace();
624 //! Copy constructor.
625 History_DiplomacyPeace(const History_DiplomacyPeace &history);
626 //! Load the historical event from an opened saved-game file.
627 History_DiplomacyPeace(XML_Helper* helper);
629 ~History_DiplomacyPeace();
631 //! Return some debug information about this historical event.
632 std::string dump() const;
634 //! Save the historical event to an opened saved-game file.
635 virtual bool doSave(XML_Helper* helper) const;
637 //! Populate the event with the Player who we are at peace with.
638 bool fillData(Player *opponent);
640 //! Get the Id of the Player object we are at peace with.
641 guint32 getOpponentId() const {return d_opponent_id;}
644 //! The Id of the Player object we are at peace with.
645 guint32 d_opponent_id;
648 //-----------------------------------------------------------------------------
650 //! A permanent record of the player going to war with an opponent.
651 class History_DiplomacyWar: public History
654 //! Default constructor.
655 History_DiplomacyWar();
656 //! Copy constructor.
657 History_DiplomacyWar(const History_DiplomacyWar &history);
658 //! Load the historical event from an opened saved-game file.
659 History_DiplomacyWar(XML_Helper* helper);
661 ~History_DiplomacyWar();
663 //! Return some debug information about this historical event.
664 std::string dump() const;
666 //! Save the historical event to an opened saved-game file.
667 virtual bool doSave(XML_Helper* helper) const;
669 //! Populate the event with the Player who we are at war with.
670 bool fillData(Player *opponent);
672 //! Get the Id of the Player object we are at war with.
673 guint32 getOpponentId() const {return d_opponent_id;}
676 // The Id of the Player object we are at war with.
677 guint32 d_opponent_id;
680 //-----------------------------------------------------------------------------
682 //! A permanent record of the player being treacherous to an opponent.
683 class History_DiplomacyTreachery: public History
686 //! Default constructor.
687 History_DiplomacyTreachery();
688 //! Copy constructor.
689 History_DiplomacyTreachery(const History_DiplomacyTreachery &history);
690 //! Load the historical event from an opened saved-game file.
691 History_DiplomacyTreachery(XML_Helper* helper);
693 ~History_DiplomacyTreachery();
695 //! Return some debug information about this historical event.
696 std::string dump() const;
698 //! Save the historical event to an opened saved-game file.
699 virtual bool doSave(XML_Helper* helper) const;
701 //! Populate the event with the Player we performed treachery on.
702 bool fillData(Player *opponent);
704 //! Get the Id of the Player object that we peformed treachery on.
705 guint32 getOpponentId() const {return d_opponent_id;}
708 //! The Id of the Player object that we peformed treachery on.
709 guint32 d_opponent_id;
712 //-----------------------------------------------------------------------------
714 //! A permanent record of a Hero finding powerful allies.
715 class History_HeroFindsAllies : public History
718 //! Default constructor.
719 History_HeroFindsAllies();
720 //! Copy constructor.
721 History_HeroFindsAllies(const History_HeroFindsAllies &history);
722 //! Load the historical event from an opened saved-game file.
723 History_HeroFindsAllies(XML_Helper* helper);
725 ~History_HeroFindsAllies();
727 //! Return some debug information about this historical event.
728 std::string dump() const;
730 //! Save the historical event to an opened saved-game file.
731 virtual bool doSave(XML_Helper* helper) const;
733 //! Populate the event with the name of the Hero who found allies.
734 bool fillData(Hero *hero);
736 //! Get the name of the Hero who found powerful allies.
737 std::string getHeroName() const {return d_hero;}
740 //! The name of the Hero who found powerful allies at a Ruin.
744 //-----------------------------------------------------------------------------
745 //! A permanent record of a player ending a turn.
746 class History_EndTurn : public History
749 //! Default constructor.
751 //! Copy constructor.
752 History_EndTurn(const History_EndTurn &history);
753 //! Load the historical event from an opened saved-game file.
754 History_EndTurn(XML_Helper* helper);
758 //! Return some debug information about this historical event.
759 std::string dump() const;
761 //! Save the historical event to an opened saved-game file.
762 virtual bool doSave(XML_Helper* helper) const;
764 //! This method doesn't need to be called for History_EndTurn.
769 //-----------------------------------------------------------------------------
771 //! A permanent record of a ruin being successfully searched by a Hero.
772 class History_HeroRuinExplored: public History
775 //! Default constructor.
776 History_HeroRuinExplored();
777 //! Copy constructor.
778 History_HeroRuinExplored(const History_HeroRuinExplored &history);
779 //! Load the historical event from an opened saved-game file.
780 History_HeroRuinExplored(XML_Helper* helper);
782 ~History_HeroRuinExplored();
784 //! Return some debug information about this historical event.
785 std::string dump() const;
787 //! Save the historical event to an opened saved-game file.
788 virtual bool doSave(XML_Helper* helper) const;
790 //! Populate the event with pertinent data.
792 * Populate the event with the Ruin that was searched and
793 * the Hero that did the exploration.
795 * @param ruin The Ruin that was explored.
796 * @param hero The Hero who did the exploration of the Ruin.
798 bool fillData(Hero *hero, Ruin *ruin);
800 //! Get the name of the Hero who searched the Ruin.
801 std::string getHeroName() const {return d_hero;}
803 //! Get the id of the Ruin that was searched.
804 guint32 getRuinId() const {return d_ruin;}
807 //! The name of the Hero who explored the Ruin.
810 //! The id of the Ruin that was searched.
815 //-----------------------------------------------------------------------------
817 //! A permanent record of the location of a ruin being given to a Hero.
818 class History_HeroRewardRuin: public History
821 //! Default constructor.
822 History_HeroRewardRuin();
823 //! Copy constructor.
824 History_HeroRewardRuin(const History_HeroRewardRuin&history);
825 //! Load the historical event from an opened saved-game file.
826 History_HeroRewardRuin(XML_Helper* helper);
828 ~History_HeroRewardRuin();
830 //! Return some debug information about this historical event.
831 std::string dump() const;
833 //! Save the historical event to an opened saved-game file.
834 virtual bool doSave(XML_Helper* helper) const;
836 //! Populate the event with pertinent data.
838 * Populate the event with the Ruin that was exposed and
839 * the Hero that received the location of the ruin.
841 * @param ruin The Ruin that was exposed.
842 * @param hero The Hero who received the location of the Ruin.
844 bool fillData(Hero *hero, Ruin *ruin);
846 //! Get the name of the Hero who was given the location of the Ruin.
847 std::string getHeroName() const {return d_hero;}
849 //! Get the id of the Ruin that was exposed.
850 guint32 getRuinId() const {return d_ruin;}
853 //! The name of the Hero who was told the location of the Ruin.
856 //! The id of the Ruin that was exposed.