stmm-games-doc  0.32.0
Public Types | Public Member Functions | List of all members
stmg::GameProxy Class Reference

Proxy class (of Game) exposed by Level available to events. More...

Public Types

enum  INTERRUPT_TYPE {
  INTERRUPT_ABORT = 0, INTERRUPT_ABORT_ASK = 1, INTERRUPT_RESTART = 2, INTERRUPT_RESTART_ASK = 3,
  INTERRUPT_QUIT_APP = 4, INTERRUPT_QUIT_APP_ASK = 5, INTERRUPT_PAUSE = 10
}
 
enum  VAR_VALUE_TEAM_STATUS { VAR_VALUE_TEAM_STATUS_COMPLETED = 1, VAR_VALUE_TEAM_STATUS_PLAYING = 0, VAR_VALUE_TEAM_STATUS_FAILED = -1 }
 The values the special team variable with id getTeamVarIdStatus() can take. More...
 
enum  VAR_VALUE_PLAYER_STATUS { VAR_VALUE_PLAYER_STATUS_COMPLETED = 1, VAR_VALUE_PLAYER_STATUS_PLAYING = 0, VAR_VALUE_PLAYER_STATUS_FAILED = -1, VAR_VALUE_PLAYER_STATUS_OUT = -2 }
 The values the special player variable with id getPlayerVarIdStatus() can take. More...
 

Public Member Functions

int32_t random (int32_t nFrom, int32_t nTo) noexcept
 Return a random value within a range. More...
 
RandomSourcegetRandomSource () noexcept
 Return the game's random source. More...
 
int64_t getGameId () const noexcept
 The unique game id. More...
 
NamedgetNamed () noexcept
 
const NamedgetNamed () const noexcept
 
bool isAllTeamsInOneLevel () const noexcept
 Whether teams play all in the same level or each on its own level. More...
 
double gameInterval () const noexcept
 The current game interval in milliseconds. More...
 
int32_t gameElapsed () const noexcept
 Number of game ticks since start of game. More...
 
double gameElapsedMillisec () const noexcept
 Number of milliseconds since start of game. More...
 
bool isInGameTick () const noexcept
 Tells whether within a game tick. More...
 
void changedInterval (int32_t nLevel) noexcept
 Tell game the preferred next interval of the level has changed. More...
 
void interrupt (INTERRUPT_TYPE eInterruptType) noexcept
 Tells owner to interrupt the current game. More...
 
bool hasVariableId (int32_t nId, OwnerType eOwnerType) const noexcept
 Whether a variable id is defined. More...
 
std::pair< int32_t, OwnerTypevariableIdAndOwner (const std::string &sName) const noexcept
 Variable id and owner by name. More...
 
const Variablevariable (int32_t nId) const noexcept
 Return the game variable instance for the id. More...
 
Variablevariable (int32_t nId) noexcept
 Return the game variable instance for the id. More...
 
const Variablevariable (int32_t nId, int32_t nLevel, int32_t nLevelTeam, int32_t nMate) const noexcept
 Return a game, team or player variable. More...
 
Variablevariable (int32_t nId, int32_t nLevel, int32_t nLevelTeam, int32_t nMate) noexcept
 Return a game, team or player variable. More...
 
int32_t getPlayer (int32_t nLevel, int32_t nLevelPlayer) noexcept
 Get the player number from the level player. More...
 
Layout const & getLayout () const noexcept
 The layout. More...
 
int32_t getGameVarIdGameOverTime () const noexcept
 Game over time variable id. More...
 
int32_t getGameVarIdWinnerTeam () const noexcept
 The winner team variable id. More...
 
int32_t getTeamVarIdFinishedTime () const noexcept
 The team's finished time variable id. More...
 
int32_t getTeamVarIdRank () const noexcept
 The team's rank variable id. More...
 
int32_t getTeamVarIdHighscoreRank () const noexcept
 The team's highscore rank variable id. More...
 
int32_t getTeamVarIdStatus () const noexcept
 The team's status variable id. More...
 
int32_t getPlayerVarIdFinishedTime () const noexcept
 The player's finished time variable id. More...
 
int32_t getPlayerVarIdStatus () const noexcept
 The player's status variable id. More...
 
void othersSend (int32_t nSenderLevelInGame, int32_t nMsg, int32_t nValue) noexcept
 Send a message to other levels. More...
 
shared_ptr< GameSoundcreateSound (int32_t nSoundIdx, int32_t nTeam, int32_t nMate, FPoint oXYPos, double fZPos, bool bListenerRelative, double fVolume01, bool bLooping) noexcept
 Create a game sound. More...
 
void preloadSound (int32_t nSoundIdx) noexcept
 Pre-load a sound. More...
 
