From: <mr...@us...> - 2008-12-18 18:10:45
|
Revision: 2711 http://planeshift.svn.sourceforge.net/planeshift/?rev=2711&view=rev Author: mr_dave Date: 2008-12-18 18:10:35 +0000 (Thu, 18 Dec 2008) Log Message: ----------- Coding guidelines improvements to minigames files Modified Paths: -------------- trunk/docs/history.txt trunk/src/client/gui/pawsgameboard.cpp trunk/src/client/gui/pawsgameboard.h trunk/src/common/util/minigame.h trunk/src/server/bulkobjects/psminigameboard.cpp trunk/src/server/bulkobjects/psminigameboard.h trunk/src/server/minigamemanager.cpp trunk/src/server/minigamemanager.h Modified: trunk/docs/history.txt =================================================================== --- trunk/docs/history.txt 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/docs/history.txt 2008-12-18 18:10:35 UTC (rev 2711) @@ -1,4 +1,7 @@ -*** 2008-12-18 by Stefano Angeleri +*** 2008-12-18 by Dave Bentham +- Coding guidelines improvements to minigames files. + +*** 2008-12-18 by Stefano Angeleri - Changed ReadableRaceGender() to use csstring fixing the data being sent to clients. Now when doing groups you will see the icon of the race again. Modified: trunk/src/client/gui/pawsgameboard.cpp =================================================================== --- trunk/src/client/gui/pawsgameboard.cpp 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/client/gui/pawsgameboard.cpp 2008-12-18 18:10:35 UTC (rev 2711) @@ -47,20 +47,20 @@ rows = 0; // Setup the piece ID to art file conversion table - pieceArt.Put(White1, "Minigame Piece White 1"); - pieceArt.Put(White2, "Minigame Piece White 2"); - pieceArt.Put(White3, "Minigame Piece White 3"); - pieceArt.Put(White4, "Minigame Piece White 4"); - pieceArt.Put(White5, "Minigame Piece White 5"); - pieceArt.Put(White6, "Minigame Piece White 6"); - pieceArt.Put(White7, "Minigame Piece White 7"); - pieceArt.Put(Black1, "Minigame Piece Black 1"); - pieceArt.Put(Black2, "Minigame Piece Black 2"); - pieceArt.Put(Black3, "Minigame Piece Black 3"); - pieceArt.Put(Black4, "Minigame Piece Black 4"); - pieceArt.Put(Black5, "Minigame Piece Black 5"); - pieceArt.Put(Black6, "Minigame Piece Black 6"); - pieceArt.Put(Black7, "Minigame Piece Black 7"); + pieceArt.Put(WHITE_1, "Minigame Piece White 1"); + pieceArt.Put(WHITE_2, "Minigame Piece White 2"); + pieceArt.Put(WHITE_3, "Minigame Piece White 3"); + pieceArt.Put(WHITE_4, "Minigame Piece White 4"); + pieceArt.Put(WHITE_5, "Minigame Piece White 5"); + pieceArt.Put(WHITE_6, "Minigame Piece White 6"); + pieceArt.Put(WHITE_7, "Minigame Piece White 7"); + pieceArt.Put(BLACK_1, "Minigame Piece Black 1"); + pieceArt.Put(BLACK_2, "Minigame Piece Black 2"); + pieceArt.Put(BLACK_3, "Minigame Piece Black 3"); + pieceArt.Put(BLACK_4, "Minigame Piece Black 4"); + pieceArt.Put(BLACK_5, "Minigame Piece Black 5"); + pieceArt.Put(BLACK_6, "Minigame Piece Black 6"); + pieceArt.Put(BLACK_7, "Minigame Piece Black 7"); } pawsGameBoard::~pawsGameBoard() @@ -116,7 +116,7 @@ // if this update is resetting a disallowed move, need to resync // with server & other clients, so undo the counter by 1. - if (msg.msgOptions & DisallowedMove) + if (msg.msgOptions & DISALLOWED_MOVE) currentCounter--; // Update or setup the game board @@ -243,20 +243,20 @@ gameOptions = msg.msgOptions; // Start from the bottom-right corner if we play with black pieces - if (gameOptions & BlackPieces) + if (gameOptions & BLACK_PIECES) { x += w*cols; y += h*rows; } // Start with a white (or black) tile - bool white = !(gameOptions & BlackSquare); + bool white = !(gameOptions & BLACK_SQUARE); for (int8_t i = 0; i < rows; i++) { for (int8_t j = 0; j < cols; j++) { - uint8_t state = EmptyTile; + uint8_t state = EMPTY_TILE; // Check the layout if (msg.msgLayout) @@ -269,7 +269,7 @@ state = (v & 0xF0) >> 4; } - if (state != DisabledTile) + if (state != DISABLED_TILE) { pawsGameTile *tile = new pawsGameTile; @@ -288,7 +288,7 @@ tile->SetBackground("Minigame Tile Black"); // Reposition the game tile - if (gameOptions & BlackPieces) + if (gameOptions & BLACK_PIECES) tile->SetRelativeFrame(x-(j+1)*w, y-(i+1)*h, w, h); else tile->SetRelativeFrame(x+j*w, y+i*h, w, h); @@ -300,13 +300,13 @@ } // Flip colors - if (!(gameOptions & PlainSquares)) + if (!(gameOptions & PLAIN_SQUARES)) white = !white; } // Flip the color once more if we have an even number of columns - if (cols % 2 == 0 && !(gameOptions & PlainSquares)) + if (cols % 2 == 0 && !(gameOptions & PLAIN_SQUARES)) white = !white; } @@ -324,22 +324,21 @@ piece = msg.msgPieces[idx] & 0x0F; else piece = (msg.msgPieces[idx] & 0xF0) >> 4; - if (piece >= White1 && piece <= White7) + if (piece >= WHITE_1 && piece <= WHITE_7) whitePieces.Push(piece); - else if (piece >= Black1 && piece <= Black7) + else if (piece >= BLACK_1 && piece <= BLACK_7) blackPieces.Push(piece); } } else { // By default we will have only one white and one black variant of pieces - whitePieces.Push(White1); - blackPieces.Push(Black1); + whitePieces.Push(WHITE_1); + blackPieces.Push(BLACK_1); } // Show the window Show(); - } void pawsGameBoard::UpdateBoard(psMGBoardMessage &msg) @@ -375,7 +374,7 @@ else state = (v & 0xF0) >> 4; - if (state != DisabledTile && k < tiles.GetSize()) + if (state != DISABLED_TILE && k < tiles.GetSize()) { tiles[k++]->SetState(state); } @@ -397,9 +396,9 @@ piece = msg.msgPieces[idx] & 0x0F; else piece = (msg.msgPieces[idx] & 0xF0) >> 4; - if (piece >= White1 && piece <= White7) + if (piece >= WHITE_1 && piece <= WHITE_7) whitePieces.Push(piece); - else if (piece >= Black1 && piece <= Black7) + else if (piece >= BLACK_1 && piece <= BLACK_7) blackPieces.Push(piece); } } @@ -429,7 +428,7 @@ if (oldTile) { updates[idx++] = (oldTile->GetColumn() << 4) + oldTile->GetRow(); - updates[idx++] = EmptyTile; + updates[idx++] = EMPTY_TILE; cnt++; } // New location. @@ -446,7 +445,6 @@ psMGUpdateMessage msg(0, ++currentCounter, gameID, cnt, updates); msgHandler->SendMessage(msg.msg); } - } void pawsGameBoard::UpdatePiece(pawsGameTile *tile) @@ -475,12 +473,11 @@ widget->SetRelativeFrame(0, 0, tile->DefaultFrame().Width(), tile->DefaultFrame().Height()); widget->SetState(tile->GetState()); PawsManager::GetSingleton().SetDragDropWidget(widget); - } uint8_t pawsGameBoard::NextPiece(uint8_t current) const { - if (current >= White1 && current <= White7) + if (current >= WHITE_1 && current <= WHITE_7) { size_t i = 0; @@ -499,7 +496,7 @@ } } - else if (current >= Black1 && current <= Black7) + else if (current >= BLACK_1 && current <= BLACK_7) { size_t i = 0; @@ -519,7 +516,7 @@ } else - return EmptyTile; + return EMPTY_TILE; } const csString pawsGameBoard::PieceArtName(uint8_t piece) const @@ -540,11 +537,10 @@ configurable = false; fade = true; - state = EmptyTile; - oldState = EmptyTile; + state = EMPTY_TILE; + oldState = EMPTY_TILE; column = -1; row = -1; - } pawsGameTile::~pawsGameTile() @@ -570,7 +566,7 @@ { pawsWidget::Draw(); - if (state != EmptyTile) + if (state != EMPTY_TILE) { csRect frame = screenFrame; ClipToParent(); @@ -580,7 +576,7 @@ bool pawsGameTile::OnMouseDown(int button, int modifiers, int x, int y) { - if (!board || board->GetGameOptions() & ReadOnly) + if (!board || board->GetGameOptions() & READ_ONLY) return false; // Use the EntitySelect mouse bind to select pieces/create player's pieces @@ -592,16 +588,16 @@ SetState(tile->GetState()); board->DropPiece(this); } - else if (state == EmptyTile) + else if (state == EMPTY_TILE) { - SetState(board->GetGameOptions() & BlackPieces ? + SetState(board->GetGameOptions() & BLACK_PIECES ? board->BlackPiecesList(0) : board->WhitePiecesList(0)); board->UpdatePiece(this); } else { board->StartDragging(this); - SetState(EmptyTile); + SetState(EMPTY_TILE); } return true; } @@ -609,9 +605,9 @@ // Use the ContextMenu mouse bind to create oponent's pieces if (psengine->GetMouseBinds()->CheckBind("ContextMenu", button, modifiers)) { - if (state == EmptyTile) + if (state == EMPTY_TILE) { - SetState(board->GetGameOptions() & BlackPieces ? + SetState(board->GetGameOptions() & BLACK_PIECES ? board->WhitePiecesList(0) : board->BlackPiecesList(0)); board->UpdatePiece(this); } @@ -628,10 +624,10 @@ bool pawsGameTile::OnDoubleClick(int button, int modifiers, int x, int y) { - if (!board || board->GetGameOptions() & ReadOnly) + if (!board || board->GetGameOptions() & READ_ONLY) return false; - if (psengine->GetMouseBinds()->CheckBind("EntitySelect", button, modifiers) && state != EmptyTile) + if (psengine->GetMouseBinds()->CheckBind("EntitySelect", button, modifiers) && state != EMPTY_TILE) { SetState(board->NextPiece(state)); @@ -655,7 +651,7 @@ if (state != this->state) { - if (state != EmptyTile && state != DisabledTile) + if (state != EMPTY_TILE && state != DISABLED_TILE) { csString art = board->PieceArtName(state); if (art.IsEmpty()) Modified: trunk/src/client/gui/pawsgameboard.h =================================================================== --- trunk/src/client/gui/pawsgameboard.h 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/client/gui/pawsgameboard.h 2008-12-18 18:10:35 UTC (rev 2711) @@ -26,7 +26,8 @@ class pawsGameBoard; -/** +/** Game tile class. + * * Defines one game tile with or without game pieces on it. */ class pawsGameTile : public pawsWidget @@ -93,9 +94,10 @@ }; - -/** - * The game window class. +/** The game window class. + * + * Minigame PAWS class handles the gameboard on the client: + * moves from players and updates from the server. */ class pawsGameBoard : public pawsWidget, public psClientNetSubscriber { @@ -159,7 +161,7 @@ if (whitePieces.GetSize() > 0) return whitePieces.Get(idx); else - return psMiniGame::White1; + return psMiniGame::WHITE_1; } /// List of available black pieces. @@ -168,7 +170,7 @@ if (blackPieces.GetSize() > 0) return blackPieces.Get(idx); else - return psMiniGame::Black1; + return psMiniGame::BLACK_1; } /// Number of available white pieces Modified: trunk/src/common/util/minigame.h =================================================================== --- trunk/src/common/util/minigame.h 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/common/util/minigame.h 2008-12-18 18:10:35 UTC (rev 2711) @@ -35,38 +35,38 @@ /// Minigame options enum GameOptions { - ManagedGame = 0x01, ///< A game managed by the server. - BlackPieces = 0x02, ///< Player with black pieces. - ReadOnly = 0x04, ///< The game is read-only (for watchers). - PersonalGame = 0x08, ///< The game is personal & private - BlackSquare = 0x10, ///< Top left/all squares Black. Else white. - PlainSquares = 0x20, ///< Board squares all plain. Else checked. - DisallowedMove = 0x40, ///< Last move disallowed - ObserveEndGame = 0x80 ///< observe endgame play + MANAGED_GAME = 0x01, ///< A game managed by the server. + BLACK_PIECES = 0x02, ///< Player with black pieces. + READ_ONLY = 0x04, ///< The game is read-only (for watchers). + PERSONAL_GAME = 0x08, ///< The game is personal & private + BLACK_SQUARE = 0x10, ///< Top left/all squares Black. Else white. + PLAIN_SQUARES = 0x20, ///< Board squares all plain. Else checked. + DISALLOWED_MOVE = 0x40, ///< Last move disallowed + OBSERVE_ENDGAME = 0x80 ///< observe endgame play }; /// Minigame tile state values enum TileStates { - EmptyTile = 0, ///< An empty game tile. + EMPTY_TILE = 0, ///< An empty game tile. - White1 = 1, ///< White regular game piece - White2, - White3, - White4, - White5, - White6, - White7, + WHITE_1 = 1, ///< White regular game piece + WHITE_2, + WHITE_3, + WHITE_4, + WHITE_5, + WHITE_6, + WHITE_7, - Black1 = 8, ///< Black regular game piece. - Black2, - Black3, - Black4, - Black5, - Black6, - Black7, + BLACK_1 = 8, ///< Black regular game piece. + BLACK_2, + BLACK_3, + BLACK_4, + BLACK_5, + BLACK_6, + BLACK_7, - DisabledTile = 15 ///< Disable game tile. + DISABLED_TILE = 15 ///< Disable game tile. }; }; Modified: trunk/src/server/bulkobjects/psminigameboard.cpp =================================================================== --- trunk/src/server/bulkobjects/psminigameboard.cpp 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/server/bulkobjects/psminigameboard.cpp 2008-12-18 18:10:35 UTC (rev 2711) @@ -340,7 +340,7 @@ case 'b': tileType = BLACK_PIECE; // tile has black piece break; case 'E': - case 'e': tileType = EMPTY_TILE; // empty tile + case 'e': tileType = NO_PIECE; // empty tile break; case 'F': case 'f': tileType = FOLLOW_SOURCE_TILE; // tile has piece as per first tile in pattern @@ -387,7 +387,7 @@ uint8_t psMiniGameBoard::Get(uint8_t col, uint8_t row) const { if (col >= gameBoardDef->cols || row >= gameBoardDef->rows || !layout) - return DisabledTile; + return DISABLED_TILE; int idx = row*gameBoardDef->cols + col; uint8_t v = layout[idx/2]; @@ -406,12 +406,12 @@ uint8_t v = layout[idx/2]; if (idx % 2) { - if ((v & 0x0F) != DisabledTile) + if ((v & 0x0F) != DISABLED_TILE) layout[idx/2] = (v & 0xF0) + (state & 0x0F); } else { - if ((v & 0xF0) >> 4 != DisabledTile) + if ((v & 0xF0) >> 4 != DISABLED_TILE) layout[idx/2] = (v & 0x0F) + ((state & 0x0F) << 4); } } @@ -443,15 +443,15 @@ tileAtPos = Get(endgameTile->col, endgameTile->row); - if (tileAtPos == DisabledTile || endgame->sourceTile == FOLLOW_SOURCE_TILE) + if (tileAtPos == DISABLED_TILE || endgame->sourceTile == FOLLOW_SOURCE_TILE) break; - if (endgameTile->tile == PLAYED_PIECE && tileAtPos == EmptyTile) + if (endgameTile->tile == PLAYED_PIECE && tileAtPos == EMPTY_TILE) break; - if (endgameTile->tile == EMPTY_TILE && tileAtPos != EmptyTile) + if (endgameTile->tile == NO_PIECE && tileAtPos != EMPTY_TILE) break; - if (endgameTile->tile == WHITE_PIECE && (tileAtPos < White1 || tileAtPos > White7)) + if (endgameTile->tile == WHITE_PIECE && (tileAtPos < WHITE_1 || tileAtPos > WHITE_7)) break; - if (endgameTile->tile == BLACK_PIECE && (tileAtPos < Black1 || tileAtPos > Black7)) + if (endgameTile->tile == BLACK_PIECE && (tileAtPos < BLACK_1 || tileAtPos > BLACK_7)) break; if (endgameTile->tile == FOLLOW_SOURCE_TILE) break; @@ -476,9 +476,9 @@ { // look for next initial played piece uint8_t initialTile = Get(colCount, rowCount); - if ((initialTile >= White1 && initialTile <= White7 && + if ((initialTile >= WHITE_1 && initialTile <= WHITE_7 && (endgame->sourceTile == WHITE_PIECE || endgame->sourceTile == PLAYED_PIECE)) || - (initialTile >= Black1 && initialTile <= Black7 && + (initialTile >= BLACK_1 && initialTile <= BLACK_7 && (endgame->sourceTile == BLACK_PIECE || endgame->sourceTile == PLAYED_PIECE))) { // ... and then through each tile for the endgame pattern @@ -491,15 +491,15 @@ colCount+endgameTile->col < 0 || rowCount+endgameTile->row < 0) break; tileAtPos = Get(colCount+endgameTile->col, rowCount+endgameTile->row); - if (tileAtPos == DisabledTile || endgame->sourceTile == FOLLOW_SOURCE_TILE) + if (tileAtPos == DISABLED_TILE || endgame->sourceTile == FOLLOW_SOURCE_TILE) break; - if (endgameTile->tile == PLAYED_PIECE && (tileAtPos < White1 || tileAtPos > Black7)) + if (endgameTile->tile == PLAYED_PIECE && (tileAtPos < WHITE_1 || tileAtPos > BLACK_7)) break; - if (endgameTile->tile == WHITE_PIECE && (tileAtPos < White1 || tileAtPos > White7)) + if (endgameTile->tile == WHITE_PIECE && (tileAtPos < WHITE_1 || tileAtPos > WHITE_7)) break; - if (endgameTile->tile == BLACK_PIECE && (tileAtPos < Black1 || tileAtPos > Black7)) + if (endgameTile->tile == BLACK_PIECE && (tileAtPos < BLACK_1 || tileAtPos > BLACK_7)) break; - if (endgameTile->tile == EMPTY_TILE && tileAtPos != EmptyTile) + if (endgameTile->tile == NO_PIECE && tileAtPos != EMPTY_TILE) break; if (endgameTile->tile == FOLLOW_SOURCE_TILE && tileAtPos != initialTile) break; Modified: trunk/src/server/bulkobjects/psminigameboard.h =================================================================== --- trunk/src/server/bulkobjects/psminigameboard.h 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/server/bulkobjects/psminigameboard.h 2008-12-18 18:10:35 UTC (rev 2711) @@ -77,7 +77,7 @@ PLAYED_PIECE, WHITE_PIECE, BLACK_PIECE, - EMPTY_TILE, + NO_PIECE, FOLLOW_SOURCE_TILE }; @@ -97,8 +97,10 @@ /*********************************************************************************/ -/** - * Game board definition class. +/** Game board definition class. + * + * Class for defining a mini-game, including board dimensions & layout + * and game rules. */ class psMiniGameBoardDef { @@ -155,6 +157,7 @@ /// The package list of available game pieces. uint8_t *pieces; + /// Number of players required for game. uint8_t numPlayers; /// gameboard options flags @@ -173,8 +176,10 @@ }; -/** - * Wrapper class for the game board layout buffer. +/** Wrapper class for game board. + * + * Wrapper class for a mini-game in play, and exists singly with a + * unique mini-game session. */ class psMiniGameBoard { Modified: trunk/src/server/minigamemanager.cpp =================================================================== --- trunk/src/server/minigamemanager.cpp 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/server/minigamemanager.cpp 2008-12-18 18:10:35 UTC (rev 2711) @@ -122,6 +122,7 @@ psString optionsStr(gameboards[i]["gameboardOptions"]); csString rulesXML(gameboards[i]["gameRules"]); csString endgameXML(gameboards[i]["endgames"]); + // verify basics of definition if (name && layout && pieces && cols >= GAMEBOARD_MIN_COLS && cols <= GAMEBOARD_MAX_COLS && rows >= GAMEBOARD_MIN_ROWS && rows <= GAMEBOARD_MAX_ROWS && @@ -141,7 +142,9 @@ gameDef->DetermineGameRules(rulesXML, name); if (!gameDef->DetermineEndgameSpecs(endgameXML, name)) + { gameDef->ClearOutEndgames(); + } } else { @@ -168,10 +171,13 @@ } if (msg.msgStart) + { HandleStartGameRequest(client); + } else + { HandleStopGameRequest(client); - + } } else if (me->GetType() == MSGTYPE_MINIGAME_UPDATE) @@ -282,7 +288,9 @@ playerSessions.DeleteAll(clientID); if (session->GetSessionReset()) + { ResetGameSession(session); + } // if session is personal, delete it. if (!session->IsSessionPublic()) @@ -320,7 +328,7 @@ // Verify the session if (!session->IsValidToUpdate(client)) { - session->Send(clientID, ReadOnly); + session->Send(clientID, READ_ONLY); return; } @@ -341,7 +349,9 @@ for (size_t i = 0; i < sessions.GetSize(); i++) { if (sessions.Get(i)->GetID() == id) + { return sessions.Get(i); + } } return 0; } @@ -390,13 +400,13 @@ // look for black/white. White by default. if (optionsStr.FindSubString("black",0,true) != -1) { - localOptions |= BlackSquare; + localOptions |= BLACK_SQUARE; } // look for checked/plain. Checked by default. if (optionsStr.FindSubString("plain",0,true) != -1) { - localOptions |= PlainSquares; + localOptions |= PLAIN_SQUARES; } // parse the options string @@ -430,20 +440,26 @@ { Client *client = clients->Find(whitePlayerID); if (client && client->GetActor()) + { client->GetActor()->UnregisterCallback(this); + } } if (blackPlayerID != (uint32_t)-1) { Client *client = clients->Find(blackPlayerID); if (client && client->GetActor()) + { client->GetActor()->UnregisterCallback(this); + } } csArray<uint32_t>::Iterator iter = watchers.GetIterator(); while (iter.HasNext()) { Client *client = clients->Find(iter.Next()); if (client && client->GetActor()) + { client->GetActor()->UnregisterCallback(this); + } } } } @@ -521,7 +537,7 @@ csString sessionStr(boardNode->GetAttributeValue("Session")); if (sessionStr.Downcase() == "personal") { - options |= PersonalGame; + options |= PERSONAL_GAME; } else if (sessionStr.Length() > 0 && sessionStr.Downcase() != "public") { @@ -533,7 +549,7 @@ csString endgameStr(boardNode->GetAttributeValue("EndGame")); if (endgameStr.Downcase() == "yes") { - options |= ObserveEndGame; + options |= OBSERVE_ENDGAME; } else if (endgameStr.Length() > 0 && endgameStr.Downcase() != "no") { @@ -544,7 +560,7 @@ gameBoard.Setup(gameBoardDef, layout); // if session is personal, check its a 1-player game - if ((options & PersonalGame) && gameBoard.GetNumPlayers() > 1) + if ((options & PERSONAL_GAME) && gameBoard.GetNumPlayers() > 1) { Error2("Personal game %s has 2 or more players, which is untenable.", gameName); return false; @@ -552,7 +568,9 @@ // intialise player to move first, if appropriate if (gameBoard.GetPlayerTurnRule() == ORDERED) + { nextPlayerToMove = 1; + } return true; } @@ -578,8 +596,10 @@ whiteIdleCounter = MINIGAME_IDLE_TIME; // If this is a managed game, reset the game board - if (options & ManagedGame) + if (options & MANAGED_GAME) + { Restart(); + } // Send notifications psSystemMessage newmsg(clientID, MSG_INFO, "%s started playing %s with white pieces.", @@ -623,7 +643,9 @@ void psMiniGameSession::RemovePlayer(Client *client) { if (!client || client->GetClientNum() == (uint32_t)-1) + { return; + } client->GetActor()->UnregisterCallback(this); @@ -665,7 +687,6 @@ psMGStartStopMessage msg(clientID, false); msg.SendMessage(); - #ifdef DEBUG_MINIGAMES Debug3(LOG_ANY, 0, "Removed player %u from the game session \"%s\"\n", clientID, name.GetData()); #endif @@ -681,7 +702,6 @@ void psMiniGameSession::Broadcast() { - if (whitePlayerID != (uint32_t)-1) { Send(whitePlayerID, 0); @@ -689,7 +709,7 @@ if (blackPlayerID != (uint32_t)-1) { - Send(blackPlayerID, BlackPieces); + Send(blackPlayerID, BLACK_PIECES); } csArray<uint32_t>::Iterator iter = watchers.GetIterator(); @@ -697,7 +717,9 @@ { uint32_t id = iter.Next(); if (id != (uint32_t)-1) - Send(id, ReadOnly); + { + Send(id, READ_ONLY); + } } } @@ -705,7 +727,9 @@ { if (!client || client->GetClientNum() == (uint32_t)-1) + { return false; + } uint32_t clientID = client->GetClientNum(); @@ -803,22 +827,26 @@ // Update idle counters if (clientnum == whitePlayerID) + { whiteIdleCounter = MINIGAME_IDLE_TIME; + } else if (clientnum == blackPlayerID) + { blackIdleCounter = MINIGAME_IDLE_TIME; + } // Broadcast the new game board layout Broadcast(); // see if endgame has been identified? - bool endgameReached = (options & ObserveEndGame) ? gameBoard.DetermineEndgame() : false; + bool endgameReached = (options & OBSERVE_ENDGAME) ? gameBoard.DetermineEndgame() : false; // if endgame reached, determine winner - if (endgameReached && piecePlayed >= White1 && piecePlayed <= Black7) + if (endgameReached && piecePlayed >= WHITE_1 && piecePlayed <= BLACK_7) { // winner determined by colour of last piece played uint32_t winnerID, loserID; - if (piecePlayed >= White1 && piecePlayed <= White7) + if (piecePlayed >= WHITE_1 && piecePlayed <= WHITE_7) { winnerID = whitePlayerID; loserID = blackPlayerID; @@ -833,11 +861,17 @@ psserver->SendSystemInfo(winnerID, (GetName() + ": You have won!")); csString wonText = GetName() + ": "; if (winnerID == whitePlayerID && whitePlayerName) + { wonText += csString(whitePlayerName) + " (white)"; + } else if (winnerID == blackPlayerID && blackPlayerName) + { wonText += csString(blackPlayerName) + " (black)"; + } else + { wonText += "Someone"; + } wonText += " has won."; psserver->SendSystemInfo(loserID, wonText); @@ -847,7 +881,9 @@ { uint32_t id = iter.Next(); if (id != (uint32_t)-1) + { psserver->SendSystemInfo(id, wonText); + } } } else @@ -855,11 +891,17 @@ // broadcast the move info too csString movedText = GetName() + ": "; if (clientnum == whitePlayerID && whitePlayerName) + { movedText += csString(whitePlayerName) + " (white)"; + } else if (clientnum == blackPlayerID && blackPlayerName) + { movedText += csString(blackPlayerName) + " (black)"; + } else + { movedText += "Someone"; + } movedText += " has moved."; if (clientnum == whitePlayerID && blackPlayerID != (uint32_t)-1) @@ -875,7 +917,9 @@ { uint32_t id = iter.Next(); if (id != (uint32_t)-1) + { psserver->SendSystemInfo(id, movedText); + } } } @@ -883,9 +927,13 @@ if (nextPlayerToMove > 0) { if (nextPlayerToMove < gameBoard.GetNumPlayers()) + { nextPlayerToMove++; + } else + { nextPlayerToMove = 1; + } } } @@ -893,12 +941,16 @@ { gemActor *actor = (gemActor *)object; if (!actor) + { return; + } Client *client = actor->GetClient(); if (client) + { RemovePlayer(client); + } } void psMiniGameSession::Idle() @@ -916,7 +968,9 @@ { Client *client = psserver->GetNetManager()->GetClient(whitePlayerID); if (client) + { RemovePlayer(client); + } } } @@ -931,7 +985,9 @@ { Client *client = psserver->GetNetManager()->GetClient(blackPlayerID); if (client) + { RemovePlayer(client); + } } } @@ -964,17 +1020,23 @@ bool psMiniGameSession::IsSessionPublic(void) { - return !(options & PersonalGame); + return !(options & PERSONAL_GAME); } void psMiniGameSession::ResendBoardLayout(uint32_t clientnum) { if (clientnum == whitePlayerID) - Send(whitePlayerID, DisallowedMove); + { + Send(whitePlayerID, DISALLOWED_MOVE); + } else if (clientnum == blackPlayerID) - Send(blackPlayerID, BlackPieces | DisallowedMove); + { + Send(blackPlayerID, BLACK_PIECES | DISALLOWED_MOVE); + } else - Send(clientnum, ReadOnly | DisallowedMove); + { + Send(clientnum, READ_ONLY | DISALLOWED_MOVE); + } // after a disallowed move, the other clients will be out of sync // with server & disallowed client, so resync. @@ -998,18 +1060,18 @@ if (gameBoard.GetMoveablePiecesRule() == OWN_PIECES_ONLY) { TileStates movingPiece = (TileStates) gameBoard.Get(col1, row1); - if (movingClient == whitePlayerID && (movingPiece < White1 || movingPiece > White7)) + if (movingClient == whitePlayerID && (movingPiece < WHITE_1 || movingPiece > WHITE_7)) { return false; } - else if (movingClient == blackPlayerID && (movingPiece < Black1 || movingPiece > Black7)) + else if (movingClient == blackPlayerID && (movingPiece < BLACK_1 || movingPiece > BLACK_7)) { return false; } } if (!newPiecePlayed && - gameBoard.GetMovePiecesToRule() == VACANCY_ONLY && gameBoard.Get(col2, row2) != EmptyTile) + gameBoard.GetMovePiecesToRule() == VACANCY_ONLY && gameBoard.Get(col2, row2) != EMPTY_TILE) { return false; } Modified: trunk/src/server/minigamemanager.h =================================================================== --- trunk/src/server/minigamemanager.h 2008-12-18 18:07:48 UTC (rev 2710) +++ trunk/src/server/minigamemanager.h 2008-12-18 18:10:35 UTC (rev 2711) @@ -42,8 +42,7 @@ class gemActionLocation; class gemObject; -/** - * Implements one minigame session. +/** Implements one minigame session. * * Game sessions are bound to a game board (action location) and identified * by a unique name. The name of the game board is defined in the action_locations table (name field). @@ -53,7 +52,7 @@ * and an optional prepared layout & is expected to have the * following format: * <Examine> - * <GameBoard Name='gameboard name' [Layout='board layout'] [Session=personal|public] /> + * <GameBoard Name='gameboard name' [Layout='board layout'] [Session='personal'|'public'] [EndGame='yes'|'no'] /> * <Description>Description as seen by players</Description> * </Examine> * @@ -66,6 +65,9 @@ * private game. Set to public is for the traditional board game, and is the default if * this option is omitted. * + * The EndGame attribute specifies whether this game session is to adhere to the end-game rules. + * Optional. Default is No. + * * In the future we will add more attributes like for game options and name of a plugin or * script for managed games. @@ -133,10 +135,13 @@ /// Checks if game is actually active at all bool GameSessionActive(void); + /// Sets session to be reset (i.e. deleted and restarted next play) void SetSessionReset(void) { toReset = true; } + /// Gets reset status of session bool GetSessionReset(void) { return toReset; } + /// returns whether this is a public session or not. bool IsSessionPublic(void); protected: @@ -196,8 +201,10 @@ }; -/** - * This manager handles minigame sessions. +/** Handles minigame sessions. + * + * This is the manager class of mini-games, handling overall mini-game definitions, + * action-location gameboards and game sessions. */ class MiniGameManager : public MessageManager { @@ -208,8 +215,10 @@ ~MiniGameManager(); + /// Handles message from client. virtual void HandleMessage(MsgEntry *me, Client *client); + /// returns session by its id. psMiniGameSession *GetSessionByID(uint32_t id); /// Idle function to check for idle players and players too far away. @@ -226,16 +235,22 @@ protected: + /// client requests start of game session. void HandleStartGameRequest(Client *client); + /// client handles stopping of game session. void HandleStopGameRequest(Client *client); + /// a client is removed from a game session. void RemovePlayerFromSessions(psMiniGameSession *session, Client *client, uint32_t clientID); + /// handles a client that has made a move. void HandleGameUpdate(Client *client, psMGUpdateMessage &msg); + /// requests a session to be reset. void ResetGameSession(psMiniGameSession *sessionToReset); + /// function parses game options string from gameboards DB table. int16_t ParseGameboardOptions(psString optionsStr); /// Game sessions. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |