X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fai%2Fai.cpp;h=95dc8f7d26e66703a50a45f9c427f990aece1370;hb=HEAD;hp=db4ae413d8170a9dbc5f7f7056978a0615f6e5ee;hpb=c4416bc2a5e446d0ba99cfeb50bb5fab287a1c4e;p=blank.git diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index db4ae41..95dc8f7 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -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 #include -#include 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,7 +145,7 @@ 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(5.0f) .SetSpeed(4.0f) @@ -153,7 +153,7 @@ void ChaseState::Enter(AIController &ctrl, Entity &e) const { ; } -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); } @@ -191,12 +191,12 @@ void FleeState::Enter(AIController &ctrl, Entity &e) const { 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); }