bool removeSound (const shared_ptr< GameSound > &refSound) noexcept
 Remove a sound. More...
 
void handleInput (int32_t nTeam, int32_t nMate, const shared_ptr< stmi::Event > &refEvent) noexcept
 Send input directly to a player. More...
 
void createKeyActionFromXYEvent (int32_t nLevel, int32_t nLevelTeam, int32_t nMate, int32_t nKeyActionId, const shared_ptr< stmi::Event > &refXYEvent) noexcept
 Create a key action input event for a player. More...
 
int32_t getTotLevels () const noexcept
 The total number of levels participating in the game. More...
 
Levellevel (int32_t nLevel) noexcept
 The level. More...
 
Level const & level (int32_t nLevel) const noexcept
 The const level. More...
 
const shared_ptr< const Highscore > & getPreGameHighscore () const noexcept
 The highscores before the game started. More...
 
Highscore const & getInGameHighscore () const noexcept
 The game highscores. More...
 

Detailed Description

Proxy class (of Game) exposed by Level available to events.

Member Enumeration Documentation

◆ INTERRUPT_TYPE

Enumerator
INTERRUPT_ABORT 

Abort the game.

INTERRUPT_ABORT_ASK 

Ask "Are you sure" and possibly abort the game.

INTERRUPT_RESTART 

Abort and restart the current game immediately.

INTERRUPT_RESTART_ASK 

Ask "Are you sure" and possibly abort and restart the current game immediately.

INTERRUPT_QUIT_APP 

Abort and quit the application.

INTERRUPT_QUIT_APP_ASK 

Ask "Are you sure" and possibly abort and quit the application.

INTERRUPT_PAUSE 

Pause the game.

If the game is already paused does nothing.

◆ VAR_VALUE_PLAYER_STATUS

The values the special player variable with id getPlayerVarIdStatus() can take.

Enumerator
VAR_VALUE_PLAYER_STATUS_COMPLETED 
VAR_VALUE_PLAYER_STATUS_PLAYING 
VAR_VALUE_PLAYER_STATUS_FAILED 
VAR_VALUE_PLAYER_STATUS_OUT 

◆ VAR_VALUE_TEAM_STATUS

The values the special team variable with id getTeamVarIdStatus() can take.

Enumerator
VAR_VALUE_TEAM_STATUS_COMPLETED 
VAR_VALUE_TEAM_STATUS_PLAYING 
VAR_VALUE_TEAM_STATUS_FAILED 

Member Function Documentation

◆ changedInterval()

void stmg::GameProxy::changedInterval ( int32_t  nLevel)
noexcept

Tell game the preferred next interval of the level has changed.

The game interval is the time between game ticks.

Parameters
nLevelThe level the preferred game interval has changed. Must be valid.

◆ createKeyActionFromXYEvent()

void stmg::GameProxy::createKeyActionFromXYEvent ( int32_t  nLevel,
int32_t  nLevelTeam,
int32_t  nMate,
int32_t  nKeyActionId,
const shared_ptr< stmi::Event > &  refXYEvent 
)
noexcept

Create a key action input event for a player.

Note that the creation might fail if a key action with the same id and player is already happening, for example from a (keyboard) key.

Parameters
nLevelThe player's level. Must be >= 0.
nLevelTeamThe player's level team. Must be >= 0.
nMateThe player's mate number within the team. Must be >= 0.
nKeyActionIdThe key action id. Must be valid.
refXYEventThe input event. Must be of type stmi::XYEvent. Cannot be null.

◆ createSound()

shared_ptr<GameSound> stmg::GameProxy::createSound ( int32_t  nSoundIdx,
int32_t  nTeam,
int32_t  nMate,
FPoint  oXYPos,
double  fZPos,
bool  bListenerRelative,
double  fVolume01,
bool  bLooping 
)
noexcept

Create a game sound.

The team or mate select the player(s) that should hear the sound.

When nTeam is not -1, the sound can only be heard in per player sound mode or if there is only one human team and it is nTeam.

When nMate is not -1, the sound can only be heard in per player sound mode or if there is only one human player and it is (nTeam, nMate).

Parameters
nSoundIdxThe sound index according to Named::sounds(). Must be valid.
nTeamThe (preferences) team or -1 if sound directed to all players.
nMateThe mate or -1 if sound directed to all players of team (provided it is not -1).
oXYPosThe position of the sound on the board. Absolute or relative to the listener.
fZPosThe z position of the sound.
bListenerRelativeWhether oXYPos is relative to the listener.
fVolume01The volume. Must be from 0.0 (inaudible) to 1.0 (max).
bLoopingWhether the sound should continuously repeat.
Returns
The created sound or null if not supported.

◆ gameElapsed()

