- player.cpp is free of array references, except one that's unavoidable for now.

This commit is contained in:
Christoph Oelckers 2020-10-23 19:50:18 +02:00
parent 79f850d126
commit 3fdeedcae7
4 changed files with 58 additions and 56 deletions

View file

@ -112,7 +112,7 @@ int wakeup(DDukeActor* sn, int pn);
int timedexit(int snum); int timedexit(int snum);
void dokneeattack(int snum, int pi, const std::initializer_list<int>& respawnlist); void dokneeattack(int snum, const std::initializer_list<int>& respawnlist);
int endoflevel(int snum); int endoflevel(int snum);
void playerisdead(int snum, int psectlotag, int fz, int cz); void playerisdead(int snum, int psectlotag, int fz, int cz);
void footprints(int snum); void footprints(int snum);
@ -135,7 +135,7 @@ void quickkill(struct player_struct* p);
void setpal(struct player_struct* p); void setpal(struct player_struct* p);
int madenoise(int playerNum); int madenoise(int playerNum);
int haskey(int sect, int snum); int haskey(int sect, int snum);
void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST); void shootbloodsplat(DDukeActor* i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST);
void breakwall(short newpn, short spr, short dawallnum); void breakwall(short newpn, short spr, short dawallnum);
int callsound(int sectnum,DDukeActor* snum); int callsound(int sectnum,DDukeActor* snum);

View file

