Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleSynchronization.cpp
Go to the documentation of this file.
2
3#include "LegacyTextIds.hpp"
4#include "Messaging.hpp"
5#include "PhaseStack.hpp"
6#include "RuleRejections.hpp"
7
8#include <cstdint>
9
11{
12 namespace
13 {
14 // Equivalent moderne du static
15 // IgnoreWaitForEverybodyReady de Rule.cpp.
16 bool waitGate = false;
17
18
19 void sendRestart()
20 {
25 );
26 }
27
28
29 void wrongPlayer(
30 const GameState& state,
31 const actions::Message& message)
32 {
34 }
35
36
37 void wrongPhase(
38 const GameState& state,
39 const actions::Message& message)
40 {
42 }
43 }
44
45
47 {
48 waitGate = false;
49 }
50
51
55 {
56 if (waitGate)
57 {
58 return false;
59 }
60
61
62 waitGate = true;
63
64
66 state,
67 hint
68 );
69
70
71 return true;
72 }
73
74
78 {
79 // WaitForEverybodyReady() original.
80
81 std::uint32_t setToWaitFor = 0;
82
83
84 for (PlayerNumber player = 0;
85 player < state.numberOfPlayers;
86 ++player)
87 {
88 if (
89 state.players[player]
90 .currentSquare < 41)
91 {
93 1u << player;
94 }
95 }
96
97
99 state,
101
102 static_cast<PlayerNumber>(
104 ),
105
106 static_cast<PlayerNumber>(
107 hint
108 ),
109
110 static_cast<std::int64_t>(
112 )
113 );
114
115
116 sendRestart();
117 }
118
119
122 const actions::Message& message)
123 {
124 // ActionIAmHere() original.
125
126 const PlayerNumber player =
127 message.fromPlayer;
128
129
130 if (
131 player >=
133 {
134 wrongPlayer(
135 state,
136 message
137 );
138
139 return;
140 }
141
142
143 if (
147 {
148 wrongPhase(
149 state,
150 message
151 );
152
153 return;
154 }
155
156
157 PendingPhase& phase =
158 state.phaseStack[0];
159
160
161 const std::uint32_t waitingSet =
162 phase.fromPlayer;
163
164
165 const std::uint32_t playerBit =
166 1u << player;
167
168
169 // Serial correct + joueur encore attendu.
170 //
171 // Duplicates et vieux messages sont ignorés,
172 // comme le source.
173
174 if (
175 phase.amount ==
176 message.numberA &&
177 (
178 waitingSet &
180 ) != 0)
181 {
182 phase.fromPlayer =
183 static_cast<PlayerNumber>(
184 waitingSet &
186 );
187
188
189 if (phase.fromPlayer == 0)
190 {
191 sendRestart();
192 }
193 }
194 }
195
196
199 {
200 if (
204 {
205 return false;
206 }
207
208
209 const PendingPhase phase =
211
212
217
218 phase.fromPlayer,
219 phase.amount,
220 phase.toPlayer,
221 0
222 );
223
224
225 if (phase.fromPlayer == 0)
226 {
228
229 sendRestart();
230
231 return true;
232 }
233
234 // Retail leaves this phase waiting after broadcasting ARE_YOU_THERE.
235 // Each UI/client answers only for the slots it actually owns. The
236 // portable UserInterface now implements that boundary (with auction
237 // roll-call still deferred until Pennybags reaches Begin), so RULE must
238 // not synthesize I_AM_HERE for every player. Doing so would acknowledge
239 // remote slots and also duplicate local replies in the same process.
240 return true;
241 }
242
243
246 {
247 // ActionTick(), GF_WAIT_FOR_EVERYBODY_READY.
248
249 if (
253 {
254 return;
255 }
256
257
258 PendingPhase& phase =
259 state.phaseStack[0];
260
261
262 if (phase.amount < 0)
263 {
264 return;
265 }
266
267
268 const std::uint64_t serial =
269 static_cast<std::uint64_t>(
270 phase.amount
271 );
272
273
274 if (
276 serial ||
278 serial < 60)
279 {
280 return;
281 }
282
283
284 // Timeout :
285 // ne plus attendre personne.
286
287 phase.fromPlayer = 0;
288
289
290 sendRestart();
291 }
292}
unsigned index
bool sendAction(const actions::Message &message)
bool pop(GameState &state)
const PendingPhase & current(const GameState &state)
bool push(GameState &state, GamePhase phase, PlayerNumber fromPlayer, PlayerNumber toPlayer, std::int64_t amount)
void wrongPlayer(const GameState &state, const actions::Message &message)
void wrongPhase(const GameState &state, const actions::Message &message)
bool restartSyncPhase(GameState &state)
void onIdleTick(GameState &state)
bool beginWaitOnce(GameState &state, actions::Type hint)
void waitForEverybodyReady(GameState &state, actions::Type hint)
void actionIAmHere(GameState &state, const actions::Message &message)
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
const GameState & state()
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
rules::PlayerNumber fromPlayer
Definition Actions.hpp:128
std::uint64_t gameDurationInSeconds
std::array< PendingPhase, MaxPendingPhases > phaseStack
std::uint8_t numberOfPendingPhases
std::array< PlayerState, MaxPlayers > players