int32_t stmg::GameProxy::gameElapsed ( ) const
noexcept

Number of game ticks since start of game.

Returns
Game ticks since game start.

◆ gameElapsedMillisec()

double stmg::GameProxy::gameElapsedMillisec ( ) const
noexcept

Number of milliseconds since start of game.

Returns
Milliseconds since game start.

◆ gameInterval()

double stmg::GameProxy::gameInterval ( ) const
noexcept

The current game interval in milliseconds.

Returns
The current game interval.

◆ getGameId()

int64_t stmg::GameProxy::getGameId ( ) const
noexcept

The unique game id.

A new one is created each time a game is started.

Returns
The game id.

◆ getGameVarIdGameOverTime()

int32_t stmg::GameProxy::getGameVarIdGameOverTime ( ) const
noexcept

Game over time variable id.

The variable's value is either the game over time is in millisec or -1 if still playing.

Returns
Game over time variable id.

◆ getGameVarIdWinnerTeam()

int32_t stmg::GameProxy::getGameVarIdWinnerTeam ( ) const
noexcept

The winner team variable id.

The variable's value is either the winner team (numbered according to AppPreferences) or -1 if still playing.

Returns
The winner team variable id.

◆ getInGameHighscore()

Highscore const& stmg::GameProxy::getInGameHighscore ( ) const
noexcept

The game highscores.

After game over contains only the teams that played the game.

Returns
The game highscores. Is empty if game not ended.

◆ getLayout()

Layout const& stmg::GameProxy::getLayout ( ) const
noexcept

The layout.

Can be used to find named widgets.

Returns
The layout. Not null.

◆ getNamed() [1/2]

Named& stmg::GameProxy::getNamed ( )
noexcept

◆ getNamed() [2/2]

const Named& stmg::GameProxy::getNamed ( ) const
noexcept

◆ getPlayer()

int32_t stmg::GameProxy::getPlayer ( int32_t  nLevel,
int32_t  nLevelPlayer 
)
noexcept

Get the player number from the level player.

Parameters
nLevelThe level. Must be valid.
nLevelPlayerThe level player. Must be valid.
Returns
The player number.

◆ getPlayerVarIdFinishedTime()

int32_t stmg::GameProxy::getPlayerVarIdFinishedTime ( ) const
noexcept

The player's finished time variable id.

The variable's value is either the time the player finished playing in millisec or -1 if still playing.

Returns
The finished time variable id.

◆ getPlayerVarIdStatus()

int32_t stmg::GameProxy::getPlayerVarIdStatus ( ) const
noexcept

The player's status variable id.

The variable's value is in enum VAR_VALUE_PLAYER_STATUS.

Returns
The status variable id.

◆ getPreGameHighscore()

const shared_ptr<const Highscore>& stmg::GameProxy::getPreGameHighscore ( ) const
noexcept

The highscores before the game started.

Returns
The pre game start highscore or null.

◆ getRandomSource()

RandomSource& stmg::GameProxy::getRandomSource ( )
noexcept

Return the game's random source.

Returns
The random source.

◆ getTeamVarIdFinishedTime()

int32_t stmg::GameProxy::getTeamVarIdFinishedTime ( ) const
noexcept

The team's finished time variable id.

The variable's value is either the time the team finished playing in millisec or -1 if still playing.

Returns
The finished time variable id.

◆ getTeamVarIdHighscoreRank()

int32_t stmg::GameProxy::getTeamVarIdHighscoreRank ( ) const
noexcept

The team's highscore rank variable id.

The highscore rank is only set when all the teams have finished and is based on the highscres definition for the game.

Returns
The highscore rank variable id.

◆ getTeamVarIdRank()

int32_t stmg::GameProxy::getTeamVarIdRank ( ) const
noexcept

The team's rank variable id.

The variable's value is either the rank of a team (starting from 0) or -1 if still playing. The normal rank is solely determined by the order of the calls to Level::gameStatusFailed() and Level::gameStatusCompleted().

Returns
The rank variable id.

◆ getTeamVarIdStatus()

int32_t stmg::GameProxy::getTeamVarIdStatus ( ) const
noexcept

The team's status variable id.

The variable's value is in enum VAR_VALUE_TEAM_STATUS.

Returns
The status variable id.

◆ getTotLevels()

int32_t stmg::GameProxy::getTotLevels ( ) const
noexcept

The total number of levels participating in the game.

Returns
The number of levels.

◆ handleInput()

void stmg::GameProxy::handleInput ( int32_t  nTeam,
int32_t  nMate,
const shared_ptr< stmi::Event > &  refEvent 
)
noexcept

Send input directly to a player.

Can only be called within a game tick.

