Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
PieceCamera.cpp
Go to the documentation of this file.
1#include "PieceCamera.hpp"
2
3#include <array>
4
5namespace monopoly::pieces
6{
7 namespace
8 {
9 using enum BoardCameraView;
10
11 constexpr std::array<BoardCameraView, 42> Camera3{{
30 }};
31
32 constexpr std::array<BoardCameraView, 42> Camera5{{
47 }};
48
49 constexpr std::array<BoardCameraView, 42> Camera15{{
64 }};
65
66 template <std::size_t Size>
67 BoardCameraView tableLookup(const std::array<BoardCameraView, Size>& table,
68 std::int32_t square) noexcept
69 {
70 if (square < 0 || static_cast<std::size_t>(square) >= table.size())
71 return CornerGo;
72 return table[static_cast<std::size_t>(square)];
73 }
74 }
75
79 std::int32_t currentSquare,
80 std::int32_t variable) noexcept
81 {
82 // Source/monopoly/UDBoard.cpp::UDBOARD_SelectAppropriateView.
83 // `variable` survives the public contract, but the only random branch
84 // that used it is commented out in the shipped source.
85 if (variable <= 0) variable = 1;
87
88 switch (type)
89 {
91 {
92 std::int32_t square = currentSquare;
93 if (square > 39) square = 10;
94
95 std::int32_t view = 3 * (square / 10);
96 square %= 10;
97 --square;
98 if (square < 0) square = 0;
99 view += square / 3;
100 view += static_cast<std::int32_t>(BoardCameraView::FifteenTiles01);
101 return static_cast<BoardCameraView>(view);
102 }
105 }
106 return desired;
107 }
108
109 BoardCameraView pickCameraFor3Squares(std::int32_t square) noexcept
110 {
111 return tableLookup(Camera3, square);
112 }
113
114 BoardCameraView pickCameraFor5Squares(std::int32_t square) noexcept
115 {
116 return tableLookup(Camera5, square);
117 }
118
119 BoardCameraView pickCameraFor15Squares(std::int32_t square) noexcept
120 {
121 return tableLookup(Camera15, square);
122 }
123
125 std::int32_t square, std::int32_t distance) noexcept
126 {
127 std::int32_t distanceToCorner = 10 - (square % 10);
128 if (distanceToCorner == 10 && distance == 0) distanceToCorner = 0;
129 if (distance >= 9) return pickCameraFor15Squares(square);
130
131 if (distanceToCorner < distance || distance == 0)
132 {
133 switch ((square + distanceToCorner) / 10)
134 {
135 case 1: return BoardCameraView::CornerJail;
137 case 3: return BoardCameraView::CornerGoToJail;
138 default: return BoardCameraView::CornerGo;
139 }
140 }
141
142 const auto destination = (square + distance) % 40;
143 if (destination <= 3)
145
146 return pickCameraFor5Squares((square + distance - 1) % 40);
147 }
148}
unsigned index
BoardCameraView pickGoodCamera(std::int32_t square, std::int32_t distance) noexcept
BoardCameraView pickCameraFor3Squares(std::int32_t square) noexcept
BoardCameraView pickCameraFor5Squares(std::int32_t square) noexcept
BoardCameraView selectAppropriateView(BoardViewSelectionType type, BoardCameraView desired, std::int32_t currentSquare, std::int32_t variable) noexcept
BoardCameraView pickCameraFor15Squares(std::int32_t square) noexcept