summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-01-12 00:24:37 +0100
committerAki <please@ignore.pl>2023-01-12 00:24:37 +0100
commitc632d5e6824603eb420a874095e8b30b9713e918 (patch)
tree6726c31b871baa6555ed913ce843a8ee2dccd814
parentcb63d6d56637b887e38a45c6f2cd20044a59bc7c (diff)
downloadkurator-c632d5e6824603eb420a874095e8b30b9713e918.zip
kurator-c632d5e6824603eb420a874095e8b30b9713e918.tar.gz
kurator-c632d5e6824603eb420a874095e8b30b9713e918.tar.bz2
Implemented naive scenario editor based on groups and loadouts
-rw-r--r--campaign/include/kurator/campaign/Loadout.h2
-rw-r--r--kurator/src/ScenarioEditor.cpp54
-rw-r--r--kurator/src/ScenarioEditor.h12
3 files changed, 55 insertions, 13 deletions
diff --git a/campaign/include/kurator/campaign/Loadout.h b/campaign/include/kurator/campaign/Loadout.h
index e528fd9..7a9bb9c 100644
--- a/campaign/include/kurator/campaign/Loadout.h
+++ b/campaign/include/kurator/campaign/Loadout.h
@@ -15,7 +15,7 @@ namespace campaign
struct Loadout
{
universe::ShipType type;
- std::vector<universe::TurretType> turrets;
+ std::vector<universe::TurretType> turrets = {};
};
diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp
index aef2f51..ab4832b 100644
--- a/kurator/src/ScenarioEditor.cpp
+++ b/kurator/src/ScenarioEditor.cpp
@@ -18,6 +18,7 @@ namespace kurator
{
+bool groups_editor(std::shared_ptr<universe::Repository> repo, std::vector<Group>& groups);
bool loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& loadout);
@@ -26,9 +27,8 @@ ScenarioEditor::ScenarioEditor(std::shared_ptr<Session> _session) :
repository {universe::load_json("resources/universe")},
battle {},
frame {},
- loadout {}
+ radius {12000.0f}
{
- loadout.type = repository->ship_type("Anvil"); // access to default/first?
regenerate();
}
@@ -38,9 +38,10 @@ ScenarioEditor::update(float)
{
frame.update();
if (ImGui::Begin("Scenario Editor")) {
- bool update = false;
- update |= loadout_editor(repository, loadout);
- if (update)
+ bool changed = false;
+ changed |= ImGui::SliderFloat("Distance", &radius, 8000.0f, 20000.0f);
+ changed |= groups_editor(repository, groups);
+ if (changed)
regenerate();
if (ImGui::Button("Start"))
start_battle();
@@ -74,10 +75,13 @@ void
ScenarioEditor::regenerate()
{
int id = 0;
- campaign::Scenario scenario {"Player Encounter", 12000, {}};
- for (int i = 0; i < 2; ++i) {
- for (int n = 0; n < 5; ++n)
- scenario.ships.push_back(campaign::ShipConfig{{id++}, i, loadout});
+ campaign::Scenario scenario {"Player Encounter", radius, {}};
+ for (const auto& group : groups) {
+ for (auto it = group.counts.begin(); it != group.counts.end(); ++it) {
+ const int team = it - group.counts.begin();
+ for (int n = 0; n < *it; ++n)
+ scenario.ships.push_back(campaign::ShipConfig{{id++}, team, group.loadout});
+ }
}
battle = std::make_shared<Battle>(session, std::move(scenario));
frame.reset(battle);
@@ -85,6 +89,34 @@ ScenarioEditor::regenerate()
bool
+groups_editor(std::shared_ptr<universe::Repository> repo, std::vector<Group>& groups)
+{
+ bool changed = false;
+ auto it = groups.begin();
+ while (it != groups.end()) {
+ ImGui::PushID(it - groups.begin());
+ const bool removed = ImGui::Button("-");
+ ImGui::SameLine();
+ changed |= loadout_editor(repo, it->loadout);
+ changed |= removed;
+ changed |= ImGui::SliderInt("Team 1", &it->counts[0], 0, 10); // yeah no
+ changed |= ImGui::SliderInt("Team 2", &it->counts[1], 0, 10);
+ changed |= ImGui::SliderInt("Team 3", &it->counts[2], 0, 10);
+ changed |= ImGui::SliderInt("Team 4", &it->counts[3], 0, 10);
+ changed |= ImGui::SliderInt("Team 5", &it->counts[4], 0, 10);
+ changed |= ImGui::SliderInt("Team 6", &it->counts[5], 0, 10);
+ it = removed ? groups.erase(it) : std::next(it);
+ ImGui::PopID();
+ }
+ if (ImGui::Button("Add Group")) {
+ groups.push_back(Group{{repo->ship_type("Anvil")}}); // access to default/first?
+ changed = true;
+ }
+ return changed;
+}
+
+
+bool
loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& loadout)
{
bool changed = false;
@@ -97,10 +129,10 @@ loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& lo
});
ImGui::EndCombo();
}
+ ImGui::Indent();
auto it = loadout.turrets.begin();
while (it != loadout.turrets.end()) {
ImGui::PushID(it - loadout.turrets.begin());
- ImGui::Indent();
const bool removed = ImGui::Button("-");
ImGui::SameLine();
if (ImGui::BeginCombo("Turret Type", it->name.c_str())) {
@@ -114,13 +146,13 @@ loadout_editor(std::shared_ptr<universe::Repository> repo, campaign::Loadout& lo
}
it = removed ? loadout.turrets.erase(it) : std::next(it);
changed |= removed;
- ImGui::Unindent();
ImGui::PopID();
}
if (ImGui::Button("Add Turret")) {
loadout.turrets.push_back(repo->turret_type("ChargeLaser")); // access to default or first?
changed = true;
}
+ ImGui::Unindent();
return changed;
}
diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h
index daed4b6..9222a64 100644
--- a/kurator/src/ScenarioEditor.h
+++ b/kurator/src/ScenarioEditor.h
@@ -1,6 +1,8 @@
#pragma once
+#include <array>
#include <memory>
+#include <vector>
#include <kurator/campaign/Loadout.h>
#include <kurator/universe/Repository.h>
@@ -14,6 +16,13 @@ namespace kurator
{
+struct Group
+{
+ campaign::Loadout loadout;
+ std::array<int, 6> counts = {0};
+};
+
+
class ScenarioEditor : public Scene
{
public:
@@ -27,7 +36,8 @@ private:
std::shared_ptr<universe::Repository> repository;
std::shared_ptr<Scene> battle;
SceneFrame frame;
- campaign::Loadout loadout;
+ float radius;
+ std::vector<Group> groups;
};