]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
perception
[blobs.git] / src / creature / goal.cpp
index f3e0891c1e1ca5cf7e6b98846f4ed43aca0688f2..61ecb3778a5b874c9b61e4e6fd93b2d107bdf941 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "Creature.hpp"
 #include "../app/Assets.hpp"
+#include "../ui/string.hpp"
 #include "../world/Planet.hpp"
 #include "../world/Resource.hpp"
 #include "../world/Simulation.hpp"
@@ -41,9 +42,9 @@ void BlobBackgroundTask::Tick(double dt) {
                // TODO: check if in compatible atmosphere
                double amount = GetCreature().GetStats().Breath().gain * -(1.5 + 0.5 * GetCreature().ExhaustionFactor());
                GetCreature().GetStats().Breath().Add(amount * dt);
-               // maintain ~2.5% gas composition
+               // maintain ~1% gas composition
                double gas_amount = GetCreature().GetComposition().Get(gas);
-               if (gas_amount < GetCreature().GetComposition().TotalMass() * 0.025) {
+               if (gas_amount < GetCreature().GetComposition().TotalMass() * 0.01) {
                        double add = std::min(GetCreature().GetComposition().TotalMass() * 0.025 - gas_amount, -amount * dt);
                        GetCreature().Ingest(gas, add);
                }
@@ -99,8 +100,7 @@ void BlobBackgroundTask::CheckStats() {
 void BlobBackgroundTask::CheckSplit() {
        if (GetCreature().Mass() > GetCreature().OffspringMass() * 2.0
                && GetCreature().OffspringChance() > Assets().random.UNorm()) {
-               std::cout << "[" << int(GetCreature().GetSimulation().Time())
-                       << "s] " << GetCreature().Name() << " split" << std::endl;
+               GetCreature().GetSimulation().Log() << GetCreature().Name() << " split" << std::endl;
                Split(GetCreature());
                return;
        }
@@ -110,7 +110,7 @@ void BlobBackgroundTask::CheckMutate() {
        // check for random property mutation
        if (GetCreature().MutateChance() > Assets().random.UNorm()) {
                double amount = 1.0 + (Assets().random.SNorm() * 0.05);
-               math::Distribution &d = GetCreature().GetGenome().properties.props[(int(Assets().random.UNorm() * 8.0) % 8)];
+               math::Distribution &d = GetCreature().GetGenome().properties.props[Assets().random.UInt(9)];
                if (Assets().random.UNorm() < 0.5) {
                        d.Mean(d.Mean() * amount);
                } else {
@@ -406,9 +406,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;
                        }
                }
@@ -421,7 +423,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);