initial commit, lordsawar source, slightly modified
[lordsawar] / src / NextTurn.h
1 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2007, 2008 Ben Asselstine
3 // Copyright (C) 2007, 2008 Ole Laursen
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 3 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Library General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
18 //  02110-1301, USA.
19
20 #ifndef NEXT_TURN_H
21 #define NEXT_TURN_H
22
23 #include <sigc++/trackable.h>
24 #include <sigc++/connection.h>
25 #include "playerlist.h"
26 #include "hero.h"
27
28 /**
29    \brief The class to pass turns around the players
30  
31    \note    This class takes care of calling the correct players in the correct
32             order. The problem is, no other class really has the scope of doing
33             this whole stuff. The playerlist and the game object aren't the
34             right candidates (they are busy with other things) and the former
35             algorithm of each player calling the next one produces a huge
36             stackload if two ai players fight each other. Plus, you want to do
37             several actions at the end or the beginning of each player's turn
38             or each round and therefore want a central place for this code.
39  */
40
41 class NextTurn: public sigc::trackable
42 {
43     public:
44         /**
45            \brief constructor
46
47            @param   turnmode    setting for the private variable d_turnmode
48            @param   random_turns change the order every round
49          */
50         NextTurn(bool turnmode, bool random_turns);
51
52         /**
53            \brief destructor
54          */
55         ~NextTurn();
56         
57         /**
58            \brief start a new game
59           
60            This function starts with the currently active player, or the first
61            if there is none active. For starting a game. This should be the
62            lowest of all scenario-related functions in the stack.
63          */
64         virtual void start()=0;
65
66         /**
67            \brief go on to the next player
68            
69            This function starts the next to the active player's turn. Used when
70            a human player has pushed the next_turn button.
71          */
72         virtual void endTurn()=0;
73
74         void stop();
75
76         void nextPlayer();
77
78         void setContinuingTurn() { continuing_turn = true; };
79
80         /**
81            \brief signals for announcing events
82          */
83         sigc::signal<void, Player*> splayerStart;
84
85         // emitted whenever a new player's turn starts.
86         sigc::signal<void, Player*> snextTurn;
87         
88         //! Signal which is emitted whenever a new round starts
89         sigc::signal<void> snextRound;
90
91         //! Signal as a workaround for a display bug; updates the screen
92         sigc::signal<void> supdating;
93
94         //! Signal when we're done doing next-turn duties.
95         sigc::signal<void> srequestAbort;
96
97     protected:
98
99         /** \brief determines whether armies are healed/produced at the
100           * beginning of a round or at the beginning of each player's turn.
101           *
102           * If the value is set to true, the production/healing of armies takes
103           * place at the beginning of each player's turn (which is fairer); else
104           * all armies of all playes are healed when a new game round starts.
105           * The latter setting is a bit unfair, because the last player knows
106           * that his armies are healed immediately when he has finished his turn
107           * while the other player's armies may have to survive some attacks,
108           * but it may be useful in some circumstances.
109           */
110         bool d_turnmode;
111
112         bool d_random_turns;
113
114         //! If set to true, the game is interrupted at the next occasion
115         bool d_stop;
116
117         // whether we're starting a turn again from loading a game
118         bool continuing_turn;
119
120     protected:
121
122         sigc::connection abort;
123 };
124
125 #endif //NEXT_TURN_H