Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleOptions.cpp
Go to the documentation of this file.
1#include "RuleOptions.hpp"
2
3#include <array>
4#include <cstdint>
5
7{
8 namespace
9 {
10 template<typename T>
11 void clampValue(
12 T& value,
13 std::int64_t minimum,
14 std::int64_t maximum)
15 {
16 const std::int64_t current =
17 static_cast<std::int64_t>(
18 value
19 );
20
21 if (current < minimum)
22 {
23 value =
24 static_cast<T>(
25 minimum
26 );
27 }
28 else if (current > maximum)
29 {
30 value =
31 static_cast<T>(
32 maximum
33 );
34 }
35 }
36 }
37
38
40 GameOptions& options)
41 {
42 // ActionNewGame() original.
43
44 options = {};
45
46 options.housesPerHotel = 5;
47
48 options.maximumHouses = 32;
49 options.maximumHotels = 12;
50
51 options.interestRate = 10;
52
53 options.initialCash = 1500;
54
55 options.passingGoAmount = 200;
56
57 options.luxuryTaxAmount = 75;
58
59 options.taxRate = 10;
60 options.flatTaxFee = 200;
61
62 options.hideCash = false;
63
64 options.evenBuildRule = true;
65
67 false;
68
69 options.cheatingAllowed = false;
70
71 options.aiTakesTimeToThink = true;
72
73 options.maximumTurnsInJail = 3;
74
75 options.getOutOfJailFee = 50;
76
78 true;
79
80 options.houseShortageLevel = 5;
81
82 options.hotelShortageLevel = 3;
83
84 options.auctionGoingTimeDelay = 5;
85
86 options.inactivityWarningTime = 0;
87
88 options.gameOverTimeLimit = 0;
89
91 false;
92
94 false;
95
96 options.freeParkingSeed = 500;
97
98 options.freeParkingPot = false;
99
100 options.doubleSalaryOnGo = false;
101
103 true;
104
105 options.dealNPropertiesAtStartup = 0;
106
108 false;
109
110 options.stopAtNthBankruptcy = 0;
111
112 options.voiceChat.recordingHz =
113 11025;
114
115 options.voiceChat.recordingBits =
116 8;
117
118 options.voiceChat.compressorName =
119 L"GSM 6.10";
120 }
121
122
124 GameOptions& options)
125 {
126 // UDPsel.cpp::udpsel_SetStandardRules. Keep the historical distinction
127 // from ActionNewGame defaults: houseShortageLevel is 6 here, not 5,
128 // and fields absent from this preset are intentionally preserved.
129 options.housesPerHotel = 5;
130 options.maximumHouses = 32;
131 options.maximumHotels = 12;
132 options.interestRate = 10;
133 options.initialCash = 1500;
134 options.passingGoAmount = 200;
135 options.luxuryTaxAmount = 75;
136 options.taxRate = 10;
137 options.flatTaxFee = 200;
138 options.freeParkingSeed = 500;
139 options.freeParkingPot = false;
140 options.doubleSalaryOnGo = false;
141 options.evenBuildRule = true;
142 options.futureRentTradingAllowed = false;
143 options.immunitiesTradingAllowed = false;
144 options.dealFreePropertiesAtStartup = false;
145 options.dealNPropertiesAtStartup = 0;
146 options.maximumTurnsInJail = 3;
147 options.getOutOfJailFee = 50;
148 options.houseShortageLevel = 6;
149 options.hotelShortageLevel = 3;
150 options.auctionGoingTimeDelay = 5;
151 }
152
153
155 GameOptions& options)
156 {
157 // UDPsel.cpp::udpsel_SetShortGameRules.
159 options.housesPerHotel = 4;
160 options.dealFreePropertiesAtStartup = true;
161 options.dealNPropertiesAtStartup = 2;
162 }
163
164
166 SetupRule rule) noexcept
167 {
168 switch (rule)
169 {
171 return 2;
172
188 return 4;
189
195 return 1;
196
197 case SetupRule::Count:
198 return 0;
199 }
200
201 return 0;
202 }
203
204
206 GameOptions& options,
207 SetupRule rule,
208 std::uint8_t choice) noexcept
209 {
210 if (choice >= setupRuleChoiceCount(rule))
211 return false;
212
213 constexpr std::array<int, 4> maximumHouses{12, 32, 60, 88};
214 constexpr std::array<int, 4> maximumHotels{4, 12, 16, 22};
215 constexpr std::array<int, 4> freeParkingSeed{0, 250, 500, 750};
216 constexpr std::array<int, 4> initialCash{500, 1000, 1500, 2000};
217 constexpr std::array<int, 4> passingGo{0, 100, 200, 400};
218 constexpr std::array<int, 4> taxRate{0, 5, 10, 15};
219 constexpr std::array<int, 4> flatTax{0, 100, 200, 400};
220 constexpr std::array<int, 4> luxuryTax{0, 75, 150, 300};
221 constexpr std::array<int, 4> turnsInJail{1, 2, 3, 4};
222 constexpr std::array<int, 4> jailFee{0, 50, 100, 200};
223 constexpr std::array<int, 4> houseShortage{0, 1, 6, 12};
224 constexpr std::array<int, 4> hotelShortage{0, 1, 3, 6};
225 constexpr std::array<int, 4> interestRate{0, 5, 10, 20};
226 constexpr std::array<int, 4> auctionDelay{3, 4, 5, 10};
227 constexpr std::array<int, 4> dealtProperties{0, 2, 4, 28};
228
229 switch (rule)
230 {
232 options.housesPerHotel = choice == 0 ? 4 : 5;
233 break;
235 options.maximumHouses = maximumHouses[choice];
236 break;
238 options.maximumHotels = maximumHotels[choice];
239 break;
241 options.freeParkingSeed = freeParkingSeed[choice];
242 break;
244 options.initialCash = initialCash[choice];
245 break;
247 options.passingGoAmount = passingGo[choice];
248 break;
250 options.taxRate = taxRate[choice];
251 break;
253 options.flatTaxFee = flatTax[choice];
254 break;
256 options.luxuryTaxAmount = luxuryTax[choice];
257 break;
259 options.maximumTurnsInJail = turnsInJail[choice];
260 break;
262 options.getOutOfJailFee = jailFee[choice];
263 break;
265 options.houseShortageLevel = houseShortage[choice];
266 break;
268 options.hotelShortageLevel = hotelShortage[choice];
269 break;
271 options.interestRate = interestRate[choice];
272 break;
274 options.auctionGoingTimeDelay = auctionDelay[choice];
275 break;
277 options.dealNPropertiesAtStartup = dealtProperties[choice];
278 break;
280 options.evenBuildRule = !options.evenBuildRule;
281 break;
283 options.doubleSalaryOnGo = !options.doubleSalaryOnGo;
284 break;
286 options.freeParkingPot = !options.freeParkingPot;
287 break;
289 options.futureRentTradingAllowed = !options.futureRentTradingAllowed;
290 options.immunitiesTradingAllowed = !options.immunitiesTradingAllowed;
291 break;
293 options.dealFreePropertiesAtStartup = !options.dealFreePropertiesAtStartup;
294 break;
295 case SetupRule::Count:
296 return false;
297 }
298
299 return true;
300 }
301
302
304 GameOptions& options)
305 {
306 // ====================================================
307 // ValidateGameOptions() original.
308 // ====================================================
309
310 // Seulement 4 ou 5 maisons équivalent à un hôtel.
311 if (options.housesPerHotel != 5)
312 {
313 options.housesPerHotel = 4;
314 }
315
316
317 // Il faut au minimum assez de maisons pour construire
318 // des hôtels sur trois propriétés.
319 const std::int64_t minimumHouses =
320 3 *
321 (
322 static_cast<std::int64_t>(
323 options.housesPerHotel
324 ) - 1
325 );
326
327
328 if (
329 static_cast<std::int64_t>(
330 options.maximumHouses
331 ) < minimumHouses)
332 {
333 options.maximumHouses =
334 static_cast<
335 decltype(
336 options.maximumHouses
337 )
338 >(minimumHouses);
339 }
340
341
342 // maximumHotels :
343 // aucune limite supplémentaire dans le source.
344
345
347 options.interestRate,
348 0,
349 1000
350 );
351
352
354 options.initialCash,
355 0,
356 10000000
357 );
358
359
361 options.passingGoAmount,
362 0,
363 1000000
364 );
365
366
368 options.luxuryTaxAmount,
369 0,
370 1000000
371 );
372
373
375 options.taxRate,
376 0,
377 100
378 );
379
380
382 options.flatTaxFee,
383 0,
384 1000000
385 );
386
387
388 if (
389 options.stopAtNthBankruptcy >
391 {
392 options.stopAtNthBankruptcy =
393 static_cast<
394 decltype(
395 options.stopAtNthBankruptcy
396 )
397 >(MaxPlayers);
398 }
399
400
401 // SQ_TOTAL_PROPERTY_SQUARES = 28.
402 if (
404 28)
405 {
407 28;
408 }
409
410
411 if (
412 options.maximumTurnsInJail >
413 100)
414 {
415 options.maximumTurnsInJail =
416 100;
417 }
418
419
421 options.getOutOfJailFee,
422 0,
423 1000000
424 );
425
426
428 options.freeParkingSeed,
429 0,
430 1000000
431 );
432
433
434 if (
435 options.houseShortageLevel >
436 options.maximumHouses)
437 {
438 options.houseShortageLevel =
439 static_cast<
440 decltype(
441 options.houseShortageLevel
442 )
443 >(options.maximumHouses);
444 }
445
446
447 if (
448 options.hotelShortageLevel >
449 options.maximumHotels)
450 {
451 options.hotelShortageLevel =
452 static_cast<
453 decltype(
454 options.hotelShortageLevel
455 )
456 >(options.maximumHotels);
457 }
458
459
461 options.auctionGoingTimeDelay,
462 1,
463 240
464 );
465
466
468 options.inactivityWarningTime,
469 0,
470 600
471 );
472
473
474 if (
475 options.gameOverTimeLimit < 60)
476 {
477 options.gameOverTimeLimit = 0;
478 }
479 else if (
480 options.gameOverTimeLimit > 43200)
481 {
482 options.gameOverTimeLimit =
483 43200;
484 }
485
486
487 // Les flags sont de vrais bool dans le port moderne,
488 // donc le passage "!= 0" du C original est implicite.
489 }
490}
unsigned index
std::uint16_t value
Definition Timers.cpp:16
void setDefaults(GameOptions &options)
std::uint8_t setupRuleChoiceCount(SetupRule rule) noexcept
void validate(GameOptions &options)
void setShortGameRules(GameOptions &options)
void setStandardMonopolyRules(GameOptions &options)
bool applySetupRuleChoice(GameOptions &options, SetupRule rule, std::uint8_t choice) noexcept
constexpr PlayerNumber MaxPlayers
Definition RuleTypes.hpp:14