Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleGameStart.cpp
Go to the documentation of this file.
1#include "RuleGameStart.hpp"
2
3#include "RuleInitialDeal.hpp"
4#include "BoardRules.hpp"
5#include "CardDecks.hpp"
6#include "LegacyTextIds.hpp"
7#include "Messaging.hpp"
8#include "PhaseStack.hpp"
9#include "RuleRandom.hpp"
10#include "RuleConfiguration.hpp"
11#include "RuleResync.hpp"
12
13#include <array>
14#include <cstddef>
15#include <cstdint>
16
18{
19 namespace
20 {
22 const actions::Message& action,
23 bool success)
24 {
29 static_cast<std::int64_t>(
30 action.action
31 ),
32 success ? 1 : 0,
33 action.fromPlayer,
34 0
35 );
36 }
37
38
39 void wrongPhase(
41 const actions::Message& action)
42 {
44 action,
45 false
46 );
47
48 if (action.fromPlayer == BankPlayer)
49 {
50 return;
51 }
52
54 action.fromPlayer < MaxPlayers
55 ? action.fromPlayer
56 : AllPlayers;
57
63 static_cast<std::int64_t>(
64 action.action
65 ),
66 action.fromPlayer,
67 static_cast<std::int64_t>(
69 )
70 );
71
76 );
77 }
78
79
80 void wrongPlayer(
82 const actions::Message& action)
83 {
85 action,
86 false
87 );
88
89 if (action.fromPlayer == BankPlayer)
90 {
91 return;
92 }
93
95 action.fromPlayer < MaxPlayers
96 ? action.fromPlayer
97 : AllPlayers;
98
104 static_cast<std::int64_t>(
105 action.action
106 ),
107 action.fromPlayer,
108 static_cast<std::int64_t>(
110 )
111 );
112
117 );
118 }
119
120
123 {
124 auto& rng =
126
127 for (PlayerNumber playerNo = 0;
129 ++playerNo)
130 {
132 .diceRollHistory =
133 rng();
134 }
135
136
137 // SortPlayersByRollHistory() original :
138 // bubble sort décroissant.
139
140 for (int playerNo =
141 static_cast<int>(
143 ) - 1;
144 playerNo >= 1;
145 --playerNo)
146 {
147 for (int otherNo = 0;
149 ++otherNo)
150 {
152 .diceRollHistory <
154 .diceRollHistory)
155 {
156 std::swap(
159 );
160 // Retail reorders each player's network address with
161 // the record. Modern connection ownership must follow.
162 const auto first = static_cast<PlayerNumber>(otherNo);
163 const auto second = static_cast<PlayerNumber>(otherNo + 1);
164 const auto owner = messaging::playerOwner(first);
166 messaging::setPlayerOwner(second, owner);
167 }
168 }
169 }
170
171
172 // L'original rediffuse les nouveaux numéros.
173
174 for (PlayerNumber playerNo = 0;
176 ++playerNo)
177 {
178 const PlayerState& player =
180
185 playerNo,
186 player.token,
187 player.colour,
188 player.aiPlayerLevel,
189 player.name
190 );
191 }
192 }
193
194
197 {
198 // ------------------------------------------------
199 // InitialisePredefinedData(GameOptions)
200 // ------------------------------------------------
201
204 );
205
206
207 // ------------------------------------------------
208 // InitialiseDecks()
209 // ------------------------------------------------
210
212 state,
214 );
215
216
217 // ------------------------------------------------
218 // Joueurs :
219 // cash initial + GO + firstMoveMade FALSE.
220 // ------------------------------------------------
221
222 for (PlayerNumber playerNo = 0;
224 ++playerNo)
225 {
226 PlayerState& player =
228
229 player.cash =
231
232 player.currentSquare = 0; // SQ_GO
233
234 player.firstMoveMade = false;
235 }
236
237
238 // ------------------------------------------------
239 // Reset des 42 cases.
240 // ------------------------------------------------
241
242 for (SquareState& square :
244 {
245 square.owner =
247
248 square.offeredInTradeTo =
250
251 square.houses = 0;
252 square.mortgaged = false;
253 square.gameEarnings = 0;
254 }
255
256
258
260
262
263
264 // Rule.cpp::StartGameInitialisation publishes the initial cash,
265 // board and tokens before GAME_STARTING, including local games.
267
272 );
273
279 0,
281 0
282 );
283
284
285 // SwitchPhase(GF_WAIT_START_TURN)
286
288 state,
290 0,
291 0,
292 0
293 );
294
295 // DealNProperties() vient exactement ici dans
296 // StartGameInitialisation() original.
298 state
299 );
300
301// DealNProperties()
302 //
303 // L'option originale par défaut est 0.
304 // Le chemin non-zéro dépend de TransferProperty(),
305 // StackDebt() et GF_TRANSFER_ESCROW_PROPERTY.
306 //
307 // On ne falsifie donc pas cette branche :
308 // elle sera portée avec le moteur dette/escrow.
309
311 {
312 // Pas encore exécuté tant que les phases
313 // dette/escrow ne sont pas portées.
314 }
315
316
317 // AddMoneyToFreeParkingPot(seed)
318
321
323 {
330 );
331 }
332
333
338 );
339 }
340 }
341
342
345 const actions::Message& message)
346 {
347 // ActionStartGame() original.
348
349 if (phases::current(state).phase !=
351 {
352 wrongPhase(state, message);
353 return;
354 }
355
356
358 message.fromPlayer >=
360 message.fromPlayer != BankPlayer)
361 {
362 wrongPlayer(state, message);
363 return;
364 }
365
366
367 if (state.numberOfPlayers < 2)
368 {
370 message,
371 false
372 );
373
379 );
380
385 );
386
387 return;
388 }
389
390
391 // RULE_NO_SPECTATORS_ALLOWED == 0 :
392 // aucun blocage spectateur.
393
394
396 message,
397 true
398 );
399
400
403
404
406 state,
408 0,
409 0,
410 0
411 );
412
413
415
416
421 );
422 }
423
424
427 const actions::Message& message)
428 {
429 // Rule.cpp::ActionAcceptConfiguration. Phase/player validation and
430 // completion notification stay here; the deterministic configuration
431 // transition is isolated in RuleConfiguration for direct tests.
433 {
434 wrongPhase(state, message);
435 return;
436 }
437
438 if (message.fromPlayer >= state.numberOfPlayers)
439 {
440 wrongPlayer(state, message);
441 return;
442 }
443
444 notifyActionCompleted(message, true);
445
446 const auto update =
448
449 if (update.restartNeeded())
450 {
455 );
456 }
457 }
458
459
462 {
463 // SortPlayersByRollHistory() appelle ensuite
464 // directement StartGameInitialisation().
465
467 }
468
469
472 {
473 const actions::Message proposal =
475
476 const auto playerSet =
477 static_cast<std::uint32_t>(proposal.numberB);
478
479 messaging::sendAction(proposal);
480
481
482 if (playerSet != 0)
483 {
484 return;
485 }
486
487
488 if (state.options
490 {
491 for (PlayerNumber playerNo = 0;
493 ++playerNo)
494 {
496 .diceRollHistory = 0;
497 }
498
500 state,
502 0,
503 0,
504 0
505 );
506
511 );
512
513 return;
514 }
515
516
517 // Chemin standard du jeu original :
518 //
519 // RandomizePlayerOrder();
520 // StartGameInitialisation();
521
523
525 }
526}
527
528
unsigned index
data::DataTag first
constexpr std::int64_t ErrorWrongPlayer
constexpr std::int64_t ErrorWrongPhase
constexpr std::int64_t ErrorGameStarting
constexpr std::int64_t ErrorNeedTwoPlayers
std::uint32_t playerOwner(rules::PlayerNumber player)
Definition Messaging.cpp:83
bool sendAction(const actions::Message &message)
void setPlayerOwner(rules::PlayerNumber player, std::uint32_t source)
Definition Messaging.cpp:76
bool initializeForOptions(const GameOptions &options)
void initializeDecks(GameState &state, std::mt19937 &randomGenerator)
Definition CardDecks.cpp:47
actions::Message proposedConfigurationMessage(const GameState &state)
void clearAcceptConfiguration(GameState &state) noexcept
AcceptanceUpdate applyAcceptedConfiguration(GameState &state, const actions::Message &message)
void actionStartGame(GameState &state, const actions::Message &message)
void startGameAfterOrdering(GameState &state)
void restartConfiguration(GameState &state)
void actionAcceptConfiguration(GameState &state, const actions::Message &message)
void dealNProperties(GameState &state)
const PendingPhase & current(const GameState &state)
void switchTo(GameState &state, GamePhase phase, PlayerNumber fromPlayer, PlayerNumber toPlayer, std::int64_t amount)
std::mt19937 & generator()
void sendClientState(const GameState &state, PlayerNumber toPlayer, Cause cause)
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
const GameState & state()
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
rules::PlayerNumber fromPlayer
Definition Actions.hpp:128
PlayerNumber configurationProposer
std::int64_t freeParkingJackpotAmount
std::array< SquareState, SquareCount > squares
std::uint64_t gameDurationInSeconds
std::array< PlayerState, MaxPlayers > players