载入中...
搜索中...
未找到
Species.cpp
浏览该文件的文档.
29Result<void> readString(const Value::Object& object, const char* key, std::string& out, bool required) {
49Result<void> readDouble(const Value::Object& object, const char* key, double& out, bool required) {
68 DiagnosticCode::InvalidArgument, std::string(key) + " must be a number", std::string("growth.species.") + key));
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());
117 if (auto max = readInt(*object, "maxCount", yield.maxCount, false); !max) return fail<YieldDef>(max.status());
120 DiagnosticCode::InvalidArgument, "yield counts must satisfy 0 <= min <= max", "growth.species.yield"));
131 return Result<std::vector<YieldDef>>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,
149 Diagnostic::error(DiagnosticCode::InvalidArgument, "needs must be an array", "growth.species.needs"));
161 Diagnostic::error(DiagnosticCode::InvalidArgument, "need id is empty", "growth.species.needs.id"));
172Result<void> parseReproduction(const Value::Object& object, ReproductionDef& out, bool& sawReproductionObject,
194 if (auto v = readInt(*reproObject, "offspringCountMin", out.offspringCountMin, false); !v) return v;
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;
199 if (auto v = readBool(*reproObject, "partnerMustSameSpecies", out.partnerMustSameSpecies); !v) return v;
201 if (auto v = readBool(*reproObject, "parentResetsStagesOnBirth", out.parentResetsStagesOnBirth); !v) return v;
212 if (auto id = readString(object, "id", def.id, true); !id) return fail<SpeciesDef>(id.status());
218 if (auto kind = readString(object, "kind", kindText, false); !kind) return fail<SpeciesDef>(kind.status());
227 Diagnostic::error(DiagnosticCode::InvalidArgument, "stages is required", "growth.species.stages"));
238 Diagnostic::error(DiagnosticCode::InvalidArgument, "stage must be an object", "growth.species.stages"));
241 if (auto sid = readString(*stageObject, "id", stage.id, true); !sid) return fail<SpeciesDef>(sid.status());
252 if (auto needs = parseNeedsArray(object, def.needs); !needs) return fail<SpeciesDef>(needs.status());
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());
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());
271 def.needs.push_back(NeedMeterDef{"water", waterDrain > 0.0 ? waterDrain : 50.0, minWater, true, true});
274 def.needs.push_back(NeedMeterDef{"food", foodDrain > 0.0 ? foodDrain : 50.0, minFood, true, true});
284 NeedMeterDef{"fertility", fertilityDrain > 0.0 ? fertilityDrain : 20.0, minFertility, true, true});
291 if (sawFert) def.needs.push_back(NeedMeterDef{"fertility", fertilityDrain, minFertility, true, true});
304 if (auto repro = parseReproduction(object, def.reproduction, sawReproduction, legacyCanBreed, legacyGestation,
338 DiagnosticCode::InvalidArgument, "seasonMul entries must be numbers", "growth.species.seasonMul"));
347 DiagnosticCode::InvalidArgument, "seasonMulById must be an object", "growth.species.seasonMulById"));
380 DiagnosticCode::InvalidArgument, "disease entry must be an object", "growth.species.diseases"));
413 if (lower == "none" || lower.empty()) return Result<ReproductionMode>::success(ReproductionMode::None);
431 Diagnostic::error(DiagnosticCode::InvalidArgument, "species id is empty", "growth.species.id"));
451 if (def.reproduction.mode == ReproductionMode::SelfBud || def.reproduction.mode == ReproductionMode::Fission ||
466 Diagnostic::error(DiagnosticCode::InvalidArgument, "need id is empty", "growth.species.needs"));
491 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid growth stage", "growth.species.stages"));
Stable, structured diagnostics shared by engine modules.
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.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
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 Result< int > loadFromJson(std::string_view json)
Parses a JSON object or array of species and registers each.
Definition Species.cpp:508
Result< T > fail(std::string message, DiagnosticCode code=DiagnosticCode::InvalidArgument)
Definition BuildingAssemblyInternal.h:35
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
Definition Growth.cpp:11
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.
@ 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)
Definition ArtifactProvider.cpp:21
Result< bool > readBool(const Value::Object &object, std::string_view name)
Reads a required boolean.
Definition WorldSnapshotParsing.cpp:75
@ InvalidArgument
Definition Container.h:602
Named vital meter (water, radiation, ether, …) — not fixed to Earth biology.
Definition Species.h:35
std::string offspringSpeciesId
Definition Species.h:59
Static species definition — fully data-driven life cycle.
Definition Species.h:81
OrganismKind kind
Convenience label derived from kindId when plant/animal; else Custom.
Definition Species.h:87
std::vector< double > seasonMul
Growth multipliers indexed by calendar season order.
Definition Species.h:95