From 6325185091d852aae5fecb35b20d4341bd0ebfaf Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 1 Feb 2022 03:51:01 -0800 Subject: [PATCH] Add P_SetPower; remove mobj hack from line 434 --- src/p_enemy.c | 8 +------- src/p_local.h | 1 + src/p_spec.c | 21 ++++++++------------- src/p_user.c | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/p_enemy.c b/src/p_enemy.c index 94c030d0f..2e99436da 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4179,7 +4179,6 @@ void A_CustomPower(mobj_t *actor) player_t *player; INT32 locvar1 = var1; INT32 locvar2 = var2; - boolean spawnshield = false; if (LUA_CallAction(A_CUSTOMPOWER, actor)) return; @@ -4198,15 +4197,10 @@ void A_CustomPower(mobj_t *actor) player = actor->target->player; - if (locvar1 == pw_shield && player->powers[pw_shield] != locvar2) - spawnshield = true; + P_SetPower(player, locvar1, locvar2); - player->powers[locvar1] = (UINT16)locvar2; if (actor->info->seesound) S_StartSound(player->mo, actor->info->seesound); - - if (spawnshield) //workaround for a bug - P_SpawnShieldOrb(player); } // Function: A_GiveWeapon diff --git a/src/p_local.h b/src/p_local.h index 4fa244a05..38c7f5d13 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -155,6 +155,7 @@ boolean P_PlayerHitFloor(player_t *player, boolean dorollstuff); void P_SetObjectMomZ(mobj_t *mo, fixed_t value, boolean relative); void P_RestoreMusic(player_t *player); +void P_SetPower(player_t *player, powertype_t power, UINT16 value); void P_SpawnShieldOrb(player_t *player); void P_SwitchShield(player_t *player, UINT16 shieldtype); mobj_t *P_SpawnGhostMobj(mobj_t *mobj); diff --git a/src/p_spec.c b/src/p_spec.c index ebabe6a79..459ee80a9 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2888,25 +2888,20 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) case 434: // Custom Power if (mo && mo->player) { - mobj_t *dummy = P_SpawnMobj(mo->x, mo->y, mo->z, MT_NULL); - - var1 = sides[line->sidenum[0]].toptexture; //(line->dx>>FRACBITS)-1; + powertype_t power = sides[line->sidenum[0]].toptexture; //(line->dx>>FRACBITS)-1; + UINT16 value; if (line->sidenum[1] != 0xffff && line->flags & ML_BLOCKMONSTERS) // read power from back sidedef - var2 = sides[line->sidenum[1]].toptexture; + value = sides[line->sidenum[1]].toptexture; else if (line->flags & ML_NOCLIMB) // 'Infinite' - var2 = UINT16_MAX; + value = UINT16_MAX; else - var2 = sides[line->sidenum[0]].textureoffset>>FRACBITS; + value = sides[line->sidenum[0]].textureoffset>>FRACBITS; - P_SetTarget(&dummy->target, mo); - A_CustomPower(dummy); + P_SetPower(mo->player, power, value); - if (bot) { - P_SetTarget(&dummy->target, bot); - A_CustomPower(dummy); - } - P_RemoveMobj(dummy); + if (bot) + P_SetPower(bot->player, power, value); } break; diff --git a/src/p_user.c b/src/p_user.c index e1998cdff..a81d90905 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2011,6 +2011,24 @@ void P_SwitchShield(player_t *player, UINT16 shieldtype) } } +// +// P_SetPower +// +// Sets a power and spawns a shield orb if required. +// +void P_SetPower(player_t *player, powertype_t power, UINT16 value) +{ + boolean spawnshield = false; + + if (power == pw_shield && player->powers[pw_shield] != value) + spawnshield = true; + + player->powers[power] = value; + + if (spawnshield) //workaround for a bug + P_SpawnShieldOrb(player); +} + // // P_SpawnGhostMobj //