From 27b2bafc876bf864cd0995de7a7ca4f7acbdf43d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 29 Dec 2022 10:56:10 +0100 Subject: [PATCH] - refactored shoot API to exclusively work with class pointers. --- source/games/duke/src/actors.cpp | 22 +++++++++++++++++++-- source/games/duke/src/actors_d.cpp | 10 +--------- source/games/duke/src/actors_r.cpp | 10 +--------- source/games/duke/src/classnames.h | 13 +++++++++++++ source/games/duke/src/funct.h | 3 ++- source/games/duke/src/gameexec.cpp | 2 +- source/games/duke/src/global.cpp | 2 +- source/games/duke/src/player.cpp | 4 ++-- source/games/duke/src/player_d.cpp | 26 ++++++++++++------------- source/games/duke/src/player_r.cpp | 30 ++++++++++++++--------------- source/games/duke/src/player_w.cpp | 6 +++--- source/games/duke/src/sectors_d.cpp | 8 ++++---- source/games/duke/src/sectors_r.cpp | 8 ++++---- source/games/duke/src/vmexports.cpp | 9 ++------- 14 files changed, 82 insertions(+), 71 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 6e55af1c869..51fe5776703 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -1060,7 +1060,7 @@ void handle_se14(DDukeActor* actor, bool checkstat, PClassActor* RPG) { auto saved_angle = actor->spr.Angles.Yaw; actor->spr.Angles.Yaw = (actor->spr.pos.XY() - ps[p].GetActor()->spr.pos.XY()).Angle(); - shoot(actor, -1, RPG); + shoot(actor, RPG); actor->spr.Angles.Yaw = saved_angle; } } @@ -1546,7 +1546,7 @@ void handle_se05(DDukeActor* actor) { auto ang = actor->spr.Angles.Yaw; actor->spr.Angles.Yaw = (actor->spr.pos.XY() - ps[p].GetActor()->spr.pos.XY()).Angle(); - shoot(actor, -1, isRR()? RedneckFirelaserClass : DukeFirelaserClass); + shoot(actor, isRR()? RedneckFirelaserClass : DukeFirelaserClass); actor->spr.Angles.Yaw = ang; } @@ -2809,6 +2809,24 @@ void handle_se35(DDukeActor *actor) // //--------------------------------------------------------------------------- +void handle_se36(DDukeActor* actor) +{ + if (actor->counter) + { + if (actor->counter == 1) + shoot(actor, GetSpawnType(actor->sector()->extra)); + else if (actor->counter == 26 * 5) + actor->counter = 0; + actor->counter++; + } +} + +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + void handle_se128(DDukeActor *actor) { auto wal = actor->temp_walls[0]; diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index dabfb540b1d..524f56a5b79 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1094,15 +1094,7 @@ void moveeffectors_d(void) //STATNUM 3 RANDOMSCRAP(act); break; case SE_36_PROJ_SHOOTER: - - if (act->counter) - { - if (act->counter == 1) - shoot(act, sc->extra, nullptr); - else if (act->counter == 26 * 5) - act->counter = 0; - act->counter++; - } + handle_se36(act); break; case SE_128_GLASS_BREAKING: diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index da042608e58..428af1ccf46 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1155,15 +1155,7 @@ void moveeffectors_r(void) //STATNUM 3 RANDOMSCRAP(act); break; case SE_36_PROJ_SHOOTER: - - if (act->counter) - { - if (act->counter == 1) - shoot(act, sc->extra, nullptr); - else if (act->counter == 26 * 5) - act->counter = 0; - act->counter++; - } + handle_se36(act); break; case SE_128_GLASS_BREAKING: diff --git a/source/games/duke/src/classnames.h b/source/games/duke/src/classnames.h index f44c4f8cb0f..ffb85c17b98 100644 --- a/source/games/duke/src/classnames.h +++ b/source/games/duke/src/classnames.h @@ -81,3 +81,16 @@ xx(RedneckUfo2) xx(RedneckUfo3) xx(RedneckUfo4) xx(RedneckUfoRRRA) +xx(DukeShotgunShot) +xx(DukeChaingunShot) +xx(DukeGrowSpark) +xx(DukeShrinker) +xx(DukeFreezeBlast) +xx(DukeHandHoldingLaser) +xx(RedneckShotgunShot) +xx(RedneckBuzzSaw) +xx(RedneckSawblade) +xx(RedneckBoatGrenade) +xx(RedneckBowlingBall) +xx(RedneckSlingbladeAttack) +xx(RedneckChickenArrow) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 47e2c13af6a..1692238a9d5 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -77,6 +77,7 @@ void handle_se29(DDukeActor* actor); void handle_se31(DDukeActor* a, bool choosedir); void handle_se32(DDukeActor* i); void handle_se35(DDukeActor* i); +void handle_se36(DDukeActor* i); void handle_se128(DDukeActor* i); void handle_se130(DDukeActor* i, int countmax); @@ -108,7 +109,7 @@ void playerAimUp(int snum, ESyncBits actions); void playerAimDown(int snum, ESyncBits actions); DDukeActor* aim(DDukeActor* s, int aang, bool force = true); DDukeActor* aim_(DDukeActor* actor, DDukeActor* weapon); -void shoot(DDukeActor* actor, int atwith, PClass* cls); +void shoot(DDukeActor* actor, PClass* cls); void checkweapons(player_struct* const p); int findotherplayer(int p, double* d); void quickkill(player_struct* p); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 25428bbf537..cadc44b0734 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1713,7 +1713,7 @@ int ParseState::parse(void) //if (g_ac->GetClass.TypeName == NAME_RedneckMinion && type == 3390 && g_ac->spr.pal == 8) typecls = RedneckFrogBallClass); //if (g_ac->GetClass.TypeName == NAME_RedneckMinion && type == 3390 && g_ac->spr.pal == 19)) typecls = RedneckShitBurnClass); } - shoot(g_ac, *insptr, nullptr); + shoot(g_ac, GetSpawnType(*insptr)); insptr++; break; } diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index b176b809472..796da2088e1 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -131,7 +131,7 @@ void RegisterClasses() auto cls = PClass::FindActor(classdef.first); if (cls == nullptr || !cls->IsDescendantOf(RUNTIME_CLASS(DDukeActor))) { - Printf(TEXTCOLOR_RED, "%s: Attempt to register unknown actor class '%s'\n", classdef.first); + Printf(TEXTCOLOR_RED "%s: Attempt to register unknown actor class\n", classdef.first); error++; } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 8f90f3620c8..cf34a30a92e 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -914,7 +914,7 @@ void playerAimDown(int snum, ESyncBits actions) // //--------------------------------------------------------------------------- -void shoot(DDukeActor* actor, int atwith, PClass* cls) +void shoot(DDukeActor* actor, PClass* cls) { int p; DVector3 spos; @@ -945,7 +945,7 @@ void shoot(DDukeActor* actor, int atwith, PClass* cls) } if (cls == nullptr) - cls = GetSpawnType(atwith); + return; CallShootThis(static_cast(GetDefaultByType(cls)), actor, p, spos, sang); } diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index b9a11969773..0e9f6838be6 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -434,7 +434,7 @@ int doincrements_d(player_struct* p) p->last_quick_kick = p->quick_kick + 1; p->quick_kick--; if (p->quick_kick == 8) - shoot(p->GetActor(), DTILE_KNEE, nullptr); + shoot(p->GetActor(), DukeMeleeAttackClass); } else if (p->last_quick_kick > 0) p->last_quick_kick--; @@ -1178,7 +1178,7 @@ static void operateweapon(int snum, ESyncBits actions) case PISTOL_WEAPON: // m-16 in NAM if (p->kickback_pic == 1) { - shoot(pact, DTILE_SHOTSPARK1, nullptr); + shoot(pact, DukeShotSparkClass); S_PlayActorSound(PISTOL_FIRE, pact); lastvisinc = PlayClock + 32; p->visibility = 0; @@ -1229,7 +1229,7 @@ static void operateweapon(int snum, ESyncBits actions) if (p->kickback_pic == 4) { for(int ii = 0; ii < 7; ii++) - shoot(pact, DTILE_SHOTGUN, nullptr); + shoot(pact, DukeShotgunShotClass); p->ammo_amount[SHOTGUN_WEAPON]--; S_PlayActorSound(SHOTGUN_FIRE, pact); @@ -1298,7 +1298,7 @@ static void operateweapon(int snum, ESyncBits actions) } S_PlayActorSound(CHAINGUN_FIRE, pact); - shoot(pact, DTILE_CHAINGUN, nullptr); + shoot(pact, DukeChaingunShotClass); lastvisinc = PlayClock + 32; p->visibility = 0; checkavailweapon(p); @@ -1342,7 +1342,7 @@ static void operateweapon(int snum, ESyncBits actions) else p->okickback_pic = p->kickback_pic = 0; p->ammo_amount[p->curr_weapon]--; - shoot(pact, DTILE_GROWSPARK, nullptr); + shoot(pact, DukeGrowSparkClass); //#ifdef NAM //#else @@ -1377,7 +1377,7 @@ static void operateweapon(int snum, ESyncBits actions) else p->okickback_pic = p->kickback_pic = 0; p->ammo_amount[SHRINKER_WEAPON]--; - shoot(pact, DTILE_SHRINKER, nullptr); + shoot(pact, DukeShrinkerClass); if (!isNam()) { @@ -1410,7 +1410,7 @@ static void operateweapon(int snum, ESyncBits actions) { p->visibility = 0; lastvisinc = PlayClock + 32; - shoot(pact, DTILE_RPG, nullptr); + shoot(pact, DukeRPGClass); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); } @@ -1420,7 +1420,7 @@ static void operateweapon(int snum, ESyncBits actions) { p->visibility = 0; lastvisinc = PlayClock + 32; - shoot(pact, DTILE_RPG, nullptr); + shoot(pact, DukeRPGClass); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); if (p->ammo_amount[DEVISTATOR_WEAPON] <= 0) p->okickback_pic = p->kickback_pic = 0; @@ -1440,7 +1440,7 @@ static void operateweapon(int snum, ESyncBits actions) p->visibility = 0; lastvisinc = PlayClock + 32; - shoot(pact, DTILE_FREEZEBLAST, nullptr); + shoot(pact, DukeFreezeBlastClass); checkavailweapon(p); } if (pact->spr.scale.X < 0.5) @@ -1468,7 +1468,7 @@ static void operateweapon(int snum, ESyncBits actions) if (p->cursector->lotag != 2) { p->ammo_amount[FLAMETHROWER_WEAPON]--; - shoot(pact, DTILE_FIREBALL, nullptr); + shoot(pact, DukeFireballClass); } checkavailweapon(p); } @@ -1490,7 +1490,7 @@ static void operateweapon(int snum, ESyncBits actions) p->GetActor()->restorez(); p->vel.Z = 0; if (p->kickback_pic == 3) - shoot(pact, DTILE_HANDHOLDINGLASER, nullptr); + shoot(pact, DukeHandHoldingLaserClass); } if (p->kickback_pic == 16) { @@ -1503,7 +1503,7 @@ static void operateweapon(int snum, ESyncBits actions) case KNEE_WEAPON: p->kickback_pic++; - if (p->kickback_pic == 7) shoot(pact, DTILE_KNEE, nullptr); + if (p->kickback_pic == 7) shoot(pact, DukeMeleeAttackClass); else if (p->kickback_pic == 14) { if (actions & SB_FIRE) @@ -1522,7 +1522,7 @@ static void operateweapon(int snum, ESyncBits actions) p->ammo_amount[RPG_WEAPON]--; lastvisinc = PlayClock + 32; p->visibility = 0; - shoot(pact, DTILE_RPG, nullptr); + shoot(pact, DukeRPGClass); checkavailweapon(p); } else if (p->kickback_pic == 20) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 84ad03322b5..8cf6b939a2e 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1788,7 +1788,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) case PISTOL_WEAPON: if (p->kickback_pic == 1) { - shoot(pact, RTILE_SHOTSPARK1, nullptr); + shoot(pact, DukeShotSparkClass); S_PlayActorSound(PISTOL_FIRE, pact); p->noise_radius = 512; madenoise(snum); @@ -1854,7 +1854,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) if (p->kickback_pic == 4) { for (int ii = 0; ii < 10; ii++) - shoot(pact, RTILE_SHOTGUN, nullptr); + shoot(pact, RedneckShotgunShotClass); p->ammo_amount[SHOTGUN_WEAPON]--; @@ -1872,7 +1872,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) if (p->shotgun_state[1]) { for (int ii = 0; ii < 10; ii++) - shoot(pact, RTILE_SHOTGUN, nullptr); + shoot(pact, RedneckShotgunShotClass); p->ammo_amount[SHOTGUN_WEAPON]--; @@ -1963,7 +1963,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) } S_PlayActorSound(CHAINGUN_FIRE, pact); - shoot(pact, RTILE_CHAINGUN, nullptr); + shoot(pact, DukeChaingunShotClass); p->noise_radius = 512; madenoise(snum); lastvisinc = PlayClock + 32; @@ -1995,7 +1995,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) if (p->kickback_pic > 3) { p->okickback_pic = p->kickback_pic = 0; - shoot(pact, RTILE_GROWSPARK, nullptr); + shoot(pact, RedneckBuzzSawClass); p->noise_radius = 64; madenoise(snum); checkavailweapon(p); @@ -2008,7 +2008,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) if (p->kickback_pic == 1) { p->ammo_amount[THROWSAW_WEAPON]--; - shoot(pact, RTILE_SAWBLADE, nullptr); + shoot(pact, RedneckSawbladeClass); checkavailweapon(p); } p->kickback_pic++; @@ -2023,7 +2023,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->visibility = 0; lastvisinc = PlayClock + 32; S_PlayActorSound(CHAINGUN_FIRE, pact); - shoot(pact, RTILE_SHOTSPARK1, nullptr); + shoot(pact, DukeShotSparkClass); p->noise_radius = 1024; madenoise(snum); p->ammo_amount[TIT_WEAPON]--; @@ -2050,7 +2050,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->visibility = 0; lastvisinc = PlayClock + 32; S_PlayActorSound(CHAINGUN_FIRE, pact); - shoot(pact, RTILE_CHAINGUN, nullptr); + shoot(pact, DukeChaingunShotClass); p->noise_radius = 1024; madenoise(snum); p->ammo_amount[MOTORCYCLE_WEAPON]--; @@ -2077,7 +2077,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { p->MotoSpeed -= 20; p->ammo_amount[BOAT_WEAPON]--; - shoot(pact, RTILE_BOATGRENADE, nullptr); + shoot(pact, RedneckBoatGrenadeClass); } p->kickback_pic++; if (p->kickback_pic > 20) @@ -2094,7 +2094,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) case ALIENBLASTER_WEAPON: p->kickback_pic++; if (p->kickback_pic >= 7 && p->kickback_pic <= 11) - shoot(pact, RTILE_FIRELASER, nullptr); + shoot(pact, RedneckFirelaserClass); if (p->kickback_pic == 5) { @@ -2152,7 +2152,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) { p->ammo_amount[BOWLING_WEAPON]--; S_PlayActorSound(354, pact); - shoot(pact, RTILE_BOWLINGBALL, nullptr); + shoot(pact, RedneckBowlingBallClass); p->noise_radius = 64; madenoise(snum); } @@ -2175,7 +2175,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(426, pact); if (p->kickback_pic == 12) { - shoot(pact, RTILE_KNEE, nullptr); + shoot(pact, DukeMeleeAttackClass); p->noise_radius = 64; madenoise(snum); } @@ -2193,7 +2193,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) S_PlayActorSound(252, pact); if (p->kickback_pic == 8) { - shoot(pact, RTILE_SLINGBLADE, nullptr); + shoot(pact, RedneckSlingbladeAttackClass); p->noise_radius = 64; madenoise(snum); } @@ -2213,7 +2213,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->ammo_amount[DYNAMITE_WEAPON]--; lastvisinc = PlayClock + 32; p->visibility = 0; - shoot(pact, RTILE_RPG, nullptr); + shoot(pact, RedneckDynamiteArrowClass); p->noise_radius = 2048; madenoise(snum); checkavailweapon(p); @@ -2231,7 +2231,7 @@ static void operateweapon(int snum, ESyncBits actions, sectortype* psectp) p->ammo_amount[CHICKEN_WEAPON]--; lastvisinc = PlayClock + 32; p->visibility = 0; - shoot(pact, RTILE_RPG2, nullptr); + shoot(pact, RedneckChickenArrowClass); p->noise_radius = 2048; madenoise(snum); checkavailweapon(p); diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index 6fe56dbce65..55041299a18 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -65,10 +65,10 @@ void DoFire(player_struct* p, int snum) SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); - shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum), nullptr); + shoot(p->GetActor(), GetSpawnType(aplWeaponShoots(p->curr_weapon, snum))); for (i = 1; i < aplWeaponShotsPerBurst(p->curr_weapon, snum); i++) { - shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum), nullptr); + shoot(p->GetActor(), GetSpawnType(aplWeaponShoots(p->curr_weapon, snum))); if (aplWeaponFlags(p->curr_weapon, snum) & WEAPON_FLAG_AMMOPERSHOT) { p->ammo_amount[p->curr_weapon]--; @@ -405,7 +405,7 @@ void operateweapon_ww(int snum, ESyncBits actions) } SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->GetActor(), snum); SetGameVarID(g_iWorksLikeVarID, aplWeaponWorksLike(p->curr_weapon, snum), p->GetActor(), snum); - shoot(p->GetActor(), aplWeaponShoots(p->curr_weapon, snum), nullptr); + shoot(p->GetActor(), GetSpawnType(aplWeaponShoots(p->curr_weapon, snum))); } } diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 43b5cd50055..4f395e4986d 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -194,10 +194,10 @@ void checkhitdefault_d(DDukeActor* targ, DDukeActor* proj) if (Owner && Owner->isPlayer() && targ->spr.picnum != DTILE_ROTATEGUN && targ->spr.picnum != DTILE_DRONE) if (ps[Owner->PlayerIndex()].curr_weapon == SHOTGUN_WEAPON) { - shoot(targ, -1, DukeBloodSplat3Class); - shoot(targ, -1, DukeBloodSplat1Class); - shoot(targ, -1, DukeBloodSplat2Class); - shoot(targ, -1, DukeBloodSplat4Class); + shoot(targ, DukeBloodSplat3Class); + shoot(targ, DukeBloodSplat1Class); + shoot(targ, DukeBloodSplat2Class); + shoot(targ, DukeBloodSplat4Class); } if (!(targ->flags2 & SFLAG2_NODAMAGEPUSH)) // RR does not have this. diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index 065195de3b0..36b327c9b47 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -192,10 +192,10 @@ void checkhitdefault_r(DDukeActor* targ, DDukeActor* proj) if (Owner && Owner->isPlayer() && targ->spr.picnum != RTILE_DRONE) if (ps[Owner->PlayerIndex()].curr_weapon == SHOTGUN_WEAPON) { - shoot(targ, -1, DukeBloodSplat3Class); - shoot(targ, -1, DukeBloodSplat1Class); - shoot(targ, -1, DukeBloodSplat2Class); - shoot(targ, -1, DukeBloodSplat4Class); + shoot(targ, DukeBloodSplat3Class); + shoot(targ, DukeBloodSplat1Class); + shoot(targ, DukeBloodSplat2Class); + shoot(targ, DukeBloodSplat4Class); } if (targ->spr.statnum == STAT_ZOMBIEACTOR) diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index a7dcf83646c..0e5ae95c2f4 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -680,16 +680,11 @@ DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, spriteheight, duke_sph) ACTION_RETURN_INT(duke_sph(self)); } -void DukeActor_shoot(DDukeActor* act, PClassActor* intname) -{ - shoot(act, -1, intname); -} - -DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, shoot, DukeActor_shoot) +DEFINE_ACTION_FUNCTION_NATIVE(DDukeActor, shoot, shoot) { PARAM_SELF_PROLOGUE(DDukeActor); PARAM_POINTER(type, PClassActor); - DukeActor_shoot(self, type); + shoot(self, type); return 0; }