Subversion Repositories eduke32

Rev

Rev 7509 | Rev 8306 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5196 hendricks2 1
//-------------------------------------------------------------------------
2
/*
3
Copyright (C) 1996, 2005 - 3D Realms Entertainment
4
 
5
This file is NOT part of Shadow Warrior version 1.2
6
However, it is either an older version of a file that is, or is
7
some test code written during the development of Shadow Warrior.
8
This file is provided purely for educational interest.
9
 
10
Shadow Warrior is free software; you can redistribute it and/or
11
modify it under the terms of the GNU General Public License
12
as published by the Free Software Foundation; either version 2
13
of the License, or (at your option) any later version.
14
 
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
 
19
See the GNU General Public License for more details.
20
 
21
You should have received a copy of the GNU General Public License
22
along with this program; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24
 
25
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
26
*/
27
//-------------------------------------------------------------------------
28
 
29
#include "build.h"
30
#include "editor.h"
31
 
32
#include "keys.h"
33
#include "names2.h"
34
#include "game.h"
35
 
36
 
37
extern int qsetmode;
38
 
5198 hendricks2 39
SWBOOL FindCeilingView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum);
40
SWBOOL FindFloorView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum);
5196 hendricks2 41
short ViewSectorInScene(short cursectnum, short type, short level);
7499 hendricks2 42
void Message(const char *string, char color);
5196 hendricks2 43
 
44
 
45
void
7499 hendricks2 46
_Assert(const char *expr, const char *strFile, unsigned uLine)
5196 hendricks2 47
{
48
    printf(ds, "Assertion failed: %s %s, line %u\n", expr, strFile, uLine);
49
    //DSPRINTF(ds, "Assertion failed: %s %s, line %u", expr, strFile, uLine);
50
    MONO_PRINT(ds);
51
    exit(0);
52
}
53
 
54
////////////////////////////////////////////////////////////////////
55
//
56
// FLOOR ABOVE FLOOR
57
//
58
////////////////////////////////////////////////////////////////////
59
 
60
 
61
#define ZMAX 400
62
typedef struct
63
{
5198 hendricks2 64
    int32_t zval[ZMAX];
65
    int16_t sectnum[ZMAX];
66
    int16_t pic[ZMAX];
67
    int16_t slope[ZMAX];
68
    int16_t zcount;
5196 hendricks2 69
} SAVE, *SAVEp;
70
 
71
SAVE save;
72
 
5198 hendricks2 73
SWBOOL FAF_DebugView = 0;
74
SWBOOL FAFon = 0;
75
SWBOOL FAF_DontMoveSectors = FALSE;
5196 hendricks2 76
 
77
short bak_searchsector, bak_searchwall, bak_searchstat;
78
extern short searchsector, searchwall, searchstat, searchit;
79
 
5198 hendricks2 80
void SetupBuildFAF(void);
81
void ResetBuildFAF(void);
5196 hendricks2 82
 
