2 #include "InhaleNeed.hpp"
3 #include "IngestNeed.hpp"
5 #include "Creature.hpp"
6 #include "LocateResourceGoal.hpp"
7 #include "../world/Planet.hpp"
8 #include "../world/TileType.hpp"
17 void Need::Tick(double dt) noexcept {
21 void Need::Increase(double delta) noexcept {
22 value = std::min(1.0, value + delta);
25 void Need::Decrease(double delta) noexcept {
26 value = std::max(0.0, value - delta);
30 IngestNeed::IngestNeed(int resource, double speed, double damage)
31 : locate_goal(nullptr)
38 IngestNeed::~IngestNeed() {
41 void IngestNeed::ApplyEffect(Creature &c, double dt) {
46 if (c.GetSituation().OnSurface()) {
47 const world::TileType &t = c.GetSituation().GetTileType();
49 for (auto &yield : t.resources) {
50 if (yield.resource == resource) {
52 // TODO: check if not busy with something else
53 Decrease(std::min(yield.ubiquity, speed) * dt);
58 locate_goal->Complete();
64 if (!found && !locate_goal) {
65 locate_goal = new LocateResourceGoal(c, resource);
66 locate_goal->OnComplete([&](Goal &g){ OnLocateComplete(g); });
67 c.AddGoal(std::unique_ptr<Goal>(locate_goal));
75 locate_goal->Urgency(value);
79 void IngestNeed::OnLocateComplete(Goal &g) {
80 if (&g == locate_goal) {
81 locate_goal = nullptr;
86 InhaleNeed::InhaleNeed(int resource, double speed, double damage)
93 InhaleNeed::~InhaleNeed() {
96 void InhaleNeed::ApplyEffect(Creature &c, double dt) {
101 if (c.GetSituation().OnPlanet() && c.GetSituation().GetPlanet().Atmosphere() == resource) {
102 Decrease(speed * dt);