From 1c4d48f5f2183317ed89e14c928c2b0f0f809e99 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 17 Apr 2022 08:53:52 +0200 Subject: [PATCH] - added some fudging so that the Dehacked parser can properly deal with ConsumeAmmo. This is a parameterized code pointer, so checking state functions for names won't work. Additionally, the handling was not correct for weapons with an ammo use other than 1. --- src/gamedata/d_dehacked.cpp | 22 +++++++++++++++++++--- src/gamedata/info.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 232dec896..99cba80b4 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -237,7 +237,6 @@ static AmmoPerAttack AmmoPerAttacks[] = { { NAME_A_FireBFG, -1}, // uses deh.BFGCells { NAME_A_FireOldBFG, 1}, { NAME_A_FireRailgun, 1}, - { NAME_MBF21_ConsumeAmmo, 1}, // MBF21 { NAME_None, 0} }; @@ -2588,12 +2587,16 @@ static int PatchCodePtrs (int dummy) { FString symname; - if ((Line2[0] == 'A' || Line2[0] == 'a') && Line2[1] == '_') symname = Line2; else symname.Format("A_%s", Line2); + // Hack alert: If A_ConsumeAmmo is used we need to handle the ammo use differently. + // Since this is a parameterized code pointer the AmmoPerAttack check cannot find it easily without some help. + if (symname.CompareNoCase("A_ConsumeAmmo") == 0) + state->StateFlags |= STF_CONSUMEAMMO; + // Let's consider as aliases some redundant MBF pointer bool ismbfcp = false; for (unsigned int i = 0; i < MBFCodePointers.Size(); i++) @@ -3571,8 +3574,8 @@ void FinishDehPatch () } else { + bool handled = false; weap->BoolVar(NAME_bDehAmmo) = true; - weap->IntVar(NAME_AmmoUse1) = 0; // to allow proper checks in CheckAmmo we have to find the first attack pointer in the Fire sequence // and set its default ammo use as the weapon's AmmoUse1. @@ -3587,6 +3590,13 @@ void FinishDehPatch () break; // State has already been checked so we reached a loop } StateVisited[state] = true; + if (state->StateFlags & STF_CONSUMEAMMO) + { + // If A_ConsumeAmmo is being used we have to rely on the existing AmmoUse1 value. + handled = true; + state->StateFlags &= ~STF_CONSUMEAMMO; + break; + } for(unsigned j = 0; AmmoPerAttacks[j].func != NAME_None; j++) { if (AmmoPerAttacks[j].ptr == nullptr) @@ -3601,12 +3611,18 @@ void FinishDehPatch () int use = AmmoPerAttacks[j].ammocount; if (use < 0) use = deh.BFGCells; weap->IntVar(NAME_AmmoUse1) = use; + handled = true; break; } } if (found) break; state = state->GetNextState(); } + if (!handled) + { + weap->IntVar(NAME_AmmoUse1) = 0; + + } } } WeaponNames.Clear(); diff --git a/src/gamedata/info.h b/src/gamedata/info.h index 0d2eadac4..d9e89037b 100644 --- a/src/gamedata/info.h +++ b/src/gamedata/info.h @@ -72,6 +72,7 @@ enum EStateFlags STF_SAMEFRAME = 16, // Ignore Frame (except when spawning actor) STF_CANRAISE = 32, // Allows a monster to be resurrected without waiting for an infinate frame STF_DEHACKED = 64, // Modified by Dehacked + STF_CONSUMEAMMO = 128, // Needed by the Dehacked parser. }; enum EStateType : int // this must ensure proper alignment.