载入中...
搜索中...
未找到
RTSAction.cpp
浏览该文件的文档.
1#include "rts/RTSAction.h"
2#include <algorithm>
3#include <cmath>
4#include <limits>
5#include <optional>
6#include <string>
7#include <utility>
8#include <vector>
9#include "action/Action.h"
10#include "common/Value.h"
11#include "rts/RTSArchetype.h"
12#include "weapon/WeaponTypes.h"
13
14// RTSAction.cpp
15namespace eve::rts {
16namespace {
17
18bool sameHandle(const ecs::EntityHandle& left, const ecs::EntityHandle& right) {
19 return left.table == right.table && left.type == right.type && left.id == right.id &&
20 left.generation == right.generation;
21}
22
23bool terminal(action::ActionPhase phase) {
26}
27
28std::optional<LogicalId> actionIdFor(const OrderRecord& order) {
29 if (!order.definitionId.empty()) return LogicalId::parse(order.definitionId);
30 return LogicalId::fromParts("rts", "command." + std::string(orderKindName(order.kind)));
31}
32
33} // namespace
34
36 struct Pending {
37 ecs::EntityHandle unit;
38 std::string orderId;
40 };
41
42 explicit Impl(action::ActionRuntime& runtimeValue) : runtime(runtimeValue) {}
43
45 std::vector<Pending> pending;
46};
47
48ActionAdapter::ActionAdapter(action::ActionRuntime& runtime) : impl_(std::make_unique<Impl>(runtime)) {}
49
51
52void ActionAdapter::clear() noexcept {
53 if (impl_) impl_->pending.clear();
54}
55
57 if (step.delta.nanoseconds() < 0)
59 DiagnosticCode::InvalidArgument, "RTS action step delta must be non-negative", "step.delta"));
60 if (!impl_)
62 Diagnostic::error(DiagnosticCode::InvariantViolation, "RTS action adapter is not initialized", "adapter"));
63
64 const ecs::EntityHandle unitHandle = ecs::handle_of(&unit);
65 auto pendingForUnit =
66 std::find_if(impl_->pending.begin(), impl_->pending.end(),
67 [&unitHandle](const Impl::Pending& pending) { return sameHandle(pending.unit, unitHandle); });
68
69 if (pendingForUnit != impl_->pending.end() && pendingForUnit->orderId != order.id) {
70 const auto* oldExecution = impl_->runtime.find(pendingForUnit->execution);
71 if (oldExecution != nullptr && !terminal(oldExecution->phase())) {
72 auto cancelled = impl_->runtime.cancel(pendingForUnit->execution, step.tick);
73 if (!cancelled) cancelled.ignore("RTS order replacement could not cancel old action");
74 }
75 impl_->pending.erase(pendingForUnit);
76 pendingForUnit = impl_->pending.end();
77 }
78
80 if (pendingForUnit == impl_->pending.end()) {
81 const auto logicalId = actionIdFor(order);
82 if (!logicalId)
84 Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS order definition is not a valid LogicalId",
85 "order.definitionId"));
86
87 action::ActionDefinition definition;
88 definition.id = *logicalId;
89
91 request.actionId = definition.id;
92 request.source = unitHandle;
93 request.requestedTick = step.tick;
94
95 auto submitted = impl_->runtime.submit(std::move(definition), std::move(request));
96 if (!submitted) return Result<ActionExecutionResult>::failure(submitted.status());
97 executionId = std::move(submitted).takeValue();
98 impl_->pending.push_back({unitHandle, order.id, executionId});
99 } else {
100 executionId = pendingForUnit->execution;
101 }
102
103 auto advanced = impl_->runtime.advance(executionId, step.tick, step.delta);
104 if (!advanced) {
105 impl_->pending.erase(
106 std::remove_if(impl_->pending.begin(), impl_->pending.end(),
107 [&executionId](const Impl::Pending& pending) { return pending.execution == executionId; }),
108 impl_->pending.end());
109 return Result<ActionExecutionResult>::failure(advanced.status());
110 }
111
112 const auto summary = std::move(advanced).takeValue();
113 bool completed = summary.phase == action::ActionPhase::Completed;
114 if (order.kind == OrderKind::Move && !unit.motion()->arrived) completed = false;
115 if (completed) {
116 impl_->pending.erase(
117 std::remove_if(impl_->pending.begin(), impl_->pending.end(),
118 [&executionId](const Impl::Pending& pending) { return pending.execution == executionId; }),
119 impl_->pending.end());
120 }
121
125}
126
127} // namespace eve::rts
128
129// RTSArchetype.cpp
130namespace eve::rts {
131namespace {
132
133const Value* field(const Value::Object& object, std::string_view name) {
134 const auto found = object.find(std::string(name));
135 return found == object.end() ? nullptr : &found->second;
136}
137
138Result<Value::Object> definitionObject(definitions::DefinitionRegistry& registry, std::string_view type,
139 const LogicalId& id) {
140 if (!id.isValid() || id.name().empty())
142 Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS root requires a logical definition",
143 std::string(type) + ".definition", {}, "rts.archetype"));
144 auto resolved = registry.resolve(std::string(type), std::string(id.name()));
145 if (!resolved) return Result<Value::Object>::failure(resolved.status());
146 auto parsed = Value::fromJson(resolved.value().get().json);
147 if (!parsed) return Result<Value::Object>::failure(parsed.status());
148 auto value = std::move(parsed).takeValue();
149 const auto* object = value.getIf<Value::Object>();
150 if (object == nullptr)
152 "RTS definition must be a JSON object",
153 std::string(type) + ".json", {}, "rts.archetype"));
154 return Result<Value::Object>::success(*object);
155}
156
157Result<float> number(const Value::Object& object, std::string_view name, float fallback,
158 float minimum = -std::numeric_limits<float>::max()) {
159 const Value* source = field(object, name);
160 double value = fallback;
161 if (source != nullptr) {
162 if (const auto* real = source->getIf<double>())
163 value = *real;
164 else if (const auto* integer = source->getIf<std::int64_t>())
165 value = static_cast<double>(*integer);
166 else
168 "RTS archetype numeric field must be a number",
169 std::string(name), {}, "rts.archetype"));
170 }
171 if (!std::isfinite(value) || value < minimum || value > std::numeric_limits<float>::max())
173 "RTS archetype numeric field is outside its valid range",
174 std::string(name), {}, "rts.archetype"));
175 return Result<float>::success(static_cast<float>(value));
176}
177
178Result<int> integer(const Value::Object& object, std::string_view name, int fallback, int minimum = 0) {
179 const Value* source = field(object, name);
180 std::int64_t value = fallback;
181 if (source != nullptr) {
182 if (const auto* exact = source->getIf<std::int64_t>())
183 value = *exact;
184 else
186 "RTS archetype integer field must be an integer",
187 std::string(name), {}, "rts.archetype"));
188 }
189 if (value < minimum || value > std::numeric_limits<int>::max())
191 "RTS archetype integer field is outside its valid range",
192 std::string(name), {}, "rts.archetype"));
193 return Result<int>::success(static_cast<int>(value));
194}
195
196Result<bool> boolean(const Value::Object& object, std::string_view name, bool fallback) {
197 const Value* source = field(object, name);
198 if (source == nullptr) return Result<bool>::success(fallback);
199 const auto* value = source->getIf<bool>();
200 if (value == nullptr)
202 "RTS archetype boolean field must be boolean", std::string(name),
203 {}, "rts.archetype"));
205}
206
207Result<std::string> text(const Value::Object& object, std::string_view name, std::string fallback = {}) {
208 const Value* source = field(object, name);
209 if (source == nullptr) return Result<std::string>::success(std::move(fallback));
210 const auto* value = source->getIf<std::string>();
211 if (value == nullptr)
213 "RTS archetype text field must be a string",
214 std::string(name), {}, "rts.archetype"));
216}
217
218Result<TagSet> tags(const Value::Object& object, std::string_view name) {
219 TagSet result;
220 const Value* source = field(object, name);
221 if (source == nullptr) return Result<TagSet>::success(std::move(result));
222 const auto* array = source->getIf<Value::Array>();
223 if (array == nullptr)
225 "RTS archetype tags must be an array", std::string(name), {},
226 "rts.archetype"));
227 for (std::size_t index = 0; index < array->size(); ++index) {
228 const auto* value = (*array)[index].getIf<std::string>();
229 if (value == nullptr)
231 Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS archetype tag must be a string",
232 std::string(name) + "[" + std::to_string(index) + "]", {}, "rts.archetype"));
233 auto added = result.add(*value);
234 if (!added) return Result<TagSet>::failure(added.status());
235 }
236 return Result<TagSet>::success(std::move(result));
237}
238
239} // namespace
240
242 const ArchetypeWeaponFactory& weaponFactory) {
243 auto objectResult = definitionObject(registry, "unit", unit.definition()->id);
244 if (!objectResult) return Result<void>::failure(objectResult.status());
245 const auto object = std::move(objectResult).takeValue();
246
247 auto health = number(object, "health", 1.0f, 0.0f);
248 auto speed = number(object, "speed", 1.0f, 0.0f);
249 auto radius = number(object, "radius", 0.5f, 0.0f);
250 auto sight = number(object, "sightRange", 0.0f, 0.0f);
251 auto detection = number(object, "detectionRange", 0.0f, 0.0f);
252 auto radar = number(object, "radarRange", 0.0f, 0.0f);
253 auto jamming = number(object, "jammingRange", 0.0f, 0.0f);
254 auto range = number(object, "attackRange", 0.0f, 0.0f);
255 auto role = text(object, "role");
256 auto weaponType = text(object, "weaponType");
257 auto targetTags = tags(object, "targetTags");
258 if (!health || !speed || !radius || !sight || !detection || !radar || !jamming || !range || !role || !weaponType ||
259 !targetTags)
261 "RTS unit definition contains an invalid core field", "unit", {},
262 "rts.archetype"));
263
264 auto capacity = number(object, "cargoCapacity", role.value() == "worker" ? 10.0f : 0.0f, 0.0f);
265 auto gatherResource = text(object, "gatherResource", role.value() == "worker" ? "minerals" : "");
266 if (!gatherResource) return Result<void>::failure(gatherResource.status());
267 if (!gatherResource.value().empty()) {
268 auto validResource = resource::ResourceId::parse(gatherResource.value());
269 if (!validResource) return Result<void>::failure(validResource.status());
270 }
271 auto gather = number(object, "gatherRate", role.value() == "worker" ? 5.0f : 0.0f, 0.0f);
272 auto buildRate = number(object, "buildRate", 1.0f, 0.0f);
273 auto repairRate = number(object, "repairRate", 0.0f, 0.0f);
274 auto captureRate = number(object, "captureRate", 0.0f, 0.0f);
275 auto shield = number(object, "shieldCapacity", 0.0f, 0.0f);
276 auto shieldRegen = number(object, "shieldRegenRate", 0.0f, 0.0f);
277 auto shieldDelay = number(object, "shieldRegenDelay", 0.0f, 0.0f);
278 auto transport = integer(object, "transportCapacity", 0);
279 auto airborne = text(object, "targetDomain");
280 auto suppression = number(object, "suppressionCapacity", 0.0f, 0.0f);
281 auto suppressionRecovery = number(object, "suppressionRecoveryRate", 0.0f, 0.0f);
282 auto suppressedSpeed = number(object, "suppressedSpeedFactor", 1.0f, 0.0f);
283 auto suppressedDamage = number(object, "suppressedDamageFactor", 1.0f, 0.0f);
284 auto retreatEnabled = boolean(object, "suppressionRetreatEnabled", false);
285 auto retreatThreshold = number(object, "suppressionRetreatThreshold", 0.8f, 0.0f);
286 auto retreatDistance = number(object, "suppressionRetreatDistance", 6.0f, 0.0f);
287 auto moraleRange = number(object, "moraleAuraRange", 0.0f, 0.0f);
288 auto moraleFactor = number(object, "moraleAuraSuppressionFactor", 1.0f, 0.0f);
289 auto moraleRecovery = number(object, "moraleAuraRecoveryBonus", 0.0f, 0.0f);
290 auto veteranThreshold = number(object, "veteranThreshold", 0.0f, 0.0f);
291 auto eliteThreshold = number(object, "eliteThreshold", 0.0f, 0.0f);
292 auto veteranDamage = number(object, "veteranDamageFactor", 1.0f, 0.0f);
293 auto eliteDamage = number(object, "eliteDamageFactor", 1.0f, 0.0f);
294 auto veteranHealth = number(object, "veteranHealthFactor", 1.0f, 0.0f);
295 auto eliteHealth = number(object, "eliteHealthFactor", 1.0f, 0.0f);
296 auto commandRange = number(object, "commandRange", 0.0f, 0.0f);
297 auto commandCapacity = integer(object, "commandCapacity", 0);
298 auto commandCost = integer(object, "commandCost", 1);
299 auto commandPriority = integer(object, "commandPriority", 0);
300 auto commandJamming = number(object, "commandJammingRange", 0.0f, 0.0f);
301 auto commandRequired = boolean(object, "requiresCommand", false);
302 auto relayUplink = boolean(object, "commandRelayRequiresUplink", false);
303 auto outOfCommandSpeed = number(object, "outOfCommandSpeedFactor", 1.0f, 0.0f);
304 auto outOfCommandDamage = number(object, "outOfCommandDamageFactor", 1.0f, 0.0f);
305 auto ammoCapacity = number(object, "ammoSupplyCapacity", 0.0f, 0.0f);
306 auto ammoRange = number(object, "ammoSupplyRange", 0.0f, 0.0f);
307 auto ammoRate = number(object, "ammoSupplyRate", 0.0f, 0.0f);
308 auto ammoRelay = boolean(object, "ammoRelayEnabled", false);
309 auto autoResupply = boolean(object, "autoResupplyEnabled", false);
310 auto autoThreshold = number(object, "autoResupplyThreshold", 0.5f, 0.0f);
311 auto reserveAmmo = number(object, "reserveAmmoCapacity", 0.0f, 0.0f);
312 auto supplyPriority = number(object, "supplyPriority", 1.0f, 0.0f);
313 auto firingTurnRate = number(object, "turretTurnRate", 0.0f, 0.0f);
314 auto firingArc = number(object, "firingArc", 0.01f, 0.0f);
315 auto firingHeight = number(object, "firingHeight", 1.0f, 0.000001f);
316 auto targetHeight = number(object, "targetHeight", 1.0f, 0.000001f);
317 if (!capacity || !gather || !buildRate || !repairRate || !captureRate || !shield || !shieldRegen || !shieldDelay ||
318 !transport || !airborne || !suppression || !suppressionRecovery || !suppressedSpeed || !suppressedDamage ||
319 !retreatEnabled || !retreatThreshold || !retreatDistance || !moraleRange || !moraleFactor || !moraleRecovery ||
320 !veteranThreshold || !eliteThreshold || !veteranDamage || !eliteDamage || !veteranHealth || !eliteHealth ||
321 !commandRange || !commandCapacity || !commandCost || !commandPriority || !commandJamming || !commandRequired ||
322 !relayUplink || !outOfCommandSpeed || !outOfCommandDamage || !ammoCapacity || !ammoRange || !ammoRate ||
323 !ammoRelay || !autoResupply || !autoThreshold || !reserveAmmo || !supplyPriority || !firingTurnRate ||
324 !firingArc || !firingHeight || !targetHeight)
326 "RTS unit definition contains an invalid capability field",
327 "unit", {}, "rts.archetype"));
328
329 weapon::WeaponEntity* weapon = nullptr;
330 if (!weaponType.value().empty()) {
331 if (!weaponFactory)
333 "RTS unit definition requires a weapon factory",
334 "unit.weaponType", {}, "rts.archetype"));
335 auto created = weaponFactory(weaponType.value(), unit.identity()->subject.persistentId());
336 if (!created) return Result<void>::failure(created.status());
337 weapon = std::move(created).takeValue();
338 }
339
340 unit.motion()->speed = speed.value();
341 unit.motion()->airborne = airborne.value() == "air";
342 unit.crowd()->radius = radius.value();
343 unit.vision()->sightRange = sight.value();
344 unit.vision()->detectionRange = detection.value();
345 unit.vision()->radarRange = radar.value();
346 unit.vision()->jammingRange = jamming.value();
347 unit.combat()->acquisitionRange = std::max(sight.value(), range.value());
348 unit.combat()->engagementRange = range.value();
349 unit.combat()->leashRange = std::max(sight.value(), range.value()) * 1.5f;
350 unit.durability()->state.subject = unit.identity()->subject;
351 unit.durability()->state.health = health.value();
352 unit.durability()->state.maxHealth = health.value();
353 unit.durability()->alive = health.value() > 0.0f;
354 unit.worker()->capacity = capacity.value();
355 unit.worker()->resourceType = std::move(gatherResource).takeValue();
356 unit.worker()->gatherRate = gather.value();
357 unit.worker()->buildRate = buildRate.value();
358 unit.worker()->repairRate = repairRate.value();
359 unit.worker()->autoAssign = role.value() == "worker";
360 unit.capture()->rate = captureRate.value();
361 unit.shield()->capacity = shield.value();
362 unit.shield()->value = shield.value();
363 unit.shield()->regenRate = shieldRegen.value();
364 unit.shield()->regenDelay = shieldDelay.value();
365 unit.containment()->capacity = static_cast<std::size_t>(transport.value());
366 unit.morale()->capacity = suppression.value();
367 unit.morale()->recoveryRate = suppressionRecovery.value();
368 unit.morale()->suppressedSpeedFactor = suppressedSpeed.value();
369 unit.morale()->suppressedDamageFactor = suppressedDamage.value();
370 unit.morale()->retreatEnabled = retreatEnabled.value();
371 unit.morale()->retreatThreshold = retreatThreshold.value();
372 unit.morale()->retreatDistance = retreatDistance.value();
373 unit.morale()->auraRange = moraleRange.value();
374 unit.morale()->auraSuppressionFactor = moraleFactor.value();
375 unit.morale()->auraRecoveryBonus = moraleRecovery.value();
376 unit.veterancy()->veteranThreshold = veteranThreshold.value();
377 unit.veterancy()->eliteThreshold = eliteThreshold.value();
378 unit.veterancy()->veteranDamageFactor = veteranDamage.value();
379 unit.veterancy()->eliteDamageFactor = eliteDamage.value();
380 unit.veterancy()->veteranHealthFactor = veteranHealth.value();
381 unit.veterancy()->eliteHealthFactor = eliteHealth.value();
382 unit.command()->range = commandRange.value();
383 unit.command()->capacity = commandCapacity.value();
384 unit.command()->cost = commandCost.value();
385 unit.command()->priority = commandPriority.value();
386 unit.command()->jammingRange = commandJamming.value();
387 unit.command()->requiresCommand = commandRequired.value();
388 unit.command()->relayRequiresUplink = relayUplink.value();
389 unit.command()->outOfCommandSpeedFactor = outOfCommandSpeed.value();
390 unit.command()->outOfCommandDamageFactor = outOfCommandDamage.value();
391 unit.supply()->capacity = std::max(ammoCapacity.value(), reserveAmmo.value());
392 unit.supply()->stock = ammoCapacity.value();
393 unit.supply()->range = ammoRange.value();
394 unit.supply()->transferRate = ammoRate.value();
395 unit.supply()->relayEnabled = ammoRelay.value();
396 unit.supply()->autoDispatch = autoResupply.value();
397 unit.supply()->autoThreshold = autoThreshold.value();
398 unit.supply()->priority = supplyPriority.value();
399 unit.combat()->turnRateDegrees = firingTurnRate.value();
400 unit.combat()->aimToleranceDegrees = firingArc.value();
401 unit.combat()->firingHeight = firingHeight.value();
402 unit.combat()->targetHeight = targetHeight.value();
403 unit.tags()->values = std::move(targetTags).takeValue();
404 if (weapon != nullptr) {
405 auto link = WeaponLink::bind(ecs::handle_of(weapon));
406 if (!link) return Result<void>::failure(link.status());
407 unit.weapon()->link = std::move(link).takeValue();
408 }
410}
411
413 const ArchetypeWeaponFactory& weaponFactory) {
414 auto objectResult = definitionObject(registry, "building", building.definition()->id);
415 if (!objectResult) return Result<void>::failure(objectResult.status());
416 const auto object = std::move(objectResult).takeValue();
417 auto health = number(object, "health", 1.0f, 0.0f);
418 auto radius = number(object, "radius", 0.5f, 0.0f);
419 auto buildTime = number(object, "buildTime", 0.0f, 0.0f);
420 auto sight = number(object, "sightRange", 0.0f, 0.0f);
421 auto weaponType = text(object, "weaponType");
422 auto garrison = integer(object, "garrisonCapacity", 0);
423 auto capturable = boolean(object, "capturable", false);
424 auto captureTime = number(object, "captureTime", 5.0f, 0.000001f);
425 auto scorePerSecond = number(object, "controlPointScorePerSecond", 0.0f, 0.0f);
426 auto powerProduced = number(object, "powerProvided", 0.0f, 0.0f);
427 auto powerUsed = number(object, "powerUsed", 0.0f, 0.0f);
428 auto powerPriority = integer(object, "powerPriority", 0);
429 auto influence = number(object, "buildInfluenceRadius", 0.0f, 0.0f);
430 auto incomeResource = text(object, "incomeResource");
431 auto dropoffResources = tags(object, "dropoffResources");
432 if (!dropoffResources) return Result<void>::failure(dropoffResources.status());
433 for (const auto& name : dropoffResources.value().values()) {
434 auto validResource = resource::ResourceId::parse(name);
435 if (!validResource) return Result<void>::failure(validResource.status());
436 }
437 auto incomeRate = number(object, "incomeRate", 0.0f, 0.0f);
438 auto repairCost = number(object, "repairCostPerHealth", 0.0f, 0.0f);
439 auto repairResource = text(object, "repairResource", "minerals");
440 auto shield = number(object, "shieldCapacity", 0.0f, 0.0f);
441 auto shieldRegen = number(object, "shieldRegenRate", 0.0f, 0.0f);
442 auto shieldDelay = number(object, "shieldRegenDelay", 0.0f, 0.0f);
443 auto garrisonBonus = number(object, "garrisonDamageBonus", 0.0f, 0.0f);
444 auto ammoCapacity = number(object, "ammoSupplyCapacity", 0.0f, 0.0f);
445 auto ammoRange = number(object, "ammoSupplyRange", 0.0f, 0.0f);
446 auto ammoRate = number(object, "ammoSupplyRate", 0.0f, 0.0f);
447 auto ammoResource = text(object, "ammoProductionResource");
448 auto ammoCost = number(object, "ammoProductionCost", 0.0f, 0.0f);
449 auto ammoProduction = number(object, "ammoProductionRate", 0.0f, 0.0f);
450 auto commandRange = number(object, "commandRange", 0.0f, 0.0f);
451 auto commandCapacity = integer(object, "commandCapacity", 0);
452 auto commandJamming = number(object, "commandJammingRange", 0.0f, 0.0f);
453 auto turretTurn = number(object, "turretTurnRate", 0.0f, 0.0f);
454 auto firingArc = number(object, "firingArc", 0.01f, 0.0f);
455 auto firingHeight = number(object, "firingHeight", 2.0f, 0.000001f);
456 auto targetHeight = number(object, "targetHeight", 1.5f, 0.000001f);
457 if (!health || !radius || !buildTime || !sight || !weaponType || !garrison || !capturable || !captureTime ||
458 !scorePerSecond || !powerProduced || !powerUsed || !powerPriority || !influence || !incomeResource ||
459 !incomeRate || !repairCost || !repairResource || !shield || !shieldRegen || !shieldDelay || !garrisonBonus ||
460 !ammoCapacity || !ammoRange || !ammoRate || !ammoResource || !ammoCost || !ammoProduction || !commandRange ||
461 !commandCapacity || !commandJamming || !turretTurn || !firingArc || !firingHeight || !targetHeight)
463 "RTS building definition contains an invalid field", "building",
464 {}, "rts.archetype"));
465
466 weapon::WeaponEntity* weapon = nullptr;
467 if (!weaponType.value().empty()) {
468 if (!weaponFactory)
470 "RTS building definition requires a weapon factory",
471 "building.weaponType", {}, "rts.archetype"));
472 auto created = weaponFactory(weaponType.value(), building.identity()->subject.persistentId());
473 if (!created) return Result<void>::failure(created.status());
474 weapon = std::move(created).takeValue();
475 }
476
477 building.placement()->placed = true;
478 building.construction()->buildTimeSeconds = buildTime.value();
479 building.integrity()->state.subject = building.identity()->subject;
480 building.integrity()->state.health = health.value();
481 building.integrity()->state.maxHealth = health.value();
482 building.integrity()->alive = health.value() > 0.0f;
483 building.integrity()->repairCostPerHealth = repairCost.value();
484 building.integrity()->repairResource = std::move(repairResource).takeValue();
485 building.shield()->capacity = shield.value();
486 building.shield()->value = shield.value();
487 building.shield()->regenRate = shieldRegen.value();
488 building.shield()->regenDelay = shieldDelay.value();
489 building.vision()->sightRange = sight.value();
490 building.garrison()->capacity = static_cast<std::size_t>(garrison.value());
491 building.garrison()->damageBonusPerOccupant = garrisonBonus.value();
492 building.capture()->capturable = capturable.value();
493 building.capture()->durationSeconds = captureTime.value();
494 building.capture()->scorePerSecond = scorePerSecond.value();
495 building.infrastructure()->powerProduced = powerProduced.value();
496 building.infrastructure()->powerConsumed = powerUsed.value();
497 building.infrastructure()->powerPriority = powerPriority.value();
498 building.infrastructure()->buildInfluenceRadius = influence.value();
499 building.infrastructure()->incomeResource = std::move(incomeResource).takeValue();
500 building.infrastructure()->incomeRate = incomeRate.value();
501 building.supply()->capacity = ammoCapacity.value();
502 building.supply()->stock = ammoCapacity.value();
503 building.supply()->range = ammoRange.value();
504 building.supply()->transferRate = ammoRate.value();
505 building.supply()->productionResource = std::move(ammoResource).takeValue();
506 building.supply()->productionCostPerRound = static_cast<std::int64_t>(std::ceil(ammoCost.value()));
507 building.supply()->productionRate = ammoProduction.value();
508 building.command()->range = commandRange.value();
509 building.command()->capacity = commandCapacity.value();
510 building.command()->jammingRange = commandJamming.value();
511 building.command()->active = commandRange.value() > 0.0f;
512 building.combat()->firingHeight = firingHeight.value();
513 building.combat()->targetHeight = targetHeight.value();
514 building.dropoff()->radius = radius.value();
515 if (const auto dropoff = boolean(object, "dropoff", false); dropoff && dropoff.value())
516 building.dropoff()->acceptedResources = field(object, "dropoffResources")
517 ? dropoffResources.value().values()
518 : std::vector<std::string>{"minerals"};
519 if (weapon != nullptr) {
520 auto link = WeaponLink::bind(ecs::handle_of(weapon));
521 if (!link) return Result<void>::failure(link.status());
522 building.weapon()->link = std::move(link).takeValue();
523 building.combat()->acquisitionRange = sight.value();
524 building.combat()->engagementRange = sight.value();
525 building.combat()->turnRateDegrees = turretTurn.value();
526 building.combat()->aimToleranceDegrees = firingArc.value();
527 }
529}
530
531} // namespace eve::rts
Renderer- and ruleset-neutral gameplay action pipeline.
eve::action::ActionExecutionId executionId
std::vector< QuestEvent > pending
std::string name
Definition ECS.cpp:154
float minimum[3]
const GltfImportRequest & request
std::uint32_t capacity
HexVec3 left
HexVec3 right
PhysicsJointLink link
Range range
std::shared_ptr< std::atomic< bool > > cancelled
Poco::JSON::Object::Ptr result
std::unordered_set< std::string > tags
double radius
Definition MeleeHit.cpp:42
std::vector< std::int32_t > order
const eve::script::BindingContractRegistry & registry
Object::Ptr value
RTS adapter boundary over the shared action lifecycle.
Canonical definition-to-RTS-component materialization.
RoadNetwork resolved
double number
bool found
int created
std::string text
std::string_view source
bool boolean
float phase
TacticalUnit * unit
float step
Definition TreeMesh.cpp:451
uint32_t index
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.
static std::optional< LogicalId > fromParts(std::string_view namespaceName, std::string_view name)
Builds a logical ID from separate namespace and name components.
Definition Identity.cpp:49
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
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
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
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
Deterministic action lifecycle coordinator.
Definition Action.h:540
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
static EVENGINE_API_FOUNDATION eve::Result< ResourceId > parse(std::string_view text)
Parse a resource id at a public input boundary.
void clear() noexcept
Forget runtime execution correlations so restored orders are rebound on their next step.
Definition RTSAction.cpp:52
ActionAdapter(action::ActionRuntime &runtime)
Bind the adapter to an owner-thread action runtime.
Definition RTSAction.cpp:48
~ActionAdapter() override
Action adapter.
Result< ActionExecutionResult > execute(Unit &unit, const OrderRecord &order, const SimulationStep &step) override
Execute or advance one active RTS order.
Definition RTSAction.cpp:56
RTS building domain root with placement and production composition.
Definition RTSTypes.h:852
static Result< void > apply(definitions::DefinitionRegistry &registry, Unit &unit, const ArchetypeWeaponFactory &weaponFactory={})
Apply the Unit root's logical definition atomically.
RTS unit domain root.
Definition RTSTypes.h:501
武器实体:数据全部在组件里,行为在 WeaponSystem。
ActionPhase
Lifecycle phase shared by every gameplay action adapter.
Definition Action.h:40
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
std::function< Result< weapon::WeaponEntity * >(std::string_view definitionId, PersistentId instanceId)> ArchetypeWeaponFactory
Factory that creates one canonical weapon instance from a registry definition.
const char * orderKindName(OrderKind kind) noexcept
Return the stable lower-case spelling of an RTS order kind.
Definition RTSTypes.cpp:177
int64_t integer(const RuntimeTensor &v, size_t i=0)
Integer.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Immutable-by-convention definition of one action kind.
Definition Action.h:119
One caller-owned request to instantiate an action execution.
Definition Action.h:156
LogicalId actionId
Definition identity this request intends to execute.
Definition Action.h:158
action::ActionExecutionId execution
Definition RTSAction.cpp:39
Impl(action::ActionRuntime &runtimeValue)
Definition RTSAction.cpp:42
action::ActionRuntime & runtime
Definition RTSAction.cpp:44
std::vector< Pending > pending
Definition RTSAction.cpp:45
Owning, domain-local projection of an action adapter outcome.
Definition RTSAction.h:27
Owning projection of the active generic order used by RTS systems.
Definition RTSTypes.h:122