PRooFPS-dd Dev Doc 1.0
PRooFPS-dd Developer Documentation
Loading...
Searching...
No Matches
proofps_dd::DeathMatchMode Class Reference

In DeathMatch a.k.a. More...

Detailed Description

In DeathMatch a.k.a.

FFA (Free For All) game mode, everyone is shooting everyone, and the winner is whoever has the most frags when either the frag limit or time limit is reached. Note: it is also valid to not to have either frag limit or time limit set, but in such case the game never ends.

Definition at line 242 of file GameMode.h.

#include <GameMode.h>

+ Inheritance diagram for proofps_dd::DeathMatchMode:

Public Member Functions

 DeathMatchMode ()
 
virtual ~DeathMatchMode ()
 
 DeathMatchMode (const DeathMatchMode &)=delete
 
DeathMatchModeoperator= (const DeathMatchMode &)=delete
 
 DeathMatchMode (DeathMatchMode &&)=delete
 
DeathMatchMode && operator= (DeathMatchMode &&)=delete
 
virtual void fetchConfig (PGEcfgProfiles &cfgProfiles, pge_network::PgeINetwork &network) override
 Fetches configuration from the given PGEcfgProfiles instance.
 
virtual bool serverCheckAndUpdateWinningConditions (pge_network::PgeINetwork &network) override
 Evaluates conditions to see if game is won or not.
 
virtual void clientReceiveAndUpdateWinningConditions (pge_network::PgeINetwork &network, bool bGameSessionWon) override
 Handles server's update about current game session goal, e.g.
 
unsigned int getTimeLimitSecs () const
 
void setTimeLimitSecs (unsigned int secs)
 Set the time limit for the game.
 
unsigned int getTimeRemainingMillisecs () const
 
void clientUpdateTimeRemainingMillisecs (const unsigned int &nRemMillisecs, pge_network::PgeINetwork &network)
 Updates the remaining time on client side, based on the remaining time received from server.
 
unsigned int getFragLimit () const
 
void setFragLimit (unsigned int limit)
 Set the frag limit for the game.
 
virtual bool addPlayer (const Player &player, pge_network::PgeINetwork &network) override
 Adds the specified player.
 
virtual bool updatePlayer (const Player &player, pge_network::PgeINetwork &network) override
 Updates data for the specified player.
 
virtual bool removePlayer (const Player &player) override
 Removes data for the specified player.
 
- Public Member Functions inherited from proofps_dd::GameMode
CConsole & getConsole () const
 
virtual ~GameMode ()
 
GameModeType getGameModeType () const
 
const std::chrono::time_point< std::chrono::steady_clock > & getResetTime () const
 
virtual void restart (pge_network::PgeINetwork &network)
 Similar to restartWithoutRemovingPlayers() but it also removes all players from this GameMode instance.
 
virtual void restartWithoutRemovingPlayers (pge_network::PgeINetwork &network)
 Resets winning time and winning condition, also zeros out relevant members of FragTableRow for all players.
 
bool isGameWon () const
 Returns the current game session win state i.e.
 
const std::chrono::time_point< std::chrono::steady_clock > & getWinTime () const
 
const std::list< FragTableRow > & getFragTable () const
 
bool renamePlayer (const std::string &sOldName, const std::string &sNewName)
 Renames the player.
 
void text (PR00FsUltimateRenderingEngine &pure, const std::string &s, int x, int y) const
 

Static Private Member Functions

static int comparePlayers (int p1frags, int p2frags, int p1deaths, int p2deaths)
 

Private Attributes

unsigned int m_nTimeLimitSecs {}
 
unsigned int m_nFragLimit {}
 

Additional Inherited Members

- Static Public Member Functions inherited from proofps_dd::GameMode
static const char * getLoggerModuleName ()
 
static GameModecreateGameMode (GameModeType gm)
 
- Static Public Attributes inherited from proofps_dd::GameMode
static constexpr char * szCvarSvDmFragLimit = "sv_dm_fraglimit"
 
static constexpr char * szCvarSvDmTimeLimit = "sv_dm_timelimit_secs"
 
static constexpr int nSvDmFragLimitDef = 10
 
static constexpr int nSvDmFragLimitMin = 0
 
static constexpr int nSvDmFragLimitMax = 999
 
static constexpr int nSvDmTimeLimitSecsDef = 0
 
static constexpr int nSvDmTimeLimitSecsMin = 0
 
