Planeshift
Public Member Functions | Protected Attributes

psMiniGameSession Class Reference

Implements one minigame session. More...

#include <minigamemanager.h>

List of all members.

Public Member Functions

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

Protected Attributes

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

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:

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

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.

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.

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.

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: