载入中...
搜索中...
未找到
Interaction.cpp
浏览该文件的文档.
47InteractionSession::InteractionSession(InteractionContext context) : context_(std::move(context)) {
51 state_ = context_.status == BattleStatus::Ended ? InteractionState::Ended : InteractionState::Blocked;
54 } else if (!context_.controlledUnit.isValid() || context_.activeUnit != context_.controlledUnit) {
72bool InteractionSession::cellInReachable(Cell cell) const { return containsCell(context_.reachableCells, cell); }
74bool InteractionSession::cellInTargetable(Cell cell) const { return containsCell(armedTargets_, cell); }
90 return Result<InteractionIntent>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation,
102 if (!cellInTargetable(cell)) return Result<InteractionIntent>::success(makeIntent(InteractionIntentKind::None, cell));
127Result<void> InteractionSession::armAbility(const LogicalId& action, std::vector<Cell> targetableCells) {
128 if (state_ == InteractionState::Ended || state_ == InteractionState::Blocked || state_ == InteractionState::Resolving)
130 DiagnosticCode::PreconditionViolation, "interaction session cannot arm an ability", "interaction.state"));
133 Diagnostic::error(DiagnosticCode::InvalidArgument, "armed ability requires a logical id", "action"));
144 return Result<InteractionIntent>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation,
157 return Result<InteractionIntent>::success(makeIntent(InteractionIntentKind::None, context_.controlledCell));
164 return Result<InteractionIntent>::success(makeIntent(InteractionIntentKind::Cancel, context_.controlledCell));
169 return Result<InteractionIntent>::failure(Diagnostic::error(DiagnosticCode::PreconditionViolation,
174 DiagnosticCode::PreconditionViolation, "interaction session cannot end the turn", "interaction.state"));
Stable, structured diagnostics shared by engine modules.
Board interaction state machine that returns intents instead of mutating.
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
A disposable, non-authoritative interaction session.
Definition Interaction.h:128
Definition Interaction.cpp:13
@ Running
std::string_view interactionStateName(InteractionState state) noexcept
Human-readable stable spelling of an interaction state (protocol text).
Definition Interaction.cpp:22
@ UseAbilityOn
Declare InteractionIntent::action against cell and optional unit.
@ None
Nothing to do: the click landed somewhere with no meaning in this state.
@ MoveTo
Move the controlled unit onto InteractionIntent::cell.
std::string_view interactionIntentKindName(InteractionIntentKind kind) noexcept
Human-readable stable spelling of an intent kind (protocol text).
Definition Interaction.cpp:34
InteractionState
Where the interaction machine is, as far as the player is concerned.
Definition Interaction.h:29
@ Blocked
Not this controller's turn, or the battle is not accepting input at all.
@ Resolving
The caller has an uncommitted intent and must commit or cancel it.
@ Targeting
An ability is armed; the next click picks its target.
@ UnitSelected
The controlled unit is selected; the next click acts on a cell.
@ AwaitSelection
Nothing selected yet; a click picks a destination or the active unit.
@ InvalidArgument
@ PreconditionViolation
@ Conflict
@ Applied
Definition Container.h:602
Logical board coordinate independent of rendering projection.
Definition TacticsTypes.h:30
Immutable projection of everything the interaction machine is allowed to know.
Definition Interaction.h:98
One player intention, expressed with stable identities only.
Definition Interaction.h:74