Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleJail.cpp
Go to the documentation of this file.
1#include "RuleJail.hpp"
2
3#include "CardDeckRuntime.hpp"
4#include "LegacyTextIds.hpp"
5#include "Messaging.hpp"
6#include "PhaseStack.hpp"
7#include "RuleRejections.hpp"
8#include "RuleEconomy.hpp"
9
11{
12 namespace
13 {
14 void actionCompleted(
15 const actions::Message& message,
16 bool success,
17 std::int64_t choice)
18 {
23 static_cast<std::int64_t>(
24 message.action
25 ),
26 success ? 1 : 0,
27 message.fromPlayer,
28 choice
29 );
30 }
31
32
33 void sendRestart()
34 {
39 );
40 }
41 }
42
43
46 const actions::Message& message)
47 {
48 // ActionExitJailDecision() original.
49
50 if (
51 phases::current(state).phase !=
53 {
55
56 return;
57 }
58
59
60 if (
61 message.fromPlayer !=
65 {
67
68 return;
69 }
70
71
72 PlayerState& player =
75 ];
76
77
78 // ----------------------------------------------------
79 // 0 : tenter un double.
80 //
81 // turnsInJail == 99 signifie :
82 // paiement obligatoire, aucun lancer autorisé.
83 // ----------------------------------------------------
84
85 if (
86 message.numberA == 0 &&
87 player.turnsInJail < 99)
88 {
90 message,
91 true,
92 message.numberA
93 );
94
95
97 state,
99 0,
100 0,
101 0
102 );
103
104
105 sendRestart();
106
107 return;
108 }
109
110
111 // ----------------------------------------------------
112 // 1 : payer les frais de sortie.
113 //
114 // Même si le cash est insuffisant, l'original crée
115 // quand même la dette : le joueur peut alors vendre,
116 // hypothéquer ou faire faillite.
117 // ----------------------------------------------------
118
119 if (message.numberA == 1)
120 {
122 message,
123 true,
124 message.numberA
125 );
126
127
128 if (
129 player.cash <
131 {
139 player.cash
140 );
141 }
142
143
144 // Lorsque la dette sera terminée,
145 // ACTION_RESTART_PHASE retombera sur
146 // GF_GET_OUT_OF_JAIL.
147
149 state,
151 0,
152 0,
153 0
154 );
155
156
158 state,
162 );
163
164
166 state,
168 );
169
170
171 return;
172 }
173
174
175 // ----------------------------------------------------
176 // 2 : utiliser Get Out of Jail Free.
177 //
178 // Interdit lorsque turnsInJail == 99.
179 // ----------------------------------------------------
180
181 const bool chanceCard =
182 state.cards[
183 static_cast<std::size_t>(
185 )
186 ].jailOwner ==
188
189
190 const bool communityCard =
191 state.cards[
192 static_cast<std::size_t>(
194 )
195 ].jailOwner ==
197
198
199 if (
200 message.numberA == 2 &&
201 player.turnsInJail < 99 &&
203 {
205 message,
206 true,
207 message.numberA
208 );
209
210
211 if (chanceCard)
212 {
214 state,
218 );
219 }
220 else
221 {
223 state,
227 );
228 }
229
230
232 state,
234 0,
235 0,
236 0
237 );
238
239
240 sendRestart();
241
242 return;
243 }
244
245
246 // ----------------------------------------------------
247 // Choix impossible.
248 //
249 // Rule.cpp fait exactement :
250 //
251 // TMN_ERROR_NEED_JAIL_ROLL + numberA
252 //
253 // 0 -> roll
254 // 1 -> money
255 // 2 -> card
256 // ----------------------------------------------------
257
259 message,
260 false,
261 0
262 );
263
264
265 sendRestart();
266
267
273 message.numberA,
276 player.cash
277 );
278 }
279}
unsigned index
constexpr std::int64_t ErrorNeedJailMoney
constexpr std::int64_t ErrorNeedJailRoll
bool sendAction(const actions::Message &message)
bool transferGetOutOfJail(GameState &state, PlayerNumber fromPlayer, PlayerNumber toPlayer, DeckType deckType)
void stackDebtAndRestart(GameState &state, PlayerNumber fromPlayer, PlayerNumber toPlayer, std::int64_t amount)
void addMoneyToFreeParkingPot(GameState &state, std::int64_t amount)
void actionExitJailDecision(GameState &state, const actions::Message &message)
Definition RuleJail.cpp:44
const PendingPhase & current(const GameState &state)
void switchTo(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)
constexpr PlayerNumber BankPlayer
Definition RuleTypes.hpp:15
const GameState & state()
constexpr PlayerNumber NobodyPlayer
Definition RuleTypes.hpp:16
constexpr PlayerNumber AllPlayers
Definition RuleTypes.hpp:17
rules::PlayerNumber fromPlayer
Definition Actions.hpp:128
std::array< CardDeck, static_cast< std::size_t >(DeckType::Count) > cards
std::array< PlayerState, MaxPlayers > players