]> git.localhorst.tv Git - blobs.git/commitdiff
smooth breathing a bit
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Nov 2017 21:43:14 +0000 (22:43 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 22 Nov 2017 21:43:14 +0000 (22:43 +0100)
src/creature/InhaleNeed.hpp
src/creature/Need.hpp
src/creature/creature.cpp
src/creature/need.cpp

index 365bb047eb9fead39d9b314469b3b518a78ceabe..3907a8bf99d66040e89f84686fb7655d134d4772 100644 (file)
@@ -23,6 +23,7 @@ private:
        int resource;
        double speed;
        double damage;
+       bool inhaling;
 
 };
 
index 2fd4898f3e40aa927b4f6fa9c9ac2c5770694059..67abe3c496d9ceab645625a986920cdee3a29c84 100644 (file)
@@ -26,6 +26,8 @@ struct Need {
        virtual ~Need() noexcept;
 
        void Tick(double dt) noexcept;
+       void Increase(double) noexcept;
+       void Decrease(double) noexcept;
 
        bool IsSatisfied() const noexcept { return value < inconvenient; }
        bool IsInconvenient() const noexcept { return value >= inconvenient && value < critical; }
index 3c4f544f2166bbf2e7f5a045988fa6442d283898..66931e921f58d06e5c227d1b3035f697203886d4 100644 (file)
@@ -171,9 +171,9 @@ void Spawn(Creature &c, world::Planet &p, app::Assets &assets) {
 
        if (p.HasAtmosphere()) {
                std::cout << "require breathing " << assets.data.resources[p.Atmosphere()].label << std::endl;
-               std::unique_ptr<Need> need(new InhaleNeed(p.Atmosphere(), 0.25, 0.1));
+               std::unique_ptr<Need> need(new InhaleNeed(p.Atmosphere(), 0.5, 0.1));
                need->name = assets.data.resources[p.Atmosphere()].label;
-               need->gain = 0.25;
+               need->gain = 0.2;
                need->inconvenient = 0.4;
                need->critical = 0.95;
                c.AddNeed(std::move(need));
index b56950070e974d6f56e48be084ea419ec4567b22..88b44197c8de80af4f6a0afcb297915c75053a33 100644 (file)
@@ -13,7 +13,15 @@ Need::~Need() {
 }
 
 void Need::Tick(double dt) noexcept {
-       value = std::min(1.0, value + gain * dt);
+       Increase(gain * dt);
+}
+
+void Need::Increase(double delta) noexcept {
+       value = std::min(1.0, value + delta);
+}
+
+void Need::Decrease(double delta) noexcept {
+       value = std::max(0.0, value - delta);
 }
 
 
@@ -39,17 +47,23 @@ void IngestNeed::ApplyEffect(Creature &c, double dt) {
 InhaleNeed::InhaleNeed(int resource, double speed, double damage)
 : resource(resource)
 , speed(speed)
-, damage(damage) {
+, damage(damage)
+, inhaling(false) {
 }
 
 InhaleNeed::~InhaleNeed() {
 }
 
 void InhaleNeed::ApplyEffect(Creature &c, double dt) {
-       if (!IsSatisfied()) {
-               // TODO: make condition more natural with thresholds and stuff
+       if (!IsSatisfied() && !inhaling) {
+               inhaling = true;
+       }
+       if (inhaling) {
                if (c.GetSituation().OnPlanet() && c.GetSituation().GetPlanet().Atmosphere() == resource) {
-                       value = std::max(0.0, value - (speed * dt));
+                       Decrease(speed * dt);
+                       if (value == 0.0) {
+                               inhaling = false;
+                       }
                } else {
                        // TODO: panic
                }