summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-13 18:58:56 +0100
committerAki <please@ignore.pl>2022-12-13 18:58:56 +0100
commit867393652a1199d4803c5707902f215f36c45350 (patch)
treeac6599385ab234f00716ae54abcb1716bcababc2
parent6e3c3628687186eb17c819af2e30082fe81fc555 (diff)
downloadkurator-867393652a1199d4803c5707902f215f36c45350.zip
kurator-867393652a1199d4803c5707902f215f36c45350.tar.gz
kurator-867393652a1199d4803c5707902f215f36c45350.tar.bz2
Added naive campaign-unique ship identifiers
-rw-r--r--campaign/include/kurator/campaign/ShipConfig.h3
-rw-r--r--campaign/include/kurator/campaign/UniqueIdentifier.h17
-rw-r--r--campaign/src/scenarios.cpp33
-rw-r--r--kurator/src/Battle.cpp18
-rw-r--r--sim/src/BaseBattle.cpp2
5 files changed, 52 insertions, 21 deletions
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 <string>
#include <vector>
+#include "UniqueIdentifier.h"
+
namespace kurator
{
@@ -12,6 +14,7 @@ namespace campaign
struct ShipConfig
{
+ UniqueIdentifier identifier;
int team;
std::string type;
std::vector<std::string> 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 <raylib.h>
#include <kurator/campaign/scenarios.h>
+#include <kurator/campaign/UniqueIdentifier.h>
#include <kurator/sim/Battle.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
@@ -31,9 +32,11 @@ Battle::Battle(std::shared_ptr<Session> _session) :
{
battle->dispatcher().sink<sim::Hit>().connect<&Battle::receive>(*this);
auto& registry = battle->registry();
- auto ships = registry.view<sim::Team, universe::ShipType>();
- for (const auto& [entity, team, type] : ships.each())
- registry.emplace<Marker>(entity, 5.0, team_color(team.id), type.name);
+ auto ships = registry.view<sim::Team, universe::ShipType, campaign::UniqueIdentifier>();
+ for (const auto& [entity, team, type, identifier] : ships.each()) {
+ std::string label = TextFormat("%s (%d)", type.name.c_str(), identifier.id);
+ registry.emplace<Marker>(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<CenteredText, sim::Transform, UIOffset>();
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 <entt/signal/dispatcher.hpp>
#include <kurator/campaign/Scenario.h>
+#include <kurator/campaign/UniqueIdentifier.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
#include <kurator/universe.h>
@@ -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<campaign::UniqueIdentifier>(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