summaryrefslogtreecommitdiff
path: root/sim/src/sim.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-02-13 22:52:18 +0100
committerAki <please@ignore.pl>2023-02-13 22:52:42 +0100
commit2a9f378c66b28cef1c5ee063cf4d7e4e2889076e (patch)
treed678fce067c527052462adf91909f23664ca0544 /sim/src/sim.cpp
parent03bb1614c25a56ef6225db09c4c59b7a5f8fa808 (diff)
downloadkurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.zip
kurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.tar.gz
kurator-2a9f378c66b28cef1c5ee063cf4d7e4e2889076e.tar.bz2
Created sim::State object to hold overall state of simulation
This is seems like it creats even more chaotic binding between the components but it is a very nice and testable intermediate step before moving everything to standalone systems and shoving state into the... well, State.
Diffstat (limited to 'sim/src/sim.cpp')
-rw-r--r--sim/src/sim.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/sim/src/sim.cpp b/sim/src/sim.cpp
new file mode 100644
index 0000000..f915d20
--- /dev/null
+++ b/sim/src/sim.cpp
@@ -0,0 +1,36 @@
+#include <kurator/sim.h>
+
+#include <kurator/campaign/Scenario.h>
+#include <kurator/sim/components.h>
+#include <kurator/sim/State.h>
+#include <kurator/universe/UniqueIdentifier.h>
+
+#include "Builder.h"
+#include "RandomSpawner.h"
+
+
+namespace kurator
+{
+namespace sim
+{
+
+
+void
+load_scenario(State& ctx, const campaign::Scenario& scenario)
+{
+ RandomSpawner spawner {scenario.last_team(), scenario.radius, 0.1};
+ Builder build {ctx.registry, spawner};
+ for (const auto& ship : scenario.ships) {
+ const auto entity = build(ship.loadout.type, ship.team);
+ ctx.registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier);
+ auto& state = ctx.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);
+ }
+ }
+}
+
+
+} // namespace sim
+} // namespace kurator