stmm-games-doc  0.32.0
Public Member Functions | List of all members
stmg::StdPreferences::Player Class Reference
Inheritance diagram for stmg::StdPreferences::Player:
Inheritance graph
[legend]

Public Member Functions

 Player () noexcept
 
const std::string & getName () const noexcept override
 The player's name. More...
 
bool isAI () const noexcept override
 Whether the player is AI. More...
 
const shared_ptr< PrefTeamgetTeam () const noexcept override
 The team the player belongs to as a mate. More...
 
Variant getOptionValue (const std::string &sOptionName) const noexcept override
 Returns value of a player specific option. More...
 
int32_t getMate () const noexcept override
 The mate number within the team. More...
 
int32_t get () const noexcept override
 The player number within the game. More...
 
shared_ptr< Team > & getTeamFull () noexcept
 Get the player's team. More...
 
bool setName (const std::string &sNewName) noexcept
 Set the player's name. More...
 
std::pair< stmi::Capability *, stmi::HARDWARE_KEYgetKeyValue (int32_t nKeyActionId) const noexcept
 Get the capability and key assigned a key action. More...
 
bool setKeyValue (int32_t nKeyActionId, stmi::Capability *p0Capability, stmi::HARDWARE_KEY eKey) noexcept
 Assign a capability key to a player's key action. More...
 
bool setAI (bool bIsAI) noexcept
 Sets player to AI or human. More...
 
bool setOptionValue (const std::string &sOptionName, const Variant &oValue) noexcept
 Set the value of a player's option. More...
 
bool assignCapability (const shared_ptr< stmi::Capability > &refCapability) noexcept
 Assign capability to player. More...
 
bool unassignCapability (const shared_ptr< stmi::Capability > &refCapability) noexcept
 Unassign capability from player. More...
 
std::vector< shared_ptr< stmi::Capability > > getCapabilities () const noexcept override
 Get the capabilities assigned to the player. More...
 
template<typename TCapa >
bool getCapability (shared_ptr< TCapa > &refCapa) const noexcept
 Request a capability of a registered class assigned to this player. More...
 
shared_ptr< stmi::CapabilitygetCapability (const stmi::Capability::Class &oClass) const noexcept
 Request a capability of a registered class assigned to this player. More...
 
- Public Member Functions inherited from stmg::AppPreferences::PrefPlayer
virtual ~PrefPlayer () noexcept=default
 

Constructor & Destructor Documentation

◆ Player()

stmg::StdPreferences::Player::Player ( )
inlinenoexcept

Member Function Documentation

◆ assignCapability()

bool stmg::StdPreferences::Player::assignCapability ( const shared_ptr< stmi::Capability > &  refCapability)
noexcept

Assign capability to player.

If a capability is already assigned to another player it is first unassigned from the other player.

Parameters
refCapabilityThe capability. Cannot be null.
Returns
Whether could assign it.

◆ get()

int32_t stmg::StdPreferences::Player::get ( ) const
inlineoverridevirtualnoexcept

The player number within the game.

Returns
The player number. Is >= 0 and < AppPreferences::getTotPlayers().

Implements stmg::AppPreferences::PrefPlayer.

◆ getCapabilities()

std::vector< shared_ptr<stmi::Capability> > stmg::StdPreferences::Player::getCapabilities ( ) const
overridevirtualnoexcept

Get the capabilities assigned to the player.

Returns
The capabilities. Elements can't be null.

Implements stmg::AppPreferences::PrefPlayer.

◆ getCapability() [1/2]

template<typename TCapa >
bool stmg::StdPreferences::Player::getCapability ( shared_ptr< TCapa > &  refCapa) const
inlinenoexcept

Request a capability of a registered class assigned to this player.

If more than one capability of class TCapa is assigned to this player, one is chosen.

Parameters
refCapa[out] The registered Capability subclass or null if not assigned.
Returns
Whether refCapa was set.

◆ getCapability() [2/2]

shared_ptr<stmi::Capability> stmg::StdPreferences::Player::getCapability ( const stmi::Capability::Class oClass) const
noexcept

