#include "IngestNeed.hpp"
#include "Creature.hpp"
+#include "LocateResourceGoal.hpp"
#include "../world/Planet.hpp"
#include "../world/TileType.hpp"
: resource(resource)
, speed(speed)
, damage(damage)
-, ingesting(false) {
+, ingesting(false)
+, locating(false) {
}
IngestNeed::~IngestNeed() {
if (!IsSatisfied()) {
ingesting = true;
}
- if (!IsSatisfied()) {
- // TODO: find resource and start ingest task
+ if (ingesting) {
if (c.GetSituation().OnSurface()) {
const world::TileType &t = c.GetSituation().GetTileType();
+ bool found = false;
for (auto &yield : t.resources) {
if (yield.resource == resource) {
+ found = true;
+ // TODO: check if not busy with something else
Decrease(std::min(yield.ubiquity, speed) * dt);
+ if (value == 0.0) {
+ ingesting = false;
+ locating = false;
+ }
break;
}
}
+ if (!found && !locating) {
+ c.AddGoal(std::unique_ptr<Goal>(new LocateResourceGoal(resource)));
+ locating = true;
+ }
}
}
if (IsCritical()) {