20 [
this](
const auto& event) {
21 using T = std::decay_t<
decltype(event)>;
22 if constexpr (std::is_same_v<T, MapSize>)
24 else if constexpr (std::is_same_v<T, TileContent>)
26 else if constexpr (std::is_same_v<T, TeamName>)
28 else if constexpr (std::is_same_v<T, PlayerNew>)
30 else if constexpr (std::is_same_v<T, PlayerPosition>)
32 else if constexpr (std::is_same_v<T, PlayerLevel>)
34 else if constexpr (std::is_same_v<T, PlayerInventory>)
36 else if constexpr (std::is_same_v<T, PlayerExpulsion>)
38 else if constexpr (std::is_same_v<T, PlayerBroadcast>)
40 else if constexpr (std::is_same_v<T, IncantationStart>)
42 else if constexpr (std::is_same_v<T, IncantationEnd>)
44 else if constexpr (std::is_same_v<T, PlayerFork>)
46 else if constexpr (std::is_same_v<T, PlayerResourceDrop>)
48 else if constexpr (std::is_same_v<T, PlayerResourceTake>)
50 else if constexpr (std::is_same_v<T, PlayerDeath>)
52 else if constexpr (std::is_same_v<T, EggNew>)
54 else if constexpr (std::is_same_v<T, EggHatch>)
56 else if constexpr (std::is_same_v<T, EggDeath>)
58 else if constexpr (std::is_same_v<T, TimeUnit>)
60 else if constexpr (std::is_same_v<T, TimeUnitChange>)
62 else if constexpr (std::is_same_v<T, GameEnd>)
64 else if constexpr (std::is_same_v<T, ServerMessage>) {
66 std::cout <<
"[SERVER MESSAGE] " <<
event.message << std::endl;
67 }
else if constexpr (std::is_same_v<T, ServerUptime>)
69 else if constexpr (std::is_same_v<T, ServerSpawnedEgg>)
71 else if constexpr (std::is_same_v<T, WinDuration>)
97 .orientation = e.orientation,
100 it->second.visual.pos =
109 Player& player = it->second;
110 int fromX = player.
x;
111 int fromY = player.
y;
118 auto& behaviors = player.visual.
behaviors;
119 behaviors.erase(std::remove_if(behaviors.begin(), behaviors.end(),
121 return dynamic_cast<MoveBehavior*>(b.get()) ||
122 dynamic_cast<TurnBehavior*>(b.get());
129 std::make_unique<TurnBehavior>(player.visual, player.visual.
angle,
138 it->second.level = e.
level;
139 _pushBehavior(it->second.visual, std::make_unique<LevelUpBehavior>(
140 it->second.visual,
static_cast<float>(
timeUnit)));
163 std::make_unique<BroadcastBehavior>(
164 it->second.visual,
static_cast<float>(
timeUnit), mapRadius,
175 int total =
static_cast<int>(e.
playerIds.size());
176 for (
int i = 0; i < total; i++) {
181 p.incantationEnded =
false;
182 p.incantationSuccess =
false;
184 std::make_unique<IncantationBehavior>(p.visual, p, i, total, cx, cz,
tileSize,
192 if (player.x == e.
x && player.y == e.
y && player.incanting) {
193 player.incanting =
false;
194 player.incantationEnded =
true;
195 player.incantationSuccess = e.
success;
227 Player dying = std::move(it->second);
233 std::make_unique<DeathBehavior>(settled.visual,
static_cast<float>(
timeUnit)));
242 Egg egg{.
id = e.
eggId, .x = e.
x, .y = e.
y, .team = it->second.team};
247 std::make_unique<ForkBehavior>(settled.visual,
static_cast<float>(
timeUnit)));
277 std::make_unique<ForkBehavior>(settled.visual,
static_cast<float>(
timeUnit)));
288 if (b->getDuration() >= b->minDuration()) visual.
behaviors.push_back(std::move(b));
std::variant< MapSize, TileContent, TeamName, PlayerNew, PlayerPosition, PlayerLevel, PlayerInventory, PlayerExpulsion, PlayerBroadcast, IncantationStart, IncantationEnd, PlayerFork, PlayerResourceDrop, PlayerResourceTake, PlayerDeath, EggNew, EggHatch, EggDeath, TimeUnit, TimeUnitChange, GameEnd, ServerMessage, UnknownCommand, BadParameters, ServerUptime, ServerSpawnedEgg, WinDuration > Event
Represents an event received from the server. Is a variant of all possible events,...
float toAngle(Orientation orientation)
Returns the Y rotation angle (degrees) for a given orientation.
unsigned int serverUptimeSeconds
void _applyPlayerInventory(const PlayerInventory &e)
int64_t gameDurationTicks
void _applyTimeUnitChange(const TimeUnitChange &e)
void _applyIncantationStart(const IncantationStart &e)
static void _pushBehavior(VisualState &visual, std::unique_ptr< IBehavior > b)
void _applyServerUptime(const ServerUptime &e)
void _applyTileContent(const TileContent &e)
void _applyPlayerDeath(const PlayerDeath &e)
void _applyPlayerResourceDrop(const PlayerResourceDrop &e)
void _applyTeamName(const TeamName &e)
void _applyPlayerBroadcast(const PlayerBroadcast &e)
void _applyPlayerExpulsion(const PlayerExpulsion &e)
void _applyMapSize(const MapSize &e)
void _applyPlayerLevel(const PlayerLevel &e)
void _applyTimeUnit(const TimeUnit &e)
void _applyServerSpawnedEgg(const ServerSpawnedEgg &e)
void _applyEggNew(const EggNew &e)
void _applyEggDeath(const EggDeath &e)
void applyEvent(const Event &e)
Applies an event to the game state, modifying it accordingly and setting the dirty flag.
void _applyPlayerResourceTake(const PlayerResourceTake &e)
void _applyEggHatch(const EggHatch &e)
void _applyIncantationEnd(const IncantationEnd &e)
void _applyPlayerNew(const PlayerNew &e)
void _applyWinDuration(const WinDuration &e)
void _applyPlayerFork(const PlayerFork &e)
void _applyPlayerPosition(const PlayerPosition &e)
void _applyGameEnd(const GameEnd &e)
static Vector3 tileToWorld(int tileX, int tileY, int worldWidth, int worldHeight, float tileSize)
Converts tile coordinates to world coordinates (centered on tile).
Visual-only state for an entity, driven by behaviors each frame. Logical state (x,...
std::vector< std::unique_ptr< IBehavior > > behaviors
Resources & at(int x, int y)
Accesses the resources at a specific tile coordinate (x, y).
std::vector< std::string > teams
std::vector< Resources > tiles
std::unordered_map< int, Player > dyingPlayers
std::unordered_map< int, Egg > eggs
std::unordered_map< int, Player > players
std::vector< int > playerIds