static constexpr int nSvDmTimeLimitSecsMax = 60 * 60 * 24
 
- Protected Member Functions inherited from proofps_dd::GameMode
 GameMode (GameModeType gm)
 
 GameMode (const GameMode &)=delete
 
GameModeoperator= (const GameMode &)=delete
 
 GameMode (GameMode &&)=delete
 
GameMode && operator= (GameMode &&)=delete
 
bool serverSendGameSessionStateToClient (pge_network::PgeINetwork &network, const pge_network::PgeNetworkConnectionHandle &connHandle)
 
bool serverSendGameSessionStateToClients (pge_network::PgeINetwork &network)
 
- Protected Attributes inherited from proofps_dd::GameMode
std::chrono::time_point< std::chrono::steady_clock > m_timeWin
 
std::list< FragTableRowm_players
 
bool m_bWon { false }
 
std::chrono::time_point< std::chrono::steady_clock > m_timeReset
 

Constructor & Destructor Documentation

◆ DeathMatchMode() [1/3]

proofps_dd::DeathMatchMode::DeathMatchMode ( )

Definition at line 194 of file GameMode.cpp.

◆ ~DeathMatchMode()

proofps_dd::DeathMatchMode::~DeathMatchMode ( )
virtual

Definition at line 199 of file GameMode.cpp.

◆ DeathMatchMode() [2/3]

proofps_dd::DeathMatchMode::DeathMatchMode ( const DeathMatchMode & )
delete

◆ DeathMatchMode() [3/3]

proofps_dd::DeathMatchMode::DeathMatchMode ( DeathMatchMode && )
delete

Member Function Documentation

◆ addPlayer()

bool proofps_dd::DeathMatchMode::addPlayer ( const Player & player,
pge_network::PgeINetwork & network )
overridevirtual

Adds the specified player.

In case of server instance, it automatically evaluates winning condition, and in case of winning it also updates winning time and sends out MsgGameSessionStateFromServer to all clients. Note that once a game is won, it stays won even if players are updated to fail the winning conditions, until explicit call to restart().

Fails if a player with same name is already added.

Returns
True if added the new player, false otherwise.

Implements proofps_dd::GameMode.

Definition at line 316 of file GameMode.cpp.

◆ clientReceiveAndUpdateWinningConditions()

void proofps_dd::DeathMatchMode::clientReceiveAndUpdateWinningConditions ( pge_network::PgeINetwork & network,
bool bGameSessionWon )
overridevirtual

Handles server's update about current game session goal, e.g.

game is won. Server sends out such notification occasionally only, when something relevant has changed about the current game session.

This function is for client instance only.

Parameters
bGameSessionWonTrue if the current game session goal has been just reached, false otherwise.

Implements proofps_dd::GameMode.

Definition at line 246 of file GameMode.cpp.

◆ clientUpdateTimeRemainingMillisecs()

void proofps_dd::DeathMatchMode::clientUpdateTimeRemainingMillisecs ( const unsigned int & nRemMillisecs,
pge_network::PgeINetwork & network )

Updates the remaining time on client side, based on the remaining time received from server.

Basically it corrects the game restart time on client side so client will have the roughly same game restart time as the server. TODO: time related functions should really be in GameMode class, I dont see use of putting it in DeathMatch and it complicates things.

Parameters
nRemMillisecsRemaining time in milliseconds, from server.
networkPGE network instance to be used to know if we are server or client.

Definition at line 292 of file GameMode.cpp.

◆ comparePlayers()

int proofps_dd::DeathMatchMode::comparePlayers ( int p1frags,
int p2frags,
int p1deaths,
int p2deaths )
staticprivate

Definition at line 433 of file GameMode.cpp.

◆ fetchConfig()

void proofps_dd::DeathMatchMode::fetchConfig ( PGEcfgProfiles & cfgProfiles,
pge_network::PgeINetwork & network )
overridevirtual

Fetches configuration from the given PGEcfgProfiles instance.

For now it does not do validation, as all validations are currently implemented in the Config class. TODO: on the long run, validation should be also done, by proper planning and implementing an IConfigHandler interface, as described in the comment above.

Parameters
cfgProfilesThe current user config profile from where we can fetch value of GameMode-specific CVARs.
networkPGE network instance to be used to know if we are server or client.

Implements proofps_dd::GameMode.

