From 2b79b29fef2cf491b9c555d3681e13c4397ffc7b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 18 Oct 2020 08:38:29 +0200 Subject: [PATCH] - further splitting of moveweapons_d. Progress with this but still not enough yet to break it down into manageable parts. --- source/games/duke/src/actors_d.cpp | 653 +++++++++++++++-------------- 1 file changed, 333 insertions(+), 320 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index f2e0d9aaf..ab458d9af 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1663,6 +1663,328 @@ bool movefireball(int i) return false; } + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +bool weaponcommon_d(int i) +{ + auto s = &sprite[i]; + + if (s->picnum == COOLEXPLOSION1) + if (!S_CheckSoundPlaying(i, WIERDSHOT_FLY)) + S_PlayActorSound(WIERDSHOT_FLY, i); + + int p = -1; + int k, ll; + + if (s->picnum == RPG && sector[s->sectnum].lotag == 2) + { + k = s->xvel >> 1; + ll = s->zvel >> 1; + } + else + { + k = s->xvel; + ll = s->zvel; + } + + int dax = s->x; + int day = s->y; + int daz = s->z; + + getglobalz(i); + unsigned qq = CLIPMASK1; + + switch (s->picnum) + { + case RPG: + if (hittype[i].picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) + { + int j = fi.spawn(i, SMALLSMOKE); + sprite[j].z += (1 << 8); + } + break; + + case FIREBALL: + if (movefireball(i)) return; + break; + } + + int j = fi.movesprite(i, + (k * (sintable[(s->ang + 512) & 2047])) >> 14, + (k * (sintable[s->ang & 2047])) >> 14, ll, qq); + + if (s->picnum == RPG && s->yvel >= 0) + if (FindDistance2D(s->x - sprite[s->yvel].x, s->y - sprite[s->yvel].y) < 256) + j = 49152 | s->yvel; + + if (s->sectnum < 0) + { + deletesprite(i); + return; + } + + if ((j & 49152) != 49152 && s->picnum != FREEZEBLAST) + { + if (s->z < hittype[i].ceilingz) + { + j = 16384 | (s->sectnum); + s->zvel = -1; + } + else + if ((s->z > hittype[i].floorz && sector[s->sectnum].lotag != 1) || + (s->z > hittype[i].floorz + (16 << 8) && sector[s->sectnum].lotag == 1)) + { + j = 16384 | (s->sectnum); + if (sector[s->sectnum].lotag != 1) + s->zvel = 1; + } + } + + if (s->picnum == FIRELASER) + { + for (k = -3; k < 2; k++) + { + int x = EGS(s->sectnum, + s->x + ((k * sintable[(s->ang + 512) & 2047]) >> 9), + s->y + ((k * sintable[s->ang & 2047]) >> 9), + s->z + ((k * ksgn(s->zvel)) * abs(s->zvel / 24)), FIRELASER, -40 + (k << 2), + s->xrepeat, s->yrepeat, 0, 0, 0, s->owner, 5); + + sprite[x].cstat = 128; + sprite[x].pal = s->pal; + } + } + else if (s->picnum == SPIT) if (s->zvel < 6144) + s->zvel += gc - 112; + + if (j != 0) + { + if (s->picnum == COOLEXPLOSION1) + { + if ((j & 49152) == 49152 && sprite[j & (MAXSPRITES - 1)].picnum != APLAYER) + { + return; + } + s->xvel = 0; + s->zvel = 0; + } + + bool fireball = (isWorldTour() && s->picnum == FIREBALL && sprite[s->owner].picnum != FIREBALL); + + if ((j & 49152) == 49152) + { + j &= (MAXSPRITES - 1); + + if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) + if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER) + { + j = fi.spawn(i, TRANSPORTERSTAR); + sprite[j].pal = 1; + sprite[j].xrepeat = 32; + sprite[j].yrepeat = 32; + + deletesprite(i); + return; + } + + if (!isWorldTour() || s->picnum != FIREBALL || fireball) + fi.checkhitsprite(j, i); + + if (sprite[j].picnum == APLAYER) + { + p = sprite[j].yvel; + + if (ud.multimode >= 2 && fireball && sprite[s->owner].picnum == APLAYER) + { + ps[p].numloogs = -1 - sprite[i].yvel; + } + + S_PlayActorSound(PISTOL_BODYHIT, j); + + if (s->picnum == SPIT) + { + ps[p].horizon.addadjustment(32); + ps[p].sync.actions |= SB_CENTERVIEW; + + if (ps[p].loogcnt == 0) + { + if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) + S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); + + j = 3 + (krand() & 3); + ps[p].numloogs = j; + ps[p].loogcnt = 24 * 4; + for (int x = 0; x < j; x++) + { + ps[p].loogiex[x] = krand() % 320; + ps[p].loogiey[x] = krand() % 200; + } + } + } + } + } + else if ((j & 49152) == 32768) + { + j &= (MAXWALLS - 1); + + if (s->picnum != RPG && s->picnum != FREEZEBLAST && s->picnum != SPIT && + (!isWorldTour() || s->picnum != FIREBALL) && + (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) + { + k = getangle( + wall[wall[j].point2].x - wall[j].x, + wall[wall[j].point2].y - wall[j].y); + s->ang = ((k << 1) - s->ang) & 2047; + s->owner = i; + fi.spawn(i, TRANSPORTERSTAR); + return; + } + else + { + setsprite(i, dax, day, daz); + fi.checkhitwall(i, j, s->x, s->y, s->z, s->picnum); + + if (s->picnum == FREEZEBLAST) + { + if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) + { + s->extra >>= 1; + s->yvel--; + } + + k = getangle( + wall[wall[j].point2].x - wall[j].x, + wall[wall[j].point2].y - wall[j].y); + s->ang = ((k << 1) - s->ang) & 2047; + return; + } + } + } + else if ((j & 49152) == 16384) + { + setsprite(i, dax, day, daz); + + if (s->zvel < 0) + { + if (sector[s->sectnum].ceilingstat & 1) + if (sector[s->sectnum].ceilingpal == 0) + { + deletesprite(i); + return; + } + + fi.checkhitceiling(s->sectnum); + } + else if (fireball) + { + j = fi.spawn(i, LAVAPOOL); + sprite[j].owner = sprite[i].owner; + sprite[j].yvel = sprite[i].yvel; + hittype[j].owner = sprite[i].owner; + deletesprite(i); + return; + } + + if (s->picnum == FREEZEBLAST) + { + bounce(i); + ssp(i, qq); + s->extra >>= 1; + if (s->xrepeat > 8) + s->xrepeat -= 2; + if (s->yrepeat > 8) + s->yrepeat -= 2; + s->yvel--; + return; + } + + + } + + if (s->picnum != SPIT) + { + if (s->picnum == RPG) + { + k = fi.spawn(i, EXPLOSION2); + sprite[k].x = dax; + sprite[k].y = day; + sprite[k].z = daz; + + if (s->xrepeat < 10) + { + sprite[k].xrepeat = 6; + sprite[k].yrepeat = 6; + } + else if ((j & 49152) == 16384) + { + if (s->zvel > 0) + fi.spawn(i, EXPLOSION2BOT); + else { sprite[k].cstat |= 8; sprite[k].z += (48 << 8); } + } + } + else if (s->picnum == SHRINKSPARK) + { + fi.spawn(i, SHRINKEREXPLOSION); + S_PlayActorSound(SHRINKER_HIT, i); + fi.hitradius(i, shrinkerblastradius, 0, 0, 0, 0); + } + else if (s->picnum != COOLEXPLOSION1 && s->picnum != FREEZEBLAST && s->picnum != FIRELASER && (!isWorldTour() || s->picnum != FIREBALL)) + { + k = fi.spawn(i, EXPLOSION2); + sprite[k].xrepeat = sprite[k].yrepeat = s->xrepeat >> 1; + if ((j & 49152) == 16384) + { + if (s->zvel < 0) + { + sprite[k].cstat |= 8; sprite[k].z += (72 << 8); + } + } + } + if (s->picnum == RPG) + { + S_PlayActorSound(RPG_EXPLODE, i); + + if (s->xrepeat >= 10) + { + int x = s->extra; + fi.hitradius(i, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); + } + else + { + int x = s->extra + (global_random & 3); + fi.hitradius(i, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); + } + } + if (fireball) + { + j = fi.spawn(i, EXPLOSION2); + sprite[j].xrepeat = sprite[j].yrepeat = (short)(s->xrepeat >> 1); + } + } + if (s->picnum != COOLEXPLOSION1) + { + deletesprite(i); + return; + } + } + if (s->picnum == COOLEXPLOSION1) + { + s->shade++; + if (s->shade >= 40) + { + deletesprite(i); + return; + } + } + else if (s->picnum == RPG && sector[s->sectnum].lotag == 2 && s->xrepeat >= 10 && rnd(140)) + fi.spawn(i, WATERBUBBLE); + +} //--------------------------------------------------------------------------- // // @@ -1671,16 +1993,11 @@ bool movefireball(int i) void moveweapons_d(void) { - int j, k, p; - int dax, day, daz, x, ll; - unsigned int qq; - spritetype* s; - StatIterator it(STAT_PROJECTILE); int i; while ((i = it.NextIndex()) >= 0) { - s = &sprite[i]; + auto s = &sprite[i]; if (s->sectnum < 0) { @@ -1705,336 +2022,32 @@ void moveweapons_d(void) case FREEZEBLAST: if (s->yvel < 1 || s->extra < 2 || (s->xvel|s->zvel) == 0) { - j = fi.spawn(i,TRANSPORTERSTAR); + int j = fi.spawn(i,TRANSPORTERSTAR); sprite[j].pal = 1; sprite[j].xrepeat = 32; sprite[j].yrepeat = 32; deletesprite(i); continue; } + case FIREBALL: + // Twentieth Anniversary World Tour + if (!isWorldTour()) break; case SHRINKSPARK: case RPG: case FIRELASER: case SPIT: case COOLEXPLOSION1: - case FIREBALL: - // Twentieth Anniversary World Tour - if (s->picnum == FIREBALL && !isWorldTour()) - break; - - if (s->picnum == COOLEXPLOSION1) - if (!S_CheckSoundPlaying(i, WIERDSHOT_FLY)) - S_PlayActorSound(WIERDSHOT_FLY, i); - - p = -1; - - if (s->picnum == RPG && sector[s->sectnum].lotag == 2) - { - k = s->xvel>>1; - ll = s->zvel>>1; - } - else - { - k = s->xvel; - ll = s->zvel; - } - - dax = s->x; day = s->y; daz = s->z; - - getglobalz(i); - qq = CLIPMASK1; - - switch(s->picnum) - { - case RPG: - if (hittype[i].picnum != BOSS2 && s->xrepeat >= 10 && sector[s->sectnum].lotag != 2) - { - j = fi.spawn(i,SMALLSMOKE); - sprite[j].z += (1 << 8); - } - break; - - case FIREBALL: - if (movefireball(i)) continue; - break; - } - - j = fi.movesprite(i, - (k*(sintable[(s->ang+512)&2047]))>>14, - (k*(sintable[s->ang&2047]))>>14,ll,qq); - - if (s->picnum == RPG && s->yvel >= 0) - if (FindDistance2D(s->x-sprite[s->yvel].x,s->y-sprite[s->yvel].y) < 256) - j = 49152|s->yvel; - - if (s->sectnum < 0) - { - deletesprite(i); - continue; - } - - if ((j&49152) != 49152 && s->picnum != FREEZEBLAST) - { - if (s->z < hittype[i].ceilingz) - { - j = 16384|(s->sectnum); - s->zvel = -1; - } - else - if ((s->z > hittype[i].floorz && sector[s->sectnum].lotag != 1) || - (s->z > hittype[i].floorz+(16 << 8) && sector[s->sectnum].lotag == 1)) - { - j = 16384|(s->sectnum); - if (sector[s->sectnum].lotag != 1) - s->zvel = 1; - } - } - - if (s->picnum == FIRELASER) - { - for(k=-3;k<2;k++) - { - x = EGS(s->sectnum, - s->x+((k*sintable[(s->ang+512)&2047])>>9), - s->y+((k*sintable[s->ang&2047])>>9), - s->z+((k*ksgn(s->zvel))*abs(s->zvel/24)),FIRELASER,-40+(k << 2), - s->xrepeat,s->yrepeat,0,0,0,s->owner,5); - - sprite[x].cstat = 128; - sprite[x].pal = s->pal; - } - } - else if (s->picnum == SPIT) if (s->zvel < 6144) - s->zvel += gc-112; - - if (j != 0) - { - if (s->picnum == COOLEXPLOSION1) - { - if ((j&49152) == 49152 && sprite[j&(MAXSPRITES-1)].picnum != APLAYER) - { - continue; - } - s->xvel = 0; - s->zvel = 0; - } - - bool fireball = (isWorldTour() && s->picnum == FIREBALL && sprite[s->owner].picnum != FIREBALL); - - if ((j&49152) == 49152) - { - j &= (MAXSPRITES-1); - - if (s->picnum == FREEZEBLAST && sprite[j].pal == 1) - if (badguy(&sprite[j]) || sprite[j].picnum == APLAYER) - { - j = fi.spawn(i,TRANSPORTERSTAR); - sprite[j].pal = 1; - sprite[j].xrepeat = 32; - sprite[j].yrepeat = 32; - - deletesprite(i); - continue; - } - - if (!isWorldTour() || s->picnum != FIREBALL || fireball) - fi.checkhitsprite(j,i); - - if (sprite[j].picnum == APLAYER) - { - p = sprite[j].yvel; - - if (ud.multimode >= 2 && fireball && sprite[s->owner].picnum == APLAYER) - { - ps[p].numloogs = -1 - sprite[i].yvel; - } - - S_PlayActorSound(PISTOL_BODYHIT,j); - - if (s->picnum == SPIT) - { - ps[p].horizon.addadjustment(32); - ps[p].sync.actions |= SB_CENTERVIEW; - - if (ps[p].loogcnt == 0) - { - if (!S_CheckActorSoundPlaying(ps[p].i, DUKE_LONGTERM_PAIN)) - S_PlayActorSound(DUKE_LONGTERM_PAIN, ps[p].i); - - j = 3+(krand()&3); - ps[p].numloogs = j; - ps[p].loogcnt = 24*4; - for(x=0;x < j;x++) - { - ps[p].loogiex[x] = krand()%320; - ps[p].loogiey[x] = krand()%200; - } - } - } - } - } - else if ((j&49152) == 32768) - { - j &= (MAXWALLS-1); - - if (s->picnum != RPG && s->picnum != FREEZEBLAST && s->picnum != SPIT && - (!isWorldTour() || s->picnum != FIREBALL) && - (wall[j].overpicnum == MIRROR || wall[j].picnum == MIRROR)) - { - k = getangle( - wall[wall[j].point2].x-wall[j].x, - wall[wall[j].point2].y-wall[j].y); - s->ang = ((k << 1) - s->ang)&2047; - s->owner = i; - fi.spawn(i,TRANSPORTERSTAR); - continue; - } - else - { - setsprite(i,dax,day,daz); - fi.checkhitwall(i,j,s->x,s->y,s->z,s->picnum); - - if (s->picnum == FREEZEBLAST) - { - if (wall[j].overpicnum != MIRROR && wall[j].picnum != MIRROR) - { - s->extra >>= 1; - s->yvel--; - } - - k = getangle( - wall[wall[j].point2].x-wall[j].x, - wall[wall[j].point2].y-wall[j].y); - s->ang = ((k << 1) - s->ang)&2047; - continue; - } - } - } - else if ((j&49152) == 16384) - { - setsprite(i,dax,day,daz); - - if (s->zvel < 0) - { - if (sector[s->sectnum].ceilingstat&1) - if (sector[s->sectnum].ceilingpal == 0) - { - deletesprite(i); - continue; - } - - fi.checkhitceiling(s->sectnum); - } - else if (fireball) - { - j = fi.spawn(i, LAVAPOOL); - sprite[j].owner = sprite[i].owner; - sprite[j].yvel = sprite[i].yvel; - hittype[j].owner = sprite[i].owner; - deletesprite(i); - continue; - } - - if (s->picnum == FREEZEBLAST) - { - bounce(i); - ssp(i,qq); - s->extra >>= 1; - if (s->xrepeat > 8) - s->xrepeat -= 2; - if (s->yrepeat > 8) - s->yrepeat -= 2; - s->yvel--; - continue; - } - - - } - - if (s->picnum != SPIT) - { - if (s->picnum == RPG) - { - k = fi.spawn(i,EXPLOSION2); - sprite[k].x = dax; - sprite[k].y = day; - sprite[k].z = daz; - - if (s->xrepeat < 10) - { - sprite[k].xrepeat = 6; - sprite[k].yrepeat = 6; - } - else if ((j&49152) == 16384) - { - if (s->zvel > 0) - fi.spawn(i,EXPLOSION2BOT); - else { sprite[k].cstat |= 8; sprite[k].z += (48 << 8); } - } - } - else if (s->picnum == SHRINKSPARK) - { - fi.spawn(i,SHRINKEREXPLOSION); - S_PlayActorSound(SHRINKER_HIT,i); - fi.hitradius(i,shrinkerblastradius,0,0,0,0); - } - else if (s->picnum != COOLEXPLOSION1 && s->picnum != FREEZEBLAST && s->picnum != FIRELASER && (!isWorldTour() || s->picnum != FIREBALL)) - { - k = fi.spawn(i,EXPLOSION2); - sprite[k].xrepeat = sprite[k].yrepeat = s->xrepeat>>1; - if ((j&49152) == 16384) - { - if (s->zvel < 0) - { - sprite[k].cstat |= 8; sprite[k].z += (72 << 8); - } - } - } - if (s->picnum == RPG) - { - S_PlayActorSound(RPG_EXPLODE,i); - - if (s->xrepeat >= 10) - { - x = s->extra; - fi.hitradius(i, rpgblastradius, x >> 2, x >> 1, x - (x >> 2), x); - } - else - { - x = s->extra+(global_random&3); - fi.hitradius(i, (rpgblastradius >> 1), x >> 2, x >> 1, x - (x >> 2), x); - } - } - if (fireball) - { - j = fi.spawn(i, EXPLOSION2); - sprite[j].xrepeat = sprite[j].yrepeat = (short)(s->xrepeat >> 1); - } - } - if (s->picnum != COOLEXPLOSION1) - { - deletesprite(i); - continue; - } - } - if (s->picnum == COOLEXPLOSION1) - { - s->shade++; - if (s->shade >= 40) - { - deletesprite(i); - continue; - } - } - else if (s->picnum == RPG && sector[s->sectnum].lotag == 2 && s->xrepeat >= 10 && rnd(140)) - fi.spawn(i,WATERBUBBLE); + weaponcommon_d(i); break; case SHOTSPARK1: - p = findplayer(s,&x); - execute(i,p,x); + { + int x; + int p = findplayer(s, &x); + execute(i, p, x); break; } + } } }