#include "IngestNeed.hpp"
#include "Creature.hpp"
+#include "LocateResourceGoal.hpp"
#include "../world/Planet.hpp"
+#include "../world/TileType.hpp"
namespace blobs {
IngestNeed::IngestNeed(int resource, double speed, double damage)
: resource(resource)
, speed(speed)
-, damage(damage) {
+, damage(damage)
+, ingesting(false)
+, locating(false) {
}
IngestNeed::~IngestNeed() {
void IngestNeed::ApplyEffect(Creature &c, double dt) {
if (!IsSatisfied()) {
- // TODO: find resource and start ingest task
+ ingesting = true;
+ }
+ 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()) {
c.Hurt(damage * dt);
}
void InhaleNeed::ApplyEffect(Creature &c, double dt) {
- if (!IsSatisfied() && !inhaling) {
+ if (!IsSatisfied()) {
inhaling = true;
}
if (inhaling) {