void Creature::Hurt(double amount) noexcept {
stats.Damage().Add(amount);
+ if (stats.Damage().Full()) {
+ Die();
+ }
+}
+
+void Creature::Die() noexcept {
+ if (Dead()) return;
+
if (stats.Damage().Full()) {
std::ostream &log = sim.Log() << name << " ";
if (stats.Exhaustion().Full()) {
<< " (" << ui::PercentageString(Age() / properties.Lifetime())
<< " of life expectancy of " << ui::TimeString(properties.Lifetime())
<< ")" << std::endl;
- Die();
}
-}
-
-void Creature::Die() noexcept {
- if (Dead()) return;
sim.SetDead(this);
death = sim.Time();
glm::dvec3 diff = s.Position() - other->GetSituation().Position();
if (length2(diff) > max_look * max_look) continue;
if (!c.PerceptionTest(other->GetSituation().Position())) continue;
- double sep = length(diff) - other->Size() * 0.707 - c.Size() * 0.707;
- if (sep < min_dist) {
- repulse += normalize(diff) * (1.0 - sep / min_dist);
- }
+ double sep = glm::clamp(length(diff) - other->Size() * 0.707 - c.Size() * 0.707, 0.0, min_dist);
+ repulse += normalize(diff) * (1.0 - sep / min_dist) * force;
}
result += repulse;
}