-Duke: replaced sector array accesses in actors_d.cpp.

This commit is contained in:
Christoph Oelckers 2021-11-06 23:16:23 +01:00
parent 8c5e4a7fa9
commit e0f3fa2aa0

View file

@ -301,13 +301,13 @@ bool ifsquished(DDukeActor* actor, int p)
if (spri->picnum == APLAYER && ud.clipping)
return false;
auto& sc = sector[spri->sectnum];
int floorceildist = sc.floorz - sc.ceilingz;
auto sectp = spri->sector();
int floorceildist = sectp->floorz - sectp->ceilingz;
if (sc.lotag != ST_23_SWINGING_DOOR)
if (sectp->lotag != ST_23_SWINGING_DOOR)
{
if (spri->pal == 1)
squishme = floorceildist < (32 << 8) && (sc.lotag & 32768) == 0;
squishme = floorceildist < (32 << 8) && (sectp->lotag & 32768) == 0;
else
squishme = floorceildist < (12 << 8);
}
@ -355,27 +355,28 @@ void hitradius_d(DDukeActor* actor, int r, int hp1, int hp2, int hp3, int h
{
tempshort[0] = spri->sectnum;
dasect = spri->sectnum;
auto dasectp = spri->sector();
sectcnt = 0; sectend = 1;
do
{
dasect = tempshort[sectcnt++];
if (((sector[dasect].ceilingz - spri->z) >> 8) < r)
if (((dasectp->ceilingz - spri->z) >> 8) < r)
{
d = abs(wall[sector[dasect].wallptr].x - spri->x) + abs(wall[sector[dasect].wallptr].y - spri->y);
d = abs(wall[dasectp->wallptr].x - spri->x) + abs(wall[dasectp->wallptr].y - spri->y);
if (d < r)
fi.checkhitceiling(dasect);
else
{
// ouch...
d = abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].x - spri->x) + abs(wall[wall[wall[sector[dasect].wallptr].point2].point2].y - spri->y);
d = abs(wall[wall[wall[dasectp->wallptr].point2].point2].x - spri->x) + abs(wall[wall[wall[dasectp->wallptr].point2].point2].y - spri->y);
if (d < r)
fi.checkhitceiling(dasect);
}
}
startwall = sector[dasect].wallptr;
endwall = startwall + sector[dasect].wallnum;
startwall = dasectp->wallptr;
endwall = startwall + dasectp->wallnum;
for (x = startwall, wal = &wall[startwall]; x < endwall; x++, wal++)
if ((abs(wal->x - spri->x) + abs(wal->y - spri->y)) < r)
{
@ -557,6 +558,7 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un
}
dasectnum = spri->sectnum;
auto dasectp = spri->sector();
daz = spri->z;
h = ((tileHeight(spri->picnum) * spri->yrepeat) << 1);
@ -584,15 +586,15 @@ int movesprite_ex_d(DDukeActor* actor, int xchange, int ychange, int zchange, un
// conditional code from hell...
if (dasectnum < 0 || (dasectnum >= 0 &&
((actor->actorstayput >= 0 && actor->actorstayput != dasectnum) ||
((spri->picnum == BOSS2) && spri->pal == 0 && sector[dasectnum].lotag != 3) ||
((spri->picnum == BOSS1 || spri->picnum == BOSS2) && sector[dasectnum].lotag == ST_1_ABOVE_WATER) ||
(sector[dasectnum].lotag == ST_1_ABOVE_WATER && (spri->picnum == LIZMAN || (spri->picnum == LIZTROOP && spri->zvel == 0)))
((spri->picnum == BOSS2) && spri->pal == 0 && dasectp->lotag != 3) ||
((spri->picnum == BOSS1 || spri->picnum == BOSS2) && dasectp->lotag == ST_1_ABOVE_WATER) ||
(dasectp->lotag == ST_1_ABOVE_WATER && (spri->picnum == LIZMAN || (spri->picnum == LIZTROOP && spri->zvel == 0)))
))
)
{
spri->x = oldx;
spri->y = oldy;
if (sector[dasectnum].lotag == ST_1_ABOVE_WATER && spri->picnum == LIZMAN)
if (dasectp->lotag == ST_1_ABOVE_WATER && spri->picnum == LIZMAN)
spri->ang = (krand()&2047);
else if ((actor->temp_data[0]&3) == 1 && spri->picnum != COMMANDER)
spri->ang = (krand()&2047);
@ -939,14 +941,13 @@ int ifhitbyweapon_d(DDukeActor *actor)
void movefallers_d(void)
{
short sect;
int j, x;
DukeStatIterator iti(STAT_FALLER);
while (auto act = iti.Next())
{
auto s = act->s;
sect = s->sectnum;
auto sectp = s->sector();
if (act->temp_data[0] == 0)
{
@ -1011,14 +1012,14 @@ void movefallers_d(void)
x = gs.gravity;
}
if (s->z < (sector[sect].floorz - FOURSLEIGHT))
if (s->z < (sectp->floorz - FOURSLEIGHT))
{
s->zvel += x;
if (s->zvel > 6144)
s->zvel = 6144;
s->z += s->zvel;
}
if ((sector[sect].floorz - s->z) < (16 << 8))
if ((sectp->floorz - s->z) < (16 << 8))
{
j = 1 + (krand() & 7);
for (x = 0; x < j; x++) RANDOMSCRAP(act);
@ -1317,7 +1318,7 @@ static void movesidebolt(DDukeActor* actor)
auto s = actor->s;
int* t = &actor->temp_data[0];
int x;
int sect = s->sectnum;
auto sectp = s->sector();
auto p = findplayer(actor, &x);
if (x > 20480) return;
@ -1343,7 +1344,7 @@ CLEAR_THE_BOLT2:
}
s->picnum++;
if ((krand() & 1) && sector[sect].floorpicnum == HURTRAIL)
if ((krand() & 1) && sectp->floorpicnum == HURTRAIL)
S_PlayActorSound(SHORT_CIRCUIT, actor);
if (s->picnum == SIDEBOLT1 + 4) s->picnum = SIDEBOLT1;
@ -1360,20 +1361,20 @@ static void movebolt(DDukeActor *actor)
auto s = actor->s;
int* t = &actor->temp_data[0];
int x;
int sect = s->sectnum;
auto sectp = s->sector();
auto p = findplayer(actor, &x);
if (x > 20480) return;
if (t[3] == 0)
t[3] = sector[sect].floorshade;
t[3] = sectp->floorshade;
CLEAR_THE_BOLT:
if (t[2])
{
t[2]--;
sector[sect].floorshade = 20;
sector[sect].ceilingshade = 20;
sectp->floorshade = 20;
sectp->ceilingshade = 20;
return;
}
if ((s->xrepeat | s->yrepeat) == 0)
@ -1396,20 +1397,20 @@ CLEAR_THE_BOLT:
if (l & 1) s->cstat ^= 2;
if (s->picnum == (BOLT1+1) && (krand()&7) == 0 && sector[sect].floorpicnum == HURTRAIL)
if (s->picnum == (BOLT1+1) && (krand()&7) == 0 && sectp->floorpicnum == HURTRAIL)
S_PlayActorSound(SHORT_CIRCUIT,actor);
if (s->picnum==BOLT1+4) s->picnum=BOLT1;
if (s->picnum & 1)
{
sector[sect].floorshade = 0;
sector[sect].ceilingshade = 0;
sectp->floorshade = 0;
sectp->ceilingshade = 0;
}
else
{
sector[sect].floorshade = 20;
sector[sect].ceilingshade = 20;
sectp->floorshade = 20;
sectp->ceilingshade = 20;
}
}
@ -2000,13 +2001,13 @@ void movetransports_d(void)
continue;
}
int sect = spr->sectnum;
int sectlotag = sector[sect].lotag;
auto sectp = spr->sector();
int sectlotag = sectp->lotag;
int onfloorz = act->temp_data[4];
if (act->temp_data[0] > 0) act->temp_data[0]--;
DukeSectIterator itj(sect);
DukeSectIterator itj(spr->sectnum);
while (auto act2 = itj.Next())
{
auto spr2 = act2->s;
@ -2087,8 +2088,8 @@ void movetransports_d(void)
int k = 0;
if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].pos.z > (sector[sect].floorz - (16 << 8)) && (PlayerInput(p, SB_CROUCH) || ps[p].poszv > 2048))
// if( onfloorz && sectlotag == 1 && ps[p].pos.z > (sector[sect].floorz-(6<<8)) )
if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].pos.z > (sectp->floorz - (16 << 8)) && (PlayerInput(p, SB_CROUCH) || ps[p].poszv > 2048))
// if( onfloorz && sectlotag == 1 && ps[p].pos.z > (sectp->floorz-(6<<8)) )
{
k = 1;
if (screenpeek == p)
@ -2105,7 +2106,7 @@ void movetransports_d(void)
}
if (onfloorz && sectlotag == ST_2_UNDERWATER && ps[p].pos.z < (sector[sect].ceilingz + (6 << 8)))
if (onfloorz && sectlotag == ST_2_UNDERWATER && ps[p].pos.z < (sectp->ceilingz + (6 << 8)))
{
k = 1;
// if( spr2->extra <= 0) break;
@ -2173,10 +2174,10 @@ void movetransports_d(void)
{
warpspriteto = 0;
if (ll && sectlotag == 2 && spr2->z < (sector[sect].ceilingz + ll))
if (ll && sectlotag == 2 && spr2->z < (sectp->ceilingz + ll))
warpspriteto = 1;
if (ll && sectlotag == 1 && spr2->z > (sector[sect].floorz - ll))
if (ll && sectlotag == 1 && spr2->z > (sectp->floorz - ll))
warpspriteto = 1;
if (sectlotag == 0 && (onfloorz || abs(spr2->z - spr->z) < 4096))
@ -2233,7 +2234,7 @@ void movetransports_d(void)
case 0:
if (onfloorz)
{
if (spr2->statnum == STAT_PROJECTILE || (checkcursectnums(sect) == -1 && checkcursectnums(Owner->s->sectnum) == -1))
if (spr2->statnum == STAT_PROJECTILE || (checkcursectnums(spr->sectnum) == -1 && checkcursectnums(Owner->s->sectnum) == -1))
{
spr2->x += (Owner->s->x - spr->x);
spr2->y += (Owner->s->y - spr->y);
@ -2314,7 +2315,7 @@ static void greenslime(DDukeActor *actor)
{
auto s = actor->s;
int* t = &actor->temp_data[0];
int sect = s->sectnum;
auto sectp = s->sector();
int j;
// #ifndef isShareware()
@ -2331,7 +2332,7 @@ static void greenslime(DDukeActor *actor)
t[1] += 128;
if (sector[sect].floorstat & 1)
if (sectp->floorstat & 1)
{
deletesprite(actor);
return;
@ -2410,7 +2411,7 @@ static void greenslime(DDukeActor *actor)
{
for (x = 0; x < 8; x++)
{
auto j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5);
auto j = EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5);
j->s->pal = 6;
}
@ -2525,7 +2526,7 @@ static void greenslime(DDukeActor *actor)
for (x = 0; x < 8; x++)
{
auto j = EGS(sect, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5);
auto j = EGS(s->sectnum, s->x, s->y, s->z - (8 << 8), SCRAP3 + (krand() & 3), -8, 48, 48, krand() & 2047, (krand() & 63) + 64, -(krand() & 4095) - (s->zvel >> 2), actor, 5);
j->s->pal = 6;
}
t[0] = -3;
@ -2590,7 +2591,7 @@ static void greenslime(DDukeActor *actor)
//Check randomly to see of there is an actor near
if (rnd(32))
{
DukeSectIterator it(sect);
DukeSectIterator it(s->sectnum);
while (auto a2 = it.Next())
{
if (gs.actorinfo[a2->s->picnum].flags & SFLAG_GREENSLIMEFOOD)
@ -2620,7 +2621,7 @@ static void greenslime(DDukeActor *actor)
s->zvel = 0;
s->cstat &= (65535 - 8);
if ((sector[sect].ceilingstat & 1) || (actor->ceilingz + 6144) < s->z)
if ((sectp->ceilingstat & 1) || (actor->ceilingz + 6144) < s->z)
{
s->z += 2048;
t[0] = 3;
@ -2653,7 +2654,7 @@ static void greenslime(DDukeActor *actor)
s->xrepeat = 36 + bcos(t[1], -11);
s->yrepeat = 16 + bsin(t[1], -13);
if (rnd(4) && (sector[sect].ceilingstat & 1) == 0 &&
if (rnd(4) && (sectp->ceilingstat & 1) == 0 &&
abs(actor->floorz - actor->ceilingz)
< (192 << 8))
{
@ -2715,12 +2716,12 @@ static void flamethrowerflame(DDukeActor *actor)
{
auto s = actor->s;
int* t = &actor->temp_data[0];
int sect = s->sectnum;
auto sectp = s->sector();
int x;
int p = findplayer(actor, &x);
execute(actor, p, x);
t[0]++;
if (sector[sect].lotag == 2)
if (sectp->lotag == 2)
{
spawn(actor, EXPLOSION2)->s->shade = 127;
deletesprite(actor);
@ -2818,7 +2819,7 @@ static void heavyhbomb(DDukeActor *actor)
auto s = actor->s;
auto t = &actor->temp_data[0];
auto Owner = actor->GetOwner();
int sect = s->sectnum;
auto sectp = s->sector();
int x, l;
if ((s->cstat & 32768))
@ -2855,16 +2856,16 @@ static void heavyhbomb(DDukeActor *actor)
{
makeitfall(actor);
if (sector[sect].lotag != 1 && s->z >= actor->floorz - (FOURSLEIGHT) && s->yvel < 3)
if (sectp->lotag != 1 && s->z >= actor->floorz - (FOURSLEIGHT) && s->yvel < 3)
{
if (s->yvel > 0 || (s->yvel == 0 && actor->floorz == sector[sect].floorz))
if (s->yvel > 0 || (s->yvel == 0 && actor->floorz == sectp->floorz))
S_PlayActorSound(PIPEBOMB_BOUNCE, actor);
s->zvel = -((4 - s->yvel) << 8);
if (s->sector()->lotag == 2)
s->zvel >>= 2;
s->yvel++;
}
if (s->z < actor->ceilingz) // && sector[sect].lotag != 2 )
if (s->z < actor->ceilingz) // && sectp->lotag != 2 )
{
s->z = actor->ceilingz + (3 << 8);
s->zvel = 0;
@ -2904,7 +2905,7 @@ static void heavyhbomb(DDukeActor *actor)
if (s->xvel > 0)
{
s->xvel -= 5;
if (sector[sect].lotag == 2)
if (sectp->lotag == 2)
s->xvel -= 10;
if (s->xvel < 0)
@ -3256,22 +3257,22 @@ static void fireflyflyingeffect(DDukeActor *actor)
void moveexplosions_d(void) // STATNUM 5
{
int sect, p;
int p;
int x;
DukeStatIterator it(STAT_MISC);
while (auto act = it.Next())
{
auto s = act->s;
int* t = &act->temp_data[0];
sect = s->sectnum;
if (sect < 0 || s->xrepeat == 0)
if (s->sectnum < 0 || s->xrepeat == 0)
{
deletesprite(act);
continue;
}
int* t = &act->temp_data[0];
auto sectp = s->sector();
switch (s->picnum)
{
@ -3416,7 +3417,7 @@ void moveexplosions_d(void) // STATNUM 5
case SHELL:
case SHOTGUNSHELL:
shell(act, (sector[sect].floorz + (24 << 8)) < s->z);
shell(act, (sectp->floorz + (24 << 8)) < s->z);
continue;
case GLASSPIECES: