Subversion Repositories eduke32

Rev

Rev 8302 | Rev 8685 | 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
    // 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
    short top_sprite = -1;
453
    int pix_diff;
454
    int newz;
455
 
456
    save.zcount = 0;
457
 
458
    // Search Stat List For closest ceiling view sprite
459
    // Get the match, xoff, yoff from this point
460
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
461
    {
462
        sp = &sprite[i];
463
 
464
        if (sp->hitag == VIEW_THRU_CEILING && sp->lotag == match)
465
        {
466
            xoff = *x - sp->x;
467
            yoff = *y - sp->y;
468
 
469
            break;
470
        }
471
    }
472
 
473
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
474
    {
475
        sp = &sprite[i];
476
 
477
        if (sp->lotag == match)
478
        {
479
            // determine x,y position
480
            if (sp->hitag == VIEW_THRU_FLOOR)
481
            {
482
                short upper, lower;
483
 
484
                *x = sp->x + xoff;
485
                *y = sp->y + yoff;
486
 
487
                // get new sector
488
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
489
                *sectnum = upper;
490
                break;
491
            }
492
        }
493
    }
494
 
495
    if (*sectnum < 0)
496
        return FALSE;
497
 
498
    ASSERT(sp);
499
    ASSERT(sp->hitag == VIEW_THRU_FLOOR);
500
 
501
    if (FAF_DontMoveSectors)
502
        return TRUE;
503
 
504
    pix_diff = labs(z - sector[sp->sectnum].floorz) >> 8;
505
    newz = sector[sp->sectnum].floorz + ((pix_diff / 128) + 1) * Z(128);
506
 
507
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
508
    {
509
        sp = &sprite[i];
510
 
511
        if (sp->lotag == match)
512
        {
513
            // move lower levels ceilings up for the correct view
514
            if (sp->hitag == VIEW_LEVEL2)
515
            {
516
                // save it off
517
                save.sectnum[save.zcount] = sp->sectnum;
518
                save.zval[save.zcount] = sector[sp->sectnum].floorz;
519
                save.pic[save.zcount] = sector[sp->sectnum].floorpicnum;
520
                save.slope[save.zcount] = sector[sp->sectnum].floorheinum;
521
 
522
                sector[sp->sectnum].floorz = newz;
523
                sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
524
                sector[sp->sectnum].floorheinum = 0;
525
 
526
                save.zcount++;
527
                ASSERT(save.zcount < ZMAX);
528
            }
529
        }
530
    }
531
 
532
    return TRUE;
533
}
534
 
5198 hendricks2 535
SWBOOL
536
FindFloorView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 537
{
538
    int xoff = 0;
539
    int yoff = 0;
540
    short i, nexti;
541
    SPRITEp sp = NULL;
542
    int newz;
543
    int pix_diff;
544
 
545
    save.zcount = 0;
546
 
547
    // Search Stat List For closest ceiling view sprite
548
    // Get the match, xoff, yoff from this point
549
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
550
    {
551
        sp = &sprite[i];
552
 
553
        if (sp->hitag == VIEW_THRU_FLOOR && sp->lotag == match)
554
        {
555
            xoff = *x - sp->x;
556
            yoff = *y - sp->y;
557
 
558
            break;
559
        }
560
    }
561
 
562
 
563
 
564
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
565
    {
566
        sp = &sprite[i];
567
 
568
        if (sp->lotag == match)
569
        {
570
            // determine x,y position
571
            if (sp->hitag == VIEW_THRU_CEILING)
572
            {
573
                short upper, lower;
574
 
575
                *x = sp->x + xoff;
576
                *y = sp->y + yoff;
577
 
578
                // get new sector
579
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
580
                *sectnum = lower;
581
                break;
582
            }
583
        }
584
    }
585
 
586
    if (*sectnum < 0)
587
        return FALSE;
588
 
589
    ASSERT(sp);
590
    ASSERT(sp->hitag == VIEW_THRU_CEILING);
591
 
592
    if (FAF_DontMoveSectors)
593
        return TRUE;
594
 
595
    // move ceiling multiple of 128 so that the wall tile will line up
596
    pix_diff = labs(z - sector[sp->sectnum].ceilingz) >> 8;
597
    newz = sector[sp->sectnum].ceilingz - ((pix_diff / 128) + 1) * Z(128);
598
 
599
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
600
    {
601
        sp = &sprite[i];
602
 
603
        if (sp->lotag == match)
604
        {
605
            // move upper levels floors down for the correct view
606
            if (sp->hitag == VIEW_LEVEL1)
607
            {
608
                // save it off
609
                save.sectnum[save.zcount] = sp->sectnum;
610
                save.zval[save.zcount] = sector[sp->sectnum].ceilingz;
611
                save.pic[save.zcount] = sector[sp->sectnum].ceilingpicnum;
612
                save.slope[save.zcount] = sector[sp->sectnum].ceilingheinum;
613
 
614
                sector[sp->sectnum].ceilingz = newz;
615
 
616
                sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
617
                sector[sp->sectnum].ceilingheinum = 0;
618
 
619
                save.zcount++;
620
                ASSERT(save.zcount < ZMAX);
621
            }
622
        }
623
    }
624
 
625
    return TRUE;
626
}
627
 