Definition at line 203 of file GameMode.cpp.

◆ getFragLimit()

unsigned int proofps_dd::DeathMatchMode::getFragLimit ( ) const
Returns
Configured frag limit previously set by setFragLimit(). 0 means no frag limit.

Definition at line 306 of file GameMode.cpp.

◆ getTimeLimitSecs()

unsigned int proofps_dd::DeathMatchMode::getTimeLimitSecs ( ) const
Returns
Configured time limit previously set by setTimeLimitSecs(). 0 means no time limit.

Definition at line 263 of file GameMode.cpp.

◆ getTimeRemainingMillisecs()

unsigned int proofps_dd::DeathMatchMode::getTimeRemainingMillisecs ( ) const
Returns
Milliseconds remaining until time limit is reached, calculated from the current time and last reset time (getResetTime()). 0 if there is no time limit set, or if the game was not yet reset, or if the time limit has been already reached, or the game has been won for any reason.

Definition at line 273 of file GameMode.cpp.

◆ operator=() [1/2]

DeathMatchMode & proofps_dd::DeathMatchMode::operator= ( const DeathMatchMode & )
delete

◆ operator=() [2/2]

DeathMatchMode && proofps_dd::DeathMatchMode::operator= ( DeathMatchMode && )
delete

◆ removePlayer()

bool proofps_dd::DeathMatchMode::removePlayer ( const Player & player)
overridevirtual

Removes data for the specified player.

Fails if player with same cannot be found.

Does not evaluate winning conditions, since once a game is won, it stays won even if all players are removed, until explicit call to restart().

Returns
True if removed the existing player, false otherwise.

Implements proofps_dd::GameMode.

Definition at line 416 of file GameMode.cpp.

◆ serverCheckAndUpdateWinningConditions()

bool proofps_dd::DeathMatchMode::serverCheckAndUpdateWinningConditions ( pge_network::PgeINetwork & network)
overridevirtual

Evaluates conditions to see if game is won or not.

Since conditions depend on game mode, the actual implementation must be in the specific derived game mode class. Note that once a game is won, it stays won even if all players are removed, until explicit call to restart().

This function is for server instance only. It also sends out MsgGameSessionStateFromServer to all clients in case game session state is changed as a result of the call.

Parameters
networkPGE network instance to be used to send out MsgGameSessionStateFromServer if needed.
Returns
True if game is won, false otherwise.

Implements proofps_dd::GameMode.

Definition at line 210 of file GameMode.cpp.

◆ setFragLimit()

void proofps_dd::DeathMatchMode::setFragLimit ( unsigned int limit)

Set the frag limit for the game.

If the frag limit is reached, the winner is the player with most frags, even if time limit is not yet reached or there is no time limit set. Note: behavior is unspecified if this value is changed on-the-fly during a game. For now, please also call restart() explicitly.

Parameters
limitThe frag limit. If 0, there is no frag limit.

Definition at line 311 of file GameMode.cpp.

◆ setTimeLimitSecs()

void proofps_dd::DeathMatchMode::setTimeLimitSecs ( unsigned int secs)

Set the time limit for the game.

If time limit expires, the winner is the player with most frags, even if frag limit is not set or not reached. Note: behavior is unspecified if this value is changed on-the-fly during a game. For now, please also call restart() explicitly.

Parameters
secsThe time limit in seconds. If 0, there is no time limit.

Definition at line 268 of file GameMode.cpp.

◆ updatePlayer()

bool proofps_dd::DeathMatchMode::updatePlayer ( const Player & player,
pge_network::PgeINetwork & network )
overridevirtual

Updates data for the specified player.

In case of server instance, it automatically evaluates winning condition, and in case of winning it also updates winning time and sends out MsgGameSessionStateFromServer to all clients. Note that once a game is won, it stays won even if players are updated to fail the winning conditions, until explicit call to restart().

Fails if player with same cannot be found.

Returns
True if updated the existing player, false otherwise.

Implements proofps_dd::GameMode.

Definition at line 359 of file GameMode.cpp.

Member Data Documentation

◆ m_nFragLimit

unsigned int proofps_dd::DeathMatchMode::m_nFragLimit {}
private

Definition at line 319 of file GameMode.h.

◆ m_nTimeLimitSecs

unsigned int proofps_dd::DeathMatchMode::m_nTimeLimitSecs {}
private

Definition at line 318 of file GameMode.h.


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