@ -147,9 +147,10 @@ void quickkill(struct player_struct* p)
{ {
SetPlayerPal(p, PalEntry(48, 48, 48, 48)); SetPlayerPal(p, PalEntry(48, 48, 48, 48));
p->GetActor()->s.extra = 0; auto pa = p->GetActor();
p->GetActor()->s.cstat |= 32768; pa->s.extra = 0;
if (ud.god == 0) fi.guts(&hittype[p->i], TILE_JIBS6, 8, myconnectindex); pa->s.cstat |= 32768;
if (ud.god == 0) fi.guts(pa, TILE_JIBS6, 8, myconnectindex);
return; return;
} }
@ -351,10 +352,10 @@ int aim(spritetype* s, int aang)
if (j >= 0) if (j >= 0)
break; break;
StatIterator it(aimstats[k]); DukeStatIterator it(aimstats[k]);
while ((i = it.NextIndex()) >= 0) while (auto act = it.Next())
{ {
auto sp = &sprite[i]; auto sp = &act->s;
if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257) if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257)
if (badguy(sp) || k < 2) if (badguy(sp) || k < 2)
{ {
@ -389,7 +390,7 @@ int aim(spritetype* s, int aang)
if (a && cans) if (a && cans)
{ {
smax = sdist; smax = sdist;
j = i; j = int(act-hittype);
} }
} }
} }
@ -406,7 +407,7 @@ int aim(spritetype* s, int aang)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnlist) void dokneeattack(int snum, const std::initializer_list<int> & respawnlist)
{ {
auto p = &ps[snum]; auto p = &ps[snum];
@ -421,10 +422,10 @@ void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnli
p->holster_weapon = 0; p->holster_weapon = 0;
if (p->weapon_pos < 0) if (p->weapon_pos < 0)
p->weapon_pos = -p->weapon_pos; p->weapon_pos = -p->weapon_pos;
if (p->actorsqu != nullptr && dist(&sprite[pi], &p->actorsqu->s) < 1400) if (p->actorsqu != nullptr && dist(p->GetActor(), p->actorsqu) < 1400)
{ {
fi.guts(p->actorsqu, TILE_JIBS6, 7, myconnectindex); fi.guts(p->actorsqu, TILE_JIBS6, 7, myconnectindex);
fi.spawn(p->actorsqu->GetIndex(), TILE_BLOODPOOL); spawn(p->actorsqu, TILE_BLOODPOOL);
S_PlayActorSound(SQUISHED, p->actorsqu); S_PlayActorSound(SQUISHED, p->actorsqu);
if (isIn(p->actorsqu->s.picnum, respawnlist)) if (isIn(p->actorsqu->s.picnum, respawnlist))
{ {
@ -459,8 +460,8 @@ void dokneeattack(int snum, int pi, const std::initializer_list<int> & respawnli
int makepainsounds(int snum, int type) int makepainsounds(int snum, int type)
{ {
auto p = &ps[snum]; auto p = &ps[snum];
auto pi = p->i; auto actor = p->GetActor();
auto s = &sprite[pi]; auto s = &actor->s;
int k = 0; int k = 0;
switch (type) switch (type)
@ -472,12 +473,12 @@ int makepainsounds(int snum, int type)
k = 1; k = 1;
else else
{ {
if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
SetPlayerPal(p, PalEntry(32, 64, 64, 64)); SetPlayerPal(p, PalEntry(32, 64, 64, 64));
s->extra -= 1 + (krand() & 3); s->extra -= 1 + (krand() & 3);
if (!S_CheckActorSoundPlaying(pi, SHORT_CIRCUIT)) if (!S_CheckActorSoundPlaying(actor, SHORT_CIRCUIT))
S_PlayActorSound(SHORT_CIRCUIT, pi); S_PlayActorSound(SHORT_CIRCUIT, actor);
} }
} }
break; break;
@ -488,8 +489,8 @@ int makepainsounds(int snum, int type)
k = 1; k = 1;
else else
{ {
if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
SetPlayerPal(p, PalEntry(32, 0, 8, 0)); SetPlayerPal(p, PalEntry(32, 0, 8, 0));
s->extra -= 1 + (krand() & 3); s->extra -= 1 + (krand() & 3);
} }
@ -502,8 +503,8 @@ int makepainsounds(int snum, int type)
k = 1; k = 1;
else else
{ {
if (!S_CheckActorSoundPlaying(pi, DUKE_LONGTERM_PAIN)) if (!S_CheckActorSoundPlaying(actor, DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
SetPlayerPal(p, PalEntry(32, 8, 0, 0)); SetPlayerPal(p, PalEntry(32, 8, 0, 0));
s->extra -= 1 + (krand() & 3); s->extra -= 1 + (krand() & 3);
} }
@ -517,7 +518,7 @@ int makepainsounds(int snum, int type)
s->extra -= 2; s->extra -= 2;
else else
s->extra -= 4; s->extra -= 4;
S_PlayActorSound(DUKE_LONGTERM_PAIN, pi); S_PlayActorSound(DUKE_LONGTERM_PAIN, actor);
} }
break; break;
} }
@ -533,36 +534,40 @@ int makepainsounds(int snum, int type)
void footprints(int snum) void footprints(int snum)
{ {
auto p = &ps[snum]; auto p = &ps[snum];
auto pi = p->i; auto actor = p->GetActor();
auto s = &sprite[pi]; auto s = &actor->s;
auto psect = s->sectnum; auto psect = s->sectnum;
if (p->footprintcount > 0 && p->on_ground) if (p->footprintcount > 0 && p->on_ground)
if ((sector[p->cursectnum].floorstat & 2) != 2) if ((sector[p->cursectnum].floorstat & 2) != 2)
{ {
int j; int j = -1;
SectIterator it(psect); DukeSectIterator it(psect);
while ((j = it.NextIndex()) >= 0) while (auto act = it.Next())
{ {
if (sprite[j].picnum == TILE_FOOTPRINTS || sprite[j].picnum == TILE_FOOTPRINTS2 || sprite[j].picnum == TILE_FOOTPRINTS3 || sprite[j].picnum == TILE_FOOTPRINTS4) if (act->s.picnum == TILE_FOOTPRINTS || act->s.picnum == TILE_FOOTPRINTS2 || act->s.picnum == TILE_FOOTPRINTS3 || act->s.picnum == TILE_FOOTPRINTS4)
if (abs(sprite[j].x - p->posx) < 384) if (abs(act->s.x - p->posx) < 384)
if (abs(sprite[j].y - p->posy) < 384) if (abs(act->s.y - p->posy) < 384)
{
j = 1;
break; break;
}
} }
if (j < 0) if (j < 0)
{ {
p->footprintcount--; p->footprintcount--;
if (sector[p->cursectnum].lotag == 0 && sector[p->cursectnum].hitag == 0) if (sector[p->cursectnum].lotag == 0 && sector[p->cursectnum].hitag == 0)
{ {
DDukeActor* fprint;
switch (krand() & 3) switch (krand() & 3)
{ {
case 0: j = fi.spawn(pi, TILE_FOOTPRINTS); break; case 0: fprint = spawn(actor, TILE_FOOTPRINTS); break;
case 1: j = fi.spawn(pi, TILE_FOOTPRINTS2); break; case 1: fprint = spawn(actor, TILE_FOOTPRINTS2); break;
case 2: j = fi.spawn(pi, TILE_FOOTPRINTS3); break; case 2: fprint = spawn(actor, TILE_FOOTPRINTS3); break;
default: j = fi.spawn(pi, TILE_FOOTPRINTS4); break; default: fprint = spawn(actor, TILE_FOOTPRINTS4); break;
} }
sprite[j].pal = p->footprintpal; fprint->s.pal = p->footprintpal;
sprite[j].shade = p->footprintshade; fprint->s.shade = p->footprintshade;
} }
} }
} }
@ -584,8 +589,8 @@ inline void backupplayer(player_struct* p)
void playerisdead(int snum, int psectlotag, int fz, int cz) void playerisdead(int snum, int psectlotag, int fz, int cz)
{ {
auto p = &ps[snum]; auto p = &ps[snum];
auto pi = p->i; auto actor = p->GetActor();
auto s = &sprite[pi]; auto s = &actor->s;
if (p->dead_flag == 0) if (p->dead_flag == 0)
{ {
@ -606,8 +611,8 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
p->jetpack_on = 0; p->jetpack_on = 0;
p->holoduke_on = nullptr; p->holoduke_on = nullptr;
if (!isRR())S_StopSound(DUKE_JETPACK_IDLE, pi); if (!isRR())S_StopSound(DUKE_JETPACK_IDLE, actor);
S_StopSound(-1, pi, CHAN_VOICE); S_StopSound(-1, actor, CHAN_VOICE);
if (s->pal != 1 && (s->cstat & 32768) == 0) s->cstat = 0; if (s->pal != 1 && (s->cstat & 32768) == 0) s->cstat = 0;
@ -658,9 +663,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
s->zvel = -348; s->zvel = -348;
} }
clipmove(&p->posx, &p->posy, clipmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 0, 0, 164, (4 << 8), (4 << 8), CLIPMASK0);
&p->posz, &p->cursectnum,
0, 0, 164L, (4L << 8), (4L << 8), CLIPMASK0);
// p->bobcounter += 32; // p->bobcounter += 32;
} }
@ -670,7 +673,7 @@ void playerisdead(int snum, int psectlotag, int fz, int cz)
updatesector(p->posx, p->posy, &p->cursectnum); updatesector(p->posx, p->posy, &p->cursectnum);
pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (20L << 8), CLIPMASK0); pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4 << 8), (20 << 8), CLIPMASK0);
if (fz > cz + (16 << 8) && s->pal != 1) if (fz > cz + (16 << 8) && s->pal != 1)
p->angle.rotscrnang = buildlook(p->dead_flag + ((fz + p->posz) >> 7)); p->angle.rotscrnang = buildlook(p->dead_flag + ((fz + p->posz) >> 7));
@ -1065,13 +1068,12 @@ int haskey(int sect, int snum)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST) void shootbloodsplat(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith, int BIGFORCE, int OOZFILTER, int NEWBEAST)
{ {
auto actor = &hittype[i];
spritetype* const s = &actor->s; spritetype* const s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int zvel; int zvel;
short hitsect, hitspr, hitwall, k; short hitsect, hitspr, hitwall;
int hitx, hity, hitz; int hitx, hity, hitz;
if (p >= 0) if (p >= 0)
@ -1099,10 +1101,10 @@ void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith, i
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
SectIterator it(wall[hitwall].nextsector); DukeSectIterator it(wall[hitwall].nextsector);
while ((k = it.NextIndex()) >= 0) while (auto act2 = it.Next())
{ {
if (sprite[k].statnum == 3 && sprite[k].lotag == 13) if (act2->s.statnum == STAT_EFFECTOR && act2->s.lotag == SE_13_EXPLOSIVE)
return; return;
} }
} }
@ -1146,7 +1148,7 @@ bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum,
ny = (sintable[(ang + 1024) & 2047] >> 4); ny = (sintable[(ang + 1024) & 2047] >> 4);
nz = q16horiz >> 9; nz = q16horiz >> 9;
sp = &sprite[pp->i]; sp = &pp->GetActor()->s;
bakcstat = sp->cstat; bakcstat = sp->cstat;
sp->cstat &= (short)~0x101; sp->cstat &= (short)~0x101;

View file

@ -1082,7 +1082,7 @@ void shoot_d(int i, int atwith)
case BLOODSPLAT2: case BLOODSPLAT2:
case BLOODSPLAT3: case BLOODSPLAT3:
case BLOODSPLAT4: case BLOODSPLAT4:
shootbloodsplat(i, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, NEWBEAST); shootbloodsplat(actor, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, NEWBEAST);
break; break;
case KNEE: case KNEE:
@ -3151,7 +3151,7 @@ HORIZONLY:
} }
} }
dokneeattack(snum, pi, { FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, PODFEM1, NAKED1, STATUE }); dokneeattack(snum, { FEM1, FEM2, FEM3, FEM4, FEM5, FEM6, FEM7, FEM8, FEM9, FEM10, PODFEM1, NAKED1, STATUE });
if (fi.doincrements(p)) return; if (fi.doincrements(p)) return;

View file

@ -888,7 +888,7 @@ void shoot_r(int i, int atwith)
case BLOODSPLAT2: case BLOODSPLAT2:
case BLOODSPLAT3: case BLOODSPLAT3:
case BLOODSPLAT4: case BLOODSPLAT4:
shootbloodsplat(i, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, -1); shootbloodsplat(actor, p, sx, sy, sz, sa, atwith, BIGFORCE, OOZFILTER, -1);
return; return;
case SLINGBLADE: case SLINGBLADE:
@ -4137,7 +4137,7 @@ HORIZONLY:
fi.addweapon(p, p->last_full_weapon); fi.addweapon(p, p->last_full_weapon);
return; return;
} }
dokneeattack(snum, pi, { FEM10, NAKED1, STATUE }); dokneeattack(snum, { FEM10, NAKED1, STATUE });
if (fi.doincrements(p)) return; if (fi.doincrements(p)) return;