83
void ToggleFAF(void)
84
{
85
    if (keystatus[KEYSC_3])
86
    {
87
        keystatus[KEYSC_3] = FALSE;
88
 
89
        FLIP(FAFon, 1);
90
        if (FAFon)
91
        {
92
            SetupBuildFAF();
93
        }
94
        else
95
        {
96
            ResetBuildFAF();
97
        }
98
    }
99
 
100
    if (FAFon && qsetmode == 200)
101
    {
5201 hendricks2 102
        DrawOverlapRoom(pos.x, pos.y, pos.z, ang, horiz, cursectnum);
5196 hendricks2 103
 
104
        // make it so that you can edit both areas in 3D
105
        // back up vars after the first drawrooms
106
        bak_searchsector = searchsector;
107
        bak_searchwall = searchwall;
108
        bak_searchstat = searchstat;
109
        searchit = 2;
110
    }
111
 
112
    if (FAFon && qsetmode == 200 && keystatus[KEYSC_4])
113
    {
114
        short match;
115
        int tx,ty,tz;
116
        short tsectnum;
117
        short i;
118
        keystatus[KEYSC_4] = FALSE;
119
 
5201 hendricks2 120
        tx = pos.x;
121
        ty = pos.y;
122
        tz = pos.z;
5196 hendricks2 123
        tsectnum = cursectnum;
124
 
125
        save.zcount = 0;
126
 
127
        if (sector[cursectnum].ceilingpicnum == FAF_MIRROR_PIC)
128
        {
129
            match = ViewSectorInScene(tsectnum, VIEW_THRU_CEILING, VIEW_LEVEL1);
130
 
131
            FAF_DontMoveSectors = TRUE;
132
            FindCeilingView(match, &tx, &ty, tz, &tsectnum);
133
            FAF_DontMoveSectors = FALSE;
134
 
5201 hendricks2 135
            pos.x = tx;
136
            pos.y = ty;
5196 hendricks2 137
            cursectnum = tsectnum;
5201 hendricks2 138
            pos.z = sector[cursectnum].floorz - Z(20);
5196 hendricks2 139
        }
140
        else if (sector[cursectnum].floorpicnum == FAF_MIRROR_PIC)
141
        {
142
            match = ViewSectorInScene(tsectnum, VIEW_THRU_FLOOR, VIEW_LEVEL2);
143
 
144
            FAF_DontMoveSectors = TRUE;
145
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
146
            FAF_DontMoveSectors = FALSE;
147
 
5201 hendricks2 148
            pos.x = tx;
149
            pos.y = ty;
5196 hendricks2 150
            cursectnum = tsectnum;
5201 hendricks2 151
            pos.z = sector[cursectnum].ceilingz + Z(20);
5196 hendricks2 152
        }
153
    }
154
 
155
 
156
}
157
 
158
 
159
void FAF_AfterDrawRooms(void)
160
{
161
    // make it so that you can edit both areas in 3D
162
    // if your cursor is in the FAF_MIRROR_PIC area use the vars from the first
163
    // drawrooms instead
164
    if ((searchstat == 1 && sector[searchsector].ceilingpicnum == FAF_MIRROR_PIC) ||
165
        (searchstat == 2 && sector[searchsector].floorpicnum == FAF_MIRROR_PIC))
166
    {
167
        searchsector = bak_searchsector;
168
        searchwall = bak_searchwall;
169
        searchstat = bak_searchstat;
170
    }
171
}
172
 
5198 hendricks2 173
void
174
SetupBuildFAF(void)
5196 hendricks2 175
{
176
    short i, nexti;
177
    SPRITEp sp,vc_sp,vf_sp,vl_sp;
178
    short SpriteNum, NextSprite;
179
    short vc,nextvc,vf,nextvf,l,nextl;
180
    int zdiff;
181
 
182
    // move every sprite to the correct list
183
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_DEFAULT], SpriteNum, NextSprite)
184
    {
185
        sp = &sprite[SpriteNum];
186
 
187
        if (sp->picnum != ST1)
188
            continue;
189
 
190
        switch (sp->hitag)
191
        {
192
        case VIEW_THRU_CEILING:
193
        case VIEW_THRU_FLOOR:
194
        {
195
            int i,nexti;
196
            // make sure there is only one set per level of these
197
            TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
198
            {
199
                if (sprite[i].hitag == sp->hitag && sprite[i].lotag == sp->lotag)
200
                {
7500 hendricks2 201
                    sprintf(ds,"Two VIEW_THRU_ tags with same match found on level\n1: x %d, y %d \n2: x %d, y %d", TrackerCast(sp->x), TrackerCast(sp->y), TrackerCast(sprite[i].x), TrackerCast(sprite[i].y));
5196 hendricks2 202
                    Message(ds,0);
203
                }
204
            }
205
 
206
            changespritestat(SpriteNum, STAT_FAF);
207
            break;
208
        }
209
 
210
        case VIEW_LEVEL1:
211
        case VIEW_LEVEL2:
212
        case VIEW_LEVEL3:
213
        case VIEW_LEVEL4:
214
        case VIEW_LEVEL5:
215
        case VIEW_LEVEL6:
216
        {
217
            changespritestat(SpriteNum, STAT_FAF);
218
            break;
219
        }
220
        }
221
    }
222
 
223
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
224
    {
225
        sp = &sprite[i];
226
 
227
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC)
228
        {
229
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC;
230
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
231
            {
7500 hendricks2 232
                sprintf(ds, "Mirror used for non-connect area. Use tile 342. Sect %d, x %d, y %d\n", TrackerCast(sp->sectnum), TrackerCast(wall[sector[sp->sectnum].wallptr].x), TrackerCast(wall[sector[sp->sectnum].wallptr].y));
5196 hendricks2 233
                Message(ds,0);
234
            }
235
        }
236
 
237
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC)
238
        {
239
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC;
240
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
241
            {
7500 hendricks2 242
                sprintf(ds, "Mirror used for non-connect area. Use tile 342. Sect %d, x %d, y %d\n", TrackerCast(sp->sectnum), TrackerCast(wall[sector[sp->sectnum].wallptr].x), TrackerCast(wall[sector[sp->sectnum].wallptr].y));
5196 hendricks2 243
                Message(ds,0);
244
            }
245
        }
246
 
247
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC+1)
248
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
249
 
250
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC+1)
251
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
252
    }
253
 
254
 
255
    for (i = 0; i < numwalls; i++)
256
    {
257
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC)
258
            wall[i].picnum = FAF_MIRROR_PIC;
259
 
260
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC+1)
261
            wall[i].picnum = FAF_MIRROR_PIC+1;
262
    }
263
 
264
#if 0
265
    // check ceiling and floor heights
266
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], vc, nextvc)
267
    {
268
        vc_sp = &sprite[vc];
269
 
270
        if (vc_sp->hitag == VIEW_THRU_CEILING)
271
        {
272
            TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], vf, nextvf)
273
            {
274
                vf_sp = &sprite[vf];
275
 
276
                if (vf_sp->hitag == VIEW_THRU_FLOOR && vf_sp->lotag == vc_sp->lotag)
277
                {
278
                    zdiff = labs(sector[vc_sp->sectnum].ceilingz - sector[vf_sp->sectnum].floorz);
279
 
280
                    //DSPRINTF(ds,"zdiff %d",zdiff);
281
                    MONO_PRINT(ds);
282
 
283
                    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], l, nextl)
284
                    {
285
                        vl_sp = &sprite[l];
286
 
287
                        if (vl_sp->hitag == VIEW_LEVEL1)
288
                        {
289
                            if (sector[vl_sp->sectnum].ceilingz < sector[vc_sp->sectnum].ceilingz + zdiff)
290
                            {
291
                                sprintf(ds,"Sector %d (x %d, y %d) ceiling z to close to VIEW_THRU_CEILING z",
292
                                        vl_sp->sectnum, wall[sector[vl_sp->sectnum].wallptr].x, wall[sector[vl_sp->sectnum].wallptr].y);
293
                                Message(ds,0);
294
                            }
295
                        }
296
                        else if (vl_sp->hitag == VIEW_LEVEL2)
297
                        {
298
                            if (sector[vl_sp->sectnum].floorz > sector[vf_sp->sectnum].floorz + zdiff)
299
                            {
300
                                sprintf(ds,"Sector %d (x %d, y %d)floor z to close to VIEW_THRU_FLOOR z",
301
                                        vl_sp->sectnum, wall[sector[vl_sp->sectnum].wallptr].x, wall[sector[vl_sp->sectnum].wallptr].y);
302
                                Message(ds,0);
303
                            }
304
                        }
305
                    }
306
                }
307
            }
308
        }
309
    }
310
#endif
311
 
312
}
313
 
