From: Daniel Karbach Date: Thu, 30 Nov 2017 09:32:40 +0000 (+0100) Subject: periodically reevaluation locate decision X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=da5e275f10252813b4de3af5e58f0c7975468962;p=blobs.git periodically reevaluation locate decision --- diff --git a/src/creature/LocateResourceGoal.hpp b/src/creature/LocateResourceGoal.hpp index 1f31d0f..c69e3e6 100644 --- a/src/creature/LocateResourceGoal.hpp +++ b/src/creature/LocateResourceGoal.hpp @@ -32,6 +32,7 @@ private: int target_srf; glm::ivec2 target_tile; bool searching; + double reevaluate; }; diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index d72c301..95a3426 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -105,7 +105,8 @@ LocateResourceGoal::LocateResourceGoal(Creature &c, int res) , target_pos(0.0) , target_srf(0) , target_tile(0) -, searching(false) { +, searching(false) +, reevaluate(0.0) { } LocateResourceGoal::~LocateResourceGoal() noexcept { @@ -116,14 +117,18 @@ std::string LocateResourceGoal::Describe() const { } void LocateResourceGoal::Enable() { - LocateResource(); + } void LocateResourceGoal::Tick(double dt) { + reevaluate -= dt; } void LocateResourceGoal::Action() { - if (!found) { + if (reevaluate < 0.0) { + LocateResource(); + reevaluate = 3.0; + } else if (!found) { if (!searching) { LocateResource(); } else {