Skip to content

Commit

Permalink
- refactored shoot API to exclusively work with class pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Mar 27, 2023
1 parent c685dce commit 27b2baf
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 71 deletions.
22 changes: 20 additions & 2 deletions source/games/duke/src/actors.cpp
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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];
Expand Down
10 changes: 1 addition & 9 deletions source/games/duke/src/actors_d.cpp
Expand Up @@ -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:
Expand Down
10 changes: 1 addition & 9 deletions source/games/duke/src/actors_r.cpp
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions source/games/duke/src/classnames.h
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion source/games/duke/src/funct.h
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/gameexec.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/games/duke/src/global.cpp
Expand Up @@ -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++;
}

Expand Down
4 changes: 2 additions & 2 deletions source/games/duke/src/player.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -945,7 +945,7 @@ void shoot(DDukeActor* actor, int atwith, PClass* cls)
}

if (cls == nullptr)
cls = GetSpawnType(atwith);
return;

CallShootThis(static_cast<DDukeActor*>(GetDefaultByType(cls)), actor, p, spos, sang);
}
Expand Down
26 changes: 13 additions & 13 deletions source/games/duke/src/player_d.cpp
Expand Up @@ -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--;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions source/games/duke/src/player_r.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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]--;

Expand All @@ -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]--;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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++;
Expand All @@ -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]--;
Expand All @@ -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]--;
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 27b2baf

Please sign in to comment.