载入中...
搜索中...
未找到
Organism.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/ECS.h"
5#include "common/Result.h"
6#include "growth/Species.h"
7
8#include <cstdint>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13namespace eve::growth {
14
15class GrowthWorld;
16
19 std::string itemId;
20 int count = 0;
21};
22
29class EVENGINE_API_FOUNDATION Organism : public ecs::Entity {
30public:
31 ENTITY(Organism, ecs::Entity)
32
33 void release() override { ecs::DestroyEntity(this); }
34
36 struct Growth {
37 std::string speciesId;
38 std::string kindId;
39 OrganismKind kind = OrganismKind::Custom;
40 int stageIndex = 0;
41 double stageProgressDays = 0.0;
42 bool mature = false;
43 bool dead = false;
44 bool harvested = false;
45 };
46
48 struct VitalNeeds {
49 std::unordered_map<std::string, double> meters;
50 };
51
53 struct Health {
54 std::string activeDiseaseId;
55 double diseaseDaysLeft = 0.0;
56 double diseaseGrowthMul = 1.0;
57 };
58
60 struct Reproduction {
61 bool pregnant = false;
62 double gestationProgressDays = 0.0;
63 double daysSinceReproduce = 0.0;
64 std::uint64_t partnerStableId = 0;
65 };
66
68 struct Produce {
69 double daysSinceProduce = 0.0;
70 };
71
72 COMPONENT(Growth, growth)
73 COMPONENT(VitalNeeds, vitalNeeds)
74 COMPONENT(Health, health)
75 COMPONENT(Reproduction, reproduction)
76 COMPONENT(Produce, produce)
77
78
83 [[nodiscard]] static Result<Organism*> createOrganism(const std::string& speciesId);
84
86 [[nodiscard]] static const std::vector<Organism*>& liveOrganisms();
87
88 [[nodiscard]] const std::string& speciesId();
89 [[nodiscard]] const std::string& kindId();
90 [[nodiscard]] OrganismKind kind();
91 [[nodiscard]] int stageIndex();
92 [[nodiscard]] std::string stageId();
93 [[nodiscard]] double stageProgressDays();
94 [[nodiscard]] bool isMature();
95 [[nodiscard]] bool isDead();
96 [[nodiscard]] bool isHarvested();
97 [[nodiscard]] bool isDiseased();
98 [[nodiscard]] bool isPregnant();
99 [[nodiscard]] std::string diseaseId();
100
102 [[nodiscard]] double waterPermille();
103 [[nodiscard]] double foodPermille();
104 [[nodiscard]] double fertilityPermille();
106 [[nodiscard]] double needPermille(const std::string& needId);
107
112 [[nodiscard]] Result<void> refillNeed(const std::string& needId, double permille);
117 [[nodiscard]] Result<void> waterBy(double permille);
122 [[nodiscard]] Result<void> feed(double permille);
127 [[nodiscard]] Result<void> fertilize(double permille);
128
133 [[nodiscard]] Result<std::vector<YieldReceipt>> harvest();
134
136 [[nodiscard]] std::uint64_t stableId() const noexcept;
137
139 void destroy();
140};
141
142} // namespace eve::growth
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
void(* destroy)(void *)
Move-only, checked operation results for the common layer.
std::string kind
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Growth short-root entity for any configured lifeform.
Definition Organism.h:29
OrganismKind
Optional Earth-biology label; custom lifeforms use Custom + free-form kindId.
Definition Species.h:18
Species binding and stage progress.
Definition Organism.h:36
Disease state; empty diseaseId means healthy.
Definition Organism.h:53
Periodic produce timer (milk, crystals, spores as yield — not offspring).
Definition Organism.h:68
Reproduction progress for any authored mode.
Definition Organism.h:60
Named need meters in permille [0, 1000], keyed by species need id.
Definition Organism.h:48
std::unordered_map< std::string, double > meters
Definition Organism.h:49
One harvested or produced item line (no inventory dependency).
Definition Organism.h:18