]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
steering tweaks
[blobs.git] / src / creature / goal.cpp
index a4f33304f3f75af56b86c376b0c653879405006e..3f61e2e8b80214571a75753f5581611ffa970d2c 100644 (file)
@@ -40,7 +40,7 @@ void BlobBackgroundTask::Tick(double dt) {
                // TODO: derive breathing ability
                int gas = Assets().data.resources["air"].id;
                // TODO: check if in compatible atmosphere
-               double amount = GetCreature().GetStats().Breath().gain * -(1.5 + 0.5 * GetCreature().ExhaustionFactor());
+               double amount = GetCreature().GetStats().Breath().gain * -(1.0 + GetCreature().ExhaustionFactor());
                GetCreature().GetStats().Breath().Add(amount * dt);
                // maintain ~1% gas composition
                double gas_amount = GetCreature().GetComposition().Get(gas);
@@ -100,8 +100,7 @@ void BlobBackgroundTask::CheckStats() {
 void BlobBackgroundTask::CheckSplit() {
        if (GetCreature().Mass() > GetCreature().OffspringMass() * 2.0
                && GetCreature().OffspringChance() > Assets().random.UNorm()) {
-               std::cout << "[" << ui::TimeString(GetCreature().GetSimulation().Time())
-                       << "] " << GetCreature().Name() << " split" << std::endl;
+               GetCreature().GetSimulation().Log() << GetCreature().Name() << " split" << std::endl;
                Split(GetCreature());
                return;
        }
@@ -385,6 +384,8 @@ void LocateResourceGoal::LocateResource() {
                }
        } else {
                // well, what now?
+               found = false;
+               searching = false;
        }
 }
 
@@ -407,9 +408,11 @@ void LocateResourceGoal::SearchVicinity() {
                        const world::TileType &type = planet.TypeAt(srf, x, y);
                        auto yield = type.FindBestResource(accept);
                        if (yield != type.resources.cend()) {
+                               glm::dvec3 tc(planet.TileCenter(srf, x, y));
+                               if (!GetCreature().PerceptionTest(tc)) continue;
                                // TODO: subtract minimum yield
                                rating[y - begin.y][x - begin.x] = yield->ubiquity * accept.Get(yield->resource);
-                               double dist = std::max(0.125, 0.25 * glm::length(planet.TileCenter(srf, x, y) - pos));
+                               double dist = std::max(0.125, 0.25 * glm::length(tc - pos));
                                rating[y - begin.y][x - begin.x] /= dist;
                        }
                }
@@ -422,7 +425,7 @@ void LocateResourceGoal::SearchVicinity() {
                glm::ivec2 coords(c->GetSituation().SurfacePosition());
                if (coords.x < begin.x || coords.x >= end.x) continue;
                if (coords.y < begin.y || coords.y >= end.y) continue;
-               rating[coords.y - begin.y][coords.x - begin.x] *= 0.9;
+               rating[coords.y - begin.y][coords.x - begin.x] *= 0.8;
        }
 
        glm::ivec2 best_pos(0);
@@ -450,8 +453,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;
+               // bias towards current heading
+               target_pos += GetSituation().Heading() * 0.5;
                target_pos = clamp(target_pos, -planet.Radius(), planet.Radius());
                GetSteering().GoTo(target_pos);
        }