]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
some tweaks
[blobs.git] / src / creature / goal.cpp
index 95a3426d986419b8e0e1459fca9cc5d442c083ca..daf8f901d7989b780cb067712eb65e4b5e14cd3c 100644 (file)
@@ -88,12 +88,15 @@ void IdleGoal::Tick(double dt) {
 }
 
 void IdleGoal::Action() {
-       double fert = GetCreature().Fertility();
-       double rand = Assets().random.UNorm();
-       if (fert > rand) {
-               std::cout << "[" << int(GetCreature().GetSimulation().Time())
-                       << "s] " << GetCreature().Name() << " split" << std::endl;
-               Split(GetCreature());
+       // check if eligible to split
+       if (GetCreature().Mass() > GetCreature().GetProperties().Birth().mass * 1.8) {
+               double fert = GetCreature().Fertility();
+               double rand = Assets().random.UNorm();
+               if (fert > rand) {
+                       std::cout << "[" << int(GetCreature().GetSimulation().Time())
+                               << "s] " << GetCreature().Name() << " split" << std::endl;
+                       Split(GetCreature());
+               }
        }
 }
 
@@ -147,6 +150,7 @@ void LocateResourceGoal::Action() {
        } else {
                GetSteering().GoTo(target_pos);
        }
+       GetSteering().Haste(Urgency());
 }
 
 void LocateResourceGoal::LocateResource() {
@@ -190,7 +194,7 @@ void LocateResourceGoal::SearchVicinity() {
                        if (yield != type.resources.cend()) {
                                // TODO: subtract minimum yield
                                rating[y - begin.y][x - begin.x] = yield->ubiquity;
-                               double dist = 1.0 - 0.25 * glm::length2(planet.TileCenter(srf, x, y) - pos);
+                               double dist = std::max(0.125, 0.25 * glm::length(planet.TileCenter(srf, x, y) - pos));
                                rating[y - begin.y][x - begin.x] /= dist;
                        }
                }
@@ -233,6 +237,7 @@ void LocateResourceGoal::SearchVicinity() {
                target_pos[(srf + 1) % 3] += Assets().random.SNorm();
                // bias towards current direction
                target_pos += glm::normalize(GetSituation().Velocity()) * 0.5;
+               target_pos = clamp(target_pos, -planet.Radius(), planet.Radius());
                GetSteering().GoTo(target_pos);
        }
 }