summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-11-10 23:22:15 +0100
committerAki <please@ignore.pl>2022-11-10 23:22:15 +0100
commit35a39b4172008546f0bb4640114a42fb3f3a6f77 (patch)
tree8e04b27ccd995dd4f51d00079ed55410fd866837
parent57cd7872a624179f3c37c20cef488ce2be6666bc (diff)
downloadkurator-35a39b4172008546f0bb4640114a42fb3f3a6f77.zip
kurator-35a39b4172008546f0bb4640114a42fb3f3a6f77.tar.gz
kurator-35a39b4172008546f0bb4640114a42fb3f3a6f77.tar.bz2
Flattened Scenario and move sample to battles module
-rw-r--r--battles/CMakeLists.txt1
-rw-r--r--battles/include/kurator/battles/Scenario.h5
-rw-r--r--battles/include/kurator/battles/ShipConfig.h1
-rw-r--r--battles/include/kurator/battles/scenarios.h19
-rw-r--r--battles/src/Battle.cpp17
-rw-r--r--battles/src/scenarios.cpp39
-rw-r--r--kurator/src/Battle.cpp19
7 files changed, 70 insertions, 31 deletions
diff --git a/battles/CMakeLists.txt b/battles/CMakeLists.txt
index c9b2c19..44a6de0 100644
--- a/battles/CMakeLists.txt
+++ b/battles/CMakeLists.txt
@@ -2,6 +2,7 @@ project(battles)
add_library(
${PROJECT_NAME}
src/Battle.cpp
+ src/scenarios.cpp
)
target_include_directories(
${PROJECT_NAME}
diff --git a/battles/include/kurator/battles/Scenario.h b/battles/include/kurator/battles/Scenario.h
index 94adf73..b9bcc09 100644
--- a/battles/include/kurator/battles/Scenario.h
+++ b/battles/include/kurator/battles/Scenario.h
@@ -1,5 +1,6 @@
#pragma once
+#include <string>
#include <vector>
#include "ShipConfig.h"
@@ -13,8 +14,8 @@ namespace battles
struct Scenario
{
- using TeamComposition = std::vector<ShipConfig>;
- std::vector<TeamComposition> teams;
+ std::string name;
+ std::vector<ShipConfig> ships;
};
diff --git a/battles/include/kurator/battles/ShipConfig.h b/battles/include/kurator/battles/ShipConfig.h
index f2315fe..bc01ad2 100644
--- a/battles/include/kurator/battles/ShipConfig.h
+++ b/battles/include/kurator/battles/ShipConfig.h
@@ -14,6 +14,7 @@ namespace battles
struct ShipConfig
{
+ int team;
universe::ShipType type;
std::vector<universe::TurretType> turrets;
};
diff --git a/battles/include/kurator/battles/scenarios.h b/battles/include/kurator/battles/scenarios.h
new file mode 100644
index 0000000..3d7e697
--- /dev/null
+++ b/battles/include/kurator/battles/scenarios.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Scenario.h"
+
+
+namespace kurator
+{
+namespace battles
+{
+namespace scenarios
+{
+
+
+Scenario example();
+
+
+} // namespace scenarios
+} // namespace battles
+} // namespace kurator
diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp
index e59f951..e410f07 100644
--- a/battles/src/Battle.cpp
+++ b/battles/src/Battle.cpp
@@ -1,10 +1,7 @@
#include <kurator/battles/Battle.h>
-#include <cmath>
#include <random>
-#include <entt/entity/entity.hpp>
-
#include <kurator/battles/components.h>
#include <kurator/battles/Scenario.h>
#include <kurator/universe/ShipType.h>
@@ -20,15 +17,11 @@ Battle::Battle(Scenario scenario)
{
std::random_device dev;
std::uniform_real_distribution<> pos{-5.0, 5.0};
- int team = 0;
- for (const auto& ships : scenario.teams) {
- for (const auto& ship : ships) {
- const auto entity = registry.create();
- registry.emplace<universe::ShipType>(entity, ship.type);
- registry.emplace<Team>(entity, team);
- registry.emplace<Transform>(entity, Point{pos(dev), pos(dev)}, Point{0.0, 0.0});
- }
- team++;
+ for (const auto& ship : scenario.ships) {
+ const auto entity = registry.create();
+ registry.emplace<universe::ShipType>(entity, ship.type);
+ registry.emplace<Team>(entity, ship.team);
+ registry.emplace<Transform>(entity, Point{pos(dev), pos(dev)}, Point{0.0, 0.0});
}
}
diff --git a/battles/src/scenarios.cpp b/battles/src/scenarios.cpp
new file mode 100644
index 0000000..ffb4f27
--- /dev/null
+++ b/battles/src/scenarios.cpp
@@ -0,0 +1,39 @@
+#include <kurator/battles/scenarios.h>
+
+#include <kurator/battles/Scenario.h>
+#include <kurator/universe/ShipType.h>
+
+
+namespace kurator
+{
+namespace battles
+{
+namespace scenarios
+{
+
+
+Scenario
+example()
+{
+ const universe::ShipType halo {"halo", 4.0};
+ const universe::ShipType cube {"cube", 10.0};
+ const universe::ShipType bell {"bell", 10.0};
+ return {
+ "example",
+ {
+ {0, halo, {}},
+ {0, halo, {}},
+ {0, cube, {}},
+ {0, bell, {}},
+ {1, bell, {}},
+ {1, cube, {}},
+ {1, cube, {}},
+ {1, bell, {}},
+ },
+ };
+}
+
+
+} // namespace scenarios
+} // namespace battles
+} // namespace kurator
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index a68df17..7d924b5 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -9,6 +9,7 @@
#include <kurator/battles/components.h>
#include <kurator/battles/Battle.h>
#include <kurator/battles/Scenario.h>
+#include <kurator/battles/scenarios.h>
#include <kurator/universe/ShipType.h>
#include "Session.h"
@@ -19,25 +20,9 @@ namespace kurator
{
-static const battles::Scenario DEFAULT {
- {
- {
- {{"cube", 10.0}, {}},
- {{"cube", 10.0}, {}},
- {{"else", 14.0}, {}},
- },
- {
- {{"cube", 10.0}, {}},
- {{"cube", 10.0}, {}},
- {{"otto", 15.0}, {}},
- },
- },
-};
-
-
Battle::Battle(std::shared_ptr<Session> _session) :
session {std::move(_session)},
- battle {DEFAULT}
+ battle {battles::scenarios::example()}
{
}