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; }
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));
}
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);
}
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
}