5198 hendricks2 314
void
315
ResetBuildFAF(void)
5196 hendricks2 316
{
317
    short i, nexti;
318
    SPRITEp sp;
319
 
320
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
321
    {
322
        sp = &sprite[i];
323
 
324
        if (sector[sp->sectnum].ceilingpicnum == FAF_MIRROR_PIC)
325
            sector[sp->sectnum].ceilingpicnum = FAF_PLACE_MIRROR_PIC;
326
 
327
        if (sector[sp->sectnum].floorpicnum == FAF_MIRROR_PIC)
328
            sector[sp->sectnum].floorpicnum = FAF_PLACE_MIRROR_PIC;
329
 
330
        if (sector[sp->sectnum].ceilingpicnum == FAF_MIRROR_PIC+1)
331
            sector[sp->sectnum].ceilingpicnum = FAF_PLACE_MIRROR_PIC+1;
332
 
333
        if (sector[sp->sectnum].floorpicnum == FAF_MIRROR_PIC+1)
334
            sector[sp->sectnum].floorpicnum = FAF_PLACE_MIRROR_PIC+1;
335
    }
336
 
337
    for (i = 0; i < numwalls; i++)
338
    {
339
        if (wall[i].picnum == FAF_MIRROR_PIC)
340
            wall[i].picnum = FAF_PLACE_MIRROR_PIC;
341
 
342
        if (wall[i].picnum == FAF_MIRROR_PIC+1)
343
            wall[i].picnum = FAF_PLACE_MIRROR_PIC+1;
344
    }
345
 
346
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
347
    {
348
        changespritestat(i, STAT_DEFAULT);
349
    }
350
}
351
 
352
 
5198 hendricks2 353
SWBOOL
354
PicInView(short tile_num, SWBOOL reset)
5196 hendricks2 355
{
356
    if (TEST(gotpic[tile_num >> 3], 1 << (tile_num & 7)))
357
    {
358
        if (reset)
359
            RESET(gotpic[tile_num >> 3], 1 << (tile_num & 7));
360
 
361
        return TRUE;
362
    }
363
 
364
    return FALSE;
365
}
366
 
367
void
368
GetUpperLowerSector(short match, int x, int y, short *upper, short *lower)
369
{
370
    int i, j;
371
    short sectorlist[16];
372
    short sln = 0;
373
    short SpriteNum, Next;
374
    SPRITEp sp;
375
 
376
    // didn't find it yet so test ALL sectors
377
    if (sln < 2)
378
    {
379
        sln = 0;
380
        for (i = numsectors - 1; i >= 0; i--)
381
        {
382
            if (inside(x, y, (short) i) == 1)
383
            {
5198 hendricks2 384
                SWBOOL found = FALSE;
5196 hendricks2 385
 
386
                TRAVERSE_SPRITE_SECT(headspritesect[i], SpriteNum, Next)
387
                {
388
                    sp = &sprite[SpriteNum];
389
 
390
                    if (sp->statnum == STAT_FAF &&
391
                        (sp->hitag >= VIEW_LEVEL1 && sp->hitag <= VIEW_LEVEL6)
392
                        && sp->lotag == match)
393
                    {
394
                        found = TRUE;
395
                    }
396
                }
397
 
398
                if (!found)
399
                    continue;
400
 
8302 hendricks2 401
                if (sln < (int)SIZ(sectorlist))
402
                    sectorlist[sln] = i;
5196 hendricks2 403
                sln++;
404
            }
405
        }
406
    }
407
 
408
    if (sln == 0)
409
    {
410
        *upper = -1;
411
        *lower = -1;
412
        return;
413
    }
414
 
415
    // Map rooms have NOT been dragged on top of each other
416
    if (sln == 1)
417
    {
418
        *lower = sectorlist[0];
419
        *upper = sectorlist[0];
420
        return;
421
    }
422
    else
423
    // Map rooms HAVE been dragged on top of each other
424
    if (sln > 2)
425
    {
426
        // try again moving the x,y pos around until you only get two sectors
427
        GetUpperLowerSector(match, x - 1, y, upper, lower);
428
    }
429
 
430
    if (sln == 2)
431
    {
432
        if (sector[sectorlist[0]].floorz < sector[sectorlist[1]].floorz)
433
        {
434
            // swap
435
            // make sectorlist[0] the LOW sector
436
            short hold;
437
 
438
            hold = sectorlist[0];
439
            sectorlist[0] = sectorlist[1];
440
            sectorlist[1] = hold;
441
        }
442
 
443
        *lower = sectorlist[0];
444
        *upper = sectorlist[1];
445
    }
446
}
447
 
