57 if (
step.delta.nanoseconds() < 0)
64 const ecs::EntityHandle unitHandle = ecs::handle_of(&
unit);
66 std::find_if(impl_->pending.begin(), impl_->pending.end(),
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);
75 impl_->pending.erase(pendingForUnit);
76 pendingForUnit = impl_->pending.end();
80 if (pendingForUnit == impl_->pending.end()) {
81 const auto logicalId = actionIdFor(
order);
85 "order.definitionId"));
88 definition.id = *logicalId;
95 auto submitted = impl_->runtime.submit(std::move(definition), std::move(
request));
105 impl_->pending.erase(
106 std::remove_if(impl_->pending.begin(), impl_->pending.end(),
108 impl_->pending.end());
112 const auto summary = std::move(advanced).takeValue();
116 impl_->pending.erase(
117 std::remove_if(impl_->pending.begin(), impl_->pending.end(),
119 impl_->pending.end());
243 auto objectResult = definitionObject(
registry,
"unit",
unit.definition()->id);
245 const auto object = std::move(objectResult).takeValue();
247 auto health =
number(
object,
"health", 1.0f, 0.0f);
248 auto speed =
number(
object,
"speed", 1.0f, 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 ||
261 "RTS unit definition contains an invalid core field",
"unit", {},
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" :
"");
267 if (!gatherResource.value().empty()) {
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"));
330 if (!weaponType.value().empty()) {
333 "RTS unit definition requires a weapon factory",
334 "unit.weaponType", {},
"rts.archetype"));
335 auto created = weaponFactory(weaponType.value(),
unit.identity()->subject.persistentId());
337 weapon = std::move(
created).takeValue();
340 unit.motion()->speed = speed.value();
341 unit.motion()->airborne = airborne.value() ==
"air";
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;
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) {
407 unit.weapon()->link = std::move(
link).takeValue();
414 auto objectResult = definitionObject(
registry,
"building", building.definition()->id);
416 const auto object = std::move(objectResult).takeValue();
417 auto health =
number(
object,
"health", 1.0f, 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");
433 for (
const auto&
name : dropoffResources.value().values()) {
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"));
467 if (!weaponType.value().empty()) {
470 "RTS building definition requires a weapon factory",
471 "building.weaponType", {},
"rts.archetype"));
472 auto created = weaponFactory(weaponType.value(), building.identity()->subject.persistentId());
474 weapon = std::move(
created).takeValue();
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) {
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();