- RR shootweapon

This commit is contained in:
Christoph Oelckers 2020-10-24 07:01:01 +02:00
parent 51705e5a61
commit 1ab13688a7

View file

@ -210,13 +210,12 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa,
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
auto actor = &hittype[i];
auto s = &actor->s; auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int zvel; int zvel;
short hitsect, hitwall, l, k; short hitsect, hitwall;
int hitx, hity, hitz; int hitx, hity, hitz;
DDukeActor* hitsprt; DDukeActor* hitsprt;
@ -271,34 +270,31 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
} }
s->cstat &= ~257; s->cstat &= ~257;
hitscan(sx, sy, sz, sect, hitscan(sx, sy, sz, sect, sintable[(sa + 512) & 2047], sintable[sa & 2047],
sintable[(sa + 512) & 2047],
sintable[sa & 2047],
zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); zvel << 6, &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1);
if (isRRRA() && (((sector[hitsect].lotag == 160 && zvel > 0) || (sector[hitsect].lotag == 161 && zvel < 0)) if (isRRRA() && (((sector[hitsect].lotag == 160 && zvel > 0) || (sector[hitsect].lotag == 161 && zvel < 0))
&& hitsprt == nullptr && hitwall == -1)) && hitsprt == nullptr && hitwall == -1))
{ {
short ii; DukeSpriteIterator its;
for (ii = 0; ii < MAXSPRITES; ii++) while (auto effector = its.Next())
{ {
if (sprite[ii].sectnum == hitsect && sprite[ii].picnum == SECTOREFFECTOR // shouldn't this only check STAT_EFFECTOR?
&& sprite[ii].lotag == 7) if (effector->s.sectnum == hitsect && effector->s.picnum == SECTOREFFECTOR && effector->GetOwner()
&& effector->s.lotag == 7)
{ {
int nx, ny, nz; int nx, ny, nz;
nx = hitx + (sprite[sprite[ii].owner].x - sprite[ii].x); nx = hitx + (effector->GetOwner()->s.x - effector->s.x);
ny = hity + (sprite[sprite[ii].owner].y - sprite[ii].y); ny = hity + (effector->GetOwner()->s.y - effector->s.y);
if (sector[hitsect].lotag == 161) if (sector[hitsect].lotag == 161)
{ {
nz = sector[sprite[sprite[ii].owner].sectnum].floorz; nz = sector[effector->GetOwner()->s.sectnum].floorz;
} }
else else
{ {
nz = sector[sprite[sprite[ii].owner].sectnum].ceilingz; nz = sector[effector->GetOwner()->s.sectnum].ceilingz;
} }
hitscan(nx, ny, nz, sprite[sprite[ii].owner].sectnum, hitscan(nx, ny, nz, effector->GetOwner()->s.sectnum, sintable[(sa + 512) & 2047], sintable[sa & 2047], zvel << 6,
sintable[(sa + 512) & 2047],
sintable[sa & 2047], zvel << 6,
&hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1); &hitsect, &hitwall, &hitsprt, &hitx, &hity, &hitz, CLIPMASK1);
break; break;
} }
@ -317,11 +313,12 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
if ((krand() & 15) == 0 && sector[hitsect].lotag == 2) if ((krand() & 15) == 0 && sector[hitsect].lotag == 2)
tracers(hitx, hity, hitz, sx, sy, sz, 8 - (ud.multimode >> 1)); tracers(hitx, hity, hitz, sx, sy, sz, 8 - (ud.multimode >> 1));
DDukeActor* spark;
if (p >= 0) if (p >= 0)
{ {
k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, i, 4); spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 10, 10, sa, 0, 0, actor, 4);
sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress];
sprite[k].extra += (krand() % 6); spark->s.extra += (krand() % 6);
if (hitwall == -1 && hitsprt == nullptr) if (hitwall == -1 && hitsprt == nullptr)
{ {
@ -329,32 +326,32 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
{ {
if (sector[hitsect].ceilingstat & 1) if (sector[hitsect].ceilingstat & 1)
{ {
sprite[k].xrepeat = 0; spark->s.xrepeat = 0;
sprite[k].yrepeat = 0; spark->s.yrepeat = 0;
return; return;
} }
else else
fi.checkhitceiling(hitsect); fi.checkhitceiling(hitsect);
} }
if (sector[hitsect].lotag != 1) if (sector[hitsect].lotag != 1)
fi.spawn(k, SMALLSMOKE); spawn(spark, SMALLSMOKE);
} }
if (hitsprt) if (hitsprt)
{ {
if (hitsprt->s.picnum == 1930) if (hitsprt->s.picnum == 1930)
return; return;
fi.checkhitsprite(hitsprt->GetIndex(), k); fi.checkhitsprite(hitsprt->GetIndex(), spark->GetIndex());
if (hitsprt->s.picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1)) if (hitsprt->s.picnum == TILE_APLAYER && (ud.coop != 1 || ud.ffire == 1))
{ {
l = fi.spawn(k, JIBS6); auto l = spawn(spark, JIBS6);
sprite[k].xrepeat = sprite[k].yrepeat = 0; spark->s.xrepeat = spark->s.yrepeat = 0;
sprite[l].z += (4 << 8); l->s.z += (4 << 8);
sprite[l].xvel = 16; l->s.xvel = 16;
sprite[l].xrepeat = sprite[l].yrepeat = 24; l->s.xrepeat = l->s.yrepeat = 24;
sprite[l].ang += 64 - (krand() & 127); l->s.ang += 64 - (krand() & 127);
} }
else fi.spawn(k, SMALLSMOKE); else spawn(spark, SMALLSMOKE);
if (p >= 0 && ( if (p >= 0 && (
hitsprt->s.picnum == DIPSWITCH || hitsprt->s.picnum == DIPSWITCH ||
@ -373,7 +370,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
} }
else if (hitwall >= 0) else if (hitwall >= 0)
{ {
fi.spawn(k, SMALLSMOKE); spawn(spark, SMALLSMOKE);
if (fi.isadoorwall(wall[hitwall].picnum) == 1) if (fi.isadoorwall(wall[hitwall].picnum) == 1)
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
@ -405,24 +402,24 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
{ {
if (wall[hitwall].nextsector >= 0) if (wall[hitwall].nextsector >= 0)
{ {
SectIterator it(wall[hitwall].nextsector); DukeSectIterator it(wall[hitwall].nextsector);
while ((l = it.NextIndex()) >= 0) while (auto l = it.Next())
{ {
if (sprite[l].statnum == 3 && sprite[l].lotag == 13) if (l->s.statnum == 3 && l->s.lotag == 13)
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
} }
} }
StatIterator it(STAT_MISC); DukeStatIterator it(STAT_MISC);
while ((l = it.NextIndex()) >= 0) while (auto l = it.Next())
{ {
if (sprite[l].picnum == BULLETHOLE) if (l->s.picnum == BULLETHOLE)
if (dist(&sprite[l], &sprite[k]) < (12 + (krand() & 7))) if (dist(l, spark) < (12 + (krand() & 7)))
goto SKIPBULLETHOLE; goto SKIPBULLETHOLE;
} }
l = fi.spawn(k, BULLETHOLE); auto l = spawn(spark, BULLETHOLE);
sprite[l].xvel = -1; l->s.xvel = -1;
sprite[l].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, l->s.ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x,
wall[hitwall].y - wall[wall[hitwall].point2].y) + 512; wall[hitwall].y - wall[wall[hitwall].point2].y) + 512;
ssp(l, CLIPMASK0); ssp(l, CLIPMASK0);
} }
@ -434,29 +431,29 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
if (hitz >= (sector[wall[hitwall].nextsector].floorz)) if (hitz >= (sector[wall[hitwall].nextsector].floorz))
hitwall = wall[hitwall].nextwall; hitwall = wall[hitwall].nextwall;
fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); fi.checkhitwall(spark->GetIndex(), hitwall, hitx, hity, hitz, SHOTSPARK1);
} }
} }
else else
{ {
k = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, i, 4); spark = EGS(hitsect, hitx, hity, hitz, SHOTSPARK1, -15, 24, 24, sa, 0, 0, actor, 4);
sprite[k].extra = ScriptCode[actorinfo[atwith].scriptaddress]; spark->s.extra = ScriptCode[actorinfo[atwith].scriptaddress];
if (hitsprt) if (hitsprt)
{ {
fi.checkhitsprite(hitsprt->GetIndex(), k); fi.checkhitsprite(hitsprt->GetIndex(), spark->GetIndex());
if (hitsprt->s.picnum != TILE_APLAYER) if (hitsprt->s.picnum != TILE_APLAYER)
fi.spawn(k, SMALLSMOKE); spawn(spark, SMALLSMOKE);
else sprite[k].xrepeat = sprite[k].yrepeat = 0; else spark->s.xrepeat = spark->s.yrepeat = 0;
} }
else if (hitwall >= 0) else if (hitwall >= 0)
fi.checkhitwall(k, hitwall, hitx, hity, hitz, SHOTSPARK1); fi.checkhitwall(spark->GetIndex(), hitwall, hitx, hity, hitz, SHOTSPARK1);
} }
if ((krand() & 255) < 10) if ((krand() & 255) < 10)
{ {
vec3_t v{ hitx, hity, hitz }; vec3_t v{ hitx, hity, hitz };
S_PlaySound3D(PISTOL_RICOCHET, k, &v); S_PlaySound3D(PISTOL_RICOCHET, spark, &v);
} }
} }
@ -903,7 +900,7 @@ void shoot_r(int i, int atwith)
case SHOTSPARK1: case SHOTSPARK1:
case SHOTGUN: case SHOTGUN:
case CHAINGUN: case CHAINGUN:
shootweapon(i, p, sx, sy, sz, sa, atwith); shootweapon(actor, p, sx, sy, sz, sa, atwith);
return; return;
case TRIPBOMBSPRITE: case TRIPBOMBSPRITE: