- split shoot_d into smaller, easier to manage chunks.

1100 lines for a single function is too much.
This commit is contained in:
Christoph Oelckers 2020-10-21 00:17:09 +02:00
parent 699c32ff4a
commit 4d1e229734

View file

@ -86,66 +86,11 @@ void incur_damage_d(struct player_struct* p)
//
//---------------------------------------------------------------------------
void shoot_d(int i, int atwith)
static void shootfireball(int i, int p, int sx, int sy, int sz, int sa)
{
short sect, hitsect, hitspr, hitwall, l, sa, p, j, k, scount;
int sx, sy, sz, vel, zvel, hitx, hity, hitz, x, oldzvel, dal;
unsigned char sizx, sizy;
spritetype* const s = &sprite[i];
if (s->picnum == TILE_APLAYER)
{
p = s->yvel;
}
else
{
p = -1;
}
int vel, zvel;
SetGameVarID(g_iAtWithVarID, 0, p, atwith);
SetGameVarID(g_iReturnVarID, 0, p, i);
OnEvent(EVENT_SHOOT, i, p, -1);
if (GetGameVarID(g_iReturnVarID, p, i) != 0)
{
return;
}
sect = s->sectnum;
zvel = 0;
if (s->picnum == TILE_APLAYER)
{
sx = ps[p].posx;
sy = ps[p].posy;
sz = ps[p].posz + ps[p].pyoff + (4 << 8);
sa = ps[p].angle.ang.asbuild();
ps[p].crack_time = CRACK_TIME;
}
else
{
sa = s->ang;
sx = s->x;
sy = s->y;
sz = s->z - ((s->yrepeat * tilesiz[s->picnum].y) << 1) + (4 << 8);
if (s->picnum != ROTATEGUN)
{
sz -= (7 << 8);
if (badguy(s) && s->picnum != COMMANDER)
{
sx += (sintable[(sa + 1024 + 96) & 2047] >> 7);
sy += (sintable[(sa + 512 + 96) & 2047] >> 7);
}
}
}
if (isWorldTour())
{ // Twentieth Anniversary World Tour
switch (atwith)
{
case FIREBALL:
{
if (s->extra >= 0)
s->shade = -96;
@ -161,7 +106,7 @@ void shoot_d(int i, int atwith)
{
sa += 16 - (krand() & 31);
int scratch;
j = findplayer(s, &scratch);
int j = findplayer(s, &scratch);
zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s);
}
else
@ -172,15 +117,15 @@ void shoot_d(int i, int atwith)
sz += (3 << 8);
}
sizx = 18;
sizy = 18;
int sizx = 18;
int sizy = 18;
if (p >= 0)
{
sizx = 7;
sizy = 7;
}
j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, (short)4);
int j = EGS(s->sectnum, sx, sy, sz, FIREBALL, -127, sizx, sizy, sa, vel, zvel, i, (short)4);
auto spr = &sprite[j];
spr->extra += (krand() & 7);
if (sprite[i].picnum == BOSS5 || p >= 0)
@ -191,17 +136,28 @@ void shoot_d(int i, int atwith)
spr->yvel = p;
spr->cstat = 128;
spr->clipdist = 4;
return;
}
case FLAMETHROWERFLAME:
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void shootflamethrowerflame(int i, int p, int sx, int sy, int sz, int sa)
{
spritetype* const s = &sprite[i];
int vel, zvel;
if (s->extra >= 0)
s->shade = -96;
vel = 400;
k = -1;
int k = -1;
if (p < 0)
{
j = findplayer(s, &x);
int x;
int j = findplayer(s, &x);
sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy);
if (sprite[i].picnum == BOSS5)
@ -212,7 +168,7 @@ void shoot_d(int i, int atwith)
else if (sprite[i].picnum == BOSS3)
sz -= 8192;
l = ldist(&sprite[ps[j].i], s);
int l = ldist(&sprite[ps[j].i], s);
if (l != 0)
zvel = ((ps[j].oposz - sz) * vel) / l;
@ -235,7 +191,7 @@ void shoot_d(int i, int atwith)
if (k == -1)
{
k = fi.spawn(i, atwith);
k = fi.spawn(i, FLAMETHROWERFLAME);
sprite[k].xvel = (short)vel;
sprite[k].zvel = (short)zvel;
}
@ -243,7 +199,7 @@ void shoot_d(int i, int atwith)
sprite[k].x = sx + sintable[(sa + 630) & 0x7FF] / 448;
sprite[k].y = sy + sintable[(sa + 112) & 0x7FF] / 448;
sprite[k].z = sz - 256;
sprite[k].sectnum = sect;
sprite[k].sectnum = s->sectnum;
sprite[k].cstat = 0x80;
sprite[k].ang = sa;
sprite[k].xrepeat = 2;
@ -262,68 +218,43 @@ void shoot_d(int i, int atwith)
sprite[k].yrepeat = 10;
}
}
return;
case FIREFLY: // BOSS5 shot
k = fi.spawn(i, atwith);
sprite[k].sectnum = sect;
sprite[k].x = sx;
sprite[k].y = sy;
sprite[k].z = sz;
sprite[k].ang = sa;
sprite[k].xvel = 500;
sprite[k].zvel = 0;
return;
}
}
switch (atwith)
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void shootbloodsplat(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{
case BLOODSPLAT1:
case BLOODSPLAT2:
case BLOODSPLAT3:
case BLOODSPLAT4:
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int zvel;
short hitsect, hitspr, hitwall, k;
int hitx, hity, hitz;
if (p >= 0)
sa += 64 - (krand() & 127);
else sa += 1024 + 64 - (krand() & 127);
zvel = 1024 - (krand() & 2047);
case KNEE:
if (atwith == KNEE)
{
if (p >= 0)
{
zvel = -ps[p].horizon.sum().asq16() >> 11;
sz += (6 << 8);
sa += 15;
}
else
{
j = ps[findplayer(s, &x)].i;
zvel = ((sprite[j].z - sz) << 8) / (x + 1);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
}
// writestring(sx,sy,sz,sect,sintable[(sa+512)&2047],sintable[sa&2047],zvel<<6);
hitscan(sx, sy, sz, sect,
sintable[(sa + 512) & 2047],
sintable[sa & 2047], zvel << 6,
&hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1);
if (atwith == BLOODSPLAT1 ||
atwith == BLOODSPLAT2 ||
atwith == BLOODSPLAT3 ||
atwith == BLOODSPLAT4)
{
if (FindDistance2D(sx - hitx, sy - hity) < 1024)
if (hitwall >= 0 && wall[hitwall].overpicnum != BIGFORCE)
if ((wall[hitwall].nextsector >= 0 && hitsect >= 0 &&
// oh my...
if (FindDistance2D(sx - hitx, sy - hity) < 1024 &&
(hitwall >= 0 && wall[hitwall].overpicnum != BIGFORCE) &&
((wall[hitwall].nextsector >= 0 && hitsect >= 0 &&
sector[wall[hitwall].nextsector].lotag == 0 &&
sector[hitsect].lotag == 0 &&
sector[wall[hitwall].nextsector].lotag == 0 &&
(sector[hitsect].floorz - sector[wall[hitwall].nextsector].floorz) > (16 << 8)) ||
(wall[hitwall].nextsector == -1 && sector[hitsect].lotag == 0))
(wall[hitwall].nextsector == -1 && sector[hitsect].lotag == 0)))
{
if ((wall[hitwall].cstat & 16) == 0)
{
if (wall[hitwall].nextsector >= 0)
@ -344,8 +275,7 @@ void shoot_d(int i, int atwith)
{
k = fi.spawn(i, atwith);
sprite[k].xvel = -12;
sprite[k].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x,
wall[hitwall].y - wall[wall[hitwall].point2].y) + 512;
sprite[k].ang = getangle(wall[hitwall].x - wall[wall[hitwall].point2].x, wall[hitwall].y - wall[wall[hitwall].point2].y) + 512;
sprite[k].x = hitx;
sprite[k].y = hity;
sprite[k].z = hitz;
@ -356,10 +286,44 @@ void shoot_d(int i, int atwith)
sprite[k].pal = 6;
}
}
return;
}
}
if (hitsect < 0) break;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void shootknee(int i, int p, int sx, int sy, int sz, int sa)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int zvel;
short hitsect, hitspr, hitwall, j, k;
int hitx, hity, hitz;
if (p >= 0)
{
zvel = -ps[p].horizon.sum().asq16() >> 11;
sz += (6 << 8);
sa += 15;
}
else
{
int x;
j = ps[findplayer(s, &x)].i;
zvel = ((sprite[j].z - sz) << 8) / (x + 1);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
hitscan(sx, sy, sz, sect,
sintable[(sa + 512) & 2047],
sintable[sa & 2047], zvel << 6,
&hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1);
if (hitsect < 0) return;
if ((abs(sx - hitx) + abs(sy - hity)) < 1024)
{
@ -392,7 +356,7 @@ void shoot_d(int i, int atwith)
if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2)
{
fi.checkhitwall(j, hitwall, hitx, hity, hitz, atwith);
fi.checkhitwall(j, hitwall, hitx, hity, hitz, KNEE);
if (p >= 0) fi.checkhitswitch(p, hitwall, 0);
}
}
@ -409,12 +373,21 @@ void shoot_d(int i, int atwith)
}
}
}
break;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
case SHOTSPARK1:
case SHOTGUN:
case CHAINGUN:
static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int zvel;
short hitsect, hitspr, hitwall, l, j, k;
int hitx, hity, hitz;
if (s->extra >= 0) s->shade = -96;
@ -430,7 +403,7 @@ void shoot_d(int i, int atwith)
if (j >= 0)
{
dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8);
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8);
switch (sprite[j].picnum)
{
case GREENSLIME:
@ -478,6 +451,7 @@ void shoot_d(int i, int atwith)
}
else
{
int x;
j = findplayer(s, &x);
sz -= (4 << 8);
zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s));
@ -641,12 +615,20 @@ void shoot_d(int i, int atwith)
vec3_t v{ hitx, hity, hitz };
S_PlaySound3D(PISTOL_RICOCHET, k, &v);
}
}
return;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
case FIRELASER:
case SPIT:
case COOLEXPLOSION1:
static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int vel, zvel;
short l, j, scount;
if (s->extra >= 0) s->shade = -96;
@ -673,7 +655,7 @@ void shoot_d(int i, int atwith)
if (j >= 0)
{
dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8);
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
}
@ -682,13 +664,15 @@ void shoot_d(int i, int atwith)
}
else
{
int x;
j = findplayer(s, &x);
// sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy);
sa += 16 - (krand() & 31);
zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s);
}
oldzvel = zvel;
int oldzvel = zvel;
int sizx, sizy;
if (atwith == SPIT) { sizx = 18; sizy = 18, sz -= (10 << 8); }
else
@ -742,12 +726,20 @@ void shoot_d(int i, int atwith)
scount--;
}
}
return;
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
case FREEZEBLAST:
sz += (3 << 8);
case RPG:
static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int vel, zvel;
short l, j, scount;
if (s->extra >= 0) s->shade = -96;
@ -761,7 +753,7 @@ void shoot_d(int i, int atwith)
j = aim(s, 48);
if (j >= 0)
{
dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8);
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]);
if (sprite[j].picnum != RECON)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy);
@ -773,6 +765,7 @@ void shoot_d(int i, int atwith)
}
else
{
int x;
j = findplayer(s, &x);
sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy);
if (s->picnum == BOSS3)
@ -906,9 +899,21 @@ void shoot_d(int i, int atwith)
else
sprite[j].clipdist = 40;
break;
}
case HANDHOLDINGLASER:
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
static void shootlaser(int i, int p, int sx, int sy, int sz, int sa)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int zvel;
short hitsect, hitspr, hitwall, j, k;
int hitx, hity, hitz;
if (p >= 0)
zvel = -ps[p].horizon.sum().asq16() >> 11;
@ -920,7 +925,7 @@ void shoot_d(int i, int atwith)
zvel << 6, &hitsect, &hitwall, &hitspr, &hitx, &hity, &hitz, CLIPMASK1);
j = 0;
if (hitspr >= 0) break;
if (hitspr >= 0) return;
if (hitwall >= 0 && hitsect >= 0)
if (((hitx - sx) * (hitx - sx) + (hity - sy) * (hity - sy)) < (290 * 290))
@ -960,38 +965,29 @@ void shoot_d(int i, int atwith)
if (p >= 0)
ps[p].ammo_amount[TRIPBOMB_WEAPON]--;
}
return;
}
case BOUNCEMINE:
case MORTER:
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
if (s->extra >= 0) s->shade = -96;
j = ps[findplayer(s, &x)].i;
x = ldist(&sprite[j], s);
zvel = -x >> 1;
if (zvel < -4096)
zvel = -2048;
vel = x >> 4;
EGS(sect,
sx + (sintable[(512 + sa + 512) & 2047] >> 8),
sy + (sintable[(sa + 512) & 2047] >> 8),
sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, i, 1);
break;
case GROWSPARK:
static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa)
{
spritetype* const s = &sprite[i];
int sect = s->sectnum;
int zvel;
short hitsect, hitspr, hitwall, j, k;
int hitx, hity, hitz;
if (p >= 0)
{
j = aim(s, AUTO_AIM_ANGLE);
if (j >= 0)
{
dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8);
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8);
switch (sprite[j].picnum)
{
case GREENSLIME:
@ -1020,6 +1016,7 @@ void shoot_d(int i, int atwith)
}
else
{
int x;
j = findplayer(s, &x);
sz -= (4 << 8);
zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s));
@ -1053,27 +1050,152 @@ void shoot_d(int i, int atwith)
else if (hitspr >= 0) fi.checkhitsprite(hitspr, j);
else if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2)
{
/* if(wall[hitwall].overpicnum == MIRROR && k == 0)
fi.checkhitwall(j, hitwall, hitx, hity, hitz, GROWSPARK);
}
}
//---------------------------------------------------------------------------
//
//
//
//---------------------------------------------------------------------------
void shoot_d(int i, int atwith)
{
l = getangle(
wall[wall[hitwall].point2].x-wall[hitwall].x,
wall[wall[hitwall].point2].y-wall[hitwall].y);
sx = hitx;
sy = hity;
sz = hitz;
sect = hitsect;
sa = ((l<<1) - sa)&2047;
sx += sintable[(sa+512)&2047]>>12;
sy += sintable[sa&2047]>>12;
k++;
goto RESHOOTGROW;
short sect, l, j, k;
int sx, sy, sz, sa, p, vel, zvel, x, dal;
spritetype* const s = &sprite[i];
if (s->picnum == TILE_APLAYER)
{
p = s->yvel;
}
else */
fi.checkhitwall(j, hitwall, hitx, hity, hitz, atwith);
else
{
p = -1;
}
SetGameVarID(g_iAtWithVarID, 0, p, atwith);
SetGameVarID(g_iReturnVarID, 0, p, i);
OnEvent(EVENT_SHOOT, i, p, -1);
if (GetGameVarID(g_iReturnVarID, p, i) != 0)
{
return;
}
sect = s->sectnum;
zvel = 0;
if (s->picnum == TILE_APLAYER)
{
sx = ps[p].posx;
sy = ps[p].posy;
sz = ps[p].posz + ps[p].pyoff + (4 << 8);
sa = ps[p].angle.ang.asbuild();
ps[p].crack_time = CRACK_TIME;
}
else
{
sa = s->ang;
sx = s->x;
sy = s->y;
sz = s->z - ((s->yrepeat * tilesiz[s->picnum].y) << 1) + (4 << 8);
if (s->picnum != ROTATEGUN)
{
sz -= (7 << 8);
if (badguy(s) && s->picnum != COMMANDER)
{
sx += (sintable[(sa + 1024 + 96) & 2047] >> 7);
sy += (sintable[(sa + 512 + 96) & 2047] >> 7);
}
}
}
if (isWorldTour())
{ // Twentieth Anniversary World Tour
switch (atwith)
{
case FIREBALL:
shootfireball(i, p, sx, sy, sz, sa);
return;
case FLAMETHROWERFLAME:
shootflamethrowerflame(i, p, sx, sy, sz, sa);
return;
case FIREFLY: // BOSS5 shot
k = fi.spawn(i, atwith);
sprite[k].sectnum = sect;
sprite[k].x = sx;
sprite[k].y = sy;
sprite[k].z = sz;
sprite[k].ang = sa;
sprite[k].xvel = 500;
sprite[k].zvel = 0;
return;
}
}
switch (atwith)
{
case BLOODSPLAT1:
case BLOODSPLAT2:
case BLOODSPLAT3:
case BLOODSPLAT4:
shootbloodsplat(i, p, sx, sy, sz, sa, atwith);
break;
case KNEE:
shootknee(i, p, sx, sy, sz, sa);
break;
case SHOTSPARK1:
case SHOTGUN:
case CHAINGUN:
shootweapon(i, p, sx, sy, sz, sa, atwith);
return;
case FIRELASER:
case SPIT:
case COOLEXPLOSION1:
shootstuff(i, p, sx, sy, sz, sa, atwith);
return;
case FREEZEBLAST:
sz += (3 << 8);
case RPG:
shootrpg(i, p, sx, sy, sz, sa, atwith);
break;
case HANDHOLDINGLASER:
shootlaser(i, p, sx, sy, sz, sa);
return;
case BOUNCEMINE:
case MORTER:
if (s->extra >= 0) s->shade = -96;
j = ps[findplayer(s, &x)].i;
x = ldist(&sprite[j], s);
zvel = -x >> 1;
if (zvel < -4096)
zvel = -2048;
vel = x >> 4;
EGS(sect,
sx + (sintable[(512 + sa + 512) & 2047] >> 8),
sy + (sintable[(sa + 512) & 2047] >> 8),
sz + (6 << 8), atwith, -64, 32, 32, sa, vel, zvel, i, 1);
break;
case GROWSPARK:
shootgrowspark(i, p, sx, sy, sz, sa);
break;
case SHRINKER: