diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | kurator/CMakeLists.txt | 1 | ||||
-rw-r--r-- | kurator/src/Battle.cpp | 21 | ||||
-rw-r--r-- | kurator/src/Battle.h | 4 | ||||
-rw-r--r-- | sim/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sim/src/BaseBattle.cpp | 12 | ||||
-rw-r--r-- | sim/src/BaseBattle.h | 1 | ||||
-rw-r--r-- | stats/CMakeLists.txt | 12 | ||||
-rw-r--r-- | stats/include/kurator/stats/events.h | 22 |
9 files changed, 70 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 80264a4..8791616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,5 @@ find_package(raylib 4 REQUIRED) add_subdirectory(campaign) add_subdirectory(kurator) add_subdirectory(sim) +add_subdirectory(stats) add_subdirectory(universe) diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 4fe1c75..2a46ef9 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -16,5 +16,6 @@ target_link_libraries( PRIVATE raylib PRIVATE campaign PRIVATE sim + PRIVATE stats PRIVATE universe ) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 5470de1..a77b57e 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -2,6 +2,7 @@ #include <algorithm> #include <cmath> +#include <iostream> #include <memory> #include <string> #include <utility> @@ -14,6 +15,7 @@ #include <kurator/sim/components.h> #include <kurator/sim/events.h> #include <kurator/sim/Point.h> +#include <kurator/stats/events.h> #include <kurator/universe/ShipType.h> #include "colors.h" @@ -30,7 +32,8 @@ Battle::Battle(std::shared_ptr<Session> _session) : session {std::move(_session)}, battle {sim::prepare(campaign::scenarios::example())} { - battle->dispatcher().sink<sim::Hit>().connect<&Battle::receive>(*this); + battle->dispatcher().sink<sim::Hit>().connect<&Battle::on_hit>(*this); + battle->dispatcher().sink<stats::ShipLeft>().connect<&Battle::on_ship_left>(*this); auto& registry = battle->registry(); auto ships = registry.view<sim::Team, universe::ShipType, campaign::UniqueIdentifier>(); for (const auto& [entity, team, type, identifier] : ships.each()) { @@ -43,6 +46,7 @@ Battle::Battle(std::shared_ptr<Session> _session) : Battle::~Battle() { battle->dispatcher().sink<sim::Hit>().disconnect(*this); + battle->dispatcher().sink<stats::ShipLeft>().disconnect(*this); } @@ -113,7 +117,7 @@ Battle::draw() const void -Battle::receive(const sim::Hit& hit) +Battle::on_hit(const sim::Hit& hit) { auto& registry = battle->registry(); if (!registry.valid(hit.victim)) @@ -133,4 +137,17 @@ Battle::receive(const sim::Hit& hit) } +void +Battle::on_ship_left(const stats::ShipLeft& event) +{ + std::cout + << event.time + << "\tShip " << (event.destroyed ? "destroyed" : "left") << ": " + << event.ship.id + << " team " + << event.team + << std::endl; +} + + } // namespace kurator diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h index b3a0d38..9080219 100644 --- a/kurator/src/Battle.h +++ b/kurator/src/Battle.h @@ -4,6 +4,7 @@ #include <kurator/sim/Battle.h> #include <kurator/sim/events.h> +#include <kurator/stats/events.h> #include "ForceBalance.h" #include "Scene.h" @@ -21,7 +22,8 @@ public: virtual ~Battle(); void update(float dt) override; void draw() const override; - void receive(const sim::Hit& hit); + void on_hit(const sim::Hit& hit); + void on_ship_left(const stats::ShipLeft& event); private: std::shared_ptr<Session> session; std::unique_ptr<sim::Battle> battle; diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt index d193630..f3d5494 100644 --- a/sim/CMakeLists.txt +++ b/sim/CMakeLists.txt @@ -16,5 +16,6 @@ target_link_libraries( ${PROJECT_NAME} PUBLIC EnTT::EnTT PUBLIC campaign + PRIVATE stats PUBLIC universe ) diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 87b2096..449cddb 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -7,6 +7,7 @@ #include <kurator/campaign/UniqueIdentifier.h> #include <kurator/sim/components.h> #include <kurator/sim/events.h> +#include <kurator/stats/events.h> #include <kurator/universe.h> #include "Builder.h" @@ -19,6 +20,7 @@ namespace sim BaseBattle::BaseBattle(const campaign::Scenario& scenario) : + time {0.0}, _registry {}, spawner {scenario.total_teams(), scenario.radius, 0.1} { @@ -51,6 +53,7 @@ BaseBattle::dispatcher() void BaseBattle::update(const float dt) { + time += dt; pick_random_targets(); keep_at_range(); floating_movement(dt); @@ -144,8 +147,13 @@ BaseBattle::kill_off_dead() { auto view = _registry.view<HitPoints>(); for (auto&& [entity, points] : view.each()) { - if (points.health <= 0.0) - _registry.destroy(entity); + if (points.health > 0.0) + continue; + if (_registry.all_of<campaign::UniqueIdentifier, Team>(entity)) { + const auto& [identifier, team] = _registry.get<campaign::UniqueIdentifier, Team>(entity); + _dispatcher.trigger(stats::ShipLeft{time, identifier, team.id, true}); + } + _registry.destroy(entity); } } diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h index b0980fe..d2f7d19 100644 --- a/sim/src/BaseBattle.h +++ b/sim/src/BaseBattle.h @@ -24,6 +24,7 @@ public: entt::dispatcher& dispatcher() override; void update(float dt) override; private: + double time; entt::registry _registry; entt::dispatcher _dispatcher; RandomSpawner spawner; diff --git a/stats/CMakeLists.txt b/stats/CMakeLists.txt new file mode 100644 index 0000000..02b68a8 --- /dev/null +++ b/stats/CMakeLists.txt @@ -0,0 +1,12 @@ +project(stats) +add_library( + ${PROJECT_NAME} INTERFACE +) +target_include_directories( + ${PROJECT_NAME} + INTERFACE include +) +target_link_libraries( + ${PROJECT_NAME} + INTERFACE campaign +) diff --git a/stats/include/kurator/stats/events.h b/stats/include/kurator/stats/events.h new file mode 100644 index 0000000..a9a9612 --- /dev/null +++ b/stats/include/kurator/stats/events.h @@ -0,0 +1,22 @@ +#pragma once + +#include <kurator/campaign/UniqueIdentifier.h> + + +namespace kurator +{ +namespace stats +{ + + +struct ShipLeft +{ + double time; + campaign::UniqueIdentifier ship; + int team; + bool destroyed; +}; + + +} // namespace stats +} // namespace kurator |