Subversion Repositories eduke32

Rev

Rev 8686 | 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);
8694 ny00123 41
short ViewSectorInScene(short cursectnum, 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
        keystatus[KEYSC_4] = FALSE;
118
 
5201 hendricks2 119
        tx = pos.x;
120
        ty = pos.y;
121
        tz = pos.z;
5196 hendricks2 122
        tsectnum = cursectnum;
123
 
124
        save.zcount = 0;
125
 
126
        if (sector[cursectnum].ceilingpicnum == FAF_MIRROR_PIC)
127
        {
8694 ny00123 128
            match = ViewSectorInScene(tsectnum, VIEW_LEVEL1);
5196 hendricks2 129
 
130
            FAF_DontMoveSectors = TRUE;
131
            FindCeilingView(match, &tx, &ty, tz, &tsectnum);
132
            FAF_DontMoveSectors = FALSE;
133
 
5201 hendricks2 134
            pos.x = tx;
135
            pos.y = ty;
5196 hendricks2 136
            cursectnum = tsectnum;
5201 hendricks2 137
            pos.z = sector[cursectnum].floorz - Z(20);
5196 hendricks2 138
        }
139
        else if (sector[cursectnum].floorpicnum == FAF_MIRROR_PIC)
140
        {
8694 ny00123 141
            match = ViewSectorInScene(tsectnum, VIEW_LEVEL2);
5196 hendricks2 142
 
143
            FAF_DontMoveSectors = TRUE;
144
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
145
            FAF_DontMoveSectors = FALSE;
146
 
5201 hendricks2 147
            pos.x = tx;
148
            pos.y = ty;
5196 hendricks2 149
            cursectnum = tsectnum;
5201 hendricks2 150
            pos.z = sector[cursectnum].ceilingz + Z(20);
5196 hendricks2 151
        }
152
    }
153
 
154
 
155
}
156
 
157
 
158
void FAF_AfterDrawRooms(void)
159
{
160
    // make it so that you can edit both areas in 3D
161
    // if your cursor is in the FAF_MIRROR_PIC area use the vars from the first
162
    // drawrooms instead
163
    if ((searchstat == 1 && sector[searchsector].ceilingpicnum == FAF_MIRROR_PIC) ||
164
        (searchstat == 2 && sector[searchsector].floorpicnum == FAF_MIRROR_PIC))
165
    {
166
        searchsector = bak_searchsector;
167
        searchwall = bak_searchwall;
168
        searchstat = bak_searchstat;
169
    }
170
}
171
 
5198 hendricks2 172
void
173
SetupBuildFAF(void)
5196 hendricks2 174
{
175
    short i, nexti;
8686 ny00123 176
    SPRITEp sp;
5196 hendricks2 177
    short SpriteNum, NextSprite;
178
    // move every sprite to the correct list
179
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_DEFAULT], SpriteNum, NextSprite)
180
    {
181
        sp = &sprite[SpriteNum];
182
 
183
        if (sp->picnum != ST1)
184
            continue;
185
 
186
        switch (sp->hitag)
187
        {
188
        case VIEW_THRU_CEILING:
189
        case VIEW_THRU_FLOOR:
190
        {
191
            int i,nexti;
192
            // make sure there is only one set per level of these
193
            TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
194
            {
195
                if (sprite[i].hitag == sp->hitag && sprite[i].lotag == sp->lotag)
196
                {
7500 hendricks2 197
                    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 198
                    Message(ds,0);
199
                }
200
            }
201
 
202
            changespritestat(SpriteNum, STAT_FAF);
203
            break;
204
        }
205
 
206
        case VIEW_LEVEL1:
207
        case VIEW_LEVEL2:
208
        case VIEW_LEVEL3:
209
        case VIEW_LEVEL4:
210
        case VIEW_LEVEL5:
211
        case VIEW_LEVEL6:
212
        {
213
            changespritestat(SpriteNum, STAT_FAF);
214
            break;
215
        }
216
        }
217
    }
218
 
219
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
220
    {
221
        sp = &sprite[i];
222
 
223
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC)
224
        {
225
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC;
226
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
227
            {
7500 hendricks2 228
                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 229
                Message(ds,0);
230
            }
231
        }
232
 
233
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC)
234
        {
235
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC;
236
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
237
            {
7500 hendricks2 238
                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 239
                Message(ds,0);
240
            }
241
        }
242
 
243
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC+1)
244
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
245
 
246
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC+1)
247
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
248
    }
249
 
250
 
251
    for (i = 0; i < numwalls; i++)
252
    {
253
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC)
254
            wall[i].picnum = FAF_MIRROR_PIC;
255
 
256
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC+1)
257
            wall[i].picnum = FAF_MIRROR_PIC+1;
258
    }
259
 
260
#if 0
261
    // check ceiling and floor heights
8686 ny00123 262
    SPRITEp vc_sp,vf_sp,vl_sp;
