X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcreature%2Fcreature.cpp;h=8c7d23569ac42b039f4ffe604b0cd2d9e177969d;hb=d238457803553ba9d83be68993758102c962c4f5;hp=376ad3ffe86438272c52ac221eb9efdaa0426863;hpb=631f0cfd6b421f5be68d60375db2ce91176d923d;p=blobs.git diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 376ad3f..8c7d235 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -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(); @@ -321,6 +322,28 @@ double Creature::OffspringMass() const noexcept { return properties.OffspringMass(); } +double Creature::PerceptionRange() const noexcept { + return 3.0 * (Dexerty() / (Dexerty() + 1)) + Size(); +} + +double Creature::PerceptionOmniRange() const noexcept { + return 0.5 * (Dexerty() / (Dexerty() + 1)) + Size(); +} + +double Creature::PerceptionField() const noexcept { + // this is the cosine of half the angle, so 1.0 is none, -1.0 is perfect + return 0.8 - (Dexerty() / (Dexerty() + 1)); +} + +bool Creature::PerceptionTest(const glm::dvec3 &p) const noexcept { + const glm::dvec3 diff(p - situation.Position()); + double omni_range = PerceptionOmniRange(); + if (length2(diff) < omni_range * omni_range) return true; + double range = PerceptionRange(); + if (length2(diff) > range * range) return false; + return dot(normalize(diff), situation.Heading()) > PerceptionField(); +} + double Creature::OffspringChance() const noexcept { return AgeFactor(0.25) * properties.Fertility() * (1.0 / 3600.0); } @@ -415,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; @@ -925,6 +947,7 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { if (&*other == &c) continue; 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);