X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2Fgoal.cpp;fp=src%2Fcreature%2Fgoal.cpp;h=74ed17f6e9b6c85fdfc95ce9312e45b8634c1919;hp=c7a7b66ac5f9be93024f8ab8f486edf11aa1b8ca;hb=a4d4cc133ff1a8b9ab209b436ee94579930eb948;hpb=2797cbced4b524543b4732041cee03a1b80d0047 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())