载入中...
搜索中...
未找到
Species.cpp
浏览该文件的文档.
1#include "growth/Species.h"
2
3#include "common/Diagnostic.h"
4#include "common/Value.h"
5
6#include <cctype>
7#include <cmath>
8
9namespace eve::growth {
10namespace {
11
12std::string lowerCopy(std::string_view text) {
13 std::string out(text);
14 for (char& c : out) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
15 return out;
16}
17
18const Value* objectField(const Value::Object& object, const char* key) {
19 auto it = object.find(key);
20 if (it == object.end()) return nullptr;
21 return &it->second;
22}
23
24template <class T>
25Result<T> fail(const Status& status) {
27}
28
29Result<void> readString(const Value::Object& object, const char* key, std::string& out, bool required) {
30 const Value* value = objectField(object, key);
31 if (!value) {
32 if (required) {
34 std::string(key) + " is required",
35 std::string("growth.species.") + key));
36 }
37 return Result<void>::success();
38 }
39 const auto* text = value->getIf<std::string>();
40 if (!text) {
42 std::string(key) + " must be a string",
43 std::string("growth.species.") + key));
44 }
45 out = *text;
46 return Result<void>::success();
47}
48
49Result<void> readDouble(const Value::Object& object, const char* key, double& out, bool required) {
50 const Value* value = objectField(object, key);
51 if (!value) {
52 if (required) {
54 std::string(key) + " is required",
55 std::string("growth.species.") + key));
56 }
57 return Result<void>::success();
58 }
59 if (const auto* number = value->getIf<double>()) {
60 out = *number;
61 return Result<void>::success();
62 }
63 if (const auto* integer = value->getIf<std::int64_t>()) {
64 out = static_cast<double>(*integer);
65 return Result<void>::success();
66 }
68 DiagnosticCode::InvalidArgument, std::string(key) + " must be a number", std::string("growth.species.") + key));
69}
70
71Result<void> readBool(const Value::Object& object, const char* key, bool& out) {
72 const Value* value = objectField(object, key);
73 if (!value) return Result<void>::success();
74 const auto* flag = value->getIf<bool>();
75 if (!flag) {
77 std::string(key) + " must be a bool",
78 std::string("growth.species.") + key));
79 }
80 out = *flag;
81 return Result<void>::success();
82}
83
84Result<void> readInt(const Value::Object& object, const char* key, int& out, bool required) {
85 const Value* value = objectField(object, key);
86 if (!value) {
87 if (required) {
89 std::string(key) + " is required",
90 std::string("growth.species.") + key));
91 }
92 return Result<void>::success();
93 }
94 if (const auto* integer = value->getIf<std::int64_t>()) {
95 out = static_cast<int>(*integer);
96 return Result<void>::success();
97 }
98 if (const auto* number = value->getIf<double>()) {
99 out = static_cast<int>(*number);
100 return Result<void>::success();
101 }
103 std::string(key) + " must be an integer",
104 std::string("growth.species.") + key));
105}
106
107Result<YieldDef> parseYield(const Value& value) {
108 const auto* object = value.getIf<Value::Object>();
109 if (!object) {
111 "yield entry must be an object", "growth.species.yield"));
112 }
113 YieldDef yield;
114 if (auto id = readString(*object, "itemId", yield.itemId, true); !id) return fail<YieldDef>(id.status());
115 if (auto min = readInt(*object, "minCount", yield.minCount, false); !min) return fail<YieldDef>(min.status());
116 yield.maxCount = yield.minCount;
117 if (auto max = readInt(*object, "maxCount", yield.maxCount, false); !max) return fail<YieldDef>(max.status());
118 if (yield.minCount < 0 || yield.maxCount < yield.minCount) {
120 DiagnosticCode::InvalidArgument, "yield counts must satisfy 0 <= min <= max", "growth.species.yield"));
121 }
122 return Result<YieldDef>::success(std::move(yield));
123}
124
125Result<std::vector<YieldDef>> parseYieldArray(const Value::Object& object, const char* key) {
126 std::vector<YieldDef> out;
127 const Value* value = objectField(object, key);
128 if (!value) return Result<std::vector<YieldDef>>::success(std::move(out));
129 const auto* array = value->getIf<Value::Array>();
130 if (!array) {
131 return Result<std::vector<YieldDef>>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,
132 std::string(key) + " must be an array",
133 std::string("growth.species.") + key));
134 }
135 for (const Value& entry : *array) {
136 auto parsed = parseYield(entry);
137 if (!parsed) return fail<std::vector<YieldDef>>(parsed.status());
138 out.push_back(std::move(parsed).takeValue());
139 }
140 return Result<std::vector<YieldDef>>::success(std::move(out));
141}
142
143Result<void> parseNeedsArray(const Value::Object& object, std::vector<NeedMeterDef>& out) {
144 const Value* value = objectField(object, "needs");
145 if (!value) return Result<void>::success();
146 const auto* array = value->getIf<Value::Array>();
147 if (!array) {
149 Diagnostic::error(DiagnosticCode::InvalidArgument, "needs must be an array", "growth.species.needs"));
150 }
151 for (const Value& entry : *array) {
152 const auto* needObject = entry.getIf<Value::Object>();
153 if (!needObject) {
155 "need entry must be an object", "growth.species.needs"));
156 }
157 NeedMeterDef need;
158 if (auto id = readString(*needObject, "id", need.id, true); !id) return id;
159 if (need.id.empty()) {
161 Diagnostic::error(DiagnosticCode::InvalidArgument, "need id is empty", "growth.species.needs.id"));
162 }
163 if (auto d = readDouble(*needObject, "drainPerDay", need.drainPerDay, false); !d) return d;
164 if (auto m = readDouble(*needObject, "minPermille", need.minPermille, false); !m) return m;
165 if (auto r = readBool(*needObject, "requiredForGrowth", need.requiredForGrowth); !r) return r;
166 if (auto l = readBool(*needObject, "lethalWhenEmpty", need.lethalWhenEmpty); !l) return l;
167 out.push_back(std::move(need));
168 }
169 return Result<void>::success();
170}
171
172Result<void> parseReproduction(const Value::Object& object, ReproductionDef& out, bool& sawReproductionObject,
173 bool& legacyCanBreed, double& legacyGestation, std::string& legacyOffspring) {
174 sawReproductionObject = false;
175 if (auto v = readBool(object, "canBreed", legacyCanBreed); !v) return v;
176 if (auto v = readDouble(object, "gestationDays", legacyGestation, false); !v) return v;
177 if (auto v = readString(object, "offspringSpeciesId", legacyOffspring, false); !v) return v;
178
179 const Value* value = objectField(object, "reproduction");
180 if (!value) return Result<void>::success();
181 const auto* reproObject = value->getIf<Value::Object>();
182 if (!reproObject) {
184 "reproduction must be an object", "growth.species.reproduction"));
185 }
186 sawReproductionObject = true;
187 std::string modeText = "none";
188 if (auto mode = readString(*reproObject, "mode", modeText, false); !mode) return mode;
189 auto parsedMode = parseReproductionMode(modeText);
190 if (!parsedMode) return Result<void>::failure(parsedMode.status());
191 out.mode = parsedMode.value();
192 if (auto v = readDouble(*reproObject, "gestationDays", out.gestationDays, false); !v) return v;
193 if (auto v = readDouble(*reproObject, "intervalDays", out.intervalDays, false); !v) return v;
194 if (auto v = readInt(*reproObject, "offspringCountMin", out.offspringCountMin, false); !v) return v;
195 out.offspringCountMax = out.offspringCountMin;
196 if (auto v = readInt(*reproObject, "offspringCountMax", out.offspringCountMax, false); !v) return v;
197 if (auto v = readString(*reproObject, "offspringSpeciesId", out.offspringSpeciesId, false); !v) return v;
198 if (auto v = readBool(*reproObject, "requiresPartner", out.requiresPartner); !v) return v;
199 if (auto v = readBool(*reproObject, "partnerMustSameSpecies", out.partnerMustSameSpecies); !v) return v;
200 if (auto v = readBool(*reproObject, "parentDiesOnBirth", out.parentDiesOnBirth); !v) return v;
201 if (auto v = readBool(*reproObject, "parentResetsStagesOnBirth", out.parentResetsStagesOnBirth); !v) return v;
202 if (out.offspringCountMin < 0 || out.offspringCountMax < out.offspringCountMin) {
204 "offspring counts must satisfy 0 <= min <= max",
205 "growth.species.reproduction"));
206 }
207 return Result<void>::success();
208}
209
210Result<SpeciesDef> parseSpeciesObject(const Value::Object& object) {
211 SpeciesDef def;
212 if (auto id = readString(object, "id", def.id, true); !id) return fail<SpeciesDef>(id.status());
213 if (auto name = readString(object, "displayName", def.displayName, false); !name)
214 return fail<SpeciesDef>(name.status());
215 if (def.displayName.empty()) def.displayName = def.id;
216
217 std::string kindText = "organism";
218 if (auto kind = readString(object, "kind", kindText, false); !kind) return fail<SpeciesDef>(kind.status());
219 def.kindId = kindText;
220 auto parsedKind = parseOrganismKind(kindText);
221 if (!parsedKind) return fail<SpeciesDef>(parsedKind.status());
222 def.kind = parsedKind.value();
223
224 const Value* stagesValue = objectField(object, "stages");
225 if (!stagesValue) {
227 Diagnostic::error(DiagnosticCode::InvalidArgument, "stages is required", "growth.species.stages"));
228 }
229 const auto* stages = stagesValue->getIf<Value::Array>();
230 if (!stages || stages->empty()) {
232 DiagnosticCode::InvalidArgument, "stages must be a non-empty array", "growth.species.stages"));
233 }
234 for (const Value& stageValue : *stages) {
235 const auto* stageObject = stageValue.getIf<Value::Object>();
236 if (!stageObject) {
238 Diagnostic::error(DiagnosticCode::InvalidArgument, "stage must be an object", "growth.species.stages"));
239 }
240 GrowthStageDef stage;
241 if (auto sid = readString(*stageObject, "id", stage.id, true); !sid) return fail<SpeciesDef>(sid.status());
242 if (auto dur = readDouble(*stageObject, "durationDays", stage.durationDays, true); !dur)
243 return fail<SpeciesDef>(dur.status());
244 if (!(stage.durationDays > 0.0) || !std::isfinite(stage.durationDays)) {
246 "durationDays must be finite and > 0",
247 "growth.species.stages.durationDays"));
248 }
249 def.stages.push_back(std::move(stage));
250 }
251
252 if (auto needs = parseNeedsArray(object, def.needs); !needs) return fail<SpeciesDef>(needs.status());
253
254 // Legacy Earth-farm fields — folded into needs by normalizeSpeciesDef when needs is empty.
255 double waterDrain = 0.0, foodDrain = 0.0, fertilityDrain = 0.0;
256 double minWater = 200.0, minFood = 200.0, minFertility = 100.0;
257 bool sawWater = objectField(object, "waterDrainPerDay") != nullptr;
258 bool sawFood = objectField(object, "foodDrainPerDay") != nullptr;
259 bool sawFert = objectField(object, "fertilityDrainPerDay") != nullptr;
260 if (auto v = readDouble(object, "waterDrainPerDay", waterDrain, false); !v) return fail<SpeciesDef>(v.status());
261 if (auto v = readDouble(object, "foodDrainPerDay", foodDrain, false); !v) return fail<SpeciesDef>(v.status());
262 if (auto v = readDouble(object, "fertilityDrainPerDay", fertilityDrain, false); !v)
263 return fail<SpeciesDef>(v.status());
264 if (auto v = readDouble(object, "minWaterPermille", minWater, false); !v) return fail<SpeciesDef>(v.status());
265 if (auto v = readDouble(object, "minFoodPermille", minFood, false); !v) return fail<SpeciesDef>(v.status());
266 if (auto v = readDouble(object, "minFertilityPermille", minFertility, false); !v)
267 return fail<SpeciesDef>(v.status());
268 if (def.needs.empty()) {
269 if (def.kind == OrganismKind::Animal || sawFood || sawWater) {
270 if (def.kind == OrganismKind::Animal || sawWater || !sawFert) {
271 def.needs.push_back(NeedMeterDef{"water", waterDrain > 0.0 ? waterDrain : 50.0, minWater, true, true});
272 }
273 if (def.kind == OrganismKind::Animal || sawFood) {
274 def.needs.push_back(NeedMeterDef{"food", foodDrain > 0.0 ? foodDrain : 50.0, minFood, true, true});
275 }
276 }
277 if (def.kind == OrganismKind::Plant || sawFert) {
278 if (def.needs.empty() || def.kind == OrganismKind::Plant) {
279 if (!def.hasNeed("water")) {
280 def.needs.push_back(
281 NeedMeterDef{"water", waterDrain > 0.0 ? waterDrain : 50.0, minWater, true, true});
282 }
283 def.needs.push_back(
284 NeedMeterDef{"fertility", fertilityDrain > 0.0 ? fertilityDrain : 20.0, minFertility, true, true});
285 }
286 }
287 if (def.needs.empty() && (sawWater || sawFood || sawFert)) {
288 if (sawWater)
289 def.needs.push_back(NeedMeterDef{"water", waterDrain, minWater, true, true});
290 if (sawFood) def.needs.push_back(NeedMeterDef{"food", foodDrain, minFood, true, true});
291 if (sawFert) def.needs.push_back(NeedMeterDef{"fertility", fertilityDrain, minFertility, true, true});
292 }
293 }
294
295 if (auto v = readDouble(object, "produceIntervalDays", def.produceIntervalDays, false); !v)
296 return fail<SpeciesDef>(v.status());
297 if (auto v = readDouble(object, "baseDiseaseResist", def.baseDiseaseResist, false); !v)
298 return fail<SpeciesDef>(v.status());
299
300 bool sawReproduction = false;
301 bool legacyCanBreed = false;
302 double legacyGestation = 0.0;
303 std::string legacyOffspring;
304 if (auto repro = parseReproduction(object, def.reproduction, sawReproduction, legacyCanBreed, legacyGestation,
305 legacyOffspring);
306 !repro)
307 return fail<SpeciesDef>(repro.status());
308 if (!sawReproduction) {
309 if (legacyCanBreed) {
310 def.reproduction.mode = ReproductionMode::PairGestation;
311 def.reproduction.gestationDays = legacyGestation;
312 def.reproduction.requiresPartner = true;
313 def.reproduction.offspringSpeciesId =
314 legacyOffspring.empty() ? def.id : legacyOffspring;
315 } else if (!legacyOffspring.empty()) {
316 def.reproduction.offspringSpeciesId = legacyOffspring;
317 }
318 } else if (def.reproduction.offspringSpeciesId.empty() && !legacyOffspring.empty()) {
319 def.reproduction.offspringSpeciesId = legacyOffspring;
320 }
321
322 if (const Value* season = objectField(object, "seasonMul")) {
323 const auto* array = season->getIf<Value::Array>();
324 if (!array || array->empty()) {
326 "seasonMul must be a non-empty number array",
327 "growth.species.seasonMul"));
328 }
329 def.seasonMul.clear();
330 def.seasonMul.reserve(array->size());
331 for (const Value& entry : *array) {
332 if (const auto* number = entry.getIf<double>()) {
333 def.seasonMul.push_back(*number);
334 } else if (const auto* integer = entry.getIf<std::int64_t>()) {
335 def.seasonMul.push_back(static_cast<double>(*integer));
336 } else {
338 DiagnosticCode::InvalidArgument, "seasonMul entries must be numbers", "growth.species.seasonMul"));
339 }
340 }
341 }
342
343 if (const Value* byId = objectField(object, "seasonMulById")) {
344 const auto* mapObject = byId->getIf<Value::Object>();
345 if (!mapObject) {
347 DiagnosticCode::InvalidArgument, "seasonMulById must be an object", "growth.species.seasonMulById"));
348 }
349 for (const auto& [seasonId, mulValue] : *mapObject) {
350 if (const auto* number = mulValue.getIf<double>()) {
351 def.seasonMulById[seasonId] = *number;
352 } else if (const auto* integer = mulValue.getIf<std::int64_t>()) {
353 def.seasonMulById[seasonId] = static_cast<double>(*integer);
354 } else {
356 "seasonMulById values must be numbers",
357 "growth.species.seasonMulById"));
358 }
359 }
360 }
361
362 auto harvest = parseYieldArray(object, "harvestYield");
363 if (!harvest) return fail<SpeciesDef>(harvest.status());
364 def.harvestYield = std::move(harvest).takeValue();
365
366 auto produce = parseYieldArray(object, "produceYield");
367 if (!produce) return fail<SpeciesDef>(produce.status());
368 def.produceYield = std::move(produce).takeValue();
369
370 if (const Value* diseases = objectField(object, "diseases")) {
371 const auto* array = diseases->getIf<Value::Array>();
372 if (!array) {
374 DiagnosticCode::InvalidArgument, "diseases must be an array", "growth.species.diseases"));
375 }
376 for (const Value& entry : *array) {
377 const auto* diseaseObject = entry.getIf<Value::Object>();
378 if (!diseaseObject) {
380 DiagnosticCode::InvalidArgument, "disease entry must be an object", "growth.species.diseases"));
381 }
382 DiseaseSusceptibility disease;
383 if (auto id = readString(*diseaseObject, "diseaseId", disease.diseaseId, true); !id)
384 return fail<SpeciesDef>(id.status());
385 if (auto c = readDouble(*diseaseObject, "chancePerDay", disease.chancePerDay, false); !c)
386 return fail<SpeciesDef>(c.status());
387 if (auto d = readDouble(*diseaseObject, "durationDays", disease.durationDays, false); !d)
388 return fail<SpeciesDef>(d.status());
389 if (auto g = readDouble(*diseaseObject, "growthMul", disease.growthMul, false); !g)
390 return fail<SpeciesDef>(g.status());
391 def.diseases.push_back(std::move(disease));
392 }
393 }
394
395 if (auto ok = normalizeSpeciesDef(def); !ok) return fail<SpeciesDef>(ok.status());
396 return Result<SpeciesDef>::success(std::move(def));
397}
398
399} // namespace
400
402 const std::string lower = lowerCopy(text);
403 if (lower == "plant") return Result<OrganismKind>::success(OrganismKind::Plant);
404 if (lower == "animal") return Result<OrganismKind>::success(OrganismKind::Animal);
405 if (lower == "custom" || lower == "organism" || lower.empty())
407 // Any other tag is a valid custom lifeform id (xeno.crystal, slime, …).
409}
410
412 const std::string lower = lowerCopy(text);
413 if (lower == "none" || lower.empty()) return Result<ReproductionMode>::success(ReproductionMode::None);
414 if (lower == "pair_gestation" || lower == "pairgestation" || lower == "gestation")
416 if (lower == "self_bud" || lower == "selfbud" || lower == "bud")
418 if (lower == "fission" || lower == "split")
420 if (lower == "spore_burst" || lower == "sporeburst" || lower == "spore")
424 "reproduction.mode must be none|pair_gestation|self_bud|fission|spore_burst",
425 "growth.species.reproduction.mode"));
426}
427
429 if (def.id.empty()) {
431 Diagnostic::error(DiagnosticCode::InvalidArgument, "species id is empty", "growth.species.id"));
432 }
433 if (def.kindId.empty()) def.kindId = "organism";
434 const std::string lowerKind = lowerCopy(def.kindId);
435 if (lowerKind == "plant")
437 else if (lowerKind == "animal")
439 else
441
444 def.reproduction.requiresPartner = true;
445 if (!(def.reproduction.gestationDays > 0.0)) {
447 "pair_gestation requires gestationDays > 0",
448 "growth.species.reproduction.gestationDays"));
449 }
450 }
453 if (!(def.reproduction.intervalDays > 0.0)) {
455 "interval reproduction requires intervalDays > 0",
456 "growth.species.reproduction.intervalDays"));
457 }
458 }
459 if (def.seasonMul.empty()) def.seasonMul = {1.0, 1.0, 1.0, 1.0};
460
461 // Deduplicate need ids.
462 std::unordered_map<std::string, int> seen;
463 for (const NeedMeterDef& need : def.needs) {
464 if (need.id.empty()) {
466 Diagnostic::error(DiagnosticCode::InvalidArgument, "need id is empty", "growth.species.needs"));
467 }
468 if (++seen[need.id] > 1) {
470 "duplicate need id: " + need.id, "growth.species.needs"));
471 }
472 }
473 return Result<void>::success();
474}
475
476std::unordered_map<std::string, SpeciesDef>& SpeciesRegistry::table() {
477 static std::unordered_map<std::string, SpeciesDef> instance;
478 return instance;
479}
480
482 SpeciesDef copy = def;
483 if (auto ok = normalizeSpeciesDef(copy); !ok) return ok;
484 if (copy.stages.empty()) {
486 "species requires at least one stage", "growth.species.stages"));
487 }
488 for (const GrowthStageDef& stage : copy.stages) {
489 if (stage.id.empty() || !(stage.durationDays > 0.0) || !std::isfinite(stage.durationDays)) {
491 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid growth stage", "growth.species.stages"));
492 }
493 }
494 // C++ authors may still fill only legacy-shaped fields via helpers; synthesize needs if empty.
495 if (copy.needs.empty()) {
496 if (copy.kind == OrganismKind::Animal) {
497 copy.needs.push_back(NeedMeterDef{"water", 50.0, 100.0, true, true});
498 copy.needs.push_back(NeedMeterDef{"food", 50.0, 100.0, true, true});
499 } else if (copy.kind == OrganismKind::Plant) {
500 copy.needs.push_back(NeedMeterDef{"water", 50.0, 100.0, true, true});
501 copy.needs.push_back(NeedMeterDef{"fertility", 20.0, 50.0, true, true});
502 }
503 }
504 table()[copy.id] = std::move(copy);
505 return Result<void>::success();
506}
507
509 auto parsed = Value::fromJson(json);
510 if (!parsed) return fail<int>(parsed.status());
511 Value root = std::move(parsed).takeValue();
512
513 int registered = 0;
514 if (const auto* array = root.getIf<Value::Array>()) {
515 for (const Value& entry : *array) {
516 const auto* object = entry.getIf<Value::Object>();
517 if (!object) {
519 DiagnosticCode::InvalidArgument, "species array entries must be objects", "growth.species"));
520 }
521 auto def = parseSpeciesObject(*object);
522 if (!def) return fail<int>(def.status());
523 if (auto ok = registerSpecies(def.value()); !ok) return fail<int>(ok.status());
524 ++registered;
525 }
526 return Result<int>::success(registered);
527 }
528
529 const auto* object = root.getIf<Value::Object>();
530 if (!object) {
532 "species JSON must be an object or array", "growth.species"));
533 }
534 auto def = parseSpeciesObject(*object);
535 if (!def) return fail<int>(def.status());
536 if (auto ok = registerSpecies(def.value()); !ok) return fail<int>(ok.status());
537 return Result<int>::success(1);
538}
539
540const SpeciesDef* SpeciesRegistry::find(const std::string& id) {
541 auto it = table().find(id);
542 if (it == table().end()) return nullptr;
543 return &it->second;
544}
545
546int SpeciesRegistry::count() { return static_cast<int>(table().size()); }
547
548bool SpeciesRegistry::has(const std::string& id) { return find(id) != nullptr; }
549
550void SpeciesRegistry::clear() { table().clear(); }
551
552} // namespace eve::growth
double m[16]
int root
Definition AnimSmr.cpp:119
Stable, structured diagnostics shared by engine modules.
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
tensor::Graph g
Definition GpuGraph.cpp:7
wgpu::PopErrorScopeStatus status
double r
float v
std::int32_t c
bool required
std::string id
Object::Ptr value
float d
double number
std::string text
ScriptStructure out
size_t end
std::string kind
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
static int count()
Number of registered species.
Definition Species.cpp:546
static const SpeciesDef * find(const std::string &id)
Looks up a species; nullptr when missing. @ownership Borrowed from the process-wide registry; caller ...
Definition Species.cpp:540
static Result< void > registerSpecies(const SpeciesDef &def)
Registers or replaces a species after normalizing legacy fields. Empty id fails.
Definition Species.cpp:481
static void clear()
Clears the table (tests).
Definition Species.cpp:550
static Result< int > loadFromJson(std::string_view json)
Parses a JSON object or array of species and registers each.
Definition Species.cpp:508
static bool has(const std::string &id)
True when id is registered.
Definition Species.cpp:548
Result< T > fail(std::string message, DiagnosticCode code=DiagnosticCode::InvalidArgument)
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
Result< OrganismKind > parseOrganismKind(std::string_view text)
Parses kind text: plant/animal/custom or any free-form tag → Custom.
Definition Species.cpp:401
@ 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
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Result< bool > readBool(const Value::Object &object, std::string_view name)
Reads a required boolean.
One authored growth stage for a species.
Definition Species.h:21
Named vital meter (water, radiation, ether, …) — not fixed to Earth biology.
Definition Species.h:35
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
std::vector< GrowthStageDef > stages
Definition Species.h:88
ReproductionDef reproduction
Definition Species.h:103
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
std::vector< double > seasonMul
Growth multipliers indexed by calendar season order.
Definition Species.h:95