Debian Codegraph @

common/main/fwd-wall.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.
6 * See COPYING.txt for license details.
7 */
8
9 #pragma once
10
11 #include <type_traits>
12 #include <physfs.h>
13 #include "piggy.h"
14 #include "textures.h"
15 #include "fwd-object.h"
16 #include "fwd-segment.h"
17 #include "cpp-valptridx.h"
18
19 namespace dcx {
20 enum class actdoornum_t : uint8_t;
21 constexpr std::integral_constant<std::size_t, 255> MAX_WALLS{}; // Maximum number of walls
22 constexpr std::integral_constant<std::size_t, 90> MAX_DOORS{}; // Maximum number of open doors
23 struct active_door;
24 }
25 DXX_VALPTRIDX_DECLARE_SUBTYPE(dcx::, active_door, actdoornum_t, MAX_DOORS);
26
27 #include "fwd-valptridx.h"
28
29 #ifdef DXX_BUILD_DESCENT
30 namespace dsx {
31 #if DXX_BUILD_DESCENT == 1
32 constexpr std::integral_constant<std::size_t, 30> MAX_WALL_ANIMS{}; // Maximum different types of doors
33 #elif DXX_BUILD_DESCENT == 2
34 constexpr std::integral_constant<std::size_t, 60> MAX_WALL_ANIMS{}; // Maximum different types of doors
35 #endif
36
37 enum wall_type_t : uint8_t
38 {
39 WALL_NORMAL = 0, // Normal wall
40 WALL_BLASTABLE = 1, // Removable (by shooting) wall
41 WALL_DOOR = 2, // Door
42 WALL_ILLUSION = 3, // Wall that appears to be there, but you can fly thru
43 WALL_OPEN = 4, // Just an open side. (Trigger)
44 WALL_CLOSED = 5, // Wall. Used for transparent walls.
45 #if DXX_BUILD_DESCENT == 2
46 WALL_OVERLAY = 6, // Goes over an actual solid side. For triggers
47 WALL_CLOAKED = 7, // Can see it, and see through it
48 #endif
49 };
50
51 struct d_level_unique_wall_subsystem_state;
52 }
53
54 namespace dcx {
55
56 enum class wall_flag : uint8_t;
57 enum class wall_state : uint8_t;
58 enum class wall_key : uint8_t;
59
60 constexpr std::integral_constant<fix, 100 * F1_0> WALL_HPS{}; // Normal wall's hp
61 constexpr std::integral_constant<fix, 5 * F1_0> WALL_DOOR_INTERVAL{}; // How many seconds a door is open
62
63 constexpr fix DOOR_OPEN_TIME = i2f(2); // How long takes to open
64 constexpr fix DOOR_WAIT_TIME = i2f(5); // How long before auto door closes
65 }
66
67 #ifdef DXX_BUILD_DESCENT
68 namespace dsx {
69 #if DXX_BUILD_DESCENT == 1
70 constexpr std::integral_constant<std::size_t, 20> MAX_CLIP_FRAMES{};
71 #elif DXX_BUILD_DESCENT == 2
72 constexpr std::integral_constant<std::size_t, 50> MAX_CLIP_FRAMES{};
73 #endif
74 }
75
76 namespace dcx {
77
78 enum class WALL_IS_DOORWAY_FLAG : uint8_t
79 {
80 None = 0,
81 fly = 1,
82 render = 2,
83 rendpast = 4,
84 external = 8,
85 /* if DXX_BUILD_DESCENT == 2 */
86 cloaked = 16,
87 /* endif */
88 };
89
90 static constexpr WALL_IS_DOORWAY_FLAG operator|(const WALL_IS_DOORWAY_FLAG a, const WALL_IS_DOORWAY_FLAG b)
91 {
92 return static_cast<WALL_IS_DOORWAY_FLAG>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
93 }
94
95 enum class wall_is_doorway_result : uint8_t;
96 }
97 #endif
98
99 namespace dcx {
100
101 struct stuckobj;
102 struct v16_wall;
103 struct v19_wall;
104
105 typedef unsigned wall_clip_flag_t;
106 constexpr std::integral_constant<wall_clip_flag_t, 1> WCF_EXPLODES{}; //door explodes when opening
107 constexpr std::integral_constant<wall_clip_flag_t, 2> WCF_BLASTABLE{}; //this is a blastable wall
108 constexpr std::integral_constant<wall_clip_flag_t, 4> WCF_TMAP1{}; //this uses primary tmap, not tmap2
109 constexpr std::integral_constant<wall_clip_flag_t, 8> WCF_HIDDEN{}; //this uses primary tmap, not tmap2
110 }
111
112 namespace dsx {
113 struct wall;
114 struct wclip;
115 constexpr std::integral_constant<std::size_t, 20> MAX_CLIP_FRAMES_D1{};
116 }
117
118 #if DXX_BUILD_DESCENT == 2
119 namespace dsx {
120 struct cloaking_wall;
121 constexpr std::integral_constant<std::size_t, 10> MAX_CLOAKING_WALLS{};
122 enum class clwallnum_t : uint8_t
123 {
124 };
125 }
126 DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, cloaking_wall, clwallnum_t, dsx::MAX_CLOAKING_WALLS);
127 namespace dsx {
128 DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(cloaking_wall, clwall);
129 }
130 #endif
131
132 DXX_VALPTRIDX_DECLARE_SUBTYPE(dsx::, wall, wallnum_t, dcx::MAX_WALLS);
133 namespace dsx {
134 DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(wall, wall);
135 using wall_animations_array = std::array<wclip, MAX_WALL_ANIMS>;
136 constexpr valptridx<wall>::magic_constant<wallnum_t{0xffffu}> wall_none{};
137 }
138
139 namespace dcx {
140 DXX_VALPTRIDX_DEFINE_SUBTYPE_TYPEDEFS(active_door, actdoor);
141 extern unsigned Num_wall_anims;
142 }
143 namespace dsx {
144
145 // Automatically checks if a there is a doorway (i.e. can fly through)
146 wall_is_doorway_result WALL_IS_DOORWAY(const GameBitmaps_array &GameBitmaps, const Textures_array &Textures, fvcwallptr &vcwallptr, cscusegment seg, sidenum_t side);
147
148 // Deteriorate appearance of wall. (Changes bitmap (paste-ons))
149 }
150 void wall_damage(vmsegptridx_t seg, sidenum_t side, fix damage);
151
152 // Destroys a blastable wall. (So it is an opening afterwards)
153 void wall_destroy(vmsegptridx_t seg, sidenum_t side);
154
155 namespace dsx {
156
157 void wall_illusion_on(fvmwallptr &, vcsegptridx_t seg, sidenum_t side);
158 void wall_illusion_off(fvmwallptr &, vcsegptridx_t seg, sidenum_t side);
159
160 // Opens a door
161 void wall_open_door(vmsegptridx_t seg, sidenum_t side);
162
163 #if DXX_BUILD_DESCENT == 1
164 #elif DXX_BUILD_DESCENT == 2
165 // Closes a door
166 void wall_close_door(wall_array &Walls, vmsegptridx_t seg, sidenum_t side);
167 #endif
168 }
169
170 //return codes for wall_hit_process()
171 enum class wall_hit_process_t : unsigned
172 {
173 WHP_NOT_SPECIAL = 0, //wasn't a quote-wall-unquote
174 WHP_NO_KEY = 1, //hit door, but didn't have key
175 WHP_BLASTABLE = 2, //hit blastable wall
176 WHP_DOOR = 3, //a door (which will now be opening)
177 };
178
179 // Determines what happens when a wall is shot
180 //obj is the object that hit...either a weapon or the player himself
181 class player_flags;
182 namespace dsx {
183 void wall_init(d_level_unique_wall_subsystem_state &LevelUniqueWallSubsystemState);
184 wall_hit_process_t wall_hit_process(player_flags, vmsegptridx_t seg, sidenum_t side, fix damage, unsigned playernum, const object &obj);
185
186 // Opens/destroys specified door.
187 void wall_toggle(fvmwallptr &vmwallptr, vmsegptridx_t segnum, sidenum_t side);
188
189 // Called once per frame..
190 void wall_frame_process(const d_robot_info_array &Robot_info);
191
192 //set the tmap_num or tmap_num2 field for a wall/door
193 void wall_set_tmap_num(const wclip &, vmsegptridx_t seg, sidenum_t side, vmsegptridx_t csegp, sidenum_t cside, unsigned frame_num);
194 void wclip_read(NamedPHYSFS_File, wclip &wc);
195 void wall_read(NamedPHYSFS_File fp, wall &w);
196 void wall_write(PHYSFS_File *fp, const wall &w, short version);
197
198 void wall_close_door_ref(fvmsegptridx &vmsegptridx, wall_array &Walls, const wall_animations_array &WallAnims, active_door &);
199 }
200
201 #if DXX_BUILD_DESCENT == 2
202 //start wall open <-> closed transitions
203 namespace dsx {
204 void start_wall_cloak(vmsegptridx_t seg, sidenum_t side);
205 void start_wall_decloak(vmsegptridx_t seg, sidenum_t side);
206
207 void cloaking_wall_read(cloaking_wall &cw, NamedPHYSFS_File fp);
208 void cloaking_wall_write(const cloaking_wall &cw, PHYSFS_File *fp);
209 void blast_nearby_glass(const object &objp, fix damage);
210 }
211 #endif
212
213 void v16_wall_read(NamedPHYSFS_File fp, v16_wall &w);
214 void v19_wall_read(NamedPHYSFS_File fp, v19_wall &w);
215
216 void active_door_read(NamedPHYSFS_File fp, active_door &ad);
217 void active_door_write(PHYSFS_File *fp, const active_door &ad);
218 #endif