]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
lose weight through exercise
[blobs.git] / src / creature / goal.cpp
index 06a689f2e0d6d1cebbe29e3c75c7224470bed6ab..5f9f1e839d9ed24bdff82c62caaf7ea50bd2b42d 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"
@@ -37,8 +38,16 @@ std::string BlobBackgroundTask::Describe() const {
 void BlobBackgroundTask::Tick(double dt) {
        if (breathing) {
                // 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());
                GetCreature().GetStats().Breath().Add(amount * dt);
+               // maintain ~1% gas composition
+               double gas_amount = GetCreature().GetComposition().Get(gas);
+               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);
+               }
                if (GetCreature().GetStats().Breath().Empty()) {
                        breathing = false;
                }
@@ -91,8 +100,8 @@ 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;
+               std::cout << "[" << ui::TimeString(GetCreature().GetSimulation().Time())
+                       << "] " << GetCreature().Name() << " split" << std::endl;
                Split(GetCreature());
                return;
        }