Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
ServerGameState Class Reference

The ServerGameState class contains all abstract game state data and logic for a single game state instance (i.e., for one match played by 4 players). More...

#include <servergamestate.hpp>

Public Member Functions

 ServerGameState ()
 Creates a ServerGameState instance. The intial GamePhase is set to Lobby. More...
 
 ServerGameState (GamePhase start_phase)
 Creats a ServerGameState instance and sets the initial game phase to the given GamePhase. More...
 
 ServerGameState (GamePhase start_phase, const GameConfig &config)
 
 ServerGameState (GameConfig config)
 This is the ONLY constructor that initializes the maze from a maze_file argument. All other constructors must call it. More...
 
 ~ServerGameState ()
 
void update (const EventList &events)
 Updates this ServerGameState from the current timestep to the next one. More...
 
void markForDeletion (EntityID id)
 tell the gamestate to delete this entity at the end of the tick More...
 
void markAsUpdated (EntityID id)
 mark an entity as updated More...
 
void updateMovement ()
 
bool hasObjectCollided (Object *object, glm::vec3 newCornerPosition)
 Detects whether a collision occurs with other objects when the given object moves to the given position. More...
 
void updateItems ()
 
void updateAttacks ()
 
void updateEnemies ()
 
void doProjectileTicks ()
 
void doTorchlightTicks ()
 
void updateTraps ()
 
void handleDeaths ()
 
void handleRespawns ()
 
void handleDM ()
 
void updateCompass ()
 
void tickStatuses ()
 
void spawnEnemies ()
 
void handleTickVelocity ()
 
void deleteEntities ()
 
void updatePlayerLightningInvulnerabilityStatus ()
 Updates player's lightning invulnerability status (sets to false once the player's lightning invulnerability duration is past) More...
 
void updateDungeonMasterParalysis ()
 Updates the DungeonMaster's paralysis status (sets to false once the DungeonMaster's paralysis duration is past) More...
 
std::vector< SharedGameStategenerateSharedGameState (bool send_all)
 Generate a SharedGameState object from this ServerGameState instance. More...
 
SoundTablesoundTable ()
 
unsigned int getTimestep () const
 Returns the current timestep of this ServerGameState instance. More...
 
GamePhase getPhase () const
 Returns the phase that this ServerGameState instance is currently in. More...
 
void setPhase (GamePhase phase)
 setter for game phase More...
 
MatchPhase getMatchPhase () const
 Returns the match phase that this ServerGameState instance is currently in. More...
 
void transitionToRelayRace ()
 Transitions this ServerGameState's match phase to MatchPhase::RelayRace and updates all necessary data. If the match phase is already MatchPhase::RelayRace, this method returns immediately. More...
 
void setPlayerVictory (bool playerVictory)
 Sets the playerVictory boolean. More...
 
