From 80f233cd0b77d0ca264329d524298e32175ef99b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 26 Nov 2016 22:25:49 +0100 Subject: [PATCH] - scriptified the fighter's fist. --- src/CMakeLists.txt | 1 - src/g_hexen/a_fighterplayer.cpp | 142 -------------------- src/g_hexen/a_hexenglobal.h | 20 --- src/g_hexen/a_hexenmisc.cpp | 1 - src/g_hexen/a_magestaff.cpp | 8 ++ src/g_shared/a_weapons.cpp | 5 + wadsrc/static/zscript/actor.txt | 1 - wadsrc/static/zscript/hexen/baseweapons.txt | 39 +++++- wadsrc/static/zscript/hexen/fighterfist.txt | 81 ++++++++++- 9 files changed, 129 insertions(+), 169 deletions(-) delete mode 100644 src/g_hexen/a_fighterplayer.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c3e241900..a57ae9c3a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -855,7 +855,6 @@ set( NOT_COMPILED_SOURCE_FILES ${OTHER_SYSTEM_SOURCES} sc_man_scanner.h sc_man_scanner.re - g_hexen/a_fighterplayer.cpp g_hexen/a_fighterquietus.cpp g_hexen/a_flechette.cpp g_hexen/a_flies.cpp diff --git a/src/g_hexen/a_fighterplayer.cpp b/src/g_hexen/a_fighterplayer.cpp deleted file mode 100644 index 4f1d1fd3b..000000000 --- a/src/g_hexen/a_fighterplayer.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/* -#include "actor.h" -#include "gi.h" -#include "m_random.h" -#include "s_sound.h" -#include "d_player.h" -#include "a_action.h" -#include "p_local.h" -#include "a_action.h" -#include "a_hexenglobal.h" -#include "vm.h" -*/ - -IMPLEMENT_CLASS(AFighterWeapon, false, false) -IMPLEMENT_CLASS(AClericWeapon, false, false) -IMPLEMENT_CLASS(AMageWeapon, false, false) - -static FRandom pr_fpatk ("FPunchAttack"); - -//============================================================================ -// -// AdjustPlayerAngle -// -//============================================================================ - -#define MAX_ANGLE_ADJUST (5.) - -void AdjustPlayerAngle (AActor *pmo, FTranslatedLineTarget *t) -{ - // normally this will adjust relative to the actual direction to the target, - // but with arbitrary portals that cannot be calculated so using the actual - // attack angle is the only option. - DAngle atkangle = t->unlinked ? t->angleFromSource : pmo->AngleTo(t->linetarget); - DAngle difference = deltaangle(pmo->Angles.Yaw, atkangle); - if (fabs(difference) > MAX_ANGLE_ADJUST) - { - if (difference > 0) - { - pmo->Angles.Yaw += MAX_ANGLE_ADJUST; - } - else - { - pmo->Angles.Yaw -= MAX_ANGLE_ADJUST; - } - } - else - { - pmo->Angles.Yaw = t->angleFromSource; - } -} - -DEFINE_ACTION_FUNCTION(AActor, AdjustPlayerAngle) -{ - PARAM_SELF_PROLOGUE(AActor); - PARAM_POINTER(t, FTranslatedLineTarget); - AdjustPlayerAngle(self, t); - return 0; -} -//============================================================================ -// -// TryPunch -// -// Returns true if an actor was punched, false if not. -// -//============================================================================ - -static bool TryPunch(APlayerPawn *pmo, DAngle angle, int damage, int power) -{ - PClassActor *pufftype; - FTranslatedLineTarget t; - DAngle slope; - - slope = P_AimLineAttack (pmo, angle, 2*MELEERANGE, &t); - if (t.linetarget != NULL) - { - if (++pmo->weaponspecial >= 3) - { - damage <<= 1; - power *= 3; - pufftype = PClass::FindActor("HammerPuff"); - } - else - { - pufftype = PClass::FindActor("PunchPuff"); - } - P_LineAttack (pmo, angle, 2*MELEERANGE, slope, damage, NAME_Melee, pufftype, true, &t); - if (t.linetarget != NULL) - { - if (t.linetarget->player != NULL || - (t.linetarget->Mass != INT_MAX && (t.linetarget->flags3 & MF3_ISMONSTER))) - { - t.linetarget->Thrust(t.angleFromSource, power); - } - AdjustPlayerAngle (pmo, &t); - return true; - } - } - return false; -} - -//============================================================================ -// -// A_FPunchAttack -// -//============================================================================ - -DEFINE_ACTION_FUNCTION(AActor, A_FPunchAttack) -{ - PARAM_ACTION_PROLOGUE(AActor); - - int damage; - int i; - player_t *player; - - if (nullptr == (player = self->player)) - { - return 0; - } - APlayerPawn *pmo = player->mo; - - damage = 40+(pr_fpatk()&15); - for (i = 0; i < 16; i++) - { - if (TryPunch(pmo, pmo->Angles.Yaw + i*(45./16), damage, 2) || - TryPunch(pmo, pmo->Angles.Yaw - i*(45./16), damage, 2)) - { // hit something - if (pmo->weaponspecial >= 3) - { - pmo->weaponspecial = 0; - P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState("Fire2")); - S_Sound (pmo, CHAN_VOICE, "*fistgrunt", 1, ATTN_NORM); - } - return 0; - } - } - // didn't find any creatures, so try to strike any walls - pmo->weaponspecial = 0; - - DAngle slope = P_AimLineAttack (pmo, pmo->Angles.Yaw, MELEERANGE); - P_LineAttack (pmo, pmo->Angles.Yaw, MELEERANGE, slope, damage, NAME_Melee, PClass::FindActor("PunchPuff"), true); - return 0; -} diff --git a/src/g_hexen/a_hexenglobal.h b/src/g_hexen/a_hexenglobal.h index dc174b32a..277d1bff1 100644 --- a/src/g_hexen/a_hexenglobal.h +++ b/src/g_hexen/a_hexenglobal.h @@ -3,26 +3,6 @@ #include "d_player.h" -void AdjustPlayerAngle(AActor *pmo, FTranslatedLineTarget *t); - -class AFighterWeapon : public AWeapon -{ - DECLARE_CLASS (AFighterWeapon, AWeapon); -public: -}; - -class AClericWeapon : public AWeapon -{ - DECLARE_CLASS (AClericWeapon, AWeapon); -public: -}; - -class AMageWeapon : public AWeapon -{ - DECLARE_CLASS (AMageWeapon, AWeapon); -public: -}; - class AArtiPoisonBag : public AInventory { DECLARE_CLASS (AArtiPoisonBag, AInventory) diff --git a/src/g_hexen/a_hexenmisc.cpp b/src/g_hexen/a_hexenmisc.cpp index f098006c7..49c1369b3 100644 --- a/src/g_hexen/a_hexenmisc.cpp +++ b/src/g_hexen/a_hexenmisc.cpp @@ -24,7 +24,6 @@ #include "serializer.h" // Include all the Hexen stuff here to reduce compile time -#include "a_fighterplayer.cpp" #include "a_fighterquietus.cpp" #include "a_flechette.cpp" #include "a_flies.cpp" diff --git a/src/g_hexen/a_magestaff.cpp b/src/g_hexen/a_magestaff.cpp index 78d9edec0..27e9f5732 100644 --- a/src/g_hexen/a_magestaff.cpp +++ b/src/g_hexen/a_magestaff.cpp @@ -11,6 +11,14 @@ #include "doomstat.h" */ +class AMageWeapon : public AWeapon +{ + DECLARE_CLASS (AMageWeapon, AWeapon); +public: +}; + +IMPLEMENT_CLASS(AMageWeapon, false, false) + static FRandom pr_mstafftrack ("MStaffTrack"); static FRandom pr_bloodscourgedrop ("BloodScourgeDrop"); diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index 2d2c3eb01..b19896e91 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -838,6 +838,7 @@ FState *AWeapon::GetUpState () stack.Call(func, params, 1, &ret, 1, nullptr); return retval; } + return nullptr; } //=========================================================================== @@ -858,6 +859,7 @@ FState *AWeapon::GetDownState () stack.Call(func, params, 1, &ret, 1, nullptr); return retval; } + return nullptr; } //=========================================================================== @@ -878,6 +880,7 @@ FState *AWeapon::GetReadyState () stack.Call(func, params, 1, &ret, 1, nullptr); return retval; } + return nullptr; } //=========================================================================== @@ -898,6 +901,7 @@ FState *AWeapon::GetAtkState (bool hold) stack.Call(func, params, 2, &ret, 1, nullptr); return retval; } + return nullptr; } //=========================================================================== @@ -918,6 +922,7 @@ FState *AWeapon::GetAltAtkState (bool hold) stack.Call(func, params, 2, &ret, 1, nullptr); return retval; } + return nullptr; } //=========================================================================== diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 2b1ba6a5a..34d74760c 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -268,7 +268,6 @@ class Actor : Thinker native virtual native bool SpecialBlastHandling (Actor source, double strength); - native void AdjustPlayerAngle(FTranslatedLineTarget t); native static readonly GetDefaultByType(class cls); native static double GetDefaultSpeed(class type); native void RemoveFromHash(); diff --git a/wadsrc/static/zscript/hexen/baseweapons.txt b/wadsrc/static/zscript/hexen/baseweapons.txt index eb685a873..4c84ed780 100644 --- a/wadsrc/static/zscript/hexen/baseweapons.txt +++ b/wadsrc/static/zscript/hexen/baseweapons.txt @@ -1,7 +1,7 @@ // The Doom and Heretic players are not excluded from pickup in case // somebody wants to use these weapons with either of those games. -class FighterWeapon : Weapon native +class FighterWeapon : Weapon { Default { @@ -10,7 +10,7 @@ class FighterWeapon : Weapon native } } -class ClericWeapon : Weapon native +class ClericWeapon : Weapon { Default { @@ -27,3 +27,38 @@ class MageWeapon : Weapon native Inventory.ForbiddenTo "FighterPlayer", "ClericPlayer"; } } + +extend class Actor +{ + //============================================================================ + // + // AdjustPlayerAngle + // + //============================================================================ + + const MAX_ANGLE_ADJUST = (5.); + + void AdjustPlayerAngle(FTranslatedLineTarget t) + { + // normally this will adjust relative to the actual direction to the target, + // but with arbitrary portals that cannot be calculated so using the actual + // attack angle is the only option. + double atkangle = t.unlinked ? t.angleFromSource : AngleTo(t.linetarget); + double difference = deltaangle(Angle, atkangle); + if (abs(difference) > MAX_ANGLE_ADJUST) + { + if (difference > 0) + { + angle += MAX_ANGLE_ADJUST; + } + else + { + angle -= MAX_ANGLE_ADJUST; + } + } + else + { + angle = t.angleFromSource; + } + } +} \ No newline at end of file diff --git a/wadsrc/static/zscript/hexen/fighterfist.txt b/wadsrc/static/zscript/hexen/fighterfist.txt index 8428ebe7d..712055e6e 100644 --- a/wadsrc/static/zscript/hexen/fighterfist.txt +++ b/wadsrc/static/zscript/hexen/fighterfist.txt @@ -13,8 +13,6 @@ class FWeapFist : FighterWeapon Tag "$TAG_FWEAPFIST"; } - action native void A_FPunchAttack(); - States { Select: @@ -44,6 +42,85 @@ class FWeapFist : FighterWeapon FPCH E 10 Offset (0, 150); Goto Ready; } + + //============================================================================ + // + // TryPunch + // + // Returns true if an actor was punched, false if not. + // + //============================================================================ + + private action bool TryPunch(double angle, int damage, int power) + { + Class pufftype; + FTranslatedLineTarget t; + + double slope = AimLineAttack (angle, 2*MELEERANGE, t); + if (t.linetarget != null) + { + if (++weaponspecial >= 3) + { + damage <<= 1; + power *= 3; + pufftype = "HammerPuff"; + } + else + { + pufftype = "PunchPuff"; + } + LineAttack (angle, 2*MELEERANGE, slope, damage, 'Melee', pufftype, true, t); + if (t.linetarget != null) + { + // The mass threshold has been changed to CommanderKeen's value which has been used most often for 'unmovable' stuff. + if (t.linetarget.player != null || + (t.linetarget.Mass < 10000000 && (t.linetarget.bIsMonster))) + { + if (!t.linetarget.bDontThrust) + t.linetarget.Thrust(power, t.angleFromSource); + } + AdjustPlayerAngle(t); + return true; + } + } + return false; + } + + //============================================================================ + // + // A_FPunchAttack + // + //============================================================================ + + action void A_FPunchAttack() + { + if (player == null) + { + return; + } + + int damage = 40 + (random[FighterAtk]() & 15); + for (int i = 0; i < 16; i++) + { + if (TryPunch(angle + i*(45./16), damage, 2) || + TryPunch(angle - i*(45./16), damage, 2)) + { // hit something + if (weaponspecial >= 3) + { + weaponspecial = 0; + player.SetPsprite(PSP_WEAPON, player.ReadyWeapon.FindState("Fire2")); + A_PlaySound ("*fistgrunt", CHAN_VOICE); + } + return; + } + } + // didn't find any creatures, so try to strike any walls + weaponspecial = 0; + + double slope = AimLineAttack (angle, MELEERANGE); + LineAttack (angle, MELEERANGE, slope, damage, 'Melee', "PunchPuff", true); + } + } // Punch puff ---------------------------------------------------------------