X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fcreature%2FCreature.hpp;h=6c918270e540594bc18d0e19bd0240f80af50c80;hp=2a40d510407e4ff791a3e16c3d9b718066ca2d93;hb=42db7d9d2286e50896ad172e2e4a8fbe65c8a4a9;hpb=8f6530c75730f901efd6708e4fde7e68a178adf1 diff --git a/src/creature/Creature.hpp b/src/creature/Creature.hpp index 2a40d51..6c91827 100644 --- a/src/creature/Creature.hpp +++ b/src/creature/Creature.hpp @@ -30,6 +30,9 @@ namespace creature { class Creature { +public: + using Callback = std::function; + public: explicit Creature(world::Simulation &); ~Creature(); @@ -50,15 +53,28 @@ public: Genome &GetGenome() noexcept { return genome; } const Genome &GetGenome() const noexcept { return genome; } - void Mass(double m) noexcept { mass = m; } + Genome::Properties &GetProperties() noexcept { return properties; } + const Genome::Properties &GetProperties() const noexcept { return properties; } + + void Mass(double m) noexcept { mass = m; size = std::cbrt(mass / density); } double Mass() const noexcept { return mass; } + void Grow(double amount) noexcept; - void Size(double s) noexcept { size = s; } - double Size() const noexcept { return size; } + 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; + // 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; } void AddNeed(std::unique_ptr &&n) { needs.emplace_back(std::move(n)); } const std::vector> &Needs() const noexcept { return needs; } @@ -76,22 +92,28 @@ public: void Velocity(const glm::dvec3 &v) noexcept { vel = v; } const glm::dvec3 &Velocity() const noexcept { return vel; } - bool Moving() const noexcept { return glm::length2(vel) < 0.000001; } + bool Moving() const noexcept { return glm::length2(vel) < 0.00000001; } glm::dmat4 LocalTransform() noexcept; void BuildVAO(); - void Draw(app::Assets &, graphics::Viewport &); + void Draw(graphics::Viewport &); private: world::Simulation ∼ std::string name; Genome genome; + Genome::Properties properties; double mass; + double density; double size; + + double birth; double health; + Callback on_death; + bool removable; std::vector> needs; std::vector> goals; @@ -111,7 +133,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 &); } }