Parameters
nTeamThe player's team. Must be >= 0.
nMateThe player's mate number within the team. Must be >= 0.
refEventThe event. Cannot be null.

◆ hasVariableId()

bool stmg::GameProxy::hasVariableId ( int32_t  nId,
OwnerType  eOwnerType 
) const
noexcept

Whether a variable id is defined.

Parameters
nIdThe variable id.
eOwnerTypeThe owner type.
Returns
Whether defined.

◆ interrupt()

void stmg::GameProxy::interrupt ( INTERRUPT_TYPE  eInterruptType)
noexcept

Tells owner to interrupt the current game.

Parameters
eInterruptTypeThe interrupt type.

◆ isAllTeamsInOneLevel()

bool stmg::GameProxy::isAllTeamsInOneLevel ( ) const
noexcept

Whether teams play all in the same level or each on its own level.

Returns
Whether all teams play in one level.

◆ isInGameTick()

bool stmg::GameProxy::isInGameTick ( ) const
noexcept

Tells whether within a game tick.

This might be useful for events to determine whether within a game tick or a view tick callback.

Returns
Whether in game tick.

◆ level() [1/2]

Level& stmg::GameProxy::level ( int32_t  nLevel)
noexcept

The level.

Parameters
nLevelThe level number. Must be >= 0 and < getTotLevels().
Returns
The level.

◆ level() [2/2]

Level const& stmg::GameProxy::level ( int32_t  nLevel) const
noexcept

The const level.

Parameters
nLevelThe level number. Must be >= 0 and < getTotLevels().
Returns
The level.

◆ othersSend()

void stmg::GameProxy::othersSend ( int32_t  nSenderLevelInGame,
int32_t  nMsg,
int32_t  nValue 
)
noexcept

Send a message to other levels.

The message can be listened to by a OthersReceiverEvent instance.

Parameters
nSenderLevelInGameThe sender level. Must be valid.
nMsgThe message to send.
nValueThe value to send with it.

◆ preloadSound()

void stmg::GameProxy::preloadSound ( int32_t  nSoundIdx)
noexcept

Pre-load a sound.

Makes sure that subsequent calls to createSound with th e same nSoundIdx are as fast as possible.

Parameters
nSoundIdxThe sound index according to Named::sounds(). Must be valid.

◆ random()

int32_t stmg::GameProxy::random ( int32_t  nFrom,
int32_t  nTo 
)
noexcept

Return a random value within a range.

This is just a shortcut to getRandomSource().random().

Parameters
nFromThe first of the possible values.
nToThe last of the possible values.
Returns
The random value >= nFrom and <= nTo.

◆ removeSound()

bool stmg::GameProxy::removeSound ( const shared_ptr< GameSound > &  refSound)
noexcept

Remove a sound.

In order for the sound to be recycled the caller should also remove reference to it.

Parameters
refSoundThe sound. Cannot be null.
Returns
Whether the sound was still active.

◆ variable() [1/4]

const Variable& stmg::GameProxy::variable ( int32_t  nId) const
noexcept

Return the game variable instance for the id.

Parameters
nIdA valid variable id for OwnerType::GAME.
Returns
The const variable.

◆ variable() [2/4]

Variable& stmg::GameProxy::variable ( int32_t  nId)
noexcept

Return the game variable instance for the id.

Parameters
nIdA valid variable id for OwnerType::GAME.
Returns
The modifiable variable.

◆ variable() [3/4]

const Variable& stmg::GameProxy::variable ( int32_t  nId,
int32_t  nLevel,
int32_t  nLevelTeam,
int32_t  nMate 
) const
noexcept

Return a game, team or player variable.

Parameters
nIdThe variable id. Must be valid for the owner type.
nLevelThe level. Must be valid or -1 for game variable.
nLevelTeamThe level team. Must be valid or -1 for game variable.
nMateThe mate. Must be valid or -1 for game or team variable.
Returns
The const variable.

◆ variable() [4/4]

Variable& stmg::GameProxy::variable ( int32_t  nId,
int32_t  nLevel,
int32_t  nLevelTeam,
int32_t  nMate 
)
noexcept

Return a game, team or player variable.

Parameters
nIdThe variable id. Must be valid for the owner type.
nLevelThe level. Must be valid or -1 for game variable.
nLevelTeamThe level team. Must be valid or -1 for game variable.
nMateThe mate. Must be valid or -1 for game or team variable.
Returns
The modifiable variable.

◆ variableIdAndOwner()

std::pair<int32_t, OwnerType> stmg::GameProxy::variableIdAndOwner ( const std::string &  sName) const
noexcept

Variable id and owner by name.

Parameters
sNameThe name of the variable. Cannot be empty.
Returns
The id (>= 0) and owner or -1 (and undefined).