5198 hendricks2 448
SWBOOL
449
FindCeilingView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 450
{
451
    int xoff = 0;
452
    int yoff = 0;
453
    short i, nexti;
454
    SPRITEp sp = NULL;
455
    short top_sprite = -1;
456
    int pix_diff;
457
    int newz;
458
 
459
    save.zcount = 0;
460
 
461
    // Search Stat List For closest ceiling view sprite
462
    // Get the match, xoff, yoff from this point
463
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
464
    {
465
        sp = &sprite[i];
466
 
467
        if (sp->hitag == VIEW_THRU_CEILING && sp->lotag == match)
468
        {
469
            xoff = *x - sp->x;
470
            yoff = *y - sp->y;
471
 
472
            break;
473
        }
474
    }
475
 
476
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
477
    {
478
        sp = &sprite[i];
479
 
480
        if (sp->lotag == match)
481
        {
482
            // determine x,y position
483
            if (sp->hitag == VIEW_THRU_FLOOR)
484
            {
485
                short upper, lower;
486
 
487
                *x = sp->x + xoff;
488
                *y = sp->y + yoff;
489
 
490
                // get new sector
491
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
492
                *sectnum = upper;
493
                break;
494
            }
495
        }
496
    }
497
 
498
    if (*sectnum < 0)
499
        return FALSE;
500
 
501
    ASSERT(sp);
502
    ASSERT(sp->hitag == VIEW_THRU_FLOOR);
503
 
504
    if (FAF_DontMoveSectors)
505
        return TRUE;
506
 
507
    pix_diff = labs(z - sector[sp->sectnum].floorz) >> 8;
508
    newz = sector[sp->sectnum].floorz + ((pix_diff / 128) + 1) * Z(128);
509
 
510
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
511
    {
512
        sp = &sprite[i];
513
 
514
        if (sp->lotag == match)
515
        {
516
            // move lower levels ceilings up for the correct view
517
            if (sp->hitag == VIEW_LEVEL2)
518
            {
519
                // save it off
520
                save.sectnum[save.zcount] = sp->sectnum;
521
                save.zval[save.zcount] = sector[sp->sectnum].floorz;
522
                save.pic[save.zcount] = sector[sp->sectnum].floorpicnum;
523
                save.slope[save.zcount] = sector[sp->sectnum].floorheinum;
524
 
525
                sector[sp->sectnum].floorz = newz;
526
                sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
527
                sector[sp->sectnum].floorheinum = 0;
528
 
529
                save.zcount++;
530
                ASSERT(save.zcount < ZMAX);
531
            }
532
        }
533
    }
534
 
535
    return TRUE;
536
}
537
 
5198 hendricks2 538
SWBOOL
539
FindFloorView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 540
{
541
    int xoff = 0;
542
    int yoff = 0;
543
    short i, nexti;
544
    SPRITEp sp = NULL;
545
    int newz;
546
    int pix_diff;
547
 
548
    save.zcount = 0;
549
 
550
    // Search Stat List For closest ceiling view sprite
551
    // Get the match, xoff, yoff from this point
552
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
553
    {
554
        sp = &sprite[i];
555
 
556
        if (sp->hitag == VIEW_THRU_FLOOR && sp->lotag == match)
557
        {
558
            xoff = *x - sp->x;
559
            yoff = *y - sp->y;
560
 
561
            break;
562
        }
563
    }
564
 
565
 
566
 
567
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
568
    {
569
        sp = &sprite[i];
570
 
571
        if (sp->lotag == match)
572
        {
573
            // determine x,y position
574
            if (sp->hitag == VIEW_THRU_CEILING)
575
            {
576
                short upper, lower;
577
 
578
                *x = sp->x + xoff;
579
                *y = sp->y + yoff;
580
 
581
                // get new sector
582
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
583
                *sectnum = lower;
584
                break;
585
            }
586
        }
587
    }
588
 
589
    if (*sectnum < 0)
590
        return FALSE;
591
 
592
    ASSERT(sp);
593
    ASSERT(sp->hitag == VIEW_THRU_CEILING);
594
 
595
    if (FAF_DontMoveSectors)
596
        return TRUE;
597
 
598
    // move ceiling multiple of 128 so that the wall tile will line up
599
    pix_diff = labs(z - sector[sp->sectnum].ceilingz) >> 8;
600
    newz = sector[sp->sectnum].ceilingz - ((pix_diff / 128) + 1) * Z(128);
601
 
602
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
603
    {
604
        sp = &sprite[i];
605
 
606
        if (sp->lotag == match)
607
        {
608
            // move upper levels floors down for the correct view
609
            if (sp->hitag == VIEW_LEVEL1)
610
            {
611
                // save it off
612
                save.sectnum[save.zcount] = sp->sectnum;
613
                save.zval[save.zcount] = sector[sp->sectnum].ceilingz;
614
                save.pic[save.zcount] = sector[sp->sectnum].ceilingpicnum;
615
                save.slope[save.zcount] = sector[sp->sectnum].ceilingheinum;
616
 
617
                sector[sp->sectnum].ceilingz = newz;
618
 
619
                sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
620
                sector[sp->sectnum].ceilingheinum = 0;
621
 
622
                save.zcount++;
623
                ASSERT(save.zcount < ZMAX);
624
            }
625
        }
626
    }
627
 
628
    return TRUE;
629
}
630
 
