From 96b12298b5aacfdd8564eb3eeff7fef453b9c8a0 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 10 Dec 2017 00:00:55 +0100 Subject: [PATCH] remove ability to fly at will --- src/creature/Situation.hpp | 2 +- src/creature/creature.cpp | 8 ++++++++ src/creature/goal.cpp | 2 +- src/ui/ui.cpp | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/creature/Situation.hpp b/src/creature/Situation.hpp index 8df8a7a..a442d44 100644 --- a/src/creature/Situation.hpp +++ b/src/creature/Situation.hpp @@ -53,6 +53,7 @@ public: bool OnPlanet() const noexcept; world::Planet &GetPlanet() const noexcept { return *planet; } bool OnSurface() const noexcept; + bool OnGround() const noexcept; const glm::dvec3 &Position() const noexcept { return state.pos; } glm::dvec3 SurfaceNormal() const noexcept; world::Tile &GetTile() const noexcept; @@ -66,7 +67,6 @@ public: void Move(const glm::dvec3 &dp) noexcept; void Accelerate(const glm::dvec3 &dv) noexcept; void EnforceConstraints(State &) noexcept; - void CheckWrap() noexcept; void Heading(const glm::dvec3 &h) noexcept { state.dir = h; } const glm::dvec3 &Heading() const noexcept { return state.dir; } diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 72d0b3f..b609fe8 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -927,6 +927,10 @@ bool Situation::OnSurface() const noexcept { return type == PLANET_SURFACE; } +bool Situation::OnGround() const noexcept { + return OnSurface() && glm::length2(state.pos) < (planet->Radius() + 0.05) * (planet->Radius() + 0.05); +} + glm::dvec3 Situation::SurfaceNormal() const noexcept { return planet->NormalAt(state.pos); } @@ -1059,6 +1063,10 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { result += TargetVelocity(s, diff * std::min(dist * force, speed) / dist, force); } } + // remove vertical component, if any + const glm::dvec3 normal(c.GetSituation().GetPlanet().NormalAt(s.pos)); + result += normal * glm::dot(normal, result); + // clamp to max if (glm::length2(result) > max_force * max_force) { result = glm::normalize(result) * max_force; } diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index 65de6c0..abac467 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -340,7 +340,7 @@ void IngestGoal::Action() { } bool IngestGoal::OnSuitableTile() { - if (!GetSituation().OnSurface()) { + if (!GetSituation().OnGround()) { return false; } const world::TileType &t = GetSituation().GetTileType(); diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index c3397fe..9d73b92 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -231,7 +231,11 @@ void CreaturePanel::Draw(graphics::Viewport &viewport) noexcept { } pos->Text(VectorString(c->GetSituation().Position(), 2)); - tile->Text(c->GetSituation().GetTileType().label); + tile->Text(c->GetSituation().GetTileType().label + ( + c->GetSituation().OnGround() + ? (c->GetSituation().Moving() ? " (moving)" : " (standing)") + : (c->GetSituation().Moving() ? " (flying)" : " (hovering)") + )); head->Text(VectorString(c->GetSituation().Heading(), 2)); const creature::Composition &comp = c->GetComposition(); -- 2.39.2