From 068d56e95ab3a96c25ec3a2d2e8fff74e527a6eb Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 17 Nov 2022 00:15:33 +0100 Subject: Moved total teams to Scenario --- battles/CMakeLists.txt | 1 + battles/include/kurator/battles/Scenario.h | 1 + battles/src/BaseBattle.cpp | 17 +---------------- battles/src/Scenario.cpp | 23 +++++++++++++++++++++++ 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 battles/src/Scenario.cpp (limited to 'battles') diff --git a/battles/CMakeLists.txt b/battles/CMakeLists.txt index 4484670..f7478e3 100644 --- a/battles/CMakeLists.txt +++ b/battles/CMakeLists.txt @@ -6,6 +6,7 @@ add_library( src/Builder.cpp src/Point.cpp src/RandomSpawner.cpp + src/Scenario.cpp src/scenarios.cpp src/TeamManager.cpp ) diff --git a/battles/include/kurator/battles/Scenario.h b/battles/include/kurator/battles/Scenario.h index b9bcc09..afbb74c 100644 --- a/battles/include/kurator/battles/Scenario.h +++ b/battles/include/kurator/battles/Scenario.h @@ -16,6 +16,7 @@ struct Scenario { std::string name; std::vector ships; + int total_teams() const; }; diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp index f12a944..e7d70c2 100644 --- a/battles/src/BaseBattle.cpp +++ b/battles/src/BaseBattle.cpp @@ -15,12 +15,9 @@ namespace battles { -int total_teams_in(const Scenario& scenario); - - BaseBattle::BaseBattle(const Scenario& scenario) : _registry {}, - spawner {total_teams_in(scenario), 2.5, 0.1} + spawner {scenario.total_teams(), 2.5, 0.1} { const auto repo = universe::load_sample(); Builder build {_registry, spawner}; @@ -130,17 +127,5 @@ BaseBattle::kill_off_dead() } -int -total_teams_in(const Scenario& scenario) -{ - int last_team = 0; - for (const auto& ship : scenario.ships) { - if (ship.team > last_team) - last_team = ship.team; - } - return last_team + 1; -} - - } // namespace battles } // namespace kurator diff --git a/battles/src/Scenario.cpp b/battles/src/Scenario.cpp new file mode 100644 index 0000000..49a9c7c --- /dev/null +++ b/battles/src/Scenario.cpp @@ -0,0 +1,23 @@ +#include + + +namespace kurator +{ +namespace battles +{ + + +int +Scenario::total_teams() const +{ + int last_team = 0; + for (const auto& ship : ships) { + if (ship.team > last_team) + last_team = ship.team; + } + return last_team + 1; +} + + +} // namespace battles +} // namespace kurator -- cgit v1.1