initial commit, lordsawar source, slightly modified
[lordsawar] / src / player.h
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
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 #ifndef PLAYER_H
25 #define PLAYER_H
26
27 #include <string>
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 Stacklist;
41 class XML_Helper;
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
65 //! The abstract player class.
66 /** 
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:
70  *
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
76  *
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.
82  *
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.
87  *
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.
94  *
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.
104  *
105  *
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.
110  *
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.
116  */
117
118 class Player: public sigc::trackable
119 {
120     public:
121         //! The xml tag of this object in a saved-game file.
122         static std::string d_tag; 
123
124         //! The available player types.
125         enum Type {
126           //! Local human player.  See the RealPlayer class.
127           HUMAN = 0, 
128           //! Local computer player (Easy).  See the AI_Fast class.
129           AI_FAST = 1, 
130           //! Local computer player (Neutral).  See the AI_Dummy class.
131           AI_DUMMY = 2, 
132           //! Local computer player (Hard).  See the AI_Smart class.
133           AI_SMART = 4,
134           //! Remote player.  See the NetworkPlayer class.
135           NETWORKED = 8
136         };
137
138         //! Every player has a diplomatic state with every other player.
139         enum DiplomaticState {
140           //! Can't attack opponent's stacks anywhere.
141           AT_PEACE = 1, 
142           //! Can't attack opponent's stacks in cities.
143           AT_WAR_IN_FIELD = 2, 
144           //! Can attack opponent's stack everywhere.
145           AT_WAR = 3
146         };
147
148         //! Every player has a diplomatic proposal to every other player.
149         enum DiplomaticProposal {
150           //! Offer to keep the status-quo with the opponent.
151           NO_PROPOSAL = 0, 
152           //! Offer peace to an opponent.
153           PROPOSE_PEACE = 1, 
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.
157           PROPOSE_WAR = 3 
158         };
159
160         /** 
161          * Make a new player.  
162          * @note AI_Fast, AI_Dummy, AI_Smart and RealPlayer use this 
163          * constructor to make new Players.
164          *
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.
173          */
174         //! Default constructor.
175         Player (std::string name, guint32 armyset, Gdk::Color color, int width,
176                 int height, Type type, int player_no = -1);
177
178         //! Copy constructor.
179         Player(const Player&);
180
181         //! Constructor for loading. See XML_Helper for documentation.
182         Player(XML_Helper* helper);
183
184         //! Destructor.
185         virtual ~Player();
186
187
188         // Set Methods
189
190         //! Change the player's name.
191         void setName(std::string name){d_name = name;}
192         
193         //! Change the player's Armyset.
194         void setArmyset(guint32 armyset){d_armyset = armyset;}
195
196         //! Set the type of the player (to be used by derived classes only.)
197         void setType(Type type) {d_type = type;}
198
199         //! Change the player's colour.
200         void setColor(Gdk::Color c);
201
202         //! Makes a player unable to die, even when having no units or cities.
203         void setMortality(bool ismortal) {d_immortal = !ismortal;}
204         
205         //! Change the number of gold pieces of the player has.
206         void setGold(int gold){d_gold = gold;}
207
208         //! Set this player's rank in diplomatic matters.  Starts at 1.
209         void setDiplomaticRank (guint32 rank) {d_diplomatic_rank = rank;};
210
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;};
215
216         //! Revive the player, this does not provide any cities.
217         void revive() {d_dead = false;}
218
219         //! Set whether or not this player has surrendered.
220         /*
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.
226          */
227         void setSurrendered(bool surr);
228
229         //! Set the fight order of the player.
230         void setFightOrder(std::list<guint32> order);
231
232
233
234         // Get Methods
235
236         //! Returns whether or not this is a computer player.
237         virtual bool isComputer() const = 0;
238
239         //! Returns the unique ID of the player.
240         guint32 getId() const {return d_id;}
241
242         //! Returns the list of player's events. 
243         std::list<History*>* getHistorylist() {return &d_history;}
244
245         //! Return the Id of the player's Armyset.
246         guint32 getArmyset() const {return d_armyset;}
247
248         //! Return whether or not the player has been killed.
249         bool isDead() const {return d_dead;}
250
251         //! Returns whether a player is immortal or not.
252         bool isImmortal() const {return d_immortal;}
253
254         //! Return the type of the player (Player::Type).
255         guint32 getType() const {return d_type;}
256
257         /**
258          * Return the amount of upkeep in gold pieces that the player spent 
259          * in the previous turn.  
260          */
261         //! Return the upkeep.
262         guint32 getUpkeep() const {return d_upkeep;}
263
264         //! Return the income from all of the player's cities.
265         guint32 getIncome () const {return d_income;}
266
267         //! What diplomatic rank does this player have?  Starts at 1.
268         guint32 getDiplomaticRank () const {return d_diplomatic_rank;};
269
270         //! What rank do we have?  As a name.
271         std::string getDiplomaticTitle() const {return d_diplomatic_title;};
272
273         //! Returns the colour of the player.
274         Gdk::Color getColor() const {return d_color;}
275
276         //! Returns the amount of gold pieces the player has in the treasury.
277         int getGold() const {return d_gold;}
278
279         //! Returns the name of the player.
280         std::string getName(bool translate = true) const;
281
282         //! Returns the player's current score.
283         guint32 getScore() const;
284
285         //! Returns the list of stacks owned by the player.
286         Stacklist* getStacklist() const {return d_stacklist;}
287
288         //! Get the FogMap of the player.
289         FogMap* getFogMap() const {return d_fogmap;}
290
291         //! Get the Triumphs of the player.
292         Triumphs* getTriumphs() const {return d_triumphs;}
293
294         //! Get the fight order of the player.
295         std::list<guint32> getFightOrder() const {return d_fight_order;}
296
297         bool isObservable() const {return d_observable;};
298
299         bool abortRequested() const {return abort_requested;};
300
301         // Methods that operate on the player's action list.
302
303         //! Returns a list of the players unit production actions for this turn.
304         std::list<Action_Produce *> getUnitsProducedThisTurn() const;
305
306         //! Return the amount of gold pieces for the newly produced armies.
307         guint32 getCostOfUnitsProducedThisTurn() const;
308
309         //! Returns a list of the player's actions to show in a report.
310         std::list<Action *> getReportableActions() const;
311
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;
318
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;
323
324         //! Remove every Action from the list of the player's actions.
325         void clearActionlist();
326
327         //! Show debugging information for the player's Action list.
328         void dumpActionlist() const;
329
330         //! Wrap the player's actions for transport over the network.
331         void saveNetworkActions(XML_Helper *helper) const;
332
333         //! Check to see if it's our turn.
334         bool hasAlreadyInitializedTurn() const;
335
336         //! Check to see if we've ended our turn this round.
337         bool hasAlreadyEndedTurn() const;
338
339         //! Return the movement history of a given stack for this turn.
340         std::list<Vector<int> > getStackTrack(Stack *s) const;
341
342
343         // Methods that operate on the player's history list.
344
345         //! Remove every History element from the list of the player's events.
346         void clearHistorylist();
347
348         //! Show debugging information for the player's History list.
349         void dumpHistorylist() const;
350
351         //! Check the player's history to see if we've conquered the given city.
352         bool conqueredCity(City *c) const;
353
354         //! Check the player's history to see if we've explored the given ruin.
355         bool searchedRuin(Ruin *r) const;
356         
357         //! Return a list of history events for the given hero.
358         std::list<History *> getHistoryForHeroId(guint32 id) const;
359
360         //! Return a list of history events for the given city.
361         std::list<History *> getHistoryForCityId(guint32 id) const;
362
363         //! Count the turns we've completed.
364         guint32 countEndTurnHistoryEntries() const;
365
366         //! Add a new history item to the player's history list.
367         void addHistory(History *history);
368
369
370         // Methods that operate on the player's stacklist
371
372         //! Return a list of the player's heroes.
373         std::list<Hero*> getHeroes() const;
374
375         //! Return the grand total of the player's armies.
376         guint32 countArmies() const;
377
378         //! Return the number of the player's armies that are awardable.
379         guint32 countAllies() const;
380
381         //! Return the player's currently selected stack.
382         Stack * getActivestack() const;
383
384         //! Select this stack.
385         void setActivestack(Stack *);
386
387         //! Return the position on the map for the given army unit.
388         Vector<int> getPositionOfArmyById(guint32 id) const;
389
390         //! Remove movement points from all of the player's army units.
391         void immobilize();
392
393         //! Remove all stacks from the player's list.
394         void clearStacklist();
395
396         //! Add a Stack to the player's Stacklist.
397         void addStack(Stack* stack);
398
399         //! Remove a Stack from the player's Stacklist.
400         bool deleteStack(Stack* stack);
401
402
403         // Methods that operate on the player's diplomatic data members.
404
405         //! Query the diplomatic state this player has with an opponent.
406         DiplomaticState getDiplomaticState (Player *player) const;
407
408         //! Query the diplomatic proposal we're making to an opponent.
409         DiplomaticProposal getDiplomaticProposal (Player *player) const;
410
411         //! Get the diplomatic score with respect to an opponent.
412         guint32 getDiplomaticScore (Player *p) const;
413
414
415         void adjustDiplomacyFromConqueringCity(City *city);
416
417
418
419         //! Add some gold pieces to the player's treasury.
420         void addGold(int gold);
421
422         //! Subtract gold pieces from the player's treasury.
423         void withdrawGold(int gold);
424
425         /**
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.
429          */
430         //! Calculates the upkeep.
431         void calculateUpkeep();
432
433         /**
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.
437          */
438         //! Calculates the upkeep.
439         void calculateIncome();
440
441
442         //! Remove all fog from the player's map.
443         void clearFogMap();
444
445
446         /** 
447          * Saves the player data to a file.
448          *
449          * @param helper     The opened saved-game file to write to.
450          *
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.
454          */
455         //! Save the player to a saved-game file.
456         virtual bool save(XML_Helper* helper) const;
457
458
459
460         /** 
461          * Called to merge two stacks into one.
462          *
463          * This callback must result in an Action_Join element being 
464          * given to the addAction method.
465          *
466          * @param receiver     The receiving stack.
467          * @param joining      The joining stack, destroyed after the join.
468          *
469          * @return False if an error occured, else true.
470          */
471         //! Callback to merge two stacks into one.
472         bool stackJoin(Stack* receiver, Stack* joining);
473
474         /**
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.
478          *
479          * This callback must result in an Action_Move element being 
480          * given to the addAction method.
481          *
482          * @param s             The stack to be moved.
483          *
484          * @return False if an error occured, else true.
485          */
486         //! Callback to move a stack on the map.
487         bool stackMove(Stack* s);
488         MoveResult* stackMove(Stack* s, Vector<int> dest);
489
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);
495
496         /** 
497          * Called to adjudicate a fight between two lists of stacks.
498          * 
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.
503          *
504          * This callback must result in an Action_Fight element being 
505          * given to the addAction method.
506          *
507          * @param attacker         The list of attacking stacks.
508          * @param defender         The list of defending stacks.
509          *
510          * @return One of Fight::ATTACKER_WON, Fight::DEFENDER_WON, or
511          *         Fight::DRAW (Fight::Result).
512          */
513         //! Callback to adjudicate fights.
514         Fight::Result stackFight(Stack** attacker, Stack** defender);
515         
516         /** 
517          * Called to adjudicate a fight between two lists of stacks in a ruin.
518          *
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 
524          *                         single Stack.
525          *
526          *  If the defender dies in the fight, the defender pointer is set 
527          *  to 0.
528          *  If the Hero loses the battle, only the Hero unit is removed
529          *  from the attacker's stack.
530          *
531          * @return One of Fight::ATTACKER_WON, Fight::DEFENDER_WON, or
532          *         Fight::DRAW (Fight::Result).
533          */
534         //! Callback to adjudicate fights in ruins.
535         Fight::Result stackRuinFight(Stack** attacker, Stack** defender);
536         /** 
537          * A stack searches a ruin.  The stack must contain a hero.
538          *
539          * This callback must result in an Action_Ruin element being 
540          * given to the addAction method.
541          *
542          * @param stack            The stack which searches the ruin.
543          * @param ruin             The ruin to be searched.
544          *
545          * @return reward          A pointer to the received Reward.  Return 
546          *                         NULL if the keeper could not be defeated.
547          */
548         //! Callback to have a stack visit a ruin.
549         Reward* stackSearchRuin(Stack* stack, Ruin* ruin);
550
551         /** 
552          * A stack visits a temple and becomes blessed. By blessing, the 
553          * strength of all armies rises by 1.
554          *
555          * This callback must result in an Action_Temple element being 
556          * given to the addAction method.
557          *
558          * @param stack            The stack visiting the temple.
559          * @param temple           The visited temple.
560          *
561          * @return The number of blessed armies.
562          */
563         //! Callback to have a stack visit a temple.
564         int stackVisitTemple(Stack* stack, Temple* temple);
565         
566         /** 
567          * Called to ask the military advisor about what would happen 
568          * if the stack attacked the tile.
569          *
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 
573          *                        not.
574          *
575          * @return The percent chance to win the fight.  The maximum value
576          *         is 100.0, and the minimum value is 0.0.
577          */
578         //! Callback to calculate the odds of winning a fight.
579         float stackFightAdvise(Stack* stack, Vector<int> tile,
580                                bool intense_combat);
581
582         /**
583          * Disbanding a player's stack removes it from the game.  Disbanding
584          * stacks saves upkeep for unwanted Army units.
585          *
586          * This callback must result in an Action_Disband element being 
587          * given to the addAction method.
588          *
589          * @param stack            The stack to disband.
590          *
591          * @return False on error, true otherwise.
592          */
593         //! Callback to disband a player's stack.
594         bool stackDisband(Stack* stack);
595
596         /**
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.
600          *
601          * For this callback to make sense, you should only change
602          * Signposts for which we have a Stack co-located.
603          *
604          * This callback must result in a Action_ModifySignpost element being
605          * given to the addAction method.
606          *
607          * @param signpost         The signpost to modify.
608          * @param message          The new text to inscribe onto the sign.
609          *
610          * @return False on error, true otherwise.
611          */
612         //! Change the text on a signpost.
613         bool signpostChange(Signpost *signpost, std::string message);
614
615
616
617
618         // Hero related actions the player can take.
619
620         /** 
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.
625          *
626          * Computer players don't currently consider vectoring units, so
627          * only human players use this method.
628          *
629          * This callback must result in an Action_Plant element being added
630          * to the player's Action list (Player::d_actions).
631          *
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.
636          *
637          * @return False on error, true otherwise.
638          */
639         //! Callback to plant a player's standard.
640         bool heroPlantStandard(Stack *stack);
641
642         /**
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.
646          * 
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
649          * drop items here.
650          *
651          * This callback must result in an Action_Equip element being 
652          * given to the addAction method.
653          *
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.
658          *
659          * @return False on error, true otherwise.
660          */
661         //! Callback to have a Hero drop an Item.
662         bool heroDropItem(Hero *hero, Item *item, Vector<int> pos);
663
664         /**
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.
668          *
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
671          * drop items here.
672          *
673          * This callback must result in one or more Action_Equip elements 
674          * being given to the addAction method.
675          *
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.
679          *
680          * @return False on error, true otherwise.
681          */
682         //! Callback to have a Hero drop all items.
683         bool heroDropAllItems(Hero *hero, Vector<int> pos);
684
685         /**
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.
689          *
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.
693          *
694          * This callback must result in an Action_Equip element being 
695          * given to the addAction method.
696          *
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.
701          *
702          * @return False on error, true otherwise.
703          */
704         //! Callback to have a Hero pick up an Item.
705         bool heroPickupItem(Hero *hero, Item *item, Vector<int> pos);
706
707         //! Pick up all of the items at the given location on the game map.
708         bool heroPickupAllItems(Hero *h, Vector<int> pos);
709
710         /**
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 
714          * quests.
715          * This callback doesn't do much except record the event for
716          * posterity (see HistoryReportDialog).
717          *
718          * This callback must result in a History_QuestCompleted element being
719          * added to the player's History list (Player::d_history).
720          *
721          * @param hero             The Hero completing the Quest.
722          *
723          * @return False on error, true otherwise.
724          */
725         //! Callback to have a Hero complete a quest.
726         bool heroCompletesQuest(Hero *hero);
727
728         /** 
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.
732          *
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).
737          *
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 
742          *                          scenario.
743          *
744          * @return The newly assigned Quest or 0 on error.
745          */
746         //! Callback to have a Hero get a new Quest from a temple.
747         Quest* heroGetQuest(Hero *hero, Temple* temple, bool except_raze);
748
749         /** 
750          * Called whenever a hero emerges in a city
751          *
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 
755          *                 the hero.
756          * 
757          * @note Only change the name and gender attributes of the Hero.
758          */
759         void recruitHero(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally);
760
761         /** 
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.
767          * 
768          * This callback must result in an Action_Level element being 
769          * given to the addAction method.
770          *
771          * @param army     The army to raise (is always a Hero.)
772          */
773         //! Callback to advance an Army's level.
774         virtual void heroGainsLevel(Hero * a) = 0;
775
776
777
778
779
780
781
782         // City related actions the player can take.
783
784         /**
785          * Callback to have a Player rename a City.
786          *
787          * Only human players currently rename cities; computer players
788          * do not consider doing so.
789          *
790          * This callback must result in a Action_RenameCity element being
791          * given to the addAction method.
792          *
793          * @param city             The city to change the name of.
794          * @param name             The new name of the city.
795          *
796          * @return False on error, true otherwise.
797          */
798         //! Callback to rename a city.
799         bool cityRename(City *city, std::string name);
800
801         /** 
802          * Callback to initiate vectoring new units from a player's City to 
803          * a destination point on the game map.
804          *
805          * Computer players don't currently consider vectoring units, so
806          * only human players use this method.
807          *
808          * This callback must result in a Action_Vector element being
809          * given to the addAction method.
810          *
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.
817          *
818          * @return False on error, true otherwise.
819          */
820         //! Callback to vector produced units from a city.
821         bool vectorFromCity(City* city, Vector<int> dest);
822
823         /** 
824          * Callback to change the vectoring destination for all of the
825          * player's cities that are vectoring to a particular city.
826          *
827          * SRC and DEST can both be the player's planted standard.
828          *
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.
833          *
834          * @return False on error, true otherwise.
835          */
836         //! Callback to make a mass change to vectoring.
837         bool changeVectorDestination(Vector<int> src, Vector<int> dest);
838
839         /** 
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.
845          *
846          * This callback must result in an Action_Occupy element being 
847          * given to the addAction method.
848          *
849          * @param city             The occupied city.
850          *
851          * @return False on error, true otherwise.
852          */
853         //! Callback to occupy a city.
854         void cityOccupy(City* city);
855
856         /** 
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.
864          *
865          * This callback must result in an Action_Pillage element being 
866          * given to the addAction method.
867          *
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.
871          *
872          * @return False on error, true otherwise.
873          */
874         //! Callback to pillage a city.
875         void cityPillage(City* city, int& gold, int *pillaged_army_type);
876
877         /**
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.
885          *
886          * The AI_Fast, AI_Dummy and AI_Smart classes use this method
887          * as defined in RealPlayer to sack cities.
888          *
889          * This callback must result in an Action_Sack element being 
890          * given to the addAction method.
891          *
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 
895          *                         for gold pieces.
896          *
897          * @return False on error, true otherwise.
898          */
899         //! Callback to sack a city.
900         void citySack(City* city, int& gold, std::list<guint32> *sacked_types);
901
902         /** 
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 
909          * treacherous.
910          *
911          * The AI_Fast, AI_Dummy and AI_Smart classes use this method
912          * as defined in RealPlayer to raze cities.
913          *
914          * This callback must result in an Action_Raze element being 
915          * given to the addAction method.
916          *
917          * @param city             The city to be razed.
918          *
919          * @return False on error, true otherwise.
920          */
921         //! Callback to raze a city.
922         void cityRaze(City* city);
923
924         /** 
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.
933          *
934          * This callback must result in an Action_Buy element being 
935          * given to the addAction method.
936          *
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
940          *                         is 3.
941          * @param armytype         The index of the army type to add.  This
942          *                         type relates to the Player's Armyset.
943          *
944          * @return False on error, true otherwise.
945          */
946         //! Callback to purchase a new Army unit for production within a City.
947         bool cityBuyProduction(City* city, int slot, int armytype);
948
949         /** 
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
955          * is -1.
956          * After a slot is selected and enough time passes, a new Army unit
957          * will arrive in the city that produced it.
958          *
959          * This callback must result in an Action_Production element being 
960          * given to the addAction method.
961          *
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.
970          *
971          * @return False on error, true otherwise.
972          */
973         //! Callback to change the Army unit being produced within a City.
974         bool cityChangeProduction(City* city, int slot);
975
976         //! A player's city produces an army unit.
977         /**
978          * @param city  The city that has produced an army unit.
979          * @return False on error, true otherwise.
980          */
981         bool cityProducesArmy(City *city);
982
983         //! A player has a vectored army unit arrive somewhere.
984         bool vectoredUnitArrives(VectoredUnit *unit);
985
986         //! Shut down a city's production due to insufficent funds.
987         void cityTooPoorToProduce(City *city, int slot);
988
989         /** 
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.
996          *
997          * @param  city   The newly conquered city.
998          *
999          * @return True if everything went well.
1000          */
1001         //! Decision callback for what to do if a city is invaded.
1002         virtual void invadeCity(City* city) = 0;
1003
1004         //! Decision callback for what to do when a hero shows up.
1005         virtual bool chooseHero(HeroProto *hero, City *city, int gold) = 0;
1006         
1007         //! Decision callback for what reward to pick when at a sage.
1008         virtual Reward *chooseReward(Ruin *ruin, Sage *sage, Stack *stack) = 0;
1009
1010         //! Decision callback for if to commit treachery or not.
1011         virtual bool chooseTreachery (Stack *stack, Player *player, Vector <int> pos) = 0;
1012
1013         //! Decision callback for when a hero gains a level.
1014         virtual Army::Stat chooseStat(Hero *hero) = 0;
1015
1016         //! Decision callback for when a hero visits a temple.
1017         virtual bool chooseQuest(Hero *hero) = 0;
1018
1019         // Player related actions the player can take.
1020
1021         /** 
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 
1025          * Historylist.
1026          *
1027          * @return True if everything went well.
1028          */
1029         //! Callback to start a Player's turn.
1030         virtual bool startTurn() = 0;
1031
1032         virtual void abortTurn() = 0;
1033
1034         /** 
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.
1038          */
1039         //! Initialise a Player's turn.
1040         void initTurn();
1041
1042         virtual void endTurn() = 0;
1043         
1044
1045         /** 
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.
1053          *
1054          * This callback must result in an Action_Reward element being 
1055          * given to the addAction method.
1056          *
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.
1060          *
1061          * @return False on error, true otherwise.
1062          */
1063         //! Callback to give a Reward to the Player or the player's Stack.
1064         bool giveReward (Stack *stack, Reward *reward);
1065
1066         //! Give the player a new name.
1067         void rename (std::string name);
1068
1069         //! have a hero show up, or not.
1070         bool maybeRecruitHero ();
1071
1072         //! Mark the player as dead. Kills all Army units in the Stacklist.
1073         void kill();
1074
1075         //! Go to a temple if we're near enough.
1076         /**
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.
1082          *
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
1086          *                     for visiting.
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
1099          *                     temple.
1100          *
1101          * Returns true if the stack moved, false if it stayed still.
1102          */
1103         bool AI_maybeVisitTempleForBlessing(Stack *s, int dist, int mp, 
1104                                             double percent_can_be_blessed, 
1105                                             bool &blessed, bool &stack_died);
1106
1107         bool AI_maybeVisitTempleForQuest(Stack *s, int dist, int max_mp, 
1108                                          bool &stack_died);
1109
1110         bool AI_maybeVisitRuin(Stack *s, int dist, int max_mp, 
1111                                bool &stack_died);
1112
1113         Vector<int> AI_getQuestDestination(Quest *quest, Stack *stack) const;
1114         bool AI_invadeCityQuestPreference(City *c, CityDefeatedAction &action) const;
1115         /** 
1116          * Callback to decide if we perform treachery on a friendly player.
1117          *
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
1121          * or not.
1122          *
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.
1127          *
1128          * @return True if we decided to be treacherous.  False otherwise.
1129          */
1130         //! Decision callback for if we should perform trechery or not.
1131         bool treachery (Stack *stack, Player *player, Vector <int> pos);
1132
1133         /**
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.
1138          *
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.
1143          *
1144          * This callback must result in a Action_Resign element being
1145          * given to the addAction method.
1146          *
1147          */
1148         //! Callback to disband all the player's stacks and raze all cities.
1149         void resign();
1150
1151         //! Declare a new diplomatic state with respect to an opponent.
1152         void declareDiplomacy(DiplomaticState state, Player *player);
1153
1154         //! Negotiate diplomatic talks with an opponent, and return a new state.
1155         DiplomaticState negotiateDiplomacy (Player *player);
1156
1157         /**
1158          * Change the player's opinion of an opponent for the better.
1159          *
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.
1163          *
1164          */
1165         //! Make your diplomatic view of another player increase.
1166         void improveDiplomaticRelationship (Player *p, guint32 amount);
1167
1168         /**
1169          * Change all players opinion of you for the better, except for 
1170          * possibly a single player.
1171          *
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.
1175          *
1176          * @note Pass except as NULL to not except a player.
1177          */
1178         //! Make all other players diplomatic view of you increase.
1179         void improveDiplomaticRelationship (guint32 amount, Player *except);
1180
1181         /**
1182          * Change the player's view of an opponent for the worse.
1183          *
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.
1187          *
1188          */
1189         //! Make your diplomatic view of another player decrease.
1190         void deteriorateDiplomaticRelationship (Player *player, guint32 amount);
1191
1192         /**
1193          * Change all players opinion of you for the worse.
1194          *
1195          * @param amount    The amount to deterioriate by.  The minimum value 
1196          *                  is 1 and the maximum value is 15.
1197          */
1198         //! Make all other players diplomatic view of you worsen
1199         void deteriorateDiplomaticRelationship (guint32 amount);
1200
1201         /**
1202          * Change all players opinion of another player for the worse, 
1203          * who happen to have a diplomatic state of state with you.
1204          *
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.
1210          */
1211         //! Make players you are at state with you think less of player.
1212         void deteriorateAlliesRelationship(Player *player, guint32 amount, 
1213                                            Player::DiplomaticState state);
1214
1215         /**
1216          * Change all players opinion of another player for the better, 
1217          * who happen to have a diplomatic state of state with you.
1218          *
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.
1224          */
1225         //! Make players who are at STATE with PLAYER think better of you.
1226         void improveAlliesRelationship(Player *player, guint32 amount, 
1227                                        Player::DiplomaticState state);
1228
1229         //! Propose a new diplomatic state wrt another player
1230         void proposeDiplomacy (DiplomaticProposal proposal, Player *player);
1231
1232
1233
1234
1235         // Signals
1236
1237         /**
1238          * @param city   The city being invaded.
1239          * @param loot   The gold looted.
1240          */
1241         //! Emitted when the player defeats a City.
1242         sigc::signal<void, City*, int> sinvadingCity;
1243
1244         /**
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.
1248          *
1249          * @return True if we're accepting a hero, false if not.
1250          */
1251         //! Emitted whenever a hero is recruited.
1252         sigc::signal<bool, HeroProto*, City *, int> srecruitingHero;
1253
1254         /**
1255          * @param army   The army that has gained a level.
1256          *
1257          * @return One of Army::Stat::STRENGTH, Army::Stat::MOVES, or 
1258          *         Army::Stat::SIGHT.
1259          */
1260         //! Emitted when an Army advances a level; returns stat to raise.
1261         sigc::signal<Army::Stat, Hero*> sheroGainsLevel;
1262
1263         /**
1264          * @param army   The army that has gotten a medal.
1265          */
1266         //! Emitted whever a player's army gets a new medal.
1267         sigc::signal<void, Army*, int> snewMedalArmy;
1268
1269         /**
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.
1273          */
1274         //! Emitted when a player's Army dies.
1275         sigc::signal<void, Army*, std::vector<guint32> > sdyingArmy;
1276
1277         /**
1278          * @param ruin    The ruin being searched.
1279          * @param stack   The stack doing the searching (must contain Hero).
1280          * @param reward  The reward received.
1281          */
1282         //! Emitted whenever the player successfully searched a ruin.
1283         sigc::signal<void, Ruin*, Stack*> ssearchingRuin;
1284
1285         /**
1286          * @param temple  The temple being visited.
1287          * @param stack   The stack that has gotten blessed.
1288          */
1289         //! Emitted whenever the player visits a temple.
1290         sigc::signal<void, Temple*, Stack*> svisitingTemple;
1291
1292         /**
1293          * @param city   The city being occupied.
1294          * @param stack  The stack doing the occupying.
1295          */
1296         //! Emitted when the player occupies a City.
1297         sigc::signal<void, City*, Stack*> soccupyingCity;
1298
1299         /**
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.
1304          */
1305         //! Emitted whenever the player pillages a city.
1306         sigc::signal<void, City*, Stack*, int, guint32> spillagingCity;
1307
1308         /**
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.
1313          */
1314         //! Emitted whenever the player sacks a city.
1315         sigc::signal<void, City*, Stack*, int, std::list<guint32> > ssackingCity;
1316
1317         /**
1318          * @param city        The city that has been razed.
1319          * @param stack       The razing stack.
1320          */
1321         //! Emitted whenever the player razes a city.
1322         sigc::signal<void, City*, Stack*> srazingCity;
1323
1324         /**
1325          * Emitted when the player's treasury has been changed.
1326          */
1327         //! Emitted whenever a player's stats changes.
1328         sigc::signal<void> schangingStats;
1329
1330         //! Emitted whenever a computer player does something of note.
1331         sigc::signal<void, std::string> schangingStatus;
1332
1333         //! Emitted whenever any player does anything at all.
1334         sigc::signal<void> sbusy;
1335
1336         /**
1337          * Emitted when the player's stack moves, is disbanded, gets blessed,
1338          * searches a ruin, or is otherwise altered.
1339          *
1340          * @param stack    The stack that has been altered.
1341          */
1342         //! Emitted whenever the stack's status has changed.
1343         sigc::signal<void, Stack*> supdatingStack;
1344
1345         //! Emitted whenever the active stack comes to a stop.
1346         sigc::signal<void, Stack*> shaltedStack;
1347
1348         /**
1349          * Emitted whenever a city is conquered or razed.
1350          *
1351          * @param city     The city that has been altered.
1352          */
1353         //! Emitted whenever the status of a city has changed.
1354         sigc::signal<void, City*> supdatingCity;
1355
1356         /**
1357          * @param fight  The details of the upcoming fight.
1358          */
1359         //! Emitted when a fight has started against a city or stack.
1360         sigc::signal<void, Fight &> fight_started;
1361
1362         /**
1363          * @param city     The city we attacked.
1364          * @param result   If we won or not.
1365          */
1366         //! Emitted after we attack a city.
1367         sigc::signal<void, City *, Fight::Result> cityfight_finished;
1368         
1369         /**
1370          * @param attacker The player's attacking stack.
1371          * @param keeper   The keeper of the ruin.
1372          */
1373         //! Emitted when a fight in a ruin is started.
1374         sigc::signal<void, Stack *, Stack *> ruinfight_started;
1375
1376         /**
1377          * @param result   If we defeated the ruin's keeper or not.
1378          */
1379         //! Emitted when a fight in a ruin has finished.
1380         sigc::signal<void, Fight::Result> ruinfight_finished;
1381
1382         /**
1383          * @param chance   The percent chance that we will prevail in battle.
1384          */
1385         //! Emitted when a player asks for help from a military advisor.
1386         sigc::signal<void, float> advice_asked;
1387
1388         //! Signal raised when a stack is considering an act of treachery.
1389         sigc::signal<bool, Stack *, Player *, Vector<int> > streacheryStack;
1390
1391         //! Signal raised when a human player is deciding.
1392         sigc::signal<bool, Stack *, Player *, Vector<int> > streachery;
1393
1394         //! Player would like to end the turn.
1395         sigc::signal<void> ending_turn;
1396
1397         //! Player has confirmed to abort the turn.
1398         sigc::signal<void> aborted_turn;
1399
1400         sigc::signal<void, int> hero_arrives_with_allies;
1401
1402         sigc::signal<void, NetworkAction *> acting;
1403         sigc::signal<void, NetworkHistory *> history_written;
1404         
1405         void loadPbmGame();
1406         //! Check the history to see if we ever conquered the given city.
1407
1408
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);
1412         
1413         // Static Methods
1414
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);
1419         /** 
1420          * Make a new player with the given parameters.
1421          * 
1422          * @note The neutral player must still be inserted as neutral player
1423          * manually!
1424          *
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).
1431          */
1432         //! Create a player.
1433         static Player* create(std::string name, guint32 armyset, 
1434                               Gdk::Color color, int width, int height, 
1435                               Type type);
1436         
1437         /** 
1438          * Copies a player to a different type.
1439          * 
1440          * @note This method does not change ownerships! (e.g. of cities)
1441          *
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.
1445          */
1446         //! Create a new player from another player.
1447         static Player* create(Player* orig, Type type);
1448
1449         /** 
1450          * Loads a player from a file.
1451          *
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
1456          * class.
1457          *
1458          * @param helper       the opened saved-game file to read from.
1459          *
1460          * @return The loaded Player instance.
1461          */
1462         static Player* loadPlayer(XML_Helper* helper);
1463
1464     
1465
1466     protected:
1467         // do some fight cleaning up, setting
1468         void cleanupAfterFight(std::list<Stack*> &attackers,
1469                                std::list<Stack*> &defenders);
1470         
1471         //! Move stack s one step forward on it's Path.
1472         bool stackMoveOneStep(Stack* s);
1473
1474         //! Move stack s one step forward on it's Path, over another stack.
1475         bool stackMoveOneStepOverTooLargeFriendlyStacks(Stack *s);
1476
1477         void addAction(Action *action);
1478
1479         // DATA
1480         //! The player's colour.
1481         /**
1482          * Mask portions of images are shaded in this colour.
1483          */
1484         Gdk::Color d_color;
1485
1486         //! The name of the Player.
1487         std::string d_name;
1488
1489         //! The ArmySet of the Player.
1490         guint32 d_armyset;
1491
1492         //! The number of gold pieces the Player has in the treasury.
1493         int d_gold;
1494
1495         //! Whether or not this player is dead.
1496         bool d_dead;
1497
1498         //! Whether or not this player can be killed.
1499         bool d_immortal;
1500
1501         //! The kind of Player (see Player::Type).
1502         guint32 d_type;
1503
1504         //! A unique numeric identifier identifying this Player.
1505         guint32 d_id;
1506
1507         //! A list of actions that this Player made this turn.
1508         std::list<Action*> d_actions;
1509
1510         //! A list of "headlines" for this Player for the whole game.
1511         std::list<History*> d_history;
1512
1513         //! A list of the Player's Stack objects.
1514         Stacklist* d_stacklist;
1515
1516         //! What the player can see on the hidden map.
1517         FogMap* d_fogmap;
1518
1519         //! A tally of the kills that this player has made
1520         Triumphs* d_triumphs;
1521
1522         //! The order in which this Player's army types fight in battle.
1523         /**
1524          * @note This value is related to the Player's ArmySet.
1525          */
1526         std::list<guint32> d_fight_order; 
1527
1528         //! How many gold pieces the Player paid out in the last turn.
1529         guint32 d_upkeep;
1530
1531         //! How many gold pieces the Player made from taxes in the last turn.
1532         guint32 d_income;
1533
1534         //! The diplomatic view that this Player has of each other Player.
1535         DiplomaticState d_diplomatic_state[MAX_PLAYERS];
1536
1537         //! The diplomatic rank this Player has among all other Players.
1538         guint32 d_diplomatic_rank;
1539
1540         //! The title that goes along with the diplomatic rank.
1541         std::string d_diplomatic_title;
1542
1543         //! The proposals that this Player is making this turn.
1544         DiplomaticProposal d_diplomatic_proposal[MAX_PLAYERS];
1545
1546         //! A quantification of how much this Player likes every other Player.
1547         guint32 d_diplomatic_score[MAX_PLAYERS];
1548
1549         //! Whether or not this player is observable by the user.
1550         bool d_observable;
1551
1552         //! Whether or not this player has surrendered.
1553         bool surrendered;
1554
1555         //! Whether or not someone has closed the main game window.
1556         bool abort_requested;
1557
1558         //! assists in scorekeeping for diplomacy
1559         void alterDiplomaticRelationshipScore (Player *player, int amount);
1560
1561         void conquerCity(City *city, Stack *stack);
1562
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);
1584         void doResign();
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);
1592         void doKill();
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);
1597
1598         bool doStackSplitArmies(Stack *stack, std::list<guint32> armies,
1599                                 Stack *&new_stack);
1600
1601         Quest* doHeroGetQuest(Hero *hero, Temple* t, bool except_raze);
1602
1603         void AI_maybeBuyScout(City *c);
1604
1605
1606         bool AI_maybePickUpItems (Stack *s, int dist, int mp, bool &picked_up,
1607                                   bool &stack_died);
1608
1609
1610
1611         bool AI_maybeVector(City *c, guint32 safe_mp, guint32 min_defenders,
1612                             City *target, City **vector_city = NULL);
1613
1614
1615         void AI_setupVectoring(guint32 safe_mp, guint32 min_defenders,
1616                                guint32 mp_to_front);
1617
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);
1621
1622         void pruneActionlist();
1623         static void pruneActionlist(std::list<Action*> actions);
1624         std::list<History*> getHistoryForThisTurn() const;
1625             
1626     private:
1627         //! Loads the subdata of a player (actions and stacklist)
1628         bool load(std::string tag, XML_Helper* helper);
1629
1630         /**
1631          * Returns all heroes in the given list of stacks.
1632          *
1633          * @param stacks           the list of stacks which is searched.
1634          * @param heroes           Return a list of id's of the heroes found.
1635          */
1636         //! Get heroes.
1637         void getHeroes(const std::list<Stack*> stacks, 
1638                        std::vector<guint32>& heroes);
1639
1640         /** 
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. 
1644          *
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.
1650          */
1651         //! Remove dead Armies from a list of stacks after a fight.
1652         double removeDeadArmies(std::list<Stack*>& stacks,
1653                                 std::vector<guint32>& culprits);
1654         
1655         /** 
1656          * Increases the number of experience points of a stack
1657          * the number of battles and checks if an army can get a medal
1658          *
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.
1663          *
1664          * @param stacks           A list of all stacks gaining experience.
1665          * @param xp_sum           The number of XP to distribute.
1666          */
1667         //! update Army state after a Fight.
1668         void updateArmyValues(std::list<Stack*>& stacks, double xp_sum);
1669
1670
1671         /** 
1672          * Called to move a Stack to a specified position.
1673          *
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.
1678          *
1679          * This callback must result in an Action_Move element being 
1680          * given to the addAction method.
1681          *
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.
1685          *
1686          * @return False on error, true otherwise.
1687          */
1688         //! Callback to move a stack on the map.
1689         MoveResult *stackMove(Stack* s, Vector<int> dest, bool follow);
1690
1691         bool nextStepOnEnemyStackOrCity(Stack *s) const;
1692
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);
1698
1699         std::list<Action *> getActionsThisTurn(int type) const;
1700 };
1701
1702 #endif // PLAYER_H
1703
1704 // End of file