From: Daniel Karbach Date: Mon, 18 Dec 2017 14:18:53 +0000 (+0100) Subject: "look around" activity X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=commitdiff_plain;h=a4d4cc133ff1a8b9ab209b436ee94579930eb948 "look around" activity utterly useless, for now --- diff --git a/src/creature/LookAroundGoal.hpp b/src/creature/LookAroundGoal.hpp new file mode 100644 index 0000000..30b248f --- /dev/null +++ b/src/creature/LookAroundGoal.hpp @@ -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 diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index e118451..ff3a81c 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index c7a7b66..74ed17f 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -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 #include #include +#include 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(new StrollGoal(GetCreature()))); + int n = Random().UInt(2); + if (n == 0) { + GetCreature().AddGoal(std::unique_ptr(new StrollGoal(GetCreature()))); + } else { + GetCreature().AddGoal(std::unique_ptr(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())