]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
some tweaks
[blobs.git] / src / creature / goal.cpp
index d72c3015be1ddbfddcc2d4936d7404154bf9828d..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());
+               }
        }
 }
 
@@ -105,7 +108,8 @@ LocateResourceGoal::LocateResourceGoal(Creature &c, int res)
 , target_pos(0.0)
 , target_srf(0)
 , target_tile(0)
-, searching(false) {
+, searching(false)
+, reevaluate(0.0) {
 }
 
 LocateResourceGoal::~LocateResourceGoal() noexcept {
@@ -116,14 +120,18 @@ std::string LocateResourceGoal::Describe() const {
 }
 
 void LocateResourceGoal::Enable() {
-       LocateResource();
+
 }
 
 void LocateResourceGoal::Tick(double dt) {
+       reevaluate -= dt;
 }
 
 void LocateResourceGoal::Action() {
-       if (!found) {
+       if (reevaluate < 0.0) {
+               LocateResource();
+               reevaluate = 3.0;
+       } else if (!found) {
                if (!searching) {
                        LocateResource();
                } else {
@@ -142,6 +150,7 @@ void LocateResourceGoal::Action() {
        } else {
                GetSteering().GoTo(target_pos);
        }
+       GetSteering().Haste(Urgency());
 }
 
 void LocateResourceGoal::LocateResource() {
@@ -185,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;
                        }
                }
@@ -228,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);
        }
 }