263
    short vc,nextvc,vf,nextvf,l,nextl;
264
    int zdiff;
265
 
5196 hendricks2 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
{
8685 ny00123 370
    int i;
5196 hendricks2 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
    // Map rooms have NOT been dragged on top of each other
8306 hendricks2 415
    else if (sln == 1)
5196 hendricks2 416
    {
417
        *lower = sectorlist[0];
418
        *upper = sectorlist[0];
419
        return;
420
    }
421
    // Map rooms HAVE been dragged on top of each other
8306 hendricks2 422
    else if (sln > 2)
5196 hendricks2 423
    {
424
        // try again moving the x,y pos around until you only get two sectors
425
        GetUpperLowerSector(match, x - 1, y, upper, lower);
426
    }
8306 hendricks2 427
    else if (sln == 2)
5196 hendricks2 428
    {
429
        if (sector[sectorlist[0]].floorz < sector[sectorlist[1]].floorz)
430
        {
431
            // swap
432
            // make sectorlist[0] the LOW sector
433
            short hold;
434
 
435
            hold = sectorlist[0];
436
            sectorlist[0] = sectorlist[1];
437
            sectorlist[1] = hold;
438
        }
439
 
440
        *lower = sectorlist[0];
441
        *upper = sectorlist[1];
442
    }
443
}
444
 
5198 hendricks2 445
SWBOOL
446
FindCeilingView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 447
{
448
    int xoff = 0;
449
    int yoff = 0;
450
    short i, nexti;
451
    SPRITEp sp = NULL;
452
    int pix_diff;
453
    int newz;
454
 
455
    save.zcount = 0;
456
 
457
    // Search Stat List For closest ceiling view sprite
458
    // Get the match, xoff, yoff from this point
459
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
460
    {
461
        sp = &sprite[i];
462
 
463
        if (sp->hitag == VIEW_THRU_CEILING && sp->lotag == match)
464
        {
465
            xoff = *x - sp->x;
466
            yoff = *y - sp->y;
467
 
468
            break;
469
        }
470
    }
471
 
472
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
473
    {
474
        sp = &sprite[i];
475
 
476
        if (sp->lotag == match)
477
        {
478
            // determine x,y position
479
            if (sp->hitag == VIEW_THRU_FLOOR)
480
            {
481
                short upper, lower;
482
 
483
                *x = sp->x + xoff;
484
                *y = sp->y + yoff;
485
 
486
                // get new sector
487
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
488
                *sectnum = upper;
489
                break;
490
            }
491
        }
492
    }
493
 
494
    if (*sectnum < 0)
495
        return FALSE;
496
 
497
    ASSERT(sp);
498
    ASSERT(sp->hitag == VIEW_THRU_FLOOR);
499
 
500
    if (FAF_DontMoveSectors)
501
        return TRUE;
502
 
503
    pix_diff = labs(z - sector[sp->sectnum].floorz) >> 8;
504
    newz = sector[sp->sectnum].floorz + ((pix_diff / 128) + 1) * Z(128);
505
 
506
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
507
    {
508
        sp = &sprite[i];
509
 
510
        if (sp->lotag == match)
511
        {
512
            // move lower levels ceilings up for the correct view
513
            if (sp->hitag == VIEW_LEVEL2)
514
            {
515
                // save it off
516
                save.sectnum[save.zcount] = sp->sectnum;
517
                save.zval[save.zcount] = sector[sp->sectnum].floorz;
518
                save.pic[save.zcount] = sector[sp->sectnum].floorpicnum;
519
                save.slope[save.zcount] = sector[sp->sectnum].floorheinum;
520
 
521
                sector[sp->sectnum].floorz = newz;
522
                sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
523
                sector[sp->sectnum].floorheinum = 0;
524
 
525
                save.zcount++;
526
                ASSERT(save.zcount < ZMAX);
527
            }
528
        }
529
    }
530
 
531
    return TRUE;
532
}
533
 
