~ubuntu-branches/ubuntu/maverick/lordsawar/maverick

« back to all changes in this revision

Viewing changes to src/playerlist.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2010-04-10 09:29:33 UTC
  • mfrom: (1.1.9 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100410092933-23uq4dxig30kmtcw
Tags: 0.1.8-1
* New upstream release.
* Add misc:Depends for -data package.
* Bump Standards Version to 3.8.4. (No changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#define PLAYERLIST_H
23
23
 
24
24
#include <list>
 
25
#include <map>
25
26
#include <string>
26
27
#include <vector>
27
28
#include <sigc++/trackable.h>
47
48
        //! The xml tag of this object in a saved-game file.
48
49
        static std::string d_tag; 
49
50
 
50
 
        //! Gets the singleton instance or creates a new one.
51
 
        static Playerlist* getInstance();
52
 
 
53
 
        /**
54
 
         * Load all Players in the Playerlist from a saved-game file.
55
 
         *
56
 
         * @param helper     The opened saved-game file to read from.
57
 
         *
58
 
         * @return The loaded Playerlist.
59
 
         */
60
 
        //! Loads the playerlist from a saved-game file.
61
 
        static Playerlist* getInstance(XML_Helper* helper);
62
 
 
63
 
        //! Explicitly deletes the singleton instance.
64
 
        static void deleteInstance();
65
 
 
66
 
        //! Returns the active player (the Player whose turn it is).
67
 
        static Player* getActiveplayer() {return d_activeplayer;}
68
 
        
 
51
        // Set Methods
 
52
 
 
53
        //! Set the winning human player.
 
54
        void setWinningPlayer(Player *winner);
 
55
 
 
56
        //! Set the player who's turn it is.  should only be used by the editor.
 
57
        void setActiveplayer(Player *p) {d_activeplayer = p;};
 
58
 
 
59
        //! set the player who is looking at the bigmap and smallmap.
 
60
        void setViewingplayer(Player *p) {viewingplayer = p;};
 
61
 
 
62
        //! Get Methods
 
63
 
 
64
        //! Returns the neutral player.
 
65
        Player* getNeutral() const {return d_neutral;}
 
66
 
 
67
        //! Return the player with the highest score.
 
68
        Player *getWinningPlayer() const;
 
69
 
 
70
 
 
71
        // Methods that operate on the class data and modify the class.
 
72
 
69
73
        //! Sets the active player to the next player in the order.
70
74
        void nextPlayer();
71
75
 
89
93
        //! Set the neutral player.
90
94
        void setNeutral(Player* neutral) {d_neutral = neutral;}
91
95
 
92
 
        //! Returns the neutral player.
93
 
        Player* getNeutral() const {return d_neutral;}
94
 
 
95
 
        /**
96
 
         * Scan the list of players for a Player with a given name.
97
 
         *
98
 
         * @param name      The name of the Player to lookup.
99
 
         *
100
 
         * @return A pointer to the Player if it is found, or NULL if it isn't.
101
 
         */
102
 
        //! Lookup a Player by it's name.
103
 
        Player* getPlayer(std::string name) const;
104
 
 
105
 
        /**
106
 
         * Scan the list of players for a Player with a given Id.
107
 
         *
108
 
         * @param id        The id of the Player to lookup.
109
 
         *
110
 
         * @return A pointer to the Player if it is found, or NULL if it isn't.
111
 
         */
112
 
        //! Lookup a Player by it's Id.
113
 
        Player* getPlayer(guint32 id) const;
114
 
 
115
 
        //! Returns the number of living players (neutral player excluded.)
116
 
        guint32 getNoOfPlayers() const;
117
 
 
118
 
        /** 
119
 
         * Scan the list of players for the first Player that is alive.
120
 
         * This method is used to determine the beginning of a round.
121
 
         *
122
 
         * @return A pointer to the first living Player.
123
 
         */
124
 
        //! Return the first living Player in the list.
125
 
        Player* getFirstLiving() const;
126
 
 
127
96
        /** 
128
97
         * Swap out a player from the list and replace it with a new one.
129
98
         * Specical care is taken to remove all references to the original
139
108
        //! Replace a Player in the list with a new Player.
140
109
        void swap(Player *old_player, Player *new_player);
141
110
        
142
 
        //! Saves the playerlist to an opened saved-game file.
143
 
        bool save(XML_Helper* helper) const;
144
 
 
145
111
        /** 
146
112
         * Erase a Player from the list, and free the contents of the Player.
147
113
         *
173
139
        //! Callback method to process all players at the start of a round.
174
140
        void nextRound(bool diplomacy, bool *surrender_already_offered);
175
141
 
176
 
        //! Return the number of human players left alive in the list.
177
 
        guint32 countHumanPlayersAlive();
178
 
 
179
 
        //! Return the number of players left alive, not including neutral.
180
 
        guint32 countPlayersAlive();
181
 
 
182
142
        /**
183
143
         * The purpose of randomzing the Playerlist is to implement
184
144
         * random turns.
208
168
        //! Sync the given player with the playerlist
209
169
        void syncPlayer(GameParameters::Player player);
210
170
 
 
171
        //! Converts all of the human players into network players.
 
172
        void turnHumansIntoNetworkPlayers();
 
173
 
 
174
        //! Converts a given number of the human players into a type of player.
 
175
        void turnHumansInto(Player::Type type, int num_players = -1);
 
176
 
 
177
        //! Reorder the list according to the given order.
 
178
        void reorder(std::list<guint32> order);
 
179
 
 
180
        //! Perform the surrender of all computer players.
 
181
        void surrender();
 
182
 
 
183
        //! Add a player to the list.  Use this instead of push_back.
 
184
        void add(Player *player);
 
185
 
 
186
 
 
187
        // Methods that operate on the class data but do not modify it.
 
188
 
 
189
        /**
 
190
         * Scan the list of players for a Player with a given name.
 
191
         *
 
192
         * @param name      The name of the Player to lookup.
 
193
         *
 
194
         * @return A pointer to the Player if it is found, or NULL if it isn't.
 
195
         */
 
196
        //! Lookup a Player by it's name.
 
197
        Player* getPlayer(std::string name) const;
 
198
 
 
199
        /**
 
200
         * Scan the list of players for a Player with a given Id.
 
201
         *
 
202
         * @param id        The id of the Player to lookup.
 
203
         *
 
204
         * @return A pointer to the Player if it is found, or NULL if it isn't.
 
205
         */
 
206
        //! Lookup a Player by it's Id.
 
207
        Player* getPlayer(guint32 id) const;
 
208
 
 
209
        //! Returns the number of living players (neutral player excluded.)
 
210
        guint32 getNoOfPlayers() const;
 
211
 
 
212
        /** 
 
213
         * Scan the list of players for the first Player that is alive.
 
214
         * This method is used to determine the beginning of a round.
 
215
         *
 
216
         * @return A pointer to the first living Player.
 
217
         */
 
218
        //! Return the first living Player in the list.
 
219
        Player* getFirstLiving() const;
 
220
 
 
221
        //! Saves the playerlist to an opened saved-game file.
 
222
        bool save(XML_Helper* helper) const;
 
223
 
 
224
        //! Return the number of human players left alive in the list.
 
225
        guint32 countHumanPlayersAlive() const;
 
226
 
 
227
        //! Return the number of players left alive, not including neutral.
 
228
        guint32 countPlayersAlive() const;
 
229
 
 
230
 
 
231
        //! Return the list of activities that the given hero has accomplished.
 
232
        std::list<History *>getHistoryForHeroId(guint32 id) const;
 
233
 
 
234
        /** 
 
235
          \brief Check to see if this is the end of the round or not.
 
236
          */
 
237
        bool isEndOfRound() const;
 
238
 
 
239
 
 
240
        // Signals
 
241
 
211
242
        /**
212
243
         * @param player  The player who has died.
213
244
         */
223
254
        //! Emitted when a surrender is offered.
224
255
        sigc::signal<void, Player*> ssurrender;
225
256
    
226
 
        void turnHumansIntoNetworkPlayers();
227
 
        void turnHumansInto(Player::Type type, int num_players = -1);
228
 
        void reorder(std::list<guint32> order);
229
 
 
230
 
        std::list<History *>getHistoryForHeroId(guint32 id);
231
 
 
232
 
        void surrender();
233
 
 
234
 
        /** 
235
 
          \brief Check to see if this is the end of the round or not.
236
 
          */
237
 
        bool isEndOfRound();
238
 
 
239
 
        void setWinningPlayer(Player *winner);
240
 
 
 
257
 
 
258
        // Static Methods
 
259
 
 
260
        //! Gets the singleton instance or creates a new one.
 
261
        static Playerlist* getInstance();
 
262
 
 
263
        /**
 
264
         * Load all Players in the Playerlist from a saved-game file.
 
265
         *
 
266
         * @param helper     The opened saved-game file to read from.
 
267
         *
 
268
         * @return The loaded Playerlist.
 
269
         */
 
270
        //! Loads the playerlist from a saved-game file.
 
271
        static Playerlist* getInstance(XML_Helper* helper);
 
272
 
 
273
        //! Explicitly deletes the singleton instance.
 
274
        static void deleteInstance();
 
275
 
 
276
        //! Returns the active player (the Player whose turn it is).
 
277
        static Player* getActiveplayer() {return d_activeplayer;}
 
278
 
 
279
        //! Returns the viewing player (the Player who is looking at maps).
 
280
        static Player *getViewingplayer() {return viewingplayer;}
 
281
 
 
282
 
 
283
        int countFightsThisTurn() const;
 
284
        int countMovesThisTurn() const;
241
285
    protected:
 
286
 
242
287
        //! Default constructor.
243
288
        Playerlist();
 
289
 
244
290
        //! Loading constructor.
245
291
        Playerlist(XML_Helper* helper);
 
292
 
246
293
        //! Destructor.
247
294
        ~Playerlist();
248
295
        
266
313
        void negotiateDiplomacy();
267
314
 
268
315
        // DATA
 
316
 
269
317
        //! The pointer to the player whose turn it is in the list.
270
318
        static Player* d_activeplayer;
271
319
 
 
320
        //! The player that the smallmap and bigmap are being viewed as.
 
321
        static Player *viewingplayer;
 
322
 
272
323
        //! The pointer to the neutral player in the list.
273
324
        Player* d_neutral;
274
325
 
 
326
        typedef std::map<guint32, Player*> IdMap;
 
327
        IdMap d_id;
 
328
 
275
329
        //! A static pointer for the singleton instance.
276
330
        static Playerlist* s_instance;
277
331