]> git.localhorst.tv Git - blobs.git/blobdiff - src/creature/goal.cpp
"look around" activity
[blobs.git] / src / creature / goal.cpp
index c7a7b66ac5f9be93024f8ab8f486edf11aa1b8ca..74ed17f6e9b6c85fdfc95ce9312e45b8634c1919 100644 (file)
@@ -4,10 +4,12 @@
 #include "IdleGoal.hpp"
 #include "IngestGoal.hpp"
 #include "LocateResourceGoal.hpp"
+#include "LookAroundGoal.hpp"
 #include "StrollGoal.hpp"
 
 #include "Creature.hpp"
 #include "../app/Assets.hpp"
+#include "../math/const.hpp"
 #include "../ui/string.hpp"
 #include "../world/Planet.hpp"
 #include "../world/Resource.hpp"
@@ -18,6 +20,7 @@
 #include <iostream>
 #include <sstream>
 #include <glm/gtx/io.hpp>
+#include <glm/gtx/rotate_vector.hpp>
 
 
 namespace blobs {
@@ -285,14 +288,19 @@ void IdleGoal::Action() {
                GetSteering().ResumeSeparate();
        }
 
-       // use boredom as chance per 30s
-       if (Random().UNorm() < GetStats().Boredom().value * (1.0 / 1800.0)) {
+       // use boredom as chance per 15s
+       if (Random().UNorm() < GetStats().Boredom().value * (1.0 / 900.0)) {
                PickActivity();
        }
 }
 
 void IdleGoal::PickActivity() {
-       GetCreature().AddGoal(std::unique_ptr<Goal>(new StrollGoal(GetCreature())));
+       int n = Random().UInt(2);
+       if (n == 0) {
+               GetCreature().AddGoal(std::unique_ptr<Goal>(new StrollGoal(GetCreature())));
+       } else {
+               GetCreature().AddGoal(std::unique_ptr<Goal>(new LookAroundGoal(GetCreature())));
+       }
 }
 
 
@@ -593,6 +601,44 @@ bool LocateResourceGoal::OnTarget() const noexcept {
 }
 
 
+LookAroundGoal::LookAroundGoal(Creature &c)
+: Goal(c)
+, timer(0.0) {
+}
+
+LookAroundGoal::~LookAroundGoal() {
+}
+
+std::string LookAroundGoal::Describe() const {
+       return "look around";
+}
+
+void LookAroundGoal::Enable() {
+       GetSteering().Halt();
+}
+
+void LookAroundGoal::Tick(double dt) {
+       timer -= dt;
+}
+
+void LookAroundGoal::Action() {
+       if (timer < 0.0) {
+               PickDirection();
+               timer = 1.0 + (Random().UNorm() * 4.0);
+       }
+}
+
+void LookAroundGoal::OnBackground() {
+       SetComplete();
+}
+
+void LookAroundGoal::PickDirection() noexcept {
+       double r = Random().SNorm();
+       r *= std::abs(r) * 0.5 * PI;
+       GetCreature().HeadingTarget(glm::rotate(GetSituation().Heading(), r, GetSituation().SurfaceNormal()));
+}
+
+
 StrollGoal::StrollGoal(Creature &c)
 : Goal(c)
 , last(GetSituation().Position())