4#include <aegis2d/core/clock.hpp>
5#include <aegis2d/core/hot_reload.hpp>
6#include <aegis2d/core/math.hpp>
7#include <aegis2d/ecs/collision.hpp>
8#include <aegis2d/ecs/components.hpp>
9#include <aegis2d/ecs/damage.hpp>
10#include <aegis2d/ecs/entity.hpp>
11#include <aegis2d/ecs/lives.hpp>
12#include <aegis2d/ecs/registry.hpp>
13#include <aegis2d/ecs/score.hpp>
14#include <aegis2d/ecs/spawner.hpp>
15#include <aegis2d/ecs/system.hpp>
16#include <aegis2d/ecs/waves.hpp>
89 bool hot_reload = aegis2d::core::hot_reload_by_default,
120 [[nodiscard]] std::optional<std::size_t>
slot_of(aegis2d::ecs::Entity player)
const noexcept;
131 aegis2d::ecs::Entity
spawn_enemy(std::string_view type, aegis2d::Vec2 position);
143 [[nodiscard]] const aegis2d::ecs::WaveSchedule&
waves() const noexcept;
149 bool set_input(aegis2d::ecs::Entity player, aegis2d::ecs::PlayerInput input);
161 [[nodiscard]] std::uint32_t
rewind(aegis2d::ecs::Entity player) const;
167 void tick(aegis2d::core::Duration step);
175 [[nodiscard]] std::uint64_t
ticks() const noexcept;
184 [[nodiscard]] aegis2d::ecs::Registry&
registry() noexcept;
187 [[nodiscard]] const aegis2d::ecs::Registry&
registry() const noexcept;
195 [[nodiscard]] const aegis2d::ecs::Scheduler&
systems() const noexcept;
199 [[nodiscard]] const std::vector<aegis2d::ecs::Entity>&
fired() const noexcept;
203 [[nodiscard]] const std::vector<aegis2d::ecs::Entity>&
enemy_fired() const noexcept;
207 [[nodiscard]] const std::vector<aegis2d::ecs::Entity>&
spawned() const noexcept;
215 [[nodiscard]] std::optional<std::uint64_t>
seed() const noexcept;
219 [[nodiscard]] const aegis2d::ecs::DamageReport&
damage() const noexcept;
223 [[nodiscard]] const std::vector<aegis2d::ecs::Award>&
awards() const noexcept;
227 [[nodiscard]] const std::vector<aegis2d::ecs::LifeLost>&
lives_lost() const noexcept;
231 [[nodiscard]] const std::vector<aegis2d::ecs::Entity>&
despawned() const noexcept;
235 [[nodiscard]] static aegis2d::ecs::Aabb
play_area() noexcept;
238 void register_systems();
240 aegis2d::ecs::Registry registry_;
242 aegis2d::core::HotReload hot_;
243 aegis2d::ecs::Scheduler systems_;
244 aegis2d::ecs::CollisionGrid grid_;
245 std::vector<aegis2d::ecs::Entity> shooters_;
246 std::vector<aegis2d::ecs::Entity> fired_;
247 std::vector<aegis2d::ecs::Entity> gunners_;
248 std::vector<aegis2d::ecs::Entity> enemy_fired_;
249 std::optional<std::uint64_t> seed_;
251 aegis2d::ecs::RandomSpawner spawner_;
252 std::vector<aegis2d::Vec2> spawn_points_;
253 std::vector<aegis2d::ecs::Entity> spawned_;
254 aegis2d::ecs::WaveSchedule waves_;
255 std::vector<aegis2d::ecs::WaveSpawn> due_;
256 std::vector<aegis2d::ecs::Contact> contacts_;
257 aegis2d::ecs::DamageReport damage_;
258 std::vector<aegis2d::ecs::Award> awards_;
259 std::vector<aegis2d::ecs::LifeLost> lives_lost_;
260 std::vector<aegis2d::ecs::Entity> despawned_;
261 std::array<aegis2d::ecs::Entity, tuning::max_players> slots_{};
263 std::array<std::uint32_t, tuning::max_players> rewinds_{};
264 bool started_ =
false;
The enemy types of a directory of Lua scripts, and the behaviors of their enemies.
Definition enemy_scripts.hpp:57
The positions of the enemies over the last tuning::position_history_ticks ticks.
Definition position_history.hpp:25
One R-Type game on the server: the world, its systems in order, and the players.
Definition server_game.hpp:75
std::size_t players() const
Players still in the game.
aegis2d::ecs::Entity add_player()
Adds a player in the first free slot.
bool remove_player(aegis2d::ecs::Entity player)
Removes a player who left: its ship is destroyed and its slot is free.
EnemyScripts & enemies() noexcept
Enemy types of the game and the scripts of their behaviors.
ServerGame(const ServerGame &)=delete
const std::vector< aegis2d::ecs::LifeLost > & lives_lost() const noexcept
Lives lost during the last tick.
aegis2d::ecs::Entity add_player(std::size_t slot)
Adds a player in a given slot, the player number of its session.
const std::vector< aegis2d::ecs::Entity > & enemy_fired() const noexcept
Missiles fired by the enemies during the last tick.
const aegis2d::ecs::Scheduler & systems() const noexcept
Systems of the game, in update order.
ServerGame & operator=(const ServerGame &)=delete
static aegis2d::ecs::Aabb play_area() noexcept
Play area: from the origin to the logical resolution.
const aegis2d::ecs::DamageReport & damage() const noexcept
Hits, kills and spent missiles of the last tick.
const aegis2d::ecs::WaveSchedule & waves() const noexcept
Enemy waves being played.
ServerGame(ServerGame &&)=delete
const std::vector< aegis2d::ecs::Entity > & fired() const noexcept
Missiles fired by the players during the last tick.
ServerGame(std::optional< std::uint64_t > seed=std::nullopt, const std::filesystem::path &enemies=default_enemies_directory(), bool hot_reload=aegis2d::core::hot_reload_by_default, GameRules rules={})
Creates an empty game with its systems registered.
void set_profiler(aegis2d::core::Profiler *profiler) noexcept
Times each system of the game with a profiler (ecs::Scheduler::set_profiler()).
aegis2d::ecs::Registry & registry() noexcept
World of the game, to spawn entities and to build snapshots.
bool game_over() const
Tells whether every player who joined is out.
bool set_rewind(aegis2d::ecs::Entity player, std::uint32_t ticks)
Sets how many ticks back a player's missiles meet the enemies (lag compensation): its rewind_ticks(),...
ServerGame & operator=(ServerGame &&)=delete
std::optional< std::uint64_t > seed() const noexcept
Seed of the random spawns.
void tick(aegis2d::core::Duration step)
Runs one simulation step: every system, in order.
const GameRules & rules() const noexcept
How the game plays.
const std::vector< aegis2d::ecs::Entity > & despawned() const noexcept
Missiles and enemies destroyed during the last tick because they left the screen.
bool set_input(aegis2d::ecs::Entity player, aegis2d::ecs::PlayerInput input)
Sets the actions a player holds, as received from its client.
std::uint64_t ticks() const noexcept
Number of ticks run.
std::optional< std::size_t > slot_of(aegis2d::ecs::Entity player) const noexcept
Slot of a player.
aegis2d::ecs::Entity spawn_enemy(std::string_view type, aegis2d::Vec2 position)
Creates an enemy of a type its script gives (EnemyScripts::spawn()).
std::uint32_t rewind(aegis2d::ecs::Entity player) const
How many ticks back a player's missiles meet the enemies.
const PositionHistory & history() const noexcept
Where the enemies were at each of the last 500 ms of ticks.
const std::vector< aegis2d::ecs::Award > & awards() const noexcept
Points given during the last tick.
const std::vector< aegis2d::ecs::Entity > & spawned() const noexcept
Enemies spawned during the last tick, at random or by the waves.
void play_waves(aegis2d::ecs::WaveSchedule waves)
Plays enemy waves from now on, replacing the ones played so far.
Enemy types written in Lua: their values and their behavior, run by the server.
constexpr std::uint32_t player_lives
Lives of a player at the start of a game.
Definition tuning.hpp:44
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
std::filesystem::path default_enemies_directory()
Directory of the enemy scripts the server plays.
Where the enemies were at each of the last ticks, for lag compensation.
How a game plays: the rules of its room, as the gameplay reads them.
Definition server_game.hpp:35
float spawn_interval_scale
Factor of the intervals between two random Bydos spawns: above 1, fewer enemies; below 1,...
Definition server_game.hpp:43
bool friendly_fire
Whether the players' missiles hit the other players.
Definition server_game.hpp:45
std::int32_t enemy_health_factor
Factor of the health of each enemy that appears, at random or by the waves, over the health its scrip...
Definition server_game.hpp:40
std::uint32_t lives
Lives of each player at the start, at least 1.
Definition server_game.hpp:37
Gameplay values of R-Type: play area, speeds, sizes, health, lives and scores.