Subversion Repositories eduke32

Rev

Rev 8306 | 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);
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
        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
        {
128
            match = ViewSectorInScene(tsectnum, VIEW_THRU_CEILING, VIEW_LEVEL1);
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
        {
141
            match = ViewSectorInScene(tsectnum, VIEW_THRU_FLOOR, VIEW_LEVEL2);
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;
176
    SPRITEp sp,vc_sp,vf_sp,vl_sp;
177
    short SpriteNum, NextSprite;
178
    short vc,nextvc,vf,nextvf,l,nextl;
179
    int zdiff;
180
 
181
    // move every sprite to the correct list
182
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_DEFAULT], SpriteNum, NextSprite)
183
    {
184
        sp = &sprite[SpriteNum];
185
 
186
        if (sp->picnum != ST1)
187
            continue;
188
 
189
        switch (sp->hitag)
190
        {
191
        case VIEW_THRU_CEILING:
192
        case VIEW_THRU_FLOOR:
193
        {
194
            int i,nexti;
195
            // make sure there is only one set per level of these
196
            TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
197
            {
198
                if (sprite[i].hitag == sp->hitag && sprite[i].lotag == sp->lotag)
199
                {
7500 hendricks2 200
                    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 201
                    Message(ds,0);
202
                }
203
            }
204
 
205
            changespritestat(SpriteNum, STAT_FAF);
206
            break;
207
        }
208
 
209
        case VIEW_LEVEL1:
210
        case VIEW_LEVEL2:
211
        case VIEW_LEVEL3:
212
        case VIEW_LEVEL4:
213
        case VIEW_LEVEL5:
214
        case VIEW_LEVEL6:
215
        {
216
            changespritestat(SpriteNum, STAT_FAF);
217
            break;
218
        }
219
        }
220
    }
221
 
222
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
223
    {
224
        sp = &sprite[i];
225
 
226
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC)
227
        {
228
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC;
229
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
230
            {
7500 hendricks2 231
                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 232
                Message(ds,0);
233
            }
234
        }
235
 
236
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC)
237
        {
238
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC;
239
            if (sector[sp->sectnum].floorz == sector[sp->sectnum].ceilingz)
240
            {
7500 hendricks2 241
                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 242
                Message(ds,0);
243
            }
244
        }
245
 
246
        if (sector[sp->sectnum].ceilingpicnum == FAF_PLACE_MIRROR_PIC+1)
247
            sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
248
 
249
        if (sector[sp->sectnum].floorpicnum == FAF_PLACE_MIRROR_PIC+1)
250
            sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
251
    }
252
 
253
 
254
    for (i = 0; i < numwalls; i++)
255
    {
256
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC)
257
            wall[i].picnum = FAF_MIRROR_PIC;
258
 
259
        if (wall[i].picnum == FAF_PLACE_MIRROR_PIC+1)
260
            wall[i].picnum = FAF_MIRROR_PIC+1;
261
    }
262
 
263
#if 0
264
    // check ceiling and floor heights
265
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], vc, nextvc)
266
    {
267
        vc_sp = &sprite[vc];
268
 
269
        if (vc_sp->hitag == VIEW_THRU_CEILING)
270
        {
271
            TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], vf, nextvf)
272
            {
273
                vf_sp = &sprite[vf];
274
 
275
                if (vf_sp->hitag == VIEW_THRU_FLOOR && vf_sp->lotag == vc_sp->lotag)
276
                {
277
                    zdiff = labs(sector[vc_sp->sectnum].ceilingz - sector[vf_sp->sectnum].floorz);
278
 
279
                    //DSPRINTF(ds,"zdiff %d",zdiff);
280
                    MONO_PRINT(ds);
281
 
282
                    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], l, nextl)
283
                    {
284
                        vl_sp = &sprite[l];
285
 
286
                        if (vl_sp->hitag == VIEW_LEVEL1)
287
                        {
288
                            if (sector[vl_sp->sectnum].ceilingz < sector[vc_sp->sectnum].ceilingz + zdiff)
289
                            {
290
                                sprintf(ds,"Sector %d (x %d, y %d) ceiling z to close to VIEW_THRU_CEILING z",
291
                                        vl_sp->sectnum, wall[sector[vl_sp->sectnum].wallptr].x, wall[sector[vl_sp->sectnum].wallptr].y);
292
                                Message(ds,0);
293
                            }
294
                        }
295
                        else if (vl_sp->hitag == VIEW_LEVEL2)
296
                        {
297
                            if (sector[vl_sp->sectnum].floorz > sector[vf_sp->sectnum].floorz + zdiff)
298
                            {
299
                                sprintf(ds,"Sector %d (x %d, y %d)floor z to close to VIEW_THRU_FLOOR z",
300
                                        vl_sp->sectnum, wall[sector[vl_sp->sectnum].wallptr].x, wall[sector[vl_sp->sectnum].wallptr].y);
301
                                Message(ds,0);
302
                            }
303
                        }
304
                    }
