]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/creature.cpp
primitive collision response
[blobs.git] / src / creature / creature.cpp
index d0000107b683e5b454d1864ba65c9c4c6dfe3873..dc857ceb08bd637460ee7b4954a95e7c17dd0275 100644 (file)
@@ -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();
        }
 }
@@ -293,6 +322,10 @@ void Creature::TickStats(double dt) {
                constexpr double dps = 1.0 / 128.0;
                Hurt(dps * dt);
        }
+       if (!situation.Moving()) {
+               // double exhaustion recovery when standing still
+               stats.Exhaustion().Add(stats.Exhaustion().gain * dt);
+       }
 }
 
 void Creature::TickBrain(double dt) {
@@ -320,13 +353,22 @@ void Creature::TickBrain(double dt) {
        }
 }
 
-glm::dmat4 Creature::LocalTransform() noexcept {
+math::AABB Creature::CollisionBox() const noexcept {
+       return { glm::dvec3(size * -0.5), glm::dvec3(size * 0.5) };
+}
+
+glm::dmat4 Creature::CollisionTransform() const noexcept {
        const double half_size = size * 0.5;
        const glm::dvec3 &pos = situation.Position();
        const glm::dmat3 srf(world::Planet::SurfaceOrientation(situation.Surface()));
        return glm::translate(glm::dvec3(pos.x, pos.y, pos.z + half_size))
                * glm::rotate(glm::orientedAngle(-srf[2], situation.Heading(), srf[1]), srf[1])
-               * glm::dmat4(srf)
+               * glm::dmat4(srf);
+}
+
+glm::dmat4 Creature::LocalTransform() noexcept {
+       const double half_size = size * 0.5;
+       return CollisionTransform()
                * glm::scale(glm::dvec3(half_size, half_size, half_size));
 }
 
@@ -451,7 +493,7 @@ void Spawn(Creature &c, world::Planet &p) {
 
        Genome genome;
        genome.properties.Strength() = { 2.0, 0.1 };
-       genome.properties.Stamina() = { 4.0, 0.1 };
+       genome.properties.Stamina() = { 2.0, 0.1 };
        genome.properties.Dexerty() = { 2.0, 0.1 };
        genome.properties.Intelligence() = { 1.0, 0.1 };
        genome.properties.Lifetime() = { 480.0, 60.0 };
@@ -566,7 +608,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 +745,10 @@ void Steering::DontSeparate() noexcept {
        separating = false;
 }
 
+void Steering::ResumeSeparate() noexcept {
+       separating = false;
+}
+
 void Steering::Halt() noexcept {
        halting = true;
        seeking = false;