5198 hendricks2 631
SWBOOL
5196 hendricks2 632
SectorInScene(short tile_num)
633
{
634
    if (TEST(gotsector[tile_num >> 3], 1 << (tile_num & 7)))
635
    {
636
        RESET(gotsector[tile_num >> 3], 1 << (tile_num & 7));
637
        return TRUE;
638
    }
639
 
640
    return FALSE;
641
}
642
 
643
short
644
ViewSectorInScene(short cursectnum, short type, short level)
645
{
646
    int i, nexti;
647
    int j, nextj;
648
    SPRITEp sp;
649
    SPRITEp sp2;
650
    int cz, fz;
651
    short match;
652
 
653
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
654
    {
655
        sp = &sprite[i];
656
 
657
        if (sp->hitag == level)
658
        {
659
            if (cursectnum == sp->sectnum)
660
            {
661
                // ignore case if sprite is pointing up
662
                if (sp->ang == 1536)
663
                    continue;
664
 
665
                // only gets to here is sprite is pointing down
666
                // found a potential match
667
                match = sp->lotag;
668
 
669
                return match;
670
            }
671
        }
672
    }
673
 
674
    return -1;
675
}
676
 
5198 hendricks2 677
void
5196 hendricks2 678
DrawOverlapRoom(int tx, int ty, int tz, short tang, int thoriz, short tsectnum)
679
{
680
    short i;
681
    short match;
682
 
683
    save.zcount = 0;
684
 
685
    match = ViewSectorInScene(tsectnum, VIEW_THRU_CEILING, VIEW_LEVEL1);
686
    if (match != -1)
687
    {
688
        FindCeilingView(match, &tx, &ty, tz, &tsectnum);
689
 
690
        if (tsectnum < 0)
691
        {
5201 hendricks2 692
            sprintf(ds,"COULD NOT FIND TAGGED LEVEL2 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 693
            Message(ds, 0);
694
            return;
695
        }
696
 
697
        drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 698
        renderDrawMasks();
5196 hendricks2 699
 
700
        // reset Z's
701
        for (i = 0; i < save.zcount; i++)
702
        {
703
            sector[save.sectnum[i]].floorz = save.zval[i];
704
            sector[save.sectnum[i]].floorpicnum = save.pic[i];
705
            sector[save.sectnum[i]].floorheinum = save.slope[i];
706
        }
707
    }
708
    else
709
    {
710
        match = ViewSectorInScene(tsectnum, VIEW_THRU_FLOOR, VIEW_LEVEL2);
711
        if (match != -1)
712
        {
713
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
714
 
715
            if (tsectnum < 0)
716
            {
5201 hendricks2 717
                sprintf(ds,"COULD NOT FIND TAGGED LEVEL1 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 718
                Message(ds, 0);
719
                return;
720
            }
721
 
722
            drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 723
            renderDrawMasks();
5196 hendricks2 724
 
725
            // reset Z's
726
            for (i = 0; i < save.zcount; i++)
727
            {
728
                sector[save.sectnum[i]].ceilingz = save.zval[i];
729
                sector[save.sectnum[i]].ceilingpicnum = save.pic[i];
730
                sector[save.sectnum[i]].ceilingheinum = save.slope[i];
731
            }
732
        }
733
    }
734
}