Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleCoreActions.cpp
Go to the documentation of this file.
1#include "RuleCoreActions.hpp"
2
3#include "BoardRules.hpp"
4#include "LegacyTextIds.hpp"
5#include "Messaging.hpp"
6#include "PhaseStack.hpp"
7#include "RuleRejections.hpp"
8#include "RuleBuildings.hpp"
9#include "RuleEconomy.hpp"
10#include "RuleRandom.hpp"
11#include "RuleOptions.hpp"
12#include "RuleSave.hpp"
14#include "RuleTrade.hpp"
15
16#include <array>
17#include <cstddef>
18#include <cstdint>
19#include <utility>
20
22{
23 namespace
24 {
26 {
32 }
33
34
35 void defaultOptions(
37 {
40 );
41 }
42
43
44 void resetState(
46 bool preservePlayers,
48 const std::array<PlayerState, MaxPlayers>&
51 {
52 state = GameState{};
54
56
57
60
61
62 for (SquareState& square :
64 {
65 square.owner =
67
68 square.offeredInTradeTo =
70
71 square.gameEarnings = 0;
72 }
73
74
75 for (CountHitRecord& hit :
77 {
78 hit.toPlayer =
80 }
81
82
84 {
87
90
91
92 for (PlayerNumber player = 0;
93 player < savedCount;
94 ++player)
95 {
96 // ActionNewGame() restaure uniquement
97 // identité + type de joueur.
98
99 state.players[player].name =
100 savedPlayers[player].name;
101
102 state.players[player].token =
103 savedPlayers[player].token;
104
105 state.players[player].colour =
106 savedPlayers[player].colour;
107
108 state.players[player]
109 .aiPlayerLevel =
110 savedPlayers[player]
111 .aiPlayerLevel;
112 }
113 }
114 else
115 {
118 );
119 }
120
121
123 state,
125 0,
126 0,
127 0
128 );
129
130
131 if (preservePlayers)
132 {
133 // Start right away.
134
139 );
140 }
141 else
142 {
148 MaxPlayers -
150 0,
151 0
152 );
153
154
159 );
160 }
161 }
162
163
164 void wrongPlayer(
165 const GameState& state,
166 const actions::Message& message)
167 {
169 }
170
171
172 void wrongPhase(
173 const GameState& state,
174 const actions::Message& message)
175 {
177 }
178
179
180 void cheatingMessage(
181 PlayerNumber player)
182 {
188 0,
189 player,
190 0
191 );
192 }
193 }
194
195
198 {
199 // RULE_InitializeSystem() :
200 //
201 // srand(GetTickCount());
202 // InitialisePredefinedData(fake housesPerHotel=5);
203 // ActionNewGame(NULL).
204
206
207
209
211
212
214 fake
215 );
216
217
218 const std::array<
221 > emptyPlayers{};
222
223
225
226
228 state,
229 false,
230 ignored,
232 0
233 );
234 }
235
236
239 const actions::Message& message)
240 {
241 // ActionNewGame() original.
242
243 if (
245 message.fromPlayer >=
247 {
248 wrongPlayer(
249 state,
250 message
251 );
252
253 return;
254 }
255
256
257 bool preservePlayers = false;
258
259
260 if (
264 message.numberA != 0)
265 {
266 preservePlayers = true;
267 }
268
269
273 : 0;
274
275
277
278 std::array<PlayerState, MaxPlayers>
279 savedPlayers{};
280
281
282 if (preservePlayers)
283 {
286
287
288 for (PlayerNumber player = 0;
289 player < savedCount;
290 ++player)
291 {
292 savedPlayers[player] =
293 state.players[player];
294 }
295 }
296
297
298 // NOTIFY_ACTION_COMPLETED :
299 //
300 // A = ACTION_NEW_GAME
301 // B = TRUE
302 // C = requesting player
303 // D = number of retained players
304
305 actions::Message completed{};
306
307 completed.action =
309
310 completed.fromPlayer =
312
313 completed.toPlayer =
315
316 completed.numberA =
317 static_cast<std::int64_t>(
319 );
320
321 completed.numberB = 1;
322
323 completed.numberC =
324 message.fromPlayer;
325
326 completed.numberD =
328
329
331 completed
332 );
333
334
336 state,
341 );
342 }
343
344
346 const actions::Message& message)
347 {
348 // ACTION_RANDOM_SEED :
349 // srand(numberA).
350
352 static_cast<std::uint32_t>(
353 message.numberA
354 )
355 );
356 }
357
358
361 const actions::Message& message)
362 {
363 // ActionCheatCash() original.
364
365 const PlayerNumber player =
366 static_cast<PlayerNumber>(
367 message.numberA
368 );
369
370
371 const std::int64_t newCash =
372 message.numberB;
373
374
375 if (
377 player >= MaxPlayers ||
378 newCash < 0)
379 {
380 return;
381 }
382
383
384 const std::int64_t oldCash =
385 state.players[player].cash;
386
387
388 state.players[player].cash =
389 newCash;
390
391
396 player,
398 newCash
399 );
400
401
403 message.fromPlayer
404 );
405 }
406
407
410 const actions::Message& message)
411 {
412 // ActionCheatOwner() original.
413
414 PlayerNumber player =
415 static_cast<PlayerNumber>(
416 message.numberA
417 );
418
419
420 const std::int64_t rawSquare =
421 message.numberB;
422
423
424 if (
426 player >= MaxPlayers ||
427 rawSquare < 0 ||
428 rawSquare >=
429 static_cast<std::int64_t>(
431 ))
432 {
433 return;
434 }
435
436
437 const auto squareType =
438 static_cast<board::SquareType>(
440 );
441
442
444 {
445 return;
446 }
447
448
449 SquareState& square =
451 static_cast<std::size_t>(
453 )
454 ];
455
456
457 if (square.owner == player)
458 {
459 player =
461 }
462
463
468 rawSquare,
469 player,
470 square.owner,
471 0
472 );
473
474
475 square.owner =
476 player;
477
478 square.offeredInTradeTo =
480
481
483 message.fromPlayer
484 );
485 }
486
487
490 const actions::Message& message)
491 {
492 // ActionKillAuctionCheat() original.
493
494 if (
498 {
499 wrongPhase(
500 state,
501 message
502 );
503
504 return;
505 }
506
507
509 {
510 return;
511 }
512
513
515 static_cast<std::uint8_t>(
518 );
519
520
522
523
525 message.fromPlayer
526 );
527 }
528
529
531 const actions::Message& message)
532 {
533 // ActionEchoChat().
534 //
535 // Le blob peut être vide.
536
538
539
540 relay.action =
541 message.action ==
545
546
547 relay.fromPlayer =
549
550
551 relay.toPlayer =
552 static_cast<PlayerNumber>(
553 message.numberA
554 );
555
556
557 relay.numberA =
558 message.numberA;
559
560
561 relay.numberB =
562 message.fromPlayer;
563
564
565 relay.numberC =
566 message.numberC;
567
568
569 // Rule.cpp::ActionEchoChat uses the ingress computer address, not
570 // the claimed player or a payload field. MESS owns the modern ID.
571 relay.numberD = message.sourceId;
572
573
574 relay.binaryDataA =
575 message.binaryDataA;
576
577
578 relay.stringA =
579 message.stringA;
580
581
583 relay
584 );
585 }
586
587
589 const actions::Message& message)
590 {
591 // ActionUpdateTradeInfo() original :
592 // rebroadcast intégral.
593
595 message;
596
597
598 relay.action =
600
601
602 relay.fromPlayer =
604
605
606 relay.toPlayer =
608
609
611 relay
612 );
613 }
614
615
617 const actions::Message& message)
618 {
619 // ActionStarWarsAnimationInfo() original.
620
622 message;
623
624
625 relay.action =
628
629
630 relay.fromPlayer =
632
633
634 relay.toPlayer =
636
637
639 relay
640 );
641 }
642}
643
unsigned index
constexpr std::int64_t ErrorPlayerCheating
constexpr std::int64_t AddingPlayers
bool sendAction(const actions::Message &message)
bool isOwnable(SquareType square)
bool initializeForOptions(const GameOptions &options)
void actionCheatCash(GameState &state, const actions::Message &message)
void actionRandomSeed(const actions::Message &message)
void actionStarWarsAnimationInfo(const actions::Message &message)
void actionCheatOwner(GameState &state, const actions::Message &message)
void resetFreshUnconditional(GameState &state)
void actionEchoChat(const actions::Message &message)
void actionKillAuctionCheat(GameState &state, const actions::Message &message)
void actionUpdateTradeInfo(const actions::Message &message)
void setDefaults(GameOptions &options)
const PendingPhase & current(const GameState &state)
bool push(GameState &state, GamePhase phase, PlayerNumber fromPlayer, PlayerNumber toPlayer, std::int64_t amount)
void seed(std::uint32_t value)
void wrongPlayer(const GameState &state, const actions::Message &message)
void wrongPhase(const GameState &state, const actions::Message &message)
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
std::uint8_t PlayerNumber
Definition RuleTypes.hpp:12
constexpr std::size_t SquareCount
Definition RuleTypes.hpp:24
const GameState & state()
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
static void actionNewGame()
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
rules::PlayerNumber fromPlayer
Definition Actions.hpp:128
std::vector< std::uint8_t > binaryDataA
Definition Actions.hpp:143
std::array< wchar_t, 80 > stringA
Definition Actions.hpp:140
std::array< CountHitRecord, MaxCountHitSets > countHits
std::array< SquareState, SquareCount > squares
std::uint8_t numberOfPendingPhases
std::array< PlayerState, MaxPlayers > players