summaryrefslogtreecommitdiff
path: root/battles/src/Battle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'battles/src/Battle.cpp')
-rw-r--r--battles/src/Battle.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/battles/src/Battle.cpp b/battles/src/Battle.cpp
index 99ed076..a28cdc6 100644
--- a/battles/src/Battle.cpp
+++ b/battles/src/Battle.cpp
@@ -9,6 +9,8 @@
#include <kurator/battles/Scenario.h>
#include <kurator/universe/ShipType.h>
+#include "RandomSpawner.h"
+
namespace kurator
{
@@ -16,6 +18,9 @@ namespace battles
{
+int total_teams_in(const Scenario& scenario);
+
+
class BaseBattle : public Battle
{
public:
@@ -24,18 +29,19 @@ public:
void update(float dt) override;
private:
entt::registry _registry;
+ RandomSpawner spawner;
};
-BaseBattle::BaseBattle(const Scenario& scenario)
+BaseBattle::BaseBattle(const Scenario& scenario) :
+ _registry {},
+ spawner {total_teams_in(scenario), 2.5, 0.1}
{
- std::random_device dev;
- std::uniform_real_distribution<> pos{-2.5, 2.5};
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});
+ _registry.emplace<Transform>(entity, spawner.get(ship.team));
}
}
@@ -63,5 +69,17 @@ prepare(const Scenario& scenario)
}
+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