]> git.localhorst.tv Git - blobs.git/commitdiff
periodically reevaluation locate decision
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 30 Nov 2017 09:32:40 +0000 (10:32 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 30 Nov 2017 09:32:40 +0000 (10:32 +0100)
src/creature/LocateResourceGoal.hpp
src/creature/goal.cpp

index 1f31d0f426457781e49f1aec24ba4fdac9043e44..c69e3e687af3cdee4ade75e01586b0ffb60ad792 100644 (file)
@@ -32,6 +32,7 @@ private:
        int target_srf;
        glm::ivec2 target_tile;
        bool searching;
+       double reevaluate;
 
 };
 
index d72c3015be1ddbfddcc2d4936d7404154bf9828d..95a3426d986419b8e0e1459fca9cc5d442c083ca 100644 (file)
@@ -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 {