- weaponcommon subfunctions.

This commit is contained in:
Christoph Oelckers 2020-10-22 20:07:05 +02:00
parent c5f7c29ead
commit 00b12c5fd6
2 changed files with 102 additions and 107 deletions

View file

@ -1613,35 +1613,35 @@ static bool movefireball(DDukeActor* actor)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool weaponhitsprite(int i, int j, bool fireball) static bool weaponhitsprite(DDukeActor* proj, DDukeActor *targ, bool fireball)
{ {
auto s = &sprite[i]; auto s = &proj->s;
if (s->picnum == FREEZEBLAST && targ->s.pal == 1)
if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) if (badguy(targ) || targ->s.picnum == APLAYER)
if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER)
{ {
j = fi.spawn(i, TRANSPORTERSTAR); auto spawned = spawn(targ, TRANSPORTERSTAR);
sprite[j].pal = 1; spawned->s.pal = 1;
sprite[j].xrepeat = 32; spawned->s.xrepeat = 32;
sprite[j].yrepeat = 32; spawned->s.yrepeat = 32;
deletesprite(i); deletesprite(proj);
return true; return true;
} }
if (!isWorldTour() || s->picnum != FIREBALL || fireball) if (!isWorldTour() || s->picnum != FIREBALL || fireball)
fi.checkhitsprite(j, i); fi.checkhitsprite(targ->GetIndex(), proj->GetIndex());
if (sprite[j].picnum == APLAYER) if (targ->s.picnum == APLAYER)
{ {
int p = sprite[j].yvel; int p = targ->s.yvel;
auto Owner = proj->GetOwner();
if (ud.multimode >= 2 && fireball && sprite[s->owner].picnum == APLAYER) if (ud.multimode >= 2 && fireball && Owner && Owner->s.picnum == APLAYER)
{ {
ps[p].numloogs = -1 - sprite[i].yvel; ps[p].numloogs = -1 - s->yvel;
} }
S_PlayActorSound(PISTOL_BODYHIT, j); S_PlayActorSound(PISTOL_BODYHIT, targ);
if (s->picnum == SPIT) if (s->picnum == SPIT)
{ {
@ -1650,10 +1650,10 @@ static bool weaponhitsprite(int i, int j, bool fireball)
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)
{ {
if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) if (!S_CheckActorSoundPlaying(ps[p].GetActor(), DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor());
j = 3 + (krand() & 3); int j = 3 + (krand() & 3);
ps[p].numloogs = j; ps[p].numloogs = j;
ps[p].loogcnt = 24 * 4; ps[p].loogcnt = 24 * 4;
for (int x = 0; x < j; x++) for (int x = 0; x < j; x++)
@ -1673,10 +1673,9 @@ static bool weaponhitsprite(int i, int j, bool fireball)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool weaponhitwall(int i, int j, const vec3_t &oldpos) static bool weaponhitwall(DDukeActor *proj, int j, const vec3_t &oldpos)
{ {
auto s = &sprite[i]; auto s = &proj->s;
if (s->picnum != RPG && s->picnum != FREEZEBLAST && s->picnum != SPIT && if (s->picnum != RPG && s->picnum != FREEZEBLAST && s->picnum != SPIT &&
(!isWorldTour() || s->picnum != FIREBALL) && (!isWorldTour() || s->picnum != FIREBALL) &&
(wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR))
@ -1685,14 +1684,14 @@ static bool weaponhitwall(int i, int j, const vec3_t &oldpos)
wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].x - wall[j].x,
wall[wall[j].point2].y - wall[j].y); wall[wall[j].point2].y - wall[j].y);
s->ang = ((k << 1) - s->ang) & 2047; s->ang = ((k << 1) - s->ang) & 2047;
s->owner = i; proj->SetOwner(proj);
fi.spawn(i, TRANSPORTERSTAR); spawn(proj, TRANSPORTERSTAR);
return true; return true;
} }
else else
{ {
setsprite(i, &oldpos); setsprite(proj, oldpos);
fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); fi.checkhitwall(proj->GetIndex(), j, s->x, s->y, s->z, s->picnum);
if (s->picnum == FREEZEBLAST) if (s->picnum == FREEZEBLAST)
{ {
@ -1718,18 +1717,17 @@ static bool weaponhitwall(int i, int j, const vec3_t &oldpos)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool weaponhitsector(int i, const vec3_t& oldpos, bool fireball) static bool weaponhitsector(DDukeActor* proj, const vec3_t& oldpos, bool fireball)
{ {
auto s = &sprite[i]; auto s = &proj->s;
setsprite(proj, oldpos);
setsprite(i, &oldpos);
if (s->zvel < 0) if (s->zvel < 0)
{ {
if (sector[s->sectnum].ceilingstat & 1) if (sector[s->sectnum].ceilingstat & 1)
if (sector[s->sectnum].ceilingpal == 0) if (sector[s->sectnum].ceilingpal == 0)
{ {
deletesprite(i); deletesprite(proj);
return true; return true;
} }
@ -1737,18 +1735,18 @@ static bool weaponhitsector(int i, const vec3_t& oldpos, bool fireball)
} }
else if (fireball) else if (fireball)
{ {
int j = fi.spawn(i, LAVAPOOL); auto spawned = spawn(proj, LAVAPOOL);
sprite[j].owner = sprite[i].owner; spawned->SetOwner(proj);
sprite[j].yvel = sprite[i].yvel; spawned->SetHitOwner(proj);
hittype[j].owner = sprite[i].owner; spawned->s.yvel = s->yvel;
deletesprite(i); deletesprite(proj);
return true; return true;
} }
if (s->picnum == FREEZEBLAST) if (s->picnum == FREEZEBLAST)
{ {
bounce(&hittype[i]); bounce(proj);
ssp(i, CLIPMASK1); ssp(proj, CLIPMASK1);
s->extra >>= 1; s->extra >>= 1;
if (s->xrepeat > 8) if (s->xrepeat > 8)
s->xrepeat -= 2; s->xrepeat -= 2;
@ -1871,16 +1869,16 @@ static void weaponcommon_d(int i)
if ((j & kHitTypeMask) == kHitSprite) if ((j & kHitTypeMask) == kHitSprite)
{ {
j &= kHitIndexMask; j &= kHitIndexMask;
if (weaponhitsprite(i, j, fireball)) return; if (weaponhitsprite(&hittype[i], &hittype[j], fireball)) return;
} }
else if ((j & kHitTypeMask) == kHitWall) else if ((j & kHitTypeMask) == kHitWall)
{ {
j &= kHitIndexMask; j &= kHitIndexMask;
if (weaponhitwall(i, j, oldpos)) return; if (weaponhitwall(&hittype[i], j, oldpos)) return;
} }
else if ((j & kHitTypeMask) == kHitSector) else if ((j & kHitTypeMask) == kHitSector)
{ {
if (weaponhitsector(i, oldpos, fireball)) return; if (weaponhitsector(&hittype[i], oldpos, fireball)) return;
} }
if (s->picnum != SPIT) if (s->picnum != SPIT)

View file

@ -1155,48 +1155,46 @@ static void chickenarrow(DDukeActor* actor)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool weaponhitsprite(int i, int j, const vec3_t &oldpos) static bool weaponhitsprite(DDukeActor *proj, DDukeActor *targ, const vec3_t &oldpos)
{ {
auto s = &sprite[i]; auto s = &proj->s;
if (isRRRA()) if (isRRRA())
{ {
if (sprite[j].picnum == MINION if (targ->s.picnum == MINION
&& (s->picnum == RPG || s->picnum == RPG2) && (s->picnum == RPG || s->picnum == RPG2)
&& sprite[j].pal == 19) && targ->s.pal == 19)
{ {
S_PlayActorSound(RPG_EXPLODE, i); S_PlayActorSound(RPG_EXPLODE, proj);
int k = fi.spawn(i, EXPLOSION2); spawn(proj, EXPLOSION2)->s.pos = oldpos;
sprite[k].pos = oldpos;
return true; return true;
} }
} }
else if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) else if (s->picnum == FREEZEBLAST && targ->s.pal == 1)
if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER) if (badguy(targ) || targ->s.picnum == APLAYER)
{ {
j = fi.spawn(i, TRANSPORTERSTAR); auto star = spawn(proj, TRANSPORTERSTAR);
sprite[j].pal = 1; star->s.pal = 1;
sprite[j].xrepeat = 32; star->s.xrepeat = 32;
sprite[j].yrepeat = 32; star->s.yrepeat = 32;
deletesprite(i); deletesprite(proj);
return true; return true;
} }
fi.checkhitsprite(j, i); fi.checkhitsprite(targ->GetIndex(), proj->GetIndex());
if (sprite[j].picnum == APLAYER) if (targ->s.picnum == APLAYER)
{ {
int p = sprite[j].yvel; int p = targ->s.yvel;
S_PlayActorSound(PISTOL_BODYHIT, j); S_PlayActorSound(PISTOL_BODYHIT, targ);
if (s->picnum == SPIT) if (s->picnum == SPIT)
{ {
if (isRRRA() && sprite[s->owner].picnum == MAMA) if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA)
{ {
guts_r(&hittype[i], RABBITJIBA, 2, myconnectindex); guts_r(proj, RABBITJIBA, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBB, 2, myconnectindex); guts_r(proj, RABBITJIBB, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBC, 2, myconnectindex); guts_r(proj, RABBITJIBC, 2, myconnectindex);
} }
ps[p].horizon.addadjustment(32); ps[p].horizon.addadjustment(32);
@ -1204,10 +1202,10 @@ static bool weaponhitsprite(int i, int j, const vec3_t &oldpos)
if (ps[p].loogcnt == 0) if (ps[p].loogcnt == 0)
{ {
if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) if (!S_CheckActorSoundPlaying(ps[p].GetActor(), DUKE_LONGTERM_PAIN))
S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].GetActor());
j = 3 + (krand() & 3); int j = 3 + (krand() & 3);
ps[p].numloogs = j; ps[p].numloogs = j;
ps[p].loogcnt = 24 * 4; ps[p].loogcnt = 24 * 4;
for (int x = 0; x < j; x++) for (int x = 0; x < j; x++)
@ -1227,36 +1225,34 @@ static bool weaponhitsprite(int i, int j, const vec3_t &oldpos)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static bool weaponhitwall(int i, int j, const vec3_t& oldpos) static bool weaponhitwall(DDukeActor *proj, int wal, const vec3_t& oldpos)
{ {
auto act = &hittype[i]; auto s = &proj->s;
auto s = &act->s; if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA)
if (isRRRA() && sprite[s->owner].picnum == MAMA)
{ {
guts_r(&hittype[i], RABBITJIBA, 2, myconnectindex); guts_r(proj, RABBITJIBA, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBB, 2, myconnectindex); guts_r(proj, RABBITJIBB, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBC, 2, myconnectindex); guts_r(proj, RABBITJIBC, 2, myconnectindex);
} }
if (s->picnum != RPG && (!isRRRA() || s->picnum != RPG2) && s->picnum != FREEZEBLAST && s->picnum != SPIT && s->picnum != SHRINKSPARK && (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) if (s->picnum != RPG && (!isRRRA() || s->picnum != RPG2) && s->picnum != FREEZEBLAST && s->picnum != SPIT && s->picnum != SHRINKSPARK && (wall[wal].overpicnum == MIRROR || wall[wal].picnum == MIRROR))
{ {
int k = getangle( int k = getangle(
wall[wall[j].point2].x - wall[j].x, wall[wall[wal].point2].x - wall[wal].x,
wall[wall[j].point2].y - wall[j].y); wall[wall[wal].point2].y - wall[wal].y);
s->ang = ((k << 1) - s->ang) & 2047; s->ang = ((k << 1) - s->ang) & 2047;
s->owner = i; proj->SetOwner(proj);
fi.spawn(i, TRANSPORTERSTAR); spawn(proj, TRANSPORTERSTAR);
return true; return true;
} }
else else
{ {
setsprite(i, &oldpos); setsprite(proj, oldpos);
fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); fi.checkhitwall(proj->GetIndex(), wal, s->x, s->y, s->z, s->picnum);
if (!isRRRA() && s->picnum == FREEZEBLAST) if (!isRRRA() && s->picnum == FREEZEBLAST)
{ {
if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) if (wall[wal].overpicnum != MIRROR && wall[wal].picnum != MIRROR)
{ {
s->extra >>= 1; s->extra >>= 1;
if (s->xrepeat > 8) if (s->xrepeat > 8)
@ -1267,42 +1263,43 @@ static bool weaponhitwall(int i, int j, const vec3_t& oldpos)
} }
int k = getangle( int k = getangle(
wall[wall[j].point2].x - wall[j].x, wall[wall[wal].point2].x - wall[wal].x,
wall[wall[j].point2].y - wall[j].y); wall[wall[wal].point2].y - wall[wal].y);
s->ang = ((k << 1) - s->ang) & 2047; s->ang = ((k << 1) - s->ang) & 2047;
return true; return true;
} }
if (s->picnum == SHRINKSPARK) if (s->picnum == SHRINKSPARK)
{ {
if (wall[j].picnum >= RRTILE3643 && wall[j].picnum < RRTILE3643 + 3) if (wall[wal].picnum >= RRTILE3643 && wall[wal].picnum < RRTILE3643 + 3)
{ {
deletesprite(i); deletesprite(proj);
} }
if (s->extra <= 0) if (s->extra <= 0)
{ {
s->x += sintable[(s->ang + 512) & 2047] >> 7; s->x += sintable[(s->ang + 512) & 2047] >> 7;
s->y += sintable[s->ang & 2047] >> 7; s->y += sintable[s->ang & 2047] >> 7;
if (!isRRRA() || (sprite[s->owner].picnum != CHEER && sprite[s->owner].picnum != CHEERSTAYPUT)) auto Owner = proj->GetOwner();
if (!isRRRA() || !Owner || (Owner->s.picnum != CHEER && Owner->s.picnum != CHEERSTAYPUT))
{ {
auto j = spawn(act, CIRCLESTUCK); auto j = spawn(proj, CIRCLESTUCK);
j->s.xrepeat = 8; j->s.xrepeat = 8;
j->s.yrepeat = 8; j->s.yrepeat = 8;
j->s.cstat = 16; j->s.cstat = 16;
j->s.ang = (j->s.ang + 512) & 2047; j->s.ang = (j->s.ang + 512) & 2047;
j->s.clipdist = mulscale7(s->xrepeat, tilesiz[s->picnum].x); j->s.clipdist = mulscale7(s->xrepeat, tilesiz[s->picnum].x);
} }
deletesprite(i); deletesprite(proj);
return true; return true;
} }
if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) if (wall[wal].overpicnum != MIRROR && wall[wal].picnum != MIRROR)
{ {
s->extra -= 20; s->extra -= 20;
s->yvel--; s->yvel--;
} }
int k = getangle( int k = getangle(
wall[wall[j].point2].x - wall[j].x, wall[wall[wal].point2].x - wall[wal].x,
wall[wall[j].point2].y - wall[j].y); wall[wall[wal].point2].y - wall[wal].y);
s->ang = ((k << 1) - s->ang) & 2047; s->ang = ((k << 1) - s->ang) & 2047;
return true; return true;
} }
@ -1310,23 +1307,23 @@ static bool weaponhitwall(int i, int j, const vec3_t& oldpos)
return false; return false;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// //
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool weaponhitsector(int i, const vec3_t& oldpos) bool weaponhitsector(DDukeActor *proj, const vec3_t& oldpos)
{ {
auto s = &sprite[i]; auto s = &proj->s;
setsprite(proj, oldpos);
setsprite(i, &oldpos); if (isRRRA() && proj->GetOwner() && proj->GetOwner()->s.picnum == MAMA)
if (isRRRA() && sprite[s->owner].picnum == MAMA)
{ {
guts_r(&hittype[i], RABBITJIBA, 2, myconnectindex); guts_r(proj, RABBITJIBA, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBB, 2, myconnectindex); guts_r(proj, RABBITJIBB, 2, myconnectindex);
guts_r(&hittype[i], RABBITJIBC, 2, myconnectindex); guts_r(proj, RABBITJIBC, 2, myconnectindex);
} }
if (s->zvel < 0) if (s->zvel < 0)
@ -1334,7 +1331,7 @@ bool weaponhitsector(int i, const vec3_t& oldpos)
if (sector[s->sectnum].ceilingstat & 1) if (sector[s->sectnum].ceilingstat & 1)
if (sector[s->sectnum].ceilingpal == 0) if (sector[s->sectnum].ceilingpal == 0)
{ {
deletesprite(i); deletesprite(proj);
return true; return true;
} }
@ -1343,8 +1340,8 @@ bool weaponhitsector(int i, const vec3_t& oldpos)
if (!isRRRA() && s->picnum == FREEZEBLAST) if (!isRRRA() && s->picnum == FREEZEBLAST)
{ {
bounce(&hittype[i]); bounce(proj);
ssp(i, CLIPMASK1); ssp(proj, CLIPMASK1);
s->extra >>= 1; s->extra >>= 1;
if (s->xrepeat > 8) if (s->xrepeat > 8)
s->xrepeat -= 2; s->xrepeat -= 2;
@ -1473,16 +1470,16 @@ static void weaponcommon_r(int i)
if ((j & kHitTypeMask) == kHitSprite) if ((j & kHitTypeMask) == kHitSprite)
{ {
j &= kHitIndexMask; j &= kHitIndexMask;
if (weaponhitsprite(i, j, oldpos)) return; if (weaponhitsprite(&hittype[i], &hittype[j], oldpos)) return;
} }
else if ((j & kHitTypeMask) == kHitWall) else if ((j & kHitTypeMask) == kHitWall)
{ {
j &= kHitIndexMask; j &= kHitIndexMask;
if (weaponhitwall(i, j, oldpos)) return; if (weaponhitwall(&hittype[i], j, oldpos)) return;
} }
else if ((j & 49152) == 16384) else if ((j & 49152) == 16384)
{ {
if (weaponhitsector(i, oldpos)) return; if (weaponhitsector(&hittype[i], oldpos)) return;
} }
if (s->picnum != SPIT) if (s->picnum != SPIT)