X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2Fgoal.cpp;h=229dffc8f3e38e04510e13a82fa1141093bf9e32;hp=18714e49cb195637d82ae1abfc0824e756b962ea;hb=42db7d9d2286e50896ad172e2e4a8fbe65c8a4a9;hpb=8f6530c75730f901efd6708e4fde7e68a178adf1 diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index 18714e4..229dffc 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -1,7 +1,9 @@ #include "Goal.hpp" +#include "IdleGoal.hpp" #include "LocateResourceGoal.hpp" #include "Creature.hpp" +#include "../app/Assets.hpp" #include "../world/Planet.hpp" #include "../world/Resource.hpp" #include "../world/Simulation.hpp" @@ -41,6 +43,14 @@ const Steering &Goal::GetSteering() const noexcept { return c.GetSteering(); } +app::Assets &Goal::Assets() noexcept { + return c.GetSimulation().Assets(); +} + +const app::Assets &Goal::Assets() const noexcept { + return c.GetSimulation().Assets(); +} + void Goal::SetComplete() noexcept { if (!complete) { complete = true; @@ -58,6 +68,37 @@ void Goal::OnComplete(std::function cb) noexcept { } +IdleGoal::IdleGoal(Creature &c) +: Goal(c) { + Urgency(-1.0); + Interruptible(true); +} + +IdleGoal::~IdleGoal() { +} + +std::string IdleGoal::Describe() const { + return "idle"; +} + +void IdleGoal::Enable() { +} + +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] splitting " << GetCreature().Name() + << " because " << fert << " > " << rand << std::endl; + Split(GetCreature()); + } +} + + LocateResourceGoal::LocateResourceGoal(Creature &c, int res) : Goal(c) , res(res) @@ -152,7 +193,6 @@ void LocateResourceGoal::SearchVicinity() { target_srf = srf; target_tile = best_pos; GetSteering().GoTo(target_pos); - std::cout << "found resource at " << target_pos << std::endl; } else { // oh crap }