summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--campaign/include/kurator/campaign/scenarios.h2
-rw-r--r--campaign/src/scenarios.cpp12
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp8
-rw-r--r--kurator/src/Battle.h2
-rw-r--r--kurator/src/Log.cpp4
-rw-r--r--kurator/src/ScenarioEditor.cpp98
-rw-r--r--kurator/src/ScenarioEditor.h37
-rw-r--r--kurator/src/main.cpp4
9 files changed, 156 insertions, 12 deletions
diff --git a/campaign/include/kurator/campaign/scenarios.h b/campaign/include/kurator/campaign/scenarios.h
index cdc1e19..65b84c5 100644
--- a/campaign/include/kurator/campaign/scenarios.h
+++ b/campaign/include/kurator/campaign/scenarios.h
@@ -11,7 +11,7 @@ namespace scenarios
{
-Scenario example();
+Scenario example(int teams=2, int anvils=3, int warbringers=2, int eclipses=3, double distance=12000.0);
} // namespace scenarios
diff --git a/campaign/src/scenarios.cpp b/campaign/src/scenarios.cpp
index de57971..2a18d22 100644
--- a/campaign/src/scenarios.cpp
+++ b/campaign/src/scenarios.cpp
@@ -13,16 +13,16 @@ namespace scenarios
Scenario
-example()
+example(int teams, int anvils, int warbringers, int eclipses, double distance)
{
int id = 0;
- Scenario scenario {"Example", 12000, {}};
- for (int team = 0; team < 2; ++team) {
- for (int i = 0; i < 2; ++i)
+ 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", "ChargeLaser"}});
- for (int i = 0; i < 3; ++i)
+ for (int i = 0; i < warbringers; ++i)
scenario.ships.push_back(ShipConfig{{id++}, team, "Warbringer", {"ChargeLaser"}});
- for (int i = 0; i < 5; ++i)
+ for (int i = 0; i < eclipses; ++i)
scenario.ships.push_back(ShipConfig{{id++}, team, "Eclipse", {"ChargeLaser"}});
}
return scenario;
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index 9fe909d..65f55eb 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -6,6 +6,7 @@ add_executable(
src/ForceBalance.cpp
src/Log.cpp
src/main.cpp
+ src/ScenarioEditor.cpp
src/Session.cpp
src/Skybox.cpp
src/Title.cpp
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index 920c444..6b3ac99 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -30,8 +30,14 @@ namespace kurator
Battle::Battle(std::shared_ptr<Session> _session) :
+ Battle(_session, campaign::scenarios::example())
+{
+}
+
+
+Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario) :
session {std::move(_session)},
- battle {sim::prepare(campaign::scenarios::example())},
+ battle {sim::prepare(scenario)},
time_factor {1.0}
{
battle->dispatcher().sink<sim::End>().connect<&Battle::on_end>(*this);
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index 918ec1c..81dd4b7 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -2,6 +2,7 @@
#include <memory>
+#include <kurator/campaign/Scenario.h>
#include <kurator/sim/Battle.h>
#include <kurator/sim/events.h>
#include <kurator/stats/events.h>
@@ -20,6 +21,7 @@ class Battle : public Scene
{
public:
explicit Battle(std::shared_ptr<Session> _session);
+ Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario);
virtual ~Battle();
void update(float dt) override;
void draw() const override;
diff --git a/kurator/src/Log.cpp b/kurator/src/Log.cpp
index 84c5103..162e309 100644
--- a/kurator/src/Log.cpp
+++ b/kurator/src/Log.cpp
@@ -9,8 +9,8 @@
#include <kurator/stats/events.h>
#include "EventLog.h"
+#include "ScenarioEditor.h"
#include "Session.h"
-#include "Title.h"
namespace kurator
@@ -36,7 +36,7 @@ void
Log::update(const float)
{
if (IsKeyPressed(KEY_SPACE))
- session->set(std::make_shared<Title>(session));
+ session->set(std::make_shared<ScenarioEditor>(session));
}
diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp
new file mode 100644
index 0000000..23ff8ff
--- /dev/null
+++ b/kurator/src/ScenarioEditor.cpp
@@ -0,0 +1,98 @@
+#include "ScenarioEditor.h"
+
+#include <memory>
+#include <utility>
+
+#include <raylib.h>
+#include <imgui.h>
+
+#include <kurator/campaign/Scenario.h>
+#include <kurator/campaign/scenarios.h>
+
+#include "Battle.h"
+#include "Session.h"
+
+
+namespace kurator
+{
+
+
+ScenarioEditor::ScenarioEditor(std::shared_ptr<Session> _session) :
+ session {std::move(_session)},
+ buffer {LoadRenderTexture(GetScreenWidth(), GetScreenHeight())},
+ teams {2},
+ anvils {3},
+ warbringers {2},
+ eclipses {3},
+ distance {12000},
+ battle {std::make_shared<Battle>(session, scenario())}
+{
+}
+
+
+ScenarioEditor::~ScenarioEditor()
+{
+ UnloadRenderTexture(buffer);
+}
+
+
+void
+ScenarioEditor::update(float)
+{
+ if (IsWindowResized()) {
+ UnloadRenderTexture(buffer);
+ buffer = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
+ }
+ if (ImGui::Begin("Scenario Editor")) {
+ bool update = false;
+ ImGui::SliderInt("Teams", &teams, 2, 6);
+ update |= ImGui::IsItemEdited();
+ ImGui::SliderInt("Anvils", &anvils, 0, 20);
+ update |= ImGui::IsItemEdited();
+ ImGui::SliderInt("Warbringers", &warbringers, 0, 20);
+ update |= ImGui::IsItemEdited();
+ ImGui::SliderInt("Eclipses", &eclipses, 0, 20);
+ update |= ImGui::IsItemEdited();
+ ImGui::SliderFloat("Distance", &distance, 10000, 20000);
+ update |= ImGui::IsItemEdited();
+ if (update)
+ battle = std::make_shared<Battle>(session, scenario());
+ if (ImGui::Button("Start"))
+ session->set(std::move(battle));
+ }
+ ImGui::End();
+ if (IsKeyPressed(KEY_SPACE))
+ session->set(std::move(battle));
+}
+
+
+void
+ScenarioEditor::draw() const
+{
+ ClearBackground(BLACK);
+ if (battle) {
+ BeginTextureMode(buffer);
+ battle->draw();
+ EndTextureMode();
+ DrawTextureRec(
+ buffer.texture,
+ {
+ 0,
+ static_cast<float>(GetScreenHeight()),
+ static_cast<float>(GetScreenWidth()),
+ static_cast<float>(-GetScreenHeight())
+ },
+ {0, 0},
+ {255, 255, 255, 150});
+ }
+}
+
+
+campaign::Scenario
+ScenarioEditor::scenario() const
+{
+ return campaign::scenarios::example(teams, anvils, warbringers, eclipses, distance);
+}
+
+
+} // namespace kurator \ No newline at end of file
diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h
new file mode 100644
index 0000000..70ce3a2
--- /dev/null
+++ b/kurator/src/ScenarioEditor.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <memory>
+
+#include <raylib.h>
+
+#include <kurator/campaign/Scenario.h>
+
+#include "Scene.h"
+#include "Session.h"
+
+
+namespace kurator
+{
+
+
+class ScenarioEditor : public Scene
+{
+public:
+ explicit ScenarioEditor(std::shared_ptr<Session> _session);
+ ~ScenarioEditor();
+ void update(float dt) override;
+ void draw() const override;
+private:
+ campaign::Scenario scenario() const;
+ std::shared_ptr<Session> session;
+ RenderTexture2D buffer;
+ int teams;
+ int anvils;
+ int warbringers;
+ int eclipses;
+ float distance;
+ std::shared_ptr<Scene> battle;
+};
+
+
+} // namespace kurator
diff --git a/kurator/src/main.cpp b/kurator/src/main.cpp
index 1a4c325..5cda6d0 100644
--- a/kurator/src/main.cpp
+++ b/kurator/src/main.cpp
@@ -1,13 +1,13 @@
#include <memory>
#include "Session.h"
-#include "Title.h"
+#include "ScenarioEditor.h"
int
main(int, char*[])
{
auto session = std::make_shared<kurator::Session>();
- session->set(std::make_shared<kurator::Title>(session));
+ session->set(std::make_shared<kurator::ScenarioEditor>(session));
session->run();
}