From: Daniel Karbach Date: Sat, 2 Dec 2017 10:52:14 +0000 (+0100) Subject: little cleanup X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=fbbee4cf7bd6f41139c2298c41d29b87401e6cf6;p=blobs.git little cleanup --- diff --git a/src/creature/Steering.hpp b/src/creature/Steering.hpp index c9c2332..e67fed1 100644 --- a/src/creature/Steering.hpp +++ b/src/creature/Steering.hpp @@ -30,6 +30,7 @@ public: public: void Separate(double min_distance, double max_lookaround) noexcept; void DontSeparate() noexcept; + void ResumeSeparate() noexcept; void Halt() noexcept; void Pass(const glm::dvec3 &) noexcept; void GoTo(const glm::dvec3 &) noexcept; diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index d000010..ccd174d 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -133,7 +133,9 @@ void Creature::Hurt(double amount) noexcept { stats.Damage().Add(amount); if (stats.Damage().Full()) { std::cout << "[" << int(sim.Time()) << "s] " << name << " "; - if (stats.Breath().Full()) { + if (stats.Exhaustion().Full()) { + std::cout << "died of exhaustion"; + } else if (stats.Breath().Full()) { std::cout << "suffocated"; } else if (stats.Thirst().Full()) { std::cout << "died of thirst"; @@ -142,7 +144,34 @@ void Creature::Hurt(double amount) noexcept { } else { std::cout << "succumed to wounds"; } - std::cout << std::endl; + std::cout << " at an age of "; + { + int age = int(Age()); + if (age >= 3600) { + std::cout << (age / 3600) << "h "; + age %= 3600; + } + if (age >= 60) { + std::cout << (age / 60) << "m "; + age %= 60; + } + std::cout << age << 's'; + } + std::cout << " (" << int(Age() / properties.Lifetime() * 100) + << "% of life expectancy of "; + { + int lt = int(properties.Lifetime()); + if (lt >= 3600) { + std::cout << (lt / 3600) << "h "; + lt %= 3600; + } + if (lt >= 60) { + std::cout << (lt / 60) << "m "; + lt %= 60; + } + std::cout << lt << 's'; + } + std::cout << ")" << std::endl; Die(); } } @@ -566,7 +595,7 @@ Memory::~Memory() { void Memory::Tick(double dt) { Situation &s = c.GetSituation(); - if (s.OnSurface()) { + if (s.OnTile()) { TrackStay({ &s.GetPlanet(), s.Surface(), s.SurfacePosition() }, dt); } } @@ -703,6 +732,10 @@ void Steering::DontSeparate() noexcept { separating = false; } +void Steering::ResumeSeparate() noexcept { + separating = false; +} + void Steering::Halt() noexcept { halting = true; seeking = false; diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index 31983de..06a689f 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -37,7 +37,7 @@ std::string BlobBackgroundTask::Describe() const { void BlobBackgroundTask::Tick(double dt) { if (breathing) { // TODO: derive breathing ability - double amount = GetCreature().GetStats().Breath().gain * -(1.0 + GetCreature().ExhaustionFactor()); + double amount = GetCreature().GetStats().Breath().gain * -(1.5 + 0.5 * GetCreature().ExhaustionFactor()); GetCreature().GetStats().Breath().Add(amount * dt); if (GetCreature().GetStats().Breath().Empty()) { breathing = false; @@ -79,6 +79,13 @@ void BlobBackgroundTask::CheckStats() { eat_subtask->OnComplete([&](Goal &) { eat_subtask = nullptr; }); GetCreature().AddGoal(std::unique_ptr(eat_subtask)); } + + // when in bad shape, don't make much effort + if (stats.Damage().Bad() || stats.Exhaustion().Bad() || stats.Fatigue().Critical()) { + GetCreature().GetSteering().DontSeparate(); + } else { + GetCreature().GetSteering().ResumeSeparate(); + } } void BlobBackgroundTask::CheckSplit() { @@ -204,7 +211,7 @@ void IngestGoal::Action() { } bool IngestGoal::OnSuitableTile() { - if (!GetSituation().OnSurface()) { + if (!GetSituation().OnTile()) { return false; } const world::TileType &t = GetSituation().GetTileType(); @@ -352,7 +359,7 @@ void LocateResourceGoal::Action() { } void LocateResourceGoal::LocateResource() { - if (GetSituation().OnSurface()) { + if (GetSituation().OnTile()) { const world::TileType &t = GetSituation().GetTileType(); auto yield = t.FindBestResource(accept); if (yield != t.resources.cend()) { @@ -382,15 +389,6 @@ void LocateResourceGoal::SearchVicinity() { glm::ivec2 begin(glm::max(glm::ivec2(0), loc - seek_radius)); glm::ivec2 end(glm::min(glm::ivec2(planet.SideLength()), loc + seek_radius + glm::ivec2(1))); - // this happens when location is way off the planet - // that's a bug in Situation, actually, but I'm working aound that here - if (end.x <= begin.x) { - end.x = begin.x + 2; - } - if (end.y <= begin.y) { - end.y = begin.y + 2; - } - double rating[end.y - begin.y][end.x - begin.x]; std::memset(rating, 0, sizeof(double) * (end.y - begin.y) * (end.x - begin.x));