From 178db4bb098ea3a45d1f492a945cc6ca451d218c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 26 Nov 2016 21:39:20 +0100 Subject: [PATCH] - scriptified the fighter's hammer. --- src/CMakeLists.txt | 1 - src/g_hexen/a_fighteraxe.cpp | 0 src/g_hexen/a_fighterhammer.cpp | 124 ------------------ src/g_hexen/a_hexenmisc.cpp | 1 - src/g_shared/a_weapons.cpp | 10 ++ wadsrc/static/zscript/hexen/fighterhammer.txt | 88 ++++++++++++- wadsrc/static/zscript/shared/inventory.txt | 8 ++ 7 files changed, 102 insertions(+), 130 deletions(-) delete mode 100644 src/g_hexen/a_fighteraxe.cpp delete mode 100644 src/g_hexen/a_fighterhammer.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 58a699477..c3e241900 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_fighterhammer.cpp g_hexen/a_fighterplayer.cpp g_hexen/a_fighterquietus.cpp g_hexen/a_flechette.cpp diff --git a/src/g_hexen/a_fighteraxe.cpp b/src/g_hexen/a_fighteraxe.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/g_hexen/a_fighterhammer.cpp b/src/g_hexen/a_fighterhammer.cpp deleted file mode 100644 index 84eca78b7..000000000 --- a/src/g_hexen/a_fighterhammer.cpp +++ /dev/null @@ -1,124 +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 "p_pspr.h" -#include "gstrings.h" -#include "a_hexenglobal.h" -#include "vm.h" -*/ - -const double HAMMER_RANGE = 1.5 * MELEERANGE; - -static FRandom pr_hammeratk ("FHammerAtk"); - -//============================================================================ -// -// A_FHammerAttack -// -//============================================================================ - -DEFINE_ACTION_FUNCTION(AActor, A_FHammerAttack) -{ - PARAM_ACTION_PROLOGUE(AActor); - - DAngle angle; - int damage; - DAngle slope; - int i; - player_t *player; - FTranslatedLineTarget t; - PClassActor *hammertime; - - if (NULL == (player = self->player)) - { - return 0; - } - AActor *pmo=player->mo; - - damage = 60+(pr_hammeratk()&63); - hammertime = PClass::FindActor("HammerPuff"); - for (i = 0; i < 16; i++) - { - for (int j = 1; j >= -1; j -= 2) - { - angle = pmo->Angles.Yaw + j*i*(45. / 32); - slope = P_AimLineAttack(pmo, angle, HAMMER_RANGE, &t, 0., ALF_CHECK3D); - if (t.linetarget != NULL) - { - P_LineAttack(pmo, angle, HAMMER_RANGE, slope, damage, NAME_Melee, hammertime, true, &t); - if (t.linetarget != NULL) - { - AdjustPlayerAngle(pmo, &t); - if (t.linetarget->flags3 & MF3_ISMONSTER || t.linetarget->player) - { - t.linetarget->Thrust(t.angleFromSource, 10); - } - pmo->weaponspecial = false; // Don't throw a hammer - goto hammerdone; - } - } - } - } - // didn't find any targets in meleerange, so set to throw out a hammer - angle = pmo->Angles.Yaw; - slope = P_AimLineAttack (pmo, angle, HAMMER_RANGE, NULL, 0., ALF_CHECK3D); - if (P_LineAttack (pmo, angle, HAMMER_RANGE, slope, damage, NAME_Melee, hammertime, true) != NULL) - { - pmo->weaponspecial = false; - } - else - { - pmo->weaponspecial = true; - } -hammerdone: - // Don't spawn a hammer if the player doesn't have enough mana - if (player->ReadyWeapon == NULL || - !player->ReadyWeapon->CheckAmmo (player->ReadyWeapon->bAltFire ? - AWeapon::AltFire : AWeapon::PrimaryFire, false, true)) - { - pmo->weaponspecial = false; - } - return 0; -} - -//============================================================================ -// -// A_FHammerThrow -// -//============================================================================ - -DEFINE_ACTION_FUNCTION(AActor, A_FHammerThrow) -{ - PARAM_ACTION_PROLOGUE(AActor); - - AActor *mo; - player_t *player; - - if (NULL == (player = self->player)) - { - return 0; - } - - if (!player->mo->weaponspecial) - { - return 0; - } - AWeapon *weapon = player->ReadyWeapon; - if (weapon != NULL) - { - if (!weapon->DepleteAmmo (weapon->bAltFire, false)) - return 0; - } - mo = P_SpawnPlayerMissile (player->mo, PClass::FindActor("HammerMissile")); - if (mo) - { - mo->special1 = 0; - } - return 0; -} diff --git a/src/g_hexen/a_hexenmisc.cpp b/src/g_hexen/a_hexenmisc.cpp index f2b8d8866..f098006c7 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_fighterhammer.cpp" #include "a_fighterplayer.cpp" #include "a_fighterquietus.cpp" #include "a_flechette.cpp" diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index e9d931520..2d2c3eb01 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -664,6 +664,16 @@ bool AWeapon::CheckAmmo (int fireMode, bool autoSwitch, bool requireAmmo, int am return false; } +DEFINE_ACTION_FUNCTION(AWeapon, CheckAmmo) +{ + PARAM_SELF_PROLOGUE(AWeapon); + PARAM_INT(mode); + PARAM_BOOL(autoswitch); + PARAM_BOOL_DEF(require); + PARAM_INT_DEF(ammocnt); + ACTION_RETURN_BOOL(self->CheckAmmo(mode, autoswitch, require, ammocnt)); +} + //=========================================================================== // // AWeapon :: DepleteAmmo diff --git a/wadsrc/static/zscript/hexen/fighterhammer.txt b/wadsrc/static/zscript/hexen/fighterhammer.txt index f415cbb72..655e59379 100644 --- a/wadsrc/static/zscript/hexen/fighterhammer.txt +++ b/wadsrc/static/zscript/hexen/fighterhammer.txt @@ -3,6 +3,8 @@ class FWeapHammer : FighterWeapon { + const HAMMER_RANGE = 1.5 * MELEERANGE; + Default { +BLOODSPLATTER @@ -18,9 +20,6 @@ class FWeapHammer : FighterWeapon Tag "$TAG_FWEAPHAMMER"; } - action native void A_FHammerAttack(); - action native void A_FHammerThrow(); - States { Spawn: @@ -50,6 +49,87 @@ class FWeapHammer : FighterWeapon FHMR A 1; Goto Ready; } + + //============================================================================ + // + // A_FHammerAttack + // + //============================================================================ + + action void A_FHammerAttack() + { + FTranslatedLineTarget t; + + if (player == null) + { + return; + } + + int damage = 60+(random[HammerAtk]() & 63); + for (int i = 0; i < 16; i++) + { + for (int j = 1; j >= -1; j -= 2) + { + double ang = angle + j*i*(45. / 32); + double slope = AimLineAttack(ang, HAMMER_RANGE, t, 0., ALF_CHECK3D); + if (t.linetarget != null) + { + LineAttack(ang, HAMMER_RANGE, slope, damage, 'Melee', "HammerPuff", true, t); + if (t.linetarget != null) + { + AdjustPlayerAngle(t); + if (t.linetarget.bIsMonster || t.linetarget.player) + { + t.linetarget.Thrust(10, t.angleFromSource); + } + weaponspecial = false; // Don't throw a hammer + return; + } + } + } + } + // didn't find any targets in meleerange, so set to throw out a hammer + double slope = AimLineAttack (angle, HAMMER_RANGE, null, 0., ALF_CHECK3D); + weaponspecial = (LineAttack (angle, HAMMER_RANGE, slope, damage, 'Melee', "HammerPuff", true) == null); + + // Don't spawn a hammer if the player doesn't have enough mana + if (player.ReadyWeapon == null || + !player.ReadyWeapon.CheckAmmo (player.ReadyWeapon.bAltFire ? + Weapon.AltFire : Weapon.PrimaryFire, false, true)) + { + weaponspecial = false; + } + } + + //============================================================================ + // + // A_FHammerThrow + // + //============================================================================ + + action void A_FHammerThrow() + { + if (player == null) + { + return; + } + + if (!weaponspecial) + { + return; + } + Weapon weapon = player.ReadyWeapon; + if (weapon != null) + { + if (!weapon.DepleteAmmo (weapon.bAltFire, false)) + return; + } + Actor mo = SpawnPlayerMissile ("HammerMissile"); + if (mo) + { + mo.special1 = 0; + } + } } // Hammer Missile ----------------------------------------------------------- @@ -76,7 +156,7 @@ class HammerMissile : Actor FHFX CDEFGH 2 Bright; Loop; Death: - FHFX I 3 Bright A_SetTranslucent(1,1); + FHFX I 3 Bright A_SetRenderStyle(1, STYLE_Add); FHFX J 3 Bright; FHFX K 3 Bright A_Explode (128, 128, 0); FHFX LM 3 Bright; diff --git a/wadsrc/static/zscript/shared/inventory.txt b/wadsrc/static/zscript/shared/inventory.txt index f6c95f8bd..54a2b0ba9 100644 --- a/wadsrc/static/zscript/shared/inventory.txt +++ b/wadsrc/static/zscript/shared/inventory.txt @@ -529,6 +529,13 @@ class PuzzleItem : Inventory native class Weapon : StateProvider native { + enum EFireMode + { + PrimaryFire, + AltFire, + EitherFire + }; + native uint WeaponFlags; native class AmmoType1, AmmoType2; // Types of ammo used by this weapon native int AmmoGive1, AmmoGive2; // Amount of each ammo to get when picking up weapon @@ -572,6 +579,7 @@ class Weapon : StateProvider native Stop; } + native bool CheckAmmo(int fireMode, bool autoSwitch, bool requireAmmo = false, int ammocount = -1); native bool DepleteAmmo(bool altFire, bool checkEnough = true, int ammouse = -1); native virtual void EndPowerup();