summaryrefslogtreecommitdiff
path: root/sim/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-13 00:48:43 +0100
committerAki <please@ignore.pl>2023-02-13 00:48:43 +0100
commit6f8db05c02f941ce75da34e3c50c987d03c23e54 (patch)
tree43dfefb9c45b2d48dc55695bcea16b42e491e7d3 /sim/src
parent4f2f2d329aeee7e45198cfc6e46f7648cedf1707 (diff)
downloadkurator-6f8db05c02f941ce75da34e3c50c987d03c23e54.zip
kurator-6f8db05c02f941ce75da34e3c50c987d03c23e54.tar.gz
kurator-6f8db05c02f941ce75da34e3c50c987d03c23e54.tar.bz2
Extracted scenario setup from BaseBattle constructor
Diffstat (limited to 'sim/src')
-rw-r--r--sim/src/BaseBattle.cpp18
-rw-r--r--sim/src/TeamManager.cpp11
-rw-r--r--sim/src/TeamManager.h1
3 files changed, 26 insertions, 4 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index fa91134..0c23065 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -25,20 +25,30 @@ namespace sim
{
+static void setup_scenario(entt::registry& registry, const campaign::Scenario& scenario);
+
+
BaseBattle::BaseBattle(const campaign::Scenario& scenario) :
_registry {}
{
+ setup_scenario(_registry, scenario);
+ manager.extend(_registry);
+}
+
+
+void
+setup_scenario(entt::registry& registry, const campaign::Scenario& scenario)
+{
RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1};
- Builder build {_registry, spawner};
+ Builder build {registry, spawner};
for (const auto& ship : scenario.ships) {
const auto entity = build(ship.loadout.type, ship.team);
- _registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier);
- auto& state = _registry.get<AIState>(entity);
+ registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier);
+ auto& state = registry.get<AIState>(entity);
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);
}
- manager.add(ship.team, entity); // registry supports on construction events
}
}
diff --git a/sim/src/TeamManager.cpp b/sim/src/TeamManager.cpp
index 7252acb..778cd18 100644
--- a/sim/src/TeamManager.cpp
+++ b/sim/src/TeamManager.cpp
@@ -8,7 +8,9 @@
#include <entt/entity/registry.hpp>
#include <kurator/engine/Context.h>
+#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
+#include <kurator/universe/ShipType.h>
namespace kurator
@@ -25,6 +27,15 @@ TeamManager::TeamManager() :
void
+TeamManager::extend(entt::registry& registry)
+{
+ auto ships = registry.view<universe::ShipType, sim::Team>();
+ for (const auto& [entity, type, team] : ships.each())
+ add(team.id, entity);
+}
+
+
+void
TeamManager::add(int team, entt::entity entity)
{
for (int i = teams.size(); i < team + 1; ++i)
diff --git a/sim/src/TeamManager.h b/sim/src/TeamManager.h
index 4f6c0af..7f53510 100644
--- a/sim/src/TeamManager.h
+++ b/sim/src/TeamManager.h
@@ -19,6 +19,7 @@ class TeamManager
public:
using Team = std::vector<entt::entity>;
TeamManager();
+ void extend(entt::registry& registry);
void add(int team, entt::entity entity);
entt::entity random(int exclude);
void update(engine::Context& ctx);