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.

Although we have player teamId, we don't use it in this game mode at all.

Definition at line 475 of file GameMode.h.

#include <GameMode.h>

+ Inheritance diagram for proofps_dd::DeathMatchMode:

Public Member Functions

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
 Extending parent class implementation by checking player frags against frag limit, if any is set.
 
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, pge_network::PgeINetwork &network) override
 Removes data for the specified player.
 
virtual bool isTeamBasedGame () const override
 Derived class shall return false if it is non-team-based game, otherwise true.
 
virtual bool isRoundBased () const override
 
virtual bool isRespawnAllowedAfterDie () const override
 
virtual bool isPlayerAllowedForGameplay (const Player &player) const override
 Checks if given player is allowed for gameplay.
 
- Public Member Functions inherited from proofps_dd::GameMode
CConsole & getConsole () const
 
virtual ~GameMode ()
 
GameModeType getGameModeType () const
 
const char * getGameModeTypeName () const
 
const std::chrono::time_point< std::chrono::steady_clock > & getResetTime () const
 
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.
 
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, const proofps_dd::GameRestartType_KeepPlayers &eRestartType)
 Resets winning time and winning condition, also zeros out relevant members of PlayersTableRow for all players.
 
void clientReceiveAndUpdateWinningConditions (pge_network::PgeINetwork &network, bool bGameSessionWon)
 Handles server's update about current game session goal, e.g.
 
virtual void serverTickUpdateWinningConditions (pge_network::PgeINetwork &network)
 Shall be invoked regularly (per tick or per frame) at the end of server tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly.
 
virtual void clientTickUpdateWinningConditions (pge_network::PgeINetwork &network)
 Shall be invoked regularly (per tick or per frame) at the end of client tick or frame loop so hasJustBeenWonThisTick() and further functionalities in derived classes can work properly.
 
bool isGameWon () const
 Returns the current game session win state i.e.
 
bool wasGameWonAlreadyInPreviousTick () const
 Returns if the current game session was already won in the previous tick.
 
bool hasJustBeenWonThisTick () const
 Returns if the current game session has been just detected as won in this tick i.e.
 
const std::chrono::time_point< std::chrono::steady_clock > & getWinTime () const
 
const std::list< PlayersTableRow > & getPlayersTable () const
 
const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & getExternalPlayersContainer () const
 
bool renamePlayer (const std::string &sOldName, const std::string &sNewName)
 Renames the player.
 
virtual bool isPlayerMovementAllowed () const
 
unsigned int getSpectatorModePlayersCount () const
 
void text (PR00FsUltimateRenderingEngine &pure, const std::string &s, int x, int y) const
 

Static Public Member Functions

static std::unique_ptr< DeathMatchModecreateGameMode (const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers)
 Used by GameMode::createGameMode(), this way we don't need to be friend with GameMode.
 
- Static Public Member Functions inherited from proofps_dd::GameMode
static const char * getLoggerModuleName ()
 
static GameModecreateGameMode (GameModeType gm, const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers)
 Similar to singleton design pattern, there is always maximum one instance.
 
static GameModegetGameMode ()
 
static bool isTeamBasedGame (GameModeType gm)
 
static bool isRoundBased (GameModeType gm)
 
static const char * getGameModeTypeName (GameModeType gm)
 
static GameModeType getGameModeTypeFromConfig (PGEcfgProfiles &cfgProfiles)
 
static const char * getRank (const PlayersTableRow &row)
 

Protected Member Functions

 DeathMatchMode (const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers)
 
- Protected Member Functions inherited from proofps_dd::GameMode
 GameMode (GameModeType gm, const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > &mapPlayers)
 
 GameMode (const GameMode &)=delete
 
GameModeoperator= (const GameMode &)=delete
 
 GameMode (GameMode &&)=delete
 
GameMode && operator= (GameMode &&)=delete
 
virtual bool serverSendGameSessionStateToClient (pge_network::PgeINetwork &network, const pge_network::PgeNetworkConnectionHandle &connHandle)
 
virtual bool serverSendGameSessionStateToClients (pge_network::PgeINetwork &network, const proofps_dd::GameRestartType_KeepPlayers &eRestartType)
 
void handleEventGameWon (pge_network::PgeINetwork &network)
 

Protected Attributes

unsigned int m_nFragLimit {}
 
- Protected Attributes inherited from proofps_dd::GameMode
std::chrono::time_point< std::chrono::steady_clock > m_timeWin
 
std::list< PlayersTableRowm_players
 
const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & m_mapPlayersExternal
 
bool m_bWon { false }
 
bool m_bWonPrevious { false }
 
GameModeType m_gameModeType
 

Static Private Member Functions

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

Additional Inherited Members

- Static Public Attributes inherited from proofps_dd::GameMode
static constexpr char * szCvarSvGamemode = "sv_gamemode"
 
static constexpr char * szCvarSvGmTimeLimit = "sv_gm_timelimit_secs"
 
static constexpr char * szCvarSvDmFragLimit = "sv_dm_fraglimit"
 
static constexpr char * szCvarSvRgmRoundWinLimit = "sv_rgm_roundwinlimit"
 
static constexpr int nSvGmTimeLimitSecsDef = 0
 
