]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/need.cpp
remove outdated TODOs
[blobs.git] / src / creature / need.cpp
index 60e7cb816b3a0b8cd375df295da00e80723dbc3a..576655a97185ec8740cde7fe6385d1128485509e 100644 (file)
@@ -28,11 +28,11 @@ void Need::Decrease(double delta) noexcept {
 
 
 IngestNeed::IngestNeed(int resource, double speed, double damage)
-: resource(resource)
+: locate_goal(nullptr)
+, resource(resource)
 , speed(speed)
 , damage(damage)
-, ingesting(false)
-, locating(false) {
+, ingesting(false) {
 }
 
 IngestNeed::~IngestNeed() {
@@ -50,23 +50,38 @@ void IngestNeed::ApplyEffect(Creature &c, double dt) {
                                if (yield.resource == resource) {
                                        found = true;
                                        // TODO: check if not busy with something else
-                                       Decrease(std::min(yield.ubiquity, speed) * dt);
+                                       double amount = std::min(yield.ubiquity, speed) * dt;
+                                       c.Ingest(resource, amount * growth * dt);
+                                       Decrease(amount);
                                        if (value == 0.0) {
                                                ingesting = false;
-                                               locating = false;
+                                               if (locate_goal) {
+                                                       // abort
+                                                       locate_goal->Complete();
+                                               }
                                        }
                                        break;
                                }
                        }
-                       if (!found && !locating) {
-                               c.AddGoal(std::unique_ptr<Goal>(new LocateResourceGoal(resource)));
-                               locating = true;
+                       if (!found && !locate_goal) {
+                               locate_goal = new LocateResourceGoal(c, resource);
+                               locate_goal->OnComplete([&](Goal &g){ OnLocateComplete(g); });
+                               c.AddGoal(std::unique_ptr<Goal>(locate_goal));
                        }
                }
        }
        if (IsCritical()) {
                c.Hurt(damage * dt);
        }
+       if (locate_goal) {
+               locate_goal->Urgency(value);
+       }
+}
+
+void IngestNeed::OnLocateComplete(Goal &g) {
+       if (&g == locate_goal) {
+               locate_goal = nullptr;
+       }
 }