summaryrefslogtreecommitdiff
path: root/battles/src/BaseBattle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'battles/src/BaseBattle.cpp')
-rw-r--r--battles/src/BaseBattle.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/battles/src/BaseBattle.cpp b/battles/src/BaseBattle.cpp
new file mode 100644
index 0000000..a9ac45c
--- /dev/null
+++ b/battles/src/BaseBattle.cpp
@@ -0,0 +1,66 @@
+#include "BaseBattle.h"
+
+#include <cmath>
+#include <memory>
+
+#include <entt/entity/registry.hpp>
+
+#include <kurator/battles/components.h>
+#include <kurator/battles/Scenario.h>
+#include <kurator/universe/ShipType.h>
+
+
+namespace kurator
+{
+namespace battles
+{
+
+
+int total_teams_in(const Scenario& scenario);
+
+
+BaseBattle::BaseBattle(const Scenario& scenario) :
+ _registry {},
+ spawner {total_teams_in(scenario), 2.5, 0.1}
+{
+ 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, spawner.get(ship.team));
+ }
+}
+
+
+entt::registry&
+BaseBattle::registry()
+{
+ return _registry;
+}
+
+
+void
+BaseBattle::update(const float dt)
+{
+ auto view = _registry.view<Transform>();
+ for (auto&& [entity, transform] : view.each()) {
+ transform.position.x += 0.1 * dt * std::cos(transform.angle);
+ transform.position.y += 0.1 * dt * std::sin(transform.angle);
+ }
+}
+
+
+int
+total_teams_in(const Scenario& scenario)
+{
+ int last_team = 0;
+ for (const auto& ship : scenario.ships) {
+ if (ship.team > last_team)
+ last_team = ship.team;
+ }
+ return last_team + 1;
+}
+
+
+} // namespace battles
+} // namespace kurator