5198 hendricks2 628
SWBOOL
5196 hendricks2 629
SectorInScene(short tile_num)
630
{
631
    if (TEST(gotsector[tile_num >> 3], 1 << (tile_num & 7)))
632
    {
633
        RESET(gotsector[tile_num >> 3], 1 << (tile_num & 7));
634
        return TRUE;
635
    }
636
 
637
    return FALSE;
638
}
639
 
640
short
641
ViewSectorInScene(short cursectnum, short type, short level)
642
{
643
    int i, nexti;
644
    int j, nextj;
645
    SPRITEp sp;
646
    SPRITEp sp2;
647
    int cz, fz;
648
    short match;
649
 
650
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
651
    {
652
        sp = &sprite[i];
653
 
654
        if (sp->hitag == level)
655
        {
656
            if (cursectnum == sp->sectnum)
657
            {
658
                // ignore case if sprite is pointing up
659
                if (sp->ang == 1536)
660
                    continue;
661
 
662
                // only gets to here is sprite is pointing down
663
                // found a potential match
664
                match = sp->lotag;
665
 
666
                return match;
667
            }
668
        }
669
    }
670
 
671
    return -1;
672
}
673
 
5198 hendricks2 674
void
5196 hendricks2 675
DrawOverlapRoom(int tx, int ty, int tz, short tang, int thoriz, short tsectnum)
676
{
677
    short i;
678
    short match;
679
 
680
    save.zcount = 0;
681
 
682
    match = ViewSectorInScene(tsectnum, VIEW_THRU_CEILING, VIEW_LEVEL1);
683
    if (match != -1)
684
    {
685
        FindCeilingView(match, &tx, &ty, tz, &tsectnum);
686
 
687
        if (tsectnum < 0)
688
        {
5201 hendricks2 689
            sprintf(ds,"COULD NOT FIND TAGGED LEVEL2 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 690
            Message(ds, 0);
691
            return;
692
        }
693
 
694
        drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 695
        renderDrawMasks();
5196 hendricks2 696
 
697
        // reset Z's
698
        for (i = 0; i < save.zcount; i++)
699
        {
700
            sector[save.sectnum[i]].floorz = save.zval[i];
701
            sector[save.sectnum[i]].floorpicnum = save.pic[i];
702
            sector[save.sectnum[i]].floorheinum = save.slope[i];
703
        }
704
    }
705
    else
706
    {
707
        match = ViewSectorInScene(tsectnum, VIEW_THRU_FLOOR, VIEW_LEVEL2);
708
        if (match != -1)
709
        {
710
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
711
 
712
            if (tsectnum < 0)
713
            {
5201 hendricks2 714
                sprintf(ds,"COULD NOT FIND TAGGED LEVEL1 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 715
                Message(ds, 0);
716
                return;
717
            }
718
 
719
            drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 720
            renderDrawMasks();
5196 hendricks2 721
 
722
            // reset Z's
723
            for (i = 0; i < save.zcount; i++)
724
            {
725
                sector[save.sectnum[i]].ceilingz = save.zval[i];
726
                sector[save.sectnum[i]].ceilingpicnum = save.pic[i];
727
                sector[save.sectnum[i]].ceilingheinum = save.slope[i];
728
            }
729
        }
730
    }
731
}