Debian Codegraph @

Descent3/doorway.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/doorway.cpp $
21 * $Revision: 25 $
22 * $Date: 4/23/99 8:28p $
23 * $Author: Kevin $
24 *
25 * Doorway code
26 *
27 * $Log: /DescentIII/main/doorway.cpp $
28 *
29 * 25 4/23/99 8:28p Kevin
30 * trying to get doors working in save/load games
31 *
32 * 24 4/20/99 8:35p Matt
33 * Changed ActivateDoorway() to not exit if a door is locked. It's the
34 * caller's responsibility to check if the door is openable (if he cares)
35 * before activating.
36 *
37 * 23 4/20/99 6:55p Matt
38 * Added code to keep a bitmask of all keys held by all players, and to
39 * allow a robot to open a door if any player has the key(s) for that
40 * door.
41 *
42 * 22 4/10/99 5:09p Samir
43 * prioritize sounds, pass 1
44 *
45 * 21 2/09/99 12:39p Matt
46 * Added notification events for door activation and door closed
47 *
48 * 20 2/06/99 10:03p Matt
49 * Added keys system
50 *
51 * 19 2/04/99 2:05p Matt
52 * Added blastable doors
53 *
54 * 18 1/29/99 2:41p Jeff
55 * removed ifdef Editor around DoorwayAdd, so Main can build
56 *
57 * 17 1/29/99 12:47p Matt
58 * Rewrote the doorway system
59 *
60 * 16 1/26/99 4:44p Jason
61 * fixed doorway bug
62 *
63 * 15 10/20/98 3:54p Matt
64 * If a door is activated while shutting, make it start opening again.
65 * If an object is in a door's room, the door will not shut.
66 *
67 * 14 9/28/98 10:55a Jason
68 * fixed some bugs that VC6 caught
69 *
70 * 13 9/08/98 12:06p Jason
71 * added automatic reinitting of doors when rooms get deleted
72 *
73 * 12 6/16/98 10:38a Jeff
74 * localization, strings pulled out to stringtable.h and d3.str
75 *
76 * 11 5/22/98 8:50p Matt
77 * Added sounds for doors
78 *
79 * 10 10/08/97 12:47p Jason
80 * Fixed bug with multiple active doorways list being corrupted
81 *
82 * 9 10/06/97 5:38p Jason
83 * fixed doors to work with timed models
84 *
85 * 8 10/03/97 12:48p Samir
86 * Return -1 if object passed is not a door in GetDoorwayNumFromObject.
87 *
88 * 7 10/03/97 12:51p Jason
89 * added GetDoorwayNumFromObject function
90 *
91 * 6 10/03/97 12:24p Jason
92 * added new keys for doorways
93 *
94 * 5 9/29/97 12:09p Jason
95 * added functionality to doorway system
96 *
97 * 4 9/18/97 1:27p Matt
98 * Cleaned up object struct
99 *
100 * 3 9/12/97 6:09p Jason
101 * fixed bug with load/save level doorways
102 * *
103 *
104 * 2 9/12/97 5:38p Jason
105 * got doors working
106 *
107 * 7 4/02/97 5:14p Samir
108 * Added better checking for ActivateDoorway and fixed GetDoorFlags to
109 * render when finding a 3d door segment.
110 *
111 * 6 3/17/97 6:33p Samir
112 * GetDoorFlags checks 3d door segments also.
113 *
114 * 5 3/14/97 12:51p Samir
115 * Added code to clear active state of doorways.
116 *
117 * 4 3/13/97 11:58a Samir
118 * Added stuff for active doorway and opening/closing
119 *
120 * 3 3/12/97 2:49p Samir
121 * Took out door.cpp globals.
122 *
123 * 2 3/12/97 2:15p Samir
124 * Added source comments and fixed typo.
125 *
126 * $NoKeywords: $
127 */
128
129 #include "doorway.h"cxx . . $ `<file>/Descent3/doorway.h`/
130 #include "door.h"cxx . . $ `<file>/Descent3/door.h`/
131 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
132 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
133 #include "room.h"cxx . . $ `<file>/Descent3/room.h`/
134 #include "polymodel.h"cxx . . $ `<file>/model/polymodel.h`/
135 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
136 #include "hlsoundlib.h"cxx . . $ `<file>/sndlib/hlsoundlib.h`/
137 #include "stringtable.h"cxx . . $ `<file>/Descent3/stringtable.h`/
138 #include "player.h"cxx . . $ `<file>/Descent3/player.h`/
139 #include "osiris_dll.h"cxx . . $ `<file>/Descent3/osiris_dll.h`/
140
141 // ---------------------------------------------------------------------------
142 // Globals
143
144 int Num_active_doorwayscxx . . $ Num_active_doorways.; // number of active doors in game
145 int Active_doorwayscxx . . $ Active_doorways.[MAX_ACTIVE_DOORWAYScxx . . $ `Descent3/doorway.h:120:9`!];
146
147 // This is a mask of all keys held by all players. Robots use this to determine if a door is openable.
148 int Global_keyscxx . . $ Global_keys.;
149
150 // ---------------------------------------------------------------------------
151 // Prototypes
152
153 // TODO: MTS: none of the following were found
154 // void DoorwayOpen(room *rp);
155 // void DoorwayClose(room *rp);
156 // void DoorwayWait(room *rp);
157 objectcxx . . $ object# *GetDoorObjectcxx . . $ GetDoorObject(82c99d40988749bb).(roomcxx . . $ room# *rp);
158
159 // ---------------------------------------------------------------------------
160 // Functions
161
162 void RemoveActiveDoorwaycxx . . $ RemoveActiveDoorway(d4f767463ce0a6b3).(int adway) {
163 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[Active_doorwayscxx . . $ Active_doorways.[adway]];
164
165 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
166 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->doorway_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
167
168 rp->doorway_datacxx . . $ room#doorway_data.->activenumcxx . . $ doorway#activenum. = -1;
169
170 for (int i = adway; i < (Num_active_doorwayscxx . . $ Num_active_doorways. - 1); i++) {
171 Active_doorwayscxx . . $ Active_doorways.[i] = Active_doorwayscxx . . $ Active_doorways.[i + 1];
172 Roomscxx . . $ Rooms.[Active_doorwayscxx . . $ Active_doorways.[i]].doorway_datacxx . . $ room#doorway_data.->activenumcxx . . $ doorway#activenum.--;
173 }
174
175 Num_active_doorwayscxx . . $ Num_active_doorways.--;
176
177 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ActiveDoorways = %d\n", Num_active_doorways);
178 }
179
180 void AddActiveDoorwaycxx . . $ AddActiveDoorway(d4f767463ce0a6b3).(int roomnum) {
181 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[roomnum];
182 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
183
184 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data.;
185 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
186
187 if (dp->activenumcxx . . $ doorway#activenum. != -1) { // already active
188 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp->activenum < Num_active_doorways);
189 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Active_doorways[dp->activenum] == roomnum);
190 } else { // make new active
191 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Num_active_doorways < MAX_ACTIVE_DOORWAYScxx . . $ `Descent3/doorway.h:120:9`!);
192 Active_doorwayscxx . . $ Active_doorways.[Num_active_doorwayscxx . . $ Num_active_doorways.] = roomnum;
193 dp->activenumcxx . . $ doorway#activenum. = Num_active_doorwayscxx . . $ Num_active_doorways.++;
194 }
195
196 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "ActiveDoorways = %d\n", Num_active_doorways);
197 }
198
199 // Given an object handle, returns the doorway number
200 doorwaycxx . . $ doorway# *GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(int door_obj_handle) {
201 objectcxx . . $ object# *objp = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(door_obj_handle);
202
203 if (!objp)
204 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
205
206 ASSERTcxx . . $ `misc/pserror.h:246:9`!(objp->type == OBJ_DOORcxx . . $ `Descent3/object_external.h:177:9`!);
207
208 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[objp->roomnumcxx . . $ object#roomnum.];
209
210 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
211 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->doorway_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
212
213 return rp->doorway_datacxx . . $ room#doorway_data.;
214 }
215
216 // Plays a sound for this door
217 void DoorwayPlaySoundcxx . . $ DoorwayPlaySound(419c470199a90a97).(objectcxx . . $ object# *objp) {
218 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[objp->roomnumcxx . . $ object#roomnum.];
219 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
220
221 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data.;
222 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
223
224 doorcxx . . $ door# *door = &Doorscxx . . $ Doors.[dp->doornumcxx . . $ doorway#doornum.];
225
226 // Stop sound if one playing
227 if (dp->sound_handlecxx . . $ doorway#sound_handle. != -1) {
228 Sound_systemcxx . . $ Sound_system..StopSoundImmediatecxx . . $ hlsSystem#StopSoundImmediate(d4f767463ce0a6b3).(dp->sound_handlecxx . . $ doorway#sound_handle.);
229 dp->sound_handlecxx . . $ doorway#sound_handle. = -1;
230 }
231
232 // Play new sound, if this door has one
233 if ((dp->statecxx . . $ doorway#state. == DOORWAY_OPENINGcxx . . $ `Descent3/doorway.h:102:9`!) || (dp->statecxx . . $ doorway#state. == DOORWAY_OPENING_AUTOcxx . . $ `Descent3/doorway.h:105:9`!)) {
234 if (door->open_soundcxx . . $ door#open_sound. != -1) {
235 float offset = dp->positioncxx . . $ doorway#position. * door->total_open_timecxx . . $ door#total_open_time.;
236 dp->sound_handlecxx . . $ doorway#sound_handle. =
237 Sound_systemcxx . . $ Sound_system..Play3dSoundcxx . . $ hlsSystem#Play3dSound(17f485224ada8dd7).(Doorscxx . . $ Doors.[dp->doornumcxx . . $ doorway#doornum.].open_soundcxx . . $ door#open_sound., SND_PRIORITY_HIGHcxx . . $ `sndlib/ssl_lib.h:283:9`!, objp, 1.0, 0, offset);
238 }
239 } else {
240 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp->state == DOORWAY_CLOSINGcxx . . $ `Descent3/doorway.h:103:9`!);
241 if (door->close_soundcxx . . $ door#close_sound. != -1) {
242 float offset = (1.0 - dp->positioncxx . . $ doorway#position.) * door->total_close_timecxx . . $ door#total_close_time.;
243 dp->sound_handlecxx . . $ doorway#sound_handle. =
244 Sound_systemcxx . . $ Sound_system..Play3dSoundcxx . . $ hlsSystem#Play3dSound(17f485224ada8dd7).(Doorscxx . . $ Doors.[dp->doornumcxx . . $ doorway#doornum.].close_soundcxx . . $ door#close_sound., SND_PRIORITY_HIGHcxx . . $ `sndlib/ssl_lib.h:283:9`!, objp, 1.0, 0, offset);
245 }
246 }
247 }
248
249 // Opens a door and, if it has the auto flag set, closes it
250 // Does not check to see if the door is openable -- the caller must do that.
251 void DoorwayActivatecxx . . $ DoorwayActivate(d4f767463ce0a6b3).(int door_obj_handle) {
252 objectcxx . . $ object# *objp;
253 doorwaycxx . . $ doorway# *dp;
254 doorcxx . . $ door# *door;
255
256 objp = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(door_obj_handle);
257
258 if (!objp)
259 return;
260
261 ASSERTcxx . . $ `misc/pserror.h:246:9`!(objp->type == OBJ_DOORcxx . . $ `Descent3/object_external.h:177:9`!);
262
263 dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
264 if (!dp)
265 return;
266
267 // If already blasted, bail
268 if (dp->flagscxx . . $ doorway#flags. & DF_BLASTEDcxx . . $ `Descent3/doorway.h:108:9`!)
269 return;
270
271 // Get pointer to door
272 door = &Doorscxx . . $ Doors.[dp->doornumcxx . . $ doorway#doornum.];
273
274 // If already open or opening or waiting, do nothing
275 if ((dp->statecxx . . $ doorway#state. == DOORWAY_OPENINGcxx . . $ `Descent3/doorway.h:102:9`!) || (dp->statecxx . . $ doorway#state. == DOORWAY_WAITINGcxx . . $ `Descent3/doorway.h:104:9`!) || (dp->statecxx . . $ doorway#state. == DOORWAY_OPENING_AUTOcxx . . $ `Descent3/doorway.h:105:9`!))
276 return;
277
278 // Store new desired position
279 dp->dest_poscxx . . $ doorway#dest_pos. = 1.0;
280
281 // If not already active, create active entry
282 AddActiveDoorwaycxx . . $ AddActiveDoorway(d4f767463ce0a6b3).(objp->roomnumcxx . . $ object#roomnum.);
283
284 // Set new state
285 dp->statecxx . . $ doorway#state. = (dp->flagscxx . . $ doorway#flags. & DF_AUTOcxx . . $ `Descent3/doorway.h:109:9`!) ? DOORWAY_OPENING_AUTOcxx . . $ `Descent3/doorway.h:105:9`! : DOORWAY_OPENINGcxx . . $ `Descent3/doorway.h:102:9`!;
286
287 // Play sound
288 DoorwayPlaySoundcxx . . $ DoorwayPlaySound(419c470199a90a97).(objp);
289
290 // Send notification event
291 tOSIRISEventInfocxx . . $ tOSIRISEventInfo# ei;
292 Osiris_CallEventcxx . . $ Osiris_CallEvent(91e8d3045aa5549c).(objp, EVT_DOOR_ACTIVATEcxx . . $ `scripts/osiris_common.h:391:9`!, &ei);
293 }
294
295 // Sets the current position of the door. 0.0 = totally closed, 1.0 = totally open
296 // Does not check to see if the door is openable -- the caller must do that.
297 void DoorwaySetPositioncxx . . $ DoorwaySetPosition(43c79ee2f1b9aefe).(int door_obj_handle, float pos) {
298 objectcxx . . $ object# *objp;
299 doorwaycxx . . $ doorway# *dp;
300 doorcxx . . $ door# *door;
301
302 objp = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(door_obj_handle);
303
304 if (!objp)
305 return;
306
307 ASSERTcxx . . $ `misc/pserror.h:246:9`!(objp->type == OBJ_DOORcxx . . $ `Descent3/object_external.h:177:9`!);
308
309 // Get pointer to doorway
310 dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
311 if (!dp)
312 return;
313
314 // Get pointer to door
315 door = &Doorscxx . . $ Doors.[dp->doornumcxx . . $ doorway#doornum.];
316
317 // Set new dest position
318 dp->dest_poscxx . . $ doorway#dest_pos. = pos;
319
320 // Check if already there
321 if (dp->positioncxx . . $ doorway#position. == pos)
322 return;
323
324 // If not already active, create active entry
325 AddActiveDoorwaycxx . . $ AddActiveDoorway(d4f767463ce0a6b3).(objp->roomnumcxx . . $ object#roomnum.);
326
327 // Set new state & play sound
328 if (dp->dest_poscxx . . $ doorway#dest_pos. > dp->positioncxx . . $ doorway#position.)
329 dp->statecxx . . $ doorway#state. = DOORWAY_OPENINGcxx . . $ `Descent3/doorway.h:102:9`!;
330 else
331 dp->statecxx . . $ doorway#state. = DOORWAY_CLOSINGcxx . . $ `Descent3/doorway.h:103:9`!;
332
333 // Play sound
334 DoorwayPlaySoundcxx . . $ DoorwayPlaySound(419c470199a90a97).(objp);
335 }
336
337 void DoorwayStopcxx . . $ DoorwayStop(d4f767463ce0a6b3).(int door_obj_handle) {
338 // Get pointer to doorway
339 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
340 if (!dp)
341 return;
342
343 // Set the door as stopped
344 dp->dest_poscxx . . $ doorway#dest_pos. = dp->positioncxx . . $ doorway#position.;
345 dp->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
346
347 // Stop the sound if one is playing
348 if (dp->sound_handlecxx . . $ doorway#sound_handle. != -1) {
349 Sound_systemcxx . . $ Sound_system..StopSoundImmediatecxx . . $ hlsSystem#StopSoundImmediate(d4f767463ce0a6b3).(dp->sound_handlecxx . . $ doorway#sound_handle.);
350 dp->sound_handlecxx . . $ doorway#sound_handle. = -1;
351 }
352
353 // Remove from the active doorway list
354 if (dp->activenumcxx . . $ doorway#activenum. != -1)
355 RemoveActiveDoorwaycxx . . $ RemoveActiveDoorway(d4f767463ce0a6b3).(dp->activenumcxx . . $ doorway#activenum.);
356 }
357
358 // Called when a door is blown up
359 void DoorwayDestroycxx . . $ DoorwayDestroy(419c470199a90a97).(objectcxx . . $ object# *objp) {
360 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[objp->roomnumcxx . . $ object#roomnum.];
361 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data.;
362
363 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
364 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp);
365
366 dp->flagscxx . . $ doorway#flags. |= DF_BLASTEDcxx . . $ `Descent3/doorway.h:108:9`!;
367 dp->positioncxx . . $ doorway#position. = 1.0;
368 dp->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
369
370 // Remove from the active doorway list
371 if (dp->activenumcxx . . $ doorway#activenum. != -1)
372 RemoveActiveDoorwaycxx . . $ RemoveActiveDoorway(d4f767463ce0a6b3).(dp->activenumcxx . . $ doorway#activenum.);
373 }
374
375 // Stop all doors
376 void DoorwayDeactivateAllcxx . . $ DoorwayDeactivateAll(49f6e7a06ebc5aa8).() {
377 int r;
378 roomcxx . . $ room# *rp;
379
380 // Go through all rooms and deactivate doors
381 for (r = 0, rp = Roomscxx . . $ Rooms.; r <= Highest_room_indexcxx . . $ Highest_room_index.; r++) {
382 if (rp->usedcxx . . $ room#used. && (rp->flagscxx . . $ room#flags. & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!)) {
383 if (rp->doorway_datacxx . . $ room#doorway_data.->statecxx . . $ doorway#state. != DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!) {
384 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data.;
385 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
386 dp->positioncxx . . $ doorway#position. = dp->dest_poscxx . . $ doorway#dest_pos.;
387 dp->activenumcxx . . $ doorway#activenum. = -1;
388 dp->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
389 if (dp->sound_handlecxx . . $ doorway#sound_handle. != -1) {
390 Sound_systemcxx . . $ Sound_system..StopSoundImmediatecxx . . $ hlsSystem#StopSoundImmediate(d4f767463ce0a6b3).(dp->sound_handlecxx . . $ doorway#sound_handle.);
391 dp->sound_handlecxx . . $ doorway#sound_handle. = -1;
392 }
393 DoorwayUpdateAnimationcxx . . $ DoorwayUpdateAnimation(cd8c4e8cd0ee4c38).(rp);
394 }
395 }
396 }
397
398 Num_active_doorwayscxx . . $ Num_active_doorways. = 0;
399 }
400
401 // Sets the corresponding door objects animation frame
402 void DoorwayUpdateAnimationcxx . . $ DoorwayUpdateAnimation(cd8c4e8cd0ee4c38).(roomcxx . . $ room# *rp) {
403 doorwaycxx . . $ doorway# *dway;
404 poly_modelcxx . . $ poly_model# *pm;
405 int doornum;
406 float norm;
407
408 dway = rp->doorway_datacxx . . $ room#doorway_data.;
409
410 objectcxx . . $ object# *objp = GetDoorObjectcxx . . $ GetDoorObject(82c99d40988749bb).(rp);
411 if (!objp)
412 return;
413
414 doornum = objp->idcxx . . $ object#id.;
415 pm = &Poly_modelscxx . . $ Poly_models.[GetDoorImagecxx . . $ GetDoorImage(7864480464b09eea).(doornum)];
416
417 norm = DoorwayPositioncxx . . $ DoorwayPosition(fd42386fc3d80a5d).(rp);
418
419 if (pm->flagscxx . . $ poly_model#flags. & PMF_TIMEDcxx . . $ `lib/polymodel_external.h:222:9`!)
420 objp->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..anim_framecxx . . $ polyobj_info#anim_frame. = pm->frame_maxcxx . . $ poly_model#frame_max. * norm;
421 else
422 objp->rtypecxx . . $ object#rtype..pobj_infocxx . . $ object#$anonymous_type_10#pobj_info..anim_framecxx . . $ polyobj_info#anim_frame. = pm->max_keyscxx . . $ poly_model#max_keys. * norm;
423 }
424
425 // Update all doorways currently active in the mine
426 void DoorwayDoFramecxx . . $ DoorwayDoFrame(49f6e7a06ebc5aa8).() {
427 int i_doorway;
428
429 for (i_doorway = 0; i_doorway < Num_active_doorwayscxx . . $ Num_active_doorways.; i_doorway++) {
430 int roomnum = Active_doorwayscxx . . $ Active_doorways.[i_doorway];
431 roomcxx . . $ room# *rp = &Roomscxx . . $ Rooms.[roomnum];
432 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
433 doorwaycxx . . $ doorway# *dway = rp->doorway_datacxx . . $ room#doorway_data.;
434 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dway != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
435 doorcxx . . $ door# *door = &Doorscxx . . $ Doors.[dway->doornumcxx . . $ doorway#doornum.];
436 float delta; // movement delta
437
438 switch (dway->statecxx . . $ doorway#state.) {
439 case DOORWAY_OPENINGcxx . . $ `Descent3/doorway.h:102:9`!:
440 case DOORWAY_OPENING_AUTOcxx . . $ `Descent3/doorway.h:105:9`!: // doorway is opening
441 delta = Frametimecxx . . $ Frametime. / door->total_open_timecxx . . $ door#total_open_time.;
442
443 dway->positioncxx . . $ doorway#position. += delta;
444
445 if (dway->positioncxx . . $ doorway#position. >= dway->dest_poscxx . . $ doorway#dest_pos.) {
446 dway->positioncxx . . $ doorway#position. = dway->dest_poscxx . . $ doorway#dest_pos.;
447
448 if (dway->statecxx . . $ doorway#state. == DOORWAY_OPENING_AUTOcxx . . $ `Descent3/doorway.h:105:9`!) {
449 dway->statecxx . . $ doorway#state. = DOORWAY_WAITINGcxx . . $ `Descent3/doorway.h:104:9`!;
450 dway->dest_poscxx . . $ doorway#dest_pos. = door->total_time_opencxx . . $ door#total_time_open.;
451 } else { // non automatic doors will stay open, hence are no longer active
452 dway->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
453 RemoveActiveDoorwaycxx . . $ RemoveActiveDoorway(d4f767463ce0a6b3).(i_doorway);
454 }
455 }
456 break;
457
458 case DOORWAY_CLOSINGcxx . . $ `Descent3/doorway.h:103:9`!: // doorway is closing
459 delta = Frametimecxx . . $ Frametime. / door->total_close_timecxx . . $ door#total_close_time.;
460
461 dway->positioncxx . . $ doorway#position. -= delta;
462
463 if (dway->positioncxx . . $ doorway#position. <= dway->dest_poscxx . . $ doorway#dest_pos.) {
464 dway->positioncxx . . $ doorway#position. = dway->dest_poscxx . . $ doorway#dest_pos.;
465
466 dway->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
467 RemoveActiveDoorwaycxx . . $ RemoveActiveDoorway(d4f767463ce0a6b3).(i_doorway);
468
469 // Send notification event
470 objectcxx . . $ object# *objp = GetDoorObjectcxx . . $ GetDoorObject(82c99d40988749bb).(rp);
471 ASSERTcxx . . $ `misc/pserror.h:246:9`!(objp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
472 tOSIRISEventInfocxx . . $ tOSIRISEventInfo# ei;
473 Osiris_CallEventcxx . . $ Osiris_CallEvent(91e8d3045aa5549c).(objp, EVT_DOOR_CLOSEcxx . . $ `scripts/osiris_common.h:392:9`!, &ei);
474 }
475 break;
476
477 case DOORWAY_WAITINGcxx . . $ `Descent3/doorway.h:104:9`!: // doorway is in wait state
478
479 dway->dest_poscxx . . $ doorway#dest_pos. -= Frametimecxx . . $ Frametime.;
480
481 if (dway->dest_poscxx . . $ doorway#dest_pos. <= 0.0) {
482
483 objectcxx . . $ object# *door_objp = GetDoorObjectcxx . . $ GetDoorObject(82c99d40988749bb).(rp);
484 ASSERTcxx . . $ `misc/pserror.h:246:9`!(door_objp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
485
486 // Time to start closing. See if there's anything in the way
487 if (!((door_objp->nextcxx . . $ object#next. != -1) || (door_objp->prevcxx . . $ object#prev. != -1))) {
488
489 dway->dest_poscxx . . $ doorway#dest_pos. = 0.0;
490 dway->statecxx . . $ doorway#state. = DOORWAY_CLOSINGcxx . . $ `Descent3/doorway.h:103:9`!;
491
492 // Play sound
493 DoorwayPlaySoundcxx . . $ DoorwayPlaySound(419c470199a90a97).(door_objp);
494 }
495 }
496 break;
497
498 default:
499 Int3cxx . . $ `misc/pserror.h:247:9`!(); // these states shouldn't happen if door is active
500 }
501
502 // Update the animation state
503 DoorwayUpdateAnimationcxx . . $ DoorwayUpdateAnimation(cd8c4e8cd0ee4c38).(rp);
504 }
505 }
506
507 // returns a pointer to the door object for the specified doorway
508 objectcxx . . $ object# *GetDoorObjectcxx . . $ GetDoorObject(82c99d40988749bb).(roomcxx . . $ room# *rp) {
509 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
510
511 for (int objnum = rp->objectscxx . . $ room#objects.; (objnum != -1); objnum = Objectscxx . . $ Objects.[objnum].nextcxx . . $ object#next.)
512 if (Objectscxx . . $ Objects.[objnum].typecxx . . $ object#type. == OBJ_DOORcxx . . $ `Descent3/object_external.h:177:9`!)
513 return &Objectscxx . . $ Objects.[objnum];
514
515 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
516 }
517
518 // Returns true if the doorway is locked, else false
519 bool DoorwayLockedcxx . . $ DoorwayLocked(83c267b20bac841a).(int door_obj_handle) {
520 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
521
522 if (!dp)
523 return 0;
524
525 return ((dp->flagscxx . . $ doorway#flags. & DF_LOCKEDcxx . . $ `Descent3/doorway.h:110:9`!) != 0);
526 }
527
528 // Returns true if the doorway is locked, else false
529 bool DoorwayLockedcxx . . $ DoorwayLocked(52ff2e225c16149e).(roomcxx . . $ room# *rp) {
530 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
531
532 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data.;
533 ASSERTcxx . . $ `misc/pserror.h:246:9`!(dp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
534
535 return ((dp->flagscxx . . $ doorway#flags. & DF_LOCKEDcxx . . $ `Descent3/doorway.h:110:9`!) != 0);
536 }
537
538 // Returns true if the doorway is openable by the specified object, else false
539 bool DoorwayOpenablecxx . . $ DoorwayOpenable(cf9ef193275fa6d8).(int door_obj_handle, int opener_handle) {
540 int keys;
541
542 // Get pointer to doorway
543 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
544 if (!dp)
545 return 0;
546
547 // If locked, no one can open it
548 if (dp->flagscxx . . $ doorway#flags. & DF_LOCKEDcxx . . $ `Descent3/doorway.h:110:9`!)
549 return 0;
550
551 // If no keys needed, anyone can open
552 if (dp->keys_neededcxx . . $ doorway#keys_needed. == 0)
553 return 1;
554
555 objectcxx . . $ object# *opener = ObjGetcxx . . $ ObjGet(11672e354c0b263a).(opener_handle);
556
557 // If invalid object, can't open
558 if (!opener)
559 return 0;
560
561 // If a weapon, get the parent
562 if (opener->typecxx . . $ object#type. == OBJ_WEAPONcxx . . $ `Descent3/object_external.h:165:9`!) {
563 opener = ObjGetUltimateParentcxx . . $ ObjGetUltimateParent(64a00b84ed3f82ee).(opener);
564 ASSERTcxx . . $ `misc/pserror.h:246:9`!(opener && (opener->type != OBJ_WEAPONcxx . . $ `Descent3/object_external.h:165:9`!));
565 }
566
567 // Get the opener's keys
568 if (opener->typecxx . . $ object#type. == OBJ_PLAYERcxx . . $ `Descent3/object_external.h:164:9`!)
569 keys = Playerscxx . . $ Players.[opener->idcxx . . $ object#id.].keyscxx . . $ player#keys.;
570 else if ((opener->typecxx . . $ object#type. == OBJ_ROBOTcxx . . $ `Descent3/object_external.h:162:9`!) || ((opener->typecxx . . $ object#type. == OBJ_BUILDINGcxx . . $ `Descent3/object_external.h:176:9`!) && opener->ai_infocxx . . $ object#ai_info.))
571 keys = Global_keyscxx . . $ Global_keys.;
572 else
573 return 0; // If not a robot or a player, cannot open keyed doors
574
575 // Door is openenable if have proper keys
576 if (dp->flagscxx . . $ doorway#flags. & DF_KEY_ONLY_ONEcxx . . $ `Descent3/doorway.h:111:9`!)
577 return ((keys & dp->keys_neededcxx . . $ doorway#keys_needed.) != 0);
578 else
579 return ((keys & dp->keys_neededcxx . . $ doorway#keys_needed.) == dp->keys_neededcxx . . $ doorway#keys_needed.);
580 }
581
582 // Returns the current state of the specified door
583 int DoorwayStatecxx . . $ DoorwayState(7864480464b09eea).(int door_obj_handle) {
584 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
585
586 if (!dp)
587 return DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
588
589 return dp->statecxx . . $ doorway#state.;
590 }
591
592 // Locks or unlocks a given doorway
593 void DoorwayLockUnlockcxx . . $ DoorwayLockUnlock(918ebd27a9ddbad3).(int door_obj_handle, bool state) {
594 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
595
596 if (!dp)
597 return;
598
599 if (state)
600 dp->flagscxx . . $ doorway#flags. |= DF_LOCKEDcxx . . $ `Descent3/doorway.h:110:9`!;
601 else
602 dp->flagscxx . . $ doorway#flags. &= ~DF_LOCKEDcxx . . $ `Descent3/doorway.h:110:9`!;
603 }
604
605 // Returns the current position of the door. 0.0 = totally closed, 1.0 = totally open
606 float DoorwayPositioncxx . . $ DoorwayPosition(fd42386fc3d80a5d).(roomcxx . . $ room# *rp) {
607 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->flags & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!);
608 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->doorway_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
609
610 return rp->doorway_datacxx . . $ room#doorway_data.->positioncxx . . $ doorway#position.;
611 }
612
613 // Returns the current position of the door. 0.0 = totally closed, 1.0 = totally open
614 float DoorwayPositioncxx . . $ DoorwayPosition(5cde91ea12d43f46).(int door_obj_handle) {
615 doorwaycxx . . $ doorway# *dp = GetDoorwayFromObjectcxx . . $ GetDoorwayFromObject(fd3f60e6b7ee6406).(door_obj_handle);
616
617 if (!dp)
618 return 0.0;
619
620 return dp->positioncxx . . $ doorway#position.;
621 }
622
623 // Called after loading a saved game to rebuild the active list
624 void DoorwayRebuildActiveListcxx . . $ DoorwayRebuildActiveList(49f6e7a06ebc5aa8).() {
625 int r;
626 roomcxx . . $ room# *rp;
627
628 // Reset active doorways count
629 Num_active_doorwayscxx . . $ Num_active_doorways. = 0;
630
631 // Go through all rooms and look for active doors
632 for (r = 0, rp = Roomscxx . . $ Rooms.; r <= Highest_room_indexcxx . . $ Highest_room_index.; r++) {
633 if (rp->usedcxx . . $ room#used. && (rp->flagscxx . . $ room#flags. & RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!)) {
634 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->doorway_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
635 if (rp->doorway_datacxx . . $ room#doorway_data.->statecxx . . $ doorway#state. != DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!)
636 AddActiveDoorwaycxx . . $ AddActiveDoorway(d4f767463ce0a6b3).(r);
637 }
638 }
639 }
640
641 // Adds a doorway to the specified room
642 // Returns a pointer to the doorway struct
643 doorwaycxx . . $ doorway# *DoorwayAddcxx . . $ DoorwayAdd(aeacdc229a118899).(roomcxx . . $ room# *rp, int doornum) {
644 ASSERTcxx . . $ `misc/pserror.h:246:9`!(rp->doorway_data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
645
646 rp->flagscxx . . $ room#flags. |= RF_DOORcxx . . $ `Descent3/room_external.h:176:9`!;
647
648 doorwaycxx . . $ doorway# *dp = rp->doorway_datacxx . . $ room#doorway_data. = (doorwaycxx . . $ doorway# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(*rp->doorway_data));
649
650 // Initialize
651 dp->doornumcxx . . $ doorway#doornum. = doornum;
652 dp->dest_poscxx . . $ doorway#dest_pos. = dp->positioncxx . . $ doorway#position. = 0.0;
653 dp->statecxx . . $ doorway#state. = DOORWAY_STOPPEDcxx . . $ `Descent3/doorway.h:101:9`!;
654 dp->flagscxx . . $ doorway#flags. = DF_AUTOcxx . . $ `Descent3/doorway.h:109:9`!;
655 dp->keys_neededcxx . . $ doorway#keys_needed. = 0;
656 dp->activenumcxx . . $ doorway#activenum. = -1;
657 dp->sound_handlecxx . . $ doorway#sound_handle. = -1;
658
659 return dp;
660 }