5198 hendricks2 534
SWBOOL
535
FindFloorView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 536
{
537
    int xoff = 0;
538
    int yoff = 0;
539
    short i, nexti;
540
    SPRITEp sp = NULL;
541
    int newz;
542
    int pix_diff;
543
 
544
    save.zcount = 0;
545
 
546
    // Search Stat List For closest ceiling view sprite
547
    // Get the match, xoff, yoff from this point
548
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
549
    {
550
        sp = &sprite[i];
551
 
552
        if (sp->hitag == VIEW_THRU_FLOOR && sp->lotag == match)
553
        {
554
            xoff = *x - sp->x;
555
            yoff = *y - sp->y;
556
 
557
            break;
558
        }
559
    }
560
 
561
 
562
 
563
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
564
    {
565
        sp = &sprite[i];
566
 
567
        if (sp->lotag == match)
568
        {
569
            // determine x,y position
570
            if (sp->hitag == VIEW_THRU_CEILING)
571
            {
572
                short upper, lower;
573
 
574
                *x = sp->x + xoff;
575
                *y = sp->y + yoff;
576
 
577
                // get new sector
578
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
579
                *sectnum = lower;
580
                break;
581
            }
582
        }
583
    }
584
 
585
    if (*sectnum < 0)
586
        return FALSE;
587
 
588
    ASSERT(sp);
589
    ASSERT(sp->hitag == VIEW_THRU_CEILING);
590
 
591
    if (FAF_DontMoveSectors)
592
        return TRUE;
593
 
594
    // move ceiling multiple of 128 so that the wall tile will line up
595
    pix_diff = labs(z - sector[sp->sectnum].ceilingz) >> 8;
596
    newz = sector[sp->sectnum].ceilingz - ((pix_diff / 128) + 1) * Z(128);
597
 
598
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
599
    {
600
        sp = &sprite[i];
601
 
602
        if (sp->lotag == match)
603
        {
604
            // move upper levels floors down for the correct view
605
            if (sp->hitag == VIEW_LEVEL1)
606
            {
607
                // save it off
608
                save.sectnum[save.zcount] = sp->sectnum;
609
                save.zval[save.zcount] = sector[sp->sectnum].ceilingz;
610
                save.pic[save.zcount] = sector[sp->sectnum].ceilingpicnum;
611
                save.slope[save.zcount] = sector[sp->sectnum].ceilingheinum;
612
 
613
                sector[sp->sectnum].ceilingz = newz;
614
 
615
                sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
616
                sector[sp->sectnum].ceilingheinum = 0;
617
 
618
                save.zcount++;
619
                ASSERT(save.zcount < ZMAX);
620
            }
621
        }
622
    }
623
 
624
    return TRUE;
625
}
626
 
5198 hendricks2 627
SWBOOL
5196 hendricks2 628
SectorInScene(short tile_num)
629
{
630
    if (TEST(gotsector[tile_num >> 3], 1 << (tile_num & 7)))
631
    {
632
        RESET(gotsector[tile_num >> 3], 1 << (tile_num & 7));
633
        return TRUE;
634
    }
635
 
636
    return FALSE;
637
}
638
 
639
short
8694 ny00123 640
ViewSectorInScene(short cursectnum, short level)
5196 hendricks2 641
{
642
    int i, nexti;
643
    SPRITEp sp;
644
    short match;
645
 
646
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
647
    {
648
        sp = &sprite[i];
649
 
650
        if (sp->hitag == level)
651
        {
652
            if (cursectnum == sp->sectnum)
653
            {
654
                // ignore case if sprite is pointing up
655
                if (sp->ang == 1536)
656
                    continue;
657
 
658
                // only gets to here is sprite is pointing down
659
                // found a potential match
660
                match = sp->lotag;
661
 
662
                return match;
663
            }
664
        }
665
    }
666
 
667
    return -1;
668
}
669
 
5198 hendricks2 670
void
5196 hendricks2 671
DrawOverlapRoom(int tx, int ty, int tz, short tang, int thoriz, short tsectnum)
672
{
673
    short i;
674
    short match;
675
 
676
    save.zcount = 0;
677
 
8694 ny00123 678
    match = ViewSectorInScene(tsectnum, VIEW_LEVEL1);
5196 hendricks2 679
    if (match != -1)
680
    {
681
        FindCeilingView(match, &tx, &ty, tz, &tsectnum);
682
 
683
        if (tsectnum < 0)
684
        {
5201 hendricks2 685
            sprintf(ds,"COULD NOT FIND TAGGED LEVEL2 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 686
            Message(ds, 0);
687
            return;
688
        }
689
 
690
        drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 691
        renderDrawMasks();
5196 hendricks2 692
 
693
        // reset Z's
694
        for (i = 0; i < save.zcount; i++)
695
        {
696
            sector[save.sectnum[i]].floorz = save.zval[i];
697
            sector[save.sectnum[i]].floorpicnum = save.pic[i];
698
            sector[save.sectnum[i]].floorheinum = save.slope[i];
699
        }
700
    }
701
    else
702
    {
8694 ny00123 703
        match = ViewSectorInScene(tsectnum, VIEW_LEVEL2);
5196 hendricks2 704
        if (match != -1)
705
        {
706
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
707
 
708
            if (tsectnum < 0)
709
            {
5201 hendricks2 710
                sprintf(ds,"COULD NOT FIND TAGGED LEVEL1 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 711
                Message(ds, 0);
712
                return;
713
            }
714
 
715
            drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 716
            renderDrawMasks();
5196 hendricks2 717
 
718
            // reset Z's
719
            for (i = 0; i < save.zcount; i++)
720
            {
721
                sector[save.sectnum[i]].ceilingz = save.zval[i];
722
                sector[save.sectnum[i]].ceilingpicnum = save.pic[i];
723
                sector[save.sectnum[i]].ceilingheinum = save.slope[i];
724
            }
725
        }
726
    }
727
}