1 /* $Id: wall.c,v 1.10 2003-10-04 03:14:48 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Destroyable wall stuff
20 * Revision 1.1 1995/05/16 15:32:08 allender
23 * Revision 2.1 1995/03/21 14:39:04 john
24 * Ifdef'd out the NETWORK code.
26 * Revision 2.0 1995/02/27 11:28:32 john
27 * New version 2.0, which has no anonymous unions, builds with
28 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
30 * Revision 1.112 1995/02/22 13:53:07 allender
31 * remove anonymous unions from object structure
33 * Revision 1.111 1995/02/01 17:32:17 adam
34 * Took out a bogus int3.
36 * Revision 1.110 1995/02/01 17:20:24 john
39 * Revision 1.109 1995/01/21 17:39:50 matt
40 * Cleaned up laser/player hit wall confusions
42 * Revision 1.108 1995/01/21 17:14:17 rob
43 * Fixed bug in multiplayer door-butting.
45 * Revision 1.107 1995/01/18 18:57:11 rob
46 * Added new hostage door hooks.
48 * Revision 1.106 1995/01/18 18:48:18 allender
49 * removed #ifdef newdemo's. Added function call to record a door that
50 * starts to open. This fixes the rewind problem
52 * Revision 1.105 1995/01/16 11:55:39 mike
53 * make control center (and robots whose id == your playernum) not able to open doors.
55 * Revision 1.104 1994/12/11 23:07:21 matt
56 * Fixed stuck objects & blastable walls
58 * Revision 1.103 1994/12/10 16:44:34 matt
59 * Added debugging code to track down door that turns into rock
61 * Revision 1.102 1994/12/06 16:27:05 matt
64 * Revision 1.101 1994/12/02 10:50:27 yuan
67 * Revision 1.100 1994/11/30 19:41:22 rob
68 * Put in a fix so that door opening sounds travel through the door.
70 * Revision 1.99 1994/11/28 11:59:50 yuan
71 * *** empty log message ***
73 * Revision 1.98 1994/11/28 11:25:45 matt
74 * Cleaned up key hud messages
76 * Revision 1.97 1994/11/27 23:15:11 matt
77 * Made changes for new mprintf calling convention
79 * Revision 1.96 1994/11/19 15:18:29 mike
80 * rip out unused code and data.
82 * Revision 1.95 1994/11/17 14:57:12 mike
83 * moved segment validation functions from editor to main.
85 * Revision 1.94 1994/11/07 08:47:30 john
86 * Made wall state record.
88 * Revision 1.93 1994/11/04 16:06:37 rob
89 * Fixed network damage of blastable walls.
91 * Revision 1.92 1994/11/02 21:54:01 matt
92 * Don't let objects with zero size keep door from shutting
94 * Revision 1.91 1994/10/31 13:48:42 rob
95 * Fixed bug in opening doors over network/modem. Added a new message
96 * type to multi.c that communicates door openings across the net.
97 * Changed includes in multi.c and wall.c to accomplish this.
99 * Revision 1.90 1994/10/28 14:42:41 john
100 * Added sound volumes to all sound calls.
102 * Revision 1.89 1994/10/23 19:16:55 matt
103 * Fixed bug with "no key" messages
112 static char rcsid[] = "$Id: wall.c,v 1.10 2003-10-04 03:14:48 btb Exp $";
135 #include "fireball.h"
136 #include "textures.h"
141 #include "laser.h" // For seeing if a flare is stuck in a wall.
146 #include "editor/editor.h"
149 // Special door on boss level which is locked if not in multiplayer...sorry for this awful solution --MK.
150 #define BOSS_LOCKED_DOOR_LEVEL 7
151 #define BOSS_LOCKED_DOOR_SEG 595
152 #define BOSS_LOCKED_DOOR_SIDE 5
154 wall Walls[MAX_WALLS]; // Master walls array
155 int Num_walls=0; // Number of walls
157 wclip WallAnims[MAX_WALL_ANIMS]; // Wall animations
159 //--unused-- int walls_bm_num[MAX_WALL_ANIMS];
161 //door Doors[MAX_DOORS]; // Master doors array
163 active_door ActiveDoors[MAX_DOORS];
164 int Num_open_doors; // Number of open doors
166 #define CLOAKING_WALL_TIME f1_0
168 #define MAX_CLOAKING_WALLS 10
169 cloaking_wall CloakingWalls[MAX_CLOAKING_WALLS];
170 int Num_cloaking_walls;
172 //--unused-- grs_bitmap *wall_title_bms[MAX_WALL_ANIMS];
174 //#define BM_FLAG_TRANSPARENT 1
175 //#define BM_FLAG_SUPER_TRANSPARENT 2
178 char Wall_names[7][10] = {
189 // Function prototypes
190 void kill_stuck_objects(int wallnum);
194 // This function determines whether the current segment/side is transparent
197 int check_transparency( segment * seg, int side )
199 if ( (seg->sides[side].tmap_num2 & 0x3FFF) == 0) {
200 if (GameBitmaps[Textures[seg->sides[side].tmap_num].index].bm_flags & BM_FLAG_TRANSPARENT )
206 if (GameBitmaps[Textures[seg->sides[side].tmap_num2 & 0x3FFF ].index].bm_flags & BM_FLAG_SUPER_TRANSPARENT )
212 //define these here so I don't have to change wall_is_doorway and run
213 //the risk of screwing it up.
214 #define WID_WALL 2 // 0/1/0 wall
215 #define WID_TRANSPARENT_WALL 6 // 0/1/1 transparent wall
216 #define WID_ILLUSORY_WALL 3 // 1/1/0 illusory wall
217 #define WID_TRANSILLUSORY_WALL 7 // 1/1/1 transparent illusory wall
218 #define WID_NO_WALL 5 // 1/0/1 no wall, can fly through
219 #define WID_EXTERNAL 8 // 0/0/0/1 don't see it, dont fly through it
221 //-----------------------------------------------------------------
222 // This function checks whether we can fly through the given side.
223 // In other words, whether or not we have a 'doorway'
227 // WID_RENDPAST_FLAG 4
229 // WID_WALL 2 // 0/1/0 wall
230 // WID_TRANSPARENT_WALL 6 // 0/1/1 transparent wall
231 // WID_ILLUSORY_WALL 3 // 1/1/0 illusory wall
232 // WID_TRANSILLUSORY_WALL 7 // 1/1/1 transparent illusory wall
233 // WID_NO_WALL 5 // 1/0/1 no wall, can fly through
234 int wall_is_doorway ( segment * seg, int side )
238 //--Covered by macro // No child.
239 //--Covered by macro if (seg->children[side] == -1)
240 //--Covered by macro return WID_WALL;
242 //--Covered by macro if (seg->children[side] == -2)
243 //--Covered by macro return WID_EXTERNAL_FLAG;
245 //--Covered by macro // No wall present.
246 //--Covered by macro if (seg->sides[side].wall_num == -1)
247 //--Covered by macro return WID_NO_WALL;
249 Assert(seg-Segments>=0 && seg-Segments<=Highest_segment_index);
250 Assert(side>=0 && side<6);
252 type = Walls[seg->sides[side].wall_num].type;
253 flags = Walls[seg->sides[side].wall_num].flags;
255 if (type == WALL_OPEN)
258 if (type == WALL_ILLUSION) {
259 if (Walls[seg->sides[side].wall_num].flags & WALL_ILLUSION_OFF)
262 if (check_transparency( seg, side))
263 return WID_TRANSILLUSORY_WALL;
265 return WID_ILLUSORY_WALL;
269 if (type == WALL_BLASTABLE) {
270 if (flags & WALL_BLASTED)
271 return WID_TRANSILLUSORY_WALL;
273 if (check_transparency( seg, side))
274 return WID_TRANSPARENT_WALL;
279 if (flags & WALL_DOOR_OPENED)
280 return WID_TRANSILLUSORY_WALL;
282 if (type == WALL_CLOAKED)
283 return WID_RENDER_FLAG | WID_RENDPAST_FLAG | WID_CLOAKED_FLAG;
285 state = Walls[seg->sides[side].wall_num].state;
286 if ((type == WALL_DOOR) && (state == WALL_DOOR_OPENING))
287 return WID_TRANSPARENT_WALL;
289 // If none of the above flags are set, there is no doorway.
290 if (check_transparency( seg, side))
291 return WID_TRANSPARENT_WALL;
293 return WID_WALL; // There are children behind the door.
297 //-----------------------------------------------------------------
298 // Initializes all the walls (in other words, no special walls)
304 for (i=0;i<MAX_WALLS;i++) {
305 Walls[i].segnum = Walls[i].sidenum = -1;
306 Walls[i].type = WALL_NORMAL;
309 Walls[i].trigger = -1;
310 Walls[i].clip_num = -1;
311 Walls[i].linked_wall = -1;
314 Num_cloaking_walls = 0;
318 //-----------------------------------------------------------------
319 // Initializes one wall.
320 void wall_reset(segment *seg, int side)
324 i = seg->sides[side].wall_num;
327 mprintf((0, "Resetting Illegal Wall\n"));
331 Walls[i].segnum = seg-Segments;
332 Walls[i].sidenum = side;
333 Walls[i].type = WALL_NORMAL;
336 Walls[i].trigger = -1;
337 Walls[i].clip_num = -1;
338 Walls[i].linked_wall = -1;
342 //set the tmap_num or tmap_num2 field for a wall/door
343 void wall_set_tmap_num(segment *seg,int side,segment *csegp,int cside,int anim_num,int frame_num)
345 wclip *anim = &WallAnims[anim_num];
346 int tmap = anim->frames[frame_num];
348 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
350 if (anim->flags & WCF_TMAP1) {
351 seg->sides[side].tmap_num = csegp->sides[cside].tmap_num = tmap;
352 if ( Newdemo_state == ND_STATE_RECORDING )
353 newdemo_record_wall_set_tmap_num1(seg-Segments,side,csegp-Segments,cside,tmap);
355 Assert(tmap!=0 && seg->sides[side].tmap_num2!=0);
356 seg->sides[side].tmap_num2 = csegp->sides[cside].tmap_num2 = tmap;
357 if ( Newdemo_state == ND_STATE_RECORDING )
358 newdemo_record_wall_set_tmap_num2(seg-Segments,side,csegp-Segments,cside,tmap);
363 // -------------------------------------------------------------------------------
364 //when the wall has used all its hitpoints, this will destroy it
365 void blast_blastable_wall(segment *seg, int side)
371 Assert(seg->sides[side].wall_num != -1);
373 Walls[seg->sides[side].wall_num].hps = -1; //say it's blasted
375 csegp = &Segments[seg->children[side]];
376 Connectside = find_connect_side(seg, csegp);
377 Assert(Connectside != -1);
379 kill_stuck_objects(seg->sides[side].wall_num);
380 kill_stuck_objects(csegp->sides[Connectside].wall_num);
382 //if this is an exploding wall, explode it
383 if (WallAnims[Walls[seg->sides[side].wall_num].clip_num].flags & WCF_EXPLODES)
384 explode_wall(seg-Segments,side);
386 //if not exploding, set final frame, and make door passable
387 a = Walls[seg->sides[side].wall_num].clip_num;
388 n = WallAnims[a].num_frames;
389 wall_set_tmap_num(seg,side,csegp,Connectside,a,n-1);
390 Walls[seg->sides[side].wall_num].flags |= WALL_BLASTED;
391 Walls[csegp->sides[Connectside].wall_num].flags |= WALL_BLASTED;
397 //-----------------------------------------------------------------
398 // Destroys a blastable wall.
399 void wall_destroy(segment *seg, int side)
401 Assert(seg->sides[side].wall_num != -1);
402 Assert(seg-Segments != 0);
404 if (Walls[seg->sides[side].wall_num].type == WALL_BLASTABLE)
405 blast_blastable_wall( seg, side );
407 Error("Hey bub, you are trying to destroy an indestructable wall.");
410 //-----------------------------------------------------------------
411 // Deteriorate appearance of wall. (Changes bitmap (paste-ons))
412 void wall_damage(segment *seg, int side, fix damage)
416 if (seg->sides[side].wall_num == -1) {
417 mprintf((0, "Damaging illegal wall\n"));
421 if (Walls[seg->sides[side].wall_num].type != WALL_BLASTABLE)
424 if (!(Walls[seg->sides[side].wall_num].flags & WALL_BLASTED) && Walls[seg->sides[side].wall_num].hps >= 0)
429 csegp = &Segments[seg->children[side]];
430 Connectside = find_connect_side(seg, csegp);
431 Assert(Connectside != -1);
433 Walls[seg->sides[side].wall_num].hps -= damage;
434 Walls[csegp->sides[Connectside].wall_num].hps -= damage;
436 a = Walls[seg->sides[side].wall_num].clip_num;
437 n = WallAnims[a].num_frames;
439 if (Walls[seg->sides[side].wall_num].hps < WALL_HPS*1/n) {
440 blast_blastable_wall( seg, side );
442 if (Game_mode & GM_MULTI)
443 multi_send_door_open(seg-Segments, side,Walls[seg->sides[side].wall_num].flags);
448 if (Walls[seg->sides[side].wall_num].hps < WALL_HPS*(n-i)/n) {
449 wall_set_tmap_num(seg,side,csegp,Connectside,a,i);
455 //-----------------------------------------------------------------
457 void wall_open_door(segment *seg, int side)
464 Assert(seg->sides[side].wall_num != -1); //Opening door on illegal wall
466 w = &Walls[seg->sides[side].wall_num];
468 //kill_stuck_objects(seg->sides[side].wall_num);
470 if ((w->state == WALL_DOOR_OPENING) || //already opening
471 (w->state == WALL_DOOR_WAITING) || //open, waiting to close
472 (w->state == WALL_DOOR_OPEN)) //open, & staying open
475 if (w->state == WALL_DOOR_CLOSING) { //closing, so reuse door
481 for (i=0;i<Num_open_doors;i++) { //find door
485 if (d->front_wallnum[0]==w-Walls || d->back_wallnum[0]==w-Walls || (d->n_parts==2 && (d->front_wallnum[1]==w-Walls || d->back_wallnum[1]==w-Walls)))
489 if (i>=Num_open_doors && (Game_mode & GM_MULTI))
492 Assert(i<Num_open_doors); //didn't find door!
493 Assert( d!=NULL ); // Get John!
495 d->time = WallAnims[w->clip_num].play_time - d->time;
501 else { //create new door
502 Assert(w->state == WALL_DOOR_CLOSED);
504 d = &ActiveDoors[Num_open_doors];
507 Assert( Num_open_doors < MAX_DOORS );
511 w->state = WALL_DOOR_OPENING;
513 // So that door can't be shot while opening
514 csegp = &Segments[seg->children[side]];
515 Connectside = find_connect_side(seg, csegp);
516 Assert(Connectside != -1);
518 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_OPENING;
520 //kill_stuck_objects(csegp->sides[Connectside].wall_num);
522 d->front_wallnum[0] = seg->sides[side].wall_num;
523 d->back_wallnum[0] = csegp->sides[Connectside].wall_num;
525 Assert( seg-Segments != -1);
527 if (Newdemo_state == ND_STATE_RECORDING) {
528 newdemo_record_door_opening(seg-Segments, side);
531 if (w->linked_wall != -1) {
535 w2 = &Walls[w->linked_wall];
536 seg2 = &Segments[w2->segnum];
538 Assert(w2->linked_wall == seg->sides[side].wall_num);
539 //Assert(!(w2->flags & WALL_DOOR_OPENING || w2->flags & WALL_DOOR_OPENED));
541 w2->state = WALL_DOOR_OPENING;
543 csegp = &Segments[seg2->children[w2->sidenum]];
544 Connectside = find_connect_side(seg2, csegp);
545 Assert(Connectside != -1);
546 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_OPENING;
549 d->front_wallnum[1] = w->linked_wall;
550 d->back_wallnum[1] = csegp->sides[Connectside].wall_num;
556 if ( Newdemo_state != ND_STATE_PLAYBACK )
558 // NOTE THE LINK TO ABOVE!!!!
560 compute_center_point_on_side(&cp, seg, side );
561 if (WallAnims[w->clip_num].open_sound > -1 )
562 digi_link_sound_to_pos( WallAnims[w->clip_num].open_sound, seg-Segments, side, &cp, 0, F1_0 );
567 //-----------------------------------------------------------------
568 // start the transition from closed -> open wall
569 void start_wall_cloak(segment *seg, int side)
577 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
579 Assert(seg->sides[side].wall_num != -1); //Opening door on illegal wall
581 w = &Walls[seg->sides[side].wall_num];
583 if (w->type == WALL_OPEN || w->state == WALL_DOOR_CLOAKING) //already open or cloaking
586 csegp = &Segments[seg->children[side]];
587 Connectside = find_connect_side(seg, csegp);
588 Assert(Connectside != -1);
590 if (w->state == WALL_DOOR_DECLOAKING) { //decloaking, so reuse door
596 for (i=0;i<Num_cloaking_walls;i++) { //find door
598 d = &CloakingWalls[i];
600 if (d->front_wallnum==w-Walls || d->back_wallnum==w-Walls )
604 Assert(i<Num_cloaking_walls); //didn't find door!
605 Assert( d!=NULL ); // Get John!
607 d->time = CLOAKING_WALL_TIME - d->time;
610 else if (w->state == WALL_DOOR_CLOSED) { //create new door
611 d = &CloakingWalls[Num_cloaking_walls];
613 if (Num_cloaking_walls >= MAX_CLOAKING_WALLS) { //no more!
614 Int3(); //ran out of cloaking wall slots
616 Walls[csegp->sides[Connectside].wall_num].type = WALL_OPEN;
619 Num_cloaking_walls++;
622 Int3(); //unexpected wall state
626 w->state = WALL_DOOR_CLOAKING;
627 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_CLOAKING;
629 d->front_wallnum = seg->sides[side].wall_num;
630 d->back_wallnum = csegp->sides[Connectside].wall_num;
632 Assert( seg-Segments != -1);
634 Assert(w->linked_wall == -1);
636 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
638 compute_center_point_on_side(&cp, seg, side );
639 digi_link_sound_to_pos( SOUND_WALL_CLOAK_ON, seg-Segments, side, &cp, 0, F1_0 );
643 d->front_ls[i] = seg->sides[side].uvls[i].l;
644 d->back_ls[i] = csegp->sides[Connectside].uvls[i].l;
648 //-----------------------------------------------------------------
649 // start the transition from open -> closed wall
650 void start_wall_decloak(segment *seg, int side)
658 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
660 Assert(seg->sides[side].wall_num != -1); //Opening door on illegal wall
662 w = &Walls[seg->sides[side].wall_num];
664 if (w->type == WALL_CLOSED || w->state == WALL_DOOR_DECLOAKING) //already closed or decloaking
667 if (w->state == WALL_DOOR_CLOAKING) { //cloaking, so reuse door
673 for (i=0;i<Num_cloaking_walls;i++) { //find door
675 d = &CloakingWalls[i];
677 if (d->front_wallnum==w-Walls || d->back_wallnum==w-Walls )
681 Assert(i<Num_cloaking_walls); //didn't find door!
682 Assert( d!=NULL ); // Get John!
684 d->time = CLOAKING_WALL_TIME - d->time;
687 else if (w->state == WALL_DOOR_CLOSED) { //create new door
688 d = &CloakingWalls[Num_cloaking_walls];
690 if (Num_cloaking_walls >= MAX_CLOAKING_WALLS) { //no more!
691 Int3(); //ran out of cloaking wall slots
692 /* what is this _doing_ here?
693 w->type = WALL_CLOSED;
694 Walls[csegp->sides[Connectside].wall_num].type = WALL_CLOSED;
698 Num_cloaking_walls++;
701 Int3(); //unexpected wall state
705 w->state = WALL_DOOR_DECLOAKING;
707 // So that door can't be shot while opening
708 csegp = &Segments[seg->children[side]];
709 Connectside = find_connect_side(seg, csegp);
710 Assert(Connectside != -1);
712 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_DECLOAKING;
714 d->front_wallnum = seg->sides[side].wall_num;
715 d->back_wallnum = csegp->sides[Connectside].wall_num;
717 Assert( seg-Segments != -1);
719 Assert(w->linked_wall == -1);
721 if ( Newdemo_state != ND_STATE_PLAYBACK ) {
723 compute_center_point_on_side(&cp, seg, side );
724 digi_link_sound_to_pos( SOUND_WALL_CLOAK_OFF, seg-Segments, side, &cp, 0, F1_0 );
728 d->front_ls[i] = seg->sides[side].uvls[i].l;
729 d->back_ls[i] = csegp->sides[Connectside].uvls[i].l;
733 //-----------------------------------------------------------------
734 // This function closes the specified door and restores the closed
735 // door texture. This is called when the animation is done
736 void wall_close_door_num(int door_num)
742 d = &ActiveDoors[door_num];
744 for (p=0;p<d->n_parts;p++) {
746 int Connectside, side;
747 segment *csegp, *seg;
749 w = &Walls[d->front_wallnum[p]];
751 seg = &Segments[w->segnum];
754 Assert(seg->sides[side].wall_num != -1); //Closing door on illegal wall
756 csegp = &Segments[seg->children[side]];
757 Connectside = find_connect_side(seg, csegp);
758 Assert(Connectside != -1);
760 Walls[seg->sides[side].wall_num].state = WALL_DOOR_CLOSED;
761 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_CLOSED;
763 wall_set_tmap_num(seg,side,csegp,Connectside,w->clip_num,0);
767 for (i=door_num;i<Num_open_doors;i++)
768 ActiveDoors[i] = ActiveDoors[i+1];
774 int check_poke(int objnum,int segnum,int side)
776 object *obj = &Objects[objnum];
778 //note: don't let objects with zero size block door
780 if (obj->size && get_seg_masks(&obj->pos,segnum,obj->size).sidemask & (1<<side))
781 return 1; //pokes through side!
783 return 0; //does not!
787 //returns true of door in unobjstructed (& thus can close)
788 int is_door_free(segment *seg,int side)
794 csegp = &Segments[seg->children[side]];
795 Connectside = find_connect_side(seg, csegp);
796 Assert(Connectside != -1);
798 //go through each object in each of two segments, and see if
799 //it pokes into the connecting seg
801 for (objnum=seg->objects;objnum!=-1;objnum=Objects[objnum].next)
802 if (Objects[objnum].type!=OBJ_WEAPON && Objects[objnum].type!=OBJ_FIREBALL && check_poke(objnum,seg-Segments,side))
805 for (objnum=csegp->objects;objnum!=-1;objnum=Objects[objnum].next)
806 if (Objects[objnum].type!=OBJ_WEAPON && Objects[objnum].type!=OBJ_FIREBALL && check_poke(objnum,csegp-Segments,Connectside))
809 return 1; //doorway is free!
814 //-----------------------------------------------------------------
816 void wall_close_door(segment *seg, int side)
823 Assert(seg->sides[side].wall_num != -1); //Opening door on illegal wall
825 w = &Walls[seg->sides[side].wall_num];
827 if ((w->state == WALL_DOOR_CLOSING) || //already closing
828 (w->state == WALL_DOOR_WAITING) || //open, waiting to close
829 (w->state == WALL_DOOR_CLOSED)) //closed
832 if (!is_door_free(seg,side))
835 if (w->state == WALL_DOOR_OPENING) { //reuse door
841 for (i=0;i<Num_open_doors;i++) { //find door
845 if (d->front_wallnum[0]==w-Walls || d->back_wallnum[0]==w-Walls || (d->n_parts==2 && (d->front_wallnum[1]==w-Walls || d->back_wallnum[1]==w-Walls)))
849 Assert(i<Num_open_doors); //didn't find door!
850 Assert( d!=NULL ); // Get John!
852 d->time = WallAnims[w->clip_num].play_time - d->time;
858 else { //create new door
859 Assert(w->state == WALL_DOOR_OPEN);
860 d = &ActiveDoors[Num_open_doors];
863 Assert( Num_open_doors < MAX_DOORS );
866 w->state = WALL_DOOR_CLOSING;
868 // So that door can't be shot while opening
869 csegp = &Segments[seg->children[side]];
870 Connectside = find_connect_side(seg, csegp);
871 Assert(Connectside != -1);
873 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_CLOSING;
875 d->front_wallnum[0] = seg->sides[side].wall_num;
876 d->back_wallnum[0] = csegp->sides[Connectside].wall_num;
878 Assert( seg-Segments != -1);
880 if (Newdemo_state == ND_STATE_RECORDING) {
881 newdemo_record_door_opening(seg-Segments, side);
884 if (w->linked_wall != -1) {
885 Int3(); //don't think we ever used linked walls
891 if ( Newdemo_state != ND_STATE_PLAYBACK )
893 // NOTE THE LINK TO ABOVE!!!!
895 compute_center_point_on_side(&cp, seg, side );
896 if (WallAnims[w->clip_num].open_sound > -1 )
897 digi_link_sound_to_pos( WallAnims[w->clip_num].open_sound, seg-Segments, side, &cp, 0, F1_0 );
902 //-----------------------------------------------------------------
903 // Animates opening of a door.
904 // Called in the game loop.
905 void do_door_open(int door_num)
910 Assert(door_num != -1); //Trying to do_door_open on illegal door
912 d = &ActiveDoors[door_num];
914 for (p=0;p<d->n_parts;p++) {
916 int Connectside, side;
917 segment *csegp, *seg;
918 fix time_elapsed, time_total, one_frame;
921 w = &Walls[d->front_wallnum[p]];
922 kill_stuck_objects(d->front_wallnum[p]);
923 kill_stuck_objects(d->back_wallnum[p]);
925 seg = &Segments[w->segnum];
928 Assert(seg->sides[side].wall_num != -1); //Trying to do_door_open on illegal wall
930 csegp = &Segments[seg->children[side]];
931 Connectside = find_connect_side(seg, csegp);
932 Assert(Connectside != -1);
934 d->time += FrameTime;
936 time_elapsed = d->time;
937 n = WallAnims[w->clip_num].num_frames;
938 time_total = WallAnims[w->clip_num].play_time;
940 one_frame = time_total/n;
942 i = time_elapsed/one_frame;
945 wall_set_tmap_num(seg,side,csegp,Connectside,w->clip_num,i);
948 Walls[seg->sides[side].wall_num].flags |= WALL_DOOR_OPENED;
949 Walls[csegp->sides[Connectside].wall_num].flags |= WALL_DOOR_OPENED;
953 wall_set_tmap_num(seg,side,csegp,Connectside,w->clip_num,n-1);
955 // If our door is not automatic just remove it from the list.
956 if (!(Walls[seg->sides[side].wall_num].flags & WALL_DOOR_AUTO)) {
957 for (i=door_num;i<Num_open_doors;i++)
958 ActiveDoors[i] = ActiveDoors[i+1];
960 Walls[seg->sides[side].wall_num].state = WALL_DOOR_OPEN;
961 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_OPEN;
965 Walls[seg->sides[side].wall_num].state = WALL_DOOR_WAITING;
966 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_WAITING;
968 ActiveDoors[Num_open_doors].time = 0; //counts up
976 //-----------------------------------------------------------------
977 // Animates and processes the closing of a door.
978 // Called from the game loop.
979 void do_door_close(int door_num)
985 Assert(door_num != -1); //Trying to do_door_open on illegal door
987 d = &ActiveDoors[door_num];
989 w = &Walls[d->front_wallnum[0]];
991 //check for objects in doorway before closing
992 if (w->flags & WALL_DOOR_AUTO)
993 if (!is_door_free(&Segments[w->segnum],w->sidenum)) {
994 digi_kill_sound_linked_to_segment(w->segnum,w->sidenum,-1);
995 wall_open_door(&Segments[w->segnum],w->sidenum); //re-open door
999 for (p=0;p<d->n_parts;p++) {
1001 int Connectside, side;
1002 segment *csegp, *seg;
1003 fix time_elapsed, time_total, one_frame;
1006 w = &Walls[d->front_wallnum[p]];
1008 seg = &Segments[w->segnum];
1011 if (seg->sides[side].wall_num == -1) {
1012 mprintf((0, "Trying to do_door_close on Illegal wall\n"));
1016 //if here, must be auto door
1017 // Assert(Walls[seg->sides[side].wall_num].flags & WALL_DOOR_AUTO);
1018 //don't assert here, because now we have triggers to close non-auto doors
1020 // Otherwise, close it.
1021 csegp = &Segments[seg->children[side]];
1022 Connectside = find_connect_side(seg, csegp);
1023 Assert(Connectside != -1);
1026 if ( Newdemo_state != ND_STATE_PLAYBACK )
1027 // NOTE THE LINK TO ABOVE!!
1028 if (p==0) //only play one sound for linked doors
1029 if ( d->time==0 ) { //first time
1031 compute_center_point_on_side(&cp, seg, side );
1032 if (WallAnims[w->clip_num].close_sound > -1 )
1033 digi_link_sound_to_pos( WallAnims[Walls[seg->sides[side].wall_num].clip_num].close_sound, seg-Segments, side, &cp, 0, F1_0 );
1036 d->time += FrameTime;
1038 time_elapsed = d->time;
1039 n = WallAnims[w->clip_num].num_frames;
1040 time_total = WallAnims[w->clip_num].play_time;
1042 one_frame = time_total/n;
1044 i = n-time_elapsed/one_frame-1;
1047 Walls[seg->sides[side].wall_num].flags &= ~WALL_DOOR_OPENED;
1048 Walls[csegp->sides[Connectside].wall_num].flags &= ~WALL_DOOR_OPENED;
1053 wall_set_tmap_num(seg,side,csegp,Connectside,w->clip_num,i);
1055 Walls[seg->sides[side].wall_num].state = WALL_DOOR_CLOSING;
1056 Walls[csegp->sides[Connectside].wall_num].state = WALL_DOOR_CLOSING;
1058 ActiveDoors[Num_open_doors].time = 0; //counts up
1061 wall_close_door_num(door_num);
1066 //-----------------------------------------------------------------
1067 // Turns off an illusionary wall (This will be used primarily for
1068 // wall switches or triggers that can turn on/off illusionary walls.)
1069 void wall_illusion_off(segment *seg, int side)
1074 csegp = &Segments[seg->children[side]];
1075 cside = find_connect_side(seg, csegp);
1076 Assert(cside != -1);
1078 if (seg->sides[side].wall_num == -1) {
1079 mprintf((0, "Trying to shut off illusion illegal wall\n"));
1083 Walls[seg->sides[side].wall_num].flags |= WALL_ILLUSION_OFF;
1084 Walls[csegp->sides[cside].wall_num].flags |= WALL_ILLUSION_OFF;
1086 kill_stuck_objects(seg->sides[side].wall_num);
1087 kill_stuck_objects(csegp->sides[cside].wall_num);
1090 //-----------------------------------------------------------------
1091 // Turns on an illusionary wall (This will be used primarily for
1092 // wall switches or triggers that can turn on/off illusionary walls.)
1093 void wall_illusion_on(segment *seg, int side)
1098 csegp = &Segments[seg->children[side]];
1099 cside = find_connect_side(seg, csegp);
1100 Assert(cside != -1);
1102 if (seg->sides[side].wall_num == -1) {
1103 mprintf((0, "Trying to turn on illusion illegal wall\n"));
1107 Walls[seg->sides[side].wall_num].flags &= ~WALL_ILLUSION_OFF;
1108 Walls[csegp->sides[cside].wall_num].flags &= ~WALL_ILLUSION_OFF;
1111 // -----------------------------------------------------------------------------
1112 // Allowed to open the normally locked special boss door if in multiplayer mode.
1113 int special_boss_opening_allowed(int segnum, int sidenum)
1115 if (Game_mode & GM_MULTI)
1116 return (Current_level_num == BOSS_LOCKED_DOOR_LEVEL) && (segnum == BOSS_LOCKED_DOOR_SEG) && (sidenum == BOSS_LOCKED_DOOR_SIDE);
1121 //-----------------------------------------------------------------
1122 // Determines what happens when a wall is shot
1123 //returns info about wall. see wall.h for codes
1124 //obj is the object that hit...either a weapon or the player himself
1125 //playernum is the number the player who hit the wall or fired the weapon,
1126 //or -1 if a robot fired the weapon
1127 int wall_hit_process(segment *seg, int side, fix damage, int playernum, object *obj )
1132 Assert (seg-Segments != -1);
1134 // If it is not a "wall" then just return.
1135 if ( seg->sides[side].wall_num < 0 )
1136 return WHP_NOT_SPECIAL;
1138 w = &Walls[seg->sides[side].wall_num];
1140 if ( Newdemo_state == ND_STATE_RECORDING )
1141 newdemo_record_wall_hit_process( seg-Segments, side, damage, playernum );
1143 if (w->type == WALL_BLASTABLE) {
1144 if (obj->ctype.laser_info.parent_type == OBJ_PLAYER)
1145 wall_damage(seg, side, damage);
1146 return WHP_BLASTABLE;
1149 if (playernum != Player_num) //return if was robot fire
1150 return WHP_NOT_SPECIAL;
1152 Assert( playernum > -1 );
1154 // Determine whether player is moving forward. If not, don't say negative
1155 // messages because he probably didn't intentionally hit the door.
1156 if (obj->type == OBJ_PLAYER)
1157 show_message = (vm_vec_dot(&obj->orient.fvec, &obj->mtype.phys_info.velocity) > 0);
1158 else if (obj->type == OBJ_ROBOT)
1160 else if ((obj->type == OBJ_WEAPON) && (obj->ctype.laser_info.parent_type == OBJ_ROBOT))
1165 if (w->keys == KEY_BLUE)
1166 if (!(Players[playernum].flags & PLAYER_FLAGS_BLUE_KEY)) {
1167 if ( playernum==Player_num )
1169 HUD_init_message("%s %s",TXT_BLUE,TXT_ACCESS_DENIED);
1173 if (w->keys == KEY_RED)
1174 if (!(Players[playernum].flags & PLAYER_FLAGS_RED_KEY)) {
1175 if ( playernum==Player_num )
1177 HUD_init_message("%s %s",TXT_RED,TXT_ACCESS_DENIED);
1181 if (w->keys == KEY_GOLD)
1182 if (!(Players[playernum].flags & PLAYER_FLAGS_GOLD_KEY)) {
1183 if ( playernum==Player_num )
1185 HUD_init_message("%s %s",TXT_YELLOW,TXT_ACCESS_DENIED);
1189 if (w->type == WALL_DOOR)
1191 if ((w->flags & WALL_DOOR_LOCKED ) && !(special_boss_opening_allowed(seg-Segments, side)) ) {
1192 if ( playernum==Player_num )
1194 HUD_init_message(TXT_CANT_OPEN_DOOR);
1198 if (w->state != WALL_DOOR_OPENING)
1200 wall_open_door(seg, side);
1202 if (Game_mode & GM_MULTI)
1203 multi_send_door_open(seg-Segments, side,w->flags);
1211 return WHP_NOT_SPECIAL; //default is treat like normal wall
1214 //-----------------------------------------------------------------
1215 // Opens doors/destroys wall/shuts off triggers.
1216 void wall_toggle(segment *seg, int side)
1220 if (seg - Segments > Highest_segment_index)
1222 Warning("Can't toggle side %d of segment %d - nonexistent segment!\n", side, seg-Segments);
1225 Assert( side < MAX_SIDES_PER_SEGMENT );
1227 wall_num = seg->sides[side].wall_num;
1229 if (wall_num == -1) {
1230 mprintf((0, "Illegal wall_toggle\n"));
1234 if ( Newdemo_state == ND_STATE_RECORDING )
1235 newdemo_record_wall_toggle(seg-Segments, side );
1237 if (Walls[wall_num].type == WALL_BLASTABLE)
1238 wall_destroy(seg, side);
1240 if ((Walls[wall_num].type == WALL_DOOR) && (Walls[wall_num].state == WALL_DOOR_CLOSED))
1241 wall_open_door(seg, side);
1246 //-----------------------------------------------------------------
1247 // Tidy up Walls array for load/save purposes.
1252 if (Num_walls < 0) {
1253 mprintf((0, "Illegal Num_walls\n"));
1257 for (i=Num_walls;i<MAX_WALLS;i++) {
1258 Walls[i].type = WALL_NORMAL;
1261 Walls[i].trigger = -1;
1262 Walls[i].clip_num = -1;
1266 void do_cloaking_wall_frame(int cloaking_wall_num)
1269 wall *wfront,*wback;
1271 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
1273 d = &CloakingWalls[cloaking_wall_num];
1274 wfront = &Walls[d->front_wallnum];
1275 wback = &Walls[d->back_wallnum];
1277 d->time += FrameTime;
1279 if (d->time > CLOAKING_WALL_TIME) {
1282 wfront->type = wback->type = WALL_OPEN;
1283 wfront->state = wback->state = WALL_DOOR_CLOSED; //why closed? why not?
1285 for (i=cloaking_wall_num;i<Num_cloaking_walls;i++)
1286 CloakingWalls[i] = CloakingWalls[i+1];
1287 Num_cloaking_walls--;
1290 else if (d->time > CLOAKING_WALL_TIME/2) {
1291 int old_type=wfront->type;
1293 wfront->cloak_value = wback->cloak_value = ((d->time - CLOAKING_WALL_TIME/2) * (GR_FADE_LEVELS-2)) / (CLOAKING_WALL_TIME/2);
1295 if (old_type != WALL_CLOAKED) { //just switched
1298 wfront->type = wback->type = WALL_CLOAKED;
1301 Segments[wfront->segnum].sides[wfront->sidenum].uvls[i].l = d->front_ls[i];
1302 Segments[wback->segnum].sides[wback->sidenum].uvls[i].l = d->back_ls[i];
1310 light_scale = fixdiv(CLOAKING_WALL_TIME/2-d->time,CLOAKING_WALL_TIME/2);
1313 Segments[wfront->segnum].sides[wfront->sidenum].uvls[i].l = fixmul(d->front_ls[i],light_scale);
1314 Segments[wback->segnum].sides[wback->sidenum].uvls[i].l = fixmul(d->back_ls[i],light_scale);
1318 if ( Newdemo_state == ND_STATE_RECORDING )
1319 newdemo_record_cloaking_wall(d->front_wallnum, d->back_wallnum, wfront->type, wfront->state, wfront->cloak_value, Segments[wfront->segnum].sides[wfront->sidenum].uvls[0].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[1].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[2].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[3].l);
1323 void do_decloaking_wall_frame(int cloaking_wall_num)
1326 wall *wfront,*wback;
1328 if ( Newdemo_state==ND_STATE_PLAYBACK ) return;
1330 d = &CloakingWalls[cloaking_wall_num];
1331 wfront = &Walls[d->front_wallnum];
1332 wback = &Walls[d->back_wallnum];
1334 d->time += FrameTime;
1336 if (d->time > CLOAKING_WALL_TIME) {
1339 wfront->state = wback->state = WALL_DOOR_CLOSED;
1342 Segments[wfront->segnum].sides[wfront->sidenum].uvls[i].l = d->front_ls[i];
1343 Segments[wback->segnum].sides[wback->sidenum].uvls[i].l = d->back_ls[i];
1346 for (i=cloaking_wall_num;i<Num_cloaking_walls;i++)
1347 CloakingWalls[i] = CloakingWalls[i+1];
1348 Num_cloaking_walls--;
1351 else if (d->time > CLOAKING_WALL_TIME/2) { //fading in
1355 wfront->type = wback->type = WALL_CLOSED;
1357 light_scale = fixdiv(d->time-CLOAKING_WALL_TIME/2,CLOAKING_WALL_TIME/2);
1360 Segments[wfront->segnum].sides[wfront->sidenum].uvls[i].l = fixmul(d->front_ls[i],light_scale);
1361 Segments[wback->segnum].sides[wback->sidenum].uvls[i].l = fixmul(d->back_ls[i],light_scale);
1364 else { //cloaking in
1365 wfront->cloak_value = wback->cloak_value = ((CLOAKING_WALL_TIME/2 - d->time) * (GR_FADE_LEVELS-2)) / (CLOAKING_WALL_TIME/2);
1366 wfront->type = wback->type = WALL_CLOAKED;
1369 if ( Newdemo_state == ND_STATE_RECORDING )
1370 newdemo_record_cloaking_wall(d->front_wallnum, d->back_wallnum, wfront->type, wfront->state, wfront->cloak_value, Segments[wfront->segnum].sides[wfront->sidenum].uvls[0].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[1].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[2].l, Segments[wfront->segnum].sides[wfront->sidenum].uvls[3].l);
1374 void wall_frame_process()
1378 for (i=0;i<Num_open_doors;i++) {
1382 d = &ActiveDoors[i];
1383 w = &Walls[d->front_wallnum[0]];
1385 if (w->state == WALL_DOOR_OPENING)
1387 else if (w->state == WALL_DOOR_CLOSING)
1389 else if (w->state == WALL_DOOR_WAITING) {
1390 d->time += FrameTime;
1392 //set flags to fix occatsional netgame problem where door is
1393 //waiting to close but open flag isn't set
1394 Assert(d->n_parts == 1);
1395 w->flags |= WALL_DOOR_OPENED;
1396 Walls[d->back_wallnum[0]].flags |= WALL_DOOR_OPENED;
1398 if (d->time > DOOR_WAIT_TIME && is_door_free(&Segments[w->segnum],w->sidenum)) {
1399 w->state = WALL_DOOR_CLOSING;
1403 else if (w->state == WALL_DOOR_CLOSED || w->state == WALL_DOOR_OPEN) {
1404 //this shouldn't happen. if the wall is in one of these states,
1405 //there shouldn't be an activedoor entry for it. So we'll kill
1406 //the activedoor entry. Tres simple.
1408 Int3(); //a bad thing has happened, but I'll try to fix it up
1409 for (t=i;t<Num_open_doors;t++)
1410 ActiveDoors[t] = ActiveDoors[t+1];
1415 for (i=0;i<Num_cloaking_walls;i++) {
1419 d = &CloakingWalls[i];
1420 w = &Walls[d->front_wallnum];
1422 if (w->state == WALL_DOOR_CLOAKING)
1423 do_cloaking_wall_frame(i);
1424 else if (w->state == WALL_DOOR_DECLOAKING)
1425 do_decloaking_wall_frame(i);
1427 Int3(); //unexpected wall state
1431 int Num_stuck_objects=0;
1433 stuckobj Stuck_objects[MAX_STUCK_OBJECTS];
1435 // An object got stuck in a door (like a flare).
1436 // Add global entry.
1437 void add_stuck_object(object *objp, int segnum, int sidenum)
1442 wallnum = Segments[segnum].sides[sidenum].wall_num;
1444 if (wallnum != -1) {
1445 if (Walls[wallnum].flags & WALL_BLASTED)
1446 objp->flags |= OF_SHOULD_BE_DEAD;
1448 for (i=0; i<MAX_STUCK_OBJECTS; i++) {
1449 if (Stuck_objects[i].wallnum == -1) {
1450 Stuck_objects[i].wallnum = wallnum;
1451 Stuck_objects[i].objnum = objp-Objects;
1452 Stuck_objects[i].signature = objp->signature;
1453 // mprintf((0, "Added wall %i at index %i\n", wallnum, i));
1454 Num_stuck_objects++;
1458 if (i == MAX_STUCK_OBJECTS)
1459 mprintf((1, "Warning: Unable to add object %i which got stuck in wall %i to Stuck_objects\n", objp-Objects, wallnum));
1466 // --------------------------------------------------------------------------------------------------
1467 // Look at the list of stuck objects, clean up in case an object has gone away, but not been removed here.
1468 // Removes up to one/frame.
1469 void remove_obsolete_stuck_objects(void)
1473 // Safety and efficiency code. If no stuck objects, should never get inside the IF, but this is faster.
1474 if (!Num_stuck_objects)
1477 objnum = FrameCount % MAX_STUCK_OBJECTS;
1479 if (Stuck_objects[objnum].wallnum != -1)
1480 if ((Walls[Stuck_objects[objnum].wallnum].state != WALL_DOOR_CLOSED) || (Objects[Stuck_objects[objnum].objnum].signature != Stuck_objects[objnum].signature)) {
1481 Num_stuck_objects--;
1482 Objects[Stuck_objects[objnum].objnum].lifeleft = F1_0/8;
1483 Stuck_objects[objnum].wallnum = -1;
1488 extern void flush_fcd_cache(void);
1490 // ----------------------------------------------------------------------------------------------------
1491 // Door with wall index wallnum is opening, kill all objects stuck in it.
1492 void kill_stuck_objects(int wallnum)
1496 if (Num_stuck_objects == 0) {
1500 Num_stuck_objects=0;
1502 for (i=0; i<MAX_STUCK_OBJECTS; i++)
1503 if (Stuck_objects[i].wallnum == wallnum) {
1504 if (Objects[Stuck_objects[i].objnum].type == OBJ_WEAPON) {
1505 Objects[Stuck_objects[i].objnum].lifeleft = F1_0/8;
1507 mprintf((1, "Warning: Stuck object of type %i, expected to be of type %i, see wall.c\n", Objects[Stuck_objects[i].objnum].type, OBJ_WEAPON));
1508 // Int3(); // What? This looks bad. Object is not a weapon and it is stuck in a wall!
1509 Stuck_objects[i].wallnum = -1;
1510 } else if (Stuck_objects[i].wallnum != -1) {
1511 Num_stuck_objects++;
1513 // Ok, this is awful, but we need to do things whenever a door opens/closes/disappears, etc.
1519 // -- unused -- // -----------------------------------------------------------------------------------
1520 // -- unused -- // Return object id of first flare found embedded in segp:sidenum.
1521 // -- unused -- // If no flare, return -1.
1522 // -- unused -- int contains_flare(segment *segp, int sidenum)
1524 // -- unused -- int i;
1526 // -- unused -- for (i=0; i<Num_stuck_objects; i++) {
1527 // -- unused -- object *objp = &Objects[Stuck_objects[i].objnum];
1529 // -- unused -- if ((objp->type == OBJ_WEAPON) && (objp->id == FLARE_ID)) {
1530 // -- unused -- if (Walls[Stuck_objects[i].wallnum].segnum == segp-Segments)
1531 // -- unused -- if (Walls[Stuck_objects[i].wallnum].sidenum == sidenum)
1532 // -- unused -- return objp-Objects;
1536 // -- unused -- return -1;
1539 // -----------------------------------------------------------------------------------
1540 // Initialize stuck objects array. Called at start of level
1541 void init_stuck_objects(void)
1545 for (i=0; i<MAX_STUCK_OBJECTS; i++)
1546 Stuck_objects[i].wallnum = -1;
1548 Num_stuck_objects = 0;
1551 // -----------------------------------------------------------------------------------
1552 // Clear out all stuck objects. Called for a new ship
1553 void clear_stuck_objects(void)
1557 for (i=0; i<MAX_STUCK_OBJECTS; i++) {
1558 if (Stuck_objects[i].wallnum != -1) {
1561 objnum = Stuck_objects[i].objnum;
1563 if ((Objects[objnum].type == OBJ_WEAPON) && (Objects[objnum].id == FLARE_ID))
1564 Objects[objnum].lifeleft = F1_0/8;
1566 Stuck_objects[i].wallnum = -1;
1568 Num_stuck_objects--;
1572 Assert(Num_stuck_objects == 0);
1576 // -----------------------------------------------------------------------------------
1577 #define MAX_BLAST_GLASS_DEPTH 5
1579 void bng_process_segment(object *objp, fix damage, segment *segp, int depth, sbyte *visited)
1583 if (depth > MAX_BLAST_GLASS_DEPTH)
1588 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
1593 // Process only walls which have glass.
1594 if ((tm=segp->sides[sidenum].tmap_num2) != 0) {
1597 tm &= 0x3fff; //tm without flags
1599 if ((((ec=TmapInfo[tm].eclip_num)!=-1) && ((db=Effects[ec].dest_bm_num)!=-1 && !(Effects[ec].flags&EF_ONE_SHOT))) || (ec==-1 && (TmapInfo[tm].destroyed!=-1))) {
1600 compute_center_point_on_side(&pnt, segp, sidenum);
1601 dist = vm_vec_dist_quick(&pnt, &objp->pos);
1602 if (dist < damage/2) {
1603 dist = find_connected_distance(&pnt, segp-Segments, &objp->pos, objp->segnum, MAX_BLAST_GLASS_DEPTH, WID_RENDPAST_FLAG);
1604 if ((dist > 0) && (dist < damage/2))
1605 check_effect_blowup(segp, sidenum, &pnt, &Objects[objp->ctype.laser_info.parent_num], 1);
1611 for (i=0; i<MAX_SIDES_PER_SEGMENT; i++) {
1612 int segnum = segp->children[i];
1615 if (!visited[segnum]) {
1616 if (WALL_IS_DOORWAY(segp, i) & WID_FLY_FLAG) {
1617 visited[segnum] = 1;
1618 bng_process_segment(objp, damage, &Segments[segnum], depth, visited);
1625 // -----------------------------------------------------------------------------------
1626 // objp is going to detonate
1627 // blast nearby monitors, lights, maybe other things
1628 void blast_nearby_glass(object *objp, fix damage)
1631 sbyte visited[MAX_SEGMENTS];
1634 cursegp = &Segments[objp->segnum];
1635 for (i=0; i<=Highest_segment_index; i++)
1638 visited[objp->segnum] = 1;
1639 bng_process_segment(objp, damage, cursegp, 0, visited);
1644 #define MAX_CLIP_FRAMES_D1 20
1647 * reads a wclip structure from a CFILE
1649 int wclip_read_n_d1(wclip *wc, int n, CFILE *fp)
1653 for (i = 0; i < n; i++) {
1654 wc[i].play_time = cfile_read_fix(fp);
1655 wc[i].num_frames = cfile_read_short(fp);
1656 for (j = 0; j < MAX_CLIP_FRAMES_D1; j++)
1657 wc[i].frames[j] = cfile_read_short(fp);
1658 wc[i].open_sound = cfile_read_short(fp);
1659 wc[i].close_sound = cfile_read_short(fp);
1660 wc[i].flags = cfile_read_short(fp);
1661 cfread(wc[i].filename, 13, 1, fp);
1662 wc[i].pad = cfile_read_byte(fp);
1667 #ifndef FAST_FILE_IO
1669 * reads a wclip structure from a CFILE
1671 int wclip_read_n(wclip *wc, int n, CFILE *fp)
1675 for (i = 0; i < n; i++) {
1676 wc[i].play_time = cfile_read_fix(fp);
1677 wc[i].num_frames = cfile_read_short(fp);
1678 for (j = 0; j < MAX_CLIP_FRAMES; j++)
1679 wc[i].frames[j] = cfile_read_short(fp);
1680 wc[i].open_sound = cfile_read_short(fp);
1681 wc[i].close_sound = cfile_read_short(fp);
1682 wc[i].flags = cfile_read_short(fp);
1683 cfread(wc[i].filename, 13, 1, fp);
1684 wc[i].pad = cfile_read_byte(fp);
1690 * reads a v16_wall structure from a CFILE
1692 extern void v16_wall_read(v16_wall *w, CFILE *fp)
1694 w->type = cfile_read_byte(fp);
1695 w->flags = cfile_read_byte(fp);
1696 w->hps = cfile_read_fix(fp);
1697 w->trigger = cfile_read_byte(fp);
1698 w->clip_num = cfile_read_byte(fp);
1699 w->keys = cfile_read_byte(fp);
1703 * reads a v19_wall structure from a CFILE
1705 extern void v19_wall_read(v19_wall *w, CFILE *fp)
1707 w->segnum = cfile_read_int(fp);
1708 w->sidenum = cfile_read_int(fp);
1709 w->type = cfile_read_byte(fp);
1710 w->flags = cfile_read_byte(fp);
1711 w->hps = cfile_read_fix(fp);
1712 w->trigger = cfile_read_byte(fp);
1713 w->clip_num = cfile_read_byte(fp);
1714 w->keys = cfile_read_byte(fp);
1715 w->linked_wall = cfile_read_int(fp);
1719 * reads a wall structure from a CFILE
1721 extern void wall_read(wall *w, CFILE *fp)
1723 w->segnum = cfile_read_int(fp);
1724 w->sidenum = cfile_read_int(fp);
1725 w->hps = cfile_read_fix(fp);
1726 w->linked_wall = cfile_read_int(fp);
1727 w->type = cfile_read_byte(fp);
1728 w->flags = cfile_read_byte(fp);
1729 w->state = cfile_read_byte(fp);
1730 w->trigger = cfile_read_byte(fp);
1731 w->clip_num = cfile_read_byte(fp);
1732 w->keys = cfile_read_byte(fp);
1733 w->controlling_trigger = cfile_read_byte(fp);
1734 w->cloak_value = cfile_read_byte(fp);
1738 * reads a v19_door structure from a CFILE
1740 extern void v19_door_read(v19_door *d, CFILE *fp)
1742 d->n_parts = cfile_read_int(fp);
1743 d->seg[0] = cfile_read_short(fp);
1744 d->seg[1] = cfile_read_short(fp);
1745 d->side[0] = cfile_read_short(fp);
1746 d->side[1] = cfile_read_short(fp);
1747 d->type[0] = cfile_read_short(fp);
1748 d->type[1] = cfile_read_short(fp);
1749 d->open = cfile_read_fix(fp);
1753 * reads an active_door structure from a CFILE
1755 extern void active_door_read(active_door *ad, CFILE *fp)
1757 ad->n_parts = cfile_read_int(fp);
1758 ad->front_wallnum[0] = cfile_read_short(fp);
1759 ad->front_wallnum[1] = cfile_read_short(fp);
1760 ad->back_wallnum[0] = cfile_read_short(fp);
1761 ad->back_wallnum[1] = cfile_read_short(fp);
1762 ad->time = cfile_read_fix(fp);