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
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.
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.
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
27 #include <sigc++/trackable.h>
44 //! A temporary record of an event during gameplay.
46 * The purpose of the action classes is to keep track of what a player has
47 * done. This information can be sent over the network, so that a networked
48 * player then just has to decode and repeat the remote player's actions so
49 * that the game state is synchronised.
51 * Each action item is derived from the abstract Action class. It must
52 * contain three functions; A loading constructor (which takes an
53 * XML_Helper parameter), a save function which saves the data to the
54 * XML file, and a fillData function which takes some parameters and
55 * stores the pertinent data about what happened.
57 * Each Player has an Actionlist to which these actions belong.
63 //! The xml tag of this object in a saved-game file.
64 static std::string d_tag;
66 //! An Action can be one of the following kinds.
68 /** A stack has moved. */
70 /** A stack has separated into two parts. */
72 /** A stack is fighting a city or another stack. */
74 /** A stack has merged with another stack. */
76 /** A stack containing a hero has examined a ruin. */
78 /** A stack has examined a temple. */
80 /** A stack has defeated a city and occupied it. */
82 /** A stack has defeated a city and pillaged it. */
84 /** A stack has defeated a city and razed it. */
86 /** A player has improved the defenses of a city. (Not used) */
88 /** A player has purchased a new Army unit to be produced
91 /** A player has changed production in a city to another
94 /** A stack has received a reward. */
96 /** A hero has received a new quest. */
98 /** A hero has picked up or dropped an item. */
100 /** An Army unit has advanced to a new level (Only used for
103 /** A stack has defeated a city and sacked it. */
105 /** A player has removed a stack. */
107 /** A player has changed what a signpost says. */
108 MODIFY_SIGNPOST = 19,
109 /** A player has changed the name of a city. */
111 /** A player has vectored Army units from one city to
114 /** A player has changed the order in which Army units do
117 /** A player has surrendered. */
119 /** A hero has planted an item in the ground. */
121 /** A newly produced Army unit arrives on the map. */
123 /** A new vectored Army unit has shown up at a location. */
124 PRODUCE_VECTORED_UNIT = 26,
125 /** The player's diplomatic relations with respect to another
126 * player has changed. */
127 DIPLOMATIC_STATE = 27,
128 /** The player's diplomatic proposal with respect to another
129 * player has changed. */
130 DIPLOMATIC_PROPOSAL = 28,
131 /** The player's diplomatic score with respect to another
132 * player has changed. */
133 DIPLOMATIC_SCORE = 29,
142 static std::string actionTypeToString(Action::Type type);
143 static Action::Type actionTypeFromString(std::string str);
145 //! Default constructor.
148 //! Copy constructor (shallow).
149 Action(const Action &action);
151 //! Loading constructor.
152 Action(XML_Helper *helper);
157 //! Returns debug information. Needs to be overwritten by derivatives.
158 virtual std::string dump() const = 0;
160 //! Save function. See XML_Helper for information about saving.
161 bool save(XML_Helper* helper) const;
162 bool saveContents(XML_Helper* helper) const;
165 * static load function (see XML_Helper)
167 * Whenever an action item is loaded, this function is called. It
168 * examines the stored id and calls the constructor of the appropriate
171 * @param helper the XML_Helper instance for the savegame
173 //! Load the action from an opened saved-game file.
174 static Action* handle_load(XML_Helper* helper);
176 //! Make a new action from an existing one.
177 static Action* copy(const Action* a);
179 //! Returns the Action::Type for this action.
180 Type getType() const {return d_type;}
183 virtual bool doSave(XML_Helper* helper) const = 0;
188 //-----------------------------------------------------------------------------
190 //! A temporary record of a Stack moving.
192 * The purpose of the Action_Move class is to record when a stack has
193 * moved to a new position on the map.
195 class Action_Move : public Action
198 //! Make a new move action.
201 Action_Move(const Action_Move &action);
202 //! Load a new move action from an opened saved-game file.
203 Action_Move(XML_Helper* helper);
204 //! Destroy a move action.
207 //! Return some debug information about this action.
208 std::string dump() const;
210 //! Save this move action to an opened saved-game file.
211 virtual bool doSave(XML_Helper* helper) const;
213 //! Populate the move action with the stack and it's new position.
214 bool fillData(Stack* s, Vector<int> dest);
216 guint32 getStackId() const {return d_stack;};
217 Vector<int> getEndingPosition() const {return d_dest;};
218 Vector<int> getPositionDelta() const {return d_delta;};
226 //! A temporary record of a Stack being disbanded.
228 * The purpose of the Action_Disband class is to record when a stack has
229 * removed from the game. Disbanding is done to primarily to save the
230 * gold pieces paid out every turn as upkeep for the Army units in the Stack.
232 class Action_Disband: public Action
235 //! Make a new disband action.
238 Action_Disband(const Action_Disband &action);
239 //! Load a new disband action from an opened saved-game file.
240 Action_Disband(XML_Helper* helper);
241 //! Destroy a disband action.
244 //! Return some debug information about this action.
245 std::string dump() const;
247 //! Save this disband action to an opened saved-game file.
248 virtual bool doSave(XML_Helper* helper) const;
250 //! Populate the action with the Stack being removed.
251 bool fillData(Stack* s);
253 guint32 getStackId() const {return d_stack;};
259 //-----------------------------------------------------------------------------
261 //! A temporary record of a Stack being split into two.
263 * The purpose of the Action_Split class is to record when a Stack has been
264 * separated into two parts. This happens when the Player groups only some
265 * of the Army units in the stack (not all), and then moves them to a new
266 * position on the map. When a split is completed there is the original
267 * stack (the remaining Army units in the stack that didn't change position),
268 * and a new stack added to the game (the stack containing the grouped army
271 class Action_Split : public Action
274 //! Make a new stack split action.
277 Action_Split(const Action_Split &action);
278 //! Load a new stack split action from an opened saved-game file.
279 Action_Split(XML_Helper* helper);
280 //! Destroy a stack split action.
283 //! Return some debug information about this action.
284 std::string dump() const;
286 //! Save this split action to an opened saved-game file.
287 bool doSave (XML_Helper* helper) const;
290 * Populate the Action_Split class with the original Stack, and the
291 * new stack that has been added to the game. Please note that the
292 * stacks have to be already split before this call.
294 //! Populate the action with pertinent data.
295 bool fillData(Stack* orig, Stack* added);
297 guint32 getStackId() const {return d_orig;};
298 guint32 getNewStackId() const {return d_added;};
299 guint32 getGroupedArmyId(int idx) const {return d_armies_moved[idx];};
301 guint32 d_orig, d_added;
302 guint32 d_armies_moved[MAX_STACK_SIZE];
305 //-----------------------------------------------------------------------------
307 //! A temporary record of a fight between opposing Stack objects.
309 * The purpose of the Action_Fight class is to record the results of a
310 * fight between two Players.
312 class Action_Fight : public Action, public sigc::trackable
315 //! Make a new fight action.
318 Action_Fight(const Action_Fight &action);
319 //! Load a new fight action from an opened saved-game file.
320 Action_Fight(XML_Helper* helper);
321 //! Destroy a fight action.
324 //! Return some debug information about this action.
325 std::string dump() const;
327 //! Save this fight action to an opened saved-game file.
328 virtual bool doSave(XML_Helper* helper) const;
331 * Populate the action with the Fight. Please note that the
332 * Fight must have already been faught.
334 //! Fill the action with pertinent data.
335 bool fillData(const Fight* f);
338 std::list<FightItem> getBattleHistory() const {return d_history;};
339 std::list<guint32> getAttackerArmyIds() const {return d_attackers;};
340 std::list<guint32> getDefenderArmyIds() const {return d_defenders;};
344 std::list<FightItem> d_history;
345 std::list<guint32> d_attackers;
346 std::list<guint32> d_defenders;
348 bool loadItem(std::string tag, XML_Helper* helper);
351 //-----------------------------------------------------------------------------
353 //! A temporary record of two Stack objects merging into one.
355 * The purpose of the Action_Join class is to record a Stack has had
356 * another Stack merged into it.
358 class Action_Join : public Action
361 //! Make a new stack join action.
364 Action_Join(const Action_Join &action);
365 //! Load a new stack join action from an opened saved-game file.
366 Action_Join(XML_Helper* helper);
367 //! Destroy a stack join action.
370 //! Return some debug information about this action.
371 std::string dump() const;
373 //! Save this stack join action to an opened saved-game file.
374 virtual bool doSave(XML_Helper* helper) const;
377 * Populate the Action_Join class with the original Stack, and the
378 * stack that is merging into the original one. Please note that
379 * this method must be called before the merge takes place.
381 //! Populate the action with pertinent data.
382 bool fillData(Stack* orig, Stack* joining);
384 guint32 getReceivingStackId() const {return d_orig_id;};
385 guint32 getJoiningStackId() const {return d_joining_id;};
387 guint32 d_orig_id, d_joining_id;
390 //-----------------------------------------------------------------------------
392 //! A temporary record of what happened when a Stack searched a Ruin.
394 * The purpose of the Action_Ruin class is to record what happens when a
395 * Stack containing a Hero attempts to search a Ruin.
397 class Action_Ruin : public Action
400 //! Make a new ruin search attempted action.
403 Action_Ruin(const Action_Ruin&action);
404 //! Load a new ruin search attempted action from a saved-game file.
405 Action_Ruin(XML_Helper* helper);
406 //! Destroy a ruin search attempted action.
409 //! Return some debug information about this action.
410 std::string dump() const;
412 //! Save this ruin search attempted action to a saved-game file.
413 virtual bool doSave(XML_Helper* helper) const;
416 * Populate the Action_Ruin class with the Stack containing the
417 * Hero Army unit, and the Ruin being searched.
419 //! Populate the action with pertinent data.
420 bool fillData(Ruin* r, Stack* explorers);
422 //! Set whether or not the Stack was successful in searching the ruin.
423 void setSearched(bool searched) {d_searched = searched;}
425 guint32 getRuinId() const {return d_ruin;};
426 guint32 getStackId() const {return d_stack;};
427 bool getSearchSuccessful() const {return d_searched;};
435 //-----------------------------------------------------------------------------
437 //! A temporary record of what happened when a Stack visited a Temple.
439 * The purpose of the Action_Temple class is to record what happens when
440 * a Stack visits a Temple. The Stack may be getting blessed, or instead it
441 * might be a Stack containing a Hero who is obtaining a new Quest.
443 class Action_Temple : public Action
446 //! Make a new temple search action.
449 Action_Temple(const Action_Temple &action);
450 //! Load a new temple search action from a saved-game file.
451 Action_Temple(XML_Helper* helper);
452 //! Destroy a temple search action.
455 //! Return some debug information about this action.
456 std::string dump() const;
458 //! Save this temple search attempted action to a saved-game file.
459 virtual bool doSave(XML_Helper* helper) const;
462 * Populate the Action_Temple class with the Stack and the Temple
465 //! Populate the action with pertinent data.
466 bool fillData(Temple* t, Stack* s);
468 guint32 getTempleId() const {return d_temple;};
469 guint32 getStackId() const {return d_stack;};
477 //-----------------------------------------------------------------------------
479 //! A temporary record of what happened when a Player occupied a City.
481 * The purpose of the Action_Occupy class is to record when a Player has
482 * defeated a City and has occupied it. Ocuppying differs from sacking
483 * and pillaging in that none of the existing Army units in the City are
484 * exchanged for gold pieces.
486 class Action_Occupy : public Action
489 //! Make a new city occupy action.
491 //! Copy constructor.
492 Action_Occupy(const Action_Occupy &action);
493 //! Load a new city occupied action from an opened saved-game file.
494 Action_Occupy(XML_Helper* helper);
495 //! Destroy a city occupy action.
498 //! Return some debug information about this action.
499 std::string dump() const;
501 //! Save this city occupied action to an opened saved-game file.
502 virtual bool doSave(XML_Helper* helper) const;
504 //! Populate the action with the City being occupied.
505 bool fillData (City* c);
507 guint32 getCityId() const {return d_city;};
513 //-----------------------------------------------------------------------------
515 //! A temporary record of what happened when a Player pillaged a City.
517 * The purpose of the Action_Pillage class is to record when a Player has
518 * defeated a City and has pillaged it. Pillaging a city results in the
519 * strongest Army unit being produced in that city being exchanged for an
520 * amount of gold pieces.
522 class Action_Pillage : public Action
525 //! Make a new city pillaged action.
528 Action_Pillage(const Action_Pillage &action);
529 //! Load a new city pillaged action from an opened saved-game file.
530 Action_Pillage(XML_Helper* helper);
531 //! Destroy a city pillaged action.
534 //! Return some debug information about this action.
535 std::string dump() const;
537 //! Save this city pillaged action to an opened saved-game file.
538 virtual bool doSave(XML_Helper* helper) const;
540 //! Populate the action with the City that has been pillaged.
541 bool fillData(City* c);
543 guint32 getCityId() const {return d_city;};
549 //-----------------------------------------------------------------------------
551 //! A temporary record of what happened when a Player sacked a City.
553 * The purpose of the Action_Sack class is to record when a Player has
554 * defeated a City and has sacked it. Sacking a city results in all
555 * Army units, except the weakest being exchanged for an amount of gold
558 class Action_Sack : public Action
561 //! Make a new city sacked action.
564 Action_Sack(const Action_Sack &action);
565 //! Load a new city sacked action from an opened saved-game file.
566 Action_Sack(XML_Helper* helper);
567 //! Destroy a city sacked action.
570 //! Return some debug information about this action.
571 std::string dump() const;
573 //! Save this city sacked action to an opened saved-game file.
574 virtual bool doSave(XML_Helper* helper) const;
576 //! Populate the action with the City that has been sacked.
577 bool fillData(City* c);
579 guint32 getCityId() const {return d_city;};
585 //-----------------------------------------------------------------------------
587 //! A temporary record of what happened when a Player razed a City.
589 * The purpose of the Action_Raze class is to record when a Player has
590 * defeated a City and has razed it. Razing a city results in that
591 * city becoming uninhabitable, and it ceases to produce new Army units.
593 class Action_Raze : public Action
596 //! Make a new city razed action.
599 Action_Raze(const Action_Raze &action);
600 //! Load a new city razed action from an opened saved-game file.
601 Action_Raze(XML_Helper* helper);
602 //! Destroy a city razed action.
605 //! Return some debug information about this action.
606 std::string dump() const;
608 //! Save this city razed action to an opened saved-game file.
609 virtual bool doSave(XML_Helper* helper) const;
611 //! Populate the action with the City that has been razed.
612 bool fillData (City* c);
614 guint32 getCityId() const {return d_city;};
620 //-----------------------------------------------------------------------------
622 //! A temporary record of what happened when a City's defenses were increased.
624 * The purpose of the Action_Upgrade class is to record when a Player has
625 * improved the City's defenses. This action is not currently used by
628 class Action_Upgrade : public Action
631 //! Make a new city upgraded action.
634 Action_Upgrade(const Action_Upgrade &action);
635 //! Load a new city upgraded action from an opened saved-game file.
636 Action_Upgrade(XML_Helper* helper);
637 //! Destroy a city upgraded action.
640 //! Return some debug information about this action.
641 std::string dump() const;
643 //! Save this city upgraded action to an opened saved-game file.
644 virtual bool doSave(XML_Helper* helper) const;
646 //! Populate the action with the City that has been upgraded.
647 bool fillData(City* c);
649 guint32 getCityId() const {return d_city;};
655 //-----------------------------------------------------------------------------
657 //! A temporary record of more production being added to a City.
659 * The purpose of the Action_Buy class is to record when a Player purchases
660 * a new Army unit for production in a City. When this happens the player
661 * specifies a production slot to hold the new Army unit type. Any existing
662 * Army unit type in that slot before the buy is removed.
663 * The idea here is that the city may produce one Army unit type from a set
664 * of available Army units, and this action records what happens when we make
665 * a new kind of Army unit available for production in the City.
666 * The army unit is taken from the Player's Armyset.
668 class Action_Buy : public Action
671 //! Make a new city buy production action.
674 Action_Buy(const Action_Buy &action);
675 //! Load a new city buy production action from a saved-game file.
676 Action_Buy(XML_Helper* helper);
677 //! Destroy a city buy production action.
680 //! Return some debug information about this action.
681 std::string dump() const;
683 //! Save this city buy production action to an opened saved-game file.
684 virtual bool doSave(XML_Helper* helper) const;
687 * Populate the Action_Buy with City where the buy has happened.
688 * Also populate it with the City's production slot that is now
689 * producing the new Army unit type. Lastly, populate the Action_Buy
690 * with the new Army unit type being produced.
692 //! Populate the action with pertinent data.
693 bool fillData(City* c, int slot, const ArmyProto *prod);
695 guint32 getCityId() const {return d_city;};
696 int getProductionSlot() const {return d_slot;};
697 int getBoughtArmyTypeId() const {return d_prod;};
703 //-----------------------------------------------------------------------------
705 //! A temporary record of a change in production strategy in a City.
707 * The purpose of the Action_Production class is to record when the Player
708 * changes the production of new Army units within a City. The idea here
709 * is that the City has a set of available Army units that it may produce,
710 * and the Player has selected a different Army unit to produce, or has
711 * stopped production of new Army units altogether.
713 class Action_Production : public Action
716 //! Make a new city change production action.
719 Action_Production (const Action_Production &action);
720 //! Load a new city change production action from a saved-game file.
721 Action_Production(XML_Helper* helper);
722 //! Destroy a city change production action.
723 ~Action_Production();
725 //! Return some debug information about this action.
726 std::string dump() const;
728 //! Save this city change production action to a saved-game file.
729 virtual bool doSave(XML_Helper* helper) const;
732 * Populate the Action_Production with City where the change
733 * in production has taken place. Also populate it with the newly
734 * active production slot (-1 means stopped).
736 //! Populate the action with pertinent data.
737 bool fillData(City* c, int slot);
739 guint32 getCityId() const {return d_city;};
740 int getSlot() const {return d_prod;};
747 //-----------------------------------------------------------------------------
749 //! A temporary record of a Player or Stack getting a Reward.
751 * The purpose of the Action_Reward class is to record when the Player
752 * has been given a Reward.
753 * It could be that the player has been given: Some gold pieces, a map that
754 * makes more of the map visible or information about the location of a new
755 * ruin. It could also be that the player's active stack has been given
756 * a number of allies. It could also be that the Player's active Stack
757 * contains a Hero, and the Reward is an Item for the Hero to carry.
759 class Action_Reward : public Action
762 //! Make a new player rewarded action.
765 Action_Reward (const Action_Reward &action);
766 //! Load a new player rewarded action from a saved-game file.
767 Action_Reward(XML_Helper* helper);
768 //! Destroy a player rewarded action.
771 //! Return some debug information about this action.
772 std::string dump() const;
774 //! Save this player rewarded action to a saved-game file.
775 virtual bool doSave(XML_Helper* helper) const;
777 //! Populate the Action_Reward with a Reward.
778 bool fillData (Stack *stack, Reward *r);
781 Reward *getReward() const {return d_reward;};
782 guint32 getStackId() const {return d_stack;};
788 bool load(std::string tag, XML_Helper *helper);
792 //-----------------------------------------------------------------------------
794 //! A temporary record of a Hero initiating a new Quest.
796 * The purpose of the Action_Quest class is to record when a Player's
797 * Hero has gone to a Temple and initiated a new Quest.
799 class Action_Quest : public Action
802 //! Make a new hero quest assigned action.
805 Action_Quest (const Action_Quest &action);
806 //! Load a new hero quest assigned action from a saved-game file.
807 Action_Quest(XML_Helper* helper);
808 //! Destroy a hero quest assigned action.
811 //! Return some debug information about this action.
812 std::string dump() const;
814 //! Save this hero quest assigned action to a saved-game file.
815 virtual bool doSave(XML_Helper* helper) const;
817 //! Populate the Action_Quest with a Quest.
818 bool fillData(Quest* q);
820 guint32 getHeroId() const {return d_hero;};
821 guint32 getQuestType() const {return d_questtype;};
822 guint32 getData() const {return d_data;};
823 guint32 getVictimPlayerId() const {return d_victim_player;};
829 guint32 d_victim_player; //victim player, only KILLARMIES uses this
832 //-----------------------------------------------------------------------------
834 //! A temporary record of a Hero picking up or dropping an Item.
836 * The purpose of the Action_Equip class is to record when a Player's Hero
837 * has picked up an Item or dropped it onto the ground. Heroes pick up
838 * and drop Items one at a time.
840 class Action_Equip : public Action
844 // The Item is going neither to the ground or the backpack.
846 //! The Item has gone into the Hero's Backpack.
848 //! The Item has been dropped onto the ground.
851 //! Make a new item equipped action.
854 Action_Equip (const Action_Equip &action);
855 //! Load a new item equipped action from an opened saved-game file.
856 Action_Equip(XML_Helper* helper);
857 //! Destroy an item equipped action.
860 //! Return some debug information about this action.
861 std::string dump() const;
863 //! Save this item equipped action to an opened saved-game file.
864 virtual bool doSave(XML_Helper* helper) const;
867 * Populate the Action_Equip class with the Id of the Hero,
868 * the Id of the Item and the destination of the Item in terms of
869 * it's Action_Equip::Slot.
871 //! Populate the action with pertinent data.
872 bool fillData(Hero *hero, Item *item, Slot slot, Vector<int> pos);
874 guint32 getHeroId() const {return d_hero;};
875 guint32 getItemId() const {return d_item;};
876 guint32 getToBackpackOrToGround() const {return d_slot;};
877 Vector<int> getItemPos() const {return d_pos;};
886 //-----------------------------------------------------------------------------
888 //! A temporary record of a Hero gaining a new level.
890 * The purpose of the Action_Level class is to record when a Player's Hero
891 * advances a level and subsequently gains a stat.
892 * Stats that may get increased are: Strength, Moves, and Sight (for use on
895 class Action_Level : public Action
898 //! Make a new level advancement action.
901 Action_Level (const Action_Level &action);
902 //! Load a new level advancement action from an opened saved-game file.
903 Action_Level(XML_Helper* helper);
904 //! Destroy a level advancement action.
907 //! Return some debug information about this action.
908 std::string dump() const;
910 //! Save this level advancement action to an opened saved-game file.
911 virtual bool doSave(XML_Helper* helper) const;
914 * Populate the Action_Level class with the the Id of the Hero
915 * Army unit, and also the Hero's stat that has been raised as a
916 * result of the level advancement.
918 //! Populate the action with pertinent data.
919 bool fillData(Army *unit, Army::Stat raised);
921 guint32 getArmyId() const {return d_army;};
922 guint32 getStatToIncrease() const {return d_stat;};
929 //-----------------------------------------------------------------------------
931 //! A temporary record of a Player changing the contents of a Signpost.
933 * The purpose of the Action_ModifySignpost is to record when a Signpost
934 * has been altered by a player to have a different message on it. The
935 * idea here is that we're playing on a hidden map and a Player wants to
936 * thwart an opponent by changing what signs say before he can read them.
938 class Action_ModifySignpost: public Action
941 //! Make a new change signpost action.
942 Action_ModifySignpost();
944 Action_ModifySignpost(const Action_ModifySignpost &action);
945 //! Load a new change signpost action from an opened saved-game file.
946 Action_ModifySignpost(XML_Helper* helper);
947 //! Destroy a change signpost action.
948 ~Action_ModifySignpost();
950 //! Return some debug information about this action.
951 std::string dump() const;
953 //! Save this change signpost action to an opened saved-game file.
954 virtual bool doSave(XML_Helper* helper) const;
956 //! Populate the action with the signpost and the new message.
957 bool fillData(Signpost * s, std::string message);
959 guint32 getSignpostId() const {return d_signpost;};
960 std::string getSignContents() const {return d_message;};
964 std::string d_message;
967 //-----------------------------------------------------------------------------
969 //! A temporary record of a Player changing the name of a City.
971 * The purpose of the Action_RenameCity class is to record when a Player has
972 * changed the name of a City. The idea here is that a Player wants
973 * to gloat by renaming a newly conquered City.
975 class Action_RenameCity: public Action
978 //! Make a new city rename action.
981 Action_RenameCity(const Action_RenameCity &action);
982 //! Load a new city rename action from an opened saved-game file.
983 Action_RenameCity(XML_Helper* helper);
984 //! Destroy a city rename action.
985 ~Action_RenameCity();
987 //! Return some debug information about this action.
988 std::string dump() const;
990 //! Save this city rename action to an opened saved-game file.
991 virtual bool doSave(XML_Helper* helper) const;
993 //! Populate the action with the city being renamed and the new name.
994 bool fillData(City *c, std::string name);
996 guint32 getCityId() const {return d_city;};
997 std::string getNewCityName() const {return d_name;};
1003 //-----------------------------------------------------------------------------
1005 //! A temporary record of a Player changing vectoring strategies for a City.
1007 * The purpose of the Action_Vector class is to record when a Player has
1008 * changed the vectoring policy of a City. The City's Army units can
1009 * be vectored to another City or to a Hero's planted standard (Item).
1010 * When units are vectored they take 2 turns to appear at their destination.
1011 * While the vectored units are en route, they are invisible.
1013 class Action_Vector: public Action
1016 //! Make a new city vector action.
1018 //! Copy constructor
1019 Action_Vector(const Action_Vector &action);
1020 //! Load a new city vector action from an opened saved-game file.
1021 Action_Vector(XML_Helper* helper);
1022 //! Destroy a city vector action.
1025 //! Return some debug information about this action.
1026 std::string dump() const;
1028 //! Save this city vector action to an opened saved-game file.
1029 virtual bool doSave(XML_Helper* helper) const;
1032 * Populate the Action_Vector class with the City being vectored
1033 * from, and the destination position for the vectored units.
1035 //! Populate the action with pertinent data.
1036 bool fillData(City* src, Vector <int> dest);
1038 guint32 getCityId() const {return d_city;};
1039 Vector<int> getVectoringDestination() const {return d_dest;};
1046 //-----------------------------------------------------------------------------
1048 //! A temporary record of a Player changing the fight order of an Armyset.
1050 * The purpose of the Action_FightOrder action is to record when a Player
1051 * changes the order in which Army units fight in battle.
1053 class Action_FightOrder: public Action
1056 //! Make a new fight order action.
1057 Action_FightOrder();
1058 //! Copy constructor
1059 Action_FightOrder(const Action_FightOrder &action);
1060 //! Load a new fight order action from an opened saved-game file.
1061 Action_FightOrder(XML_Helper* helper);
1062 //! Destroy a fight order action.
1063 ~Action_FightOrder();
1065 //! Return some debug information about this action.
1066 std::string dump() const;
1068 //! Save this fight order action to an opened saved-game file.
1069 virtual bool doSave(XML_Helper* helper) const;
1071 //! Populate the action with a list of ranks, one per Army unit type.
1072 bool fillData(std::list<guint32> order);
1074 std::list<guint32> getFightOrder() const {return d_order;};
1077 std::list<guint32> d_order;
1080 //-----------------------------------------------------------------------------
1082 //! A temporary record of a Player surrendering.
1084 * The purpose of the Action_Resign class is to record when a Player has
1085 * resigned from the game. Because these actions are held in a Player's
1086 * Actionlist, we do not have to store the player's Id.
1088 class Action_Resign: public Action
1091 //! Make a new player resignation action.
1093 //! Copy constructor
1094 Action_Resign(const Action_Resign &action);
1095 //! Load a new player resignation action from an opened saved-game file.
1096 Action_Resign(XML_Helper* helper);
1097 //! Destroy a player resignation action.
1100 //! Return some debug information about this action.
1101 std::string dump() const;
1103 //! Save this player resignation action to an opened saved-game file.
1104 virtual bool doSave(XML_Helper* helper) const;
1106 //! This method doesn't need to be called for Action_Resign actions.
1110 //-----------------------------------------------------------------------------
1112 //! A temporary record of a Hero planting a standard into the ground.
1114 * The purpose of the Action_Plant class is to record when a Hero has
1115 * planted a standard (e.g. a flag Item) into the ground, so that Army units
1116 * can be vectored there.
1118 class Action_Plant: public Action
1121 //! Make a new item planted action.
1123 //! Copy constructor
1124 Action_Plant(const Action_Plant &action);
1125 //! Load a new item planted action from an opened saved-game file.
1126 Action_Plant(XML_Helper* helper);
1127 //! Destroy a item planted action.
1130 //! Return some debug information about this action.
1131 std::string dump() const;
1133 //! Save this item planted action to an opened saved-game file.
1134 virtual bool doSave(XML_Helper* helper) const;
1136 //! Populate the action with the Id of the Hero and the Id of the Item.
1137 bool fillData(Hero *hero, Item *item);
1139 guint32 getHeroId() const {return d_hero;};
1140 guint32 getItemId() const {return d_item;};
1147 //-----------------------------------------------------------------------------
1149 //! A temporary record of a new Army unit showing up at a city.
1151 * The purpose of the Action_Produce class is to record when a new Army unit
1152 * is created. The idea here is that a City has produced a new Army unit.
1153 * The City might be vectoring elsewhere, so the unit doesn't show up in the
1154 * City that produced it. If vectoring is not enabled the Army unit shows
1155 * up right away in the host City.
1156 * This action is used primarily for reporting purposes. The player's
1157 * production report shows which army units were created in what cities.
1158 * The army unit is taken from the Player's Armyset.
1160 class Action_Produce: public Action
1163 //! Make a new unit produced action.
1165 //! Copy constructor
1166 Action_Produce(const Action_Produce &action);
1167 //! Load a new unit produced action from an opened saved-game file.
1168 Action_Produce(XML_Helper* helper);
1169 //! Destroy a unit produced action.
1172 //! Return some debug information about this action.
1173 std::string dump() const;
1175 //! Save this unit produced action to an opened saved-game file.
1176 virtual bool doSave(XML_Helper* helper) const;
1179 * Populate the Action_Produce action with the army type being
1180 * produced, the City in which it has arrived, and also whether
1181 * or not this unit was prevented from showing up here because
1182 * it is being vectored elsewhere.
1184 * pos is the vectored location if we're vectoring
1185 * or it's the position on the map where the newly produced army ended
1188 //! Populate the action with pertinent data.
1189 bool fillData(const ArmyProdBase *a, City *city, bool vectored, Vector<int> pos, guint32 army_id);
1191 //! Get the production details of the army that was produced.
1192 ArmyProdBase * getArmy() const {return d_army;}
1194 //! Get the Id of the City that produced the Army unit.
1195 guint32 getCityId() const {return d_city;}
1197 //! Get whether or not the Army unit is being vectored elsewhere.
1198 bool getVectored() const {return d_vectored;}
1200 //! Get where this army ends up on the map.
1201 Vector<int> getDestination() const {return d_dest;}
1203 //! Get the id of the army instance that was created.
1204 guint32 getArmyId() const {return d_army_id;}
1206 ArmyProdBase *d_army;
1212 bool load(std::string tag, XML_Helper *helper);
1216 //-----------------------------------------------------------------------------
1218 //! A temporary record of a vectored Army unit showing up at a city.
1220 * The purpose of the Action_ProduceVectored class is to record when a new
1221 * vectored Army unit arrives at it's destination. The idea here is that
1222 * two turns have passed since a unit was vectored, and now the unit has
1224 * This action is used primarily for reporting purposes. The player's
1225 * production report shows which vectored army units arrived in what cities.
1226 * The army unit is taken from the Player's Armyset.
1228 class Action_ProduceVectored: public Action
1231 //! Make a new vector arrival action.
1232 Action_ProduceVectored();
1233 //! Copy constructor
1234 Action_ProduceVectored(const Action_ProduceVectored &action);
1235 //! Load a new vector arrival action from an opened saved-game file.
1236 Action_ProduceVectored(XML_Helper* helper);
1237 //! Destroy a vector arrival action.
1238 ~Action_ProduceVectored();
1240 //! Return some debug information about this action.
1241 std::string dump() const;
1243 //! Save this vector arrival action to an opened saved-game file.
1244 virtual bool doSave(XML_Helper* helper) const;
1247 * Populate the Action_ProduceVectored with the Id of the army
1248 * unit type being produced, and the position on the map where
1249 * it has showing up.
1251 //! Populate the action with pertinent data.
1252 bool fillData(ArmyProdBase *army, Vector <int> dest, Vector<int> src);
1254 //! Get the army type Id that has shown up.
1255 ArmyProdBase *getArmy() const {return d_army;};
1257 //! Get the position on the map where the army showed up.
1258 Vector<int> getDestination() const {return d_dest;}
1260 //! Get the position on the map where the army is coming from.
1261 Vector<int> getOrigination() const {return d_src;}
1263 ArmyProdBase *d_army;
1266 bool load(std::string tag, XML_Helper *helper);
1269 //-----------------------------------------------------------------------------
1271 //! A temporary record of the diplomatic state changing.
1273 * The purpose of the Action_DiplomacyState action is to record our
1274 * diplomatic state with other players has it changes. The idea here is
1275 * that every player has a diplomatic status with every other player.
1276 * Although we might propose war on a given turn, we would achieve the
1277 * state of being at war on a later turn.
1279 class Action_DiplomacyState: public Action
1282 //! Make a new diplomatic state action.
1283 Action_DiplomacyState();
1284 //! Copy constructor
1285 Action_DiplomacyState(const Action_DiplomacyState &action);
1286 //! Load a new diplomatic state action from an opened saved-game file.
1287 Action_DiplomacyState(XML_Helper* helper);
1288 //! Destroy a diplomatic state action.
1289 ~Action_DiplomacyState();
1291 //! Return some debug information about this action.
1292 std::string dump() const;
1294 //! Save this diplomatic state action to an opened saved-game file.
1295 virtual bool doSave(XML_Helper* helper) const;
1298 * Populate the Action_DiplomacyState class with the Player for
1299 * which we are in a state with. Also populate the action with
1300 * the new diplomatic state.
1302 //! Populate action with pertinent data.
1303 bool fillData(Player *player, Player::DiplomaticState state);
1305 //! Get the Id of the Player that we have entered a new state for.
1306 guint32 getOpponentId() const {return d_opponent_id;}
1308 //! Get the state that we're in with the other Player.
1309 Player::DiplomaticState getDiplomaticState() const
1310 {return d_diplomatic_state;};
1312 guint32 d_opponent_id;
1313 Player::DiplomaticState d_diplomatic_state;
1316 //-----------------------------------------------------------------------------
1318 //! A temporary record of a diplomatic proposal.
1320 * The purpose of the Action_DiplomacyProposal action is to record our
1321 * diplomatic proposals to other players. The idea here is that the player
1322 * wishes to go to war with another Player and so offers/proposes war to a
1323 * prospective enemy.
1325 class Action_DiplomacyProposal: public Action
1328 //! Make a new diplomatic proposal action.
1329 Action_DiplomacyProposal();
1330 //! Copy constructor
1331 Action_DiplomacyProposal(const Action_DiplomacyProposal &action);
1332 //! Load a new diplomatic proposal action from a saved-game file.
1333 Action_DiplomacyProposal(XML_Helper* helper);
1334 //! Destroy a diplomatic proposal action.
1335 ~Action_DiplomacyProposal();
1337 //! Return some debug information about this action.
1338 std::string dump() const;
1340 //! Save this diplomatic proposal action to an opened saved-game file.
1341 virtual bool doSave(XML_Helper* helper) const;
1344 * Populate the Action_DiplomacyProposal class with the Player for
1345 * which we have a new proposal for. Also populate the action with
1346 * the new diplomatic proposal.
1348 //! Populate action with pertinent data.
1349 bool fillData(Player *player, Player::DiplomaticProposal proposal);
1351 //! Get the Id of the Player that our proposal is for.
1352 guint32 getOpponentId() const {return d_opponent_id;}
1354 //! Get the proposal that we're offering.
1355 Player::DiplomaticProposal getDiplomaticProposal() const
1356 {return d_diplomatic_proposal;};
1358 guint32 d_opponent_id;
1359 Player::DiplomaticProposal d_diplomatic_proposal;
1362 //-----------------------------------------------------------------------------
1364 //! A temporary record of the diplomatic score.
1366 * The purpose of the Action_DiplomacyScore is to record when a Player's
1367 * diplomatic opinion of another Player has changed. The idea here is that
1368 * an enemy player has razed a city and now our opinion of that player
1371 class Action_DiplomacyScore: public Action
1374 //! Make a new diplomatic score action.
1375 Action_DiplomacyScore();
1376 //! Copy constructor.
1377 Action_DiplomacyScore(const Action_DiplomacyScore &action);
1378 //! Load a new diplomatic score action from an opened saved-game file.
1379 Action_DiplomacyScore(XML_Helper* helper);
1380 //! Destroy a diplomatic score action.
1381 ~Action_DiplomacyScore();
1383 //! Return some debug information about this action.
1384 std::string dump() const;
1386 //! Save this diplomatic score action to an opened saved-game file.
1387 virtual bool doSave(XML_Helper* helper) const;
1390 * Populate the Action_DiplomacyScore class with the Player for
1391 * which we have changed our opinion of. Also populate the action
1392 * with the amount of change for that Player. The change can be
1393 * negative, and is added to the existing score to get the new
1396 //! Populate action with pertinent data.
1397 bool fillData(Player *player, int amount);
1399 //! Get the Id of the Player that our opinion has changed of.
1400 guint32 getOpponentId() const {return d_opponent_id;}
1402 //! Get the amount of the opinion change.
1403 int getAmountChange() const {return d_amount;};
1405 guint32 d_opponent_id;
1409 //-----------------------------------------------------------------------------
1411 class Action_EndTurn: public Action
1414 //! Make a new end turn action.
1416 //! Copy constructor
1417 Action_EndTurn(const Action_EndTurn &action);
1418 //! Load a new end turn action from an opened saved-game file.
1419 Action_EndTurn(XML_Helper* helper);
1420 //! Destroy a end turn action.
1423 //! Return some debug information about this action.
1424 std::string dump() const;
1426 //! Save this action to an opened saved-game file.
1427 virtual bool doSave(XML_Helper* helper) const;
1430 //-----------------------------------------------------------------------------
1432 class Action_ConquerCity : public Action
1435 //! Make a new city conquer action.
1436 Action_ConquerCity();
1437 //! Copy constructor
1438 Action_ConquerCity(const Action_ConquerCity &action);
1439 //! Load a new city conquer action from an opened saved-game file.
1440 Action_ConquerCity(XML_Helper* helper);
1441 //! Destroy a city conquer action.
1442 ~Action_ConquerCity();
1444 //! Return some debug information about this action.
1445 std::string dump() const;
1447 //! Save this city occupied action to an opened saved-game file.
1448 virtual bool doSave(XML_Helper* helper) const;
1450 //! Populate the action with the City being conquered.
1451 bool fillData (City* c, Stack *s);
1453 guint32 getCityId() const {return d_city;};
1454 guint32 getStackId() const {return d_stack;};
1456 guint32 d_city, d_stack;
1459 //-----------------------------------------------------------------------------
1461 class Action_RecruitHero : public Action
1464 //! Make a new recruit hero action.
1465 Action_RecruitHero();
1466 //! Copy a new recruit hero action
1467 Action_RecruitHero(const Action_RecruitHero &action);
1468 //! Load a new recruit hero action from an opened saved-game file.
1469 Action_RecruitHero(XML_Helper* helper);
1470 //! Destroy a recruit hero action.
1471 ~Action_RecruitHero();
1473 //! Return some debug information about this action.
1474 std::string dump() const;
1476 //! Save this city occupied action to an opened saved-game file.
1477 virtual bool doSave(XML_Helper* helper) const;
1479 //! Populate the action.
1480 bool fillData(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
1482 HeroProto* getHero() const {return d_hero;};
1483 guint32 getCityId() const {return d_city;};
1484 guint32 getCost() const {return d_cost;};
1485 guint32 getNumAllies() const {return d_allies;};
1486 guint32 getAllyArmyType() const {return d_ally_army_type;};
1490 guint32 d_city, d_cost, d_allies, d_ally_army_type;
1492 bool load(std::string tag, XML_Helper *helper);
1495 //-----------------------------------------------------------------------------
1497 class Action_RenamePlayer: public Action
1500 //! Make a new rename player action
1501 Action_RenamePlayer();
1502 //! Copy constructor
1503 Action_RenamePlayer(const Action_RenamePlayer &action);
1504 //! Load a new rename player action from an opened saved-game file.
1505 Action_RenamePlayer(XML_Helper* helper);
1506 //! Destroy a rename player action.
1507 ~Action_RenamePlayer();
1509 //! Return some debug information about this action.
1510 std::string dump() const;
1512 //! Save this city occupied action to an opened saved-game file.
1513 virtual bool doSave(XML_Helper* helper) const;
1515 //! Populate the action.
1516 bool fillData(std::string name);
1518 std::string getName() const {return d_name;};
1524 //-----------------------------------------------------------------------------
1526 class Action_CityTooPoorToProduce: public Action
1529 //! Make a new city-too-poor action
1530 Action_CityTooPoorToProduce();
1531 //! Copy constructor
1532 Action_CityTooPoorToProduce(const Action_CityTooPoorToProduce &action);
1533 //! Load a new too-poor action from an opened saved-game file.
1534 Action_CityTooPoorToProduce(XML_Helper* helper);
1535 //! Destroy a too-poor action.
1536 ~Action_CityTooPoorToProduce();
1538 //! Return some debug information about this action.
1539 std::string dump() const;
1541 //! Save this city occupied action to an opened saved-game file.
1542 virtual bool doSave(XML_Helper* helper) const;
1544 //! Populate the action.
1545 bool fillData(City *city, const ArmyProdBase *army);
1547 guint32 getCityId() const {return d_city;}
1548 guint32 getArmyType() const {return d_army_type;}
1552 guint32 d_army_type;
1555 //-----------------------------------------------------------------------------
1557 class Action_InitTurn: public Action
1560 //! Make a new initialize turn action.
1562 //! Copy constructor
1563 Action_InitTurn(const Action_InitTurn &action);
1564 //! Load a new initialize turn action from an opened saved-game file.
1565 Action_InitTurn(XML_Helper* helper);
1566 //! Destroy a initialize turn action.
1569 //! Return some debug information about this action.
1570 std::string dump() const;
1572 //! Save this action to an opened saved-game file.
1573 virtual bool doSave(XML_Helper* helper) const;
1576 //-----------------------------------------------------------------------------
1578 //! A temporary record of what happened when a Player loots a City.
1580 * The purpose of the Action_Loot class is to record when a Player has
1581 * defeated a City and has looted it. Looting a city results in the
1582 * looting player's coffers gaining some gold pieces while the looted
1583 * player's coffers decrease.
1585 class Action_Loot : public Action
1588 //! Make a new city looting action.
1590 //! Copy constructor
1591 Action_Loot(const Action_Loot &action);
1592 //! Load a new city looting action from an opened saved-game file.
1593 Action_Loot(XML_Helper* helper);
1594 //! Destroy a city looting action.
1597 //! Return some debug information about this action.
1598 std::string dump() const;
1600 //! Save this city looting action to an opened saved-game file.
1601 virtual bool doSave(XML_Helper* helper) const;
1603 //! Populate the action with the players involved and the amounts.
1604 bool fillData(Player *looter, Player *looted, guint32 amount_to_add,
1605 guint32 amount_to_subtract);
1607 guint32 getAmountToAdd() const { return d_gold_added;};
1608 guint32 getAmountToSubtract() const { return d_gold_removed;};
1609 guint32 getLootingPlayerId() const {return d_looting_player_id;};
1610 guint32 getLootedPlayerId() const {return d_looted_player_id;};
1613 guint32 d_looting_player_id;
1614 guint32 d_looted_player_id;
1615 guint32 d_gold_added;
1616 guint32 d_gold_removed;