Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
PieceBuildingDisplay.cpp
Go to the documentation of this file.
2
3#include <cstddef>
4
6{
7 namespace
8 {
10 {
12 }
13
14 [[nodiscard]] std::uint16_t housingPriority(
15 std::uint8_t square, std::uint8_t slot) noexcept
16 {
17 return static_cast<std::uint16_t>(BoardHousingPriority +
18 static_cast<std::uint16_t>(square) * HouseSlotCount + slot);
19 }
20
21 }
22
24 {
25 hotels_.fill(false);
26 for (auto& flags : houses_) flags.fill(false);
27 }
28
29 bool PieceBuildingDisplay::hotelShown(std::uint8_t square) const noexcept
30 {
31 return square < hotels_.size() && hotels_[square];
32 }
33
35 std::uint8_t square, std::uint8_t slot) const noexcept
36 {
37 return square < houses_.size() && slot < HouseSlotCount &&
38 houses_[square][slot];
39 }
40
41 std::expected<PieceBuildingDisplayUpdate, std::string>
43 bool boardVisible, engine::SequencePlayback& playback)
44 {
45 std::size_t requiredCommands{};
46 for (std::uint8_t square = 0; square < rules::SquareCount; ++square)
47 {
48 const bool hotelWanted = boardVisible &&
49 state.squares[square].houses == state.options.housesPerHotel;
50 if (hotelWanted)
51 {
52 if (!hotels_[square])
53 {
55 for (bool shown : houses_[square])
56 if (shown) ++requiredCommands;
57 }
58 continue;
59 }
60 if (hotels_[square]) ++requiredCommands;
61 for (std::uint8_t slot = 0; slot < HouseSlotCount; ++slot)
62 {
63 const bool houseWanted = boardVisible &&
64 slot < state.squares[square].houses;
65 if (houseWanted != houses_[square][slot])
66 requiredCommands += houseWanted ? 2U : 1U;
67 }
68 }
69
71 playback.commands().pendingCount() >
73 return std::unexpected("building display command queue capacity exceeded");
74
76 const auto hotelId = buildingId(HotelMeshTag);
77 const auto houseId = buildingId(HouseMeshTag);
78
79 for (std::uint8_t square = 0; square < rules::SquareCount; ++square)
80 {
81 const bool hotelWanted = boardVisible &&
82 state.squares[square].houses == state.options.housesPerHotel;
83 if (hotelWanted)
84 {
85 if (hotels_[square]) continue;
86 const auto pose = hotelPosition(square);
87 if (!pose) return std::unexpected("hotel square is invalid");
88 const auto started = playback.startRySTxz(
89 hotelId, housingPriority(square, 0),
90 pose->yaw, BuildingDisplayScale, pose->x, pose->z);
91 if (!started) return std::unexpected(started.error());
92 hotels_[square] = true;
93 ++update.started;
94 for (std::uint8_t slot = 0; slot < HouseSlotCount; ++slot)
95 {
96 if (!houses_[square][slot]) continue;
97 const auto stopped = playback.stop(houseId,
98 housingPriority(square, slot));
99 if (!stopped) return std::unexpected(stopped.error());
100 houses_[square][slot] = false;
101 ++update.stopped;
102 }
103 continue;
104 }
105
106 if (hotels_[square])
107 {
108 const auto stopped = playback.stop(hotelId,
109 housingPriority(square, 0));
110 if (!stopped) return std::unexpected(stopped.error());
111 hotels_[square] = false;
112 ++update.stopped;
113 }
114
115 for (std::uint8_t slot = 0; slot < HouseSlotCount; ++slot)
116 {
117 const bool houseWanted = boardVisible &&
118 slot < state.squares[square].houses;
119 if (houseWanted == houses_[square][slot]) continue;
120 const auto priority = housingPriority(square, slot);
121 if (!houseWanted)
122 {
123 const auto stopped = playback.stop(houseId, priority);
124 if (!stopped) return std::unexpected(stopped.error());
125 houses_[square][slot] = false;
126 ++update.stopped;
127 continue;
128 }
129 const auto pose = housePosition(square, slot);
130 if (!pose) return std::unexpected("house square/slot is invalid");
131 const auto started = playback.startRySTxz(
133 pose->x, pose->z);
134 if (!started) return std::unexpected(started.error());
135 houses_[square][slot] = true;
136 ++update.started;
137 }
138 }
139 return update;
140 }
141}
std::uint16_t priority
PlayerNumber slot
unsigned state
unsigned index
bool hotelShown(std::uint8_t square) const noexcept
std::expected< PieceBuildingDisplayUpdate, std::string > sync(const rules::GameState &state, bool boardVisible, engine::SequencePlayback &playback)
bool houseShown(std::uint8_t square, std::uint8_t slot) const noexcept
std::uint32_t DataId
Definition DataBanks.hpp:10
std::uint16_t DataTag
Definition DataBanks.hpp:11
constexpr DataId packDataId(std::uint16_t group, DataTag tag) noexcept
Definition DataBanks.hpp:39
std::optional< BuildingPose > housePosition(std::uint8_t boardSquare, std::uint8_t house) noexcept
std::optional< BuildingPose > hotelPosition(std::uint8_t boardSquare) noexcept
constexpr std::uint8_t HouseSlotCount
constexpr data::DataTag HotelMeshTag
constexpr std::uint16_t BoardHousingPriority
constexpr float BuildingDisplayScale
constexpr data::DataTag HouseMeshTag
constexpr std::size_t SquareCount
Definition RuleTypes.hpp:24