Debian Codegraph @

similar/main/wall.cpp

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 #include <ranges>
21 #include "wall.h"
22 #include "text.h"
23 #include "fireball.h"
24 #include "textures.h"
25 #include "newdemo.h"
26 #include "multi.h"
27 #include "gameseq.h"
28 #include "physfs-serial.h"
29 #include "gameseg.h"
30 #include "hudmsg.h"
31 #include "effects.h"
32
33 #include "d_enumerate.h"
34 #include "d_levelstate.h"
35 #include "d_range.h"
36 #include "compiler-range_for.h"
37 #include "partial_range.h"
38 #include "segiter.h"
39 #include "d_zip.h"
40
41 // Special door on boss level which is locked if not in multiplayer...sorry for this awful solution --MK.
42 #define BOSS_LOCKED_DOOR_LEVEL 7
43 #define BOSS_LOCKED_DOOR_SEG 595
44 #define BOSS_LOCKED_DOOR_SIDE sidenum_t::WFRONT
45
46 namespace dcx {
47 unsigned Num_wall_anims;
48 }
49
50 namespace dsx {
51
52 namespace {
53
54 struct ad_removal_predicate
55 {
56 bool operator()(active_door &) const;
57 };
58
59 struct find_active_door_predicate
60 {
61 const wallnum_t wall_num;
62 explicit find_active_door_predicate(const wallnum_t i) :
63 wall_num(i)
64 {
65 }
66 bool operator()(active_door &d) const {
67 if (d.front_wallnum[0] == wall_num)
68 return true;
69 if (d.back_wallnum[0] == wall_num)
70 return true;
71 if (d.n_parts != 2)
72 return false;
73 if (d.front_wallnum[1] == wall_num)
74 return true;
75 if (d.back_wallnum[1] == wall_num)
76 return true;
77 return false;
78 }
79 };
80
81 }
82
83 }
84 #if DXX_BUILD_DESCENT == 2
85 #include "collide.h"
86 namespace dsx {
87 constexpr std::integral_constant<unsigned, F1_0> CLOAKING_WALL_TIME{};
88
89 namespace {
90
91 struct cwframe
92 {
93 wall &w;
94 std::array<uvl, 4> &uvls;
95 cwframe(fvmsegptr &vmsegptr, wall &wr) :
96 w(wr),
97 uvls(vmsegptr(w.segnum)->unique_segment::sides[w.sidenum].uvls)
98 {
99 }
100 };
101
102 struct cwresult
103 {
104 const bool remove;
105 const bool record;
106 };
107
108 struct cw_removal_predicate
109 {
110 fvmsegptr &vmsegptr;
111 wall_array &Walls;
112 unsigned num_cloaking_walls{0};
113 bool operator()(cloaking_wall &d);
114 };
115
116 struct find_cloaked_wall_predicate
117 {
118 const vmwallidx_t w;
119 bool operator()(const cloaking_wall &cw) const
120 {
121 return cw.front_wallnum == w || cw.back_wallnum == w;
122 }
123 };
124
125 }
126
127 }
128 #endif
129
130 namespace {
131
132 static std::pair<uint_fast32_t, uint_fast32_t> get_transparency_check_values(const unique_side &side)
133 {
134 if (const auto masked_tmap_num2 = static_cast<uint_fast32_t>(get_texture_index(side.tmap_num2)))
135 return {masked_tmap_num2, BM_FLAG_SUPER_TRANSPARENT};
136 return {get_texture_index(side.tmap_num), BM_FLAG_TRANSPARENT};
137 }
138
139 // This function determines whether the current segment/side is transparent
140 // 1 = YES
141 // 0 = NO
142 static uint_fast32_t check_transparency(const GameBitmaps_array &GameBitmaps, const Textures_array &Textures, const unique_side &side)
143 {
144 const auto &&v = get_transparency_check_values(side);
145 return GameBitmaps[Textures[v.first]].get_flag_mask(v.second);
146 }
147
148 }
149
150 //-----------------------------------------------------------------
151 // This function checks whether we can fly through the given side.
152 // In other words, whether or not we have a 'doorway'
153 // Flags:
154 // WALL_IS_DOORWAY_FLAG::FLY 1
155 // WALL_IS_DOORWAY_FLAG::RENDER 2
156 // WALL_IS_DOORWAY_FLAG::RENDPAST 4
157 // Return values:
158 // wall_is_doorway_result::wall 2 // 0/1/0 wall
159 // wall_is_doorway_result::transparent_wall 6 // 0/1/1 transparent wall
160 // wall_is_doorway_result::illusory_wall 3 // 1/1/0 illusory wall
161 // wall_is_doorway_result::transillusory_wall 7 // 1/1/1 transparent illusory wall
162 // wall_is_doorway_result::no_wall 5 // 1/0/1 no wall, can fly through
163 namespace dsx {
164
165 namespace {
166
167 static wall_is_doorway_result wall_is_doorway(const GameBitmaps_array &GameBitmaps, const Textures_array &Textures, fvcwallptr &vcwallptr, const shared_side &sside, const unique_side &uside)
168 {
169 auto &w = *vcwallptr(sside.wall_num);
170 const auto type{w.type};
171 if (type == WALL_OPEN)
172 return wall_is_doorway_result::no_wall;
173
174 #if DXX_BUILD_DESCENT == 2
175 if (unlikely(type == WALL_CLOAKED))
176 return wall_is_doorway_result::cloaked_wall;
177 #endif
178
179 const auto flags{w.flags};
180 if (type == WALL_ILLUSION) {
181 if (flags & wall_flag::illusion_off)
182 return wall_is_doorway_result::no_wall;
183 else {
184 if (check_transparency(GameBitmaps, Textures, uside))
185 return wall_is_doorway_result::transillusory_wall;
186 else
187 return wall_is_doorway_result::illusory_wall;
188 }
189 }
190
191 if (type == WALL_BLASTABLE) {
192 if (flags & wall_flag::blasted)
193 return wall_is_doorway_result::transillusory_wall;
194 }
195 else
196 {
197 if (unlikely(flags & wall_flag::door_opened))
198 return wall_is_doorway_result::transillusory_wall;
199 if (likely(type == WALL_DOOR) && unlikely(w.state == wall_state::opening))
200 return wall_is_doorway_result::transparent_wall;
201 }
202 // If none of the above flags are set, there is no doorway.
203 if (check_transparency(GameBitmaps, Textures, uside))
204 return wall_is_doorway_result::transparent_wall;
205 else
206 return wall_is_doorway_result::wall; // There are children behind the door.
207 }
208
209 }
210
211 wall_is_doorway_result WALL_IS_DOORWAY(const GameBitmaps_array &GameBitmaps, const Textures_array &Textures, fvcwallptr &vcwallptr, const cscusegment seg, const sidenum_t side)
212 {
213 const auto child = seg.s.children[side];
214 if (unlikely(child == segment_none))
215 return wall_is_doorway_result::wall;
216 if (unlikely(child == segment_exit))
217 return wall_is_doorway_result::external;
218 auto &sside = seg.s.sides[side];
219 if (likely(sside.wall_num == wall_none))
220 return wall_is_doorway_result::no_wall;
221 auto &uside = seg.u.sides[side];
222 return wall_is_doorway(GameBitmaps, Textures, vcwallptr, sside, uside);
223 }
224
225 #if DXX_USE_EDITOR
226 //-----------------------------------------------------------------
227 // Initializes all the walls (in other words, no special walls)
228 void wall_init(d_level_unique_wall_subsystem_state &LevelUniqueWallSubsystemState)
229 {
230 init_exploding_walls();
231 auto &Walls = LevelUniqueWallSubsystemState.Walls;
232 Walls.set_count(0);
233 range_for (auto &w, Walls)
234 {
235 w.segnum = segment_none;
236 w.sidenum = side_none;
237 w.type = WALL_NORMAL;
238 w.flags = {};
239 w.hps = 0;
240 w.trigger = trigger_none;
241 w.clip_num = -1;
242 w.linked_wall = wall_none;
243 }
244 auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors;
245 ActiveDoors.set_count(0);
246 #if DXX_BUILD_DESCENT == 2
247 auto &CloakingWalls = LevelUniqueWallSubsystemState.CloakingWalls;
248 CloakingWalls.set_count(0);
249 #endif
250
251 }
252 #endif
253
254 //set the tmap_num or tmap_num2 field for a wall/door
255 void wall_set_tmap_num(const wclip &anim, const vmsegptridx_t seg, const sidenum_t side, const vmsegptridx_t csegp, const sidenum_t cside, const unsigned frame_num)
256 {
257 const auto newdemo_state{Newdemo_state};
258 if (newdemo_state == ND_STATE_PLAYBACK)
259 return;
260
261 const auto tmap = anim.frames[frame_num];
262 auto &uside = seg->unique_segment::sides[side];
263 auto &cuside = csegp->unique_segment::sides[cside];
264 if (anim.flags & WCF_TMAP1) {
265 const texture1_value t1{tmap};
266 if (t1 != uside.tmap_num || t1 != cuside.tmap_num)
267 {
268 uside.tmap_num = cuside.tmap_num = t1;
269 if (newdemo_state == ND_STATE_RECORDING)
270 newdemo_record_wall_set_tmap_num1(seg,side,csegp,cside,t1);
271 }
272 } else {
273 const texture2_value t2{tmap};
274 if (t2 != uside.tmap_num2 || t2 != cuside.tmap_num2)
275 {
276 uside.tmap_num2 = cuside.tmap_num2 = t2;
277 if (newdemo_state == ND_STATE_RECORDING)
278 newdemo_record_wall_set_tmap_num2(seg,side,csegp,cside,t2);
279 }
280 }
281 }
282
283 }
284
285 namespace {
286
287 // -------------------------------------------------------------------------------
288 //when the wall has used all its hitpoints, this will destroy it
289 static void blast_blastable_wall(const vmsegptridx_t seg, const sidenum_t side, wall &w0)
290 {
291 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
292 auto &Objects = LevelUniqueObjectState.Objects;
293 auto &Vertices = LevelSharedVertexState.get_vertices();
294 auto &vmobjptr = Objects.vmptr;
295 auto &sside = seg->shared_segment::sides[side];
296 const auto wall_num = sside.wall_num;
297 w0.hps = -1; //say it's blasted
298
299 const auto &&csegp = seg.absolute_sibling(seg->shared_segment::children[side]);
300 auto Connectside = find_connect_side(seg, csegp);
301 Assert(Connectside != side_none);
302 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
303 auto &Walls = LevelUniqueWallSubsystemState.Walls;
304 auto &WallAnims = GameSharedState.WallAnims;
305 auto &imwallptr = Walls.imptr;
306 const auto &&w1 = imwallptr(cwall_num);
307 if (w1)
308 LevelUniqueStuckObjectState.kill_stuck_objects(vmobjptr, cwall_num);
309 LevelUniqueStuckObjectState.kill_stuck_objects(vmobjptr, wall_num);
310 flush_fcd_cache();
311
312 const auto a = w0.clip_num;
313 auto &wa = WallAnims[a];
314 //if this is an exploding wall, explode it
315 if (wa.flags & WCF_EXPLODES)
316 {
317 auto &vcvertptr = Vertices.vcptr;
318 explode_wall(vcvertptr, seg, static_cast<sidenum_t>(side), w0);
319 }
320 else {
321 //if not exploding, set final frame, and make door passable
322 const auto n = wa.num_frames;
323 w0.flags |= wall_flag::blasted;
324 if (w1)
325 w1->flags |= wall_flag::blasted;
326 wall_set_tmap_num(wa, seg, side, csegp, Connectside, n - 1);
327 }
328
329 }
330
331 }
332
333 //-----------------------------------------------------------------
334 // Destroys a blastable wall.
335 void wall_destroy(const vmsegptridx_t seg, const sidenum_t side)
336 {
337 auto &Walls = LevelUniqueWallSubsystemState.Walls;
338 auto &vmwallptr = Walls.vmptr;
339 auto &w = *vmwallptr(seg->shared_segment::sides[side].wall_num);
340 if (w.type == WALL_BLASTABLE)
341 blast_blastable_wall(seg, side, w);
342 else
343 Error("Hey bub, you are trying to destroy an indestructable wall.");
344 }
345
346 //-----------------------------------------------------------------
347 // Deteriorate appearance of wall. (Changes bitmap (paste-ons))
348 void wall_damage(const vmsegptridx_t seg, const sidenum_t side, fix damage)
349 {
350 auto &WallAnims = GameSharedState.WallAnims;
351 int i;
352
353 auto &sside = seg->shared_segment::sides[side];
354 const auto wall_num = sside.wall_num;
355 if (wall_num == wall_none) {
356 return;
357 }
358
359 auto &Walls = LevelUniqueWallSubsystemState.Walls;
360 auto &vmwallptr = Walls.vmptr;
361 auto &w0 = *vmwallptr(wall_num);
362 if (w0.type != WALL_BLASTABLE)
363 return;
364
365 if (!(w0.flags & wall_flag::blasted) && w0.hps >= 0)
366 {
367 const auto &&csegp = seg.absolute_sibling(seg->shared_segment::children[side]);
368 auto Connectside = find_connect_side(seg, csegp);
369 Assert(Connectside != side_none);
370 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
371 auto &imwallptr = Walls.imptr;
372 if (const auto &&w1p = imwallptr(cwall_num))
373 {
374 auto &w1 = *w1p;
375 w1.hps -= damage;
376 }
377 w0.hps -= damage;
378
379 const auto a = w0.clip_num;
380 const auto n = WallAnims[a].num_frames;
381
382 if (w0.hps < WALL_HPS*1/n) {
383 blast_blastable_wall(seg, side, w0);
384 if (Game_mode & GM_MULTI)
385 multi_send_door_open(seg, side, w0.flags);
386 }
387 else
388 for (i=0;i<n;i++)
389 if (w0.hps < WALL_HPS*(n-i)/n)
390 {
391 wall_set_tmap_num(WallAnims[a], seg, side, csegp, Connectside, i);
392 }
393 }
394 }
395
396
397 //-----------------------------------------------------------------
398 // Opens a door
399 namespace dsx {
400 void wall_open_door(const vmsegptridx_t seg, const sidenum_t side)
401 {
402 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
403 auto &Objects = LevelUniqueObjectState.Objects;
404 auto &Vertices = LevelSharedVertexState.get_vertices();
405 auto &WallAnims = GameSharedState.WallAnims;
406 auto &vmobjptr = Objects.vmptr;
407 active_door *d;
408
409 auto &sside = seg->shared_segment::sides[side];
410 const auto wall_num = sside.wall_num;
411 auto &Walls = LevelUniqueWallSubsystemState.Walls;
412 auto &vmwallptr = Walls.vmptr;
413 wall *const w = vmwallptr(wall_num);
414 LevelUniqueStuckObjectState.kill_stuck_objects(vmobjptr, wall_num);
415
416 if (w->state == wall_state::opening || //already opening
417 w->state == wall_state::waiting) //open, waiting to close
418 return;
419 #if DXX_BUILD_DESCENT == 2
420 if (w->state == wall_state::open) //open, & staying open
421 return;
422 #endif
423
424 auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors;
425 auto &vmactdoorptr = ActiveDoors.vmptr;
426 if (w->state == wall_state::closing) { //closing, so reuse door
427 const auto &&r{std::ranges::subrange(vmactdoorptr)};
428 const auto &&re = r.end();
429 const auto &&i{std::ranges::find_if(r.begin(), re, find_active_door_predicate(wall_num))};
430 if (i == re) // likely in demo playback or multiplayer
431 {
432 const auto c = ActiveDoors.get_count();
433 ActiveDoors.set_count(c + 1);
434 d = vmactdoorptr(static_cast<actdoornum_t>(c));
435 d->time = 0;
436 }
437 else
438 {
439 d = &*i;
440 d->time = WallAnims[w->clip_num].play_time - d->time;
441 if (d->time < 0)
442 d->time = 0;
443 }
444 }
445 else { //create new door
446 Assert(w->state == wall_state::closed);
447 const auto i = ActiveDoors.get_count();
448 ActiveDoors.set_count(i + 1);
449 d = vmactdoorptr(static_cast<actdoornum_t>(i));
450 d->time = 0;
451 }
452
453
454 w->state = wall_state::opening;
455
456 // So that door can't be shot while opening
457 const auto &&csegp = vcsegptr(seg->shared_segment::children[side]);
458 auto Connectside = find_connect_side(seg, csegp);
459 if (Connectside != side_none)
460 {
461 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
462 auto &imwallptr = Walls.imptr;
463 if (const auto &&w1 = imwallptr(cwall_num))
464 {
465 w1->state = wall_state::opening;
466 d->back_wallnum[0] = cwall_num;
467 }
468 d->front_wallnum[0] = seg->shared_segment::sides[side].wall_num;
469 }
470 else
471 con_printf(CON_URGENT, "Illegal Connectside %i in wall_open_door on segment %hu. Trying to hop over. Please check your level!", underlying_value(side), seg.get_unchecked_index());
472
473 if (Newdemo_state == ND_STATE_RECORDING) {
474 newdemo_record_door_opening(seg, side);
475 }
476
477 if (w->linked_wall != wall_none)
478 {
479 wall *const w2 = vmwallptr(w->linked_wall);
480
481 Assert(w2->linked_wall == seg->shared_segment::sides[side].wall_num);
482 //Assert(!(w2->flags & WALL_DOOR_OPENING || w2->flags & WALL_DOOR_OPENED));
483
484 w2->state = wall_state::opening;
485
486 const auto &&seg2 = vcsegptridx(w2->segnum);
487 const auto &&csegp2 = vcsegptr(seg2->shared_segment::children[w2->sidenum]);
488 Connectside = find_connect_side(seg2, csegp2);
489 Assert(Connectside != side_none);
490 const auto cwall_num = csegp2->shared_segment::sides[Connectside].wall_num;
491 auto &imwallptr = Walls.imptr;
492 if (const auto &&w3 = imwallptr(cwall_num))
493 w3->state = wall_state::opening;
494
495 d->n_parts = 2;
496 d->front_wallnum[1] = w->linked_wall;
497 d->back_wallnum[1] = cwall_num;
498 }
499 else
500 d->n_parts = 1;
501
502
503 if ( Newdemo_state != ND_STATE_PLAYBACK )
504 {
505 // NOTE THE LINK TO ABOVE!!!!
506 auto &vcvertptr = Vertices.vcptr;
507 const auto cp{compute_center_point_on_side(vcvertptr, seg, side)};
508 const auto open_sound = WallAnims[w->clip_num].open_sound;
509 if (open_sound != sound_effect::None)
510 digi_link_sound_to_pos(open_sound, seg, side, cp, 0, F1_0);
511
512 }
513 }
514
515 #if DXX_BUILD_DESCENT == 2
516 //-----------------------------------------------------------------
517 // start the transition from closed -> open wall
518 void start_wall_cloak(const vmsegptridx_t seg, const sidenum_t side)
519 {
520 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
521 auto &Vertices = LevelSharedVertexState.get_vertices();
522 cloaking_wall *d;
523
524 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
525
526 auto &Walls = LevelUniqueWallSubsystemState.Walls;
527 const auto &&w = Walls.vmptridx(seg->shared_segment::sides[side].wall_num);
528
529 if (w->type == WALL_OPEN || w->state == wall_state::cloaking) //already open or cloaking
530 return;
531
532 const auto &&csegp = vcsegptr(seg->children[side]);
533 auto Connectside = find_connect_side(seg, csegp);
534 Assert(Connectside != side_none);
535 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
536
537 auto &CloakingWalls = LevelUniqueWallSubsystemState.CloakingWalls;
538 if (w->state == wall_state::decloaking)
539 { //decloaking, so reuse door
540 const auto &&r{std::ranges::subrange(CloakingWalls.vmptr)};
541 const auto &&re = r.end();
542 const auto &&i{std::ranges::find_if(r.begin(), re, find_cloaked_wall_predicate{w})};
543 if (i == re)
544 {
545 d_debugbreak();
546 return;
547 }
548 d = i.base();
549 d->time = CLOAKING_WALL_TIME - d->time;
550 }
551 else if (w->state == wall_state::closed) { //create new door
552 const auto c = CloakingWalls.get_count();
553 if (c >= CloakingWalls.size())
554 {
555 Int3(); //ran out of cloaking wall slots
556 w->type = WALL_OPEN;
557 if (const auto &&w1 = Walls.vmptr.check_untrusted(cwall_num))
558 (*w1)->type = WALL_OPEN;
559 return;
560 }
561 CloakingWalls.set_count(c + 1);
562 d = CloakingWalls.vmptr(clwallnum_t{c});
563 d->time = 0;
564 }
565 else {
566 Int3(); //unexpected wall state
567 return;
568 }
569
570 w->state = wall_state::cloaking;
571 if (const auto &&w1 = Walls.imptr(cwall_num))
572 w1->state = wall_state::cloaking;
573
574 d->front_wallnum = seg->shared_segment::sides[side].wall_num;
575 d->back_wallnum = cwall_num;
576 Assert(w->linked_wall == wall_none);
577
578 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
579 auto &vcvertptr = Vertices.vcptr;
580 digi_link_sound_to_pos(sound_effect::SOUND_WALL_CLOAK_ON, seg, side, compute_center_point_on_side(vcvertptr, seg, side), 0, F1_0);
581 }
582
583 for (auto &&[front_ls, back_ls, s0_uvls, s1_uvls] : zip(
584 d->front_ls,
585 d->back_ls,
586 seg->unique_segment::sides[side].uvls,
587 csegp->unique_segment::sides[Connectside].uvls
588 ))
589 {
590 front_ls = s0_uvls.l;
591 back_ls = s1_uvls.l;
592 }
593 }
594
595 //-----------------------------------------------------------------
596 // start the transition from open -> closed wall
597 void start_wall_decloak(const vmsegptridx_t seg, const sidenum_t side)
598 {
599 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
600 auto &Vertices = LevelSharedVertexState.get_vertices();
601 cloaking_wall *d;
602
603 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
604
605 auto &sside = seg->shared_segment::sides[side];
606 assert(sside.wall_num != wall_none); //Opening door on illegal wall
607
608 auto &Walls = LevelUniqueWallSubsystemState.Walls;
609 const auto &&w = Walls.vmptridx(sside.wall_num);
610
611 if (w->type == WALL_CLOSED || w->state == wall_state::decloaking) //already closed or decloaking
612 return;
613
614 auto &CloakingWalls = LevelUniqueWallSubsystemState.CloakingWalls;
615 if (w->state == wall_state::cloaking) { //cloaking, so reuse door
616 const auto &&r{std::ranges::subrange(CloakingWalls.vmptr)};
617 const auto &&re = r.end();
618 const auto &&i{std::ranges::find_if(r.begin(), re, find_cloaked_wall_predicate{w})};
619 if (i == re)
620 {
621 d_debugbreak();
622 return;
623 }
624 d = i.base();
625 d->time = CLOAKING_WALL_TIME - d->time;
626 }
627 else if (w->state == wall_state::closed) { //create new door
628 const auto c = CloakingWalls.get_count();
629 if (c >= CloakingWalls.size())
630 {
631 Int3(); //ran out of cloaking wall slots
632 /* what is this _doing_ here?
633 w->type = WALL_CLOSED;
634 Walls[csegp->sides[Connectside].wall_num].type = WALL_CLOSED;
635 */
636 return;
637 }
638 CloakingWalls.set_count(c + 1);
639 d = CloakingWalls.vmptr(clwallnum_t{c});
640 d->time = 0;
641 }
642 else {
643 Int3(); //unexpected wall state
644 return;
645 }
646
647 w->state = wall_state::decloaking;
648
649 // So that door can't be shot while opening
650 const auto &&csegp = vcsegptr(seg->children[side]);
651 auto Connectside = find_connect_side(seg, csegp);
652 Assert(Connectside != side_none);
653 auto &csside = csegp->shared_segment::sides[Connectside];
654 const auto cwall_num = csside.wall_num;
655 if (const auto &&w1 = Walls.imptr(cwall_num))
656 w1->state = wall_state::decloaking;
657
658 d->front_wallnum = seg->shared_segment::sides[side].wall_num;
659 d->back_wallnum = csside.wall_num;
660 Assert(w->linked_wall == wall_none);
661
662 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
663 auto &vcvertptr = Vertices.vcptr;
664 digi_link_sound_to_pos(sound_effect::SOUND_WALL_CLOAK_OFF, seg, side, compute_center_point_on_side(vcvertptr, seg, side), 0, F1_0);
665 }
666
667 for (auto &&[front_ls, back_ls, s0_uvls, s1_uvls] : zip(
668 d->front_ls,
669 d->back_ls,
670 seg->unique_segment::sides[side].uvls,
671 csegp->unique_segment::sides[Connectside].uvls
672 ))
673 {
674 front_ls = s0_uvls.l;
675 back_ls = s1_uvls.l;
676 }
677 }
678 #endif
679
680 //-----------------------------------------------------------------
681 // This function closes the specified door and restores the closed
682 // door texture. This is called when the animation is done
683 void wall_close_door_ref(fvmsegptridx &vmsegptridx, wall_array &Walls, const wall_animations_array &WallAnims, active_door &d)
684 {
685 range_for (const auto p, partial_const_range(d.front_wallnum, d.n_parts))
686 {
687 wall &w = *Walls.vmptr(p);
688
689 const auto &&seg = vmsegptridx(w.segnum);
690 const auto side{w.sidenum};
691 w.state = wall_state::closed;
692
693 assert(seg->shared_segment::sides[side].wall_num != wall_none); //Closing door on illegal wall
694
695 const auto &&csegp = seg.absolute_sibling(seg->shared_segment::children[side]);
696 auto Connectside = find_connect_side(seg, csegp);
697 Assert(Connectside != side_none);
698 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
699 if (const auto &&w1 = Walls.imptr(cwall_num))
700 w1->state = wall_state::closed;
701
702 wall_set_tmap_num(WallAnims[w.clip_num], seg, side, csegp, Connectside, 0);
703 }
704 }
705
706 }
707
708 namespace dcx {
709
710 namespace {
711
712 static unsigned check_poke(fvcvertptr &vcvertptr, const object_base &obj, const shared_segment &seg, const sidenum_t side)
713 {
714 //note: don't let objects with zero size block door
715 if (!obj.size)
716 return 0;
717 return get_seg_masks(vcvertptr, obj.pos, seg, obj.size).sidemask & build_sidemask(side); //pokes through side!
718 }
719
720 }
721
722 }
723
724 namespace dsx {
725
726 namespace {
727
728 static unsigned is_door_side_obstructed(fvcobjptridx &vcobjptridx, fvcsegptr &vcsegptr, const cscusegment seg, const sidenum_t side)
729 {
730 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
731 auto &Vertices = LevelSharedVertexState.get_vertices();
732 auto &vcvertptr = Vertices.vcptr;
733 for (auto &obj : objects_in<const object_base>(seg, vcobjptridx, vcsegptr))
734 {
735 #if DXX_BUILD_DESCENT == 2
736 if (obj.type == OBJ_WEAPON)
737 continue;
738 if (obj.type == OBJ_FIREBALL)
739 continue;
740 #endif
741 if (const auto obstructed = check_poke(vcvertptr, obj, seg, side))
742 return obstructed;
743 }
744 return 0;
745 }
746
747 //returns true if door is obstructed (& thus cannot close)
748 static unsigned is_door_obstructed(fvcobjptridx &vcobjptridx, fvcsegptr &vcsegptr, const vcsegptridx_t seg, const sidenum_t side)
749 {
750 if (const auto obstructed = is_door_side_obstructed(vcobjptridx, vcsegptr, seg, side))
751 return obstructed;
752 const auto &&csegp = vcsegptr(seg->shared_segment::children[side]);
753 const auto &&Connectside = find_connect_side(seg, csegp);
754 Assert(Connectside != side_none);
755 //go through each object in each of two segments, and see if
756 //it pokes into the connecting seg
757 return is_door_side_obstructed(vcobjptridx, vcsegptr, csegp, Connectside);
758 }
759
760 }
761
762 #if DXX_BUILD_DESCENT == 2
763 //-----------------------------------------------------------------
764 // Closes a door
765 void wall_close_door(wall_array &Walls, const vmsegptridx_t seg, const sidenum_t side)
766 {
767 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
768 auto &Objects = LevelUniqueObjectState.Objects;
769 auto &Vertices = LevelSharedVertexState.get_vertices();
770 auto &WallAnims = GameSharedState.WallAnims;
771 auto &vcobjptridx = Objects.vcptridx;
772 active_door *d;
773
774 const auto wall_num = seg->shared_segment::sides[side].wall_num;
775 wall *const w = Walls.vmptr(wall_num);
776 if ((w->state == wall_state::closing) || //already closing
777 (w->state == wall_state::waiting) || //open, waiting to close
778 (w->state == wall_state::closed)) //closed
779 return;
780
781 if (is_door_obstructed(vcobjptridx, vcsegptr, seg, side))
782 return;
783
784 auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors;
785 auto &vmactdoorptr = ActiveDoors.vmptr;
786 if (w->state == wall_state::opening)
787 { //reuse door
788 const auto &&r{std::ranges::subrange(vmactdoorptr)};
789 const auto &&re = r.end();
790 const auto &&i{std::ranges::find_if(r.begin(), re, find_active_door_predicate(wall_num))};
791 if (i == re)
792 {
793 d_debugbreak();
794 return;
795 }
796 d = i.base();
797 d->time = WallAnims[w->clip_num].play_time - d->time;
798
799 if (d->time < 0)
800 d->time = 0;
801
802 }
803 else { //create new door
804 assert(w->state == wall_state::open);
805 const auto i = ActiveDoors.get_count();
806 ActiveDoors.set_count(i + 1);
807 d = vmactdoorptr(static_cast<actdoornum_t>(i));
808 d->time = 0;
809 }
810
811 w->state = wall_state::closing;
812
813 // So that door can't be shot while opening
814 const auto &&csegp = vcsegptr(seg->children[side]);
815 const auto &&Connectside = find_connect_side(seg, csegp);
816 Assert(Connectside != side_none);
817 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
818 if (const auto &&w1 = Walls.imptr(cwall_num))
819 w1->state = wall_state::closing;
820
821 d->front_wallnum[0] = seg->shared_segment::sides[side].wall_num;
822 d->back_wallnum[0] = cwall_num;
823 if (Newdemo_state == ND_STATE_RECORDING) {
824 newdemo_record_door_opening(seg, side);
825 }
826
827 if (w->linked_wall != wall_none)
828 {
829 Int3(); //don't think we ever used linked walls
830 }
831 else
832 d->n_parts = 1;
833
834
835 if ( Newdemo_state != ND_STATE_PLAYBACK )
836 {
837 // NOTE THE LINK TO ABOVE!!!!
838 auto &vcvertptr = Vertices.vcptr;
839 const auto cp{compute_center_point_on_side(vcvertptr, seg, side)};
840 const auto open_sound = WallAnims[w->clip_num].open_sound;
841 if (open_sound != sound_effect::None)
842 digi_link_sound_to_pos(open_sound, seg, side, cp, 0, F1_0);
843
844 }
845 }
846 #endif
847
848 namespace {
849
850 //-----------------------------------------------------------------
851 // Animates opening of a door.
852 // Called in the game loop.
853 static bool do_door_open(active_door &d)
854 {
855 auto &Objects = LevelUniqueObjectState.Objects;
856 auto &WallAnims = GameSharedState.WallAnims;
857 auto &vmobjptr = Objects.vmptr;
858 bool remove = false;
859 auto &Walls = LevelUniqueWallSubsystemState.Walls;
860 auto &vmwallptr = Walls.vmptr;
861 for (unsigned p = 0; p < d.n_parts; ++p)
862 {
863 fix time_elapsed, time_total, one_frame;
864 int i;
865
866 wall &w = *vmwallptr(d.front_wallnum[p]);
867 LevelUniqueStuckObjectState.kill_stuck_objects(vmobjptr, d.front_wallnum[p]);
868 LevelUniqueStuckObjectState.kill_stuck_objects(vmobjptr, d.back_wallnum[p]);
869
870 const auto &&seg = vmsegptridx(w.segnum);
871 const auto side{w.sidenum};
872
873 if (seg->shared_segment::sides[side].wall_num == wall_none)
874 {
875 con_printf(CON_URGENT, "Trying to do_door_open on illegal wall %i. Please check your level!", underlying_value(side));
876 continue;
877 }
878
879 const auto &&csegp = seg.absolute_sibling(seg->shared_segment::children[side]);
880 const auto &&Connectside = find_connect_side(seg, csegp);
881 Assert(Connectside != side_none);
882
883 d.time += FrameTime;
884
885 time_elapsed = d.time;
886 auto &wa = WallAnims[w.clip_num];
887 const auto n = wa.num_frames;
888 time_total = wa.play_time;
889
890 one_frame = time_total/n;
891
892 i = time_elapsed/one_frame;
893
894 if (i < n)
895 wall_set_tmap_num(wa, seg, side, csegp, Connectside, i);
896
897 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
898 auto &w1 = *vmwallptr(cwall_num);
899 if (i> n/2) {
900 w.flags |= wall_flag::door_opened;
901 w1.flags |= wall_flag::door_opened;
902 }
903
904 if (i >= n-1) {
905 wall_set_tmap_num(wa, seg, side, csegp, Connectside, n - 1);
906
907 // If our door is not automatic just remove it from the list.
908 if (!(w.flags & wall_flag::door_auto))
909 {
910 remove = true;
911 #if DXX_BUILD_DESCENT == 2
912 w.state = wall_state::open;
913 w1.state = wall_state::open;
914 #endif
915 }
916 else {
917 w.state = wall_state::waiting;
918 w1.state = wall_state::waiting;
919 }
920 }
921
922 }
923 flush_fcd_cache();
924 return remove;
925 }
926
927 //-----------------------------------------------------------------
928 // Animates and processes the closing of a door.
929 // Called from the game loop.
930 static bool do_door_close(active_door &d)
931 {
932 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
933 auto &Objects = LevelUniqueObjectState.Objects;
934 auto &Vertices = LevelSharedVertexState.get_vertices();
935 auto &vcobjptridx = Objects.vcptridx;
936 auto &Walls = LevelUniqueWallSubsystemState.Walls;
937 auto &WallAnims = GameSharedState.WallAnims;
938 auto &vmwallptr = Walls.vmptr;
939 auto &w0 = *vmwallptr(d.front_wallnum[0]);
940 const auto &&seg0 = vmsegptridx(w0.segnum);
941
942 //check for objects in doorway before closing
943 if (w0.flags & wall_flag::door_auto)
944 if (is_door_obstructed(vcobjptridx, vcsegptr, seg0, w0.sidenum))
945 {
946 #if DXX_BUILD_DESCENT == 2
947 digi_kill_sound_linked_to_segment(w0.segnum, w0.sidenum, sound_effect::None);
948 wall_open_door(seg0, w0.sidenum); //re-open door
949 #endif
950 return false;
951 }
952
953 bool played_sound = false;
954 bool remove = false;
955 range_for (const auto p, partial_const_range(d.front_wallnum, d.n_parts))
956 {
957 fix time_elapsed, time_total, one_frame;
958 int i;
959
960 auto &wp = *vmwallptr(p);
961
962 const auto &&seg = vmsegptridx(wp.segnum);
963 const auto side{wp.sidenum};
964
965 if (seg->shared_segment::sides[side].wall_num == wall_none) {
966 return false;
967 }
968
969 #if DXX_BUILD_DESCENT == 1
970 //if here, must be auto door
971 //don't assert here, because now we have triggers to close non-auto doors
972 assert(wp.flags & wall_flag::door_auto);
973 #endif
974
975 // Otherwise, close it.
976 const auto &&csegp = seg.absolute_sibling(seg->shared_segment::children[side]);
977 const auto &&Connectside = find_connect_side(seg, csegp);
978 Assert(Connectside != side_none);
979
980
981 auto &wa = WallAnims[wp.clip_num];
982 if ( Newdemo_state != ND_STATE_PLAYBACK )
983 {
984 // NOTE THE LINK TO ABOVE!!
985 if (!played_sound) //only play one sound for linked doors
986 {
987 played_sound = true;
988 if (d.time == 0)
989 { //first time
990 const auto close_sound = wa.close_sound;
991 if (close_sound != sound_effect::None)
992 {
993 auto &vcvertptr = Vertices.vcptr;
994 digi_link_sound_to_pos(close_sound, seg, side, compute_center_point_on_side(vcvertptr, seg, side), 0, F1_0);
995 }
996 }
997 }
998 }
999
1000 d.time += FrameTime;
1001
1002 time_elapsed = d.time;
1003 const auto n = wa.num_frames;
1004 time_total = wa.play_time;
1005
1006 one_frame = time_total/n;
1007
1008 i = n-time_elapsed/one_frame-1;
1009
1010 const auto cwall_num = csegp->shared_segment::sides[Connectside].wall_num;
1011 auto &w1 = *vmwallptr(cwall_num);
1012 if (i < n/2) {
1013 wp.flags &= ~wall_flag::door_opened;
1014 w1.flags &= ~wall_flag::door_opened;
1015 }
1016
1017 // Animate door.
1018 if (i > 0) {
1019 wall_set_tmap_num(wa, seg, side, csegp, Connectside, i);
1020
1021 wp.state = wall_state::closing;
1022 w1.state = wall_state::closing;
1023 } else
1024 remove = true;
1025 }
1026
1027 if (remove)
1028 wall_close_door_ref(Segments.vmptridx, Walls, WallAnims, d);
1029 return remove;
1030 }
1031
1032 static std::pair<wall *, wall *> wall_illusion_op(fvmwallptr &vmwallptr, const vcsegptridx_t seg, const sidenum_t side)
1033 {
1034 const auto wall0 = seg->shared_segment::sides[side].wall_num;
1035 if (wall0 == wall_none)
1036 return {nullptr, nullptr};
1037 const shared_segment &csegp = *seg.absolute_sibling(seg->shared_segment::children[side]);
1038 const auto &&cside = find_connect_side(seg, csegp);
1039 if (cside == side_none)
1040 {
1041 assert(cside != side_none);
1042 return {nullptr, nullptr};
1043 }
1044 const auto wall1 = csegp.sides[cside].wall_num;
1045 if (wall1 == wall_none)
1046 return {nullptr, nullptr};
1047 return {vmwallptr(wall0), vmwallptr(wall1)};
1048 }
1049
1050 static void wall_illusion_op(fvmwallptr &vmwallptr, const vcsegptridx_t seg, const sidenum_t side, auto &&op)
1051 {
1052 const auto &&r = wall_illusion_op(vmwallptr, seg, side);
1053 if (r.first)
1054 {
1055 op(*r.first);
1056 op(*r.second);
1057 }
1058 }
1059
1060 }
1061
1062 //-----------------------------------------------------------------
1063 // Turns off an illusionary wall (This will be used primarily for
1064 // wall switches or triggers that can turn on/off illusionary walls.)
1065 void wall_illusion_off(fvmwallptr &vmwallptr, const vcsegptridx_t seg, const sidenum_t side)
1066 {
1067 const auto &&op = [](wall &w) {
1068 w.flags |= wall_flag::illusion_off;
1069 };
1070 wall_illusion_op(vmwallptr, seg, side, op);
1071 }
1072
1073 //-----------------------------------------------------------------
1074 // Turns on an illusionary wall (This will be used primarily for
1075 // wall switches or triggers that can turn on/off illusionary walls.)
1076 void wall_illusion_on(fvmwallptr &vmwallptr, const vcsegptridx_t seg, const sidenum_t side)
1077 {
1078 const auto &&op = [](wall &w) {
1079 w.flags &= ~wall_flag::illusion_off;
1080 };
1081 wall_illusion_op(vmwallptr, seg, side, op);
1082 }
1083
1084 }
1085
1086 namespace {
1087
1088 // -----------------------------------------------------------------------------
1089 // Allowed to open the normally locked special boss door if in multiplayer mode.
1090 static int special_boss_opening_allowed(const segnum_t segnum, const sidenum_t sidenum)
1091 {
1092 if (Game_mode & GM_MULTI)
1093 return (Current_level_num == BOSS_LOCKED_DOOR_LEVEL) && (segnum == BOSS_LOCKED_DOOR_SEG) && (sidenum == BOSS_LOCKED_DOOR_SIDE);
1094 else
1095 return 0;
1096 }
1097
1098 }
1099
1100 //-----------------------------------------------------------------
1101 // Determines what happens when a wall is shot
1102 //returns info about wall. see wall.h for codes
1103 //obj is the object that hit...either a weapon or the player himself
1104 //playernum is the number the player who hit the wall or fired the weapon,
1105 //or -1 if a robot fired the weapon
1106 namespace dsx {
1107 wall_hit_process_t wall_hit_process(const player_flags powerup_flags, const vmsegptridx_t seg, const sidenum_t side, const fix damage, const unsigned playernum, const object &obj)
1108 {
1109 fix show_message;
1110
1111 // If it is not a "wall" then just return.
1112 const auto wall_num = seg->shared_segment::sides[side].wall_num;
1113 if (wall_num == wall_none)
1114 return wall_hit_process_t::WHP_NOT_SPECIAL;
1115
1116 auto &Walls = LevelUniqueWallSubsystemState.Walls;
1117 auto &vmwallptr = Walls.vmptr;
1118 wall *const w = vmwallptr(wall_num);
1119
1120 if ( Newdemo_state == ND_STATE_RECORDING )
1121 newdemo_record_wall_hit_process( seg, side, damage, playernum );
1122
1123 if (w->type == WALL_BLASTABLE) {
1124 #if DXX_BUILD_DESCENT == 2
1125 if (obj.ctype.laser_info.parent_type == OBJ_PLAYER)
1126 #endif
1127 wall_damage(seg, side, damage);
1128 return wall_hit_process_t::WHP_BLASTABLE;
1129 }
1130
1131 if (playernum != Player_num) //return if was robot fire
1132 return wall_hit_process_t::WHP_NOT_SPECIAL;
1133
1134 // Determine whether player is moving forward. If not, don't say negative
1135 // messages because he probably didn't intentionally hit the door.
1136 if (obj.type == OBJ_PLAYER)
1137 show_message = (vm_vec_build_dot(obj.orient.fvec, obj.mtype.phys_info.velocity) > 0);
1138 #if DXX_BUILD_DESCENT == 2
1139 else if (obj.type == OBJ_ROBOT)
1140 show_message = 0;
1141 else if (obj.type == OBJ_WEAPON && obj.ctype.laser_info.parent_type == OBJ_ROBOT)
1142 show_message = 0;
1143 #endif
1144 else
1145 show_message = 1;
1146
1147 /* Set key_color only after the type matches, since TXT_* are macros
1148 * that trigger a load from memory. Use operator,() to suppress the
1149 * truth test on the second branch since the compiler cannot prove
1150 * that the loaded value will always be non-null.
1151 */
1152 const char *key_color;
1153 if (
1154 (w->keys == wall_key::blue && (key_color = TXT_BLUE, true)) ||
1155 (w->keys == wall_key::gold && (key_color = TXT_YELLOW, true)) ||
1156 (w->keys == wall_key::red && (key_color = TXT_RED, true))
1157 )
1158 {
1159 if (!(powerup_flags & static_cast<PLAYER_FLAG>(w->keys)))
1160 {
1161 static_assert(static_cast<unsigned>(wall_key::blue) == static_cast<unsigned>(PLAYER_FLAGS_BLUE_KEY), "BLUE key flag mismatch");
1162 static_assert(static_cast<unsigned>(wall_key::gold) == static_cast<unsigned>(PLAYER_FLAGS_GOLD_KEY), "GOLD key flag mismatch");
1163 static_assert(static_cast<unsigned>(wall_key::red) == static_cast<unsigned>(PLAYER_FLAGS_RED_KEY), "RED key flag mismatch");
1164 if (show_message)
1165 HUD_init_message(HM_DEFAULT, "%s %s",key_color,TXT_ACCESS_DENIED);
1166 return wall_hit_process_t::WHP_NO_KEY;
1167 }
1168 }
1169
1170 if (w->type == WALL_DOOR)
1171 {
1172 if ((w->flags & wall_flag::door_locked) && !special_boss_opening_allowed(seg, side))
1173 {
1174 if (show_message)
1175 {
1176 const auto &&m = TXT_CANT_OPEN_DOOR;
1177 HUD_init_message_literal(HM_DEFAULT, {m, strlen(m)});
1178 }
1179 return wall_hit_process_t::WHP_NO_KEY;
1180 }
1181 else {
1182 if (w->state != wall_state::opening)
1183 {
1184 wall_open_door(seg, side);
1185 if (Game_mode & GM_MULTI)
1186 {
1187 #if DXX_BUILD_DESCENT == 1
1188 const wall_flags flags{};
1189 #elif DXX_BUILD_DESCENT == 2
1190 const auto flags = w->flags;
1191 #endif
1192 multi_send_door_open(seg, side,flags);
1193 }
1194 }
1195 return wall_hit_process_t::WHP_DOOR;
1196
1197 }
1198 }
1199 return wall_hit_process_t::WHP_NOT_SPECIAL; //default is treat like normal wall
1200 }
1201
1202 //-----------------------------------------------------------------
1203 // Opens doors/destroys wall/shuts off triggers.
1204 void wall_toggle(fvmwallptr &vmwallptr, const vmsegptridx_t segp, const sidenum_t side)
1205 {
1206 if (side >= MAX_SIDES_PER_SEGMENT)
1207 {
1208 #ifndef NDEBUG
1209 Warning("Can't toggle side %u of segment %d (%u)!\n", underlying_value(side), segp.get_unchecked_index(), Highest_segment_index);
1210 #endif
1211 return;
1212 }
1213 const auto wall_num = segp->shared_segment::sides[side].wall_num;
1214 if (wall_num == wall_none)
1215 {
1216 LevelError("Ignoring attempt to toggle wall in segment %hu, side %u: no wall exists there.", segp.get_unchecked_index(), underlying_value(side));
1217 return;
1218 }
1219
1220 if ( Newdemo_state == ND_STATE_RECORDING )
1221 newdemo_record_wall_toggle(segp, side);
1222
1223 wall *const w = vmwallptr(wall_num);
1224 if (w->type == WALL_BLASTABLE)
1225 wall_destroy(segp, side);
1226
1227 if (w->type == WALL_DOOR && w->state == wall_state::closed)
1228 wall_open_door(segp, side);
1229 }
1230
1231 bool ad_removal_predicate::operator()(active_door &d) const
1232 {
1233 #if DXX_BUILD_DESCENT == 2
1234 auto &Objects = LevelUniqueObjectState.Objects;
1235 auto &vcobjptridx = Objects.vcptridx;
1236 #endif
1237 auto &Walls = LevelUniqueWallSubsystemState.Walls;
1238 wall &w = *Walls.vmptr(d.front_wallnum[0]);
1239 if (w.state == wall_state::opening)
1240 return do_door_open(d);
1241 else if (w.state == wall_state::closing)
1242 return do_door_close(d);
1243 else if (w.state == wall_state::waiting)
1244 {
1245 d.time += FrameTime;
1246 // set flags to fix occasional netgame problem where door is waiting to close but open flag isn't set
1247 w.flags |= wall_flag::door_opened;
1248 if (wall *const w1 = Walls.imptr(d.back_wallnum[0]))
1249 w1->flags |= wall_flag::door_opened;
1250 if (d.time > DOOR_WAIT_TIME)
1251 #if DXX_BUILD_DESCENT == 2
1252 if (!is_door_obstructed(vcobjptridx, vcsegptr, vcsegptridx(w.segnum), w.sidenum))
1253 #endif
1254 {
1255 w.state = wall_state::closing;
1256 d.time = 0;
1257 }
1258 }
1259 return false;
1260 }
1261
1262 #if DXX_BUILD_DESCENT == 2
1263 namespace {
1264
1265 static void copy_cloaking_wall_light_to_wall(std::array<uvl, 4> &back_uvls, std::array<uvl, 4> &front_uvls, const cloaking_wall &d)
1266 {
1267 range_for (const uint_fast32_t i, xrange(4u))
1268 {
1269 back_uvls[i].l = d.back_ls[i];
1270 front_uvls[i].l = d.front_ls[i];
1271 }
1272 }
1273
1274 static void scale_cloaking_wall_light_to_wall(std::array<uvl, 4> &back_uvls, std::array<uvl, 4> &front_uvls, const cloaking_wall &d, const fix light_scale)
1275 {
1276 range_for (const uint_fast32_t i, xrange(4u))
1277 {
1278 back_uvls[i].l = fixmul(d.back_ls[i], light_scale);
1279 front_uvls[i].l = fixmul(d.front_ls[i], light_scale);
1280 }
1281 }
1282
1283 static cwresult do_cloaking_wall_frame(const bool initial, cloaking_wall &d, const cwframe front, const cwframe back)
1284 {
1285 if (d.time > CLOAKING_WALL_TIME) {
1286 front.w.type = back.w.type = WALL_OPEN;
1287 front.w.state = back.w.state = wall_state::closed; //why closed? why not?
1288 return {
1289 .remove = true,
1290 .record = initial,
1291 };
1292 }
1293 else if (d.time > CLOAKING_WALL_TIME/2) {
1294 const int8_t cloak_value = ((d.time - CLOAKING_WALL_TIME / 2) * (GR_FADE_LEVELS - 2)) / (CLOAKING_WALL_TIME / 2);
1295 bool record = initial;
1296 if (front.w.cloak_value != cloak_value)
1297 {
1298 record = true;
1299 front.w.cloak_value = back.w.cloak_value = cloak_value;
1300 }
1301
1302 if (front.w.type != WALL_CLOAKED)
1303 { //just switched
1304 front.w.type = back.w.type = WALL_CLOAKED;
1305 copy_cloaking_wall_light_to_wall(back.uvls, front.uvls, d);
1306 }
1307 return {
1308 .remove = false,
1309 .record = record,
1310 };
1311 }
1312 else { //fading out
1313 fix light_scale;
1314 light_scale = fixdiv(CLOAKING_WALL_TIME / 2 - d.time, CLOAKING_WALL_TIME / 2);
1315 scale_cloaking_wall_light_to_wall(back.uvls, front.uvls, d, light_scale);
1316 return {
1317 .remove = false,
1318 .record = initial,
1319 };
1320 }
1321 }
1322
1323 static cwresult do_decloaking_wall_frame(const bool initial, cloaking_wall &d, const cwframe front, const cwframe back)
1324 {
1325 if (d.time > CLOAKING_WALL_TIME) {
1326
1327 back.w.state = wall_state::closed;
1328 front.w.state = wall_state::closed;
1329 copy_cloaking_wall_light_to_wall(back.uvls, front.uvls, d);
1330 return {
1331 .remove = true,
1332 .record = initial,
1333 };
1334 }
1335 else if (d.time > CLOAKING_WALL_TIME/2) { //fading in
1336 fix light_scale;
1337 front.w.type = back.w.type = WALL_CLOSED;
1338
1339 light_scale = fixdiv(d.time - CLOAKING_WALL_TIME / 2, CLOAKING_WALL_TIME / 2);
1340 scale_cloaking_wall_light_to_wall(back.uvls, front.uvls, d, light_scale);
1341 return {
1342 .remove = false,
1343 .record = initial,
1344 };
1345 }
1346 else { //cloaking in
1347 const int8_t cloak_value = ((CLOAKING_WALL_TIME / 2 - d.time) * (GR_FADE_LEVELS - 2)) / (CLOAKING_WALL_TIME / 2);
1348 bool record = initial;
1349 if (front.w.cloak_value != cloak_value)
1350 {
1351 record = true;
1352 front.w.cloak_value = back.w.cloak_value = cloak_value;
1353 }
1354 front.w.type = WALL_CLOAKED;
1355 back.w.type = WALL_CLOAKED;
1356 return {
1357 .remove = false,
1358 .record = record,
1359 };
1360 }
1361 }
1362
1363 bool cw_removal_predicate::operator()(cloaking_wall &d)
1364 {
1365 const cwframe front(vmsegptr, *Walls.vmptr(d.front_wallnum));
1366 const auto &&wpback = Walls.imptr(d.back_wallnum);
1367 const cwframe back = (wpback ? cwframe(vmsegptr, *wpback) : front);
1368 const bool initial = (d.time == 0);
1369 d.time += FrameTime;
1370
1371 const cwresult r{
1372 (front.w.state == wall_state::cloaking)
1373 ? do_cloaking_wall_frame(initial, d, front, back)
1374 : (front.w.state == wall_state::decloaking)
1375 ? do_decloaking_wall_frame(initial, d, front, back)
1376 : (
1377 d_debugbreak(), //unexpected wall state
1378 cwresult{}
1379 )
1380 };
1381 if (r.record)
1382 {
1383 // check if the actual cloak_value changed in this frame to prevent redundant recordings and wasted bytes
1384 if (Newdemo_state == ND_STATE_RECORDING && r.record)
1385 newdemo_record_cloaking_wall(d.front_wallnum, d.back_wallnum, front.w.type, front.w.state, front.w.cloak_value, front.uvls[0].l, front.uvls[1].l, front.uvls[2].l, front.uvls[3].l);
1386 }
1387 if (!r.remove)
1388 ++ num_cloaking_walls;
1389 return r.remove;
1390 }
1391
1392 }
1393 #endif
1394
1395 namespace {
1396
1397 static void process_exploding_walls(const d_robot_info_array &Robot_info)
1398 {
1399 if (Newdemo_state == ND_STATE_PLAYBACK)
1400 return;
1401 if (unsigned num_exploding_walls = Num_exploding_walls)
1402 {
1403 auto &Walls = LevelUniqueWallSubsystemState.Walls;
1404 for (auto &w1 : Walls.vmptr)
1405 {
1406 if (w1.flags & wall_flag::exploding)
1407 {
1408 assert(num_exploding_walls);
1409 const auto n = do_exploding_wall_frame(Robot_info, w1);
1410 num_exploding_walls -= n;
1411 if (!num_exploding_walls)
1412 break;
1413 }
1414 }
1415 }
1416 }
1417
1418 }
1419
1420 void wall_frame_process(const d_robot_info_array &Robot_info)
1421 {
1422 process_exploding_walls(Robot_info);
1423 {
1424 auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors;
1425 const auto &&r = partial_range(ActiveDoors, ActiveDoors.get_count());
1426 auto &&i = std::remove_if(r.begin(), r.end(), ad_removal_predicate());
1427 ActiveDoors.set_count(std::distance(r.begin(), i));
1428 }
1429 #if DXX_BUILD_DESCENT == 2
1430 if (Newdemo_state != ND_STATE_PLAYBACK)
1431 {
1432 auto &CloakingWalls = LevelUniqueWallSubsystemState.CloakingWalls;
1433 const auto &&r = partial_range(CloakingWalls, CloakingWalls.get_count());
1434 auto &Walls = LevelUniqueWallSubsystemState.Walls;
1435 cw_removal_predicate rp{Segments.vmptr, Walls};
1436 static_cast<void>(std::remove_if(r.begin(), r.end(), std::ref(rp)));
1437 CloakingWalls.set_count(rp.num_cloaking_walls);
1438 }
1439 #endif
1440 }
1441
1442 d_level_unique_stuck_object_state LevelUniqueStuckObjectState;
1443
1444 // An object got stuck in a door (like a flare).
1445 // Add global entry.
1446 void d_level_unique_stuck_object_state::add_stuck_object(fvcwallptr &vcwallptr, const vmobjptridx_t objp, const shared_segment &segp, const sidenum_t sidenum)
1447 {
1448 const auto wallnum = segp.sides[sidenum].wall_num;
1449 if (wallnum != wall_none)
1450 {
1451 if (vcwallptr(wallnum)->flags & wall_flag::blasted)
1452 {
1453 objp->flags |= OF_SHOULD_BE_DEAD;
1454 return;
1455 }
1456 if (Num_stuck_objects >= Stuck_objects.size())
1457 {
1458 assert(Num_stuck_objects <= Stuck_objects.size());
1459 con_printf(CON_NORMAL, "%s:%u: all stuck objects are busy; terminating %hu early", __FILE__, __LINE__, objp.get_unchecked_index());
1460 objp->flags |= OF_SHOULD_BE_DEAD;
1461 return;
1462 }
1463 auto &so = Stuck_objects[Num_stuck_objects++];
1464 so.wallnum = wallnum;
1465 so.objnum = objp;
1466 }
1467 }
1468
1469 void d_level_unique_stuck_object_state::remove_stuck_object(const vcobjidx_t obj)
1470 {
1471 auto &&pr = partial_range(Stuck_objects, Num_stuck_objects);
1472 auto &&pre = pr.end();
1473 const auto predicate = [obj](const stuckobj &so) { return so.objnum == obj; };
1474 const auto &&i{std::ranges::find_if(pr.begin(), pre, predicate)};
1475 if (i == pre)
1476 /* Objects enter this function if they are able to become stuck,
1477 * without regard to whether they actually are stuck. If the
1478 * object terminated without being stuck in a wall, then it will
1479 * not be found in Stuck_objects.
1480 */
1481 return;
1482 /* If pr.begin() == pr.end(), then i == pr.end(), and this line
1483 * cannot be reached.
1484 *
1485 * If pr.begin() != pr.end(), then prev(pr.end()) must point to a
1486 * valid element.
1487 *
1488 * Move that valid element to the location vacated by the removed
1489 * object. This may be a self-move if the removed object is the
1490 * last object.
1491 */
1492 auto &last_element = *std::prev(pr.end());
1493 static_assert(std::is_trivially_move_assignable<stuckobj>::value, "stuckobj move may require a check to prevent self-move");
1494 *i = std::move(last_element);
1495 DXX_POISON_VAR(last_element.wallnum, 0xcc);
1496 DXX_POISON_VAR(last_element.objnum, 0xcc);
1497 -- Num_stuck_objects;
1498 }
1499
1500 // ----------------------------------------------------------------------------------------------------
1501 // Door with wall index wallnum is opening, kill all objects stuck in it.
1502 void d_level_unique_stuck_object_state::kill_stuck_objects(fvmobjptr &vmobjptr, const vcwallidx_t wallnum)
1503 {
1504 if (!Num_stuck_objects)
1505 return;
1506 auto &&pr = partial_range(Stuck_objects, Num_stuck_objects);
1507 const auto predicate = [&vmobjptr, wallnum](const stuckobj &so)
1508 {
1509 if (so.wallnum != wallnum)
1510 return false;
1511 auto &obj = *vmobjptr(so.objnum);
1512 #if DXX_BUILD_DESCENT == 1
1513 #define DXX_WEAPON_LIFELEFT F1_0/4
1514 #elif DXX_BUILD_DESCENT == 2
1515 #define DXX_WEAPON_LIFELEFT F1_0/8
1516 #endif
1517 assert(obj.type == OBJ_WEAPON);
1518 assert(obj.movement_source == object::movement_type::physics);
1519 assert(obj.mtype.phys_info.flags & PF_STICK);
1520 obj.lifeleft = DXX_WEAPON_LIFELEFT;
1521 return true;
1522 };
1523 const auto i = std::remove_if(pr.begin(), pr.end(), predicate);
1524 static_assert(std::is_trivially_destructible<stuckobj>::value, "stuckobj destructor not called");
1525 Num_stuck_objects = std::distance(pr.begin(), i);
1526 std::array<stuckobj, 1> empty;
1527 DXX_POISON_VAR(empty, 0xcc);
1528 std::fill(i, pr.end(), empty[0]);
1529 }
1530
1531 }
1532
1533 namespace dcx {
1534 // -----------------------------------------------------------------------------------
1535 // Initialize stuck objects array. Called at start of level
1536 void d_level_unique_stuck_object_state::init_stuck_objects()
1537 {
1538 DXX_POISON_VAR(Stuck_objects, 0xcc);
1539 Num_stuck_objects = 0;
1540 }
1541 }
1542
1543 #if DXX_BUILD_DESCENT == 2
1544 // -----------------------------------------------------------------------------------
1545 #define MAX_BLAST_GLASS_DEPTH 5
1546
1547 namespace dsx {
1548 namespace {
1549
1550 class blast_nearby_glass_context
1551 {
1552 using TmapInfo_array = d_level_unique_tmap_info_state::TmapInfo_array;
1553 const object &obj;
1554 const fix half_damage;
1555 const d_eclip_array &Effects;
1556 const GameBitmaps_array &GameBitmaps;
1557 const Textures_array &Textures;
1558 const TmapInfo_array &TmapInfo;
1559 const d_vclip_array &Vclip;
1560 fvcvertptr &vcvertptr;
1561 fvcwallptr &vcwallptr;
1562 visited_segment_bitarray_t visited;
1563 unsigned can_blast(texture2_value tmap_num2) const;
1564 public:
1565 blast_nearby_glass_context(const object &obj, const fix damage, const d_eclip_array &Effects, const GameBitmaps_array &GameBitmaps, const Textures_array &Textures, const TmapInfo_array &TmapInfo, const d_vclip_array &Vclip, fvcvertptr &vcvertptr, fvcwallptr &vcwallptr) :
1566 obj{obj}, half_damage{damage / 2}, Effects{Effects}, GameBitmaps{GameBitmaps},
1567 Textures(Textures), TmapInfo(TmapInfo), Vclip(Vclip),
1568 vcvertptr(vcvertptr), vcwallptr(vcwallptr), visited{}
1569 {
1570 }
1571 blast_nearby_glass_context(const blast_nearby_glass_context &) = delete;
1572 blast_nearby_glass_context &operator=(const blast_nearby_glass_context &) = delete;
1573 void process_segment(vmsegptridx_t segp, unsigned steps_remaining);
1574 };
1575
1576 unsigned blast_nearby_glass_context::can_blast(const texture2_value tmap_num2) const
1577 {
1578 const auto tm = get_texture_index(tmap_num2); //tm without flags
1579 auto &ti = TmapInfo[tm];
1580 const auto ec = ti.eclip_num;
1581 if (ec == eclip_none)
1582 {
1583 return ti.destroyed != -1;
1584 }
1585 else
1586 {
1587 auto &e = Effects[ec];
1588 return e.dest_bm_num != ~0u && !(e.flags & EF_ONE_SHOT);
1589 }
1590 }
1591
1592 void blast_nearby_glass_context::process_segment(const vmsegptridx_t segp, const unsigned steps_remaining)
1593 {
1594 visited[segp] = true;
1595
1596 const auto &objp = obj;
1597 for (const auto &&[sidenum, uside] : enumerate(segp->unique_segment::sides))
1598 {
1599 // Process only walls which have glass.
1600 if (const auto tmap_num2 = uside.tmap_num2; tmap_num2 != texture2_value::None)
1601 {
1602 if (can_blast(tmap_num2))
1603 {
1604 const auto pnt{compute_center_point_on_side(vcvertptr, segp, sidenum)};
1605 if (!(vm_vec_dist_quick(pnt, objp.pos) < half_damage))
1606 /* If the distance in abstract space is too great, then the
1607 * connected distance will also be too great, so skip
1608 * measuring connected distance.
1609 */
1610 continue;
1611 /* The distance in abstract space is close enough, so check the
1612 * connected distance. This allows closed doors and other
1613 * solid barriers to stop the blast propagation, since such
1614 * barriers will either return that the distance is unreachable
1615 * or, if a detour through a nearby open passage exists, return
1616 * the distance of that detour.
1617 */
1618 if (const auto dist{find_connected_distance(pnt, segp, objp.pos, segp.absolute_sibling(objp.segnum), MAX_BLAST_GLASS_DEPTH, wall_is_doorway_mask::rendpast)}; dist > 0 && dist < half_damage)
1619 {
1620 assert(objp.type == OBJ_WEAPON);
1621 check_effect_blowup(LevelSharedSegmentState.DestructibleLights, Vclip, segp, sidenum, pnt, objp.ctype.laser_info, 1, 0);
1622 }
1623 }
1624 }
1625 }
1626
1627 const unsigned next_steps_remaining = steps_remaining - 1;
1628 if (!next_steps_remaining)
1629 return;
1630 for (const auto &&[i, segnum] : enumerate(segp->children))
1631 {
1632 if (segnum != segment_none) {
1633 if (!visited[segnum]) {
1634 if (WALL_IS_DOORWAY(GameBitmaps, Textures, vcwallptr, segp, static_cast<sidenum_t>(i)) & WALL_IS_DOORWAY_FLAG::fly)
1635 {
1636 process_segment(segp.absolute_sibling(segnum), next_steps_remaining);
1637 }
1638 }
1639 }
1640 }
1641 }
1642
1643 struct d1wclip
1644 {
1645 wclip *const wc;
1646 d1wclip(wclip &w) : wc(&w) {}
1647 };
1648
1649 DEFINE_SERIAL_UDT_TO_MESSAGE(d1wclip, dwc, (dwc.wc->play_time, dwc.wc->num_frames, dwc.wc->d1_frames, dwc.wc->open_sound, serial::pad<1>(), dwc.wc->close_sound, serial::pad<1>(), dwc.wc->flags, dwc.wc->filename, serial::pad<1>()));
1650 ASSERT_SERIAL_UDT_MESSAGE_SIZE(d1wclip, 26 + (sizeof(int16_t) * MAX_CLIP_FRAMES_D1));
1651
1652 }
1653
1654 // -----------------------------------------------------------------------------------
1655 // objp is going to detonate
1656 // blast nearby monitors, lights, maybe other things
1657 void blast_nearby_glass(const object &objp, const fix damage)
1658 {
1659 auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
1660 auto &Effects = LevelUniqueEffectsClipState.Effects;
1661 auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo;
1662 auto &Vertices = LevelSharedVertexState.get_vertices();
1663 auto &vcvertptr = Vertices.vcptr;
1664 auto &Walls = LevelUniqueWallSubsystemState.Walls;
1665 auto &vcwallptr = Walls.vcptr;
1666 blast_nearby_glass_context{objp, damage, Effects, GameBitmaps, Textures, TmapInfo, Vclip, vcvertptr, vcwallptr}.process_segment(vmsegptridx(objp.segnum), MAX_BLAST_GLASS_DEPTH);
1667 }
1668
1669 }
1670
1671 #endif
1672
1673 DEFINE_SERIAL_UDT_TO_MESSAGE(wclip, wc, (wc.play_time, wc.num_frames, wc.frames, wc.open_sound, serial::pad<1>(), wc.close_sound, serial::pad<1>(), wc.flags, wc.filename, serial::pad<1>()));
1674 ASSERT_SERIAL_UDT_MESSAGE_SIZE(wclip, 26 + (sizeof(int16_t) * MAX_CLIP_FRAMES));
1675
1676 namespace dsx {
1677 /*
1678 * reads a wclip structure from a PHYSFS_File
1679 */
1680 void wclip_read(const NamedPHYSFS_File fp, wclip &wc)
1681 {
1682 PHYSFSX_serialize_read(fp, wc);
1683 }
1684
1685 #if 0
1686 void wclip_write(PHYSFS_File *fp, const wclip &wc)
1687 {
1688 PHYSFSX_serialize_write(fp, wc);
1689 }
1690 #endif
1691 }
1692
1693 struct wrap_v16_wall
1694 {
1695 const wall *w;
1696 wrap_v16_wall(const wall &t) : w(&t) {}
1697 };
1698
1699 #define _SERIAL_UDT_WALL_V16_MEMBERS(P) (P type, P flags, P hps, P trigger, P clip_num, P keys)
1700
1701 DEFINE_SERIAL_UDT_TO_MESSAGE(v16_wall, w, _SERIAL_UDT_WALL_V16_MEMBERS(w.));
1702 DEFINE_SERIAL_UDT_TO_MESSAGE(wrap_v16_wall, w, _SERIAL_UDT_WALL_V16_MEMBERS(w.w->));
1703 ASSERT_SERIAL_UDT_MESSAGE_SIZE(wrap_v16_wall, 9);
1704
1705 /*
1706 * reads a v16_wall structure from a PHYSFS_File
1707 */
1708 void v16_wall_read(const NamedPHYSFS_File fp, v16_wall &w)
1709 {
1710 PHYSFSX_serialize_read(fp, w);
1711 }
1712
1713 struct wrap_v19_wall
1714 {
1715 const wall *w;
1716 wrap_v19_wall(const wall &t) : w(&t) {}
1717 };
1718
1719 DEFINE_SERIAL_UDT_TO_MESSAGE(v19_wall, w, (w.segnum, serial::pad<2>(), w.sidenum, w.type, w.flags, w.hps, w.trigger, w.clip_num, w.keys, w.linked_wall, serial::pad<2>()));
1720 DEFINE_SERIAL_UDT_TO_MESSAGE(wrap_v19_wall, w, (w.w->segnum, serial::pad<2>(), w.w->sidenum, serial::pad<3>(), w.w->type, w.w->flags, w.w->hps, w.w->trigger, w.w->clip_num, w.w->keys, w.w->linked_wall, serial::pad<2>()));
1721 ASSERT_SERIAL_UDT_MESSAGE_SIZE(v19_wall, 21);
1722 ASSERT_SERIAL_UDT_MESSAGE_SIZE(wrap_v19_wall, 21);
1723
1724 /*
1725 * reads a v19_wall structure from a PHYSFS_File
1726 */
1727 void v19_wall_read(const NamedPHYSFS_File fp, v19_wall &w)
1728 {
1729 PHYSFSX_serialize_read(fp, w);
1730 }
1731
1732 #if DXX_BUILD_DESCENT == 1
1733 #define _SERIAL_UDT_WALL_D2X_MEMBERS serial::pad<2>()
1734 #elif DXX_BUILD_DESCENT == 2
1735 #define _SERIAL_UDT_WALL_D2X_MEMBERS w.controlling_trigger, w.cloak_value
1736 #endif
1737 DEFINE_SERIAL_UDT_TO_MESSAGE(wall, w, (serial::sign_extend<int>(w.segnum), w.sidenum, serial::pad<3, 0>(), w.hps, w.linked_wall, serial::pad<2, 0>(), w.type, w.flags, w.state, w.trigger, w.clip_num, w.keys, _SERIAL_UDT_WALL_D2X_MEMBERS));
1738 ASSERT_SERIAL_UDT_MESSAGE_SIZE(wall, 24);
1739
1740 namespace dsx {
1741 /*
1742 * reads a wall structure from a PHYSFS_File
1743 */
1744 void wall_read(const NamedPHYSFS_File fp, wall &w)
1745 {
1746 PHYSFSX_serialize_read(fp, w);
1747 w.flags &= ~wall_flag::exploding;
1748 }
1749
1750 }
1751
1752 DEFINE_SERIAL_UDT_TO_MESSAGE(active_door, d, (d.n_parts, d.front_wallnum, d.back_wallnum, d.time));
1753 ASSERT_SERIAL_UDT_MESSAGE_SIZE(active_door, 16);
1754
1755 /*
1756 * reads an active_door structure from a PHYSFS_File
1757 */
1758 void active_door_read(const NamedPHYSFS_File fp, active_door &ad)
1759 {
1760 PHYSFSX_serialize_read(fp, ad);
1761 }
1762
1763 void active_door_write(PHYSFS_File *fp, const active_door &ad)
1764 {
1765 PHYSFSX_serialize_write(fp, ad);
1766 }
1767
1768 namespace dsx {
1769
1770 void wall_write(PHYSFS_File *fp, const wall &w, short version)
1771 {
1772 if (version <= 16)
1773 PHYSFSX_serialize_write<wrap_v16_wall>(fp, w);
1774 else if (version <= 19)
1775 PHYSFSX_serialize_write<wrap_v19_wall>(fp, w);
1776 else
1777 PHYSFSX_serialize_write(fp, w);
1778 }
1779
1780 }
1781
1782 #if DXX_BUILD_DESCENT == 2
1783 DEFINE_SERIAL_UDT_TO_MESSAGE(dsx::cloaking_wall, cw, (cw.front_wallnum, cw.back_wallnum, cw.front_ls, cw.back_ls, cw.time));
1784 ASSERT_SERIAL_UDT_MESSAGE_SIZE(dsx::cloaking_wall, 40);
1785
1786 namespace dsx {
1787
1788 void cloaking_wall_read(cloaking_wall &cw, const NamedPHYSFS_File fp)
1789 {
1790 PHYSFSX_serialize_read(fp, cw);
1791 }
1792
1793 void cloaking_wall_write(const cloaking_wall &cw, PHYSFS_File *fp)
1794 {
1795 PHYSFSX_serialize_write(fp, cw);
1796 }
1797 }
1798 #endif