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-2011, 2014, 2015, 2017 Ben Asselstine
7 // Copyright (C) 2007, 2008 Ole Laursen
8 //
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.
13 //
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.
18 //
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
22 //  02110-1301, USA.
23 
24 #pragma once
25 #ifndef PLAYER_H
26 #define PLAYER_H
27 
28 #include <list>
29 #include <vector>
30 #include <sigc++/trackable.h>
31 #include <sigc++/signal.h>
32 #include <gtkmm.h>
33 
34 #include "vector.h"
35 #include "fight.h"
36 #include "army.h"
37 #include "defs.h"
38 #include "callback-enums.h"
39 
40 class XML_Helper;
41 class Stacklist;
42 class Hero;
43 class HeroProto;
44 class Action;
45 class Action_Produce;
46 class NetworkAction;
47 class History;
48 class NetworkHistory;
49 class City;
50 class Quest;
51 class Army;
52 class Ruin;
53 class Temple;
54 class MoveResult;
55 class FogMap;
56 class Fight;
57 class Reward;
58 class Signpost;
59 class VectoredUnit;
60 class ArmyProto;
61 class Item;
62 class Triumphs;
63 class Sage;
64 class StackReflist;
65 class Maptile;
66 class Keeper;
67 
68 //! The abstract player class.
69 /**
70  * This class does not yet implement an actual player type. Its purpose is to
71  * provide an abstract class design which every player implementation has to
72  * fulfill. Of each player class we demand the following functionality:
73  *
74  * 1. functions for _every_ action a player can do
75  * 2. some kind of callback functions if the player has a choice (e.g. if he has
76  *    conquered a city, he may choose between razing, pillaging and occupying)
77  * 3. signals which are raised whenever something important happens
78  * 4. an actionlist which keeps track of _everything_ a player has done
79  *
80  * The fourth point allows us an easy network playing scheme. After a player
81  * has finished, all he has to do is sending his actionlist to the over network
82  * players. Since every item which the player can touch/kill etc. (cities,
83  * armies, ruins,...) has a unique id, the remote game instances can then
84  * simply apply these action lists to their own situation.
85  *
86  * The third point allows us to dock other classes to every possible event. One
87  * example are ruin searching quests which must be informed whenever any
88  * player searches a ruin. Or the bigmap can be informed when a stack moves,
89  * so that it may update its contents.
90  *
91  * The second item allows an easy coexistence of AI and human players.
92  * Basically, an AI player just follows some kind of routine while a human
93  * player uses gui interaction. However, this becomes a bit problematic
94  * whenever the player may decide something. One solution is providing
95  * callbacks for these cases. The human player then opens a dialog somehow
96  * while the AI player overwrites the default behaviour.
97  *
98  * The first point makes a nice derivation scheme possible. It is possible to
99  * divide the player types into a local player, who implements all these
100  * functions and a networked player. The latter one simply overwrites these
101  * functions so that the game status is updated for each item of the actionlist
102  * he has been sent. Furthermore, with a local player having been implemented,
103  * it is extremely easy to write an AI player. All you have to do is overwrite
104  * the startTurn function with your own code. For every action you already know
105  * there is an implementation in a superior class which takes off the burden
106  * for the actual work.
107  *
108  *
109  * Finally, the current derivation scheme is as follows:
110  * RealPlayer derives from Player.
111  * NetworkPlayer derives from Player.
112  * AI_Fast, AI_Dummy, and AI_Smart derive from RealPlayer.
113  *
114  * The Ids of players are very specific.  The first player (the White player)
115  * must have the Id of 0, the next player (Green) must have the Id of 1, and
116  * so on.  The Neutral player must have the final player Id.
117  * If the White player is not in the scenario, then the Id 0 must be skipped.
118  * There can only be MAX_PLAYERS players in total.
119  */
120 
121 class Player: public sigc::trackable
122 {
123     public:
124 	//! The xml tag of this object in a saved-game file.
125 	static Glib::ustring d_tag;
126 
127         //! The available player types.
128         enum Type {
129 	  //! Local human player.  See the RealPlayer class.
130 	  HUMAN = 0,
131 	  //! Local computer player (Easy).  See the AI_Fast class.
132 	  AI_FAST = 1,
133 	  //! Local computer player (Neutral).  See the AI_Dummy class.
134 	  AI_DUMMY = 2,
135 	  //! Local computer player (Hard).  See the AI_Smart class.
136 	  AI_SMART = 4,
137 	  //! Remote player.  See the NetworkPlayer class.
138 	  NETWORKED = 8
139 	};
140 
141 	//! Every player has a diplomatic state with every other player.
142 	enum DiplomaticState {
143 	  //! Can't attack opponent's stacks anywhere.
144 	  AT_PEACE = 1,
145 	  //! Can't attack opponent's stacks in cities.
146 	  AT_WAR_IN_FIELD = 2,
147 	  //! Can attack opponent's stack everywhere.
148 	  AT_WAR = 3
149 	};
150 
151 	//! Every player has a diplomatic proposal to every other player.
152 	enum DiplomaticProposal {
153 	  //! Offer to keep the status-quo with the opponent.
154 	  NO_PROPOSAL = 0,
155 	  //! Offer peace to an opponent.
156 	  PROPOSE_PEACE = 1,
157 	  //! Offer limited war to an opponent (only kill stacks in the field).
158 	  PROPOSE_WAR_IN_FIELD = 2,
159 	  //! Offer all-out war to an opponent.
160 	  PROPOSE_WAR = 3
161 	};
162 
163         /**
164 	 * Make a new player.
165 	 * @note AI_Fast, AI_Dummy, AI_Smart and RealPlayer use this
166 	 * constructor to make new Players.
167          *
168          * @param name         The name of the player.
169          * @param armyset      The Id of the player's Armyset.
170          * @param color        The player's colour.
171 	 * @param width        The width of the player's FogMap.
172 	 * @param height       The height of the player's FogMap.
173 	 * @param type         The kind of player (Player::Type).
174 	 * @param player_no    The Id of the player.  If this value is -1,
175 	 *                     the next free Id it used.
176          */
177 	//! Default constructor.
178         Player (Glib::ustring name, guint32 armyset, Gdk::RGBA color, int width,
179 		int height, Type type, int player_no = -1);
180 
181         //! Copy constructor.
182         Player(const Player&);
183 
184         //! Constructor for loading. See XML_Helper for documentation.
185         Player(XML_Helper* helper);
186 
187 	//! Destructor.
188         virtual ~Player();
189 
190 
191 	// Set Methods
192 
193         //! Change the player's name.
setName(Glib::ustring name)194         void setName(Glib::ustring name){d_name = name;}
195 
196         //! Change the player's Armyset.
setArmyset(guint32 armyset)197         void setArmyset(guint32 armyset){d_armyset = armyset;}
198 
199         //! Set the type of the player (to be used by derived classes only.)
setType(Type type)200         void setType(Type type) {d_type = type;}
201 
202         //! Change the player's colour.
203         void setColor(Gdk::RGBA c);
204 
205         //! Makes a player unable to die, even when having no units or cities.
setMortality(bool ismortal)206         void setMortality(bool ismortal) {d_immortal = !ismortal;}
207 
208         //! Change the number of gold pieces of the player has.
setGold(int gold)209         void setGold(int gold){d_gold = gold;}
210 
211 	//! Set this player's rank in diplomatic matters.  Starts at 1.
setDiplomaticRank(guint32 rank)212 	void setDiplomaticRank (guint32 rank) {d_diplomatic_rank = rank;};
213 
214 	//! Set the rank as a name.
setDiplomaticTitle(Glib::ustring title)215 	void setDiplomaticTitle (Glib::ustring title) {d_diplomatic_title = title;};
216 	//! Set if this player will be seen as it moves through visible terrain.
setObservable(bool observable)217 	void setObservable(bool observable) {d_observable = observable;};
218 
219         //! Revive the player, this does not provide any cities.
revive()220         void revive() {d_dead = false;}
221 
222 	//! Set whether or not this player has surrendered.
223 	/*
224 	 * computer players may surrender to a lone human player who has most
225 	 * of the cities on the board.
226 	 * this method merely sets the surrendered member so that we can
227 	 * quit properly. e.g. it triggers the aborted_Turn signal to be fired
228 	 * at a different time in fast, smart and dummy players.
229 	 */
230 	void setSurrendered(bool surr);
231 
232         //! Set the fight order of the player.
233 	void setFightOrder(std::list<guint32> order);
234 
235         //! Set path of the stack to the previously moved stack's destination.
236         bool setPathOfStackToPreviousDestination(Stack *stack);
237 
238 
239 	// Get Methods
240 
241 	//! Returns whether or not this is a computer player.
242 	virtual bool isComputer() const = 0;
243 
244         //! Returns the unique ID of the player.
getId()245         guint32 getId() const {return d_id;}
246 
247         //! Returns the list of player's events.
getHistorylist()248         std::list<History*>* getHistorylist() {return &d_history;}
249 
250         //! Return the Id of the player's Armyset.
getArmyset()251         guint32 getArmyset() const {return d_armyset;}
252 
253         //! Return whether or not the player has been killed.
isDead()254         bool isDead() const {return d_dead;}
255 
256         //! Returns whether a player is immortal or not.
isImmortal()257         bool isImmortal() const {return d_immortal;}
258 
259         //! Return the type of the player (Player::Type).
getType()260         guint32 getType() const {return d_type;}
261 
262         /**
263 	 * Return the amount of upkeep in gold pieces that the player spent
264 	 * in the previous turn.
265 	 */
266 	//! Return the upkeep.
getUpkeep()267         guint32 getUpkeep() const {return d_upkeep;}
268 
269 	//! Return the income from all of the player's cities.
getIncome()270         guint32 getIncome () const {return d_income;}
271 
272 	//! What diplomatic rank does this player have?  Starts at 1.
getDiplomaticRank()273 	guint32 getDiplomaticRank () const {return d_diplomatic_rank;};
274 
275 	//! What rank do we have?  As a name.
getDiplomaticTitle()276 	Glib::ustring getDiplomaticTitle() const {return d_diplomatic_title;};
277 
278         //! Returns the colour of the player.
getColor()279 	Gdk::RGBA getColor() const {return d_color;}
280 
281         //! Returns the amount of gold pieces the player has in the treasury.
getGold()282         int getGold() const {return d_gold;}
283 
284         //! Returns the name of the player.
285         Glib::ustring getName() const;
286 
287 	//! Returns the player's current score.
288         guint32 getScore() const;
289 
290         //! Returns the list of stacks owned by the player.
getStacklist()291         Stacklist* getStacklist() const {return d_stacklist;}
292 
293         //! Returns the list of stacks with items.
294         std::list<Stack*> getStacksWithItems() const;
295 
296         //! Get the FogMap of the player.
getFogMap()297         FogMap* getFogMap() const {return d_fogmap;}
298 
299         //! Get the Triumphs of the player.
getTriumphs()300         Triumphs* getTriumphs() const {return d_triumphs;}
301 
302         //! Get the fight order of the player.
getFightOrder()303 	std::list<guint32> getFightOrder() const {return d_fight_order;}
304 
isObservable()305 	bool isObservable() const {return d_observable;};
306 
abortRequested()307         bool abortRequested() const {return abort_requested;};
308 
309 	// Methods that operate on the player's action list.
310 
311 	//! Returns a list of the players unit production actions for this turn.
312 	std::list<Action_Produce *> getUnitsProducedThisTurn() const;
313 
314         //! Returns a list of the player's actions to show in a report.
315 	std::list<Action *> getReportableActions() const;
316 
317         //! Returns number of cities that were too poor to produce this turn.
318         int countDestituteCitiesThisTurn() const;
319 
320         //! Returns all actions for this turn.
321         std::list<Action *> getMovesThisTurn() const;
322 
323         //! Returns the first city conquered that is still ours and not razed.
324         City *getFirstCity() const;
325 
326         //! Remove every Action from the list of the player's actions.
327         void clearActionlist();
328 
329         //! Show debugging information for the player's Action list.
330         void dumpActionlist() const;
331 
332 	//! Check to see if it's our turn.
333 	bool hasAlreadyInitializedTurn() const;
334 
335 	//! Check to see if we've already collected from cities and paid troops
336 	bool hasAlreadyCollectedTaxesAndPaidUpkeep() const;
337 
338 	//! Check to see if we've ended our turn this round.
339 	bool hasAlreadyEndedTurn() const;
340 
341 	//! Return the movement history of a given stack for this turn.
342 	std::list<Vector<int> > getStackTrack(Stack *s) const;
343 
344 
345 	// Methods that operate on the player's history list.
346 
347         //! Remove every History element from the list of the player's events.
348         void clearHistorylist();
349 
350         //! Show debugging information for the player's History list.
351         void dumpHistorylist() const;
352 
353 	//! Check the player's history to see if we've conquered the given city.
354 	bool conqueredCity(City *c, guint32 &turns_ago) const;
355 
356         //! Check the player's history to see if we've explored the given ruin.
357         bool searchedRuin(Ruin *r) const;
358 
359 	//! Return a list of history events for the given hero.
360 	std::list<History *> getHistoryForHeroId(guint32 id) const;
361 
362 	//! Return a list of history events for the given city.
363 	std::list<History *> getHistoryForCityId(guint32 id) const;
364 
365 	//! Count the turns we've completed.
366 	guint32 countEndTurnHistoryEntries() const;
367 
368 	//! Add a new history item to the player's history list.
369 	void addHistory(History *history);
370 
371 
372 	// Methods that operate on the player's stacklist
373 
374 	//! Return a list of the player's heroes.
375 	std::list<Hero*> getHeroes() const;
376 
377 	//! Return the grand total of the player's armies.
378 	guint32 countArmies() const;
379 
380 	//! Return the player's currently selected stack.
381 	Stack * getActivestack() const;
382 
383 	//! Select this stack.
384 	void setActivestack(Stack *);
385 
386 	//! Return the position on the map for the given army unit.
387 	Vector<int> getPositionOfArmyById(guint32 id) const;
388 
389 	//! Remove movement points from all of the player's army units.
390 	void immobilize();
391 
392 	//! Remove all stacks from the player's list.
393 	void clearStacklist();
394 
395         //! Add a Stack to the player's Stacklist.
396         void addStack(Stack* stack);
397 
398         //! Remove a Stack from the player's Stacklist.
399         bool deleteStack(Stack* stack);
400 
401         //! Return a list of all of the player's items that can be used.
402         std::list<Item*> getUsableItems() const;
403 
404         //! Return whether or not the player has any items that can be used.
405         bool hasUsableItem() const;
406 
407         //! Return which stack and hero the item belongs to.
408         bool getItemHolder(Item *item, Stack **stack, Hero **hero) const;
409 
410 	// Methods that operate on the player's diplomatic data members.
411 
412 	//! Query the diplomatic state this player has with an opponent.
413 	DiplomaticState getDiplomaticState (Player *player) const;
414 
415 	//! Query the diplomatic proposal we're making to an opponent.
416 	DiplomaticProposal getDiplomaticProposal (Player *player) const;
417 
418 	//! Get the diplomatic score with respect to an opponent.
419 	guint32 getDiplomaticScore (Player *p) const;
420 
421         void adjustDiplomacyFromConqueringCity(City *city);
422 
423         //! Add some gold pieces to the player's treasury.
424         void addGold(int gold);
425 
426         //! Subtract gold pieces from the player's treasury.
427         void withdrawGold(int gold);
428 
429 	/**
430 	 * Perform a summation of the upkeep value for every Army in the
431 	 * player's Stacklist.  This method sets d_upkeep.
432 	 * The upkeep value is in gold pieces.
433 	 */
434 	//! Calculates the upkeep.
435 	void calculateUpkeep();
436 
437 	/**
438 	 * Perform a summation of the income value for every City in the
439 	 * player's Citylist.  This method sets d_income.
440 	 * The income value is in gold pieces.
441 	 */
442 	//! Calculates the upkeep.
443 	void calculateIncome();
444 
445 
446 	//! Remove all fog from the player's map.
447 	void clearFogMap();
448 
449 
450         /**
451 	 * Saves the player data to a file.
452 	 *
453 	 * @param helper     The opened saved-game file to write to.
454          *
455          * @note This function only saves basic data, it doesn't open/close the
456          * player tags, this has to be done by the derived methods in
457 	 * RealPlayer, AI_Fast, AI_Smart and AI_Dummy.
458          */
459 	//! Save the player to a saved-game file.
460         virtual bool save(XML_Helper* helper) const;
461 
462 
463 
464         /**
465 	 * Called to merge two stacks into one.
466 	 *
467 	 * This callback must result in an Action_Join element being
468 	 * given to the addAction method.
469          *
470          * @param receiver     The receiving stack.
471          * @param joining      The joining stack, destroyed after the join.
472 	 *
473          * @return False if an error occured, else true.
474          */
475 	//! Callback to merge two stacks into one.
476         bool stackJoin(Stack* receiver, Stack* joining);
477 
478 	/**
479 	 * Called to change the position of a Stack on the map.
480 	 * The new position is dictated by the last point of the Path of the
481 	 * Stack.  This method can trigger many other actions.
482 	 *
483 	 * This callback must result in an Action_Move element being
484 	 * given to the addAction method.
485 	 *
486 	 * @param s             The stack to be moved.
487 	 *
488          * @return False if an error occured, else true.
489 	 */
490         //! Callback to move a stack on the map.
491         bool stackMove(Stack* s);
492         MoveResult* stackMove(Stack* s, Vector<int> dest);
493 
494 	//! Callback to take the armies from the stack that have at least
495 	//! enough moves to reach the end of the stack's path.
496 	bool stackSplitAndMove(Stack* s, Stack *& new_stack);
497 	bool stackSplitAndMoveToAttack(Stack* s, Stack *& new_stack);
498 	bool stackSplitAndMoveToJoin(Stack* s, Stack *join, Stack *& new_stack);
499 
500         /**
501 	 * Called to adjudicate a fight between two lists of stacks.
502          *
503          * Note that all stacks next to the defending stack also take part in
504          * the fight, if they belong either to the attacker's side or to the
505          * defender.  If the attacker or the defender die in the course of
506 	 * events, the pointers are set to 0.
507          *
508 	 * This callback must result in an Action_Fight element being
509 	 * given to the addAction method.
510 	 *
511          * @param attacker         The list of attacking stacks.
512          * @param defender         The list of defending stacks.
513 	 *
514          * @return A pointer to a fight object to be passed to
515          *         finishStackFight.
516          */
517 	//! Callback to adjudicate fights.
518         Fight * stackFight(Stack** attacker, Stack** defender);
519 
520         //! Finalize a fight (drop bags, delete stacks, etc)
521         void finishStackFight (Fight *fight, Stack **attacker, Stack **def);
522 
523         /**
524 	 * A stack searches a ruin.  The stack must contain a hero.
525 	 *
526 	 * This callback must result in an Action_Ruin element being
527 	 * given to the addAction method.
528 	 *
529          * @param stack            The stack which searches the ruin.
530          * @param ruin             The ruin to be searched.
531          * @param stackdied        Whether or not the stack went away because
532          *                         of the searching of the ruin.
533 	 *
534          * @return reward          A pointer to the received Reward.  Return
535 	 *                         NULL if the keeper could not be defeated.
536          */
537 	//! Callback to have a stack visit a ruin.
538         Reward* stackSearchRuin(Stack* stack, Ruin* ruin, bool &stackdied);
539 
540         /**
541 	 * A stack visits a temple and becomes blessed. By blessing, the
542          * strength of all armies rises by 1.
543          *
544 	 * This callback must result in an Action_Temple element being
545 	 * given to the addAction method.
546 	 *
547          * @param stack            The stack visiting the temple.
548          * @param temple           The visited temple.
549 	 *
550          * @return The number of blessed armies.
551          */
552 	//! Callback to have a stack visit a temple.
553         int stackVisitTemple(Stack* stack, Temple* temple);
554 
555         /**
556 	 * Called to ask the military advisor about what would happen
557 	 * if the stack attacked the tile.
558          *
559          * @param stack    The stack to attack with.
560 	 * @param tile     The tile to attack (could be a city, or a stack).
561 	 * @param intense_combat  If the intense combat game option is on or
562 	 *                        not.
563 	 *
564          * @return The percent chance to win the fight.  The maximum value
565 	 *         is 100.0, and the minimum value is 0.0.
566          */
567 	//! Callback to calculate the odds of winning a fight.
568         float stackFightAdvise(Stack* stack, Vector<int> tile,
569                                bool intense_combat);
570 
571 	/**
572 	 * Disbanding a player's stack removes it from the game.  Disbanding
573 	 * stacks saves upkeep for unwanted Army units.
574 	 *
575 	 * This callback must result in an Action_Disband element being
576 	 * given to the addAction method.
577 	 *
578 	 * @param stack            The stack to disband.
579 	 *
580          * @return False on error, true otherwise.
581 	 */
582         //! Callback to disband a player's stack.
583         bool stackDisband(Stack* stack);
584 
585         //! Recharge the player's stacks with hp and movement points.
586         void stacksReset();
587 
588         //! Recharge the monsters in all of the ruins. (neutral does this)
589         void ruinsReset();
590 
591         void collectTaxesAndPayUpkeep();
592 
593 	/**
594 	 * Modifying a signpost entails changing the message on the sign.
595 	 * When playing in a hidden map, the hope is that we change the
596 	 * message on the sign before an opponent can read it.
597 	 *
598 	 * For this callback to make sense, you should only change
599 	 * Signposts for which we have a Stack co-located.
600 	 *
601 	 * This callback must result in a Action_ModifySignpost element being
602 	 * given to the addAction method.
603 	 *
604 	 * @param signpost         The signpost to modify.
605 	 * @param message          The new text to inscribe onto the sign.
606 	 *
607          * @return False on error, true otherwise.
608 	 */
609         //! Change the text on a signpost.
610         bool signpostChange(Signpost *signpost, Glib::ustring message);
611 
612 
613 
614 
615 	// Hero related actions the player can take.
616 
617         /**
618 	 * Callback to plant the Player's flag Item on the ground.
619 	 * Planting a standard entails taking the Item out of the Hero's
620 	 * backpack and putting it on the ground so that Army units can
621 	 * be vectored to that location.
622 	 *
623 	 * Computer players don't currently consider vectoring units, so
624 	 * only human players use this method.
625 	 *
626 	 * This callback must result in an Action_Plant element being added
627 	 * to the player's Action list (Player::d_actions).
628 	 *
629 	 * @param  stack  The Stack that contains the Hero who is holding
630 	 *                the plantable Item.  Every player has exactly one
631 	 *                plantable Item.  The item is planted at the
632 	 *                position of the Stack on the map.
633 	 *
634          * @return False on error, true otherwise.
635          */
636         //! Callback to plant a player's standard.
637         bool heroPlantStandard(Stack *stack);
638 
639 	/**
640 	 * Callback to drop an item at a particular position on the game map.
641 	 * The item is removed from the Hero's backback and placed in a bag
642 	 * at place on the map.
643 	 *
644 	 * For this method to make sense, the Hero should be in a Stack
645 	 * that is co-located with the drop position.  E.g. Heroes should
646 	 * drop items here.
647 	 *
648 	 * This callback must result in an Action_Equip element being
649 	 * given to the addAction method.
650 	 *
651 	 * @param hero             The Hero that holds the item.
652 	 * @param item             The Item to drop onto the ground.
653 	 * @param pos              The position of the tile on the game map to
654 	 *                         drop the item onto.
655          * @param splash           Whether or not the item sunk in the water
656          *                         after dropping it.
657 	 *
658          * @return False on error, true otherwise.
659 	 */
660         //! Callback to have a Hero drop an Item.
661         bool heroDropItem(Hero *hero, Item *item, Vector<int> pos, bool &splash);
662 
663 	/**
664 	 * Callback to drop a all items at a particular position on the
665 	 * game map.  All items in the Hero's backback are removed and placed
666 	 * into a bag at place on the map.
667 	 *
668 	 * For this method to make sense, the Hero should be in a Stack
669 	 * that is co-located with the drop position.  E.g. Heroes should
670 	 * drop items here.
671 	 *
672 	 * This callback must result in one or more Action_Equip elements
673 	 * being given to the addAction method.
674 	 *
675 	 * @param hero             The Hero that holds the items.
676 	 * @param pos              The position of the tile on the game map to
677 	 *                         drop the item onto.
678          * @param splash           Whether or not the items sunk in the water
679          *                         after dropping them.
680 	 *
681          * @return False on error, true otherwise.
682 	 */
683         //! Callback to have a Hero drop all items.
684         bool heroDropAllItems(Hero *hero, Vector<int> pos, bool &splash);
685 
686 	/**
687 	 * Callback to pickup an Item at a particular position on the game
688 	 * map.  The item is removed from a tile on the game map, and placed
689 	 * into the Hero's backback.
690 	 *
691 	 * For this method to make sense, the Hero should be in a Stack
692 	 * that is co-located with the pickup position.  E.g. Heroes should
693 	 * pickup items from the tile they are on.
694 	 *
695 	 * This callback must result in an Action_Equip element being
696 	 * given to the addAction method.
697 	 *
698 	 * @param hero             The Hero that holds the item.
699 	 * @param item             The Item to pickup off of the ground.
700 	 * @param pos              The position of the tile on the game map to
701 	 *                         pickup the item from.
702 	 *
703          * @return False on error, true otherwise.
704 	 */
705         //! Callback to have a Hero pick up an Item.
706         bool heroPickupItem(Hero *hero, Item *item, Vector<int> pos);
707 
708 	//! Pick up all of the items at the given location on the game map.
709 	bool heroPickupAllItems(Hero *h, Vector<int> pos);
710 
711         //! Have the given hero use the given item, on the given player.
712         bool heroUseItem(Hero *h, Item *item, Player *player, City *friendly_city, City *enemy_city, City *neutral_city, City *city);
713 
714 	/**
715 	 * Completing a Quest entails that the Hero is going to receive a
716 	 * reward, but that happens in Player::giveReward.
717 	 * The QuestsManager class handles removal of expired or completed
718 	 * quests.
719 	 * This callback doesn't do much except record the event for
720 	 * posterity (see HistoryReportDialog).
721 	 *
722 	 * This callback must result in a History_QuestCompleted element being
723 	 * added to the player's History list (Player::d_history).
724 	 *
725 	 * @param hero             The Hero completing the Quest.
726 	 *
727          * @return False on error, true otherwise.
728 	 */
729         //! Callback to have a Hero complete a quest.
730         bool heroCompletesQuest(Hero *hero);
731 
732         /**
733 	 * A hero visits a temple and receives a Quest from the temple's
734          * priests.  If there is more than one hero in the stack, the quest is
735          * assigned to the first hero without a quest.
736          *
737 	 * This callback must result in an Action_Quest element being
738 	 * given to the addAction method.
739 	 * This callback must result in a History_QuestStarted element being
740 	 * added to the player's History list (Player::d_history).
741 	 *
742          * @param hero              The visiting hero.
743          * @param temple            The visited temple.
744          * @param except_raze       Don't give out a raze quest because it's
745 	 *                          impossible to raze a city in this
746 	 *                          scenario.
747 	 *
748          * @return The newly assigned Quest or 0 on error.
749          */
750 	//! Callback to have a Hero get a new Quest from a temple.
751         Quest* heroGetQuest(Hero *hero, Temple* temple, bool except_raze);
752 
753         /**
754 	 * Called whenever a hero emerges in a city
755 	 *
756          * @param  hero    The hero who has offered his or her service.
757          * @param  city    The city where the hero is emerging.
758          * @param  cost    The amount of gold pieces neccessary to recruit
759 	 *                 the hero.
760          * @param stacks   Where the allies ended up (if any).
761 	 *
762          * @note Only change the name and gender attributes of the Hero.
763          */
764         void recruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally, StackReflist *stacks);
765 
766         /**
767 	 * Called whenever a hero advances a level.
768 	 * For human players this method presents a dialog that allows the
769 	 * user to select an Army::STAT to improve (HP, MOVES, or SIGHT if
770 	 * a hidden map is in use).  For computer players this method is
771 	 * used to decide which stat should be improved.
772          *
773 	 * This callback must result in an Action_Level element being
774 	 * given to the addAction method.
775 	 *
776          * @param army     The army to raise (is always a Hero.)
777          */
778 	//! Callback to advance an Army's level.
779         virtual void heroGainsLevel(Hero * a) = 0;
780 
781 
782 
783 
784 
785 
786 
787 	// City related actions the player can take.
788 
789 	/**
790 	 * Callback to have a Player rename a City.
791 	 *
792 	 * Only human players currently rename cities; computer players
793 	 * do not consider doing so.
794 	 *
795 	 * This callback must result in a Action_RenameCity element being
796 	 * given to the addAction method.
797 	 *
798 	 * @param city             The city to change the name of.
799 	 * @param name             The new name of the city.
800 	 *
801          * @return False on error, true otherwise.
802 	 */
803         //! Callback to rename a city.
804         bool cityRename(City *city, Glib::ustring name);
805 
806         /**
807 	 * Callback to initiate vectoring new units from a player's City to
808 	 * a destination point on the game map.
809 	 *
810 	 * Computer players don't currently consider vectoring units, so
811 	 * only human players use this method.
812 	 *
813 	 * This callback must result in a Action_Vector element being
814 	 * given to the addAction method.
815 	 *
816          * @param  city   The city to vector from.
817          * @param  dest   The place on the map to vector the produced Army
818 	 *                units to.  If the  destination is -1,-1 it means
819 	 *                to stop vectoring altogether.  The destination
820 	 *                point should be co-located with a City or a
821 	 *                planted standard Item.
822 	 *
823          * @return False on error, true otherwise.
824          */
825 	//! Callback to vector produced units from a city.
826         bool vectorFromCity(City* city, Vector<int> dest);
827 
828         /**
829 	 * Callback to change the vectoring destination for all of the
830 	 * player's cities that are vectoring to a particular city.
831 	 *
832 	 * SRC and DEST can both be the player's planted standard.
833 	 *
834 	 * @param  src    The place that we want to take all the vectoring from.
835          * @param  dest   The place on the map to vector to.  The destination
836 	 *                point should be co-located with a City or a
837 	 *                planted standard Item.
838 	 *
839          * @return False on error, true otherwise.
840          */
841 	//! Callback to make a mass change to vectoring.
842 	bool changeVectorDestination(Vector<int> src, Vector<int> dest);
843 
844         //! The player's stack takes a city.  Stack can be NULL.
845         void conquerCity(City *city, Stack *stack);
846 
847         //! Take them all!  (used for testing)
848         void conquerAllCities();
849 
850         //! Park all the stacks that aren't already parked.
851         void parkAllStacks();
852 
853         /**
854 	 * Callback to have the active player occupy a given city.
855 	 * The player has defeated a City and now it has been decided
856 	 * that the player wishes to occupy this city.  The decision
857 	 * happens in Player::invadeCity. Occupying means that the city
858 	 * becomes owned by the ocuppying player.
859          *
860 	 * This callback must result in an Action_Occupy element being
861 	 * given to the addAction method.
862 	 *
863          * @param city             The occupied city.
864 	 *
865          * @return False on error, true otherwise.
866          */
867 	//! Callback to occupy a city.
868         void cityOccupy(City* city);
869 
870         /**
871 	 * Pillage a city (trade in the best army type and get some gold.)
872 	 * The player has defeated a City and now it has been decided
873 	 * that the player wishes to pillage this city.  The decision to
874 	 * pillage happened in Player::invadeCity. Pillaging means that the
875 	 * city becomes owned by the pillaging player, and that the strongest
876 	 * Army unit type that the city can produce is traded-in for an
877 	 * amount of gold pieces.
878          *
879 	 * This callback must result in an Action_Pillage element being
880 	 * given to the addAction method.
881 	 *
882          * @param city             The city to be pillaged.
883          * @param gold             Returns the amount of gold pillaged.
884 	 * @param pillaged_army_type The army type that is cashed in for gold.
885 	 *
886          * @return False on error, true otherwise.
887          */
888 	//! Callback to pillage a city.
889         void cityPillage(City* city, int& gold, int *pillaged_army_type);
890 
891         /**
892 	 * Sack a city (trade in all army types except one and get some gold.)
893 	 * The player has defeated a City and now it has been decided
894 	 * that the player wishes to sack this city.  The decision to sack
895 	 * was made in Player::invadeCity.  Sacking entails that the city
896 	 * becomes owned by the sacking player, and that all of the Army
897 	 * units that the city produces are traded-in for gold pieces except
898 	 * for the weakest Army unit.
899          *
900 	 * The AI_Fast, AI_Dummy and AI_Smart classes use this method
901 	 * as defined in RealPlayer to sack cities.
902          *
903 	 * This callback must result in an Action_Sack element being
904 	 * given to the addAction method.
905          *
906          * @param city             The city to be sacked .
907          * @param gold             Returns the amount of gold sacked.
908 	 * @param sacked_types     Returns the Army types that were cashed-in
909 	 *                         for gold pieces.
910 	 *
911          * @return False on error, true otherwise.
912          */
913 	//! Callback to sack a city.
914         void citySack(City* city, int& gold, std::list<guint32> *sacked_types);
915 
916         /**
917 	 * Raze (permanently destroy) a city.
918 	 * The player has defeated a City and now it has been decided
919 	 * that the player wishes to raze this city.  The decision to raze
920 	 * was made in Player::invadeCity.  Razing entails that the city
921 	 * becomes burned, and is owned by nobody.  The city cannot produce
922 	 * Army units.  Other players find razing to be diplomatically
923 	 * treacherous.
924          *
925 	 * The AI_Fast, AI_Dummy and AI_Smart classes use this method
926 	 * as defined in RealPlayer to raze cities.
927          *
928 	 * This callback must result in an Action_Raze element being
929 	 * given to the addAction method.
930          *
931          * @param city             The city to be razed.
932 	 *
933          * @return False on error, true otherwise.
934          */
935 	//! Callback to raze a city.
936         void cityRaze(City* city);
937 
938         /**
939 	 * Add another production to a city.
940 	 * The city has a set of Army units available to produce, but the
941 	 * Player deems this insufficent.  A new Army unit is purchased
942 	 * for an amount of gold pieces, so that the City can produce that
943 	 * Army unit.  Each Army unit type that can be produced is
944 	 * associated with one of 4 slots.  If the player purchases a new
945 	 * Army unit in a slot that already has an Army unit, it is
946 	 * removed permanently.
947          *
948 	 * This callback must result in an Action_Buy element being
949 	 * given to the addAction method.
950          *
951          * @param city             The lucky city.
952          * @param slot             The production slot of the city.  The
953 	 *                         minimum value is 0 and the maximum value
954 	 *                         is 3.
955          * @param armytype         The index of the army type to add.  This
956 	 *                         type relates to the Player's Armyset.
957 	 *
958          * @return False on error, true otherwise.
959          */
960 	//! Callback to purchase a new Army unit for production within a City.
961         bool cityBuyProduction(City* city, int slot, int armytype);
962 
963         /**
964 	 * Change the production of a city.
965 	 * The City has a set of Army units that it may produce.  There are
966 	 * up to 4 army units available for production in the City, and each
967 	 * sits in a slot.  The change of production is indicated by slot
968 	 * number.  If the production is to stop altogether the slot number
969 	 * is -1.
970 	 * After a slot is selected and enough time passes, a new Army unit
971 	 * will arrive in the city that produced it.
972          *
973 	 * This callback must result in an Action_Production element being
974 	 * given to the addAction method.
975          *
976          * @param city             The affected city.
977          * @param slot             The index of the selected production slot.
978 	 *                         The minimum value is -1 which means to
979 	 *                         stop production in the City.  The other
980 	 *                         legal values are 0 through 3; one for
981 	 *                         each slot in the city.  If a slot does
982 	 *                         not contain an Army unit, then that slot
983 	 *                         number is an illegal value to this method.
984 	 *
985          * @return False on error, true otherwise.
986          */
987 	//! Callback to change the Army unit being produced within a City.
988         bool cityChangeProduction(City* city, int slot);
989 
990 	//! A player's city produces an army unit.
991 	/**
992 	 * @param city  The city that has produced an army unit.
993          * @return False on error, true otherwise.
994 	 */
995 	bool cityProducesArmy(City *city);
996 
997 	//! A player has a vectored army unit arrive somewhere.
998 	bool vectoredUnitArrives(VectoredUnit *unit);
999 
1000 	//! Shut down a city's production due to insufficent funds.
1001 	void cityTooPoorToProduce(City *city, int slot);
1002 
1003         /**
1004 	 * Called so that the player can decide what to do with a newly
1005 	 * conquered city.  For human players this method presents the dialog
1006 	 * that asks the user what should be done (Razing, Pillaging, etc).
1007 	 * For the computer players this method is for deciding what to do.
1008 	 * The decision is made by emitting one of the following signals:
1009 	 * srazingCity, spillagingCity, ssackingCity, soccupyingCity.
1010 	 *
1011          * @param  city   The newly conquered city.
1012 	 *
1013          * @return True if everything went well.
1014          */
1015 	//! Decision callback for what to do if a city is invaded.
1016         virtual void invadeCity(City* city) = 0;
1017 
1018         //! Decision callback for what to do when a hero shows up.
1019         virtual bool chooseHero(HeroProto *hero, City *city, int gold) = 0;
1020 
1021         //! Decision callback for what reward to pick when at a sage.
1022         virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack) = 0;
1023 
1024         //! Decision callback for if to commit treachery or not.
1025 	virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos) = 0;
1026 
1027         //! Decision callback for when a hero gains a level.
1028         virtual Army::Stat chooseStat(Hero *hero) = 0;
1029 
1030         //! Decision callback for when a hero visits a temple.
1031         virtual bool chooseQuest(Hero *hero) = 0;
1032 
1033         //! Decision callback for when an ai player considers going to a ruin.
1034         virtual bool computerChooseVisitRuin(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns) = 0;
1035         //! Decision callback for when an ai player considers picking up a bag.
1036         virtual bool computerChoosePickupBag(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns) = 0;
1037         //! Decision callback for when the ai going to a temple.
1038         virtual bool computerChooseVisitTempleForBlessing(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns) = 0;
1039         //! Decision callback for when the ai considers obtaining a quest.
1040         virtual bool computerChooseVisitTempleForQuest(Stack *stack, Vector<int> dest, guint32 moves, guint32 turns) = 0;
1041         //! Decision callback for considering the next target in a quest.
1042         virtual bool computerChooseContinueQuest(Stack *stack, Quest *quest, Vector<int> dest, guint32 moves, guint32 turns) = 0;
1043 
1044 	// Player related actions the player can take.
1045 
1046         /**
1047 	 * This function is called when a player's turn starts.
1048 	 * For AI players this function should start the algorithm.
1049 	 * Results in a History_StartTurn event going into the player's
1050 	 * Historylist.
1051          *
1052          * @return True if everything went well.
1053          */
1054 	//! Callback to start a Player's turn.
1055         virtual bool startTurn() = 0;
1056 
1057         virtual void abortTurn() = 0;
1058 
1059         /**
1060 	 * This function is called before a player's turn starts.
1061          * The idea here is that it happens before heroes are recruited,
1062          * and before new army units show up in cities.
1063          */
1064 	//! Initialise a Player's turn.
1065         void initTurn();
1066 
1067         virtual void endTurn() = 0;
1068 
1069         //! record the player's score for this round.
1070         void reportEndOfRound(guint32 score);
1071 
1072         //! record the player's end of turn.
1073         void reportEndOfTurn();
1074 
1075         /**
1076 	 * This method gives the player the specified Reward.  There are
1077 	 * various possibilities when they player is being given a reward.
1078 	 * It could be that the player has been given: some gold pieces, a
1079 	 * map that makes more of the map visible or information about the
1080 	 * location of a new ruin.  It could also be that a stack has been
1081 	 * given a number of powerful allies.  It could also be that a stack
1082 	 * contains a Hero, and the Reward is an Item for the Hero to carry.
1083          *
1084          * The caller needs to free the stackreflist and the reward.
1085 	 *
1086 	 * This callback must result in an Action_Reward element being
1087 	 * given to the addAction method.
1088          *
1089          * @param stack            The stack which has caused the reward.
1090          * @param reward           A pointer for storing the Reward being
1091 	 *                         given to the player.
1092          * @param stacks           Where the allies ended up (if any).
1093          * @param quest            true/false if we're giving this out
1094          *                         as a quest reward or not.
1095 	 *
1096          * @return False on error, true otherwise.
1097          */
1098 	//! Callback to give a Reward to the Player or the player's Stack.
1099         bool giveReward (Stack *stack, Reward *reward, StackReflist *stacks,
1100                          bool quest);
1101 
1102 	//! Give the player a new name.
1103 	void rename (Glib::ustring name);
1104 
1105         //! have a hero show up, or not.
1106         bool maybeRecruitHero ();
1107 
1108         //! Mark the player as dead. Kills all Army units in the Stacklist.
1109         void kill(bool record_action = true);
1110 
1111         //! Put the given stack into defend-mode.
1112         void stackDefend(Stack *s);
1113 
1114         //! Take the given stack out of defend-mode.
1115         void stackUndefend(Stack *s);
1116 
1117         //! Put the given stack into parked-mode.
1118         void stackPark(Stack *s);
1119 
1120         //! Take the given stack out of parked-mode.
1121         void stackUnpark(Stack *s);
1122 
1123         //! Select the given stack.
1124         void stackSelect(Stack *s);
1125 
1126         //! Deselect any and all stacks.
1127         void stackDeselect();
1128 
1129 	//! Go to a temple if we're near enough.
1130 	/**
1131 	 * Helper method to take a stack on a mission to get blessed.
1132 	 * If the method returns false initially, it means that the nearest
1133 	 * temple is unsuitable.
1134 	 * @note The idea is that this method is called over subsequent turns,
1135 	 * until the blessed parameter gets filled with a value of true.
1136 	 *
1137 	 * @param s            The stack to visit a temple.
1138 	 * @param dist         The maximum number of tiles that a temple
1139 	 *                     can be away from the stack, and be considered
1140 	 *                     for visiting.
1141 	 * @param percent_can_be_blessed  If the stack has this many army
1142 	 *                                units that have not been blessed
1143 	 *                                at the temple (expressed as a
1144 	 *                                percent), then the temple will be
1145 	 *                                considered for visiting.
1146 	 * @param blessed      Gets filled with false if the stack didn't get
1147 	 *                     blessed.  Gets filled with true if the stack
1148 	 *                     got blessed at the temple.
1149 	 * @param stack_died   Gets filled with true if the stack got killed
1150 	 *                     by an enemy stack on the same square as the
1151 	 *                     temple.
1152 	 *
1153 	 * Returns true if the stack moved, false if it stayed still.
1154 	 */
1155 	bool AI_maybeVisitTempleForBlessing(Stack *s, int dist,
1156 					    double percent_can_be_blessed,
1157 					    bool &blessed, bool &stack_died);
1158 
1159         bool AI_maybeVisitTempleForQuest(Stack *s, int dist, bool &got_quest,
1160                                          bool &stack_died);
1161 
1162         bool AI_maybeVisitRuin(Stack *s, int dist, bool &visited_ruin,
1163                                bool &stack_died);
1164 
1165         Vector<int> AI_getQuestDestination(Quest *quest, Stack *stack) const;
1166         bool AI_invadeCityQuestPreference(City *c, CityDefeatedAction &action) const;
1167         bool AI_maybeContinueQuest(Stack *s, Quest *quest,
1168                                    bool &completed_quest, bool &stack_died);
1169 
1170 	bool AI_maybePickUpItems (Stack *s, int dist, bool &picked_up,
1171 				  bool &stack_died);
1172 
1173 	/**
1174 	 * Callback to have the Player resign.  This entails disbanding
1175 	 * all of the player's stacks and then razing all of the player's
1176 	 * remaining cities.  It also removes all of the gold pieces from
1177 	 * the player's treasury.
1178 	 *
1179 	 * This callback is called when a human player wants to surrender
1180 	 * ungracefully.  Computer players do not currently consider
1181 	 * calling this method to surrender, and they use a different
1182 	 * mechanism to collectively surrender to a final human player.
1183 	 *
1184 	 * This callback must result in a Action_Resign element being
1185 	 * given to the addAction method.
1186 	 *
1187 	 */
1188         //! Callback to disband all the player's stacks and raze all cities.
1189         void resign();
1190 
1191 	//! Declare a new diplomatic state with respect to an opponent.
1192 	void declareDiplomacy(DiplomaticState state, Player *player, bool treachery);
1193 
1194 	//! Negotiate diplomatic talks with an opponent, and return a new state.
1195 	DiplomaticState negotiateDiplomacy (Player *player);
1196 
1197 	/**
1198 	 * Change the player's opinion of an opponent for the better.
1199 	 *
1200 	 * @param player    The player to improve our opinion by.
1201 	 * @param amount    The amount to improve by.  The minimum value
1202 	 *                  is 1 and the maximum value is 15.
1203 	 *
1204 	 */
1205 	//! Make your diplomatic view of another player increase.
1206 	void improveDiplomaticRelationship (Player *p, guint32 amount);
1207 
1208 	/**
1209 	 * Change all players opinion of you for the better, except for
1210 	 * possibly a single player.
1211 	 *
1212 	 * @param amount    The amount to improve.  The minimum value is 1
1213 	 *                  and the maximum value is 15.
1214 	 * @param except    Don't improve this player's view of the player.
1215 	 *
1216 	 * @note Pass except as NULL to not except a player.
1217 	 */
1218 	//! Make all other players diplomatic view of you increase.
1219 	void improveDiplomaticRelationship (guint32 amount, Player *except);
1220 
1221 	/**
1222 	 * Change the player's view of an opponent for the worse.
1223 	 *
1224 	 * @param player    The player to deteriorate our view of.
1225 	 * @param amount    The amount to deteriorate by.  The minimum value
1226 	 *                  is 1 and the maximum value is 15.
1227 	 *
1228 	 */
1229 	//! Make your diplomatic view of another player decrease.
1230 	void deteriorateDiplomaticRelationship (Player *player, guint32 amount);
1231 
1232 	/**
1233 	 * Change all players opinion of you for the worse.
1234 	 *
1235 	 * @param amount    The amount to deterioriate by.  The minimum value
1236 	 *                  is 1 and the maximum value is 15.
1237 	 */
1238 	//! Make all other players diplomatic view of you worsen
1239 	void deteriorateDiplomaticRelationship (guint32 amount);
1240 
1241 	/**
1242 	 * Change all players opinion of another player for the worse,
1243 	 * who happen to have a diplomatic state of state with you.
1244 	 *
1245 	 * @param player    The target player.
1246 	 * @param amount    The amount to deterioriate by.  The minimum value
1247 	 *                  is 1 and the maximum value is 15.
1248 	 * @param state     The state that an opponent has to be in with you,
1249 	 *                  to make the deterioration happen.
1250 	 */
1251 	//! Make players you are at state with you think less of player.
1252 	void deteriorateAlliesRelationship(Player *player, guint32 amount,
1253 					   Player::DiplomaticState state);
1254 
1255 	/**
1256 	 * Change all players opinion of another player for the better,
1257 	 * who happen to have a diplomatic state of state with you.
1258 	 *
1259 	 * @param player    The target player.
1260 	 * @param amount    The amount to improve by.  The minimum value
1261 	 *                  is 1 and the maximum value is 15.
1262 	 * @param state     The state that an opponent has to be in with you,
1263 	 *                  to make the improvement happen.
1264 	 */
1265 	//! Make players who are at STATE with PLAYER think better of you.
1266 	void improveAlliesRelationship(Player *player, guint32 amount,
1267 				       Player::DiplomaticState state);
1268 
1269 	//! Propose a new diplomatic state wrt another player
1270 	void proposeDiplomacy (DiplomaticProposal proposal, Player *player);
1271 
1272         /**
1273          * Account for the dead armies in the given list of stacks.  For
1274          * each dead army we increment a counter for that kind of army unit.
1275          */
1276         //! Keeps stats of what kind of units we killed in a battle.
1277         void tallyDeadArmyTriumphs(std::list<Stack*> &stacks);
1278 
1279 
1280 	// Signals
1281 
1282 	/**
1283 	 * @param city   The city being invaded.
1284 	 * @param loot   The gold looted.
1285 	 */
1286 	//! Emitted when the player defeats a City.
1287         sigc::signal<void, City*, int> sinvadingCity;
1288 
1289 	/**
1290 	 * @param hero   The new hero that is emerging.
1291 	 * @param city   The city in which the hero is emerging.
1292 	 * @param gold   The amount of gold pieces the hero costs.
1293 	 *
1294 	 * @return True if we're accepting a hero, false if not.
1295 	 */
1296         //! Emitted whenever a hero is recruited.
1297         sigc::signal<bool, HeroProto*, City *, int> srecruitingHero;
1298 
1299 	/**
1300 	 * @param army   The army that has gained a level.
1301 	 *
1302 	 * @return One of Army::Stat::STRENGTH, Army::Stat::MOVES, or
1303 	 *         Army::Stat::SIGHT.
1304 	 */
1305         //! Emitted when an Army advances a level; returns stat to raise.
1306         sigc::signal<Army::Stat, Hero*> sheroGainsLevel;
1307 
1308 	/**
1309 	 * @param army   The army that has gotten a medal.
1310 	 */
1311         //! Emitted whever a player's army gets a new medal.
1312         sigc::signal<void, Army*, int> snewMedalArmy;
1313 
1314 	/**
1315 	 * @param ruin    The ruin being searched.
1316 	 * @param stack   The stack doing the searching (must contain Hero).
1317          *
1318          * Returns whether or not the stack was deleted as a result.
1319 	 */
1320         //! Emitted by the player to search a ruin.
1321         sigc::signal<bool, Ruin*, Stack*> ssearchingRuin;
1322 
1323 	/**
1324 	 * @param temple  The temple being visited.
1325 	 * @param stack   The stack to be blessed.
1326          *
1327          * Returns whether or not a hero got a quest.
1328 	 */
1329         //! Emitted by the player to visit a temple.
1330         sigc::signal<bool, Temple*, Stack*> svisitingTemple;
1331 
1332 	/**
1333 	 * @param city   The city being occupied.
1334 	 * @param stack  The stack doing the occupying.
1335 	 */
1336 	//! Emitted when the player occupies a City.
1337         sigc::signal<void, City*, Stack*> soccupyingCity;
1338 
1339 	/**
1340 	 * @param city        The city that has been pillaged.
1341 	 * @param stack       The stack doing the pillaging.
1342 	 * @param gold        The amount of gold pieces pillaged.
1343 	 * @param army_types  The list of Army types traded-in for gold pieces.
1344 	 */
1345         //! Emitted whenever the player pillages a city.
1346         sigc::signal<void, City*, Stack*, int, guint32> spillagingCity;
1347 
1348 	/**
1349 	 * @param city        The city that has been sacked.
1350 	 * @param stack       The stack doing the sacked.
1351 	 * @param gold        The amount of gold pieces sacked.
1352 	 * @param army_types  The list of Army types traded-in for gold pieces.
1353 	 */
1354         //! Emitted whenever the player sacks a city.
1355         sigc::signal<void, City*, Stack*, int, std::list<guint32> > ssackingCity;
1356 
1357 	/**
1358 	 * @param city        The city that has been razed.
1359 	 * @param stack       The razing stack.
1360 	 */
1361         //! Emitted whenever the player razes a city.
1362         sigc::signal<void, City*, Stack*> srazingCity;
1363 
1364 	/**
1365 	 * Emitted when the player's treasury has been changed.
1366 	 */
1367         //! Emitted whenever a player's stats changes.
1368         sigc::signal<void> schangingStats;
1369 
1370 	//! Emitted whenever a computer player does something of note.
1371         sigc::signal<void, Glib::ustring> schangingStatus;
1372 
1373 	//! Emitted whenever any player does anything at all.
1374 	sigc::signal<void> sbusy;
1375 
1376 	/**
1377 	 * Emitted when the player's stack moves, is disbanded, gets blessed,
1378 	 * searches a ruin, or is otherwise altered.
1379 	 *
1380 	 * @param stack    The stack that has been altered.
1381 	 */
1382         //! Emitted whenever the stack's status has changed.
1383         sigc::signal<void, Stack*> supdatingStack;
1384 
1385         //! Emitted whenever a hero drops a bag.
1386         sigc::signal<void> sbagdropped;
1387 
1388         //! Emitted whenever the active stack comes to a stop.
1389         sigc::signal<void, Stack*> shaltedStack;
1390 
1391         //! Emitted whenever the active stack comes to a stop.
1392         sigc::signal<void> sstoppingStack;
1393 
1394         //! Emitted whenever the active stack starts moving.
1395         sigc::signal<void, Stack*> smovingStack;
1396 
1397 	/**
1398 	 * Emitted whenever a city is conquered or razed.
1399 	 *
1400 	 * @param city     The city that has been altered.
1401 	 */
1402         //! Emitted whenever the status of a city has changed.
1403         sigc::signal<void, City*> supdatingCity;
1404 
1405 	/**
1406 	 * @param fight  The details of the upcoming fight.
1407 	 */
1408 	//! Emitted when a fight has started against a city or stack.
1409         sigc::signal<void, Fight &> fight_started;
1410 
1411 	/**
1412 	 * @param city     The city we attacked.
1413 	 * @param result   If we won or not.
1414 	 */
1415 	//! Emitted after we attack a city.
1416         sigc::signal<void, City *, Fight::Result> cityfight_finished;
1417 
1418 	/**
1419 	 * @param attacker The player's attacking stack.
1420 	 * @param keeper   The keeper of the ruin.
1421 	 */
1422 	//! Emitted when a fight in a ruin is started.
1423         sigc::signal<void, Stack *, Keeper *> ruinfight_started;
1424 
1425 	/**
1426 	 * @param result   If we defeated the ruin's keeper or not.
1427 	 */
1428 	//! Emitted when a fight in a ruin has finished.
1429         sigc::signal<void, Fight::Result> ruinfight_finished;
1430 
1431 	/**
1432 	 * @param chance   The percent chance that we will prevail in battle.
1433 	 */
1434 	//! Emitted when a player asks for help from a military advisor.
1435         sigc::signal<void, float> advice_asked;
1436 
1437 	//! Signal raised when a stack is considering an act of treachery.
1438         sigc::signal<bool, Stack *, Player *, Vector<int> > streacheryStack;
1439 
1440         //! Player would like to end the turn.
1441         sigc::signal<void> ending_turn;
1442 
1443         //! Player has confirmed to abort the turn.
1444         sigc::signal<void> aborted_turn;
1445 
1446         sigc::signal<void, int> hero_arrives_with_allies;
1447 
1448         sigc::signal<void, Item*> using_item;
1449 
1450         sigc::signal<void, Action *, guint32> acting;
1451         sigc::signal<void, History *, guint32> history_written;
1452 
1453         //! Results of using items
1454         sigc::signal<void, Player*, guint32> stole_gold;
1455         sigc::signal<void, Player*, guint32> sunk_ships;
1456         sigc::signal<void, Hero *, guint32> bags_picked_up;
1457         sigc::signal<void, Hero *, guint32> mp_added_to_hero_stack;
1458         sigc::signal<void, Hero *, Glib::ustring, guint32> worms_killed;
1459         sigc::signal<void, Hero *> bridge_burned;
1460         sigc::signal<void, Hero *, Ruin*, Glib::ustring> keeper_captured;
1461         sigc::signal<void, Hero *, Glib::ustring> monster_summoned;
1462         sigc::signal<void, Hero *, Glib::ustring, guint32> city_diseased;
1463         sigc::signal<void, Hero *, Glib::ustring, Glib::ustring, guint32> city_defended;
1464         sigc::signal<void, Hero *, Glib::ustring, guint32> city_persuaded;
1465         sigc::signal<void, Hero *, Glib::ustring> stack_teleported;
1466 
1467         sigc::signal<void, Glib::ustring> save_game;
1468         sigc::signal<guint32> get_round;
1469 	//! Check the history to see if we ever conquered the given city.
1470 
1471 
1472 	Stack *stackSplitArmy(Stack *stack, Army *a);
1473 	Stack *stackSplitArmies(Stack *stack, std::list<guint32> armies);
1474 	Stack *stackSplitArmies(Stack *stack, std::list<Army*> armies);
1475 
1476 	// Static Methods
1477 
1478 	static Glib::ustring playerTypeToString(const Player::Type type);
1479 	static Player::Type playerTypeFromString(const Glib::ustring str);
1480 	//! is it safe to vector from the given city?
1481 	static bool safeFromAttack(City *c, guint32 safe_mp, guint32 min_defenders);
1482         /**
1483 	 * Make a new player with the given parameters.
1484          *
1485          * @note The neutral player must still be inserted as neutral player
1486          * manually!
1487          *
1488          * @param name     The name of the player.
1489          * @param armyset  The Id of the player's Armyset.
1490          * @param color    The player's colour.
1491          * @param width    The width of the player's FogMap.
1492          * @param height   The height of the player's FogMap.
1493          * @param type     The player's type (Player::Type).
1494          */
1495 	//! Create a player.
1496         static Player* create(Glib::ustring name, guint32 armyset,
1497 			      Gdk::RGBA color, int width, int height,
1498 			      Type type);
1499 
1500         /**
1501 	 * Copies a player to a different type.
1502          *
1503          * @note This method does not change ownerships! (e.g. of cities)
1504          *
1505          * @param player   The original player.
1506          * @param type     The type we want to get out (Player::Type).
1507          * @return A new player with the old player's data and the given type.
1508          */
1509 	//! Create a new player from another player.
1510         static Player* create(Player* orig, Type type);
1511 
1512         /**
1513 	 * Loads a player from a file.
1514          *
1515          * This is a bit inconsistent with other classes, but with players you
1516          * have the problem that there are different types with different
1517          * classes. So we need a static member function which looks which
1518          * player type to load and calls the constructor of the appropriate
1519          * class.
1520          *
1521          * @param helper       the opened saved-game file to read from.
1522 	 *
1523 	 * @return The loaded Player instance.
1524          */
1525         static Player* loadPlayer(XML_Helper* helper);
1526 
1527 
1528 
1529     protected:
1530         // do some fight cleaning up, setting
1531         void cleanupAfterFight(std::list<Stack*> &attackers,
1532                                std::list<Stack*> &defenders,
1533                                std::list<History*> &attacker_history,
1534                                std::list<History*> &defender_history);
1535 
1536         void clearHistorylist(std::list<History*> &history);
1537         //! Move stack s one step forward on it's Path.
1538         bool stackMoveOneStep(Stack* s);
1539 
1540 	//! Move stack s one step forward on it's Path, over another stack.
1541 	bool stackMoveOneStepOverTooLargeFriendlyStacks(Stack *s);
1542 
1543         void addAction(Action *action);
1544 
1545         // DATA
1546 	//! The player's colour.
1547 	/**
1548 	 * Mask portions of images are shaded in this colour.
1549 	 */
1550 	Gdk::RGBA d_color;
1551 
1552 	//! The name of the Player.
1553         Glib::ustring d_name;
1554 
1555 	//! The ArmySet of the Player.
1556         guint32 d_armyset;
1557 
1558 	//! The number of gold pieces the Player has in the treasury.
1559         int d_gold;
1560 
1561 	//! Whether or not this player is dead.
1562         bool d_dead;
1563 
1564 	//! Whether or not this player can be killed.
1565         bool d_immortal;
1566 
1567 	//! The kind of Player (see Player::Type).
1568         guint32 d_type;
1569 
1570 	//! A unique numeric identifier identifying this Player.
1571         guint32 d_id;
1572 
1573 	//! A list of actions that this Player made this turn.
1574         std::list<Action*> d_actions;
1575 
1576 	//! A list of "headlines" for this Player for the whole game.
1577         std::list<History*> d_history;
1578 
1579 	//! A list of the Player's Stack objects.
1580         Stacklist* d_stacklist;
1581 
1582 	//! What the player can see on the hidden map.
1583         FogMap* d_fogmap;
1584 
1585 	//! A tally of the kills that this player has made
1586         Triumphs* d_triumphs;
1587 
1588 	//! The order in which this Player's army types fight in battle.
1589 	/**
1590 	 * @note This value is related to the Player's ArmySet.
1591 	 */
1592 	std::list<guint32> d_fight_order;
1593 
1594 	//! How many gold pieces the Player paid out in the last turn.
1595 	guint32 d_upkeep;
1596 
1597 	//! How many gold pieces the Player made from taxes in the last turn.
1598 	guint32 d_income;
1599 
1600 	//! The diplomatic view that this Player has of each other Player.
1601 	DiplomaticState d_diplomatic_state[MAX_PLAYERS];
1602 
1603 	//! The diplomatic rank this Player has among all other Players.
1604 	guint32 d_diplomatic_rank;
1605 
1606 	//! The title that goes along with the diplomatic rank.
1607 	Glib::ustring d_diplomatic_title;
1608 
1609 	//! The proposals that this Player is making this turn.
1610 	DiplomaticProposal d_diplomatic_proposal[MAX_PLAYERS];
1611 
1612 	//! A quantification of how much this Player likes every other Player.
1613 	guint32 d_diplomatic_score[MAX_PLAYERS];
1614 
1615 	//! Whether or not this player is observable by the user.
1616 	bool d_observable;
1617 
1618 	//! Whether or not this player has surrendered.
1619 	bool surrendered;
1620 
1621         //! Whether or not someone has closed the main game window.
1622         bool abort_requested;
1623 
1624 	//! assists in scorekeeping for diplomacy
1625 	void alterDiplomaticRelationshipScore (Player *player, int amount);
1626 
1627 
1628         // return the new stack if split succeeded
1629         Stack *doStackSplit(Stack *s);
1630 	bool doStackSplitArmy(Stack *s, Army *a, Stack *& new_stack);
1631         void doStackJoin(Stack* receiver, Stack* joining);
1632         int doStackVisitTemple(Stack *s);
1633         void doCityOccupy(City *c);
1634         void doCityPillage(City *c, int& gold, int* pillaged_army_type);
1635         void doCitySack(City *c, int& gold, std::list<guint32> *sacked_types);
1636         void doCityRaze(City *c);
1637         void doCityBuyProduction(City *c, int slot, int type);
1638         void doCityChangeProduction(City *c, int slot);
1639         void doGiveReward(Stack *s, Reward *reward, StackReflist *stacks);
1640         void doHeroDropItem(Hero *hero, Item *item, Vector<int> pos, bool &splash);
1641 	bool doHeroDropAllItems(Hero *h, Vector<int> pos, bool &splash);
1642         bool doHeroUseItem(Hero *h, Item *item, Player *victim, City *friendly_city, City *enemy_city, City *neutral_city, City *city);
1643         void doHeroPickupItem(Hero *hero, Item *item, Vector<int> pos);
1644         bool doHeroPickupAllItems(Hero *h, Vector<int> pos);
1645         void doHeroGainsLevel(Hero *hero, Army::Stat stat);
1646         bool doStackDisband(Stack *stack);
1647         void doStacksReset();
1648         void doRuinsReset();
1649         void doCollectTaxesAndPayUpkeep();
1650         void doSignpostChange(Signpost *signpost, Glib::ustring message);
1651         void doCityRename(City *c, Glib::ustring name);
1652         void doVectorFromCity(City * c, Vector<int> dest);
1653         void doSetFightOrder(std::list<guint32> order);
1654         void doResign(std::list<History*> &history);
1655         void doHeroPlantStandard(Hero *hero, Item *item, Vector<int> pos);
1656         void doDeclareDiplomacy (DiplomaticState state, Player *player);
1657         void doProposeDiplomacy (DiplomaticProposal proposal, Player *player);
1658         void doConquerCity(City *city);
1659 	void doLootCity(Player *looted, guint32 added, guint32 subtracted);
1660         Hero* doRecruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally, StackReflist *stacks);
1661         void doRename(Glib::ustring name);
1662 	void doKill();
1663         void doStackDefend(Stack *stack);
1664         void doStackUndefend(Stack *stack);
1665         void doStackPark(Stack *stack);
1666         void doStackUnpark(Stack *stack);
1667         void doStackSelect(Stack *stack);
1668         void doStackDeselect();
1669 	const Army *doCityProducesArmy(City *city, Stack *& stack, bool &vectored);
1670 	Army *doVectoredUnitArrives(VectoredUnit *unit, Stack *& stack);
1671 	bool doChangeVectorDestination(Vector<int> src, Vector<int> dest,
1672 				       std::list<City*> &vectored);
1673 
1674 	bool doStackSplitArmies(Stack *stack, std::list<guint32> armies,
1675 				Stack *&new_stack);
1676 
1677         Quest* doHeroGetQuest(Hero *hero, bool except_raze);
1678 
1679         void doStackSort(Stack *s, std::list<guint32> army_ids);
1680 
1681         void doStackSearchRuin(Stack *s, Ruin *r, Fight::Result result);
1682         /**
1683 	 * Called to adjudicate a fight between two lists of stacks in a ruin.
1684          *
1685          * @param attacker         The list of attacking stacks.  This list
1686 	 *                         consists of a single Stack containing at
1687 	 *                         least one Hero unit.
1688          * @param defender         The list of defending stacks.  This list
1689 	 *                         consists of a single Army unit in a
1690 	 *                         single Stack.
1691          * @param stackdied        Whether or not the stack went away because
1692          *                         of the searching of the ruin.
1693 	 *
1694          *  If the defender dies in the fight, the defender pointer is set
1695 	 *  to 0.
1696 	 *  If the Hero loses the battle, only the Hero unit is removed
1697 	 *  from the attacker's stack.
1698          *
1699          * @return One of Fight::ATTACKER_WON, Fight::DEFENDER_WON, or
1700 	 *         Fight::DRAW (Fight::Result).
1701          */
1702 	//! Callback to adjudicate fights in ruins.
1703         Fight::Result stackRuinFight(Stack** attacker, Keeper* defender, bool &stackdied, std::list<History*> &attacker_history, std::list<History*> &defender_history);
1704 
1705 	void AI_maybeBuyScout(City *c);
1706 
1707 	bool AI_maybeVector(City *c, guint32 safe_mp, guint32 min_defenders,
1708 			    City *target, City **vector_city = NULL);
1709 
1710 	void AI_setupVectoring(guint32 safe_mp, guint32 min_defenders,
1711 			       guint32 mp_to_front);
1712 
1713 	bool AI_maybeDisband(Stack *s, City *city, guint32 min_defenders,
1714 			     int safe_mp, bool &stack_killed);
1715 	bool AI_maybeDisband(Stack *s, int safe_mp, bool &stack_killed);
1716 
1717 	void pruneActionlist();
1718 	static void pruneActionlist(std::list<Action*> &actions);
1719 
1720     private:
1721         //! Loads the subdata of a player (actions and stacklist)
1722         bool load(Glib::ustring tag, XML_Helper* helper);
1723 
1724         /**
1725 	 * Returns all heroes in the given list of stacks.
1726          *
1727          * @param stacks           the list of stacks which is searched.
1728          * @param heroes           Return a list of id's of the heroes found.
1729          */
1730 	//! Get heroes.
1731         void getHeroes(const std::list<Stack*> stacks,
1732 		       std::vector<guint32>& heroes);
1733 
1734 
1735         /**
1736 	 * Goes through a list of stacks and removes all armies with less
1737          * than 1 hitpoint.  It also removes empty stacks.
1738          * This function also heals regenerating units at the end of combat.
1739          *
1740          * @param stacks           The list searched for dead armies.
1741          * @param culprits         The list of heroes responsible for killing
1742 	 *                         the armies.  This is needed for tracking
1743 	 *                         the progress of a Quest.
1744          * @return The number of armies removed because they were killed.
1745          */
1746 	//! Remove dead Armies from a list of stacks after a fight.
1747         guint32 removeDeadArmies(std::list<Stack*>& stacks,
1748                                 std::vector<guint32>& culprits,
1749                                 std::list<History*> &history);
1750 
1751         guint32 removeDeadArmies(std::list<Stack*>& stacks, std::list<History*> &history);
1752 
1753         guint32 removeDeadArmies(Stack *stack, std::list<History*> &history);
1754 
1755         double countXPFromDeadArmies(std::list<Stack*>& stacks);
1756 
1757         void handleDeadHeroes(std::list<Stack*> &stacks, std::list<History*> &history);
1758         History* handleDeadHero(Hero *h, Maptile *tile, Vector<int> pos);
1759 
1760         void handleDeadArmiesForQuests(std::list<Stack*> &stacks, std::vector<guint32> &culprits);
1761 
1762         /**
1763 	 * Increases the number of experience points of a stack
1764          * the number of battles and checks if an army can get a medal
1765          *
1766          * This functions takes a number of experience points and distributes
1767          * them equally over all armies in the stack list. Therefore, the less
1768          * armies fight, the more experience the single armies get. It emits a
1769          * signal when a unit gains a level.
1770          *
1771          * @param stacks           A list of all stacks gaining experience.
1772          * @param xp_sum           The number of XP to distribute.
1773          */
1774 	//! update Army state after a Fight.
1775         void updateArmyValues(std::list<Stack*>& stacks, double xp_sum);
1776 
1777 
1778         /**
1779 	 * Called to move a Stack to a specified position.
1780          *
1781          * The Path is calculated on the fly unless follow is set to true.
1782 	 * In this case, an existing path is checked and iterated over.
1783 	 * This is useful if a stack didn't reach its target within one
1784 	 * round and should continue the movement.
1785          *
1786 	 * This callback must result in an Action_Move element being
1787 	 * given to the addAction method.
1788 	 *
1789          * @param s                The stack to be moved.
1790          * @param dest             The destination of the move.
1791          * @param follow           If set to false, calculate the path.
1792 	 *
1793          * @return False on error, true otherwise.
1794          */
1795         //! Callback to move a stack on the map.
1796         MoveResult *stackMove(Stack* s, Vector<int> dest, bool follow);
1797 
1798 	bool nextStepOnEnemyStackOrCity(Stack *s) const;
1799 
1800         void lootCity(City *city, Player *looted);
1801 	void calculateLoot(Player *looted, guint32 &added, guint32 &subtracted);
1802         void takeCityInPossession(City* c);
1803 	static void pruneCityVectorings(std::list<Action*> &actions);
1804 	static void pruneCityProductions(std::list<Action*> &actions);
1805 
1806         std::list<Action *> getActionsThisTurn(int type) const;
1807 
1808         bool computerSearch(Stack *s, MoveResult *r);
1809 };
1810 
1811 Fight::Result ruinfight (Stack **attacker, Stack **defender);
1812 #endif // PLAYER_H
1813 
1814 // End of file
1815