载入中...
搜索中...
未找到
Interaction.h
浏览该文件的文档.
1#pragma once
2
18#include "common/Result.h"
20
21#include <cstdint>
22#include <map>
23#include <string>
24#include <vector>
25
26namespace eve::tactics {
27
29enum class InteractionState : std::uint8_t {
31 Blocked,
41 Ended,
42};
43
45enum class InteractionIntentKind : std::uint8_t {
47 None,
51 MoveTo,
55 Cancel,
57 Confirm,
59 EndTurn,
60};
61
63[[nodiscard]] EVENGINE_API_DOMAINS std::string_view interactionStateName(InteractionState state) noexcept;
65[[nodiscard]] EVENGINE_API_DOMAINS std::string_view interactionIntentKindName(InteractionIntentKind kind) noexcept;
66
86
116
129public:
140 [[nodiscard]] static InteractionSession create(InteractionContext context);
141
143 [[nodiscard]] InteractionState state() const noexcept;
145 [[nodiscard]] const InteractionContext& context() const noexcept { return context_; }
147 [[nodiscard]] const LogicalId& armedAction() const noexcept { return armedAction_; }
148
156 [[nodiscard]] Result<InteractionIntent> onCellClicked(Cell cell);
157
168 [[nodiscard]] Result<void> armAbility(const LogicalId& action, std::vector<Cell> targetableCells);
169
171 [[nodiscard]] Result<InteractionIntent> onCancel();
172
174 [[nodiscard]] Result<InteractionIntent> onEndTurn();
175
184 [[nodiscard]] Result<void> markResolving();
185
187 [[nodiscard]] Result<void> resolve();
188
189private:
191
192 [[nodiscard]] bool acceptsInput() const noexcept;
193 [[nodiscard]] bool cellInReachable(Cell cell) const;
194 [[nodiscard]] bool cellInTargetable(Cell cell) const;
195 [[nodiscard]] InteractionIntent makeIntent(InteractionIntentKind kind, Cell cell) const;
196
197 InteractionContext context_;
198 InteractionState state_ = InteractionState::Blocked;
199 bool unitSelected_ = false;
200 LogicalId armedAction_;
201 std::vector<Cell> armedTargets_;
203};
204
205} // namespace eve::tactics
#define EVENGINE_API_DOMAINS
Definition Export.h:110
TokenKind kind
std::string action
Definition PlayHost.cpp:117
Move-only, checked operation results for the common layer.
Cell cell
Deterministic board values and short-root ECS entities for tactics.
const VegetationPresetContext & context
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
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
A disposable, non-authoritative interaction session.
const InteractionContext & context() const noexcept
The context this session was created from.
const LogicalId & armedAction() const noexcept
The ability currently armed, or an invalid id when none is.
BattleStatus
Tactical battle lifecycle.
std::string_view interactionStateName(InteractionState state) noexcept
Human-readable stable spelling of an interaction state (protocol text).
InteractionIntentKind
What the player asked for. A value, not a mutation.
Definition Interaction.h:45
@ UseAbilityOn
Declare InteractionIntent::action against cell and optional unit.
@ EndTurn
End the controlled unit's activation.
@ SelectUnit
Focus the controlled unit.
@ None
Nothing to do: the click landed somewhere with no meaning in this state.
@ Confirm
Submit whatever intent is pending.
@ MoveTo
Move the controlled unit onto InteractionIntent::cell.
@ Cancel
Armed ability/selection should be dropped.
std::string_view interactionIntentKindName(InteractionIntentKind kind) noexcept
Human-readable stable spelling of an intent kind (protocol text).
BattlePhase
Explicit, externally observable battle phase.
InteractionState
Where the interaction machine is, as far as the player is concerned.
Definition Interaction.h:29
@ Ended
The battle is over; only inspection remains.
@ 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.
Logical board coordinate independent of rendering projection.
Immutable projection of everything the interaction machine is allowed to know.
Definition Interaction.h:98
std::map< Cell, SubjectRef > unitsByCell
Unit occupying each cell, for turning a targeted cell into a targeted unit.
SubjectRef controlledUnit
The unit this session drives. An invalid subject means "observe only".
SubjectRef activeUnit
The unit currently allowed to act, or an invalid subject when none is.
Revision revision
The revision the caller observed when it built this context.
std::vector< Cell > reachableCells
Destinations the controlled unit may legally move to.
std::vector< Cell > targetableCells
Cells where an armed ability may legally land.
Cell controlledCell
Cell of the controlled unit, used to recognise a click on the unit itself.
One player intention, expressed with stable identities only.
Definition Interaction.h:74
InteractionIntentKind kind
Definition Interaction.h:75
LogicalId action
Armed ability for InteractionIntentKind::UseAbilityOn.
Definition Interaction.h:80
Revision expected
The revision this intent was decided against.
Definition Interaction.h:84
SubjectRef actor
The unit the intent is about (the controlled unit when one is known).
Definition Interaction.h:77
SubjectRef targetUnit
Unit occupying the target cell, when the intent targets a unit.
Definition Interaction.h:82