]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
track a few things
[blobs.git] / src / creature / goal.cpp
index 06a689f2e0d6d1cebbe29e3c75c7224470bed6ab..f3e0891c1e1ca5cf7e6b98846f4ed43aca0688f2 100644 (file)
@@ -37,8 +37,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 ~2.5% gas composition
+               double gas_amount = GetCreature().GetComposition().Get(gas);
+               if (gas_amount < GetCreature().GetComposition().TotalMass() * 0.025) {
+                       double add = std::min(GetCreature().GetComposition().TotalMass() * 0.025 - gas_amount, -amount * dt);
+                       GetCreature().Ingest(gas, add);
+               }
                if (GetCreature().GetStats().Breath().Empty()) {
                        breathing = false;
                }