Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
sharedgamestate.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <chrono>
6#include <vector>
7#include <boost/serialization/string.hpp>
8
9//#include "server/game/servergamestate.hpp"
14//#include "server/game/constants.hpp"
16
17// Forward declaration of PlayerRole enum to avoid circular reference
18enum class PlayerRole;
19
20enum class GamePhase {
22 LOBBY,
24 GAME,
26};
27
28enum class MatchPhase {
31};
32
43
51
56 bool ready;
57
59
62
63 DEF_SERIALIZE(Archive& ar, unsigned int version) {
64 ar& id& desired_role & ready;
65 }
66
67 /* Debug Methods */
68
73 std::string to_string(unsigned int tab_offset);
74 std::string to_string() { return this->to_string(0); }
75};
76
80struct Lobby {
84 std::string name;
85
92 std::vector<boost::optional<LobbyPlayer>> players;
93
98
102 Lobby() : Lobby(4) {}
103
104 explicit Lobby(int max_players) : Lobby("Default Lobby Name", max_players) {}
105
106 Lobby(const std::string& name, int max_players) : name(name), max_players(max_players) {
107 // Reserve max_players slots in the players vector
108 for (int i = 0; i < max_players; i++) {
109 this->players.push_back(boost::none);
110 }
111 }
112
124 const boost::optional<LobbyPlayer>& getPlayer(int playerIndex) const;
125
133 const boost::optional<LobbyPlayer>& getPlayer(EntityID id) const;
134
142 int numPlayersInLobby() const;
143
144
145 DEF_SERIALIZE(Archive& ar, unsigned int version) {
146 ar & name & players & max_players;
147 }
148
149 // TODO: Add a player role listing? I.e., which player is playing which
150 // character and which player is playing as the Dungeon Master?
151
152 /* Debug Methods */
153
158 std::string to_string(unsigned int tab_offset) const;
159 std::string to_string() const { return this->to_string(0); }
160};
161
168 std::unordered_map<EntityID, boost::optional<SharedObject>> objects;
169
170 unsigned int timestep;
171
173
175
177
179
181
182 unsigned int numPlayerDeaths;
183
185 objects(std::unordered_map<EntityID, boost::optional<SharedObject>>())
186 {
187 this->phase = GamePhase::TITLE_SCREEN;
188 this->timestep = FIRST_TIMESTEP;
189 this->lobby.max_players = MAX_PLAYERS;
190 this->matchPhase = MatchPhase::MazeExploration;
191 this->relay_finish_time = 0;
192 this->playerVictory = false;
193 this->numPlayerDeaths = 0;
194 }
195
196 SharedGameState(GamePhase start_phase, const GameConfig& config):
197 objects(std::unordered_map<EntityID, boost::optional<SharedObject>>())
198 {
199 this->phase = start_phase;
200 this->timestep = FIRST_TIMESTEP;
201 this->lobby.max_players = config.server.max_players;
202 this->lobby.name = config.server.lobby_name;
203 this->matchPhase = MatchPhase::MazeExploration;
204 this->relay_finish_time = 0;
205 this->playerVictory = false;
206 this->numPlayerDeaths = 0;
207 }
208
209 DEF_SERIALIZE(Archive& ar, const unsigned int version) {
212 }
213
219 void update(const SharedGameState& update);
220};
Representation of the Object class used by ServerGameState, containing exactly the subset of Object d...
Definition: sharedobject.hpp:302
PlayerRole
Definition: event.hpp:82
GLuint id
Definition: glad.h:1776
GLuint const GLchar * name
Definition: glad.h:1846
Definition: serialize.hpp:45
#define MAX_PLAYERS
Definition: constants.hpp:6
#define FIRST_TIMESTEP
Definition: constants.hpp:4
GamePhase
Definition: sharedgamestate.hpp:20
MatchPhase
Definition: sharedgamestate.hpp:28
Definition: config.hpp:12
int max_players
max number of players this server allows
Definition: config.hpp:51
std::string lobby_name
Name of the server's lobby.
Definition: config.hpp:47
struct GameConfig::@2 server
Config settings for the server.
Information about a player that has connected to the current lobby.
Definition: sharedgamestate.hpp:37
PlayerRole desired_role
This is the player's desired role (though they may not actually play as this role - the server must s...
Definition: sharedgamestate.hpp:50
bool ready
Whether the player is in the Ready state on the lobby screen.
Definition: sharedgamestate.hpp:56
LobbyPlayer(EntityID id, PlayerRole desired_role, bool ready)
Definition: sharedgamestate.hpp:60
LobbyPlayer()
Definition: sharedgamestate.hpp:58
EntityID id
Player's EntityID (this is the EntityID of their Player or DungeonMaster object in the game state)
Definition: sharedgamestate.hpp:42
DEF_SERIALIZE(Archive &ar, unsigned int version)
Definition: sharedgamestate.hpp:63
std::string to_string()
Definition: sharedgamestate.hpp:74
Information about the current lobby of players.
Definition: sharedgamestate.hpp:80
std::string name
name of the lobby as set by the server
Definition: sharedgamestate.hpp:84
std::string to_string() const
Definition: sharedgamestate.hpp:159
std::vector< boost::optional< LobbyPlayer > > players
A vector of length max_players that maps a player's index (technically, index - 1 as player indices a...
Definition: sharedgamestate.hpp:92
Lobby(int max_players)
Definition: sharedgamestate.hpp:104
Lobby()
Default Lobby constructor supports exactly 4 players.
Definition: sharedgamestate.hpp:102
int max_players
The maximum number of players that this game instance can support.
Definition: sharedgamestate.hpp:97
DEF_SERIALIZE(Archive &ar, unsigned int version)
Definition: sharedgamestate.hpp:145
const boost::optional< LobbyPlayer > & getPlayer(int playerIndex) const
Given a player's 1-indexed player index, this method returns a reference to the boost::optional<Lobby...
Definition: sharedgamestate.cpp:21
int numPlayersInLobby() const
Returns the number of players in the lobby Note: use this method and note players....
Definition: sharedgamestate.cpp:34
Lobby(const std::string &name, int max_players)
Definition: sharedgamestate.hpp:106
The SharedGameState is a representation of the ServerGameState instance maintained by the server and ...
Definition: sharedgamestate.hpp:167
SharedGameState(GamePhase start_phase, const GameConfig &config)
Definition: sharedgamestate.hpp:196
unsigned int numPlayerDeaths
Definition: sharedgamestate.hpp:182
SharedGameState()
Definition: sharedgamestate.hpp:184
Lobby lobby
Definition: sharedgamestate.hpp:172
void update(const SharedGameState &update)
Definition: sharedgamestate.cpp:4
MatchPhase matchPhase
Definition: sharedgamestate.hpp:176
GamePhase phase
Definition: sharedgamestate.hpp:174
bool playerVictory
Definition: sharedgamestate.hpp:180
unsigned int timestep
Definition: sharedgamestate.hpp:170
time_t relay_finish_time
Definition: sharedgamestate.hpp:178
DEF_SERIALIZE(Archive &ar, const unsigned int version)
Definition: sharedgamestate.hpp:209
std::unordered_map< EntityID, boost::optional< SharedObject > > objects
Definition: sharedgamestate.hpp:168
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9