Planeshift

minigamemanager.h

Go to the documentation of this file.
00001 /*
00002 * minigamemanager.h - Author: Enar Vaikene
00003 *
00004 * Copyright (C) 2006 Atomic Blue ([email protected], http://www.atomicblue.org)
00005 *
00006 *
00007 * This program is free software; you can redistribute it and/or
00008 * modify it under the terms of the GNU General Public License
00009 * as published by the Free Software Foundation (version 2 of the License)
00010 * This program is distributed in the hope that it will be useful,
00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 * GNU General Public License for more details.
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 *
00018 */
00019 
00020 #ifndef __MINIGAMEMANAGER_H
00021 #define __MINIGAMEMANAGER_H
00022 
00023 //=============================================================================
00024 // Crystal Space Includes
00025 //=============================================================================
00026 #include <csutil/weakref.h>
00027 
00028 //=============================================================================
00029 // Project Includes
00030 //=============================================================================
00031 #include "bulkobjects/psminigameboard.h"
00032 
00033 //=============================================================================
00034 // Local Includes
00035 //=============================================================================
00036 #include "deleteobjcallback.h"
00037 #include "msgmanager.h"             // Parent class
00038 
00039 class Client;
00040 class MiniGameManager;
00041 class gemActionLocation;
00042 class gemObject;
00043 class psMGUpdateMessage;
00044 
00049 enum MinigameStyle
00050 {
00051     MG_GAME,    
00052     MG_PUZZLE   
00053 };
00054 
00058 struct MinigamePlayer
00059 {
00060     uint32_t playerID;
00061     const char* playerName;
00062 
00064     int idleCounter;
00065 
00067     MinigamePlayer* nextMover;
00068 
00070     int blackOrWhite;
00071 };
00072 
00138 class psMiniGameSession : public iDeleteObjectCallback
00139 {
00140 public:
00141 
00142     psMiniGameSession(MiniGameManager* mng, gemActionLocation* obj, const char* name);
00143 
00144     ~psMiniGameSession();
00145 
00147     const uint32_t GetID() const
00148     {
00149         return id;
00150     }
00151 
00153     const csString &GetName() const
00154     {
00155         return name;
00156     }
00157 
00159     uint16_t GetOptions() const
00160     {
00161         return options;
00162     }
00163 
00172     bool Load(csString &responseString);
00173 
00175     void Restart();
00176 
00178     void AddPlayer(Client* client);
00179 
00181     void RemovePlayer(Client* client);
00182 
00184     bool IsValidToUpdate(Client* client) const;
00185 
00187     void Update(Client* client, psMGUpdateMessage &msg);
00188 
00195     void Send(uint32_t clientID, uint32_t modOptions);
00196 
00198     void Broadcast();
00199 
00201     virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
00202 
00204     void Idle();
00205 
00207     bool GameSessionActive(void);
00208 
00210     void SetSessionReset(void)
00211     {
00212         toReset = true;
00213     }
00214 
00216     bool GetSessionReset(void)
00217     {
00218         return toReset;
00219     }
00220 
00222     bool IsSessionPublic(void);
00223 
00224 protected:
00225 
00227     MiniGameManager* manager;
00228 
00230     uint32_t id;
00231 
00233     csString name;
00234 
00236     csWeakRef<gemObject> actionObject;
00237 
00239     uint16_t options;
00240 
00242     csPDelArray<MinigamePlayer> players;
00243 
00245     csArray<uint32_t> watchers;
00246 
00248     uint8_t currentCounter;
00249 
00251     psMiniGameBoard gameBoard;
00252 
00254     bool toReset;
00255 
00257     MinigamePlayer* nextPlayerToMove;
00258 
00259 private:
00261     bool endgameReached;
00262 
00264     uint8_t playerCount;
00265 
00267     csString winnerScript;
00268 
00270     MinigameStyle minigameStyle;
00271 
00273     csString paramZero;
00274     csString paramOne;
00275     csString paramTwo;
00276 
00278     void ResendBoardLayout(MinigamePlayer* player);
00279 
00281     bool GameMovePassesRules(MinigamePlayer* player,
00282                              int8_t col1, int8_t row1, int8_t state1,
00283                              int8_t col2=-1, int8_t row2=-1, int8_t state2=-1);
00284 };
00285 
00286 
00293 class MiniGameManager : public MessageManager<MiniGameManager>
00294 {
00295 
00296 public:
00297 
00298     MiniGameManager();
00299 
00300     ~MiniGameManager();
00301 
00303     psMiniGameSession* GetSessionByID(uint32_t id);
00304 
00306     void Idle();
00307 
00309     bool Initialise();
00310 
00312     psMiniGameBoardDef* FindGameDef(csString gameName);
00313 
00315     void ResetAllGameSessions(void);
00316 
00317 protected:
00318 
00320     void HandleStartStop(MsgEntry* me, Client* client);
00321 
00323     void HandleGameUpdate(MsgEntry* me, Client* client);
00324 
00326     void HandleStartGameRequest(Client* client);
00327 
00329     void HandleStopGameRequest(Client* client);
00330 
00332     void RemovePlayerFromSessions(psMiniGameSession* session, Client* client, uint32_t clientID);
00333 
00335     void ResetGameSession(psMiniGameSession* sessionToReset);
00336 
00338     int16_t ParseGameboardOptions(psString optionsStr);
00340     csPDelArray<psMiniGameSession> sessions;
00341 
00343     csHash<psMiniGameSession*, uint32_t> playerSessions;
00344 
00346     csHash<psMiniGameBoardDef*, csString> gameBoardDef;
00347 };
00348 
00351 #endif