static constexpr int nSvGmTimeLimitSecsMin = 0
 
static constexpr int nSvGmTimeLimitSecsMax = 60 * 60 * 24
 
static constexpr int nSvDmFragLimitDef = 10
 
static constexpr int nSvDmFragLimitMin = 0
 
static constexpr int nSvDmFragLimitMax = 999
 
static constexpr int nSvRgmRoundWinLimitDef = 5
 
static constexpr int nSvRgmRoundWinLimitMin = 1
 
static constexpr int nSvRgmRoundWinLimitMax = 999
 

Constructor & Destructor Documentation

◆ ~DeathMatchMode()

proofps_dd::DeathMatchMode::~DeathMatchMode ( )
virtual

Definition at line 526 of file GameMode.cpp.

◆ DeathMatchMode() [1/3]

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

◆ DeathMatchMode() [2/3]

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

◆ DeathMatchMode() [3/3]

proofps_dd::DeathMatchMode::DeathMatchMode ( const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & mapPlayers)
protected

Definition at line 741 of file GameMode.cpp.

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, if the added player is a client, it SHALL immediately send game win condition to this client using serverSendGameSessionStateToClient(). In case of server instance, it SHALL automatically evaluate winning condition using serverCheckAndUpdateWinningConditions() after adding the player. 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().

Note that GameMode does not ensure that a spectating player cannot win a game. The game shall ensure that the player does not gain any frags while in spectator mode! Therefore, if the added player already has enough frags to flip game won state, the game will go into won state, regardless of the player's spectating state!

Fails if a player with same name is already added.

Returns
True if added the new player, false otherwise.

Implements proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamDeathMatchMode, and proofps_dd::TeamRoundGameMode.

Definition at line 574 of file GameMode.cpp.

◆ comparePlayers()

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

Definition at line 725 of file GameMode.cpp.

◆ createGameMode()

std::unique_ptr< proofps_dd::DeathMatchMode > proofps_dd::DeathMatchMode::createGameMode ( const std::map< pge_network::PgeNetworkConnectionHandle, proofps_dd::Player > & mapPlayers)
static

Used by GameMode::createGameMode(), this way we don't need to be friend with GameMode.

The previous GameMode instance is destroyed automatically. See GameMode::createGameMode() for more details.

Returns
Smart pointer to the created TeamRoundGameMode instance.

Definition at line 519 of file GameMode.cpp.

◆ fetchConfig()

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

Fetches configuration from the given PGEcfgProfiles instance.

Derived class shall extend this function by overriding and calling this parent implementation from the specialized implementation.

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.

Reimplemented from proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamRoundGameMode.

Definition at line 530 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 564 of file GameMode.cpp.

◆ isPlayerAllowedForGameplay()

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

Checks if given player is allowed for gameplay.

For example, in a team-based game mode, server can freeze player actions when no team is assigned to the player. But it also checks for spectator mode.

Can be used by both server and client instances. Must also work properly on client-side, since in player-follow spectating view, this function is used to determine which players can be spectated.

Returns
True if player is ready and active for gameplay in the current game mode, false otherwise.

Reimplemented from proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamDeathMatchMode.

Definition at line 720 of file GameMode.cpp.

◆ isRespawnAllowedAfterDie()

bool proofps_dd::DeathMatchMode::isRespawnAllowedAfterDie ( ) const
overridevirtual

Implements proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamRoundGameMode.

Definition at line 715 of file GameMode.cpp.

◆ isRoundBased()

bool proofps_dd::DeathMatchMode::isRoundBased ( ) const
overridevirtual

Implements proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamRoundGameMode.

Definition at line 710 of file GameMode.cpp.

◆ isTeamBasedGame()

bool proofps_dd::DeathMatchMode::isTeamBasedGame ( ) const
overridevirtual

Derived class shall return false if it is non-team-based game, otherwise true.

Implements proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamDeathMatchMode.

Definition at line 705 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,
pge_network::PgeINetwork & network )
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.

Reimplemented in proofps_dd::TeamRoundGameMode.

Definition at line 688 of file GameMode.cpp.

◆ serverCheckAndUpdateWinningConditions()

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

Extending parent class implementation by checking player frags against frag limit, if any is set.

Reimplemented from proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamDeathMatchMode, and proofps_dd::TeamRoundGameMode.

Definition at line 538 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 with the 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. In general it is not recommended to change this value on-the-fly during a game because it might put the game into won state if there is a spectating player having equal or more frags than the new frag limit!

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

Definition at line 569 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 SHALL automatically evaluate winning condition using serverCheckAndUpdateWinningConditions() after updating the player. 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().

Note that GameMode does not ensure that a spectating player cannot win a game. The game shall ensure that the player does not gain any frags while in spectator mode! Therefore, if the added player already has enough frags to flip game won state, the game will go into won state, regardless of the player's spectating state!

Fails if player with same cannot be found.

Returns
True if updated the existing player, false otherwise.

Implements proofps_dd::GameMode.

Reimplemented in proofps_dd::TeamDeathMatchMode.

Definition at line 626 of file GameMode.cpp.

Member Data Documentation

◆ m_nFragLimit

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

Definition at line 539 of file GameMode.h.


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