]> git.localhorst.tv Git - blobs.git/commitdiff
"look around" activity
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 18 Dec 2017 14:18:53 +0000 (15:18 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 18 Dec 2017 14:18:53 +0000 (15:18 +0100)
utterly useless, for now

src/creature/LookAroundGoal.hpp [new file with mode: 0644]
src/creature/creature.cpp
src/creature/goal.cpp

diff --git a/src/creature/LookAroundGoal.hpp b/src/creature/LookAroundGoal.hpp
new file mode 100644 (file)
index 0000000..30b248f
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef BLOBS_CREATURE_LOOKAROUNDGOAL_HPP_
+#define BLOBS_CREATURE_LOOKAROUNDGOAL_HPP_
+
+#include "Goal.hpp"
+
+
+namespace blobs {
+namespace creature {
+
+class LookAroundGoal
+: public Goal {
+
+public:
+       explicit LookAroundGoal(Creature &);
+       ~LookAroundGoal() override;
+
+public:
+       std::string Describe() const override;
+       void Enable() override;
+       void Tick(double dt) override;
+       void Action() override;
+       void OnBackground() override;
+
+       void PickDirection() noexcept;
+
+private:
+       double timer;
+
+};
+
+}
+}
+
+#endif
index e118451147fa0e3d88919ecd2a4b96e96698924d..ff3a81c06c050b3a8013f5ddc6d44e06ef63696a 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <algorithm>
 #include <sstream>
+#include <glm/gtx/rotate_vector.hpp>
 #include <glm/gtx/transform.hpp>
 #include <glm/gtx/vector_angle.hpp>
 
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())