summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-10 00:22:10 +0100
committerAki <please@ignore.pl>2023-01-10 00:22:10 +0100
commit9d752200d3412eeea70327d8f544877bafc5b6d2 (patch)
tree9f5bfccae71e028213f11f9e0ac7f45cfb20945a
parent209648a39c98ccddc622703554912a21c2471531 (diff)
downloadkurator-9d752200d3412eeea70327d8f544877bafc5b6d2.zip
kurator-9d752200d3412eeea70327d8f544877bafc5b6d2.tar.gz
kurator-9d752200d3412eeea70327d8f544877bafc5b6d2.tar.bz2
Moved universe repo initialization to campaign module
-rw-r--r--campaign/include/kurator/campaign/ShipConfig.h6
-rw-r--r--campaign/src/scenarios.cpp14
-rw-r--r--kurator/src/Campaign.cpp2
-rw-r--r--sim/src/BaseBattle.cpp9
4 files changed, 19 insertions, 12 deletions
diff --git a/campaign/include/kurator/campaign/ShipConfig.h b/campaign/include/kurator/campaign/ShipConfig.h
index e10251b..c8ee449 100644
--- a/campaign/include/kurator/campaign/ShipConfig.h
+++ b/campaign/include/kurator/campaign/ShipConfig.h
@@ -3,6 +3,8 @@
#include <string>
#include <vector>
+#include <kurator/universe/ShipType.h>
+#include <kurator/universe/TurretType.h>
#include <kurator/universe/UniqueIdentifier.h>
@@ -16,8 +18,8 @@ struct ShipConfig
{
universe::UniqueIdentifier identifier;
int team;
- std::string type;
- std::vector<std::string> turrets;
+ universe::ShipType type;
+ std::vector<universe::TurretType> turrets;
};
diff --git a/campaign/src/scenarios.cpp b/campaign/src/scenarios.cpp
index 979128b..dbd1f73 100644
--- a/campaign/src/scenarios.cpp
+++ b/campaign/src/scenarios.cpp
@@ -2,6 +2,7 @@
#include <kurator/campaign/Scenario.h>
#include <kurator/campaign/ShipConfig.h>
+#include <kurator/universe.h>
namespace kurator
@@ -16,14 +17,21 @@ Scenario
example(int teams, int anvils, int warbringers, int eclipses, double distance)
{
int id = 0;
+ const auto repo = universe::load_json("resources/universe");
+ const auto anvil = repo->ship_type("Anvil");
+ const auto eclipse = repo->ship_type("Eclipse");
+ const auto warbringer = repo->ship_type("Warbringer");
+ const auto burst_laser = repo->turret_type("BurstLaser");
+ const auto charge_laser = repo->turret_type("ChargeLaser");
+ const auto gauss_cannon = repo->turret_type("GaussCannon");
Scenario scenario {"Example", distance, {}};
for (int team = 0; team < teams; ++team) {
for (int i = 0; i < anvils; ++i)
- scenario.ships.push_back(ShipConfig{{id++}, team, "Anvil", {"ChargeLaser", "GaussCannon"}});
+ scenario.ships.push_back(ShipConfig{{id++}, team, anvil, {charge_laser, gauss_cannon}});
for (int i = 0; i < warbringers; ++i)
- scenario.ships.push_back(ShipConfig{{id++}, team, "Warbringer", {"BurstLaser"}});
+ scenario.ships.push_back(ShipConfig{{id++}, team, warbringer, {burst_laser}});
for (int i = 0; i < eclipses; ++i)
- scenario.ships.push_back(ShipConfig{{id++}, team, "Eclipse", {"ChargeLaser"}});
+ scenario.ships.push_back(ShipConfig{{id++}, team, eclipse, {charge_laser}});
}
return scenario;
}
diff --git a/kurator/src/Campaign.cpp b/kurator/src/Campaign.cpp
index be02862..7349676 100644
--- a/kurator/src/Campaign.cpp
+++ b/kurator/src/Campaign.cpp
@@ -58,7 +58,7 @@ Campaign::update(const float)
ImGui::Text("Level %d, ships left:", level);
for (const auto& ship : ships) {
if (ship.team == team)
- ImGui::Text("%s", ship.type.c_str());
+ ImGui::Text("%s", ship.type.name.c_str());
}
if (ImGui::Button("Start")) {
campaign::Scenario scenario {"encounter", 12000, {}};
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index f195181..037a818 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -12,7 +12,6 @@
#include <kurator/sim/HitPoints.h>
#include <kurator/sim/TurretControl.h>
#include <kurator/stats/events.h>
-#include <kurator/universe.h>
#include <kurator/universe/UniqueIdentifier.h>
#include "Builder.h"
@@ -29,16 +28,14 @@ BaseBattle::BaseBattle(const campaign::Scenario& scenario) :
_registry {},
spawner {scenario.last_team(), scenario.radius, 0.1}
{
- const auto repo = universe::load_json("resources/universe");
Builder build {_registry, spawner};
for (const auto& ship : scenario.ships) {
- const auto entity = build(repo->ship_type(ship.type), ship.team);
+ const auto entity = build(ship.type, ship.team);
_registry.emplace<universe::UniqueIdentifier>(entity, ship.identifier);
auto& state = _registry.get<AIState>(entity);
for (const auto& turret_type : ship.turrets) {
- auto def = repo->turret_type(turret_type);
- build(def, entity);
- state.keep_at_range = std::min(state.keep_at_range, def.optimal_range);
+ 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
}