mirror of
https://github.com/Gigaslav/HL2Overcharged.git
synced 2026-01-05 06:10:21 +03:00
184 lines
5.3 KiB
C++
184 lines
5.3 KiB
C++
#include "cbase.h"
|
|
#include "player.h"
|
|
#include "gamerules.h"
|
|
#include "grenade_flash.h"
|
|
#include "npcevent.h"
|
|
#include "engine/IEngineSound.h"
|
|
#include "items.h"
|
|
#include "in_buttons.h"
|
|
#include "NPCEvent.h"
|
|
#include "soundent.h"
|
|
#include "ieffects.h"
|
|
#include "vstdlib/random.h"
|
|
|
|
#include "weapon_flashbang.h"
|
|
// memdbgon must be the last include file in a .cpp file!!!
|
|
#include "tier0/memdbgon.h"
|
|
|
|
|
|
BEGIN_DATADESC( CWeaponFlashbang )
|
|
|
|
END_DATADESC()
|
|
|
|
acttable_t CWeaponFlashbang::m_acttable[] =
|
|
{
|
|
{ ACT_HL2MP_IDLE, ACT_HL2MP_IDLE_GRENADE, false }, // Light Kill : MP animstate for singleplayer
|
|
{ ACT_HL2MP_RUN, ACT_HL2MP_RUN_GRENADE, false },
|
|
{ ACT_HL2MP_IDLE_CROUCH, ACT_HL2MP_IDLE_CROUCH_GRENADE, false },
|
|
{ ACT_HL2MP_WALK_CROUCH, ACT_HL2MP_WALK_CROUCH_GRENADE, false },
|
|
{ ACT_HL2MP_GESTURE_RANGE_ATTACK, ACT_HL2MP_GESTURE_RANGE_ATTACK_GRENADE, false },
|
|
{ ACT_HL2MP_GESTURE_RELOAD, ACT_HL2MP_GESTURE_RELOAD_GRENADE, false },
|
|
{ ACT_HL2MP_JUMP, ACT_HL2MP_JUMP_SLAM, false },
|
|
|
|
{ ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_THROW, true },
|
|
|
|
{ ACT_IDLE_RELAXED, ACT_IDLE, false }, // L1ght 15 : Anims update
|
|
{ ACT_RUN_RELAXED, ACT_RUN, false },
|
|
{ ACT_WALK_RELAXED, ACT_WALK, false },
|
|
};
|
|
|
|
IMPLEMENT_ACTTABLE(CWeaponFlashbang);
|
|
|
|
IMPLEMENT_SERVERCLASS_ST(CWeaponFlashbang, DT_WeaponFlashbang)
|
|
END_SEND_TABLE()
|
|
|
|
LINK_ENTITY_TO_CLASS( weapon_flashbang, CWeaponFlashbang );
|
|
PRECACHE_WEAPON_REGISTER(weapon_flashbang);
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
// Input : *pPlayer -
|
|
//-----------------------------------------------------------------------------
|
|
void CWeaponFlashbang::ThrowGrenade( CBasePlayer *pPlayer )
|
|
{
|
|
Vector vecEye = pPlayer->EyePosition();
|
|
Vector vForward, vRight;
|
|
|
|
pPlayer->EyeVectors(&vForward, &vRight, NULL);
|
|
Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f;
|
|
CheckThrowPosition(pPlayer, vecEye, vecSrc);
|
|
// vForward[0] += 0.1f;
|
|
vForward[2] += 0.1f;
|
|
|
|
Vector vecThrow;
|
|
pPlayer->GetVelocity(&vecThrow, NULL);
|
|
vecThrow += vForward * 1200;
|
|
|
|
Flashgrenade_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(600,random->RandomInt(-1200,1200),0), pPlayer, GRENADE_TIMER );
|
|
|
|
m_bRedraw = true;
|
|
|
|
WeaponSound(SINGLE);
|
|
|
|
// Send the player 'attack' animation.
|
|
pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
m_iPrimaryAttacks++;
|
|
gamestats->Event_WeaponFired(pPlayer, true, GetClassname());
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
// Input : *pPlayer -
|
|
//-----------------------------------------------------------------------------
|
|
void CWeaponFlashbang::LobGrenade( CBasePlayer *pPlayer )
|
|
{
|
|
Vector vecEye = pPlayer->EyePosition();
|
|
Vector vForward, vRight;
|
|
|
|
pPlayer->EyeVectors(&vForward, &vRight, NULL);
|
|
Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f + Vector(0, 0, -8);
|
|
CheckThrowPosition(pPlayer, vecEye, vecSrc);
|
|
|
|
Vector vecThrow;
|
|
pPlayer->GetVelocity(&vecThrow, NULL);
|
|
vecThrow += vForward * 350 + Vector(0, 0, 50);
|
|
Flashgrenade_Create(vecSrc, vec3_angle, vecThrow, AngularImpulse(200, random->RandomInt(-600, 600), 0), pPlayer, GRENADE_TIMER);
|
|
|
|
WeaponSound(WPN_DOUBLE);
|
|
|
|
// Send the player 'attack' animation.
|
|
pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
m_bRedraw = true;
|
|
|
|
m_iPrimaryAttacks++;
|
|
gamestats->Event_WeaponFired(pPlayer, true, GetClassname());
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose:
|
|
// Input : *pPlayer -
|
|
//-----------------------------------------------------------------------------
|
|
void CWeaponFlashbang::RollGrenade( CBasePlayer *pPlayer )
|
|
{
|
|
// BUGBUG: Hardcoded grenade width of 4 - better not change the model :)
|
|
Vector vecSrc;
|
|
pPlayer->CollisionProp()->NormalizedToWorldSpace(Vector(0.5f, 0.5f, 0.0f), &vecSrc);
|
|
vecSrc.z += GRENADE_RADIUS;
|
|
|
|
Vector vecFacing = pPlayer->BodyDirection2D();
|
|
// no up/down direction
|
|
vecFacing.z = 0;
|
|
VectorNormalize(vecFacing);
|
|
trace_t tr;
|
|
UTIL_TraceLine(vecSrc, vecSrc - Vector(0, 0, 16), MASK_PLAYERSOLID, pPlayer, COLLISION_GROUP_NONE, &tr);
|
|
if (tr.fraction != 1.0)
|
|
{
|
|
// compute forward vec parallel to floor plane and roll grenade along that
|
|
Vector tangent;
|
|
CrossProduct(vecFacing, tr.plane.normal, tangent);
|
|
CrossProduct(tr.plane.normal, tangent, vecFacing);
|
|
}
|
|
vecSrc += (vecFacing * 18.0);
|
|
CheckThrowPosition(pPlayer, pPlayer->WorldSpaceCenter(), vecSrc);
|
|
|
|
Vector vecThrow;
|
|
pPlayer->GetVelocity(&vecThrow, NULL);
|
|
vecThrow += vecFacing * 700;
|
|
// put it on its side
|
|
QAngle orientation(0, pPlayer->GetLocalAngles().y, -90);
|
|
// roll it
|
|
AngularImpulse rotSpeed(0, 0, 720);
|
|
|
|
Flashgrenade_Create( vecSrc, orientation, vecThrow, rotSpeed, pPlayer, GRENADE_TIMER );
|
|
|
|
WeaponSound(SPECIAL1);
|
|
|
|
// Send the player 'attack' animation.
|
|
pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
m_bRedraw = true;
|
|
|
|
m_iPrimaryAttacks++;
|
|
gamestats->Event_WeaponFired(pPlayer, true, GetClassname());
|
|
}
|
|
|
|
void CWeaponFlashbang::GrenChangeVisible( void )
|
|
{
|
|
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
|
|
|
|
if (!pOwner)
|
|
return;
|
|
|
|
if ( !HasPrimaryAmmo() )
|
|
{
|
|
pOwner->ShowViewModel(false);
|
|
}
|
|
else
|
|
{
|
|
pOwner->ShowViewModel(true);
|
|
}
|
|
|
|
}
|
|
|
|
void CWeaponFlashbang::GrenSetVisible( void )
|
|
{
|
|
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
|
|
|
|
if (!pOwner)
|
|
return;
|
|
|
|
pOwner->ShowViewModel(true);
|
|
}
|