Planeshift
minigamemanager.h
Go to the documentation of this file.
1 /*
2 * minigamemanager.h - Author: Enar Vaikene
3 *
4 * Copyright (C) 2006 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation (version 2 of the License)
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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 */
19 
20 #ifndef __MINIGAMEMANAGER_H
21 #define __MINIGAMEMANAGER_H
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/weakref.h>
27 
28 //=============================================================================
29 // Project Includes
30 //=============================================================================
32 
33 //=============================================================================
34 // Local Includes
35 //=============================================================================
36 #include "deleteobjcallback.h"
37 #include "msgmanager.h" // Parent class
38 
39 class Client;
40 class MiniGameManager;
41 class gemActionLocation;
42 class gemObject;
43 class psMGUpdateMessage;
44 
50 {
53 };
54 
59 {
60  uint32_t playerID;
61  const char* playerName;
62 
65 
68 
71 };
72 
139 {
140 public:
141 
142  psMiniGameSession(MiniGameManager* mng, gemActionLocation* obj, const char* name);
143 
145 
147  const uint32_t GetID() const
148  {
149  return id;
150  }
151 
153  const csString &GetName() const
154  {
155  return name;
156  }
157 
159  uint16_t GetOptions() const
160  {
161  return options;
162  }
163 
172  bool Load(csString &responseString);
173 
175  void Restart();
176 
178  void AddPlayer(Client* client);
179 
181  void RemovePlayer(Client* client);
182 
184  bool IsValidToUpdate(Client* client) const;
185 
187  void Update(Client* client, psMGUpdateMessage &msg);
188 
195  void Send(uint32_t clientID, uint32_t modOptions);
196 
198  void Broadcast();
199 
201  virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
202 
204  void Idle();
205 
207  bool GameSessionActive(void);
208 
210  void SetSessionReset(void)
211  {
212  toReset = true;
213  }
214 
216  bool GetSessionReset(void)
217  {
218  return toReset;
219  }
220 
222  bool IsSessionPublic(void);
223 
224 protected:
225 
228 
230  uint32_t id;
231 
233  csString name;
234 
236  csWeakRef<gemObject> actionObject;
237 
239  uint16_t options;
240 
242  csPDelArray<MinigamePlayer> players;
243 
245  csArray<uint32_t> watchers;
246 
248  uint8_t currentCounter;
249 
252 
254  bool toReset;
255 
258 
259 private:
261  bool endgameReached;
262 
264  uint8_t playerCount;
265 
267  csString winnerScript;
268 
270  MinigameStyle minigameStyle;
271 
273  csString paramZero;
274  csString paramOne;
275  csString paramTwo;
276 
278  void ResendBoardLayout(MinigamePlayer* player);
279 
281  bool GameMovePassesRules(MinigamePlayer* player,
282  int8_t col1, int8_t row1, int8_t state1,
283  int8_t col2=-1, int8_t row2=-1, int8_t state2=-1);
284 };
285 
286 
293 class MiniGameManager : public MessageManager<MiniGameManager>
294 {
295 
296 public:
297 
298  MiniGameManager();
299 
300  ~MiniGameManager();
301 
303  psMiniGameSession* GetSessionByID(uint32_t id);
304 
306  void Idle();
307 
309  bool Initialise();
310 
312  psMiniGameBoardDef* FindGameDef(csString gameName);
313 
315  void ResetAllGameSessions(void);
316 
317 protected:
318 
320  void HandleStartStop(MsgEntry* me, Client* client);
321 
323  void HandleGameUpdate(MsgEntry* me, Client* client);
324 
326  void HandleStartGameRequest(Client* client);
327 
329  void HandleStopGameRequest(Client* client);
330 
332  void RemovePlayerFromSessions(psMiniGameSession* session, Client* client, uint32_t clientID);
333 
335  void ResetGameSession(psMiniGameSession* sessionToReset);
336 
338  int16_t ParseGameboardOptions(psString optionsStr);
340  csPDelArray<psMiniGameSession> sessions;
341 
343  csHash<psMiniGameSession*, uint32_t> playerSessions;
344 
346  csHash<psMiniGameBoardDef*, csString> gameBoardDef;
347 };
348 
351 #endif
MinigamePlayer * nextPlayerToMove
pointer to next player to move
bool GetSessionReset(void)
Gets reset status of session.
const csString & GetName() const
Returns the session name.
int blackOrWhite
identifies colour pieces for player TODO this is temp
MinigamePlayer * nextMover
point to next player to move
uint16_t options
Game options.
void SetSessionReset(void)
Sets session to be reset (i.e. deleted and restarted next play)
Structure to hold player data.
csWeakRef< gemObject > actionObject
Action location object.
single player mini-game
uint32_t id
The game session ID (equals to the action location ID)
Wrapper class for game board.
csHash< psMiniGameBoardDef *, csString > gameBoardDef
Minigame board definitions by name.
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
Game board definition class.
csArray< uint32_t > watchers
Watchers.
csString name
The game session name.
const char * playerName
normally 2 or more player mini-game
csPDelArray< MinigamePlayer > players
Minigame players.
const uint32_t GetID() const
Returns the game session ID.
csHash< psMiniGameSession *, uint32_t > playerSessions
Maps players to game sessions for quicker access.
bool toReset
if game session marked for reset
MiniGameManager * manager
Game manager.
csPDelArray< psMiniGameSession > sessions
Game sessions.
This class collects data of a netclient.
Definition: client.h:95
uint16_t GetOptions() const
Returns the game options.
int idleCounter
Idle counter for the player with black pieces.
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
Handles minigame sessions.
Message from the client with a minigame board update.
Definition: messages.h:5690
uint8_t currentCounter
Current message counter for versionin.
MinigameStyle
psMiniGameBoard gameBoard
The current game board.
This class generically allows objects to be notified when a gemObject is removed. ...
Implements one minigame session.
Provides a manager to facilitate subscriptions.
Definition: msgmanager.h:106