载入中...
搜索中...
未找到
RTSTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
16#include "common/ECS.h"
17#include "common/Identity.h"
18#include "common/Result.h"
19#include "common/SubjectRef.h"
20#include "combat/Damage.h"
21#include "common/Time.h"
22#include "rts/RTSEffects.h"
24
25#include <cstddef>
26#include <cstdint>
27#include <memory>
28#include <map>
29#include <optional>
30#include <span>
31#include <string>
32#include <string_view>
33#include <vector>
34
35namespace eve::orders {
36class CommandQueue;
37}
38
39namespace eve::production {
40class WorkQueue;
41}
42
43namespace eve::rts {
44
45class RTSProductionActionAdapter;
46
49 float x = 0.0f;
50 float y = 0.0f;
51};
52
54enum class CombatStance : std::uint8_t { Passive, Defensive, Aggressive };
55
61[[nodiscard]] const char* combatStanceName(CombatStance stance) noexcept;
62
64enum class OrderKind : std::uint8_t {
65 Move,
66 Attack,
67 Build,
68 Gather,
71 Stop,
73 Patrol,
74 Repair,
77 Capture,
80 Escort,
83};
84
93[[nodiscard]] const char* orderKindName(OrderKind kind) noexcept;
94
104 std::string definitionId;
105 int priority = 0;
106 double timeoutSeconds = 0.0;
107 ecs::EntityHandle targetEntity{};
109 float radius = 0.0f;
110 bool append = false;
111
113 [[nodiscard]] Result<void> validate() const;
114};
115
118 std::string id;
121 std::string definitionId;
122 ecs::EntityHandle targetEntity{};
124 float radius = 0.0f;
125 bool append = false;
127};
128
130enum class AbilityTarget : std::uint8_t { Self, Ally, Enemy, Point };
131
134 std::string id;
137 std::string resourceType;
138 std::string damageType = "damage.magic";
139 float range = 0.0f;
140 float radius = 0.0f;
141 float cooldown = 0.0f;
142 std::int64_t resourceCost = 0;
143 float damage = 0.0f;
144 float healing = 0.0f;
145 float castTime = 0.0f;
147 bool interruptOnDamage = true;
148 bool appliesEffect = false;
150};
151
154public:
156 [[nodiscard]] Result<void> add(std::string_view tag);
158 [[nodiscard]] Result<void> remove(std::string_view tag);
160 [[nodiscard]] bool contains(std::string_view tag) const noexcept;
162 [[nodiscard]] const std::vector<std::string>& values() const noexcept { return values_; }
163
164private:
165 std::vector<std::string> values_;
166};
167
170
179template <typename Tag>
182public:
184 [[nodiscard]] static Result<EntityLink> bind(ecs::EntityHandle handle) {
185 if (ecs::try_get(handle) == nullptr) {
189 Diagnostic::error(DiagnosticCode::StaleHandle, "RTS entity link target is not live", "link.handle"));
190 }
191 EntityLink result;
192 result.handle_ = handle;
193 result.bound_ = true;
195 return Result<EntityLink>::success(std::move(result));
196 }
197
202 [[nodiscard]] static EntityLink fromHandleForRestore(ecs::EntityHandle handle) noexcept {
203 EntityLink result;
204 result.handle_ = handle;
205 result.bound_ = true;
206 return result;
207 }
208
210 [[nodiscard]] bool isBound() const noexcept { return bound_; }
212 [[nodiscard]] bool isStale() const noexcept { return bound_ && ecs::try_get(handle_) == nullptr; }
214 [[nodiscard]] ecs::Entity* resolve() const noexcept { return bound_ ? ecs::try_get(handle_) : nullptr; }
216 [[nodiscard]] const ecs::EntityHandle& handle() const noexcept { return handle_; }
218 void reset() noexcept {
219 bound_ = false;
220 handle_ = {};
221 }
222
223private:
224 ecs::EntityHandle handle_{};
225 bool bound_ = false;
226};
227
230
238template <typename Tag>
241public:
243 [[nodiscard]] static Result<ServiceLink> bind(std::string_view key) {
244 if (key.empty()) {
247 DiagnosticCode::InvalidArgument, "RTS service link key must not be empty", "link.key"));
248 }
249 ServiceLink result;
250 result.key_ = key;
252 return Result<ServiceLink>::success(std::move(result));
253 }
254
256 [[nodiscard]] static ServiceLink fromKeyForRestore(std::string_view key) {
257 ServiceLink result;
258 result.key_ = key;
259 return result;
260 }
261
263 [[nodiscard]] bool isBound() const noexcept { return !key_.empty(); }
265 [[nodiscard]] bool isStale() const noexcept { return key_.empty(); }
267 [[nodiscard]] const std::string& key() const noexcept { return key_; }
269 void reset() noexcept { key_.clear(); }
270
271private:
272 std::string key_;
273};
274
290
296struct CrowdLinkTag {};
321
324public:
332 AttributeComponent& operator=(const AttributeComponent& other);
337
339 [[nodiscard]] Result<void> setBase(std::string_view attribute, double value);
341 [[nodiscard]] Result<void> modifyBase(std::string_view attribute, double delta);
343 [[nodiscard]] bool has(std::string_view attribute) const;
345 [[nodiscard]] Result<double> getFinal(std::string_view attribute, double fallback = 0.0) const;
347 [[nodiscard]] std::size_t modifierCount() const noexcept;
360 [[nodiscard]] const eve::attributes::AttributeModifier* modifierAt(int index) const noexcept;
361
363 [[nodiscard]] Result<void> bindOwner(ecs::EntityHandle owner);
365 [[nodiscard]] bool initialized() const noexcept;
367 [[nodiscard]] Result<void> initialize(std::span<const eve::attributes::AttributeSnapshotBase> values);
369 [[nodiscard]] bool isStale() const noexcept;
371 [[nodiscard]] Result<eve::attributes::ModifierId> addModifier(eve::attributes::AttributeModifier modifier);
373 [[nodiscard]] Result<eve::attributes::AttributeProjectionSnapshot> snapshot(
374 std::span<const std::string_view> attributes) const;
376 [[nodiscard]] Result<void> restore(const eve::attributes::AttributeProjectionSnapshot& snapshot,
377 Revision expectedRevision);
378
379private:
380 struct Impl;
381 std::unique_ptr<Impl> impl_;
382};
383
386public:
388 struct Snapshot {
389 std::string queueJson;
390 std::map<std::string, CommandSpec> extended;
391 };
394 OrderComponent(const OrderComponent& other);
395 OrderComponent& operator=(const OrderComponent& other);
396 OrderComponent(OrderComponent&& other) noexcept;
397 OrderComponent& operator=(OrderComponent&& other) noexcept;
398
400 [[nodiscard]] Result<std::string> enqueue(const CommandSpec& command, int formationSlot = -1);
402 [[nodiscard]] Result<std::string> replace(const CommandSpec& command, int formationSlot = -1);
404 [[nodiscard]] Result<OrderRecord> current() const;
406 [[nodiscard]] Result<void> complete(std::string_view orderId);
408 [[nodiscard]] Result<void> fail(std::string_view orderId, std::string_view reason);
410 [[nodiscard]] Result<void> cancel(std::string_view orderId, std::string_view reason);
412 [[nodiscard]] bool empty() const noexcept;
414 void clear() noexcept;
416 [[nodiscard]] std::size_t orderCount() const noexcept;
418 [[nodiscard]] Result<std::string> snapshot() const;
420 [[nodiscard]] Result<void> restore(std::string_view json);
422 [[nodiscard]] Result<Snapshot> snapshotState() const;
424 [[nodiscard]] Result<void> restoreState(const Snapshot& snapshot);
425
426private:
428 friend class RTS;
430 std::uint64_t membershipEpoch_ = 0;
431 [[nodiscard]] orders::CommandQueue* queueForComposition() noexcept;
432
433 struct Impl;
434 std::unique_ptr<Impl> impl_;
435};
436
439public:
447 ProductionComponent& operator=(const ProductionComponent& other);
452
454 [[nodiscard]] Result<std::string> enqueue(std::string_view owner, std::string_view kind, std::string_view product,
455 Duration duration, int priority = 0);
459 [[nodiscard]] Result<void> advance(const SimulationStep& step);
461 [[nodiscard]] std::size_t taskCount() const noexcept;
463 [[nodiscard]] OptionalRef<const production::ProductionTask> taskAt(int index);
465 [[nodiscard]] OptionalRef<const production::ProductionTask> find(std::string_view taskId);
467 [[nodiscard]] Result<void> pause(std::string_view taskId);
469 [[nodiscard]] Result<void> resume(std::string_view taskId);
471 [[nodiscard]] Result<void> cancel(std::string_view taskId, std::string_view reason = "cancelled");
473 [[nodiscard]] std::vector<production::ProductionTask> readyToSettle(std::string_view kind) const;
475 [[nodiscard]] Result<void> settle(std::string_view taskId, production::ProductionSettlementReceipt receipt);
477 [[nodiscard]] Result<std::string> snapshot() const;
479 [[nodiscard]] Result<void> restore(std::string_view json);
480
481private:
483 [[nodiscard]] production::WorkQueue* queueForComposition() noexcept;
484
485 struct Impl;
486 std::unique_ptr<Impl> impl_;
487};
488
495class EVENGINE_API_DOMAINS Unit : public ecs::Entity {
496public:
498 ENTITY(Unit, ecs::Entity)
499
500
501 void release() override { ecs::DestroyEntity(this); }
502
504 struct Identity {
505 ecs::EntityHandle self{};
507 std::string displayName;
508 };
510 struct Definition {
512 };
518 struct Tags {
520 };
530 struct Sensing {
532 };
538 struct Crowd {
540 float radius = 0.5f;
541 float heading = 0.0f;
542 };
544 struct Weapon {
546 };
548 struct Action {
550 };
560 struct Motion {
561 float x = 0.0f;
562 float y = 0.0f;
563 float speed = 1.0f;
564 float arrivalRadius = 0.01f;
565 bool arrived = true;
566 bool airborne = false;
567 };
569 struct Navigation {
570 std::vector<WorldPosition> waypoints;
571 std::size_t waypointIndex = 0;
572 std::string plannedOrderId;
575 int movementPriority = 0;
576 bool patrolInitialized = false;
577 bool patrolTowardTarget = true;
578 bool trafficWaiting = false;
579 bool unreachable = false;
580 bool unreachableReported = false;
581 float formationSpeedFactor = 1.f;
582 std::optional<WorldPosition> formationTarget;
583 std::optional<WorldPosition> trafficRecoveryTarget;
584 };
586 struct Vision {
587 float sightRange = 0.0f;
588 float detectionRange = 0.0f;
589 float detectionStrength = 0.0f;
590 float radarRange = 0.0f;
591 float radarResolution = 0.0f;
592 float jammingRange = 0.0f;
593 float stealth = 0.0f;
594 bool enabled = true;
595 bool cloaked = false;
596 };
598 struct Worker {
599 std::string resourceType;
602 float cargo = 0.0f;
603 float capacity = 0.0f;
604 float gatherRate = 0.0f;
605 float buildRate = 1.0f;
606 float repairRate = 0.0f;
607 bool autoAssign = false;
608 };
610 struct Combat {
611 ecs::EntityHandle target{};
612 CombatStance stance = CombatStance::Defensive;
613 float acquisitionRange = 0.0f;
614 float engagementRange = 0.0f;
615 float leashRange = 0.0f;
616 float guardX = 0.0f;
617 float guardY = 0.0f;
618 bool guardSet = false;
619 bool holdPosition = false;
620 bool attackMove = false;
621 float suppressionPerShot = 0.0f;
622 float upgradeDamageFactor = 1.0f;
623 float turnRateDegrees = 0.0f;
624 float aimToleranceDegrees = 0.01f;
625 float firingHeight = 1.0f;
626 float targetHeight = 1.0f;
627 std::uint64_t shotSequence = 0;
628 std::map<std::string, float> targetPriorities;
629 };
631 struct Durability {
633 bool alive = true;
634 };
636 struct Shield {
637 float value = 0.0f;
638 float capacity = 0.0f;
639 float regenRate = 0.0f;
640 float regenDelay = 0.0f;
641 float cooldown = 0.0f;
642 };
644 struct Veterancy {
645 float experience = 0.0f;
646 int level = 0;
647 float veteranThreshold = 0.0f;
648 float eliteThreshold = 0.0f;
649 float veteranDamageFactor = 1.0f;
650 float eliteDamageFactor = 1.0f;
651 float veteranHealthFactor = 1.0f;
652 float eliteHealthFactor = 1.0f;
653 };
655 struct Command {
656 float range = 0.0f;
657 int capacity = 0;
658 int load = 0;
659 int cost = 1;
660 int priority = 0;
661 float jammingRange = 0.0f;
662 float outOfCommandSpeedFactor = 1.0f;
663 float outOfCommandDamageFactor = 1.0f;
664 bool requiresCommand = false;
665 bool relayRequiresUplink = false;
666 bool relayActive = false;
667 bool jammed = false;
668 bool inCommand = true;
669 ecs::EntityHandle source{};
670 ecs::EntityHandle uplink{};
671 };
673 struct Abilities {
675 struct Cooldown { std::string id; float remaining = 0.0f; };
677 struct Channel {
679 ecs::EntityHandle target{};
681 double startingHealth = 0.0;
682 float remaining = 0.0f;
683 float tickRemaining = 0.0f;
684 };
685 std::vector<Cooldown> cooldowns;
686 std::optional<Channel> channel;
687 };
689 struct Capture {
690 float rate = 0.0f;
691 };
693 struct Containment {
695 std::size_t capacity = 0;
696 std::vector<ecs::EntityHandle> occupants;
697 };
699 struct Supply {
700 float stock = 0.0f;
701 float capacity = 0.0f;
702 float range = 0.0f;
703 float transferRate = 0.0f;
704 float transferProgress = 0.0f;
705 float reservedStock = 0.0f;
706 float autoThreshold = 0.5f;
707 float priority = 1.0f;
708 bool autoDispatch = false;
709 bool relayEnabled = false;
710 bool returning = false;
711 bool rendezvousActive = false;
712 bool convoyWaiting = false;
713 std::size_t convoyIndex = 0;
714 ecs::EntityHandle assignedTarget{};
715 ecs::EntityHandle convoyLeader{};
718 float rendezvousThreat = 0.0f;
719 bool rendezvousAvoidedThreat = false;
720 float routeThreat = 0.0f;
721 bool routeAvoidedThreat = false;
722 };
724 struct Morale {
725 float suppression = 0.0f;
726 float capacity = 0.0f;
727 float recoveryRate = 0.0f;
728 float suppressedSpeedFactor = 1.0f;
729 float suppressedDamageFactor = 1.0f;
730 float retreatThreshold = 0.8f;
731 float retreatDistance = 6.0f;
732 float auraRange = 0.0f;
733 float auraSuppressionFactor = 1.0f;
734 float auraRecoveryBonus = 0.0f;
735 bool active = false;
736 bool retreatEnabled = false;
737 bool retreating = false;
738 };
740 struct Artillery {
741 float deployTime = 0.0f;
742 float deployRemaining = 0.0f;
743 float shootAndScootDistance = 0.0f;
744 float previousX = 0.0f;
745 float previousY = 0.0f;
748 float relocationThreat = 0.0f;
749 int relocationConflictCount = 0;
750 bool positionInitialized = false;
751 bool relocating = false;
752 bool hasDepartedPosition = false;
753 std::uint32_t shotSequence = 0;
754 int suppressionShotsRemaining = -1;
755 ecs::EntityHandle fireSupportRequester{};
756 ecs::EntityHandle observedFireSpotter{};
757 bool usingObservedFire = false;
758 SimulationTick lastFireTick{};
760 bool autoCounterBattery = false;
761 std::uint64_t counterBatteryWindowTicks = 0;
762 };
764 struct Tactics {
765 std::uint64_t combatGroup = 0;
766 int threatSector = 0;
767 float coordinatedVolleyInterval = 0.0f;
768 float volleyReleaseRemaining = 0.0f;
769 float fireControlEffectiveness = 1.0f;
770 bool volleyHolding = false;
771 ecs::EntityHandle escortTarget{};
772 float escortOffsetX = 0.0f;
773 float escortOffsetY = 0.0f;
774 float protectionRange = 8.0f;
775 float guardX = 0.0f;
776 float guardY = 0.0f;
777 bool guardSet = false;
778 int escortScreenSector = 0;
779 bool escortSectorMatched = false;
780 bool escortReinforcing = false;
781 int escortReinforcementSector = 0;
782 bool escortRearGuard = false;
784 std::uint32_t escortHandoffCount = 0;
785 int retreatFireTeam = -1;
786 float retreatCoverElapsed = 0.0f;
787 bool retreatCovering = false;
788 };
790 struct Technology {
791 std::vector<std::string> applied;
792 };
793
794 COMPONENT(Identity, identity)
795 COMPONENT(Definition, definition)
796 COMPONENT(Attributes, attributes)
797 COMPONENT(Tags, tags)
798 COMPONENT(Effects, effects)
799 COMPONENT(Orders, orders)
800 COMPONENT(Sensing, sensing)
801 COMPONENT(Steering, steering)
802 COMPONENT(Crowd, crowd)
803 COMPONENT(Weapon, weapon)
804 COMPONENT(Action, action)
805 COMPONENT(Settlement, settlement)
806 COMPONENT(Faction, faction)
807 COMPONENT(Motion, motion)
808 COMPONENT(Navigation, navigation)
809 COMPONENT(Vision, vision)
810 COMPONENT(Worker, worker)
811 COMPONENT(Combat, combat)
812 COMPONENT(Durability, durability)
813 COMPONENT(Shield, shield)
814 COMPONENT(Veterancy, veterancy)
815 COMPONENT(Command, command)
816 COMPONENT(Abilities, abilities)
817 COMPONENT(Capture, capture)
818 COMPONENT(Containment, containment)
819 COMPONENT(Supply, supply)
820 COMPONENT(Morale, morale)
821 COMPONENT(Artillery, artillery)
822 COMPONENT(Tactics, tactics)
823 COMPONENT(Technology, technology)
824
825
836 [[nodiscard]] static Unit* createUnit(SubjectRef subject = {}, LogicalId definition = {});
837};
838
840class EVENGINE_API_DOMAINS Building : public ecs::Entity {
841public:
843 ENTITY(Building, ecs::Entity)
844
845
846 void release() override { ecs::DestroyEntity(this); }
847
849 struct Identity {
850 ecs::EntityHandle self{};
852 std::string displayName;
853 };
855 struct Definition {
857 };
859 struct Placement {
861 int cellX = 0;
862 int cellY = 0;
863 float worldX = 0.0f;
864 float worldY = 0.0f;
865 float rotation = 0.0f;
866 bool placed = false;
867 };
873 struct Economy {
875 };
881 struct Tags {
883 };
898 float progress = 1.0f;
899 float buildTimeSeconds = 0.0f;
900 bool paused = false;
901 std::vector<ecs::EntityHandle> builders;
902 };
904 struct Integrity {
906 bool alive = true;
907 float repairCostPerHealth = 0.0f;
908 float repairCostRemainder = 0.0f;
909 std::string repairResource;
910 };
912 struct Shield {
913 float value = 0.0f;
914 float capacity = 0.0f;
915 float regenRate = 0.0f;
916 float regenDelay = 0.0f;
917 float cooldown = 0.0f;
918 };
920 struct Capture {
921 bool capturable = false;
922 float durationSeconds = 5.0f;
923 float progress = 0.0f;
924 ecs::EntityHandle capturingFaction{};
925 bool blockedByGarrison = false;
926 };
928 struct Dropoff {
929 std::vector<std::string> acceptedResources;
930 float radius = 1.0f;
931 };
933 struct Rally {
934 bool enabled = false;
936 std::uint64_t combatGroup = 0;
937 ecs::EntityHandle transport{};
938 std::size_t minimumTransportLoad = 1;
939 bool transportActive = false;
940 bool productionSpawnBlocked = false;
942 std::vector<std::string> settledProductionTasks;
943 std::vector<ecs::EntityHandle> reinforcements;
944 std::size_t reinforcementLimit = 0;
945 std::map<std::string, std::size_t> reinforcementTypeLimits;
946 std::map<std::string, int> reinforcementTypePriorities;
947 std::map<std::string, std::string> reinforcementFallbacks;
948 bool reinforcementCapped = false;
950 float reinforcementAutoCancelDelay = 0.0f;
951 float reinforcementCappedSeconds = 0.0f;
952 };
954 struct Weapon {
956 };
958 struct Combat {
959 ecs::EntityHandle target{};
960 ecs::EntityHandle airDefenseNetworkRoot{};
961 float acquisitionRange = 0.0f;
962 float engagementRange = 0.0f;
963 float airDefenseNetworkRange = 0.0f;
964 std::size_t airDefenseNetworkSize = 0;
965 float turnRateDegrees = 0.0f;
966 float aimToleranceDegrees = 0.01f;
967 float firingHeight = 2.0f;
968 float targetHeight = 1.5f;
969 std::uint64_t shotSequence = 0;
970 std::map<std::string, float> targetPriorities;
971 };
973 struct Garrison {
974 std::size_t capacity = 0;
975 float damageBonusPerOccupant = 0.0f;
976 std::vector<ecs::EntityHandle> occupants;
977 };
979 struct Supply {
980 float stock = 0.0f;
981 float capacity = 0.0f;
982 float range = 0.0f;
983 float transferRate = 0.0f;
984 float transferProgress = 0.0f;
986 std::int64_t productionCostPerRound = 0;
987 float productionRate = 0.0f;
988 float productionProgress = 0.0f;
989 };
991 struct Vision {
992 float sightRange = 0.0f;
993 float detectionRange = 0.0f;
994 float detectionStrength = 0.0f;
995 float radarRange = 0.0f;
996 float radarResolution = 0.0f;
997 float jammingRange = 0.0f;
998 bool enabled = true;
999 };
1001 struct Technology {
1002 std::vector<std::string> applied;
1003 };
1006 float powerProduced = 0.0f;
1007 float powerConsumed = 0.0f;
1008 int powerPriority = 0;
1009 bool powered = true;
1010 float buildInfluenceRadius = 0.0f;
1011 std::string incomeResource;
1012 float incomeRate = 0.0f;
1013 float incomeProgress = 0.0f;
1014 };
1016 struct Command {
1017 float range = 0.0f;
1018 int capacity = 0;
1019 int load = 0;
1020 float jammingRange = 0.0f;
1021 bool jammed = false;
1022 bool active = false;
1023 };
1029
1030 COMPONENT(Identity, identity)
1031 COMPONENT(Definition, definition)
1032 COMPONENT(Placement, placement)
1033 COMPONENT(Production, production)
1034 COMPONENT(Economy, economy)
1035 COMPONENT(Orders, orders)
1036 COMPONENT(Tags, tags)
1037 COMPONENT(Effects, effects)
1038 COMPONENT(Settlement, settlement)
1039 COMPONENT(Faction, faction)
1040 COMPONENT(Construction, construction)
1041 COMPONENT(Integrity, integrity)
1042 COMPONENT(Shield, shield)
1043 COMPONENT(Capture, capture)
1044 COMPONENT(Dropoff, dropoff)
1045 COMPONENT(Rally, rally)
1046 COMPONENT(Weapon, weapon)
1047 COMPONENT(Combat, combat)
1048 COMPONENT(Garrison, garrison)
1049 COMPONENT(Supply, supply)
1050 COMPONENT(Vision, vision)
1051 COMPONENT(Technology, technology)
1052 COMPONENT(Infrastructure, infrastructure)
1053 COMPONENT(Command, command)
1054 COMPONENT(IndirectFire, indirectFire)
1055
1056
1067 [[nodiscard]] static Building* createBuilding(SubjectRef subject = {}, LogicalId definition = {});
1068};
1069
1071class EVENGINE_API_DOMAINS ResourceNode : public ecs::Entity {
1072public:
1074 ENTITY(ResourceNode, ecs::Entity)
1075
1076
1077 void release() override { ecs::DestroyEntity(this); }
1078
1080 struct Identity {
1081 ecs::EntityHandle self{};
1083 std::string displayName;
1084 };
1086 struct Position {
1087 float x = 0.0f;
1088 float y = 0.0f;
1089 float radius = 1.0f;
1090 };
1092 struct Stock {
1093 std::string resourceType;
1094 float remaining = 0.0f;
1095 float maximum = 0.0f;
1096 bool infinite = false;
1097 };
1099 struct Harvest {
1100 std::size_t capacity = 1;
1101 std::vector<ecs::EntityHandle> workers;
1102 };
1103
1104 COMPONENT(Identity, identity)
1105 COMPONENT(Position, position)
1106 COMPONENT(Stock, stock)
1107 COMPONENT(Harvest, harvest)
1108
1109
1115 [[nodiscard]] static ResourceNode* createResourceNode(SubjectRef subject = {});
1116};
1117
1119class Player : public ecs::Entity {
1120public:
1122 ENTITY(Player, ecs::Entity)
1123
1124
1125 void release() override { ecs::DestroyEntity(this); }
1126
1128 struct Identity {
1129 ecs::EntityHandle self{};
1131 std::string displayName;
1132 };
1138 struct Economy {
1140 };
1142 struct Social {
1144 };
1146 struct Selection {
1147 std::vector<ecs::EntityHandle> units;
1148 std::vector<ecs::EntityHandle> buildings;
1150 std::uint64_t revision = 0;
1152 SimulationTick tick = SimulationTick::zero();
1153 };
1158 COMPONENT(Identity, identity)
1159 COMPONENT(Authority, authority)
1160 COMPONENT(Economy, economy)
1161 COMPONENT(Social, social)
1162 COMPONENT(Selection, selection)
1163 COMPONENT(GameEvent, eventStream)
1164
1165
1174 [[nodiscard]] static Player* createPlayer(SubjectRef subject = {});
1175};
1176
1178class EVENGINE_API_DOMAINS Faction : public ecs::Entity {
1179public:
1181 ENTITY(Faction, ecs::Entity)
1182
1183
1184 void release() override { ecs::DestroyEntity(this); }
1185
1187 struct Identity {
1188 ecs::EntityHandle self{};
1190 std::string displayName;
1191 };
1197 struct Economy {
1199 };
1201 struct Social {
1203 };
1205 struct Members {
1206 std::vector<ecs::EntityHandle> units;
1207 std::vector<ecs::EntityHandle> buildings;
1208 };
1214 struct Strategy {
1218 int desiredWorkers = 0;
1219 int attackThreshold = 1;
1220 float thinkInterval = 1.0f;
1221 float thinkAccumulator = 0.0f;
1222 float formationSpacing = 1.1f;
1223 bool enabled = false;
1224 };
1226 struct Workforce {
1227 bool autoConstruction = false;
1228 bool autoRepair = false;
1229 std::size_t maxBuildersPerSite = 2;
1230 std::size_t maxRepairersPerBuilding = 2;
1231 std::size_t reserveWorkers = 0;
1232 };
1236 struct Reserve {
1237 std::int64_t amount = 0;
1238 int minimumPriority = 0;
1239 };
1240 std::map<std::string, Reserve> resourceReserves;
1241 };
1243 struct Intel {
1245 struct Contact {
1247 std::string kind;
1249 double ageSeconds = 0.0;
1250 bool visible = false;
1251 bool detected = false;
1252 };
1254 bool enabled = false;
1255 std::vector<Contact> contacts;
1256 };
1258 struct Technology {
1259 std::vector<std::string> unlocked;
1260 std::vector<std::string> consumedTasks;
1262 std::map<std::string, Value::Object> unlockedDefinitions;
1263 };
1264
1265 COMPONENT(Identity, identity)
1266 COMPONENT(Authority, authority)
1267 COMPONENT(Economy, economy)
1268 COMPONENT(Social, social)
1269 COMPONENT(Members, members)
1270 COMPONENT(GameEvent, eventStream)
1271 COMPONENT(Strategy, strategy)
1272 COMPONENT(Workforce, workforce)
1273 COMPONENT(ProductionPolicy, productionPolicy)
1274 COMPONENT(Intel, intel)
1275 COMPONENT(Technology, technology)
1276
1277
1286 [[nodiscard]] static Faction* createFaction(SubjectRef subject = {});
1287};
1288
1292enum class MatchPhase : std::uint8_t { Setup, Running, Finished };
1293
1295class EVENGINE_API_DOMAINS Match : public ecs::Entity {
1296public:
1298 ENTITY(Match, ecs::Entity)
1300 void release() override { ecs::DestroyEntity(this); }
1301
1303 struct Identity {
1304 ecs::EntityHandle self{};
1306 };
1308 struct Rules {
1309 VictoryRule rule = VictoryRule::Annihilation;
1310 std::string archetype;
1311 double targetValue = 0.0;
1312 };
1316 struct Entry {
1318 int team = 0;
1319 bool eliminated = false;
1320 bool surrendered = false;
1321 std::string reason;
1322 };
1323 std::vector<Entry> entries;
1324 };
1326 struct State {
1327 MatchPhase phase = MatchPhase::Setup;
1328 int winningTeam = -1;
1329 std::uint64_t updateSequence = 0;
1330 };
1332 struct Events {
1334 struct Event {
1335 std::uint64_t sequence = 0;
1336 std::string kind;
1338 int team = -1;
1339 std::string reason;
1340 };
1341 std::vector<Event> values;
1342 };
1343
1344 COMPONENT(Identity, identity)
1345 COMPONENT(Rules, rules)
1346 COMPONENT(Participants, participants)
1347 COMPONENT(State, state)
1348 COMPONENT(Events, events)
1349
1350
1356 [[nodiscard]] static Match* createMatch(SubjectRef subject = {});
1357};
1358
1359} // namespace eve::rts
LogicalId target
double value
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float duration
int subject
Definition AnimSmr.cpp:163
Owner-aware canonical attribute state shared by gameplay adapters.
int priority
float phase
Definition CaveMesh.cpp:58
Deterministic damage, poise, hit-reaction and knockback resolution.
eve::resource::CostSpec cost
std::map< std::string, Var > values
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float maximum[3]
const GltfImportRequest & request
std::uint32_t alive
std::uint32_t capacity
Strong identity values shared by persistence, content and logical-name APIs.
TokenKind kind
Range range
std::array< float, 4 > rotation
std::array< float, 3 > position
int level
const std::string * tag
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::uint64_t revision
float radius
std::string action
Definition PlayHost.cpp:117
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
std::string taskId
RTS effect adapter with morale, suppression and production policies.
Move-only, checked operation results for the common layer.
double current
Stable reference to a runtime gameplay subject.
bool placed
Battle::Events events
LogicalId definition
SimulationTick tick
bool visible
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
V3 heading
Definition TreeMesh.cpp:292
std::map< std::string, std::span< const std::uint8_t > > members
uint32_t index
const UnitySourceAsset & source
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Signed, fixed-resolution simulation duration in nanoseconds.
Definition Time.h:43
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
Canonical attributes component adapter, backed by attributes::AttributeSet.
Definition RTSTypes.h:323
AttributeComponent & operator=(AttributeComponent &&other) noexcept
Operator =.
AttributeComponent(AttributeComponent &&other) noexcept
Attribute component.
~AttributeComponent()
Attribute component.
RTS building domain root with placement and production composition.
Definition RTSTypes.h:840
Validates a typed selection and fans one command out in formation order.
Definition RTSSystems.h:215
Faction domain root; membership is a set of typed runtime handles.
Definition RTSTypes.h:1178
Independent match composition root; factions may participate in different matches.
Definition RTSTypes.h:1295
Generic orders component adapter; the queue remains the sole order owner.
Definition RTSTypes.h:385
Player domain root; selection is RTS-local, authority/economy/social are links.
Definition RTSTypes.h:1119
Production adapter whose queue owns all task state.
Definition RTSTypes.h:438
~ProductionComponent()
Production component.
ProductionComponent(ProductionComponent &&other) noexcept
Production component.
ProductionComponent & operator=(ProductionComponent &&other) noexcept
Operator =.
Entity-local RTS effect component backed by the canonical adapter.
Definition RTSEffects.h:118
Coordinates Orders, Production, Action and resource payment.
Owns RTS root entities and coordinates the phase-one systems.
Definition RTS.h:63
Harvestable RTS resource node; deposited balances are owned by an external resource account.
Definition RTSTypes.h:1071
Entity-local sorted tags; this is the RTS entity's tag authority.
Definition RTSTypes.h:153
const std::vector< std::string > & values() const noexcept
Return tags in deterministic order.
Definition RTSTypes.h:162
RTS unit domain root.
Definition RTSTypes.h:495
const char * combatStanceName(CombatStance stance) noexcept
Return the stable lower-case spelling of a combat stance. @ownership Returns a borrowed pointer to im...
Definition RTSTypes.cpp:168
OrderKind
Commands shared by movement, combat, construction and gathering.
Definition RTSTypes.h:64
MatchPhase
Lifecycle of one independent RTS match root.
Definition RTSTypes.h:1292
CombatStance
Automatic target-acquisition policy for an RTS unit.
Definition RTSTypes.h:54
AbilityTarget
Target relationship accepted by one RTS ability.
Definition RTSTypes.h:130
const char * orderKindName(OrderKind kind) noexcept
Return the stable lower-case spelling of an RTS order kind.
Definition RTSTypes.cpp:177
VictoryRule
Supported deterministic RTS victory policies.
Definition RTSTypes.h:1290
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Mutable combat state owned by the gameplay domain for one subject.
Definition Damage.h:37
Validated input used to create a domain-neutral production task.
Definition Production.h:137
Typed ability policy; lifecycle effects remain owned by the canonical effect container.
Definition RTSTypes.h:133
std::string damageType
Definition RTSTypes.h:138
AbilityTarget target
Definition RTSTypes.h:136
std::int64_t resourceCost
Definition RTSTypes.h:142
std::string resourceType
Definition RTSTypes.h:137
RTSEffectDefinition effect
Definition RTSTypes.h:149
LogicalId casterDefinition
Definition RTSTypes.h:135
ActionLinkTag public API.
Definition RTSTypes.h:298
AuthorityLinkTag public API.
Definition RTSTypes.h:306
BuildingLinkTag public API.
Definition RTSTypes.h:282
Deterministic contested capture state.
Definition RTSTypes.h:920
Automatic targeting policy for a stationary defensive building.
Definition RTSTypes.h:958
std::map< std::string, float > targetPriorities
Definition RTSTypes.h:970
Static command provider and hostile jamming policy.
Definition RTSTypes.h:1016
Construction progress and generation-checked assigned builders.
Definition RTSTypes.h:897
std::vector< ecs::EntityHandle > builders
Definition RTSTypes.h:901
Logical building definition identity.
Definition RTSTypes.h:855
Resource delivery policy; actual balances remain in the economy provider.
Definition RTSTypes.h:928
std::vector< std::string > acceptedResources
Definition RTSTypes.h:929
Economy account/provider link.
Definition RTSTypes.h:873
Lifecycle-only effects.
Definition RTSTypes.h:885
RTSEffectComponent values
Definition RTSTypes.h:886
Owning faction link.
Definition RTSTypes.h:893
rts::FactionLink link
Definition RTSTypes.h:894
Building garrison capacity and generation-checked occupants.
Definition RTSTypes.h:973
std::vector< ecs::EntityHandle > occupants
Definition RTSTypes.h:976
Runtime identity.
Definition RTSTypes.h:849
Last indirect-fire exposure for static artillery and counter-battery observation.
Definition RTSTypes.h:1025
RTS infrastructure projection; economy balances remain owned by the linked provider.
Definition RTSTypes.h:1005
Building health and repair economy configuration.
Definition RTSTypes.h:904
combat::CombatState state
Definition RTSTypes.h:905
Generic building orders.
Definition RTSTypes.h:877
OrderComponent values
Definition RTSTypes.h:878
Placement world key and authoritative cell state.
Definition RTSTypes.h:859
Canonical production queue.
Definition RTSTypes.h:869
ProductionComponent values
Definition RTSTypes.h:870
Rally order copied to newly produced units.
Definition RTSTypes.h:933
std::string reinforcementPolicyPausedTask
Definition RTSTypes.h:949
std::map< std::string, std::size_t > reinforcementTypeLimits
Definition RTSTypes.h:945
std::string blockedProductionTask
Definition RTSTypes.h:941
std::vector< ecs::EntityHandle > reinforcements
Definition RTSTypes.h:943
std::map< std::string, std::string > reinforcementFallbacks
Definition RTSTypes.h:947
std::map< std::string, int > reinforcementTypePriorities
Definition RTSTypes.h:946
std::vector< std::string > settledProductionTasks
Definition RTSTypes.h:942
Settlement provider link.
Definition RTSTypes.h:889
RTS shield layer for structures; canonical CombatState remains health authority.
Definition RTSTypes.h:912
Static ammunition stock and transfer policy for completed buildings.
Definition RTSTypes.h:979
std::string productionResource
Definition RTSTypes.h:985
Building-local tags.
Definition RTSTypes.h:881
Upgrade ids already projected onto this building.
Definition RTSTypes.h:1001
std::vector< std::string > applied
Definition RTSTypes.h:1002
Static vision contribution projected into a faction-owned canonical map FOV provider.
Definition RTSTypes.h:991
Canonical weapon entity used by an armed building.
Definition RTSTypes.h:954
One domain-neutral command submitted to a unit's generic order queue.
Definition RTSTypes.h:101
std::string definitionId
Definition RTSTypes.h:104
ecs::EntityHandle targetEntity
Definition RTSTypes.h:107
Result< void > validate() const
Validate coordinates and command metadata without mutating state.
Definition RTSTypes.cpp:201
WorldPosition target
Definition RTSTypes.h:103
WorldPosition secondaryTarget
Definition RTSTypes.h:108
ContainerLinkTag public API.
Definition RTSTypes.h:284
CrowdLinkTag public API.
Definition RTSTypes.h:296
EconomyLinkTag public API.
Definition RTSTypes.h:304
Typed link tag for links to another ECS entity.
Definition RTSTypes.h:169
FactionLinkTag public API.
Definition RTSTypes.h:276
Authority provider link.
Definition RTSTypes.h:1193
Economy account/provider link.
Definition RTSTypes.h:1197
Event stream/provider link.
Definition RTSTypes.h:1210
Runtime identity.
Definition RTSTypes.h:1187
Persistent last-known enemy contacts derived from the faction's canonical FOV provider.
Definition RTSTypes.h:1243
std::vector< Contact > contacts
Definition RTSTypes.h:1255
Authoritative faction membership handles.
Definition RTSTypes.h:1205
std::vector< ecs::EntityHandle > buildings
Definition RTSTypes.h:1207
std::vector< ecs::EntityHandle > units
Definition RTSTypes.h:1206
Cross-factory resource floors reserved for production at or above a priority threshold.
Definition RTSTypes.h:1234
std::map< std::string, Reserve > resourceReserves
Definition RTSTypes.h:1240
Social graph/provider link.
Definition RTSTypes.h:1201
Deterministic high-level production and attack policy for an AI-controlled faction.
Definition RTSTypes.h:1214
Completed research definitions and canonical production tasks already consumed.
Definition RTSTypes.h:1258
std::vector< std::string > consumedTasks
Definition RTSTypes.h:1260
std::map< std::string, Value::Object > unlockedDefinitions
Validated immutable rule payload accepted for each completed research id.
Definition RTSTypes.h:1262
std::vector< std::string > unlocked
Definition RTSTypes.h:1259
Deterministic idle-worker assignment policy for construction and repair.
Definition RTSTypes.h:1226
GameEventLinkTag public API.
Definition RTSTypes.h:310
Deterministic retained lifecycle events.
Definition RTSTypes.h:1332
std::vector< Event > values
Definition RTSTypes.h:1341
Runtime and persistent identity.
Definition RTSTypes.h:1303
One faction's team and elimination projection.
Definition RTSTypes.h:1314
std::vector< Entry > entries
Definition RTSTypes.h:1323
Configured victory rule; immutable while the match is running.
Definition RTSTypes.h:1308
std::string archetype
Definition RTSTypes.h:1310
Authoritative match outcome.
Definition RTSTypes.h:1326
Complete RTS order projection snapshot; entity handles must be rebound by the owning domain.
Definition RTSTypes.h:388
std::map< std::string, CommandSpec > extended
Definition RTSTypes.h:390
Owning projection of the active generic order used by RTS systems.
Definition RTSTypes.h:117
ecs::EntityHandle targetEntity
Definition RTSTypes.h:122
WorldPosition secondaryTarget
Definition RTSTypes.h:123
std::string definitionId
Definition RTSTypes.h:121
WorldPosition target
Definition RTSTypes.h:120
PlacementLinkTag public API.
Definition RTSTypes.h:302
Authority provider link.
Definition RTSTypes.h:1134
Economy account/provider link.
Definition RTSTypes.h:1138
Event stream/provider link.
Definition RTSTypes.h:1155
Runtime identity.
Definition RTSTypes.h:1128
RTS-owned selection handles; handles are generation checked on use.
Definition RTSTypes.h:1146
std::vector< ecs::EntityHandle > units
Definition RTSTypes.h:1147
std::vector< ecs::EntityHandle > buildings
Definition RTSTypes.h:1148
Social graph/provider link.
Definition RTSTypes.h:1142
Typed RTS definition projected to the common lifecycle schema.
Definition RTSEffects.h:35
ResourceNodeLinkTag public API.
Definition RTSTypes.h:280
Concurrent worker capacity and current generation-checked assignments.
Definition RTSTypes.h:1099
std::vector< ecs::EntityHandle > workers
Definition RTSTypes.h:1101
Runtime and persistent identity.
Definition RTSTypes.h:1080
Authoritative world position and interaction radius.
Definition RTSTypes.h:1086
Authoritative remaining resource stock.
Definition RTSTypes.h:1092
SensingLinkTag public API.
Definition RTSTypes.h:292
Typed link tag for a provider-owned capability or registry entry.
Definition RTSTypes.h:229
SettlementLinkTag public API.
Definition RTSTypes.h:300
SocialLinkTag public API.
Definition RTSTypes.h:308
SteeringLinkTag public API.
Definition RTSTypes.h:294
Ability cooldowns and an optional deterministic cast/channel in progress.
Definition RTSTypes.h:673
std::optional< Channel > channel
Definition RTSTypes.h:686
std::vector< Cooldown > cooldowns
Definition RTSTypes.h:685
Shared action runtime/provider link.
Definition RTSTypes.h:548
Indirect-fire deployment and deterministic area-fire policy.
Definition RTSTypes.h:740
WorldPosition lastFirePosition
Definition RTSTypes.h:759
WorldPosition departedPosition
Definition RTSTypes.h:747
WorldPosition relocationTarget
Definition RTSTypes.h:746
Canonical attribute state.
Definition RTSTypes.h:514
AttributeComponent values
Definition RTSTypes.h:515
Capture contribution while executing a Capture order.
Definition RTSTypes.h:689
RTS stance and pursuit limits used by automatic combat policies.
Definition RTSTypes.h:610
std::map< std::string, float > targetPriorities
Definition RTSTypes.h:628
Command-network policy and derived connection state for a mobile unit or relay.
Definition RTSTypes.h:655
Unit containment state for transports and building garrisons.
Definition RTSTypes.h:693
std::vector< ecs::EntityHandle > occupants
Definition RTSTypes.h:696
Crowd provider link.
Definition RTSTypes.h:538
Logical unit definition identity.
Definition RTSTypes.h:510
Canonical combat durability state consumed by combat::DamageRuntime.
Definition RTSTypes.h:631
combat::CombatState state
Definition RTSTypes.h:632
Lifecycle-only active effects.
Definition RTSTypes.h:522
RTSEffectComponent values
Definition RTSTypes.h:523
Owning faction link.
Definition RTSTypes.h:556
rts::FactionLink link
Definition RTSTypes.h:557
Runtime identity and logical unit definition.
Definition RTSTypes.h:504
std::string displayName
Definition RTSTypes.h:507
Suppression, recovery, retreat policy, and friendly morale aura.
Definition RTSTypes.h:724
Authoritative kinematic state used by the phase-one move slice.
Definition RTSTypes.h:560
RTS projection of a canonical map path; the map provider remains the grid authority.
Definition RTSTypes.h:569
WorldPosition patrolOrigin
Definition RTSTypes.h:574
std::vector< WorldPosition > waypoints
Definition RTSTypes.h:570
std::optional< WorldPosition > formationTarget
Derived moving slot; rebuilt each step, excluded from saves.
Definition RTSTypes.h:582
WorldPosition plannedGoal
Definition RTSTypes.h:573
std::optional< WorldPosition > trafficRecoveryTarget
Derived evacuation step; does not replace the order.
Definition RTSTypes.h:583
Generic command/order state.
Definition RTSTypes.h:526
OrderComponent values
Definition RTSTypes.h:527
Sensing provider link.
Definition RTSTypes.h:530
Settlement provider link.
Definition RTSTypes.h:552
RTS shield layer consumed before canonical health damage and regenerated deterministically.
Definition RTSTypes.h:636
Steering provider link.
Definition RTSTypes.h:534
Tactical ammunition logistics; weapon ammunition remains authoritative in WeaponEntity.
Definition RTSTypes.h:699
WorldPosition rendezvousPoint
Definition RTSTypes.h:717
WorldPosition returnPoint
Definition RTSTypes.h:716
Escort geometry and combat-group coordination state.
Definition RTSTypes.h:764
SubjectRef escortInterceptTarget
Definition RTSTypes.h:783
Entity-local tags.
Definition RTSTypes.h:518
Upgrade ids already projected onto this unit, preventing repeated multiplicative application.
Definition RTSTypes.h:790
std::vector< std::string > applied
Definition RTSTypes.h:791
Persistent combat experience and deterministic veteran/elite modifiers.
Definition RTSTypes.h:644
Vision contribution projected into a faction-owned canonical map FOV provider.
Definition RTSTypes.h:586
Weapon entity link.
Definition RTSTypes.h:544
Worker gathering and delivery state; balances remain owned by the linked economy account.
Definition RTSTypes.h:598
ResourceNodeLink resourceNode
Definition RTSTypes.h:600
std::string resourceType
Definition RTSTypes.h:599
BuildingLink dropoff
Definition RTSTypes.h:601
WeaponLinkTag public API.
Definition RTSTypes.h:278
Two-dimensional deterministic RTS world position.
Definition RTSTypes.h:48