Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
PieceMovePlayback.cpp
Go to the documentation of this file.
2
3#include "PiecePlacement.hpp"
4
5
6namespace monopoly::pieces
7{
8 namespace
9 {
10 constexpr std::uint16_t MovePlaybackPriority = 100;
11 }
12
13 std::expected<void, std::string> PieceMovePlayback::begin(PieceMovePlan plan)
14 {
15 if (plan_) return std::unexpected("piece move playback already active");
16 if (plan.instructions.empty())
17 return std::unexpected("piece move plan has no TokenAnimStack instructions");
19 {
20 if (!plan.loopBegin || !plan.loopEnd ||
21 *plan.loopBegin >= *plan.loopEnd ||
22 *plan.loopEnd > plan.instructions.size())
23 return std::unexpected("victory TokenAnimStack loop bounds are invalid");
24 }
25 plan_ = std::move(plan);
26 index_ = 0;
27 currentSequence_ = data::EmptyDataId;
28 desiredCamera_.reset();
29 return {};
30 }
31
32 std::expected<void, std::string> PieceMovePlayback::startInstruction(
36 {
37 if (instruction.sequence == data::EmptyDataId)
38 return std::unexpected("sequence TokenAnimStack item has an empty DataID");
40 static_cast<std::uint8_t>(instruction.startSquare), instruction.sequence);
41 if (!pose) return std::unexpected("TokenAnimStack start square is invalid");
42 const auto& startPose = *pose;
43
44 const std::optional<data::DataId> previous =
45 currentSequence_ == data::EmptyDataId ? std::nullopt :
46 std::optional<data::DataId>(currentSequence_);
47 const auto transitioned = playback.transitionRySTxzDropStayAtEnd(
49 startPose.yaw, 1.0F, startPose.x, startPose.z);
50 if (!transitioned) return std::unexpected(transitioned.error());
51 update.stoppedSequence = previous.has_value();
52 update.startedSequence = instruction.sequence;
53 currentSequence_ = instruction.sequence;
54 return {};
55 }
56
57 std::expected<PieceMovePlaybackUpdate, std::string> PieceMovePlayback::tick(
58 bool boardVisible, engine::SequencePlayback& playback)
59 {
61 if (!plan_) return update;
62 auto& plan = *plan_;
63 const auto top = plan.instructions.size() - 1U;
64
65 bool escalate{};
66 if (!boardVisible)
67 {
68 index_ = plan.instructions.size();
69 }
70 else if (index_ == 0)
71 {
72 escalate = true;
73 }
74 else
75 {
76 escalate = true;
77 if (currentSequence_ != data::EmptyDataId)
78 {
79 const auto info = playback.runtime().info(
80 currentSequence_, MovePlaybackPriority, false);
81 if (info && info->endTime > info->sequenceClock)
82 escalate = false;
83 }
84 }
85
86 if (escalate && index_ > 0 &&
87 plan.special == PieceMoveSpecial::None &&
88 plan.destinationSquare != 0)
89 {
90 const auto& previous = plan.instructions[index_ - 1u];
91 if (!previous.cameraOnly && previous.landingSquare == 0)
92 update.passedGo = true;
93 }
94
95 while (escalate && index_ < top &&
96 plan.instructions[index_].cameraOnly)
97 ++index_;
98
99 if (escalate && index_ < plan.instructions.size())
100 {
101 const auto& instruction = plan.instructions[index_];
102 if (!instruction.cameraOnly)
103 {
104 const auto started = startInstruction(instruction, playback, update);
105 if (!started) return std::unexpected(started.error());
106 }
107
108 desiredCamera_ = instruction.camera;
109 update.camera = instruction.camera;
110 ++index_;
111
113 plan.loopBegin && plan.loopEnd && index_ == *plan.loopEnd)
114 {
115 index_ = *plan.loopBegin;
116 update.looped = true;
117 }
118 }
119
120 if (index_ > top)
121 {
122 if (currentSequence_ != data::EmptyDataId)
123 {
124 const auto stopped = playback.stop(
125 currentSequence_, MovePlaybackPriority);
126 if (!stopped) return std::unexpected(stopped.error());
127 currentSequence_ = data::EmptyDataId;
128 update.stoppedSequence = true;
129 }
130 plan_.reset();
131 index_ = 0;
132 update.completed = true;
133 update.active = false;
134 return update;
135 }
136
137 update.active = true;
138 return update;
139 }
140}
decision::EconomicActionPlan plan
int top
unsigned index
std::expected< PieceMovePlaybackUpdate, std::string > tick(bool boardVisible, engine::SequencePlayback &playback)
std::expected< void, std::string > begin(PieceMovePlan plan)
constexpr DataId EmptyDataId
Definition DataBanks.hpp:13
std::optional< TokenPose > tokenAnimationStartOrientation(std::uint8_t boardSquare, data::DataId sequenceId) noexcept