gzdoom/src/g_hexen/a_fighteraxe.cpp

283 lines
5.8 KiB
C++
Raw Normal View History

2016-03-01 15:47:10 +00:00
/*
#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 "thingdef/thingdef.h"
*/
#define AXERANGE (2.25 * MELEERANGE)
2016-03-01 15:47:10 +00:00
static FRandom pr_axeatk ("FAxeAtk");
void A_FAxeCheckReady (AActor *actor);
void A_FAxeCheckUp (AActor *actor);
void A_FAxeCheckAtk (AActor *actor);
void A_FAxeCheckReadyG (AActor *actor);
void A_FAxeCheckUpG (AActor *actor);
void A_FAxeAttack (AActor *actor);
// The Fighter's Axe --------------------------------------------------------
class AFWeapAxe : public AFighterWeapon
{
DECLARE_CLASS (AFWeapAxe, AFighterWeapon)
public:
FState *GetUpState ();
FState *GetDownState ();
FState *GetReadyState ();
FState *GetAtkState (bool hold);
};
IMPLEMENT_CLASS (AFWeapAxe)
FState *AFWeapAxe::GetUpState ()
{
return Ammo1->Amount ? FindState ("SelectGlow") : Super::GetUpState();
}
FState *AFWeapAxe::GetDownState ()
{
return Ammo1->Amount ? FindState ("DeselectGlow") : Super::GetDownState();
}
FState *AFWeapAxe::GetReadyState ()
{
return Ammo1->Amount ? FindState ("ReadyGlow") : Super::GetReadyState();
}
FState *AFWeapAxe::GetAtkState (bool hold)
{
return Ammo1->Amount ? FindState ("FireGlow") : Super::GetAtkState(hold);
}
//============================================================================
//
// A_FAxeCheckReady
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeCheckReady)
{
PARAM_ACTION_PROLOGUE;
player_t *player;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
if (player->ReadyWeapon->Ammo1->Amount)
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("ReadyGlow"));
2016-03-01 15:47:10 +00:00
}
else
{
DoReadyWeapon(self);
}
return 0;
}
//============================================================================
//
// A_FAxeCheckReadyG
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeCheckReadyG)
{
PARAM_ACTION_PROLOGUE;
player_t *player;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
if (player->ReadyWeapon->Ammo1->Amount <= 0)
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("Ready"));
2016-03-01 15:47:10 +00:00
}
else
{
DoReadyWeapon(self);
}
return 0;
}
//============================================================================
//
// A_FAxeCheckUp
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeCheckUp)
{
PARAM_ACTION_PROLOGUE;
player_t *player;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
if (player->ReadyWeapon->Ammo1->Amount)
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("SelectGlow"));
2016-03-01 15:47:10 +00:00
}
else
{
CALL_ACTION(A_Raise, self);
}
return 0;
}
//============================================================================
//
// A_FAxeCheckUpG
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeCheckUpG)
{
PARAM_ACTION_PROLOGUE;
player_t *player;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
if (player->ReadyWeapon->Ammo1->Amount <= 0)
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("Select"));
2016-03-01 15:47:10 +00:00
}
else
{
CALL_ACTION(A_Raise, self);
}
return 0;
}
//============================================================================
//
// A_FAxeCheckAtk
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeCheckAtk)
{
PARAM_ACTION_PROLOGUE;
player_t *player;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
if (player->ReadyWeapon->Ammo1->Amount)
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("FireGlow"));
2016-03-01 15:47:10 +00:00
}
return 0;
}
//============================================================================
//
// A_FAxeAttack
//
//============================================================================
DEFINE_ACTION_FUNCTION(AActor, A_FAxeAttack)
{
PARAM_ACTION_PROLOGUE;
DAngle angle;
int power;
2016-03-01 15:47:10 +00:00
int damage;
DAngle slope;
2016-03-01 15:47:10 +00:00
int i;
int useMana;
player_t *player;
AWeapon *weapon;
PClassActor *pufftype;
FTranslatedLineTarget t;
if (nullptr == (player = self->player))
2016-03-01 15:47:10 +00:00
{
return 0;
}
AActor *pmo=player->mo;
damage = 40+(pr_axeatk()&15);
damage += pr_axeatk()&7;
power = 0;
weapon = player->ReadyWeapon;
if (player->ReadyWeapon->Ammo1->Amount > 0)
{
damage <<= 1;
power = 6;
2016-03-01 15:47:10 +00:00
pufftype = PClass::FindActor ("AxePuffGlow");
useMana = 1;
}
else
{
pufftype = PClass::FindActor ("AxePuff");
useMana = 0;
}
for (i = 0; i < 16; i++)
{
for (int j = 1; j >= -1; j -= 2)
{
angle = pmo->Angles.Yaw + j*i*(45. / 16);
2016-03-01 15:47:10 +00:00
slope = P_AimLineAttack(pmo, angle, AXERANGE, &t);
if (t.linetarget)
{
P_LineAttack(pmo, angle, AXERANGE, slope, damage, NAME_Melee, pufftype, true, &t);
if (t.linetarget != nullptr)
2016-03-01 15:47:10 +00:00
{
if (t.linetarget->flags3&MF3_ISMONSTER || t.linetarget->player)
{
t.linetarget->Thrust(t.angleFromSource, power);
2016-03-01 15:47:10 +00:00
}
AdjustPlayerAngle(pmo, &t);
useMana++;
goto axedone;
}
}
}
}
// didn't find any creatures, so try to strike any walls
pmo->weaponspecial = 0;
angle = pmo->Angles.Yaw;
2016-03-01 15:47:10 +00:00
slope = P_AimLineAttack (pmo, angle, MELEERANGE);
P_LineAttack (pmo, angle, MELEERANGE, slope, damage, NAME_Melee, pufftype, true);
axedone:
if (useMana == 2)
{
AWeapon *weapon = player->ReadyWeapon;
if (weapon != nullptr)
2016-03-01 15:47:10 +00:00
{
weapon->DepleteAmmo (weapon->bAltFire, false);
if ((weapon->Ammo1 == nullptr || weapon->Ammo1->Amount == 0) &&
2016-03-01 15:47:10 +00:00
(!(weapon->WeaponFlags & WIF_PRIMARY_USES_BOTH) ||
weapon->Ammo2 == nullptr || weapon->Ammo2->Amount == 0))
2016-03-01 15:47:10 +00:00
{
2016-06-16 12:24:00 +00:00
P_SetPsprite(player, PSP_WEAPON, player->ReadyWeapon->FindState ("Fire") + 5);
2016-03-01 15:47:10 +00:00
}
}
}
return 0;
}