summaryrefslogtreecommitdiff
path: root/sim/src/BaseBattle.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-31 14:27:11 +0100
committerAki <please@ignore.pl>2022-12-31 15:03:09 +0100
commitd90ab6b90f2507970c2da52b166d26a7c9b48d66 (patch)
tree42c23c2665dde54a893d8eccbfb0fe1df67f30d3 /sim/src/BaseBattle.cpp
parent8cf68dfc5725e4a92a87390dcba2b9d7e5ef4e84 (diff)
downloadkurator-d90ab6b90f2507970c2da52b166d26a7c9b48d66.zip
kurator-d90ab6b90f2507970c2da52b166d26a7c9b48d66.tar.gz
kurator-d90ab6b90f2507970c2da52b166d26a7c9b48d66.tar.bz2
Extracted FloatingMovement component to own header and impl
Diffstat (limited to 'sim/src/BaseBattle.cpp')
-rw-r--r--sim/src/BaseBattle.cpp26
1 files changed, 2 insertions, 24 deletions
diff --git a/sim/src/BaseBattle.cpp b/sim/src/BaseBattle.cpp
index 4b65139..99c1b99 100644
--- a/sim/src/BaseBattle.cpp
+++ b/sim/src/BaseBattle.cpp
@@ -7,6 +7,7 @@
#include <kurator/campaign/UniqueIdentifier.h>
#include <kurator/sim/components.h>
#include <kurator/sim/events.h>
+#include <kurator/sim/FloatingMovement.h>
#include <kurator/stats/events.h>
#include <kurator/universe.h>
@@ -56,7 +57,7 @@ BaseBattle::update(const float dt)
time += dt;
pick_random_targets();
keep_at_range();
- floating_movement(dt);
+ FloatingMovement::update(_registry, _dispatcher, dt);
turrets(dt);
kill_off_dead();
manager.clear(_registry); // registry supports on destructions events
@@ -90,29 +91,6 @@ BaseBattle::keep_at_range()
void
-BaseBattle::floating_movement(const float dt)
-{
- auto view = _registry.view<Transform, FloatingMovement, AIState>();
- for (auto&& [entity, transform, movement, ai] : view.each()) {
- const auto offset = ai.destination - transform.position;
- const auto at_destination = offset.magnitude() > movement.destination_boundary;
- const auto acceleration =
- at_destination ?
- offset.normalized().scale(movement.acceleration * dt) :
- offset.normalized().scale(-1 * movement.deceleration * dt);
- movement.speed.x += acceleration.x;
- movement.speed.y += acceleration.y;
- if (movement.speed.magnitude() > movement.max_speed)
- movement.speed = movement.speed.normalized().scale(movement.max_speed);
- const auto speed = movement.speed.scale(dt);
- transform.position.x += speed.x;
- transform.position.y += speed.y;
- transform.angle = speed.angle();
- }
-}
-
-
-void
BaseBattle::turrets(const float dt)
{
auto view = _registry.view<TurretControl, universe::TurretType>();