From 13e4f3e3908220d484b01b9fb6dc4375ab28a16e Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 3 Dec 2022 01:01:39 +0100 Subject: Extracted Scenario and related things into own campaign module --- CMakeLists.txt | 1 + campaign/CMakeLists.txt | 14 +++++++++ campaign/include/kurator/campaign/Scenario.h | 24 ++++++++++++++ campaign/include/kurator/campaign/ShipConfig.h | 22 +++++++++++++ campaign/include/kurator/campaign/scenarios.h | 19 ++++++++++++ campaign/src/Scenario.cpp | 23 ++++++++++++++ campaign/src/scenarios.cpp | 43 ++++++++++++++++++++++++++ kurator/CMakeLists.txt | 1 + kurator/src/Battle.cpp | 4 +-- sim/CMakeLists.txt | 3 +- sim/include/kurator/sim/Battle.h | 4 +-- sim/include/kurator/sim/Scenario.h | 24 -------------- sim/include/kurator/sim/ShipConfig.h | 22 ------------- sim/include/kurator/sim/scenarios.h | 19 ------------ sim/src/BaseBattle.cpp | 4 +-- sim/src/BaseBattle.h | 4 +-- sim/src/Battle.cpp | 4 +-- sim/src/Scenario.cpp | 23 -------------- sim/src/scenarios.cpp | 43 -------------------------- 19 files changed, 158 insertions(+), 143 deletions(-) create mode 100644 campaign/CMakeLists.txt create mode 100644 campaign/include/kurator/campaign/Scenario.h create mode 100644 campaign/include/kurator/campaign/ShipConfig.h create mode 100644 campaign/include/kurator/campaign/scenarios.h create mode 100644 campaign/src/Scenario.cpp create mode 100644 campaign/src/scenarios.cpp delete mode 100644 sim/include/kurator/sim/Scenario.h delete mode 100644 sim/include/kurator/sim/ShipConfig.h delete mode 100644 sim/include/kurator/sim/scenarios.h delete mode 100644 sim/src/Scenario.cpp delete mode 100644 sim/src/scenarios.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b0e4aa..80264a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_CXX_EXTENSIONS No) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") find_package(EnTT 3 REQUIRED) find_package(raylib 4 REQUIRED) +add_subdirectory(campaign) add_subdirectory(kurator) add_subdirectory(sim) add_subdirectory(universe) diff --git a/campaign/CMakeLists.txt b/campaign/CMakeLists.txt new file mode 100644 index 0000000..ca2663a --- /dev/null +++ b/campaign/CMakeLists.txt @@ -0,0 +1,14 @@ +project(campaign) +add_library( + ${PROJECT_NAME} + src/Scenario.cpp + src/scenarios.cpp +) +target_include_directories( + ${PROJECT_NAME} + PUBLIC include +) +target_link_libraries( + ${PROJECT_NAME} + PUBLIC universe +) diff --git a/campaign/include/kurator/campaign/Scenario.h b/campaign/include/kurator/campaign/Scenario.h new file mode 100644 index 0000000..23647fc --- /dev/null +++ b/campaign/include/kurator/campaign/Scenario.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +#include "ShipConfig.h" + + +namespace kurator +{ +namespace campaign +{ + + +struct Scenario +{ + std::string name; + std::vector ships; + int total_teams() const; +}; + + +} // namespace campaign +} // namespace kurator diff --git a/campaign/include/kurator/campaign/ShipConfig.h b/campaign/include/kurator/campaign/ShipConfig.h new file mode 100644 index 0000000..cb5ca48 --- /dev/null +++ b/campaign/include/kurator/campaign/ShipConfig.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + + +namespace kurator +{ +namespace campaign +{ + + +struct ShipConfig +{ + int team; + std::string type; + std::vector turrets; +}; + + +} // namespace campaign +} // namespace kurator diff --git a/campaign/include/kurator/campaign/scenarios.h b/campaign/include/kurator/campaign/scenarios.h new file mode 100644 index 0000000..cdc1e19 --- /dev/null +++ b/campaign/include/kurator/campaign/scenarios.h @@ -0,0 +1,19 @@ +#pragma once + +#include "Scenario.h" + + +namespace kurator +{ +namespace campaign +{ +namespace scenarios +{ + + +Scenario example(); + + +} // namespace scenarios +} // namespace campaign +} // namespace kurator diff --git a/campaign/src/Scenario.cpp b/campaign/src/Scenario.cpp new file mode 100644 index 0000000..cd5a1c6 --- /dev/null +++ b/campaign/src/Scenario.cpp @@ -0,0 +1,23 @@ +#include + + +namespace kurator +{ +namespace campaign +{ + + +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 campaign +} // namespace kurator diff --git a/campaign/src/scenarios.cpp b/campaign/src/scenarios.cpp new file mode 100644 index 0000000..06b4659 --- /dev/null +++ b/campaign/src/scenarios.cpp @@ -0,0 +1,43 @@ +#include + +#include + + +namespace kurator +{ +namespace campaign +{ +namespace scenarios +{ + + +Scenario +example() +{ + return { + "Example", + { + {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {0, "Warbringer", {"ChargeLaser"}}, + {0, "Warbringer", {"ChargeLaser"}}, + {0, "Eclipse", {"ChargeLaser"}}, + {0, "Eclipse", {"ChargeLaser"}}, + {0, "Eclipse", {"ChargeLaser"}}, + {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {1, "Warbringer", {"ChargeLaser"}}, + {1, "Warbringer", {"ChargeLaser"}}, + {1, "Eclipse", {"ChargeLaser"}}, + {1, "Eclipse", {"ChargeLaser"}}, + {1, "Eclipse", {"ChargeLaser"}}, + }, + }; +} + + +} // namespace scenarios +} // namespace campaign +} // namespace kurator diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 58a1e0c..0dc7720 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable( target_link_libraries( ${PROJECT_NAME} PRIVATE raylib + PRIVATE campaign PRIVATE sim PRIVATE universe ) diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 81f74fd..9d6d6c5 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -8,11 +8,11 @@ #include +#include #include #include #include #include -#include #include #include "components.h" @@ -26,7 +26,7 @@ namespace kurator Battle::Battle(std::shared_ptr _session) : session {std::move(_session)}, - battle {sim::prepare(sim::scenarios::example())} + battle {sim::prepare(campaign::scenarios::example())} { battle->dispatcher().sink().connect<&Battle::receive>(*this); auto& registry = battle->registry(); diff --git a/sim/CMakeLists.txt b/sim/CMakeLists.txt index fd7d75a..d193630 100644 --- a/sim/CMakeLists.txt +++ b/sim/CMakeLists.txt @@ -6,8 +6,6 @@ add_library( src/Builder.cpp src/Point.cpp src/RandomSpawner.cpp - src/Scenario.cpp - src/scenarios.cpp src/TeamManager.cpp ) target_include_directories( @@ -17,5 +15,6 @@ target_include_directories( target_link_libraries( ${PROJECT_NAME} PUBLIC EnTT::EnTT + PUBLIC campaign PUBLIC universe ) diff --git a/sim/include/kurator/sim/Battle.h b/sim/include/kurator/sim/Battle.h index e1728f4..0b20ce8 100644 --- a/sim/include/kurator/sim/Battle.h +++ b/sim/include/kurator/sim/Battle.h @@ -5,7 +5,7 @@ #include #include -#include "Scenario.h" +#include namespace kurator @@ -24,7 +24,7 @@ public: }; -auto prepare(const Scenario& scenario) -> std::unique_ptr; +auto prepare(const campaign::Scenario& scenario) -> std::unique_ptr; } // namespace sim diff --git a/sim/include/kurator/sim/Scenario.h b/sim/include/kurator/sim/Scenario.h deleted file mode 100644 index b037365..0000000 --- a/sim/include/kurator/sim/Scenario.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include - -#include "ShipConfig.h" - - -namespace kurator -{ -namespace sim -{ - - -struct Scenario -{ - std::string name; - std::vector ships; - int total_teams() const; -}; - - -} // namespace sim -} // namespace kurator diff --git a/sim/include/kurator/sim/ShipConfig.h b/sim/include/kurator/sim/ShipConfig.h deleted file mode 100644 index bb089ac..0000000 --- a/sim/include/kurator/sim/ShipConfig.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include - - -namespace kurator -{ -namespace sim -{ - - -struct ShipConfig -{ - int team; - std::string type; - std::vector turrets; -}; - - -} // namespace sim -} // namespace kurator diff --git a/sim/include/kurator/sim/scenarios.h b/sim/include/kurator/sim/scenarios.h deleted file mode 100644 index d22b62a..0000000 --- a/sim/include/kurator/sim/scenarios.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "Scenario.h" - - -namespace kurator -{ -namespace sim -{ -namespace scenarios -{ - - -Scenario example(); - - -} // namespace scenarios -} // namespace sim -} // namespace kurator diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 3b56b0a..621b6bb 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include #include #include "Builder.h" @@ -20,7 +20,7 @@ namespace sim { -BaseBattle::BaseBattle(const Scenario& scenario) : +BaseBattle::BaseBattle(const campaign::Scenario& scenario) : _registry {}, spawner {scenario.total_teams(), 12000, 0.1} { diff --git a/sim/src/BaseBattle.h b/sim/src/BaseBattle.h index 13d7457..b0980fe 100644 --- a/sim/src/BaseBattle.h +++ b/sim/src/BaseBattle.h @@ -3,8 +3,8 @@ #include #include +#include #include -#include #include "RandomSpawner.h" #include "TeamManager.h" @@ -19,7 +19,7 @@ namespace sim class BaseBattle : public Battle { public: - BaseBattle(const Scenario& scenario); + BaseBattle(const campaign::Scenario& scenario); entt::registry& registry() override; entt::dispatcher& dispatcher() override; void update(float dt) override; diff --git a/sim/src/Battle.cpp b/sim/src/Battle.cpp index f8eacb5..4bbfcb6 100644 --- a/sim/src/Battle.cpp +++ b/sim/src/Battle.cpp @@ -2,7 +2,7 @@ #include -#include +#include #include "BaseBattle.h" @@ -14,7 +14,7 @@ namespace sim std::unique_ptr -prepare(const Scenario& scenario) +prepare(const campaign::Scenario& scenario) { return std::make_unique(scenario); } diff --git a/sim/src/Scenario.cpp b/sim/src/Scenario.cpp deleted file mode 100644 index 49201c3..0000000 --- a/sim/src/Scenario.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - - -namespace kurator -{ -namespace sim -{ - - -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 sim -} // namespace kurator diff --git a/sim/src/scenarios.cpp b/sim/src/scenarios.cpp deleted file mode 100644 index 65588bf..0000000 --- a/sim/src/scenarios.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#include - - -namespace kurator -{ -namespace sim -{ -namespace scenarios -{ - - -Scenario -example() -{ - return { - "Example", - { - {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {0, "Warbringer", {"ChargeLaser"}}, - {0, "Warbringer", {"ChargeLaser"}}, - {0, "Eclipse", {"ChargeLaser"}}, - {0, "Eclipse", {"ChargeLaser"}}, - {0, "Eclipse", {"ChargeLaser"}}, - {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, - {1, "Warbringer", {"ChargeLaser"}}, - {1, "Warbringer", {"ChargeLaser"}}, - {1, "Eclipse", {"ChargeLaser"}}, - {1, "Eclipse", {"ChargeLaser"}}, - {1, "Eclipse", {"ChargeLaser"}}, - }, - }; -} - - -} // namespace scenarios -} // namespace sim -} // namespace kurator -- cgit v1.1