Planeshift
|
00001 /* 00002 * psminigameboard.h 00003 * 00004 * Copyright (C) 2008 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 __MINIGAMEBOARD_H 00021 #define __MINIGAMEBOARD_H 00022 00023 //============================================================================= 00024 // Crystal Space Includes 00025 //============================================================================= 00026 00027 //============================================================================= 00028 // Project Includes 00029 //============================================================================= 00030 #include "psstdint.h" 00031 00032 //============================================================================= 00033 // Local Includes 00034 //============================================================================= 00035 00036 class Client; 00037 00041 #define GAMEBOARD_MIN_PLAYERS 1 00042 #define GAMEBOARD_MAX_PLAYERS 2 00043 #define GAMEBOARD_DEFAULT_PLAYERS 2 00044 00048 enum Rule_PlayerTurn 00049 { 00050 RELAXED, 00051 ORDERED, 00052 STRICT_ORDERED 00053 }; 00054 enum Rule_MovePieceType 00055 { 00056 PLACE_OR_MOVE, 00057 PLACE_ONLY, 00058 MOVE_ONLY 00059 }; 00060 enum Rule_MoveablePieces 00061 { 00062 ANY_PIECE, 00063 OWN_PIECES_ONLY 00064 }; 00065 enum Rule_MovePiecesTo 00066 { 00067 ANYWHERE, 00068 VACANCY_ONLY 00069 }; 00070 enum Rule_MoveDirection 00071 { 00072 ANY, 00073 VERTICAL, 00074 HORIZONTAL, 00075 CROSS, 00076 DIAGONAL 00077 }; 00078 00083 enum Endgame_TileType 00084 { 00085 PLAYED_PIECE, 00086 WHITE_PIECE, 00087 BLACK_PIECE, 00088 NO_PIECE, 00089 FOLLOW_SOURCE_TILE, 00090 SPECIFIC_TILE 00091 }; 00092 00093 struct Endgame_TileSpec 00094 { 00095 int col; 00096 int row; 00097 Endgame_TileType tile; 00098 uint8_t specificTile; 00099 }; 00100 00101 struct Endgame_Spec 00102 { 00103 bool positionsAbsolute; // true=x,y coords absolute, false=coords relative to source tile 00104 Endgame_TileType sourceTile; 00105 Endgame_TileType winner; 00106 csArray<Endgame_TileSpec*> endgameTiles; 00107 }; 00108 00109 /*********************************************************************************/ 00110 00116 class psMiniGameBoardDef 00117 { 00118 friend class psMiniGameBoard; 00119 00120 public: 00121 00122 psMiniGameBoardDef(const uint8_t defCols, const uint8_t defRows, 00123 const char* defLayout, const char* defPieces, 00124 const uint8_t defPlayers, const int16_t options); 00125 00126 ~psMiniGameBoardDef(); 00127 00129 uint8_t GetCols() const 00130 { 00131 return cols; 00132 } 00133 00135 uint8_t GetRows() const 00136 { 00137 return rows; 00138 } 00139 00141 int GetLayoutSize() const 00142 { 00143 return layoutSize; 00144 }; 00145 00147 void PackLayoutString(const char* layoutStr, uint8_t* packedLayout); 00148 00150 uint8_t PackPiece(char pieceStr); 00151 00153 uint16_t GetGameboardOptions(void) 00154 { 00155 return gameboardOptions; 00156 }; 00157 00159 bool DetermineGameRules(csString rulesXMLstr, csString name); 00160 00162 bool DetermineEndgameSpecs(csString endgameXMLstr, csString name); 00163 00165 void ClearOutEndgames(void) 00166 { 00167 endgames.Empty(); 00168 }; 00169 00170 private: 00172 int layoutSize; 00173 00175 uint8_t* layout; 00176 00178 uint8_t cols; 00179 00181 uint8_t rows; 00182 00184 uint8_t numPieces; 00185 00187 uint8_t piecesSize; 00188 00190 uint8_t* pieces; 00191 00193 uint8_t numPlayers; 00194 00196 int16_t gameboardOptions; 00197 00199 Rule_PlayerTurn playerTurnRule; 00200 Rule_MovePieceType movePieceTypeRule; 00201 Rule_MoveablePieces moveablePiecesRule; 00202 Rule_MovePiecesTo movePiecesToRule; 00203 Rule_MoveDirection moveDirectionRule; 00204 int moveDistanceRule; 00205 00207 csArray<Endgame_Spec*> endgames; 00208 bool EvaluateTileTypeStr(csString TileTypeStr, Endgame_TileType &tileType); 00209 00210 }; 00211 00212 00218 class psMiniGameBoard 00219 { 00220 public: 00221 00222 psMiniGameBoard(); 00223 00224 ~psMiniGameBoard(); 00225 00227 void Setup(psMiniGameBoardDef* newGameDef, uint8_t* preparedLayout); 00228 00230 uint8_t GetCols() const 00231 { 00232 return gameBoardDef->cols; 00233 } 00234 00236 uint8_t GetRows() const 00237 { 00238 return gameBoardDef->rows; 00239 } 00240 00242 uint8_t* GetLayout() const 00243 { 00244 return layout; 00245 }; 00246 00248 uint8_t GetNumPieces() const 00249 { 00250 return gameBoardDef->numPieces; 00251 } 00252 00254 uint8_t GetPiecesSize() const 00255 { 00256 return gameBoardDef->piecesSize; 00257 } 00258 00260 uint8_t* GetPieces() const 00261 { 00262 return gameBoardDef->pieces; 00263 } 00264 00266 uint8_t Get(uint8_t col, uint8_t row) const; 00267 00269 void Set(uint8_t col, uint8_t row, uint8_t state); 00270 00272 uint8_t GetNumPlayers(void) 00273 { 00274 return gameBoardDef->numPlayers; 00275 }; 00276 00278 Rule_PlayerTurn GetPlayerTurnRule(void) 00279 { 00280 return gameBoardDef->playerTurnRule; 00281 }; 00282 Rule_MovePieceType GetMovePieceTypeRule(void) 00283 { 00284 return gameBoardDef->movePieceTypeRule; 00285 }; 00286 Rule_MoveablePieces GetMoveablePiecesRule(void) 00287 { 00288 return gameBoardDef->moveablePiecesRule; 00289 }; 00290 Rule_MovePiecesTo GetMovePiecesToRule(void) 00291 { 00292 return gameBoardDef->movePiecesToRule; 00293 }; 00294 Rule_MoveDirection GetMoveDirectionRule(void) 00295 { 00296 return gameBoardDef->moveDirectionRule; 00297 }; 00298 int GetMoveDistanceRule(void) 00299 { 00300 return gameBoardDef->moveDistanceRule; 00301 }; 00302 00304 bool DetermineEndgame(Endgame_TileType &winningPiece); 00305 00306 private: 00307 00309 Endgame_TileType EndgameWinner(uint8_t winningTileState); 00310 00312 uint8_t* layout; 00313 00315 psMiniGameBoardDef* gameBoardDef; 00316 }; 00317 00318 #endif 00319