]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/creature.cpp
log death just once
[blobs.git] / src / creature / creature.cpp
index 667dc1740bdfa4fa37227b5ba74396a61dc9de2b..8c7d23569ac42b039f4ffe604b0cd2d9e177969d 100644 (file)
@@ -209,22 +209,6 @@ void Creature::DoWork(double amount) noexcept {
 void Creature::Hurt(double amount) noexcept {
        stats.Damage().Add(amount);
        if (stats.Damage().Full()) {
-               std::ostream &log = sim.Log() << name << " ";
-               if (stats.Exhaustion().Full()) {
-                       log << "died of exhaustion";
-               } else if (stats.Breath().Full()) {
-                       log << "suffocated";
-               } else if (stats.Thirst().Full()) {
-                       log << "died of thirst";
-               } else if (stats.Hunger().Full()) {
-                       log << "starved to death";
-               } else {
-                       log << "succumed to wounds";
-               }
-               log << " at an age of " << ui::TimeString(Age())
-                       << " (" << ui::PercentageString(Age() / properties.Lifetime())
-                       << " of life expectancy of " << ui::TimeString(properties.Lifetime())
-                       << ")" << std::endl;
                Die();
        }
 }
@@ -232,6 +216,23 @@ void Creature::Hurt(double amount) noexcept {
 void Creature::Die() noexcept {
        if (Dead()) return;
 
+       std::ostream &log = sim.Log() << name << " ";
+       if (stats.Exhaustion().Full()) {
+               log << "died of exhaustion";
+       } else if (stats.Breath().Full()) {
+               log << "suffocated";
+       } else if (stats.Thirst().Full()) {
+               log << "died of thirst";
+       } else if (stats.Hunger().Full()) {
+               log << "starved to death";
+       } else {
+               log << "succumed to wounds";
+       }
+       log << " at an age of " << ui::TimeString(Age())
+               << " (" << ui::PercentageString(Age() / properties.Lifetime())
+               << " of life expectancy of " << ui::TimeString(properties.Lifetime())
+               << ")" << std::endl;
+
        sim.SetDead(this);
        death = sim.Time();
        steering.Off();
@@ -437,7 +438,6 @@ void Creature::TickStats(double dt) {
        for (auto &s : stats.stat) {
                s.Add(s.gain * dt);
        }
-       stats.Breath().Add(stats.Breath().gain * stats.Exhaustion().value * dt);
        // TODO: damage values depending on properties
        if (stats.Breath().Full()) {
                constexpr double dps = 1.0 / 4.0;