Request a capability of a registered class assigned to this player.

If more than one capability of class oClass is assigned to this player one is chosen.

Parameters
oClassThe registered capability class.
Returns
The assigned capability or null.

◆ getKeyValue()

std::pair<stmi::Capability*, stmi::HARDWARE_KEY> stmg::StdPreferences::Player::getKeyValue ( int32_t  nKeyActionId) const
noexcept

Get the capability and key assigned a key action.

The returned pair is {null, stmi::HK_NULL} if the key action wasn't defined or {null, eKey} if the capability was removed at runtime.

Parameters
nKeyActionIdThe key action id.
Returns
The capability and key.

◆ getMate()

int32_t stmg::StdPreferences::Player::getMate ( ) const
inlineoverridevirtualnoexcept

The mate number within the team.

Note: *this == *(getTeam()->getMate(this->getMate()))

Returns
The mate number. Is >= 0 and < getTeam()->getTotMates().

Implements stmg::AppPreferences::PrefPlayer.

◆ getName()

const std::string& stmg::StdPreferences::Player::getName ( ) const
inlineoverridevirtualnoexcept

The player's name.

The name is unique among all players.

Returns
The name. Is not empty.

Implements stmg::AppPreferences::PrefPlayer.

◆ getOptionValue()

Variant stmg::StdPreferences::Player::getOptionValue ( const std::string &  sName) const
overridevirtualnoexcept

Returns value of a player specific option.

Parameters
sNameThe option name.
Returns
The value. Null if option name not defined.

Implements stmg::AppPreferences::PrefPlayer.

◆ getTeam()

const shared_ptr<PrefTeam> stmg::StdPreferences::Player::getTeam ( ) const
inlineoverridevirtualnoexcept

The team the player belongs to as a mate.

Returns
The team. Is not null.

Implements stmg::AppPreferences::PrefPlayer.

◆ getTeamFull()

shared_ptr<Team>& stmg::StdPreferences::Player::getTeamFull ( )
inlinenoexcept

Get the player's team.

Returns
The team. Can't be null.

◆ isAI()

bool stmg::StdPreferences::Player::isAI ( ) const
inlineoverridevirtualnoexcept

Whether the player is AI.

This is a shortcut for the AI option.

See also
StdConfig::getAIOptionName
Returns
Whether AI.

Implements stmg::AppPreferences::PrefPlayer.

◆ setAI()

bool stmg::StdPreferences::Player::setAI ( bool  bIsAI)
noexcept

Sets player to AI or human.

Parameters
bIsAIWhether the player is AI.
Returns
Whether the operation succeeded.

◆ setKeyValue()

bool stmg::StdPreferences::Player::setKeyValue ( int32_t  nKeyActionId,
stmi::Capability p0Capability,
stmi::HARDWARE_KEY  eKey 
)
noexcept

Assign a capability key to a player's key action.

If the new capability key is already assigned to another key action it is swapped.

Parameters
nKeyActionIdThe key action id.
p0CapabilityThe capability. Cannot be null.
eKeyThe key. Cannot be stmi::HK_NULL.
Returns
Whether a swap was necessary.

◆ setName()

bool stmg::StdPreferences::Player::setName ( const std::string &  sNewName)
noexcept

Set the player's name.

If another existing player already has the name the operation fails and false is returned.

Parameters
sNewNameThe new name. Cannot be empty.
Returns
Whether the name could be changed.

◆ setOptionValue()

bool stmg::StdPreferences::Player::setOptionValue ( const std::string &  sOptionName,
const Variant oValue 
)
noexcept

Set the value of a player's option.

Parameters
sOptionNameThe name of the option. Must exist and not be read only.
oValueThe new value.
Returns
Whether the operation succeeded.

◆ unassignCapability()

bool stmg::StdPreferences::Player::unassignCapability ( const shared_ptr< stmi::Capability > &  refCapability)
noexcept

Unassign capability from player.

Parameters
refCapabilityThe capability. Cannot be null.
Returns
Whether could unassign it.