From 0e91fc6a8e14eebb5a89b260f66e5e74b42074bb Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 10 Jan 2023 00:57:41 +0100 Subject: Extracted ship loadout into own class --- campaign/include/kurator/campaign/Loadout.h | 23 +++++++++++++++++++++++ campaign/include/kurator/campaign/ShipConfig.h | 7 +++---- campaign/src/scenarios.cpp | 15 +++++++-------- kurator/src/Campaign.cpp | 2 +- sim/src/BaseBattle.cpp | 4 ++-- 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 campaign/include/kurator/campaign/Loadout.h diff --git a/campaign/include/kurator/campaign/Loadout.h b/campaign/include/kurator/campaign/Loadout.h new file mode 100644 index 0000000..e528fd9 --- /dev/null +++ b/campaign/include/kurator/campaign/Loadout.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +#include +#include + + +namespace kurator +{ +namespace campaign +{ + + +struct Loadout +{ + universe::ShipType type; + std::vector turrets; +}; + + +} // namespace campaign +} // namespace kurator diff --git a/campaign/include/kurator/campaign/ShipConfig.h b/campaign/include/kurator/campaign/ShipConfig.h index c8ee449..d596206 100644 --- a/campaign/include/kurator/campaign/ShipConfig.h +++ b/campaign/include/kurator/campaign/ShipConfig.h @@ -3,10 +3,10 @@ #include #include -#include -#include #include +#include "Loadout.h" + namespace kurator { @@ -18,8 +18,7 @@ struct ShipConfig { universe::UniqueIdentifier identifier; int team; - universe::ShipType type; - std::vector turrets; + Loadout loadout; }; diff --git a/campaign/src/scenarios.cpp b/campaign/src/scenarios.cpp index dbd1f73..f32943f 100644 --- a/campaign/src/scenarios.cpp +++ b/campaign/src/scenarios.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -18,20 +19,18 @@ example(int teams, int anvils, int warbringers, int eclipses, double distance) { int id = 0; const auto repo = universe::load_json("resources/universe"); - const auto anvil = repo->ship_type("Anvil"); - const auto eclipse = repo->ship_type("Eclipse"); - const auto warbringer = repo->ship_type("Warbringer"); - const auto burst_laser = repo->turret_type("BurstLaser"); const auto charge_laser = repo->turret_type("ChargeLaser"); - const auto gauss_cannon = repo->turret_type("GaussCannon"); + const Loadout anvil{repo->ship_type("Anvil"), {charge_laser, repo->turret_type("GaussCannon")}}; + const Loadout eclipse{repo->ship_type("Eclipse"), {charge_laser}}; + const Loadout warbringer{repo->ship_type("Warbringer"), {repo->turret_type("BurstLaser")}}; Scenario scenario {"Example", distance, {}}; for (int team = 0; team < teams; ++team) { for (int i = 0; i < anvils; ++i) - scenario.ships.push_back(ShipConfig{{id++}, team, anvil, {charge_laser, gauss_cannon}}); + scenario.ships.push_back(ShipConfig{{id++}, team, anvil}); for (int i = 0; i < warbringers; ++i) - scenario.ships.push_back(ShipConfig{{id++}, team, warbringer, {burst_laser}}); + scenario.ships.push_back(ShipConfig{{id++}, team, warbringer}); for (int i = 0; i < eclipses; ++i) - scenario.ships.push_back(ShipConfig{{id++}, team, eclipse, {charge_laser}}); + scenario.ships.push_back(ShipConfig{{id++}, team, eclipse}); } return scenario; } diff --git a/kurator/src/Campaign.cpp b/kurator/src/Campaign.cpp index 7349676..7067bba 100644 --- a/kurator/src/Campaign.cpp +++ b/kurator/src/Campaign.cpp @@ -58,7 +58,7 @@ Campaign::update(const float) ImGui::Text("Level %d, ships left:", level); for (const auto& ship : ships) { if (ship.team == team) - ImGui::Text("%s", ship.type.name.c_str()); + ImGui::Text("%s", ship.loadout.type.name.c_str()); } if (ImGui::Button("Start")) { campaign::Scenario scenario {"encounter", 12000, {}}; diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index 037a818..5173892 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -30,10 +30,10 @@ BaseBattle::BaseBattle(const campaign::Scenario& scenario) : { Builder build {_registry, spawner}; for (const auto& ship : scenario.ships) { - const auto entity = build(ship.type, ship.team); + const auto entity = build(ship.loadout.type, ship.team); _registry.emplace(entity, ship.identifier); auto& state = _registry.get(entity); - for (const auto& turret_type : ship.turrets) { + for (const auto& turret_type : ship.loadout.turrets) { build(turret_type, entity); state.keep_at_range = std::min(state.keep_at_range, turret_type.optimal_range); } -- cgit v1.1