载入中...
搜索中...
未找到
Tactics.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
9#include "common/Module.h"
11#include "tactics/Interaction.h"
16
17#include <cstddef>
18#include <vector>
19
20namespace eve::tactics {
21
26
36 ~TacticsBattleSession() noexcept;
37
38 ecs::EntityHandle battle{};
39};
40
53public:
55
57 Tactics();
59 ~Tactics() override;
60
63 [[nodiscard]] std::string_view gameplayDomain() const noexcept override;
66 [[nodiscard]] std::vector<SubjectRef> gameplayInstances() const override;
69 [[nodiscard]] Result<GameplayObservation> observeGameplay(const GameplaySession& session,
70 SubjectRef instance) const override;
73 [[nodiscard]] Result<std::vector<GameplayActionDescriptor>> availableGameplayActions(
74 const GameplaySession& session, SubjectRef instance, SubjectRef subject) const override;
77 [[nodiscard]] Result<GameplayCommandReceipt> submitGameplay(const GameplaySession& session,
78 SubjectRef instance,
79 const GameplayCommand& command) override;
82 [[nodiscard]] Result<GameplayObservation> advanceGameplay(const GameplaySession& session,
83 SubjectRef instance,
84 const SimulationStep& step) override;
87 [[nodiscard]] Result<std::vector<GameplayEvent>> gameplayEvents(const GameplaySession& session,
88 SubjectRef instance,
89 std::uint64_t afterSequence) const override;
90
92 [[nodiscard]] Result<ecs::EntityHandle> newBattle(SubjectRef subject, std::uint64_t seed = 0);
94 [[nodiscard]] Result<ecs::EntityHandle> newSide(ecs::EntityHandle battle, SubjectRef subject);
99 [[nodiscard]] Result<ecs::EntityHandle> newUnit(ecs::EntityHandle battle, ecs::EntityHandle side,
102
104 [[nodiscard]] Result<void> addCell(ecs::EntityHandle battle, Cell cell, CellState state = {});
106 [[nodiscard]] Result<void> setTopology(ecs::EntityHandle battle, BoardTopology topology);
114 [[nodiscard]] Result<void> start(ecs::EntityHandle battle, std::string_view policyId);
116 [[nodiscard]] Result<BattlePhase> advance(ecs::EntityHandle battle, const SimulationStep& step);
118 [[nodiscard]] Result<void> endTurn(ecs::EntityHandle battle, SubjectRef actor);
133 [[nodiscard]] Result<AbilityReceipt> useAbility(ecs::EntityHandle battle, SubjectRef actor,
134 const LogicalId& action, Cell targetCell,
135 SubjectRef targetUnit = {}, std::string payload = {});
136
145 [[nodiscard]] Result<AbilityReceipt> previewAbility(ecs::EntityHandle battle, SubjectRef actor,
146 const LogicalId& action, Cell targetCell,
147 SubjectRef targetUnit = {},
148 std::string_view payload = {});
150 [[nodiscard]] Result<MoveReceipt> moveUnit(ecs::EntityHandle battle, SubjectRef actor, Cell destination);
152 [[nodiscard]] Result<void> faceUnit(ecs::EntityHandle battle, SubjectRef actor, int facing);
154 [[nodiscard]] Result<void> waitUnit(ecs::EntityHandle battle, SubjectRef actor);
156 [[nodiscard]] Result<void> finish(ecs::EntityHandle battle);
157
164 [[nodiscard]] Result<MoveReceipt> previewMove(ecs::EntityHandle battle, SubjectRef actor, Cell destination);
166 [[nodiscard]] Result<void> previewFace(ecs::EntityHandle battle, SubjectRef actor, int facing);
168 [[nodiscard]] Result<void> previewWait(ecs::EntityHandle battle, SubjectRef actor);
169
176 [[nodiscard]] Result<Reachability> reachable(ecs::EntityHandle battle, SubjectRef subject, int budget);
181 [[nodiscard]] Result<std::vector<Cell>> cellsInRange(ecs::EntityHandle battle, Cell origin, int minimum,
182 int maximum, CellRangeMetric metric);
190 [[nodiscard]] Result<TacticalUnit::TurnResources> unitResources(ecs::EntityHandle battle, SubjectRef unit);
191
198 [[nodiscard]] Result<void> addEdge(ecs::EntityHandle battle, Cell from, Cell to, EdgeState state = {});
200 [[nodiscard]] Result<EdgeState> edge(ecs::EntityHandle battle, Cell from, Cell to);
202 [[nodiscard]] std::optional<EdgeState> tryEdge(ecs::EntityHandle battle, Cell from, Cell to);
208 [[nodiscard]] Result<std::string> policyId(ecs::EntityHandle battle);
210 [[nodiscard]] Result<std::size_t> openReaction(ecs::EntityHandle battle, std::uint64_t triggerSequence,
211 std::vector<ReactionCandidate> candidates);
213 [[nodiscard]] Result<ReactionReceipt> acceptReaction(ecs::EntityHandle battle, SubjectRef reactor,
214 const LogicalId& action);
216 [[nodiscard]] Result<void> declineReaction(ecs::EntityHandle battle);
218 [[nodiscard]] Result<void> addObjective(ecs::EntityHandle battle, ObjectiveSpec objective);
220 [[nodiscard]] Result<void> defeatUnit(ecs::EntityHandle battle, SubjectRef unit);
222 [[nodiscard]] Result<std::uint64_t> roll(ecs::EntityHandle battle, const LogicalId& stream);
223
225 [[nodiscard]] Result<BattleStatus> status(ecs::EntityHandle battle);
227 [[nodiscard]] Result<BattlePhase> phase(ecs::EntityHandle battle);
229 [[nodiscard]] Result<SubjectRef> activeUnit(ecs::EntityHandle battle);
231 [[nodiscard]] Result<SnapshotEnvelope> snapshot(ecs::EntityHandle battle,
232 const SnapshotHashProvider& hashProvider);
234 [[nodiscard]] Result<void> restore(ecs::EntityHandle battle, const SnapshotEnvelope& snapshot,
235 const SnapshotHashProvider& hashProvider);
237 [[nodiscard]] Result<std::vector<BattleCommand>> commandsFrom(ecs::EntityHandle battle, Revision revision);
239 [[nodiscard]] Result<void> replay(ecs::EntityHandle battle, std::span<const BattleCommand> commands);
240
251 [[nodiscard]] Result<std::string> snapshotJson(ecs::EntityHandle battle);
252
258 [[nodiscard]] Result<void> restoreJson(ecs::EntityHandle battle, std::string_view json);
259
264 [[nodiscard]] Result<std::string> commandLogJson(ecs::EntityHandle battle, Revision revision);
265
274 [[nodiscard]] Result<void> replayJson(ecs::EntityHandle battle, std::string_view json);
275
285 [[nodiscard]] Result<std::vector<Cell>> visibleCellsInRange(ecs::EntityHandle battle, Cell origin, int minimum,
286 int maximum, CellRangeMetric metric);
287
298 [[nodiscard]] Result<InteractionContext> interactionContext(ecs::EntityHandle battle, SubjectRef controlledUnit);
299
303 [[nodiscard]] std::string_view lineOfSightAlgorithm() const noexcept;
304
315 [[nodiscard]] Result<void> attachLineOfSightBoard(ecs::EntityHandle battle);
316
318 [[nodiscard]] Result<void> detachLineOfSightBoard(ecs::EntityHandle battle);
319
330 [[nodiscard]] Result<std::vector<PresentationCommand>> presentationIntents(ecs::EntityHandle battle,
331 std::uint64_t afterSequence,
332 std::uint64_t transientTicks = 20);
333
340 [[nodiscard]] std::string_view snapshotHashAlgorithm() const noexcept;
341
343 [[nodiscard]] std::size_t battleCount() const noexcept;
345 [[nodiscard]] std::size_t unitCount() const noexcept;
347 [[nodiscard]] std::size_t sideCount() const noexcept;
348
350 [[nodiscard]] static Result<TacticsBattleSessionRef> newSession(SubjectRef subject, std::uint64_t seed = 0);
352 [[nodiscard]] static script::Borrowed<TacticsBattleSession> resolve(TacticsBattleSessionRef reference) noexcept;
354 [[nodiscard]] static Result<void> release(TacticsBattleSessionRef reference);
356 [[nodiscard]] static bool isStale(TacticsBattleSessionRef reference) noexcept;
357
358private:
359 [[nodiscard]] Battle* resolveBattle(ecs::EntityHandle handle) const noexcept;
360 [[nodiscard]] Battle* resolveBattle(SubjectRef subject) const noexcept;
361 [[nodiscard]] TacticalUnit* findUnit(SubjectRef subject) const noexcept;
362 [[nodiscard]] bool owns(const std::vector<ecs::EntityHandle>& handles,
363 const ecs::EntityHandle& handle) const noexcept;
364
365 std::vector<ecs::EntityHandle> battles_;
366 std::vector<ecs::EntityHandle> units_;
367 std::vector<ecs::EntityHandle> sides_;
368 script::RuntimeObjectRegistry<TacticsBattleSession, TacticsBattleSessionTag> sessions_;
369};
370
371} // namespace eve::tactics
Value::Object payload
Duration start
int subject
Definition AnimSmr.cpp:163
std::string from
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
float phase
Definition CaveMesh.cpp:58
#define EVENGINE_API_DOMAINS
Definition Export.h:110
Host-neutral player-equivalent command and observation protocol.
Optional companion surface for gameplay providers that can enumerate instances.
float maximum[3]
float minimum[3]
wgpu::PopErrorScopeStatus status
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
Board interaction state machine that returns intents instead of mutating.
ModuleFacing facing
std::vector< std::weak_ptr< DeviceBytes > > resources
Definition OnnxGpgpu.cpp:55
Topology topology
std::uint64_t revision
std::string action
Definition PlayHost.cpp:117
std::string script
Definition PlayHost.cpp:116
std::uint32_t seed
Definition PointSet.cpp:807
Presentation intents derived from the battle event stream, with an explicit undo.
PrimitiveHandle handle
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
V3 origin
Definition RoadBake.cpp:138
const RoadEdge * edge
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
Checked battle setup and deterministic phase systems.
Cell cell
TacticalUnit * unit
LogicalId definition
std::string policyId
ecs::EntityHandle side
std::optional< ecs::EntityHandle > activeUnit
Versioned battle snapshots with transactional restore.
Deterministic accepted-command replay.
std::optional< InteractionSession > session
Definition Tactics.cpp:39
float step
Definition TreeMesh.cpp:314
std::vector< VegetationPresetCommand > commands
Multi-provider gameplay boundary consumed by input, scripts and automation.
Optional read-only discovery surface implemented beside a gameplay provider.
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
Owns tactics short-root entities and coordinates checked battle setup.
Definition Tactics.h:52
Result< void > replay(const Trace &trace, IEnvironment &environment, double tolerance)
Reset and replay actual actions, checking all observations and failure evidence.
Definition Agent.cpp:258
Result< std::vector< Cell > > visibleCellsInRange(const BoardState &board, const ILineOfSightPolicy &policy, Cell origin, int minimum, int maximum, CellRangeMetric metric)
Cells within a metric range of origin that policy can actually see.
One discoverable domain action and its owning schema projection.
Owning evidence that a gameplay authority accepted one command.
One player-semantic command submitted to a domain authority.
Owning event projection safe across frames and process boundaries.
Immutable owning observation of one authoritative gameplay instance.
Owning authorization context shared by player, script and automation adapters.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Handle plus owner-lifetime epoch for a non-ECS registry object.
One authoritative board cell fact.
Logical board coordinate independent of rendering projection.
Owner tag for script-visible battle-session handles.
Definition Tactics.h:23
Module-owned script session referencing one battle aggregate.
Definition Tactics.h:34
~TacticsBattleSession() noexcept
Releases TacticsBattleSession resources.
Definition Tactics.cpp:479
Initial and per-round tactical resource values for one unit.