Debian Codegraph @

common/main/cntrlcen.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 * Header for cntrlcen.c
23 *
24 */
25
26 #pragma once
27
28 #include <ranges>
29 #include <physfs.h>
30 #include <ranges>
31
32 #include "fwd-object.h"
33 #include "pack.h"
34 #include "fwd-robot.h"
35 #include "fwd-segment.h"
36 #include "fwd-window.h"
37
38 #include "fwd-partial_range.h"
39 #include "physfsx.h"
40
41 namespace dcx {
42
43 struct control_center_triggers : public prohibit_void_ptr<control_center_triggers>
44 {
45 static constexpr std::integral_constant<std::size_t, 10> max_links{};
46 uint8_t num_links;
47 std::array<segnum_t, max_links> seg;
48 std::array<sidenum_t, max_links> side;
49 };
50
51 struct v1_control_center_triggers
52 {
53 v1_control_center_triggers(NamedPHYSFS_File);
54 v1_control_center_triggers(const control_center_triggers &);
55 static constexpr std::integral_constant<std::size_t, 10> max_links{};
56 uint16_t num_links;
57 std::array<segnum_t, max_links> seg;
58 std::array<uint16_t, max_links> side;
59 };
60 static_assert(sizeof(v1_control_center_triggers) == (2 + (2 * 10) + (2 * 10)));
61 extern control_center_triggers ControlCenterTriggers;
62
63 /*
64 * reads 1 control_center_triggers struct from a PHYSFS_File
65 */
66 [[nodiscard]]
67 control_center_triggers control_center_triggers_read(NamedPHYSFS_File fp);
68 void control_center_triggers_write(const control_center_triggers &cct, PHYSFS_File *fp);
69
70 }
71
72 #ifdef DXX_BUILD_DESCENT
73 #include "vecmat.h"
74
75 namespace dsx {
76
77 struct reactor {
78 #if DXX_BUILD_DESCENT == 2
79 polygon_model_index model_num;
80 #endif
81 uint8_t n_guns;
82 /* Location of the gun on the reactor model */
83 std::array<vms_vector, MAX_CONTROLCEN_GUNS> gun_points;
84 /* Orientation of the gun on the reactor model */
85 std::array<vms_vector, MAX_CONTROLCEN_GUNS> gun_dirs;
86 };
87
88 // fills in arrays gun_points & gun_dirs, returns the number of guns read
89 [[nodiscard]]
90 reactor read_model_guns(const char *filename);
91
92 #if DXX_BUILD_DESCENT == 1
93 constexpr std::integral_constant<unsigned, 1> MAX_REACTORS{};
94 #elif DXX_BUILD_DESCENT == 2
95 constexpr std::integral_constant<unsigned, 7> MAX_REACTORS{};
96 #define DEFAULT_CONTROL_CENTER_EXPLOSION_TIME 30 // Note: Usually uses Alan_pavlish_reactor_times, but can be overridden in editor.
97
98 struct d_level_shared_control_center_state
99 {
100 int Base_control_center_explosion_time; // how long to blow up on insane
101 int Reactor_strength;
102 };
103
104 extern d_level_shared_control_center_state LevelSharedControlCenterState;
105
106 extern unsigned Num_reactors;
107
108 /*
109 * reads n reactor structs from a PHYSFS_File
110 */
111 void reactor_read_n(NamedPHYSFS_File fp, std::ranges::subrange<reactor *> r);
112 #endif
113
114 extern std::array<reactor, MAX_REACTORS> Reactors;
115
116 static inline polygon_model_index get_reactor_model_number(const uint8_t id)
117 {
118 #if DXX_BUILD_DESCENT == 1
119 return polygon_model_index{id};
120 #elif DXX_BUILD_DESCENT == 2
121 return Reactors[id].model_num;
122 #endif
123 }
124
125 // Initialize control center for a level.
126 // Call when a new level is started.
127 void init_controlcen_for_level(const d_robot_info_array &Robot_info);
128 void calc_controlcen_gun_point(object &obj);
129
130 void do_controlcen_destroyed_stuff(imobjidx_t objp);
131 window_event_result do_controlcen_dead_frame();
132 }
133 #endif