Debian Codegraph @

common/main/game.h

raw
1 /*
2 * Portions of this file are copyright Rebirth contributors and licensed as
3 * described in COPYING.txt.
4 * Portions of this file are copyright Parallax Software and licensed
5 * according to the Parallax license below.
6 * See COPYING.txt for license details.
7
8 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
10 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
16 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
18 */
19
20 /*
21 *
22 * Constants & prototypes which pertain to the game only
23 *
24 */
25
26 #pragma once
27
28 #include "fwd-game.h"
29
30 #include "pack.h"
31 #include "fwd-segment.h"
32 #include "robot.h"
33 #include "window.h"
34 #include "wall.h"
35 #include "d_underlying_value.h"
36 #include <optional>
37
38 namespace dcx {
39
40 enum class game_mode_flag : uint16_t
41 {
42 normal = 0,
43 network = 1u << 2,
44 multi_robots = 1u << 3,
45 multi_coop = 1u << 4,
46 team = 1u << 8,
47 bounty = 1u << 9,
48 /* if DXX_BUILD_DESCENT == 2 */
49 capture = 1u << 10,
50 hoard = 1u << 11,
51 /* endif */
52 };
53
54 enum class game_mode_flags : uint16_t
55 {
56 normal = 0,
57 anarchy_no_robots = static_cast<uint16_t>(game_mode_flag::network),
58 team_anarchy_no_robots = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::team),
59 anarchy_with_robots = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::multi_robots),
60 cooperative = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::multi_robots) | static_cast<uint16_t>(game_mode_flag::multi_coop),
61 bounty = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::bounty),
62 /* if DXX_BUILD_DESCENT == 2 */
63 capture_flag = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::team) | static_cast<uint16_t>(game_mode_flag::capture),
64 hoard = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::hoard),
65 team_hoard = static_cast<uint16_t>(game_mode_flag::network) | static_cast<uint16_t>(game_mode_flag::team) | static_cast<uint16_t>(game_mode_flag::hoard),
66 /* endif */
67 };
68
69 static constexpr auto operator&(const game_mode_flags game_mode, const game_mode_flag f)
70 {
71 #if DXX_USE_MULTIPLAYER
72 return underlying_value(game_mode) & underlying_value(f);
73 #else
74 /* `normal` has the value 0, and every flag with a non-zero value is
75 * related to multiplayer. A build without the ability to use multiplayer
76 * will therefore only ever have a `game_mode` of 0, so the test can be
77 * simplified to always return false.
78 */
79 (void)game_mode;
80 (void)f;
81 return std::false_type{};
82 #endif
83 }
84
85 /* This must be a signed type. Some sites, such as `bump_this_object`,
86 * use Difficulty_level_type in arithmetic expressions, and those
87 * expressions must be signed to produce the correct result.
88 */
89 enum class Difficulty_level_type : signed int
90 {
91 _0,
92 _1,
93 _2,
94 _3,
95 _4,
96 };
97
98 constexpr Difficulty_level_type DEFAULT_DIFFICULTY = Difficulty_level_type::_1;
99
100 static inline Difficulty_level_type cast_clamp_difficulty(const int8_t d)
101 {
102 return (static_cast<uint8_t>(d) <= static_cast<uint8_t>(Difficulty_level_type::_4)) ? Difficulty_level_type{d} : Difficulty_level_type::_4;
103 }
104
105 std::optional<Difficulty_level_type> build_difficulty_level_from_untrusted(int8_t untrusted);
106
107 struct d_game_shared_state
108 {
109 };
110
111 struct d_game_unique_state
112 {
113 using savegame_file_path = std::array<char, PATH_MAX>;
114 /* 20 is required by the save game ABI and the multiplayer
115 * save/restore command ABI.
116 */
117 using savegame_description = std::array<char, 20>;
118 static constexpr std::integral_constant<unsigned, 11> MAXIMUM_SAVE_SLOTS{};
119 enum class save_slot : unsigned
120 {
121 _0,
122 _1,
123 _2,
124 _3,
125 _4,
126 _5,
127 _6,
128 _7,
129 _8,
130 _9,
131 _autosave,
132 secret_save_filename_override = MAXIMUM_SAVE_SLOTS + 1,
133 None = UINT32_MAX
134 };
135 Difficulty_level_type Difficulty_level; // Difficulty level in 0..NDL-1, 0 = easiest, NDL-1 = hardest
136 fix Boss_gate_interval;
137 unsigned accumulated_robots;
138 unsigned total_hostages;
139 std::chrono::steady_clock::time_point Next_autosave;
140 save_slot quicksave_selection = save_slot::None;
141 static constexpr unsigned valid_save_slot(const save_slot s)
142 {
143 return static_cast<unsigned>(s) < static_cast<unsigned>(save_slot::_autosave);
144 }
145 static constexpr unsigned valid_load_slot(const save_slot s)
146 {
147 return static_cast<unsigned>(s) <= static_cast<unsigned>(save_slot::_autosave);
148 }
149 };
150
151 #if DXX_USE_STEREOSCOPIC_RENDER
152 // Stereo viewport formats
153 enum class StereoFormat : uint8_t
154 {
155 None = 0,
156 AboveBelow,
157 SideBySideFullHeight,
158 SideBySideHalfHeight,
159 AboveBelowSync,
160 HighestFormat = AboveBelowSync
161 };
162 #endif
163
164 }
165
166 #ifdef DXX_BUILD_DESCENT
167 namespace dsx {
168
169 struct game_window final : window
170 {
171 using window::window;
172 virtual window_event_result event_handler(const d_event &) override;
173 };
174
175 struct d_game_shared_state : ::dcx::d_game_shared_state
176 {
177 wall_animations_array WallAnims;
178 };
179
180 #if DXX_BUILD_DESCENT == 2
181 struct d_game_unique_state : ::dcx::d_game_unique_state
182 {
183 fix Final_boss_countdown_time;
184 };
185
186 struct d_level_shared_seismic_state
187 {
188 fix Level_shake_frequency;
189 fix Level_shake_duration;
190 };
191
192 struct d_level_unique_seismic_state
193 {
194 fix64 Seismic_disturbance_end_time;
195 fix64 Next_seismic_sound_time;
196 int Seismic_tremor_volume;
197 fix Seismic_tremor_magnitude;
198 std::array<fix64, 4> Earthshaker_detonate_times;
199 };
200 #endif
201
202 }
203 #endif
204
205 namespace dcx {
206
207 class pause_game_world_time
208 {
209 public:
210 pause_game_world_time();
211 ~pause_game_world_time();
212 };
213
214 enum class cockpit_mode_t : uint8_t
215 {
216 //valid modes for cockpit
217 full_cockpit, // normal screen with cockpit
218 rear_view, // looking back with bitmap
219 status_bar, // small status bar, w/ reticle
220 full_screen, // full screen, no cockpit (w/ reticle)
221 letterbox // half-height window (for cutscenes)
222 };
223
224 enum class player_ship_color : uint8_t
225 {
226 /* These are the colors assigned by `gauges.cpp`:`player_rgb_normal` in the
227 * unmodified game.
228 */
229 blue,
230 red,
231 green,
232 purple,
233 orange,
234 dim_orange,
235 dim_green,
236 yellow,
237 };
238
239 }
240
241 #ifdef DXX_BUILD_DESCENT
242 #if DXX_BUILD_DESCENT == 1
243 static inline void full_palette_save(void)
244 {
245 palette_save();
246 }
247 #endif
248
249 namespace dsx {
250
251 #if DXX_BUILD_DESCENT == 1
252 /* For flags which are only valid for Descent 2, define a special case that
253 * always returns false in Descent 1, without examining the flag.
254 */
255 struct test_game_mode_d2x_flag
256 {
257 constexpr std::false_type operator()(game_mode_flags) const // C++23 static
258 {
259 return {};
260 }
261 };
262
263 constexpr test_game_mode_d2x_flag game_mode_capture_flag{};
264 constexpr test_game_mode_d2x_flag game_mode_hoard{};
265 #elif DXX_BUILD_DESCENT == 2
266 static inline uint16_t game_mode_capture_flag(const game_mode_flags mode)
267 {
268 return mode & GM_CAPTURE;
269 }
270 static inline uint16_t game_mode_hoard(const game_mode_flags mode)
271 {
272 return mode & GM_HOARD;
273 }
274
275 //Flickering light system
276 struct flickering_light {
277 segnum_t segnum;
278 sidenum_t sidenum;
279 uint32_t mask; // determines flicker pattern
280 fix timer; // time until next change
281 fix delay; // time between changes
282 };
283
284 struct d_flickering_light_state
285 {
286 using Flickering_light_array_t = std::array<flickering_light, 100>;
287 unsigned Num_flickering_lights;
288 Flickering_light_array_t Flickering_lights;
289 };
290 #endif
291
292 //Cheats
293 struct game_cheats : prohibit_void_ptr<game_cheats>
294 {
295 int8_t enabled;
296 int8_t wowie;
297 int8_t allkeys;
298 int8_t invul;
299 int8_t shields;
300 int8_t killreactor;
301 int8_t exitpath;
302 int8_t levelwarp;
303 int8_t fullautomap;
304 int8_t ghostphysics;
305 int8_t rapidfire;
306 int8_t turbo;
307 int8_t robotfiringsuspended;
308 int8_t acid;
309 #if DXX_BUILD_DESCENT == 1
310 int8_t wowie2;
311 int8_t cloak;
312 int8_t extralife;
313 int8_t baldguy;
314 #elif DXX_BUILD_DESCENT == 2
315 int8_t lamer;
316 int8_t accessory;
317 int8_t bouncyfire;
318 int8_t homingfire;
319 int8_t killallrobots;
320 int8_t robotskillrobots;
321 int8_t monsterdamage;
322 int8_t buddyclone;
323 int8_t buddyangry;
324 #endif
325 };
326
327 void game_render_frame(const d_robot_info_array &Robot_info, const control_info &Controls);
328 void game_render_frame_mono(const d_robot_info_array &Robot_info, const control_info &Controls);
329 window_event_result ReadControls(const d_level_shared_robot_info_state &LevelSharedRobotInfoState, const d_event &event, control_info &Controls);
330
331 }
332 #endif