]> git.localhorst.tv Git - blank.git/blobdiff - src/ai/ai.cpp
make gcc nag more
[blank.git] / src / ai / ai.cpp
index 820eb4d19a996aabdc1e89a188ec06710f11d0eb..95dc8f7d26e66703a50a45f9c427f990aece1370 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "../geometry/distance.hpp"
 #include "../geometry/rotation.hpp"
+#include "../graphics/glm.hpp"
 #include "../rand/GaloisLFSR.hpp"
 #include "../world/Entity.hpp"
 #include "../world/World.hpp"
@@ -13,7 +14,6 @@
 
 #include <cmath>
 #include <limits>
-#include <glm/glm.hpp>
 
 
 namespace blank {
@@ -58,7 +58,7 @@ void AIController::Update(Entity &e, float dt) {
                // orient head towards heading
                glm::vec3 heading(e.Heading());
                // only half pitch, so we don't crane our neck
-               float tgt_pitch = std::atan(heading.y / length(glm::vec2(heading.x, heading.z))) * 0.5f;
+               float tgt_pitch = std::atan(heading.y / glm::length(glm::vec2(heading.x, heading.z))) * 0.5f;
                // always look straight ahead
                // maybe look at the pursuit target if there is one
                float tgt_yaw = 0.0f;
@@ -77,11 +77,11 @@ Player *AIController::ClosestVisiblePlayer(const Entity &e) noexcept {
 
                // distance test
                const glm::vec3 diff(pe.AbsoluteDifference(e));
-               float dist = length(diff);
+               float dist = glm::length(diff);
                if (dist > distance) continue;
 
                // FOV test, 45° in each direction
-               if (dot(diff / dist, aim.dir) < sight_angle) {
+               if (glm::dot(diff / dist, aim.dir) < sight_angle) {
                        continue;
                }
 
@@ -102,8 +102,8 @@ bool AIController::LineOfSight(const Entity &from, const Entity &to) const noexc
        const glm::ivec3 &reference(from.ChunkCoords());
        Ray aim(from.Aim(reference));
        const glm::vec3 diff(to.AbsoluteDifference(from));
-       float dist = length(diff);
-       if (dist > sight_dist || dot(diff / dist, aim.dir) < sight_angle) {
+       float dist = glm::length(diff);
+       if (dist > sight_dist || glm::dot(diff / dist, aim.dir) < sight_angle) {
                return false;
        }
        WorldCollision col;
@@ -145,15 +145,15 @@ unsigned int AIController::Decide(unsigned int num_choices) noexcept {
 
 // chase
 
-void ChaseState::Enter(AIController &ctrl, Entity &e) const {
+void ChaseState::Enter(AIController &, Entity &e) const {
        e.GetSteering()
-               .SetAcceleration(1.0f)
+               .SetAcceleration(5.0f)
                .SetSpeed(4.0f)
                .Enable(Steering::PURSUE_TARGET)
        ;
 }
 
-void ChaseState::Update(AIController &ctrl, Entity &e, float dt) const {
+void ChaseState::Update(AIController &ctrl, Entity &e, float) const {
        Steering &steering = e.GetSteering();
        // check if target still alive and in sight
        if (
@@ -166,7 +166,7 @@ void ChaseState::Update(AIController &ctrl, Entity &e, float dt) const {
                return;
        }
        // halt if we're close enough, flee if we're too close
-       float dist_sq = length2(e.AbsoluteDifference(steering.GetTargetEntity()));
+       float dist_sq = glm::length2(e.AbsoluteDifference(steering.GetTargetEntity()));
        if (dist_sq < 8.0f) {
                ctrl.SetState(flee, e);
        } else if (dist_sq < 25.0f) {
@@ -176,7 +176,7 @@ void ChaseState::Update(AIController &ctrl, Entity &e, float dt) const {
        }
 }
 
-void ChaseState::Exit(AIController &ctrl, Entity &e) const {
+void ChaseState::Exit(AIController &, Entity &e) const {
        e.GetSteering().Disable(Steering::HALT | Steering::PURSUE_TARGET);
 }
 
@@ -184,19 +184,19 @@ void ChaseState::Exit(AIController &ctrl, Entity &e) const {
 
 void FleeState::Enter(AIController &ctrl, Entity &e) const {
        e.GetSteering()
-               .SetAcceleration(1.0f)
+               .SetAcceleration(5.0f)
                .SetSpeed(4.0f)
                .Enable(Steering::EVADE_TARGET)
        ;
        ctrl.CueDecision(6.0f, 3.0f);
 }
 
-void FleeState::Update(AIController &ctrl, Entity &e, float dt) const {
+void FleeState::Update(AIController &ctrl, Entity &e, float) const {
        if (!ctrl.DecisionDue()) return;
        ctrl.SetState(idle, e);
 }
 
-void FleeState::Exit(AIController &ctrl, Entity &e) const {
+void FleeState::Exit(AIController &, Entity &e) const {
        e.GetSteering().Disable(Steering::EVADE_TARGET);
 }
 
@@ -212,7 +212,7 @@ void IdleState::Enter(AIController &ctrl, Entity &e) const {
        ctrl.CueDecision(10.0f, 5.0f);
 }
 
-void IdleState::Update(AIController &ctrl, Entity &e, float dt) const {
+void IdleState::Update(AIController &ctrl, Entity &e, float) const {
        if (ctrl.MayThink()) {
                const Player *player = ctrl.ClosestVisiblePlayer(e);
                if (player) {
@@ -238,7 +238,7 @@ void IdleState::Update(AIController &ctrl, Entity &e, float dt) const {
        ctrl.CueDecision(10.0f, 5.0f);
 }
 
-void IdleState::Exit(AIController &ctrl, Entity &e) const {
+void IdleState::Exit(AIController &, Entity &e) const {
        e.GetSteering().Disable(Steering::HALT | Steering::WANDER);
 }
 
@@ -254,7 +254,7 @@ void RoamState::Enter(AIController &ctrl, Entity &e) const {
        ctrl.CueDecision(10.0f, 5.0f);
 }
 
-void RoamState::Update(AIController &ctrl, Entity &e, float dt) const {
+void RoamState::Update(AIController &ctrl, Entity &e, float) const {
        if (ctrl.MayThink()) {
                const Player *player = ctrl.ClosestVisiblePlayer(e);
                if (player) {
@@ -274,7 +274,7 @@ void RoamState::Update(AIController &ctrl, Entity &e, float dt) const {
        ctrl.CueDecision(10.0f, 5.0f);
 }
 
-void RoamState::Exit(AIController &ctrl, Entity &e) const {
+void RoamState::Exit(AIController &, Entity &e) const {
        e.GetSteering().Disable(Steering::WANDER);
 }