Planeshift
psMiniGameSession Class Reference

Implements one minigame session. More...

#include <minigamemanager.h>

Public Member Functions

void AddPlayer (Client *client)
 Adds a player to the session. More...
 
void Broadcast ()
 Broadcast the current game board layout to all the players/watchers. More...
 
virtual void DeleteObjectCallback (iDeleteNotificationObject *object)
 Handles disconnected players. More...
 
bool GameSessionActive (void)
 Checks if game is actually active at all. More...
 
const uint32_t GetID () const
 Returns the game session ID. More...
 
const csString & GetName () const
 Returns the session name. More...
 
uint16_t GetOptions () const
 Returns the game options. More...
 
bool GetSessionReset (void)
 Gets reset status of session. More...
 
void Idle ()
 Checks for idle players and players too far away. More...
 
bool IsSessionPublic (void)
 returns whether this is a public session or not. More...
 
bool IsValidToUpdate (Client *client) const
 Returns true if it is valid for this player to update the game board. More...
 
bool Load (csString &responseString)
 Loads the game. More...
 
 psMiniGameSession (MiniGameManager *mng, gemActionLocation *obj, const char *name)
 
void RemovePlayer (Client *client)
 Removes a player from the session. More...
 
void Restart ()
 Restarts the game. More...
 
void Send (uint32_t clientID, uint32_t modOptions)
 Sends the current game board to the given player. More...
 
void SetSessionReset (void)
 Sets session to be reset (i.e. deleted and restarted next play) More...
 
void Update (Client *client, psMGUpdateMessage &msg)
 Updates the game board. NB! Call IsValidToUpdate() first to verify that updating is valid. More...
 
 ~psMiniGameSession ()
 
- Public Member Functions inherited from iDeleteObjectCallback
virtual ~iDeleteObjectCallback ()
 

Protected Attributes

csWeakRef< gemObjectactionObject
 Action location object. More...
 
uint8_t currentCounter
 Current message counter for versionin. More...
 
psMiniGameBoard gameBoard
 The current game board. More...
 
uint32_t id
 The game session ID (equals to the action location ID) More...
 
MiniGameManagermanager
 Game manager. More...
 
csString name
 The game session name. More...
 
MinigamePlayernextPlayerToMove
 pointer to next player to move More...
 
uint16_t options
 Game options. More...
 
csPDelArray< MinigamePlayerplayers
 Minigame players. More...
 
bool toReset
 if game session marked for reset More...
 
csArray< uint32_t > watchers
 Watchers. More...
 

Detailed Description

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).