305
                }
306
            }
307
        }
308
    }
309
#endif
310
 
311
}
312
 
5198 hendricks2 313
void
314
ResetBuildFAF(void)
5196 hendricks2 315
{
316
    short i, nexti;
317
    SPRITEp sp;
318
 
319
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
320
    {
321
        sp = &sprite[i];
322
 
323
        if (sector[sp->sectnum].ceilingpicnum == FAF_MIRROR_PIC)
324
            sector[sp->sectnum].ceilingpicnum = FAF_PLACE_MIRROR_PIC;
325
 
326
        if (sector[sp->sectnum].floorpicnum == FAF_MIRROR_PIC)
327
            sector[sp->sectnum].floorpicnum = FAF_PLACE_MIRROR_PIC;
328
 
329
        if (sector[sp->sectnum].ceilingpicnum == FAF_MIRROR_PIC+1)
330
            sector[sp->sectnum].ceilingpicnum = FAF_PLACE_MIRROR_PIC+1;
331
 
332
        if (sector[sp->sectnum].floorpicnum == FAF_MIRROR_PIC+1)
333
            sector[sp->sectnum].floorpicnum = FAF_PLACE_MIRROR_PIC+1;
334
    }
335
 
336
    for (i = 0; i < numwalls; i++)
337
    {
338
        if (wall[i].picnum == FAF_MIRROR_PIC)
339
            wall[i].picnum = FAF_PLACE_MIRROR_PIC;
340
 
341
        if (wall[i].picnum == FAF_MIRROR_PIC+1)
342
            wall[i].picnum = FAF_PLACE_MIRROR_PIC+1;
343
    }
344
 
345
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
346
    {
347
        changespritestat(i, STAT_DEFAULT);
348
    }
349
}
350
 
351
 
5198 hendricks2 352
SWBOOL
353
PicInView(short tile_num, SWBOOL reset)
5196 hendricks2 354
{
355
    if (TEST(gotpic[tile_num >> 3], 1 << (tile_num & 7)))
356
    {
357
        if (reset)
358
            RESET(gotpic[tile_num >> 3], 1 << (tile_num & 7));
359
 
360
        return TRUE;
361
    }
362
 
363
    return FALSE;
364
}
365
 
366
void
367
GetUpperLowerSector(short match, int x, int y, short *upper, short *lower)
368
{
8685 ny00123 369
    int i;
5196 hendricks2 370
    short sectorlist[16];
371
    short sln = 0;
372
    short SpriteNum, Next;
373
    SPRITEp sp;
374
 
375
    // didn't find it yet so test ALL sectors
376
    if (sln < 2)
377
    {
378
        sln = 0;
379
        for (i = numsectors - 1; i >= 0; i--)
380
        {
381
            if (inside(x, y, (short) i) == 1)
382
            {
5198 hendricks2 383
                SWBOOL found = FALSE;
5196 hendricks2 384
 
385
                TRAVERSE_SPRITE_SECT(headspritesect[i], SpriteNum, Next)
386
                {
387
                    sp = &sprite[SpriteNum];
388
 
389
                    if (sp->statnum == STAT_FAF &&
390
                        (sp->hitag >= VIEW_LEVEL1 && sp->hitag <= VIEW_LEVEL6)
391
                        && sp->lotag == match)
392
                    {
393
                        found = TRUE;
394
                    }
395
                }
396
 
397
                if (!found)
398
                    continue;
399
 
8302 hendricks2 400
                if (sln < (int)SIZ(sectorlist))
401
                    sectorlist[sln] = i;
5196 hendricks2 402
                sln++;
403
            }
404
        }
405
    }
406
 
407
    if (sln == 0)
408
    {
409
        *upper = -1;
410
        *lower = -1;
411
        return;
412
    }
413
    // Map rooms have NOT been dragged on top of each other
8306 hendricks2 414
    else if (sln == 1)
5196 hendricks2 415
    {
416
        *lower = sectorlist[0];
417
        *upper = sectorlist[0];
418
        return;
419
    }
420
    // Map rooms HAVE been dragged on top of each other
8306 hendricks2 421
    else if (sln > 2)
5196 hendricks2 422
    {
423
        // try again moving the x,y pos around until you only get two sectors
424
        GetUpperLowerSector(match, x - 1, y, upper, lower);
425
    }
8306 hendricks2 426
    else if (sln == 2)
5196 hendricks2 427
    {
428
        if (sector[sectorlist[0]].floorz < sector[sectorlist[1]].floorz)
429
        {
430
            // swap
431
            // make sectorlist[0] the LOW sector
432
            short hold;
433
 
434
            hold = sectorlist[0];
435
            sectorlist[0] = sectorlist[1];
436
            sectorlist[1] = hold;
437
        }
438
 
439
        *lower = sectorlist[0];
440
        *upper = sectorlist[1];
441
    }
442
}
443
 
5198 hendricks2 444
SWBOOL
445
FindCeilingView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 446
{
447
    int xoff = 0;
448
    int yoff = 0;
449
    short i, nexti;
450
    SPRITEp sp = NULL;
451
    int pix_diff;
452
    int newz;
453
 
454
    save.zcount = 0;
455
 
456
    // Search Stat List For closest ceiling view sprite
457
    // Get the match, xoff, yoff from this point
458
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
459
    {
460
        sp = &sprite[i];
461
 
462
        if (sp->hitag == VIEW_THRU_CEILING && sp->lotag == match)
463
        {
464
            xoff = *x - sp->x;
465
            yoff = *y - sp->y;
466
 
467
            break;
468
        }
469
    }
470
 
471
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
472
    {
473
        sp = &sprite[i];
474
 
475
        if (sp->lotag == match)
476
        {
477
            // determine x,y position
478
            if (sp->hitag == VIEW_THRU_FLOOR)
479
            {
480
                short upper, lower;
481
 
482
                *x = sp->x + xoff;
483
                *y = sp->y + yoff;
484
 
485
                // get new sector
486
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
487
                *sectnum = upper;
488
                break;
489
            }
490
        }
491
    }
492
 
493
    if (*sectnum < 0)
494
        return FALSE;
495
 
496
    ASSERT(sp);
497
    ASSERT(sp->hitag == VIEW_THRU_FLOOR);
498
 
499
    if (FAF_DontMoveSectors)
500
        return TRUE;
501
 
502
    pix_diff = labs(z - sector[sp->sectnum].floorz) >> 8;
503
    newz = sector[sp->sectnum].floorz + ((pix_diff / 128) + 1) * Z(128);
504
 
505
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
506
    {
507
        sp = &sprite[i];
508
 
509
        if (sp->lotag == match)
510
        {
511
            // move lower levels ceilings up for the correct view
512
            if (sp->hitag == VIEW_LEVEL2)
513
            {
514
                // save it off
515
                save.sectnum[save.zcount] = sp->sectnum;
516
                save.zval[save.zcount] = sector[sp->sectnum].floorz;
517
                save.pic[save.zcount] = sector[sp->sectnum].floorpicnum;
518
                save.slope[save.zcount] = sector[sp->sectnum].floorheinum;
519
 
520
                sector[sp->sectnum].floorz = newz;
521
                sector[sp->sectnum].floorpicnum = FAF_MIRROR_PIC+1;
522
                sector[sp->sectnum].floorheinum = 0;
523
 
524
                save.zcount++;
525
                ASSERT(save.zcount < ZMAX);
526
            }
527
        }
528
    }
529
 
530
    return TRUE;
531
}
532
 
5198 hendricks2 533
SWBOOL
534
FindFloorView(short match, int32_t* x, int32_t* y, int32_t z, int16_t* sectnum)
5196 hendricks2 535
{
536
    int xoff = 0;
537
    int yoff = 0;
538
    short i, nexti;
539
    SPRITEp sp = NULL;
540
    int newz;
541
    int pix_diff;
542
 
543
    save.zcount = 0;
544
 
545
    // Search Stat List For closest ceiling view sprite
546
    // Get the match, xoff, yoff from this point
547
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
548
    {
549
        sp = &sprite[i];
550
 
551
        if (sp->hitag == VIEW_THRU_FLOOR && sp->lotag == match)
552
        {
553
            xoff = *x - sp->x;
554
            yoff = *y - sp->y;
555
 
556
            break;
557
        }
558
    }
559
 
560
 
561
 
562
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
563
    {
564
        sp = &sprite[i];
565
 
566
        if (sp->lotag == match)
567
        {
568
            // determine x,y position
569
            if (sp->hitag == VIEW_THRU_CEILING)
570
            {
571
                short upper, lower;
572
 
573
                *x = sp->x + xoff;
574
                *y = sp->y + yoff;
575
 
576
                // get new sector
577
                GetUpperLowerSector(match, *x, *y, &upper, &lower);
578
                *sectnum = lower;
579
                break;
580
            }
581
        }
582
    }
583
 
584
    if (*sectnum < 0)
585
        return FALSE;
586
 
587
    ASSERT(sp);
588
    ASSERT(sp->hitag == VIEW_THRU_CEILING);
589
 
590
    if (FAF_DontMoveSectors)
591
        return TRUE;
592
 
593
    // move ceiling multiple of 128 so that the wall tile will line up
594
    pix_diff = labs(z - sector[sp->sectnum].ceilingz) >> 8;
595
    newz = sector[sp->sectnum].ceilingz - ((pix_diff / 128) + 1) * Z(128);
596
 
597
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
598
    {
599
        sp = &sprite[i];
600
 
601
        if (sp->lotag == match)
602
        {
603
            // move upper levels floors down for the correct view
604
            if (sp->hitag == VIEW_LEVEL1)
605
            {
606
                // save it off
607
                save.sectnum[save.zcount] = sp->sectnum;
608
                save.zval[save.zcount] = sector[sp->sectnum].ceilingz;
609
                save.pic[save.zcount] = sector[sp->sectnum].ceilingpicnum;
610
                save.slope[save.zcount] = sector[sp->sectnum].ceilingheinum;
611
 
612
                sector[sp->sectnum].ceilingz = newz;
613
 
614
                sector[sp->sectnum].ceilingpicnum = FAF_MIRROR_PIC+1;
615
                sector[sp->sectnum].ceilingheinum = 0;
616
 
617
                save.zcount++;
618
                ASSERT(save.zcount < ZMAX);
619
            }
620
        }
621
    }
622
 
623
    return TRUE;
624
}
625
 
5198 hendricks2 626
SWBOOL
5196 hendricks2 627
SectorInScene(short tile_num)
628
{
629
    if (TEST(gotsector[tile_num >> 3], 1 << (tile_num & 7)))
630
    {
631
        RESET(gotsector[tile_num >> 3], 1 << (tile_num & 7));
632
        return TRUE;
633
    }
634
 
635
    return FALSE;
636
}
637
 
638
short
639
ViewSectorInScene(short cursectnum, short type, short level)
640
{
641
    int i, nexti;
642
    SPRITEp sp;
643
    short match;
644
 
645
    TRAVERSE_SPRITE_STAT(headspritestat[STAT_FAF], i, nexti)
646
    {
647
        sp = &sprite[i];
648
 
649
        if (sp->hitag == level)
650
        {
651
            if (cursectnum == sp->sectnum)
652
            {
653
                // ignore case if sprite is pointing up
654
                if (sp->ang == 1536)
655
                    continue;
656
 
657
                // only gets to here is sprite is pointing down
658
                // found a potential match
659
                match = sp->lotag;
660
 
661
                return match;
662
            }
663
        }
664
    }
665
 
666
    return -1;
667
}
668
 
5198 hendricks2 669
void
5196 hendricks2 670
DrawOverlapRoom(int tx, int ty, int tz, short tang, int thoriz, short tsectnum)
671
{
672
    short i;
673
    short match;
674
 
675
    save.zcount = 0;
676
 
677
    match = ViewSectorInScene(tsectnum, VIEW_THRU_CEILING, VIEW_LEVEL1);
678
    if (match != -1)
679
    {
680
        FindCeilingView(match, &tx, &ty, tz, &tsectnum);
681
 
682
        if (tsectnum < 0)
683
        {
5201 hendricks2 684
            sprintf(ds,"COULD NOT FIND TAGGED LEVEL2 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 685
            Message(ds, 0);
686
            return;
687
        }
688
 
689
        drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 690
        renderDrawMasks();
5196 hendricks2 691
 
692
        // reset Z's
693
        for (i = 0; i < save.zcount; i++)
694
        {
695
            sector[save.sectnum[i]].floorz = save.zval[i];
696
            sector[save.sectnum[i]].floorpicnum = save.pic[i];
697
            sector[save.sectnum[i]].floorheinum = save.slope[i];
698
        }
699
    }
700
    else
701
    {
702
        match = ViewSectorInScene(tsectnum, VIEW_THRU_FLOOR, VIEW_LEVEL2);
703
        if (match != -1)
704
        {
705
            FindFloorView(match, &tx, &ty, tz, &tsectnum);
706
 
707
            if (tsectnum < 0)
708
            {
5201 hendricks2 709
                sprintf(ds,"COULD NOT FIND TAGGED LEVEL1 SECTOR FROM X %d, Y %d, SECTNUM %d.",pos.x,pos.y,cursectnum);
5196 hendricks2 710
                Message(ds, 0);
711
                return;
712
            }
713
 
714
            drawrooms(tx, ty, tz, tang, thoriz, tsectnum);
7509 hendricks2 715
            renderDrawMasks();
5196 hendricks2 716
 
717
            // reset Z's
718
            for (i = 0; i < save.zcount; i++)
719
            {
720
                sector[save.sectnum[i]].ceilingz = save.zval[i];
721
                sector[save.sectnum[i]].ceilingpicnum = save.pic[i];
722
                sector[save.sectnum[i]].ceilingheinum = save.slope[i];
723
            }
724
        }
725
    }
726
}