From 867393652a1199d4803c5707902f215f36c45350 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 13 Dec 2022 18:58:56 +0100 Subject: Added naive campaign-unique ship identifiers --- campaign/include/kurator/campaign/ShipConfig.h | 3 ++ .../include/kurator/campaign/UniqueIdentifier.h | 17 +++++++++++ campaign/src/scenarios.cpp | 33 +++++++++++----------- kurator/src/Battle.cpp | 18 ++++++++---- sim/src/BaseBattle.cpp | 2 ++ 5 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 campaign/include/kurator/campaign/UniqueIdentifier.h diff --git a/campaign/include/kurator/campaign/ShipConfig.h b/campaign/include/kurator/campaign/ShipConfig.h index cb5ca48..9aec2fa 100644 --- a/campaign/include/kurator/campaign/ShipConfig.h +++ b/campaign/include/kurator/campaign/ShipConfig.h @@ -3,6 +3,8 @@ #include #include +#include "UniqueIdentifier.h" + namespace kurator { @@ -12,6 +14,7 @@ namespace campaign struct ShipConfig { + UniqueIdentifier identifier; int team; std::string type; std::vector turrets; diff --git a/campaign/include/kurator/campaign/UniqueIdentifier.h b/campaign/include/kurator/campaign/UniqueIdentifier.h new file mode 100644 index 0000000..6e3c4f5 --- /dev/null +++ b/campaign/include/kurator/campaign/UniqueIdentifier.h @@ -0,0 +1,17 @@ +#pragma once + + +namespace kurator +{ +namespace campaign +{ + + +struct UniqueIdentifier +{ + int id; +}; + + +} // namespace campaign +} // namespace kurator diff --git a/campaign/src/scenarios.cpp b/campaign/src/scenarios.cpp index 6fd0403..9f4222b 100644 --- a/campaign/src/scenarios.cpp +++ b/campaign/src/scenarios.cpp @@ -14,26 +14,27 @@ namespace scenarios Scenario example() { + int id = 0; return { "Example", 12000, { - {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"}}, + {{id++}, 0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 0, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 0, "Warbringer", {"ChargeLaser"}}, + {{id++}, 0, "Warbringer", {"ChargeLaser"}}, + {{id++}, 0, "Eclipse", {"ChargeLaser"}}, + {{id++}, 0, "Eclipse", {"ChargeLaser"}}, + {{id++}, 0, "Eclipse", {"ChargeLaser"}}, + {{id++}, 1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 1, "Anvil", {"ChargeLaser", "ChargeLaser"}}, + {{id++}, 1, "Warbringer", {"ChargeLaser"}}, + {{id++}, 1, "Warbringer", {"ChargeLaser"}}, + {{id++}, 1, "Eclipse", {"ChargeLaser"}}, + {{id++}, 1, "Eclipse", {"ChargeLaser"}}, + {{id++}, 1, "Eclipse", {"ChargeLaser"}}, }, }; } diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 9c5afc6..5470de1 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -31,9 +32,11 @@ Battle::Battle(std::shared_ptr _session) : { battle->dispatcher().sink().connect<&Battle::receive>(*this); auto& registry = battle->registry(); - auto ships = registry.view(); - for (const auto& [entity, team, type] : ships.each()) - registry.emplace(entity, 5.0, team_color(team.id), type.name); + auto ships = registry.view(); + for (const auto& [entity, team, type, identifier] : ships.each()) { + std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id); + registry.emplace(entity, 5.0, team_color(team.id), std::move(label)); + } } @@ -91,8 +94,13 @@ Battle::draw() const const int x = hwidth + transform.position.x*scale; const int y = hheight + transform.position.y*scale; DrawCircle(x, y, marker.radius, marker.color); - DrawLine(x, y, x + marker.radius*std::cos(transform.angle), y + marker.radius*std::sin(transform.angle), WHITE); - DrawText(marker.name.c_str(), x+10, y-10, 20.0f, GRAY); + DrawLine( + x, + y, + x + marker.radius*std::cos(transform.angle), + y + marker.radius*std::sin(transform.angle), + WHITE); + DrawText(marker.name.c_str(), x+10, y-5, 10.0f, GRAY); } auto pops = registry.view(); for (const auto& [entity, text, transform, offset] : pops.each()) { diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp index b85c0eb..87b2096 100644 --- a/sim/src/BaseBattle.cpp +++ b/sim/src/BaseBattle.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,7 @@ BaseBattle::BaseBattle(const campaign::Scenario& scenario) : Builder build {_registry, spawner}; for (const auto& ship : scenario.ships) { const auto entity = build(repo->ship_type(ship.type), ship.team); + _registry.emplace(entity, ship.identifier); for (const auto& turret_type : ship.turrets) build(repo->turret_type(turret_type), entity); manager.add(ship.team, entity); // registry supports on construction events -- cgit v1.1