]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
avoid others when steering
[blobs.git] / src / creature / goal.cpp
index 8f8a3fa88f2911d2c6e0be6506cd43974df11d7e..77a0dece1a261b55cdf9318529ea6682d947accf 100644 (file)
@@ -92,8 +92,7 @@ void IdleGoal::Action() {
        double rand = Assets().random.UNorm();
        if (fert > rand) {
                std::cout << "[" << int(GetCreature().GetSimulation().Time())
-                       << "s] splitting " << GetCreature().Name()
-                       << " because " << fert << " > " << rand << std::endl;
+                       << "s] " << GetCreature().Name() << " split" << std::endl;
                Split(GetCreature());
        }
 }
@@ -130,15 +129,14 @@ void LocateResourceGoal::Action() {
                } else {
                        double dist = glm::length2(GetSituation().Position() - target_pos);
                        if (dist < 0.0001) {
-                               GetSteering().Halt();
-                               searching = false;
+                               LocateResource();
                        } else {
                                GetSteering().GoTo(target_pos);
                        }
                }
        } else if (OnTargetTile()) {
                GetSteering().Halt();
-               if (!GetCreature().Moving()) {
+               if (!GetSituation().Moving()) {
                        SetComplete();
                }
        } else {
@@ -212,6 +210,8 @@ void LocateResourceGoal::SearchVicinity() {
                target_pos = GetSituation().Position();
                target_pos[(srf + 0) % 3] += Assets().random.SNorm();
                target_pos[(srf + 1) % 3] += Assets().random.SNorm();
+               // bias towards current direction
+               target_pos += glm::normalize(GetSituation().Velocity()) * 0.5;
                GetSteering().GoTo(target_pos);
        }
 }