6#include <unordered_map>
50 World(
int width,
int height,
const std::vector<std::string>& teamNames,
unsigned int seed);
54 const Tile&
at(
int x,
int y)
const;
58 int addPlayer(
int connectionId,
const std::string& teamName,
int x,
int y,
86 std::optional<Egg>
popEggForTeam(
const std::string& teamName);
104 std::optional<std::string>
checkWin()
const;
109 const std::optional<std::string>&
winner()
const;
114 const std::unordered_map<int, Player>&
getPlayers()
const;
115 const std::unordered_map<int, Egg>&
getEggs()
const;
120 int _spawnEgg(
const std::string& teamName,
int x,
int y,
int parentPlayerId);
ResourceType
Enumerate the different types of resources in the game.
Observer hooks for game-state changes (Observer pattern).
Pure game state - no networking, no scheduling.
std::unordered_map< int, Egg > _eggs
std::vector< IWorldObserver * > _observers
bool takeResource(int playerId, ResourceType type)
void movePlayer(int id, int x, int y)
bool finalizeIncantation(int x, int y, const std::vector< int > &participantIds)
Finalize an incantation after the 300/f second delay. Re-checks prerequisites. On success,...
const std::unordered_map< int, Player > & getPlayers() const
std::optional< Egg > popEggForTeam(const std::string &teamName)
void turnPlayer(int id, Orientation orientation)
void spawnInitialEggs(int countPerTeam)
Spawn countPerTeam eggs for every team at random tiles (server startup).
int teamPlayerCount(const std::string &team) const
Tile & at(int x, int y)
Access a tile by position. Map is toroidal, coordinates wrap.
void addWorldObserver(IWorldObserver *observer)
std::vector< Tile > _tiles
int _spawnEgg(const std::string &teamName, int x, int y, int parentPlayerId)
EjectResult ejectPlayers(int ejectorId)
std::unordered_map< int, Player > _players
int addPlayer(int connectionId, const std::string &teamName, int x, int y, Orientation orientation)
bool consumeFood(int playerId)
Consume one unit of food from playerId (starvation tick). Fires onPlayerInventoryChanged so observers...
void playerBroadcast(int playerId, const std::string &message)
Fire onBroadcast to observers (GUI animation, logging). No state change.
std::optional< std::string > checkWin() const
std::vector< std::pair< int, int > > spawnResources()
bool isGameEnded() const
True once a team has won. Game logic stops reacting to AI commands.
const std::unordered_map< int, Egg > & getEggs() const
void removePlayer(int id)
bool setResource(int playerId, ResourceType type)
std::vector< std::string > _teamNames
std::optional< std::vector< int > > startIncantation(int playerId)
Validate and start an incantation for playerId. Returns the list of participant IDs on success,...
std::optional< std::string > _winner
Player & getPlayer(int id)
int teamEggCount(const std::string &team) const
const std::optional< std::string > & winner() const
Winning team name, set when isGameEnded() becomes true.
Result of an Eject command. dx/dy encode the push direction (used to notify ejected players).
std::vector< int > ejectedPlayerIds
Stone and player requirements for one incantation level.
Represents a player in the game Each player has an ID, position (x, y), orientation,...
Represents a tile on the game map, containing resources, player IDs, and egg IDs.