37 if (
const auto owner = registry.
try_get<
Owner>(killer)) {
38 player = owner->get().entity;
40 if (!registry.
alive(player) || !registry.
has<
Score>(player)) {
58 std::vector<Award>& awards) {
62 const auto player =
shooter_of(registry, kill.killer);
63 if (!value || !player) {
66 auto& score = registry.
get<
Score>(*player);
67 const std::uint32_t room = std::numeric_limits<std::uint32_t>::max() - score.
points;
68 const std::uint32_t points = value->get().points < room ? value->get().points : room;
69 score.points += points;
70 awards.push_back(
Award{.
player = *player, .victim = kill.victim, .
points = points});
Handle to an entity: 32 bits made of a 24-bit index and an 8-bit generation.
Definition entity.hpp:23
Entry point of the ECS: creates entities and stores their components.
Definition registry.hpp:34
Component & get(Entity entity)
Component of an entity.
Definition registry.hpp:124
std::optional< std::reference_wrapper< Component > > try_get(Entity entity)
Component of an entity, if it has one.
Definition registry.hpp:147
bool has(Entity entity) const
Tells whether an entity has every listed component.
Definition registry.hpp:114
bool alive(Entity entity) const noexcept
Tells whether a handle designates a living entity.
Damage on hit: turns collision contacts into lost health, kills and spent missiles.
Components shared by the client and the server.
Generational entity handle: an index into the component pools plus a generation.
Entity-Component-System used by client and server.
Definition animation.hpp:13
void credit_kills(Registry ®istry, const DamageReport &report, std::vector< Award > &awards)
Adds the value of each killed entity to the score of the player who killed it.
Definition score.hpp:57
std::optional< Entity > shooter_of(const Registry ®istry, Entity killer)
Player credited for a kill made by an entity.
Definition score.hpp:35
Registry: owns the entities and one component pool per component type.
Points given to a player for a kill.
Definition score.hpp:17
std::uint32_t points
Points added (less than the victim's value if the score was saturated).
Definition score.hpp:23
Entity victim
Entity that was killed.
Definition score.hpp:21
Entity player
Player whose Score increased.
Definition score.hpp:19
friend constexpr bool operator==(const Award &, const Award &) noexcept=default
Compares the awards.
What apply_damage() did during one tick, in the order of the contacts.
Definition damage.hpp:45
std::vector< Kill > kills
Entities whose health reached zero or less during the tick, once each.
Definition damage.hpp:49
An entity whose health reached zero, and the hit that did it.
Definition damage.hpp:32
Entity that created this one, e.g. the player who fired a missile.
Definition components.hpp:137
Points earned by the player who destroys this entity.
Definition components.hpp:149
std::uint32_t points
Points of one kill, 100 by default.
Definition components.hpp:151
Points a player has earned.
Definition components.hpp:143
std::uint32_t points
Total points; it stops at the largest value instead of wrapping.
Definition components.hpp:145