X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcreature%2FCreature.hpp;h=d3cd86c462a7d8f22933ab2b8a0da41673a0ce25;hb=6c1097479fd1ea41f0f76b91e67613822acf2e90;hp=f4c000408a63fa9f5bee40af3927f34b92403230;hpb=bcf776b6d51aeb9147bde32da8dd0768b10db993;p=blobs.git diff --git a/src/creature/Creature.hpp b/src/creature/Creature.hpp index f4c0004..d3cd86c 100644 --- a/src/creature/Creature.hpp +++ b/src/creature/Creature.hpp @@ -1,11 +1,16 @@ #ifndef BLOBS_CREATURE_CREATURE_HPP_ #define BLOBS_CREATURE_CREATURE_HPP_ +#include "Genome.hpp" +#include "Goal.hpp" +#include "Memory.hpp" #include "Need.hpp" #include "Situation.hpp" -#include "../graphics/glm.hpp" +#include "Steering.hpp" #include "../graphics/SimpleVAO.hpp" +#include "../math/glm.hpp" +#include #include #include @@ -20,13 +25,17 @@ namespace graphics { namespace world { class Body; class Planet; + class Simulation; } namespace creature { class Creature { public: - Creature(); + using Callback = std::function; + +public: + explicit Creature(world::Simulation &); ~Creature(); Creature(const Creature &) = delete; @@ -36,31 +45,101 @@ public: Creature &operator =(Creature &&) = delete; public: + world::Simulation &GetSimulation() noexcept { return sim; } + const world::Simulation &GetSimulation() const noexcept { return sim; } + void Name(const std::string &n) noexcept { name = n; } const std::string &Name() const noexcept { return name; } + Genome &GetGenome() noexcept { return genome; } + const Genome &GetGenome() const noexcept { return genome; } + + Genome::Properties &GetProperties() noexcept { return properties; } + const Genome::Properties &GetProperties() const noexcept { return properties; } + + const Genome::PropertySet &CurProps() const noexcept { return properties.props[cur_prop]; } + const Genome::PropertySet &NextProps() const noexcept { return properties.props[std::min(5, cur_prop + 1)]; } + + void BaseColor(const glm::dvec3 &c) noexcept { base_color = c; } + const glm::dvec3 &BaseColor() const noexcept { return base_color; } + + void HighlightColor(const glm::dvec3 &c) noexcept { highlight_color = c; } + glm::dvec4 HighlightColor() const noexcept; + + void Mass(double m) noexcept { mass = m; size = std::cbrt(mass / density); } + double Mass() const noexcept { return mass; } + void Ingest(int res, double amount) noexcept; + + void Density(double d) noexcept { density = d; size = std::cbrt(mass / density); } + double Density() const noexcept { return density; } + + double Size() const noexcept; + double Age() const noexcept; + std::string AgeName() const; + double AgeLerp(double from, double to) const noexcept; + // change of giving birth per tick + double Fertility() const noexcept; + void Health(double h) noexcept { health = h; } double Health() const noexcept { return health; } + void Hurt(double d) noexcept; + void Die() noexcept; + void OnDeath(Callback cb) noexcept { on_death = cb; } + void Remove() noexcept { removable = true; } + bool Removable() const noexcept { return removable; } + + Memory &GetMemory() noexcept { return memory; } + const Memory &GetMemory() const noexcept { return memory; } - void AddNeed(const Need &n) { needs.push_back(n); } - const std::vector &Needs() const noexcept { return needs; } + void AddNeed(std::unique_ptr &&n) { needs.emplace_back(std::move(n)); } + const std::vector> &Needs() const noexcept { return needs; } + + void AddGoal(std::unique_ptr &&); + const std::vector> &Goals() const noexcept { return goals; } void Tick(double dt); Situation &GetSituation() noexcept { return situation; } const Situation &GetSituation() const noexcept { return situation; } + Steering &GetSteering() noexcept { return steering; } + const Steering &GetSteering() const noexcept { return steering; } + glm::dmat4 LocalTransform() noexcept; void BuildVAO(); - void Draw(app::Assets &, graphics::Viewport &); + void Draw(graphics::Viewport &); + +private: + Situation::Derivative Step(const Situation::Derivative &ds, double dt) const noexcept; private: + world::Simulation ∼ std::string name; + + Genome genome; + Genome::Properties properties; + int cur_prop; + + glm::dvec3 base_color; + glm::dvec3 highlight_color; + + double mass; + double density; + double size; + + double birth; double health; - std::vector needs; + Callback on_death; + bool removable; + + Memory memory; + + std::vector> needs; + std::vector> goals; Situation situation; + Steering steering; struct Attributes { glm::vec3 position; @@ -72,7 +151,10 @@ private: }; /// put creature on planet and configure it to (hopefully) survive -void Spawn(Creature &, world::Planet &, app::Assets &); +void Spawn(Creature &, world::Planet &); + +/// split the creature into two +void Split(Creature &); } }