1 // Copyright (C) 2000, 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2003 Marek Publicewicz
4 // Copyright (C) 2004 John Farrell
5 // Copyright (C) 2005 Bryan Duff
6 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
7 // Copyright (C) 2007, 2008 Ole Laursen
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 3 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU Library General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include <sigc++/trackable.h>
31 #include <sigc++/signal.h>
38 #include "callback-enums.h"
65 //! The abstract player class.
67 * This class does not yet implement an actual player type. Its purpose is to
68 * provide an abstract class design which every player implementation has to
69 * fulfill. Of each player class we demand the following functionality:
71 * 1. functions for _every_ action a player can do
72 * 2. some kind of callback functions if the player has a choice (e.g. if he has
73 * conquered a city, he may choose between razing, pillaging and occupying)
74 * 3. signals which are raised whenever something important happens
75 * 4. an actionlist which keeps track of _everything_ a player has done
77 * The fourth point allows us an easy network playing scheme. After a player
78 * has finished, all he has to do is sending his actionlist to the over network
79 * players. Since every item which the player can touch/kill etc. (cities,
80 * armies, ruins,...) has a unique id, the remote game instances can then
81 * simply apply these action lists to their own situation.
83 * The third point allows us to dock other classes to every possible event. One
84 * example are ruin searching quests which must be informed whenever any
85 * player searches a ruin. Or the bigmap can be informed when a stack moves,
86 * so that it may update its contents.
88 * The second item allows an easy coexistence of AI and human players.
89 * Basically, an AI player just follows some kind of routine while a human
90 * player uses gui interaction. However, this becomes a bit problematic
91 * whenever the player may decide something. One solution is providing
92 * callbacks for these cases. The human player then opens a dialog somehow
93 * while the AI player overwrites the default behaviour.
95 * The first point makes a nice derivation scheme possible. It is possible to
96 * divide the player types into a local player, who implements all these
97 * functions and a networked player. The latter one simply overwrites these
98 * functions so that the game status is updated for each item of the actionlist
99 * he has been sent. Furthermore, with a local player having been implemented,
100 * it is extremely easy to write an AI player. All you have to do is overwrite
101 * the startTurn function with your own code. For every action you already know
102 * there is an implementation in a superior class which takes off the burden
103 * for the actual work.
106 * Finally, the current derivation scheme is as follows:
107 * RealPlayer derives from Player.
108 * NetworkPlayer derives from Player.
109 * AI_Fast, AI_Dummy, and AI_Smart derive from RealPlayer.
111 * The Ids of players are very specific. The first player (the White player)
112 * must have the Id of 0, the next player (Green) must have the Id of 1, and
113 * so on. The Neutral player must have the final player Id.
114 * If the White player is not in the scenario, then the Id 0 must be skipped.
115 * There can only be MAX_PLAYERS players in total.
118 class Player: public sigc::trackable
121 //! The xml tag of this object in a saved-game file.
122 static std::string d_tag;
124 //! The available player types.
126 //! Local human player. See the RealPlayer class.
128 //! Local computer player (Easy). See the AI_Fast class.
130 //! Local computer player (Neutral). See the AI_Dummy class.
132 //! Local computer player (Hard). See the AI_Smart class.
134 //! Remote player. See the NetworkPlayer class.
138 //! Every player has a diplomatic state with every other player.
139 enum DiplomaticState {
140 //! Can't attack opponent's stacks anywhere.
142 //! Can't attack opponent's stacks in cities.
144 //! Can attack opponent's stack everywhere.
148 //! Every player has a diplomatic proposal to every other player.
149 enum DiplomaticProposal {
150 //! Offer to keep the status-quo with the opponent.
152 //! Offer peace to an opponent.
154 //! Offer limited war to an opponent (only kill stacks in the field).
155 PROPOSE_WAR_IN_FIELD = 2,
156 //! Offer all-out war to an opponent.
162 * @note AI_Fast, AI_Dummy, AI_Smart and RealPlayer use this
163 * constructor to make new Players.
165 * @param name The name of the player.
166 * @param armyset The Id of the player's Armyset.
167 * @param color The player's colour.
168 * @param width The width of the player's FogMap.
169 * @param height The height of the player's FogMap.
170 * @param type The kind of player (Player::Type).
171 * @param player_no The Id of the player. If this value is -1,
172 * the next free Id it used.
174 //! Default constructor.
175 Player (std::string name, guint32 armyset, Gdk::Color color, int width,
176 int height, Type type, int player_no = -1);
178 //! Copy constructor.
179 Player(const Player&);
181 //! Constructor for loading. See XML_Helper for documentation.
182 Player(XML_Helper* helper);
190 //! Change the player's name.
191 void setName(std::string name){d_name = name;}
193 //! Change the player's Armyset.
194 void setArmyset(guint32 armyset){d_armyset = armyset;}
196 //! Set the type of the player (to be used by derived classes only.)
197 void setType(Type type) {d_type = type;}
199 //! Change the player's colour.
200 void setColor(Gdk::Color c);
202 //! Makes a player unable to die, even when having no units or cities.
203 void setMortality(bool ismortal) {d_immortal = !ismortal;}
205 //! Change the number of gold pieces of the player has.
206 void setGold(int gold){d_gold = gold;}
208 //! Set this player's rank in diplomatic matters. Starts at 1.
209 void setDiplomaticRank (guint32 rank) {d_diplomatic_rank = rank;};
211 //! Set the rank as a name.
212 void setDiplomaticTitle (std::string title) {d_diplomatic_title = title;};
213 //! Set if this player will be seen as it moves through visible terrain.
214 void setObservable(bool observable) {d_observable = observable;};
216 //! Revive the player, this does not provide any cities.
217 void revive() {d_dead = false;}
219 //! Set whether or not this player has surrendered.
221 * computer players may surrender to a lone human player who has most
222 * of the cities on the board.
223 * this method merely sets the surrendered member so that we can
224 * quit properly. e.g. it triggers the aborted_Turn signal to be fired
225 * at a different time in fast, smart and dummy players.
227 void setSurrendered(bool surr);
229 //! Set the fight order of the player.
230 void setFightOrder(std::list<guint32> order);
236 //! Returns whether or not this is a computer player.
237 virtual bool isComputer() const = 0;
239 //! Returns the unique ID of the player.
240 guint32 getId() const {return d_id;}
242 //! Returns the list of player's events.
243 std::list<History*>* getHistorylist() {return &d_history;}
245 //! Return the Id of the player's Armyset.
246 guint32 getArmyset() const {return d_armyset;}
248 //! Return whether or not the player has been killed.
249 bool isDead() const {return d_dead;}
251 //! Returns whether a player is immortal or not.
252 bool isImmortal() const {return d_immortal;}
254 //! Return the type of the player (Player::Type).
255 guint32 getType() const {return d_type;}
258 * Return the amount of upkeep in gold pieces that the player spent
259 * in the previous turn.
261 //! Return the upkeep.
262 guint32 getUpkeep() const {return d_upkeep;}
264 //! Return the income from all of the player's cities.
265 guint32 getIncome () const {return d_income;}
267 //! What diplomatic rank does this player have? Starts at 1.
268 guint32 getDiplomaticRank () const {return d_diplomatic_rank;};
270 //! What rank do we have? As a name.
271 std::string getDiplomaticTitle() const {return d_diplomatic_title;};
273 //! Returns the colour of the player.
274 Gdk::Color getColor() const {return d_color;}
276 //! Returns the amount of gold pieces the player has in the treasury.
277 int getGold() const {return d_gold;}
279 //! Returns the name of the player.
280 std::string getName(bool translate = true) const;
282 //! Returns the player's current score.
283 guint32 getScore() const;
285 //! Returns the list of stacks owned by the player.
286 Stacklist* getStacklist() const {return d_stacklist;}
288 //! Get the FogMap of the player.
289 FogMap* getFogMap() const {return d_fogmap;}
291 //! Get the Triumphs of the player.
292 Triumphs* getTriumphs() const {return d_triumphs;}
294 //! Get the fight order of the player.
295 std::list<guint32> getFightOrder() const {return d_fight_order;}
297 bool isObservable() const {return d_observable;};
299 bool abortRequested() const {return abort_requested;};
301 // Methods that operate on the player's action list.
303 //! Returns a list of the players unit production actions for this turn.
304 std::list<Action_Produce *> getUnitsProducedThisTurn() const;
306 //! Return the amount of gold pieces for the newly produced armies.
307 guint32 getCostOfUnitsProducedThisTurn() const;
309 //! Returns a list of the player's actions to show in a report.
310 std::list<Action *> getReportableActions() const;
312 //! Returns the number of times we fought so far this turn.
313 int countFightsThisTurn() const;
314 //! Returns the number of times we moved a stack this turn.
315 int countMovesThisTurn() const;
316 //! Returns number of cities that were too poor to produce this turn.
317 int countDestituteCitiesThisTurn() const;
319 //! Returns the battle actions for this turn.
320 std::list<Action *> getFightsThisTurn() const;
321 //! Returns the movement actions for this turn.
322 std::list<Action *> getMovesThisTurn() const;
324 //! Remove every Action from the list of the player's actions.
325 void clearActionlist();
327 //! Show debugging information for the player's Action list.
328 void dumpActionlist() const;
330 //! Wrap the player's actions for transport over the network.
331 void saveNetworkActions(XML_Helper *helper) const;
333 //! Check to see if it's our turn.
334 bool hasAlreadyInitializedTurn() const;
336 //! Check to see if we've ended our turn this round.
337 bool hasAlreadyEndedTurn() const;
339 //! Return the movement history of a given stack for this turn.
340 std::list<Vector<int> > getStackTrack(Stack *s) const;
343 // Methods that operate on the player's history list.
345 //! Remove every History element from the list of the player's events.
346 void clearHistorylist();
348 //! Show debugging information for the player's History list.
349 void dumpHistorylist() const;
351 //! Check the player's history to see if we've conquered the given city.
352 bool conqueredCity(City *c) const;
354 //! Check the player's history to see if we've explored the given ruin.
355 bool searchedRuin(Ruin *r) const;
357 //! Return a list of history events for the given hero.
358 std::list<History *> getHistoryForHeroId(guint32 id) const;
360 //! Return a list of history events for the given city.
361 std::list<History *> getHistoryForCityId(guint32 id) const;
363 //! Count the turns we've completed.
364 guint32 countEndTurnHistoryEntries() const;
366 //! Add a new history item to the player's history list.
367 void addHistory(History *history);
370 // Methods that operate on the player's stacklist
372 //! Return a list of the player's heroes.
373 std::list<Hero*> getHeroes() const;
375 //! Return the grand total of the player's armies.
376 guint32 countArmies() const;
378 //! Return the number of the player's armies that are awardable.
379 guint32 countAllies() const;
381 //! Return the player's currently selected stack.
382 Stack * getActivestack() const;
384 //! Select this stack.
385 void setActivestack(Stack *);
387 //! Return the position on the map for the given army unit.
388 Vector<int> getPositionOfArmyById(guint32 id) const;
390 //! Remove movement points from all of the player's army units.
393 //! Remove all stacks from the player's list.
394 void clearStacklist();
396 //! Add a Stack to the player's Stacklist.
397 void addStack(Stack* stack);
399 //! Remove a Stack from the player's Stacklist.
400 bool deleteStack(Stack* stack);
403 // Methods that operate on the player's diplomatic data members.
405 //! Query the diplomatic state this player has with an opponent.
406 DiplomaticState getDiplomaticState (Player *player) const;
408 //! Query the diplomatic proposal we're making to an opponent.
409 DiplomaticProposal getDiplomaticProposal (Player *player) const;
411 //! Get the diplomatic score with respect to an opponent.
412 guint32 getDiplomaticScore (Player *p) const;
415 void adjustDiplomacyFromConqueringCity(City *city);
419 //! Add some gold pieces to the player's treasury.
420 void addGold(int gold);
422 //! Subtract gold pieces from the player's treasury.
423 void withdrawGold(int gold);
426 * Perform a summation of the upkeep value for every Army in the
427 * player's Stacklist. This method sets d_upkeep.
428 * The upkeep value is in gold pieces.
430 //! Calculates the upkeep.
431 void calculateUpkeep();
434 * Perform a summation of the income value for every City in the
435 * player's Citylist. This method sets d_income.
436 * The income value is in gold pieces.
438 //! Calculates the upkeep.
439 void calculateIncome();
442 //! Remove all fog from the player's map.
447 * Saves the player data to a file.
449 * @param helper The opened saved-game file to write to.
451 * @note This function only saves basic data, it doesn't open/close the
452 * player tags, this has to be done by the derived methods in
453 * RealPlayer, AI_Fast, AI_Smart and AI_Dummy.
455 //! Save the player to a saved-game file.
456 virtual bool save(XML_Helper* helper) const;
461 * Called to merge two stacks into one.
463 * This callback must result in an Action_Join element being
464 * given to the addAction method.
466 * @param receiver The receiving stack.
467 * @param joining The joining stack, destroyed after the join.
469 * @return False if an error occured, else true.
471 //! Callback to merge two stacks into one.
472 bool stackJoin(Stack* receiver, Stack* joining);
475 * Called to change the position of a Stack on the map.
476 * The new position is dictated by the last point of the Path of the
477 * Stack. This method can trigger many other actions.
479 * This callback must result in an Action_Move element being
480 * given to the addAction method.
482 * @param s The stack to be moved.
484 * @return False if an error occured, else true.
486 //! Callback to move a stack on the map.
487 bool stackMove(Stack* s);
488 MoveResult* stackMove(Stack* s, Vector<int> dest);
490 //! Callback to take the armies from the stack that have at least
491 //! enough moves to reach the end of the stack's path.
492 bool stackSplitAndMove(Stack* s, Stack *& new_stack);
493 bool stackSplitAndMoveToAttack(Stack* s, Stack *& new_stack);
494 bool stackSplitAndMoveToJoin(Stack* s, Stack *join, Stack *& new_stack);
497 * Called to adjudicate a fight between two lists of stacks.
499 * Note that all stacks next to the defending stack also take part in
500 * the fight, if they belong either to the attacker's side or to the
501 * defender. If the attacker or the defender die in the course of
502 * events, the pointers are set to 0.
504 * This callback must result in an Action_Fight element being
505 * given to the addAction method.
507 * @param attacker The list of attacking stacks.
508 * @param defender The list of defending stacks.
510 * @return One of Fight::ATTACKER_WON, Fight::DEFENDER_WON, or
511 * Fight::DRAW (Fight::Result).
513 //! Callback to adjudicate fights.
514 Fight::Result stackFight(Stack** attacker, Stack** defender);
517 * Called to adjudicate a fight between two lists of stacks in a ruin.
519 * @param attacker The list of attacking stacks. This list
520 * consists of a single Stack containing at
521 * least one Hero unit.
522 * @param defender The list of defending stacks. This list
523 * consists of a single Army unit in a
526 * If the defender dies in the fight, the defender pointer is set
528 * If the Hero loses the battle, only the Hero unit is removed
529 * from the attacker's stack.
531 * @return One of Fight::ATTACKER_WON, Fight::DEFENDER_WON, or
532 * Fight::DRAW (Fight::Result).
534 //! Callback to adjudicate fights in ruins.
535 Fight::Result stackRuinFight(Stack** attacker, Stack** defender);
537 * A stack searches a ruin. The stack must contain a hero.
539 * This callback must result in an Action_Ruin element being
540 * given to the addAction method.
542 * @param stack The stack which searches the ruin.
543 * @param ruin The ruin to be searched.
545 * @return reward A pointer to the received Reward. Return
546 * NULL if the keeper could not be defeated.
548 //! Callback to have a stack visit a ruin.
549 Reward* stackSearchRuin(Stack* stack, Ruin* ruin);
552 * A stack visits a temple and becomes blessed. By blessing, the
553 * strength of all armies rises by 1.
555 * This callback must result in an Action_Temple element being
556 * given to the addAction method.
558 * @param stack The stack visiting the temple.
559 * @param temple The visited temple.
561 * @return The number of blessed armies.
563 //! Callback to have a stack visit a temple.
564 int stackVisitTemple(Stack* stack, Temple* temple);
567 * Called to ask the military advisor about what would happen
568 * if the stack attacked the tile.
570 * @param stack The stack to attack with.
571 * @param tile The tile to attack (could be a city, or a stack).
572 * @param intense_combat If the intense combat game option is on or
575 * @return The percent chance to win the fight. The maximum value
576 * is 100.0, and the minimum value is 0.0.
578 //! Callback to calculate the odds of winning a fight.
579 float stackFightAdvise(Stack* stack, Vector<int> tile,
580 bool intense_combat);
583 * Disbanding a player's stack removes it from the game. Disbanding
584 * stacks saves upkeep for unwanted Army units.
586 * This callback must result in an Action_Disband element being
587 * given to the addAction method.
589 * @param stack The stack to disband.
591 * @return False on error, true otherwise.
593 //! Callback to disband a player's stack.
594 bool stackDisband(Stack* stack);
597 * Modifying a signpost entails changing the message on the sign.
598 * When playing in a hidden map, the hope is that we change the
599 * message on the sign before an opponent can read it.
601 * For this callback to make sense, you should only change
602 * Signposts for which we have a Stack co-located.
604 * This callback must result in a Action_ModifySignpost element being
605 * given to the addAction method.
607 * @param signpost The signpost to modify.
608 * @param message The new text to inscribe onto the sign.
610 * @return False on error, true otherwise.
612 //! Change the text on a signpost.
613 bool signpostChange(Signpost *signpost, std::string message);
618 // Hero related actions the player can take.
621 * Callback to plant the Player's flag Item on the ground.
622 * Planting a standard entails taking the Item out of the Hero's
623 * backpack and putting it on the ground so that Army units can
624 * be vectored to that location.
626 * Computer players don't currently consider vectoring units, so
627 * only human players use this method.
629 * This callback must result in an Action_Plant element being added
630 * to the player's Action list (Player::d_actions).
632 * @param stack The Stack that contains the Hero who is holding
633 * the plantable Item. Every player has exactly one
634 * plantable Item. The item is planted at the
635 * position of the Stack on the map.
637 * @return False on error, true otherwise.
639 //! Callback to plant a player's standard.
640 bool heroPlantStandard(Stack *stack);
643 * Callback to drop an item at a particular position on the game map.
644 * The item is removed from the Hero's backback and placed in a bag
645 * at place on the map.
647 * For this method to make sense, the Hero should be in a Stack
648 * that is co-located with the drop position. E.g. Heroes should
651 * This callback must result in an Action_Equip element being
652 * given to the addAction method.
654 * @param hero The Hero that holds the item.
655 * @param item The Item to drop onto the ground.
656 * @param pos The position of the tile on the game map to
657 * drop the item onto.
659 * @return False on error, true otherwise.
661 //! Callback to have a Hero drop an Item.
662 bool heroDropItem(Hero *hero, Item *item, Vector<int> pos);
665 * Callback to drop a all items at a particular position on the
666 * game map. All items in the Hero's backback are removed and placed
667 * into a bag at place on the map.
669 * For this method to make sense, the Hero should be in a Stack
670 * that is co-located with the drop position. E.g. Heroes should
673 * This callback must result in one or more Action_Equip elements
674 * being given to the addAction method.
676 * @param hero The Hero that holds the items.
677 * @param pos The position of the tile on the game map to
678 * drop the item onto.
680 * @return False on error, true otherwise.
682 //! Callback to have a Hero drop all items.
683 bool heroDropAllItems(Hero *hero, Vector<int> pos);
686 * Callback to pickup an Item at a particular position on the game
687 * map. The item is removed from a tile on the game map, and placed
688 * into the Hero's backback.
690 * For this method to make sense, the Hero should be in a Stack
691 * that is co-located with the pickup position. E.g. Heroes should
692 * pickup items from the tile they are on.
694 * This callback must result in an Action_Equip element being
695 * given to the addAction method.
697 * @param hero The Hero that holds the item.
698 * @param item The Item to pickup off of the ground.
699 * @param pos The position of the tile on the game map to
700 * pickup the item from.
702 * @return False on error, true otherwise.
704 //! Callback to have a Hero pick up an Item.
705 bool heroPickupItem(Hero *hero, Item *item, Vector<int> pos);
707 //! Pick up all of the items at the given location on the game map.
708 bool heroPickupAllItems(Hero *h, Vector<int> pos);
711 * Completing a Quest entails that the Hero is going to receive a
712 * reward, but that happens in Player::giveReward.
713 * The QuestsManager class handles removal of expired or completed
715 * This callback doesn't do much except record the event for
716 * posterity (see HistoryReportDialog).
718 * This callback must result in a History_QuestCompleted element being
719 * added to the player's History list (Player::d_history).
721 * @param hero The Hero completing the Quest.
723 * @return False on error, true otherwise.
725 //! Callback to have a Hero complete a quest.
726 bool heroCompletesQuest(Hero *hero);
729 * A hero visits a temple and receives a Quest from the temple's
730 * priests. If there is more than one hero in the stack, the quest is
731 * assigned to the first hero without a quest.
733 * This callback must result in an Action_Quest element being
734 * given to the addAction method.
735 * This callback must result in a History_QuestStarted element being
736 * added to the player's History list (Player::d_history).
738 * @param hero The visiting hero.
739 * @param temple The visited temple.
740 * @param except_raze Don't give out a raze quest because it's
741 * impossible to raze a city in this
744 * @return The newly assigned Quest or 0 on error.
746 //! Callback to have a Hero get a new Quest from a temple.
747 Quest* heroGetQuest(Hero *hero, Temple* temple, bool except_raze);
750 * Called whenever a hero emerges in a city
752 * @param hero The hero who has offered his or her service.
753 * @param city The city where the hero is emerging.
754 * @param cost The amount of gold pieces neccessary to recruit
757 * @note Only change the name and gender attributes of the Hero.
759 void recruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
762 * Called whenever a hero advances a level.
763 * For human players this method presents a dialog that allows the
764 * user to select an Army::STAT to improve (HP, MOVES, or SIGHT if
765 * a hidden map is in use). For computer players this method is
766 * used to decide which stat should be improved.
768 * This callback must result in an Action_Level element being
769 * given to the addAction method.
771 * @param army The army to raise (is always a Hero.)
773 //! Callback to advance an Army's level.
774 virtual void heroGainsLevel(Hero * a) = 0;
782 // City related actions the player can take.
785 * Callback to have a Player rename a City.
787 * Only human players currently rename cities; computer players
788 * do not consider doing so.
790 * This callback must result in a Action_RenameCity element being
791 * given to the addAction method.
793 * @param city The city to change the name of.
794 * @param name The new name of the city.
796 * @return False on error, true otherwise.
798 //! Callback to rename a city.
799 bool cityRename(City *city, std::string name);
802 * Callback to initiate vectoring new units from a player's City to
803 * a destination point on the game map.
805 * Computer players don't currently consider vectoring units, so
806 * only human players use this method.
808 * This callback must result in a Action_Vector element being
809 * given to the addAction method.
811 * @param city The city to vector from.
812 * @param dest The place on the map to vector the produced Army
813 * units to. If the destination is -1,-1 it means
814 * to stop vectoring altogether. The destination
815 * point should be co-located with a City or a
816 * planted standard Item.
818 * @return False on error, true otherwise.
820 //! Callback to vector produced units from a city.
821 bool vectorFromCity(City* city, Vector<int> dest);
824 * Callback to change the vectoring destination for all of the
825 * player's cities that are vectoring to a particular city.
827 * SRC and DEST can both be the player's planted standard.
829 * @param src The place that we want to take all the vectoring from.
830 * @param dest The place on the map to vector to. The destination
831 * point should be co-located with a City or a
832 * planted standard Item.
834 * @return False on error, true otherwise.
836 //! Callback to make a mass change to vectoring.
837 bool changeVectorDestination(Vector<int> src, Vector<int> dest);
840 * Callback to have the active player occupy a given city.
841 * The player has defeated a City and now it has been decided
842 * that the player wishes to occupy this city. The decision
843 * happens in Player::invadeCity. Occupying means that the city
844 * becomes owned by the ocuppying player.
846 * This callback must result in an Action_Occupy element being
847 * given to the addAction method.
849 * @param city The occupied city.
851 * @return False on error, true otherwise.
853 //! Callback to occupy a city.
854 void cityOccupy(City* city);
857 * Pillage a city (trade in the best army type and get some gold.)
858 * The player has defeated a City and now it has been decided
859 * that the player wishes to pillage this city. The decision to
860 * pillage happened in Player::invadeCity. Pillaging means that the
861 * city becomes owned by the pillaging player, and that the strongest
862 * Army unit type that the city can produce is traded-in for an
863 * amount of gold pieces.
865 * This callback must result in an Action_Pillage element being
866 * given to the addAction method.
868 * @param city The city to be pillaged.
869 * @param gold Returns the amount of gold pillaged.
870 * @param pillaged_army_type The army type that is cashed in for gold.
872 * @return False on error, true otherwise.
874 //! Callback to pillage a city.
875 void cityPillage(City* city, int& gold, int *pillaged_army_type);
878 * Sack a city (trade in all army types except one and get some gold.)
879 * The player has defeated a City and now it has been decided
880 * that the player wishes to sack this city. The decision to sack
881 * was made in Player::invadeCity. Sacking entails that the city
882 * becomes owned by the sacking player, and that all of the Army
883 * units that the city produces are traded-in for gold pieces except
884 * for the weakest Army unit.
886 * The AI_Fast, AI_Dummy and AI_Smart classes use this method
887 * as defined in RealPlayer to sack cities.
889 * This callback must result in an Action_Sack element being
890 * given to the addAction method.
892 * @param city The city to be sacked .
893 * @param gold Returns the amount of gold sacked.
894 * @param sacked_types Returns the Army types that were cashed-in
897 * @return False on error, true otherwise.
899 //! Callback to sack a city.
900 void citySack(City* city, int& gold, std::list<guint32> *sacked_types);
903 * Raze (permanently destroy) a city.
904 * The player has defeated a City and now it has been decided
905 * that the player wishes to raze this city. The decision to raze
906 * was made in Player::invadeCity. Razing entails that the city
907 * becomes burned, and is owned by nobody. The city cannot produce
908 * Army units. Other players find razing to be diplomatically
911 * The AI_Fast, AI_Dummy and AI_Smart classes use this method
912 * as defined in RealPlayer to raze cities.
914 * This callback must result in an Action_Raze element being
915 * given to the addAction method.
917 * @param city The city to be razed.
919 * @return False on error, true otherwise.
921 //! Callback to raze a city.
922 void cityRaze(City* city);
925 * Add another production to a city.
926 * The city has a set of Army units available to produce, but the
927 * Player deems this insufficent. A new Army unit is purchased
928 * for an amount of gold pieces, so that the City can produce that
929 * Army unit. Each Army unit type that can be produced is
930 * associated with one of 4 slots. If the player purchases a new
931 * Army unit in a slot that already has an Army unit, it is
932 * removed permanently.
934 * This callback must result in an Action_Buy element being
935 * given to the addAction method.
937 * @param city The lucky city.
938 * @param slot The production slot of the city. The
939 * minimum value is 0 and the maximum value
941 * @param armytype The index of the army type to add. This
942 * type relates to the Player's Armyset.
944 * @return False on error, true otherwise.
946 //! Callback to purchase a new Army unit for production within a City.
947 bool cityBuyProduction(City* city, int slot, int armytype);
950 * Change the production of a city.
951 * The City has a set of Army units that it may produce. There are
952 * up to 4 army units available for production in the City, and each
953 * sits in a slot. The change of production is indicated by slot
954 * number. If the production is to stop altogether the slot number
956 * After a slot is selected and enough time passes, a new Army unit
957 * will arrive in the city that produced it.
959 * This callback must result in an Action_Production element being
960 * given to the addAction method.
962 * @param city The affected city.
963 * @param slot The index of the selected production slot.
964 * The minimum value is -1 which means to
965 * stop production in the City. The other
966 * legal values are 0 through 3; one for
967 * each slot in the city. If a slot does
968 * not contain an Army unit, then that slot
969 * number is an illegal value to this method.
971 * @return False on error, true otherwise.
973 //! Callback to change the Army unit being produced within a City.
974 bool cityChangeProduction(City* city, int slot);
976 //! A player's city produces an army unit.
978 * @param city The city that has produced an army unit.
979 * @return False on error, true otherwise.
981 bool cityProducesArmy(City *city);
983 //! A player has a vectored army unit arrive somewhere.
984 bool vectoredUnitArrives(VectoredUnit *unit);
986 //! Shut down a city's production due to insufficent funds.
987 void cityTooPoorToProduce(City *city, int slot);
990 * Called so that the player can decide what to do with a newly
991 * conquered city. For human players this method presents the dialog
992 * that asks the user what should be done (Razing, Pillaging, etc).
993 * For the computer players this method is for deciding what to do.
994 * The decision is made by emitting one of the following signals:
995 * srazingCity, spillagingCity, ssackingCity, soccupyingCity.
997 * @param city The newly conquered city.
999 * @return True if everything went well.
1001 //! Decision callback for what to do if a city is invaded.
1002 virtual void invadeCity(City* city) = 0;
1004 //! Decision callback for what to do when a hero shows up.
1005 virtual bool chooseHero(HeroProto *hero, City *city, int gold) = 0;
1007 //! Decision callback for what reward to pick when at a sage.
1008 virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack) = 0;
1010 //! Decision callback for if to commit treachery or not.
1011 virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos) = 0;
1013 //! Decision callback for when a hero gains a level.
1014 virtual Army::Stat chooseStat(Hero *hero) = 0;
1016 //! Decision callback for when a hero visits a temple.
1017 virtual bool chooseQuest(Hero *hero) = 0;
1019 // Player related actions the player can take.
1022 * This function is called when a player's turn starts.
1023 * For AI players this function should start the algorithm.
1024 * Results in a History_StartTurn event going into the player's
1027 * @return True if everything went well.
1029 //! Callback to start a Player's turn.
1030 virtual bool startTurn() = 0;
1032 virtual void abortTurn() = 0;
1035 * This function is called before a player's turn starts.
1036 * The idea here is that it happens before heroes are recruited,
1037 * and before new army units show up in cities.
1039 //! Initialise a Player's turn.
1042 virtual void endTurn() = 0;
1046 * This method gives the player the specified Reward. There are
1047 * various possibilities when they player is being given a reward.
1048 * It could be that the player has been given: some gold pieces, a
1049 * map that makes more of the map visible or information about the
1050 * location of a new ruin. It could also be that a stack has been
1051 * given a number of powerful allies. It could also be that a stack
1052 * contains a Hero, and the Reward is an Item for the Hero to carry.
1054 * This callback must result in an Action_Reward element being
1055 * given to the addAction method.
1057 * @param stack The stack which has caused the reward.
1058 * @param reward A pointer for storing the Reward being
1059 * given to the player.
1061 * @return False on error, true otherwise.
1063 //! Callback to give a Reward to the Player or the player's Stack.
1064 bool giveReward (Stack *stack, Reward *reward);
1066 //! Give the player a new name.
1067 void rename (std::string name);
1069 //! have a hero show up, or not.
1070 bool maybeRecruitHero ();
1072 //! Mark the player as dead. Kills all Army units in the Stacklist.
1075 //! Go to a temple if we're near enough.
1077 * Helper method to take a stack on a mission to get blessed.
1078 * If the method returns false initially, it means that the nearest
1079 * temple is unsuitable.
1080 * @note The idea is that this method is called over subsequent turns,
1081 * until the blessed parameter gets filled with a value of true.
1083 * @param s The stack to visit a temple.
1084 * @param dist The maximum number of tiles that a temple
1085 * can be away from the stack, and be considered
1087 * @param mp The maximum number of movement points that a
1088 * stack needs to have to reach the temple.
1089 * @param percent_can_be_blessed If the stack has this many army
1090 * units that have not been blessed
1091 * at the temple (expressed as a
1092 * percent), then the temple will be
1093 * considered for visiting.
1094 * @param blessed Gets filled with false if the stack didn't get
1095 * blessed. Gets filled with true if the stack
1096 * got blessed at the temple.
1097 * @param stack_died Gets filled with true if the stack got killed
1098 * by an enemy stack on the same square as the
1101 * Returns true if the stack moved, false if it stayed still.
1103 bool AI_maybeVisitTempleForBlessing(Stack *s, int dist, int mp,
1104 double percent_can_be_blessed,
1105 bool &blessed, bool &stack_died);
1107 bool AI_maybeVisitTempleForQuest(Stack *s, int dist, int max_mp,
1110 bool AI_maybeVisitRuin(Stack *s, int dist, int max_mp,
1113 Vector<int> AI_getQuestDestination(Quest *quest, Stack *stack) const;
1114 bool AI_invadeCityQuestPreference(City *c, CityDefeatedAction &action) const;
1116 * Callback to decide if we perform treachery on a friendly player.
1118 * For human players this method presents a dialog for the user
1119 * to confirm if treachery should happen or not. For computer
1120 * players this method implements the decision to perform treachery
1123 * @param stack My stack considering the treachery.
1124 * @param player The friendly player.
1125 * @param pos The place on the map being targetted.
1126 * @param state The state we end up in if we decide yes.
1128 * @return True if we decided to be treacherous. False otherwise.
1130 //! Decision callback for if we should perform trechery or not.
1131 bool treachery (Stack *stack, Player *player, Vector <int> pos);
1134 * Callback to have the Player resign. This entails disbanding
1135 * all of the player's stacks and then razing all of the player's
1136 * remaining cities. It also removes all of the gold pieces from
1137 * the player's treasury.
1139 * This callback is called when a human player wants to surrender
1140 * ungracefully. Computer players do not currently consider
1141 * calling this method to surrender, and they use a different
1142 * mechanism to collectively surrender to a final human player.
1144 * This callback must result in a Action_Resign element being
1145 * given to the addAction method.
1148 //! Callback to disband all the player's stacks and raze all cities.
1151 //! Declare a new diplomatic state with respect to an opponent.
1152 void declareDiplomacy(DiplomaticState state, Player *player);
1154 //! Negotiate diplomatic talks with an opponent, and return a new state.
1155 DiplomaticState negotiateDiplomacy (Player *player);
1158 * Change the player's opinion of an opponent for the better.
1160 * @param player The player to improve our opinion by.
1161 * @param amount The amount to improve by. The minimum value
1162 * is 1 and the maximum value is 15.
1165 //! Make your diplomatic view of another player increase.
1166 void improveDiplomaticRelationship (Player *p, guint32 amount);
1169 * Change all players opinion of you for the better, except for
1170 * possibly a single player.
1172 * @param amount The amount to improve. The minimum value is 1
1173 * and the maximum value is 15.
1174 * @param except Don't improve this player's view of the player.
1176 * @note Pass except as NULL to not except a player.
1178 //! Make all other players diplomatic view of you increase.
1179 void improveDiplomaticRelationship (guint32 amount, Player *except);
1182 * Change the player's view of an opponent for the worse.
1184 * @param player The player to deteriorate our view of.
1185 * @param amount The amount to deteriorate by. The minimum value
1186 * is 1 and the maximum value is 15.
1189 //! Make your diplomatic view of another player decrease.
1190 void deteriorateDiplomaticRelationship (Player *player, guint32 amount);
1193 * Change all players opinion of you for the worse.
1195 * @param amount The amount to deterioriate by. The minimum value
1196 * is 1 and the maximum value is 15.
1198 //! Make all other players diplomatic view of you worsen
1199 void deteriorateDiplomaticRelationship (guint32 amount);
1202 * Change all players opinion of another player for the worse,
1203 * who happen to have a diplomatic state of state with you.
1205 * @param player The target player.
1206 * @param amount The amount to deterioriate by. The minimum value
1207 * is 1 and the maximum value is 15.
1208 * @param state The state that an opponent has to be in with you,
1209 * to make the deterioration happen.
1211 //! Make players you are at state with you think less of player.
1212 void deteriorateAlliesRelationship(Player *player, guint32 amount,
1213 Player::DiplomaticState state);
1216 * Change all players opinion of another player for the better,
1217 * who happen to have a diplomatic state of state with you.
1219 * @param player The target player.
1220 * @param amount The amount to improve by. The minimum value
1221 * is 1 and the maximum value is 15.
1222 * @param state The state that an opponent has to be in with you,
1223 * to make the improvement happen.
1225 //! Make players who are at STATE with PLAYER think better of you.
1226 void improveAlliesRelationship(Player *player, guint32 amount,
1227 Player::DiplomaticState state);
1229 //! Propose a new diplomatic state wrt another player
1230 void proposeDiplomacy (DiplomaticProposal proposal, Player *player);
1238 * @param city The city being invaded.
1239 * @param loot The gold looted.
1241 //! Emitted when the player defeats a City.
1242 sigc::signal<void, City*, int> sinvadingCity;
1245 * @param hero The new hero that is emerging.
1246 * @param city The city in which the hero is emerging.
1247 * @param gold The amount of gold pieces the hero costs.
1249 * @return True if we're accepting a hero, false if not.
1251 //! Emitted whenever a hero is recruited.
1252 sigc::signal<bool, HeroProto*, City *, int> srecruitingHero;
1255 * @param army The army that has gained a level.
1257 * @return One of Army::Stat::STRENGTH, Army::Stat::MOVES, or
1258 * Army::Stat::SIGHT.
1260 //! Emitted when an Army advances a level; returns stat to raise.
1261 sigc::signal<Army::Stat, Hero*> sheroGainsLevel;
1264 * @param army The army that has gotten a medal.
1266 //! Emitted whever a player's army gets a new medal.
1267 sigc::signal<void, Army*, int> snewMedalArmy;
1270 * @param army The army that has died.
1271 * @param culprit_ids A std::vector of enemy Army Ids to have
1272 * participated in the death of this player's Army.
1274 //! Emitted when a player's Army dies.
1275 sigc::signal<void, Army*, std::vector<guint32> > sdyingArmy;
1278 * @param ruin The ruin being searched.
1279 * @param stack The stack doing the searching (must contain Hero).
1280 * @param reward The reward received.
1282 //! Emitted whenever the player successfully searched a ruin.
1283 sigc::signal<void, Ruin*, Stack*> ssearchingRuin;
1286 * @param temple The temple being visited.
1287 * @param stack The stack that has gotten blessed.
1289 //! Emitted whenever the player visits a temple.
1290 sigc::signal<void, Temple*, Stack*> svisitingTemple;
1293 * @param city The city being occupied.
1294 * @param stack The stack doing the occupying.
1296 //! Emitted when the player occupies a City.
1297 sigc::signal<void, City*, Stack*> soccupyingCity;
1300 * @param city The city that has been pillaged.
1301 * @param stack The stack doing the pillaging.
1302 * @param gold The amount of gold pieces pillaged.
1303 * @param army_types The list of Army types traded-in for gold pieces.
1305 //! Emitted whenever the player pillages a city.
1306 sigc::signal<void, City*, Stack*, int, guint32> spillagingCity;
1309 * @param city The city that has been sacked.
1310 * @param stack The stack doing the sacked.
1311 * @param gold The amount of gold pieces sacked.
1312 * @param army_types The list of Army types traded-in for gold pieces.
1314 //! Emitted whenever the player sacks a city.
1315 sigc::signal<void, City*, Stack*, int, std::list<guint32> > ssackingCity;
1318 * @param city The city that has been razed.
1319 * @param stack The razing stack.
1321 //! Emitted whenever the player razes a city.
1322 sigc::signal<void, City*, Stack*> srazingCity;
1325 * Emitted when the player's treasury has been changed.
1327 //! Emitted whenever a player's stats changes.
1328 sigc::signal<void> schangingStats;
1330 //! Emitted whenever a computer player does something of note.
1331 sigc::signal<void, std::string> schangingStatus;
1333 //! Emitted whenever any player does anything at all.
1334 sigc::signal<void> sbusy;
1337 * Emitted when the player's stack moves, is disbanded, gets blessed,
1338 * searches a ruin, or is otherwise altered.
1340 * @param stack The stack that has been altered.
1342 //! Emitted whenever the stack's status has changed.
1343 sigc::signal<void, Stack*> supdatingStack;
1345 //! Emitted whenever the active stack comes to a stop.
1346 sigc::signal<void, Stack*> shaltedStack;
1349 * Emitted whenever a city is conquered or razed.
1351 * @param city The city that has been altered.
1353 //! Emitted whenever the status of a city has changed.
1354 sigc::signal<void, City*> supdatingCity;
1357 * @param fight The details of the upcoming fight.
1359 //! Emitted when a fight has started against a city or stack.
1360 sigc::signal<void, Fight &> fight_started;
1363 * @param city The city we attacked.
1364 * @param result If we won or not.
1366 //! Emitted after we attack a city.
1367 sigc::signal<void, City *, Fight::Result> cityfight_finished;
1370 * @param attacker The player's attacking stack.
1371 * @param keeper The keeper of the ruin.
1373 //! Emitted when a fight in a ruin is started.
1374 sigc::signal<void, Stack *, Stack *> ruinfight_started;
1377 * @param result If we defeated the ruin's keeper or not.
1379 //! Emitted when a fight in a ruin has finished.
1380 sigc::signal<void, Fight::Result> ruinfight_finished;
1383 * @param chance The percent chance that we will prevail in battle.
1385 //! Emitted when a player asks for help from a military advisor.
1386 sigc::signal<void, float> advice_asked;
1388 //! Signal raised when a stack is considering an act of treachery.
1389 sigc::signal<bool, Stack *, Player *, Vector<int> > streacheryStack;
1391 //! Signal raised when a human player is deciding.
1392 sigc::signal<bool, Stack *, Player *, Vector<int> > streachery;
1394 //! Player would like to end the turn.
1395 sigc::signal<void> ending_turn;
1397 //! Player has confirmed to abort the turn.
1398 sigc::signal<void> aborted_turn;
1400 sigc::signal<void, int> hero_arrives_with_allies;
1402 sigc::signal<void, NetworkAction *> acting;
1403 sigc::signal<void, NetworkHistory *> history_written;
1406 //! Check the history to see if we ever conquered the given city.
1409 Stack *stackSplitArmy(Stack *stack, Army *a);
1410 Stack *stackSplitArmies(Stack *stack, std::list<guint32> armies);
1411 Stack *stackSplitArmies(Stack *stack, std::list<Army*> armies);
1415 static std::string playerTypeToString(const Player::Type type);
1416 static Player::Type playerTypeFromString(const std::string str);
1417 //! is it safe to vector from the given city?
1418 static bool safeFromAttack(City *c, guint32 safe_mp, guint32 min_defenders);
1420 * Make a new player with the given parameters.
1422 * @note The neutral player must still be inserted as neutral player
1425 * @param name The name of the player.
1426 * @param armyset The Id of the player's Armyset.
1427 * @param color The player's colour.
1428 * @param width The width of the player's FogMap.
1429 * @param height The height of the player's FogMap.
1430 * @param type The player's type (Player::Type).
1432 //! Create a player.
1433 static Player* create(std::string name, guint32 armyset,
1434 Gdk::Color color, int width, int height,
1438 * Copies a player to a different type.
1440 * @note This method does not change ownerships! (e.g. of cities)
1442 * @param player The original player.
1443 * @param type The type we want to get out (Player::Type).
1444 * @return A new player with the old player's data and the given type.
1446 //! Create a new player from another player.
1447 static Player* create(Player* orig, Type type);
1450 * Loads a player from a file.
1452 * This is a bit inconsistent with other classes, but with players you
1453 * have the problem that there are different types with different
1454 * classes. So we need a static member function which looks which
1455 * player type to load and calls the constructor of the appropriate
1458 * @param helper the opened saved-game file to read from.
1460 * @return The loaded Player instance.
1462 static Player* loadPlayer(XML_Helper* helper);
1467 // do some fight cleaning up, setting
1468 void cleanupAfterFight(std::list<Stack*> &attackers,
1469 std::list<Stack*> &defenders);
1471 //! Move stack s one step forward on it's Path.
1472 bool stackMoveOneStep(Stack* s);
1474 //! Move stack s one step forward on it's Path, over another stack.
1475 bool stackMoveOneStepOverTooLargeFriendlyStacks(Stack *s);
1477 void addAction(Action *action);
1480 //! The player's colour.
1482 * Mask portions of images are shaded in this colour.
1486 //! The name of the Player.
1489 //! The ArmySet of the Player.
1492 //! The number of gold pieces the Player has in the treasury.
1495 //! Whether or not this player is dead.
1498 //! Whether or not this player can be killed.
1501 //! The kind of Player (see Player::Type).
1504 //! A unique numeric identifier identifying this Player.
1507 //! A list of actions that this Player made this turn.
1508 std::list<Action*> d_actions;
1510 //! A list of "headlines" for this Player for the whole game.
1511 std::list<History*> d_history;
1513 //! A list of the Player's Stack objects.
1514 Stacklist* d_stacklist;
1516 //! What the player can see on the hidden map.
1519 //! A tally of the kills that this player has made
1520 Triumphs* d_triumphs;
1522 //! The order in which this Player's army types fight in battle.
1524 * @note This value is related to the Player's ArmySet.
1526 std::list<guint32> d_fight_order;
1528 //! How many gold pieces the Player paid out in the last turn.
1531 //! How many gold pieces the Player made from taxes in the last turn.
1534 //! The diplomatic view that this Player has of each other Player.
1535 DiplomaticState d_diplomatic_state[MAX_PLAYERS];
1537 //! The diplomatic rank this Player has among all other Players.
1538 guint32 d_diplomatic_rank;
1540 //! The title that goes along with the diplomatic rank.
1541 std::string d_diplomatic_title;
1543 //! The proposals that this Player is making this turn.
1544 DiplomaticProposal d_diplomatic_proposal[MAX_PLAYERS];
1546 //! A quantification of how much this Player likes every other Player.
1547 guint32 d_diplomatic_score[MAX_PLAYERS];
1549 //! Whether or not this player is observable by the user.
1552 //! Whether or not this player has surrendered.
1555 //! Whether or not someone has closed the main game window.
1556 bool abort_requested;
1558 //! assists in scorekeeping for diplomacy
1559 void alterDiplomaticRelationshipScore (Player *player, int amount);
1561 void conquerCity(City *city, Stack *stack);
1563 // return the new stack if split succeeded
1564 Stack *doStackSplit(Stack *s);
1565 bool doStackSplitArmy(Stack *s, Army *a, Stack *& new_stack);
1566 void doStackJoin(Stack* receiver, Stack* joining);
1567 int doStackVisitTemple(Stack *s, Temple *t);
1568 void doCityOccupy(City *c);
1569 void doCityPillage(City *c, int& gold, int* pillaged_army_type);
1570 void doCitySack(City *c, int& gold, std::list<guint32> *sacked_types);
1571 void doCityRaze(City *c);
1572 void doCityBuyProduction(City *c, int slot, int type);
1573 void doCityChangeProduction(City *c, int slot);
1574 void doGiveReward(Stack *s, Reward *reward);
1575 void doHeroDropItem(Hero *hero, Item *item, Vector<int> pos);
1576 bool doHeroDropAllItems(Hero *h, Vector<int> pos);
1577 void doHeroPickupItem(Hero *hero, Item *item, Vector<int> pos);
1578 void doHeroGainsLevel(Hero *hero, Army::Stat stat);
1579 bool doStackDisband(Stack *stack);
1580 void doSignpostChange(Signpost *signpost, std::string message);
1581 void doCityRename(City *c, std::string name);
1582 void doVectorFromCity(City * c, Vector<int> dest);
1583 void doSetFightOrder(std::list<guint32> order);
1585 void doHeroPlantStandard(Hero *hero, Item *item, Vector<int> pos);
1586 void doDeclareDiplomacy (DiplomaticState state, Player *player);
1587 void doProposeDiplomacy (DiplomaticProposal proposal, Player *player);
1588 void doConquerCity(City *city, Stack *stack);
1589 void doLootCity(Player *looted, guint32 added, guint32 subtracted);
1590 Hero* doRecruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
1591 void doRename(std::string name);
1593 const Army *doCityProducesArmy(City *city, Vector<int> &pos);
1594 Army *doVectoredUnitArrives(VectoredUnit *unit);
1595 bool doChangeVectorDestination(Vector<int> src, Vector<int> dest,
1596 std::list<City*> &vectored);
1598 bool doStackSplitArmies(Stack *stack, std::list<guint32> armies,
1601 Quest* doHeroGetQuest(Hero *hero, Temple* t, bool except_raze);
1603 void AI_maybeBuyScout(City *c);
1606 bool AI_maybePickUpItems (Stack *s, int dist, int mp, bool &picked_up,
1611 bool AI_maybeVector(City *c, guint32 safe_mp, guint32 min_defenders,
1612 City *target, City **vector_city = NULL);
1615 void AI_setupVectoring(guint32 safe_mp, guint32 min_defenders,
1616 guint32 mp_to_front);
1618 bool AI_maybeDisband(Stack *s, City *city, guint32 min_defenders,
1619 int safe_mp, bool &stack_killed);
1620 bool AI_maybeDisband(Stack *s, int safe_mp, bool &stack_killed);
1622 void pruneActionlist();
1623 static void pruneActionlist(std::list<Action*> actions);
1624 std::list<History*> getHistoryForThisTurn() const;
1627 //! Loads the subdata of a player (actions and stacklist)
1628 bool load(std::string tag, XML_Helper* helper);
1631 * Returns all heroes in the given list of stacks.
1633 * @param stacks the list of stacks which is searched.
1634 * @param heroes Return a list of id's of the heroes found.
1637 void getHeroes(const std::list<Stack*> stacks,
1638 std::vector<guint32>& heroes);
1641 * Goes through a list of stacks and removes all armies with less
1642 * than 1 hitpoint. It also removes empty stacks.
1643 * This function also heals regenerating units at the end of combat.
1645 * @param stacks The list searched for dead armies.
1646 * @param culprits The list of heroes responsible for killing
1647 * the armies. This is needed for tracking
1648 * the progress of a Quest.
1649 * @return The sum of the XP of the killed armies.
1651 //! Remove dead Armies from a list of stacks after a fight.
1652 double removeDeadArmies(std::list<Stack*>& stacks,
1653 std::vector<guint32>& culprits);
1656 * Increases the number of experience points of a stack
1657 * the number of battles and checks if an army can get a medal
1659 * This functions takes a number of experience points and distributes
1660 * them equally over all armies in the stack list. Therefore, the less
1661 * armies fight, the more experience the single armies get. It emits a
1662 * signal when a unit gains a level.
1664 * @param stacks A list of all stacks gaining experience.
1665 * @param xp_sum The number of XP to distribute.
1667 //! update Army state after a Fight.
1668 void updateArmyValues(std::list<Stack*>& stacks, double xp_sum);
1672 * Called to move a Stack to a specified position.
1674 * The Path is calculated on the fly unless follow is set to true.
1675 * In this case, an existing path is checked and iterated over.
1676 * This is useful if a stack didn't reach its target within one
1677 * round and should continue the movement.
1679 * This callback must result in an Action_Move element being
1680 * given to the addAction method.
1682 * @param s The stack to be moved.
1683 * @param dest The destination of the move.
1684 * @param follow If set to false, calculate the path.
1686 * @return False on error, true otherwise.
1688 //! Callback to move a stack on the map.
1689 MoveResult *stackMove(Stack* s, Vector<int> dest, bool follow);
1691 bool nextStepOnEnemyStackOrCity(Stack *s) const;
1693 void lootCity(City *city, Player *looted);
1694 void calculateLoot(Player *looted, guint32 &added, guint32 &subtracted);
1695 void takeCityInPossession(City* c);
1696 static void pruneCityVectorings(std::list<Action*> actions);
1697 static void pruneCityProductions(std::list<Action*> actions);
1699 std::list<Action *> getActionsThisTurn(int type) const;