载入中...
搜索中...
未找到
RTSTypes.cpp
浏览该文件的文档.
17bool finitePosition(WorldPosition position) { return std::isfinite(position.x) && std::isfinite(position.y); }
46Result<OrderRecord> projectOrder(const orders::Order& order, const CommandSpec* extended = nullptr) {
50 DiagnosticCode::InvariantViolation, "generic order contains an unknown RTS kind", "order.kind"));
78 DiagnosticCode::InvariantViolation, "generic order payload contains a non-finite target", "order.payload"));
203 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS command target must contain finite coordinates", "target"));
206 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS command timeout must be finite and non-negative", "timeoutSeconds"));
209 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS command radius must be finite and non-negative", "radius"));
228 case OrderKind::SupplyRelay: return Result<void>::success(Status::success(StatusCode::Applied));
230 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS command kind is invalid", "kind"));
234 if (tag.empty()) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS tag must not be empty", "tag"));
237 if (it != values_.end() && *it == tag) return Result<void>::success(Status::success(StatusCode::NoOp));
243 if (tag.empty()) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS tag must not be empty", "tag"));
246 if (it == values_.end() || *it != tag) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "RTS tag is not present", "tag"));
271AttributeComponent& AttributeComponent::operator=(AttributeComponent&& other) noexcept = default;
275 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS attribute base requires a non-empty finite value", "attribute"));
283 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS attribute delta requires a non-empty finite value", "attribute"));
307const eve::attributes::AttributeModifier* AttributeComponent::modifierAt(int index) const noexcept {
316bool AttributeComponent::initialized() const noexcept { return impl_ != nullptr && impl_->values.initialized(); }
318Result<void> AttributeComponent::initialize(std::span<const eve::attributes::AttributeSnapshotBase> values) {
323bool AttributeComponent::isStale() const noexcept { return impl_ != nullptr && impl_->values.isStale(); }
334 DiagnosticCode::InvariantViolation, "RTS attribute component is not initialized", "attributes"));
376 auto queued = impl_->queue.append(orderKindName(command.kind), command.priority, command.timeoutSeconds);
382 DiagnosticCode::InvariantViolation, "generic order queue lost its newly appended command", "order"));
399 auto queued = impl_->queue.replace(orderKindName(command.kind), command.priority, command.timeoutSeconds);
405 DiagnosticCode::InvariantViolation, "generic order queue lost its replacement command", "order"));
429 if (orderId.empty()) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS order id must not be empty", "orderId"));
431 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "RTS order id is not present", "orderId"));
433 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Conflict, "RTS order is not active or is already terminal", "orderId"));
440 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS order failure requires an id and reason", "order"));
442 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "RTS order id is not present", "orderId"));
444 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Conflict, "RTS order is not active", "orderId"));
451 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "RTS order cancellation requires an id and reason", "order"));
453 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "RTS order id is not present", "orderId"));
455 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Conflict, "RTS order is already terminal", "orderId"));
509 return Result<void>::failure(Diagnostic::error(DiagnosticCode::Conflict, "RTS order extension references an absent canonical queue record", "orders.extended"));
550ProductionComponent& ProductionComponent::operator=(ProductionComponent&& other) noexcept = default;
559 return impl_->queue.enqueue(owner, kind, product, eve::Value(eve::Value::Object{}), duration.seconds(), priority);
580OptionalRef<const production::ProductionTask> ProductionComponent::find(std::string_view taskId) {
605std::vector<production::ProductionTask> ProductionComponent::readyToSettle(std::string_view kind) const {
610 if (task && task->get().kind == kind && task->get().state == production::TaskState::ReadyToSettle)
616Result<void> ProductionComponent::settle(std::string_view taskId, production::ProductionSettlementReceipt receipt) {
626 Diagnostic::error(DiagnosticCode::Failed, "RTS production component is unavailable", "production"));
Owning effect storage and lifecycle-only executor.
RTS domain roots and composition-only components.
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
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Canonical selected-attribute storage with owner and revision checks.
Definition AttributeProjection.h:55
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:581
Generic priority order queue with no gameplay or entity semantics.
Definition CommandQueue.h:89
eve::Result< void > restore(std::string_view json)
Restores a command queue transactionally from a JSON snapshot.
Definition CommandQueue.cpp:476
eve::OptionalRef< Order > find(const std::string &id)
Returns an order by stable id, including terminal history.
Definition CommandQueue.cpp:384
Generic multi-owner, multi-slot continuous-progress work queue.
Definition Production.h:200
eve::Result< std::string > snapshot() const
Serializes the complete queue as deterministic JSON.
Definition ProductionPersistence.cpp:148
eve::Result< void > restore(std::string_view json)
Transactionally restores a snapshot; failure preserves current state.
Definition ProductionPersistence.cpp:287
Canonical attributes component adapter, backed by attributes::AttributeSet.
Definition RTSTypes.h:323
std::size_t modifierCount() const noexcept
Return the number of canonical modifiers.
Definition RTSTypes.cpp:303
Result< void > modifyBase(std::string_view attribute, double delta)
Add to one authoritative base value.
Definition RTSTypes.cpp:281
AttributeComponent & operator=(const AttributeComponent &other)
Operator =.
Definition RTSTypes.cpp:265
Result< void > bindOwner(ecs::EntityHandle owner)
Bind the canonical attribute state to an ECS owner generation.
Definition RTSTypes.cpp:311
Result< eve::attributes::ModifierId > addModifier(eve::attributes::AttributeModifier modifier)
Add a modifier with the common source/priority/sequence contract.
Definition RTSTypes.cpp:325
bool has(std::string_view attribute) const
Return whether an attribute exists.
Definition RTSTypes.cpp:289
Result< eve::attributes::AttributeProjectionSnapshot > snapshot(std::span< const std::string_view > attributes) const
Capture selected values with owner and revision metadata.
Definition RTSTypes.cpp:330
Result< void > setBase(std::string_view attribute, double value)
Set one authoritative base value.
Definition RTSTypes.cpp:273
bool isStale() const noexcept
Return whether the canonical attribute owner is stale.
Definition RTSTypes.cpp:323
Result< void > initialize(std::span< const eve::attributes::AttributeSnapshotBase > values)
Seed unit stat bases once without replacing existing values.
Definition RTSTypes.cpp:318
bool initialized() const noexcept
Return whether initial unit stat bases have been installed.
Definition RTSTypes.cpp:316
const eve::attributes::AttributeModifier * modifierAt(int index) const noexcept
Return a canonical modifier in deterministic sequence order.
Definition RTSTypes.cpp:307
Result< double > getFinal(std::string_view attribute, double fallback=0.0) const
Read the deterministic final value or a caller-supplied default.
Definition RTSTypes.cpp:293
Result< void > restore(const eve::attributes::AttributeProjectionSnapshot &snapshot, Revision expectedRevision)
Restore selected values after generation and revision checks.
Definition RTSTypes.cpp:338
RTS building domain root with placement and production composition.
Definition RTSTypes.h:840
static Building * createBuilding(SubjectRef subject={}, LogicalId definition={})
Create a building and initialize its self handle and identity.
Definition RTSTypes.cpp:656
Faction domain root; membership is a set of typed runtime handles.
Definition RTSTypes.h:1178
static Faction * createFaction(SubjectRef subject={})
Create a faction and initialize its self handle and identity.
Definition RTSTypes.cpp:684
Independent match composition root; factions may participate in different matches.
Definition RTSTypes.h:1295
static Match * createMatch(SubjectRef subject={})
Create a match and initialize every composition component. @ownership The active ECS table owns the e...
Definition RTSTypes.cpp:692
Generic orders component adapter; the queue remains the sole order owner.
Definition RTSTypes.h:385
Result< std::string > snapshot() const
Serialize the canonical generic queue for persistence/replay.
Definition RTSTypes.cpp:473
Result< Snapshot > snapshotState() const
Capture the generic queue and every RTS-specific payload atomically.
Definition RTSTypes.cpp:491
Result< void > complete(std::string_view orderId)
Complete the active order by its stable queue id.
Definition RTSTypes.cpp:428
~OrderComponent()
Result< void > restoreState(const Snapshot &snapshot)
Transactionally restore a complete RTS order projection.
Definition RTSTypes.cpp:501
Result< OrderRecord > current() const
Project the active order or return NotFound when idle.
Definition RTSTypes.cpp:419
Result< void > restore(std::string_view json)
Transactionally restore the canonical generic queue.
Definition RTSTypes.cpp:480
std::size_t orderCount() const noexcept
Return the number of retained order records.
Definition RTSTypes.cpp:469
Result< std::string > replace(const CommandSpec &command, int formationSlot=-1)
Replace unfinished commands with one new command.
Definition RTSTypes.cpp:395
Result< void > cancel(std::string_view orderId, std::string_view reason)
Cancel an active or queued order by its stable queue id.
Definition RTSTypes.cpp:449
OrderComponent & operator=(const OrderComponent &other)
Definition RTSTypes.cpp:353
bool empty() const noexcept
Return whether no order is currently retained.
Definition RTSTypes.cpp:460
Result< void > fail(std::string_view orderId, std::string_view reason)
Fail the active order by its stable queue id.
Definition RTSTypes.cpp:438
Result< std::string > enqueue(const CommandSpec &command, int formationSlot=-1)
Append a Move/Attack/Build/Gather command.
Definition RTSTypes.cpp:372
Player domain root; selection is RTS-local, authority/economy/social are links.
Definition RTSTypes.h:1119
static Player * createPlayer(SubjectRef subject={})
Create a player and initialize its self handle and identity.
Definition RTSTypes.cpp:676
Production adapter whose queue owns all task state.
Definition RTSTypes.h:438
Result< void > cancel(std::string_view taskId, std::string_view reason="cancelled")
Cancel a non-terminal task through the canonical queue.
Definition RTSTypes.cpp:598
Result< void > resume(std::string_view taskId)
Resume a paused task through the canonical queue.
Definition RTSTypes.cpp:591
Result< void > pause(std::string_view taskId)
Pause a queued or running task through the canonical queue.
Definition RTSTypes.cpp:584
Result< void > restore(std::string_view json)
Transactionally restore the canonical production queue.
Definition RTSTypes.cpp:630
Result< void > settle(std::string_view taskId, production::ProductionSettlementReceipt receipt)
Commit one domain settlement with an idempotency receipt.
Definition RTSTypes.cpp:616
Result< std::string > enqueue(std::string_view owner, std::string_view kind, std::string_view product, Duration duration, int priority=0)
Enqueue a production task with an injected simulation duration.
Definition RTSTypes.cpp:552
std::size_t taskCount() const noexcept
Return the number of retained tasks.
Definition RTSTypes.cpp:572
ProductionComponent & operator=(const ProductionComponent &other)
Operator =.
Definition RTSTypes.cpp:544
OptionalRef< const production::ProductionTask > taskAt(int index)
Borrow a retained canonical task by enqueue index.
Definition RTSTypes.cpp:576
Result< void > advance(const SimulationStep &step)
Advance the queue using a caller-owned deterministic step.
Definition RTSTypes.cpp:567
std::vector< production::ProductionTask > readyToSettle(std::string_view kind) const
Copy work-complete tasks of one kind that await domain settlement.
Definition RTSTypes.cpp:605
Result< std::string > snapshot() const
Serialize the canonical production queue for persistence/replay.
Definition RTSTypes.cpp:623
OptionalRef< const production::ProductionTask > find(std::string_view taskId)
Borrow a retained canonical task by stable task id.
Definition RTSTypes.cpp:580
Harvestable RTS resource node; deposited balances are owned by an external resource account.
Definition RTSTypes.h:1071
static ResourceNode * createResourceNode(SubjectRef subject={})
Create a resource node and initialize all composition components. @ownership The active ECS table own...
Definition RTSTypes.cpp:668
bool contains(std::string_view tag) const noexcept
Test exact tag membership.
Definition RTSTypes.cpp:251
Result< void > add(std::string_view tag)
Add a tag in deterministic lexical order.
Definition RTSTypes.cpp:233
Result< void > remove(std::string_view tag)
Remove a tag, returning NotFound when it is absent.
Definition RTSTypes.cpp:242
static Unit * createUnit(SubjectRef subject={}, LogicalId definition={})
Create a unit and initialize its self handle and identity.
Definition RTSTypes.cpp:644
@ ReadyToSettle
Definition RTS.cpp:24
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
@ BoardTransport
@ Repair
@ Garrison
@ ReturnCargo
@ HoldPosition
@ Escort
@ AttackGround
@ AttackMove
@ Capture
@ Gather
@ Build
@ SuppressArea
@ Attack
@ Patrol
@ SupplyRelay
@ Resupply
@ Defensive
@ Aggressive
@ Passive
const char * orderKindName(OrderKind kind) noexcept
Return the stable lower-case spelling of an RTS order kind.
Definition RTSTypes.cpp:177
@ InvalidArgument
@ NotFound
@ InvariantViolation
@ Failed
@ ParseError
@ Conflict
@ NoOp
@ Applied
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
Definition Container.h:602
One canonical runtime modifier applied to one named attribute.
Definition AttributeSet.h:96
Transaction-safe snapshot of selected attributes and their modifiers.
Definition AttributeProjection.h:40
Validated input used to create a domain-neutral production task.
Definition Production.h:137
Owning proof that a domain consumer published one task exactly once.
Definition Production.h:46
attributes::AttributeProjection values
Definition RTSTypes.cpp:258
One domain-neutral command submitted to a unit's generic order queue.
Definition RTSTypes.h:101
Result< void > validate() const
Validate coordinates and command metadata without mutating state.
Definition RTSTypes.cpp:201
std::map< std::string, CommandSpec > extended
Definition RTSTypes.cpp:346
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
Impl()=default
Impl & operator=(const Impl &other)
Definition RTSTypes.cpp:532