Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
RuleConfiguration.cpp
Go to the documentation of this file.
2
3#include "RuleArchive.hpp"
4
5#include <utility>
6
8{
10 {
11 // RULE_PLAYERSVOTEONRULES == 0 in the shipped source: everyone is
12 // pre-approved, then the host (first local human in the original)
13 // must confirm. The modern rules runtime is local-only, so the first
14 // non-AI player is the same host approximation already used here.
15 for (PlayerState& player : state.players)
16 player.acceptedConfiguration = true;
17
19 {
20 if (state.players[playerNo].aiPlayerLevel == 0)
21 {
22 state.players[playerNo].acceptedConfiguration = false;
23 break;
24 }
25 }
26 }
27
30 const actions::Message& message)
31 {
32 AcceptanceUpdate update{};
34
35 // Rule.cpp defaults to the current options when the RIFF payload is
36 // absent or invalid. decodeOptions is transactional, so a failed
37 // decode intentionally leaves `received` unchanged.
39
40 if (message.numberC < 1)
41 {
43 received.immunitiesTradingAllowed = false;
44 }
45
46 if (received != state.options)
47 {
48 update.optionsChanged = true;
49
50 if (message.numberD == 0)
52
55 }
56
57 if (message.numberD == 0 &&
58 !state.players[message.fromPlayer].acceptedConfiguration)
59 {
60 state.players[message.fromPlayer].acceptedConfiguration = true;
61 update.acceptanceChanged = true;
62 }
63
64 return update;
65 }
66
68 const GameOptions& options,
69 PlayerNumber fromPlayer,
70 bool interim,
71 actions::Message& result)
72 {
73 if (fromPlayer >= MaxPlayers)
74 return false;
75
76 actions::Message message{};
78 message.fromPlayer = fromPlayer;
79 message.toPlayer = BankPlayer;
80 message.numberC = 1;
81 message.numberD = interim ? 1 : 0;
82
83 if (!archive::encodeOptions(options, message.binaryDataA))
84 return false;
85
86 result = std::move(message);
87 return true;
88 }
89
90
92 {
93 actions::Message message{};
95 message.fromPlayer = BankPlayer;
96 message.toPlayer = AllPlayers;
97 message.numberA = state.configurationProposer;
98
99 std::uint32_t playerSet = 0;
101 {
102 if (!state.players[playerNo].acceptedConfiguration)
103 playerSet |= (1u << playerNo);
104 }
105
106 message.numberB = playerSet;
107 message.numberC = 1;
108 (void)archive::encodeOptions(state.options, message.binaryDataA);
109 return message;
110 }
111}
unsigned index
bool encodeOptions(const GameOptions &options, std::vector< std::uint8_t > &result)
bool decodeOptions(std::span< const std::uint8_t > data, GameOptions &result)
actions::Message proposedConfigurationMessage(const GameState &state)
void clearAcceptConfiguration(GameState &state) noexcept
bool acceptedConfigurationMessage(const GameOptions &options, PlayerNumber fromPlayer, bool interim, actions::Message &result)
AcceptanceUpdate applyAcceptedConfiguration(GameState &state, const actions::Message &message)
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 AllPlayers
Definition RuleTypes.hpp:17
rules::PlayerNumber fromPlayer
Definition Actions.hpp:128
std::vector< std::uint8_t > binaryDataA
Definition Actions.hpp:143
PlayerNumber configurationProposer
std::array< PlayerState, MaxPlayers > players