The game itself is defined in the gameboards db table. gameboard options include:

  • name : the name of the board
  • layout : the layout of the board in terms of tiles and shape
  • numColumns, numRows : the size x,y of the full board
  • numPlayers: defines if it's a single player or multiplayer minigame
  • gameboardOptions: White/Black (colors the board white or black), Plain (makes it one color), Checked (checkerboard)
  • gameRules: PlayerTurns can be 'Ordered' (order of players' moves enforced) or 'StrictOrdered' (as Ordered, and all players must be present) or 'Relaxed' (default - free for all). MoveType can be 'MoveOnly' (player can only move existing pieces), or 'PlaceOnly' (player can only place new pieces on the board; cant move others), or 'PlaceOrMovePiece' (default - either move existing or place new pieces). MoveDistance can be an integer number MoveDirection can be 'Vertical', 'Horizontal', 'Cross', 'Diagonal' MoveablePieces can be 'Own' (player can only move their own pieces) or 'Any' (default - player can move any piece in play). MoveTo can be 'Vacancy' (player can move pieces to vacant squares only) or 'Anywhere' (default - can move to any square, vacant or occupied).
  • endgames: <MGEndGame> <EndGame Coords="relative"/"absolute" [SourceTile="T"] [Winner="T"]> <Coord Col="0-15" Row="0-15" Tile="T" [Piece="X"] /> </EndGame> </MGEndGame> where T : A = any valid piece / W = any white piece / B = any black piece E = empty tile / F = follows source piece / S = specific pieces Each <EndGame> has 1 or more <Coord> spec. Each <MGEndGame> has 1 or more <EndGame>. Endgames can be left blank.

The response string specifies the name to the record in gameboards and an optional prepared layout & is expected to have the following format: <Examine> <GameBoard Name='gameboard name' [Layout='board layout'] [Session='personal'|'public'] [EndGame='yes'|'no'] /> <Description>Description as seen by players</Description> </Examine>

The Layout attribute defines the layout of the game board and optionally also preset game pieces on it. Optional - to override the default set in the database.

The Session attribute allows a game to be personal (restricted to one-player games) whereby only the player sees the game, no other players or watchers. One such minigame at one action_location can spawn a session per player who plays their own 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.

Every session can have 0, 1, 2 or more players attached to it. The first player gets white game pieces and the second player black game pieces. All other players can just watch the game.

Definition at line 138 of file minigamemanager.h.

Constructor & Destructor Documentation

psMiniGameSession::psMiniGameSession ( MiniGameManager mng,
gemActionLocation obj,
const char *  name 
)
psMiniGameSession::~psMiniGameSession ( )

Member Function Documentation

void psMiniGameSession::AddPlayer ( Client client)

Adds a player to the session.

void psMiniGameSession::Broadcast ( )

Broadcast the current game board layout to all the players/watchers.

virtual void psMiniGameSession::DeleteObjectCallback ( iDeleteNotificationObject object)
virtual

Handles disconnected players.

Implements iDeleteObjectCallback.

bool psMiniGameSession::GameSessionActive ( void  )

Checks if game is actually active at all.

const uint32_t psMiniGameSession::GetID ( ) const
inline

Returns the game session ID.

Definition at line 147 of file minigamemanager.h.

const csString& psMiniGameSession::GetName ( ) const
inline

Returns the session name.

Definition at line 153 of file minigamemanager.h.

uint16_t psMiniGameSession::GetOptions ( ) const
inline

Returns the game options.

Definition at line 159 of file minigamemanager.h.

bool psMiniGameSession::GetSessionReset ( void  )
inline

Gets reset status of session.

Definition at line 216 of file minigamemanager.h.

void psMiniGameSession::Idle ( )

Checks for idle players and players too far away.

bool psMiniGameSession::IsSessionPublic ( void  )

returns whether this is a public session or not.

bool psMiniGameSession::IsValidToUpdate ( Client client) const

Returns true if it is valid for this player to update the game board.

bool psMiniGameSession::Load ( csString &  responseString)

Loads the game.

The Load() function loads the game from the given action location response string.

Parameters
[in]responseStringThe string with minigame options and board layout.
Returns
Returns true if the game was loaded and false if not.
void psMiniGameSession::RemovePlayer ( Client client)

Removes a player from the session.

void psMiniGameSession::Restart ( )

Restarts the game.

void psMiniGameSession::Send ( uint32_t  clientID,
uint32_t  modOptions 
)

Sends the current game board to the given player.

Parameters
[in]clientIDThe ID of the client.
[in]modOptionsModifier for game options.
void psMiniGameSession::SetSessionReset ( void  )
inline

Sets session to be reset (i.e. deleted and restarted next play)

Definition at line 210 of file minigamemanager.h.

void psMiniGameSession::Update ( Client client,
psMGUpdateMessage msg 
)

Updates the game board. NB! Call IsValidToUpdate() first to verify that updating is valid.

Member Data Documentation

csWeakRef<gemObject> psMiniGameSession::actionObject
protected

Action location object.

Definition at line 236 of file minigamemanager.h.

uint8_t psMiniGameSession::currentCounter
protected

Current message counter for versionin.

Definition at line 248 of file minigamemanager.h.

psMiniGameBoard psMiniGameSession::gameBoard
protected

The current game board.

Definition at line 251 of file minigamemanager.h.

uint32_t psMiniGameSession::id
protected

The game session ID (equals to the action location ID)

Definition at line 230 of file minigamemanager.h.

MiniGameManager* psMiniGameSession::manager
protected

Game manager.

Definition at line 227 of file minigamemanager.h.

csString psMiniGameSession::name
protected

The game session name.

Definition at line 233 of file minigamemanager.h.

MinigamePlayer* psMiniGameSession::nextPlayerToMove
protected

pointer to next player to move

Definition at line 257 of file minigamemanager.h.

uint16_t psMiniGameSession::options
protected

Game options.

Definition at line 239 of file minigamemanager.h.

csPDelArray<MinigamePlayer> psMiniGameSession::players
protected

Minigame players.

Definition at line 242 of file minigamemanager.h.

bool psMiniGameSession::toReset
protected

if game session marked for reset

Definition at line 254 of file minigamemanager.h.

csArray<uint32_t> psMiniGameSession::watchers
protected

Watchers.

Definition at line 245 of file minigamemanager.h.


The documentation for this class was generated from the following file: