From 5d0cba2b45aa30226ba72231b35424d404a5eec1 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 15 Nov 2022 00:37:54 +0100 Subject: Implemented naive skeleton for types repository in universe --- battles/include/kurator/battles/ShipConfig.h | 8 +++--- battles/src/BaseBattle.cpp | 15 ++++++----- battles/src/scenarios.cpp | 37 ++++++++++++---------------- 3 files changed, 28 insertions(+), 32 deletions(-) (limited to 'battles') diff --git a/battles/include/kurator/battles/ShipConfig.h b/battles/include/kurator/battles/ShipConfig.h index bc01ad2..2066430 100644 --- a/battles/include/kurator/battles/ShipConfig.h +++ b/battles/include/kurator/battles/ShipConfig.h @@ -1,10 +1,8 @@ #pragma once +#include #include -#include -#include - namespace kurator { @@ -15,8 +13,8 @@ namespace battles struct ShipConfig { int team; - universe::ShipType type; - std::vector turrets; + std::string type; + std::vector turrets; }; diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp index 815c683..8a3dc37 100644 --- a/battles/src/BaseBattle.cpp +++ b/battles/src/BaseBattle.cpp @@ -1,13 +1,13 @@ #include "BaseBattle.h" -#include #include +#include #include #include #include -#include +#include namespace kurator @@ -23,17 +23,20 @@ BaseBattle::BaseBattle(const Scenario& scenario) : _registry {}, spawner {total_teams_in(scenario), 2.5, 0.1} { + const auto repo = universe::load_sample(); for (const auto& ship : scenario.ships) { const auto entity = _registry.create(); - _registry.emplace(entity, ship.type); + const auto type = repo->ship_type(ship.type); + _registry.emplace::type>(entity, type); _registry.emplace(entity, ship.team); _registry.emplace(entity, spawner.get(ship.team)); _registry.emplace(entity, 0.4); _registry.emplace(entity, Point{0.0, 0.0}); - _registry.emplace(entity, ship.type.base_health_points); - for (const auto& turret_def : ship.turrets) { + _registry.emplace(entity, type.base_health_points); + for (const auto& turret_name : ship.turrets) { const auto turret = _registry.create(); - _registry.emplace(turret, turret_def); + const auto def = repo->turret_type(turret_name); + _registry.emplace::type>(turret, def); _registry.emplace(turret, 0.0, entity); _registry.emplace(turret, Point{0.0, 0.0}, 0.0, entity); } diff --git a/battles/src/scenarios.cpp b/battles/src/scenarios.cpp index 3b35f44..7a79942 100644 --- a/battles/src/scenarios.cpp +++ b/battles/src/scenarios.cpp @@ -1,7 +1,6 @@ #include #include -#include namespace kurator @@ -15,29 +14,25 @@ namespace scenarios Scenario example() { - const universe::ShipType halo {"halo", 6.0}; - const universe::ShipType cube {"cube", 12.0}; - const universe::ShipType bell {"bell", 30.0}; - const universe::TurretType cannon {"cannon", 1.0, 1.0, 0.5}; return { "example", { - {0, halo, {cannon}}, - {0, halo, {cannon}}, - {0, cube, {cannon, cannon}}, - {0, cube, {cannon, cannon}}, - {0, cube, {cannon, cannon}}, - {0, bell, {cannon}}, - {0, bell, {cannon}}, - {0, bell, {cannon}}, - {1, halo, {cannon}}, - {1, halo, {cannon}}, - {1, bell, {cannon}}, - {1, cube, {cannon, cannon}}, - {1, cube, {cannon, cannon}}, - {1, cube, {cannon, cannon}}, - {1, bell, {cannon}}, - {1, bell, {cannon}}, + {0, "halo", {"cannon"}}, + {0, "halo", {"cannon"}}, + {0, "cube", {"cannon", "cannon"}}, + {0, "cube", {"cannon", "cannon"}}, + {0, "cube", {"cannon", "cannon"}}, + {0, "bell", {"cannon"}}, + {0, "bell", {"cannon"}}, + {0, "bell", {"cannon"}}, + {1, "halo", {"cannon"}}, + {1, "halo", {"cannon"}}, + {1, "bell", {"cannon"}}, + {1, "cube", {"cannon", "cannon"}}, + {1, "cube", {"cannon", "cannon"}}, + {1, "cube", {"cannon", "cannon"}}, + {1, "bell", {"cannon"}}, + {1, "bell", {"cannon"}}, }, }; } -- cgit v1.1