载入中...
搜索中...
未找到
Species.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
5
6#include <cstdint>
7#include <string>
8#include <string_view>
9#include <unordered_map>
10#include <vector>
11
12namespace eve::growth {
13
18enum class OrganismKind : std::uint8_t { Plant = 0, Animal = 1, Custom = 2 };
19
22 std::string id;
24 double durationDays = 1.0;
25};
26
28struct YieldDef {
29 std::string itemId;
30 int minCount = 1;
31 int maxCount = 1;
32};
33
36 std::string id;
37 double drainPerDay = 0.0;
38 double minPermille = 0.0;
39 bool requiredForGrowth = true;
40 bool lethalWhenEmpty = false;
41};
42
44enum class ReproductionMode : std::uint8_t {
45 None = 0,
46 PairGestation = 1,
47 SelfBud = 2,
48 Fission = 3,
49 SporeBurst = 4,
50};
51
65
68 std::string diseaseId;
69 double chancePerDay = 0.0;
71 double durationDays = 3.0;
73 double growthMul = 0.5;
74};
75
81struct SpeciesDef {
82 std::string id;
83 std::string displayName;
85 std::string kindId = "organism";
88 std::vector<GrowthStageDef> stages;
89 std::vector<NeedMeterDef> needs;
90
95 std::vector<double> seasonMul = {1.0, 1.0, 1.0, 1.0};
97 std::unordered_map<std::string, double> seasonMulById;
98
99 std::vector<YieldDef> harvestYield;
100 std::vector<YieldDef> produceYield;
102
104
105 std::vector<DiseaseSusceptibility> diseases;
106 double baseDiseaseResist = 0.5;
107
112 [[nodiscard]] bool hasNeed(std::string_view needId) const { return findNeed(needId) != nullptr; }
120 [[nodiscard]] const NeedMeterDef* findNeed(std::string_view needId) const {
121 for (const NeedMeterDef& need : needs) {
122 if (need.id == needId) return &need;
123 }
124 return nullptr;
125 }
126};
127
130public:
132 [[nodiscard]] static Result<void> registerSpecies(const SpeciesDef& def);
134 [[nodiscard]] static Result<int> loadFromJson(std::string_view json);
141 [[nodiscard]] static const SpeciesDef* find(const std::string& id);
143 [[nodiscard]] static int count();
145 [[nodiscard]] static bool has(const std::string& id);
147 static void clear();
148
149private:
150 static std::unordered_map<std::string, SpeciesDef>& table();
151};
152
162
163} // namespace eve::growth
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
Move-only, checked operation results for the common layer.
std::string text
int count
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Process-wide species table used by GrowthWorld and Organism factories.
Definition Species.h:129
Result< OrganismKind > parseOrganismKind(std::string_view text)
Parses kind text: plant/animal/custom or any free-form tag → Custom.
Definition Species.cpp:401
ReproductionMode
Authored reproduction strategy — pair gestation is only one mode.
Definition Species.h:44
@ PairGestation
Two parents; carrier gestates then spawns offspring.
@ Fission
Single parent splits; optional parent death or stage reset.
@ SporeBurst
Periodic offspring bursts without a partner.
@ SelfBud
Single mature parent; interval then spawn (alien budding).
Result< void > normalizeSpeciesDef(SpeciesDef &def)
Fills needs/reproduction from legacy plant/animal fields when authors omit the new schema....
Definition Species.cpp:428
Result< ReproductionMode > parseReproductionMode(std::string_view text)
Parses reproduction.mode text.
Definition Species.cpp:411
OrganismKind
Optional Earth-biology label; custom lifeforms use Custom + free-form kindId.
Definition Species.h:18
Per-day infection chance while the organism is stressed.
Definition Species.h:67
double durationDays
Duration of the disease in simulation days when contracted.
Definition Species.h:71
double growthMul
Growth-rate multiplier while diseased (typically < 1).
Definition Species.h:73
One authored growth stage for a species.
Definition Species.h:21
double durationDays
Baseline duration of this stage in simulation days.
Definition Species.h:24
Named vital meter (water, radiation, ether, …) — not fixed to Earth biology.
Definition Species.h:35
double minPermille
Below this: stress + optional growth stall.
Definition Species.h:38
bool requiredForGrowth
When true, meter below min stalls growth.
Definition Species.h:39
double drainPerDay
Permille (0..1000) drained per sim day.
Definition Species.h:37
Species reproduction parameters selected by ReproductionMode.
Definition Species.h:53
double intervalDays
SelfBud / Fission / SporeBurst cooldown.
Definition Species.h:56
std::string offspringSpeciesId
Definition Species.h:59
double gestationDays
PairGestation only.
Definition Species.h:55
ReproductionMode mode
Definition Species.h:54
Static species definition — fully data-driven life cycle.
Definition Species.h:81
std::vector< NeedMeterDef > needs
Definition Species.h:89
const NeedMeterDef * findNeed(std::string_view needId) const
Looks up a need meter; nullptr when absent. @ownership Borrowed from this SpeciesDef; caller must not...
Definition Species.h:120
std::vector< GrowthStageDef > stages
Definition Species.h:88
std::vector< YieldDef > harvestYield
Definition Species.h:99
ReproductionDef reproduction
Definition Species.h:103
std::vector< YieldDef > produceYield
Definition Species.h:100
std::unordered_map< std::string, double > seasonMulById
Optional multipliers keyed by calendar season id (preferred when set).
Definition Species.h:97
OrganismKind kind
Convenience label derived from kindId when plant/animal; else Custom.
Definition Species.h:87
std::string kindId
Free-form lifeform tag (plant, animal, xeno.crystal, …).
Definition Species.h:85
bool hasNeed(std::string_view needId) const
True when the species declares a need meter with this id.
Definition Species.h:112
std::string displayName
Definition Species.h:83
std::vector< double > seasonMul
Growth multipliers indexed by calendar season order.
Definition Species.h:95
std::vector< DiseaseSusceptibility > diseases
Definition Species.h:105
One item emitted by harvest or periodic produce.
Definition Species.h:28
std::string itemId
Definition Species.h:29