void addPlayerToLobby (LobbyPlayer player)
 Adds a new LobbyPlayer to this ServerGameState's Lobby struct. This method will assign the new player's LobbyPlayer to the first free index in the Lobby.players vector. Note: this method will CAUSE THE SERVER TO CRASH if all LobbyPlayer indices are currently in use (i.e., if Lobby.max_players players have already connected to this server's lobby). More...
 
void updateLobbyPlayer (EntityID id, LobbyPlayer player)
 Updates the LobbyPlayer with the given EntityID to the given LobbyPlayer struct. More...
 
void removePlayerFromLobby (EntityID id)
 
const LobbygetLobby () const
 
TrapplaceTrapInCell (GridCell *cell, CellType type)
 
void loadMaze (const Grid &grid)
 Reads from maze file and initializes this ServerGameState's Grid instance, as well as creating all necessary environment objects. More...
 
GridgetGrid ()
 Returns a reference to the Grid in use by this ServerGameState. More...
 
std::string to_string ()
 Creates a string representation of this ServerGameState object. More...
 

Data Fields

ObjectManager objects
 ObjectManager instance that manages all objects in this game instance at the current timestep. More...
 
std::unique_ptr< Spawnerspawner
 Controls the spawns for the enemies. More...
 

Detailed Description

The ServerGameState class contains all abstract game state data and logic for a single game state instance (i.e., for one match played by 4 players).

Constructor & Destructor Documentation

◆ ServerGameState() [1/4]

ServerGameState::ServerGameState ( )

Creates a ServerGameState instance. The intial GamePhase is set to Lobby.

◆ ServerGameState() [2/4]

ServerGameState::ServerGameState ( GamePhase  start_phase)
explicit

Creats a ServerGameState instance and sets the initial game phase to the given GamePhase.

Parameters
start_phaseGamePhase that the new ServerGameState instance will start in.

◆ ServerGameState() [3/4]

ServerGameState::ServerGameState ( GamePhase  start_phase,
const GameConfig config 
)

◆ ServerGameState() [4/4]

ServerGameState::ServerGameState ( GameConfig  config)
explicit

This is the ONLY constructor that initializes the maze from a maze_file argument. All other constructors must call it.

Parameters
maze_fileName of maze file to load. (should be in maps/ directory).

◆ ~ServerGameState()

ServerGameState::~ServerGameState ( )

Member Function Documentation

◆ addPlayerToLobby()

void ServerGameState::addPlayerToLobby ( LobbyPlayer  player)

Adds a new LobbyPlayer to this ServerGameState's Lobby struct. This method will assign the new player's LobbyPlayer to the first free index in the Lobby.players vector. Note: this method will CAUSE THE SERVER TO CRASH if all LobbyPlayer indices are currently in use (i.e., if Lobby.max_players players have already connected to this server's lobby).

Reassign id to the specified name in the mapping. This is okay to call if the player is already in the mapping, as nothing will happen. If a player's name has changed, then this will update their name as well.

Parameters
playerLobbyPlayer struct of the new player to add to this ServerGameState instance's Lobby.

◆ deleteEntities()

void ServerGameState::deleteEntities ( )

◆ doProjectileTicks()

void ServerGameState::doProjectileTicks ( )

◆ doTorchlightTicks()

void ServerGameState::doTorchlightTicks ( )

◆ generateSharedGameState()

std::vector< SharedGameState > ServerGameState::generateSharedGameState ( bool  send_all)

Generate a SharedGameState object from this ServerGameState instance.

Parameters
send_allTrue if you should send a 100% update to the client, false if you should just send the updated objects

NOTE: if send_all is false and you generate an update based on the diffs, this function will clear the updated_entities unordered_set for you

Returns
vector of partial ShareGameState instances that represent different pieces of the SharedGameState instance

◆ getGrid()

Grid & ServerGameState::getGrid ( )

Returns a reference to the Grid in use by this ServerGameState.

Returns
Reference to Grid instance used by this ServerGameState instance

◆ getLobby()

const Lobby & ServerGameState::getLobby ( ) const

◆ getMatchPhase()

MatchPhase ServerGameState::getMatchPhase ( ) const

Returns the match phase that this ServerGameState instance is currently in.

Returns
The current MatchPhase of this ServerGameState instance.

◆ getPhase()

GamePhase ServerGameState::getPhase ( ) const

Returns the phase that this ServerGameState instance is currently in.

Returns
The current GamePhase of this ServerGameState instance.

◆ getTimestep()

unsigned int ServerGameState::getTimestep ( ) const

Returns the current timestep of this ServerGameState instance.

Returns
The current timestep of this ServerGameState instance.

◆ handleDeaths()

void ServerGameState::handleDeaths ( )

◆ handleDM()

void ServerGameState::handleDM ( )

◆ handleRespawns()

void ServerGameState::handleRespawns ( )

◆ handleTickVelocity()

void ServerGameState::handleTickVelocity ( )

◆ hasObjectCollided()

bool ServerGameState::hasObjectCollided ( Object object,
glm::vec3  newCornerPosition 
)

Detects whether a collision occurs with other objects when the given object moves to the given position.

Parameters
objectObject to perform collision detection for
newCornerPositionCorner position object moves to at which collision detection is performed
Note
This method moves the object to the given position - i.e., it updates the object's gridCellPositions vector and the ObjectManager's cellToObjects unordered_map.
Returns
true if the object overlaps (collides) with any other object that has a collider at the given position, and false otherwise.

◆ loadMaze()

void ServerGameState::loadMaze ( const Grid grid)

Reads from maze file and initializes this ServerGameState's Grid instance, as well as creating all necessary environment objects.

◆ markAsUpdated()

void ServerGameState::markAsUpdated ( EntityID  id)

mark an entity as updated

◆ markForDeletion()

void ServerGameState::markForDeletion ( EntityID  id)

tell the gamestate to delete this entity at the end of the tick

◆ placeTrapInCell()

Trap * ServerGameState::placeTrapInCell ( GridCell cell,
CellType  type 
)

◆ removePlayerFromLobby()

void ServerGameState::removePlayerFromLobby ( EntityID  id)

Removes a player from the lobby with the specified id.

◆ setPhase()

void ServerGameState::setPhase ( GamePhase  phase)

setter for game phase

◆ setPlayerVictory()

void ServerGameState::setPlayerVictory ( bool  playerVictory)

Sets the playerVictory boolean.

Parameters
playerVictoryboolean value to set the playerVictory value to

◆ soundTable()

SoundTable & ServerGameState::soundTable ( )

◆ spawnEnemies()

void ServerGameState::spawnEnemies ( )

◆ tickStatuses()

void ServerGameState::tickStatuses ( )

◆ to_string()

std::string ServerGameState::to_string ( )

Creates a string representation of this ServerGameState object.

Returns
A string representation of this ServerGameState object.

◆ transitionToRelayRace()

void ServerGameState::transitionToRelayRace ( )

Transitions this ServerGameState's match phase to MatchPhase::RelayRace and updates all necessary data. If the match phase is already MatchPhase::RelayRace, this method returns immediately.

◆ update()

void ServerGameState::update ( const EventList events)

Updates this ServerGameState from the current timestep to the next one.

◆ updateAttacks()

void ServerGameState::updateAttacks ( )

◆ updateCompass()

void ServerGameState::updateCompass ( )

◆ updateDungeonMasterParalysis()

void ServerGameState::updateDungeonMasterParalysis ( )

Updates the DungeonMaster's paralysis status (sets to false once the DungeonMaster's paralysis duration is past)

◆ updateEnemies()

void ServerGameState::updateEnemies ( )

◆ updateItems()

void ServerGameState::updateItems ( )

◆ updateLobbyPlayer()

void ServerGameState::updateLobbyPlayer ( EntityID  id,
LobbyPlayer  player 
)

Updates the LobbyPlayer with the given EntityID to the given LobbyPlayer struct.

Parameters
idEntityID of the LobbyPlayer to update
playerLobbyPlayer struct to copy to the current lobby player

◆ updateMovement()

void ServerGameState::updateMovement ( )

◆ updatePlayerLightningInvulnerabilityStatus()

void ServerGameState::updatePlayerLightningInvulnerabilityStatus ( )

Updates player's lightning invulnerability status (sets to false once the player's lightning invulnerability duration is past)

◆ updateTraps()

void ServerGameState::updateTraps ( )

Field Documentation

◆ objects

ObjectManager ServerGameState::objects

ObjectManager instance that manages all objects in this game instance at the current timestep.

◆ spawner

std::unique_ptr<Spawner> ServerGameState::spawner

Controls the spawns for the enemies.


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