Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleStartupActions.cpp
Go to the documentation of this file.
2#include "RuleGameStart.hpp"
3#include "RuleEconomy.hpp"
4#include "RuleAuction.hpp"
5#include "RuleTrade.hpp"
6#include "RuleLifecycle.hpp"
7#include "RuleSave.hpp"
9#include "RuleBuildings.hpp"
10#include "RuleTurnActions.hpp"
11
12#include "LegacyTextIds.hpp"
13#include "Messaging.hpp"
14#include "PhaseStack.hpp"
15
16#include <algorithm>
17#include <cwctype>
18#include <string>
19#include <string_view>
20
22{
23 namespace
24 {
25 std::wstring messageString(
26 const actions::Message& message)
27 {
28 return std::wstring(message.stringA.data());
29 }
30
32 std::wstring_view lhs,
33 std::wstring_view rhs)
34 {
35 if (lhs.size() != rhs.size())
36 {
37 return false;
38 }
39
40 for (std::size_t i = 0; i < lhs.size(); ++i)
41 {
42 if (std::towlower(lhs[i]) !=
43 std::towlower(rhs[i]))
44 {
45 return false;
46 }
47 }
48
49 return true;
50 }
51 }
52
53
57 {
58 // ActionNewGame() original :
59 //
60 // NOTIFY_ACTION_COMPLETED(
61 // ACTION_NEW_GAME,
62 // TRUE,
63 // initiator,
64 // SavedNumberOfPlayers
65 // );
66
71 static_cast<std::int64_t>(
73 ),
74 1,
76 0
77 );
78
79 // Fresh game :
80 //
81 // TMN_ADDING_PLAYERS,
82 // RULE_MAX_PLAYERS - NumberOfPlayers
83
90 0,
91 0
92 );
93
94 // ActionNewGame() finit en demandant le restart
95 // de GF_ADDING_NEW_PLAYERS.
96
101 );
102 }
103
104
107 const actions::Message& message)
108 {
109 // ActionRestartPhase() original.
110
112 {
113 // Source :
114 // flush queue + ACTION_NEW_GAME.
115
117
122 );
123
124 return;
125 }
126
127 const PendingPhase& phase =
129
130 switch (phase.phase)
131 {
133 {
134 // RULE_NO_SPECTATORS_ALLOWED == 0
135 // dans ce build original.
136
141 0
142 );
143
149 );
150
151 for (PlayerNumber playerNo = 0;
153 ++playerNo)
154 {
155 const PlayerState& player =
157
162 playerNo,
163 player.token,
164 player.colour,
165 player.aiPlayerLevel,
166 player.name
167 );
168 }
169
170 break;
171 }
172
174 {
176 state
177 );
178
179 break;
180 }
181
182 default:
183 {
184 // Synchronisation historique :
185 // GF_WAIT_FOR_EVERYBODY_READY.
186 if (
188 state
189 ))
190 {
191 break;
192 }
193
194
195 // Save-game :
196 // GF_COLLECT_AI_PARAMETERS_FOR_SAVE.
197 if (
199 state
200 ))
201 {
202 break;
203 }
204
205
206 // Cycle de vie :
207 // GF_GAME_FINISHED / GF_PAUSED.
208 if (
210 state
211 ))
212 {
213 break;
214 }
215
216
217 // Trade / acceptance / règlement.
218 if (
220 state,
221 message
222 ))
223 {
224 break;
225 }
226
227
228 // Enchères et pénuries.
229 if (
231 state
232 ))
233 {
234 break;
235 }
236
237
238 // Construction / BSSM / décomposition.
239 if (
241 state
242 ))
243 {
244 break;
245 }
246
247
248 // D'abord les phases économiques :
249 //
250 // GF_COLLECTING_PAYMENT
251 // GF_TRANSFER_ESCROW_PROPERTY
252 // GF_FREE_UNMORTGAGE
253
255 state,
256 message
257 ))
258 {
259 break;
260 }
261
262 // Puis les phases du tour.
263
265 state,
266 message
267 );
268
269 break;
270 }
271 }
272 }
273
274
277 const actions::Message& message)
278 {
279 // Première branche réelle de ActionNamePlayer():
280 //
281 // numberA == RULE_NOBODY_PLAYER
282 // => inscription d'un nouveau joueur.
283
284 if (message.numberA != NobodyPlayer)
285 {
286 // Rename/delete/take-over AI sera porté avec
287 // l'association joueur/adresse réseau originale.
288 return;
289 }
290
294 {
300 0,
301 0,
302 0,
303 messageString(message)
304 );
305
306 return;
307 }
308
309 const std::wstring requestedName =
310 messageString(message);
311
312 const bool invalidName =
313 requestedName.empty() ||
315
316 const bool invalidToken =
317 message.numberC < 0 ||
318 static_cast<std::uint64_t>(message.numberC) >=
319 MaxTokens;
320
321 const bool invalidColour =
322 message.numberD < 0 ||
323 static_cast<std::uint64_t>(message.numberD) >=
325
326 bool badRequest =
327 invalidName ||
328 invalidToken ||
330
333
334 for (PlayerNumber i = 0;
336 ++i)
337 {
338 const PlayerState& player = state.players[i];
339
340 if (player.token ==
341 static_cast<std::uint8_t>(message.numberC) ||
342 player.colour ==
343 static_cast<std::uint8_t>(message.numberD) ||
345 player.name,
347 {
349 badRequest = true;
350 }
351 }
352
353 if (badRequest)
354 {
360 0,
362 0,
364 );
365
366 return;
367 }
368
369 // Ajout réel du joueur.
370 const PlayerNumber playerNo =
372
373 PlayerState& player =
375
376 player.name = requestedName;
377
378 player.token =
379 static_cast<std::uint8_t>(message.numberC);
380
381 player.colour =
382 static_cast<std::uint8_t>(message.numberD);
383
384 player.aiPlayerLevel =
385 static_cast<std::uint8_t>(message.numberB);
386
387 // Source :
388 // TMN_ADDING_PLAYERS,
389 // RULE_MAX_PLAYERS - NumberOfPlayers
390
397 );
398
399 // Le source ne diffuse pas directement le joueur ici :
400 // il relance GF_ADDING_NEW_PLAYERS, qui renvoie
401 // toute la liste des joueurs.
402
407 );
408 }
409}
410
411
412
413
414
415
416
417
418
419
420
unsigned index
constexpr std::int64_t ErrorNoMorePlayers
constexpr std::int64_t ErrorNameInUse
constexpr std::int64_t AddingPlayers
bool sendAction(const actions::Message &message)
bool restartAuctionPhase(GameState &state)
bool restartBuildingPhase(GameState &state)
bool restartEconomyPhase(GameState &state, const actions::Message &message)
void restartConfiguration(GameState &state)
bool restartLifecyclePhase(GameState &state)
const PendingPhase & current(const GameState &state)
void namePlayer(GameState &state, const actions::Message &message)
void afterNewGame(GameState &state, PlayerNumber initiator)
void restartPhase(GameState &state, const actions::Message &message)
bool restartSavePhase(GameState &state)
Definition RuleSave.cpp:641
bool restartSyncPhase(GameState &state)
bool restartTradePhase(GameState &state, const actions::Message &message)
bool restartGameplayPhase(GameState &state, const actions::Message &message)
constexpr std::size_t MaxPlayerColours
Definition RuleTypes.hpp:33
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr std::size_t MaxPlayerNameLength
Definition RuleTypes.hpp:26
constexpr std::size_t MaxTokens
Definition RuleTypes.hpp:30
const GameState & state()
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
std::array< wchar_t, 80 > stringA
Definition Actions.hpp:140
std::uint8_t numberOfPendingPhases
std::array< PlayerState, MaxPlayers > players