Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

544 lines
12 KiB

/***
*
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "weapons.h"
#include "gamerules.h"
5 years ago
#include "player.h"
#include "skill.h"
#include "effects.h"
#include "customentity.h"
#ifndef CLIENT_DLL
#include "grapple_tonguetip.h"
#endif
5 years ago
LINK_ENTITY_TO_CLASS( weapon_grapple, CBarnacleGrapple )
enum bgrap_e {
5 years ago
BGRAPPLE_BREATHE = 0,
BGRAPPLE_LONGIDLE,
BGRAPPLE_SHORTIDLE,
BGRAPPLE_COUGH,
BGRAPPLE_DOWN,
BGRAPPLE_UP,
BGRAPPLE_FIRE,
BGRAPPLE_FIREWAITING,
BGRAPPLE_FIREREACHED,
BGRAPPLE_FIRETRAVEL,
BGRAPPLE_FIRERELEASE
};
5 years ago
void CBarnacleGrapple::Precache( void )
{
5 years ago
PRECACHE_MODEL( "models/v_bgrap.mdl" );
PRECACHE_MODEL( "models/w_bgrap.mdl" );
PRECACHE_MODEL( "models/p_bgrap.mdl" );
5 years ago
PRECACHE_SOUND( "weapons/bgrapple_release.wav" );
PRECACHE_SOUND( "weapons/bgrapple_impact.wav" );
PRECACHE_SOUND( "weapons/bgrapple_fire.wav" );
PRECACHE_SOUND( "weapons/bgrapple_cough.wav" );
PRECACHE_SOUND( "weapons/bgrapple_pull.wav" );
PRECACHE_SOUND( "weapons/bgrapple_wait.wav" );
PRECACHE_SOUND( "weapons/alienweap_draw.wav" );
PRECACHE_SOUND( "barnacle/bcl_chew1.wav" );
PRECACHE_SOUND( "barnacle/bcl_chew2.wav" );
PRECACHE_SOUND( "barnacle/bcl_chew3.wav" );
5 years ago
PRECACHE_MODEL( "sprites/tongue.spr" );
5 years ago
UTIL_PrecacheOther( "grapple_tip" );
}
5 years ago
void CBarnacleGrapple::Spawn( void )
{
5 years ago
Precache();
m_iId = WEAPON_GRAPPLE;
SET_MODEL( ENT(pev), "models/w_bgrap.mdl" );
m_pTip = NULL;
m_bGrappling = FALSE;
m_iClip = -1;
5 years ago
FallInit();
}
5 years ago
int CBarnacleGrapple::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = NULL;
p->iMaxAmmo1 = -1;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
5 years ago
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 0;
p->iPosition = 3;
5 years ago
p->iId = m_iId = WEAPON_GRAPPLE;
p->iWeight = GRAPPLE_WEIGHT;
return 1;
}
5 years ago
int CBarnacleGrapple::AddToPlayer( CBasePlayer* pPlayer )
{
5 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
5 years ago
BOOL CBarnacleGrapple::Deploy()
{
5 years ago
int r = DefaultDeploy("models/v_bgrap.mdl", "models/p_bgrap.mdl", BGRAPPLE_UP, "gauss" );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.1;
5 years ago
return r;
}
5 years ago
void CBarnacleGrapple::Holster( int skiplocal /* = 0 */ )
{
5 years ago
m_pPlayer->m_flNextAttack = gpGlobals->time + 0.5;
5 years ago
if( m_fireState != OFF )
EndAttack();
5 years ago
SendWeaponAnim( BGRAPPLE_DOWN );
}
5 years ago
void CBarnacleGrapple::WeaponIdle( void )
{
5 years ago
ResetEmptySound();
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
5 years ago
return;
5 years ago
if( m_fireState != OFF )
{
EndAttack();
return;
}
5 years ago
m_bMissed = FALSE;
5 years ago
const float flNextIdle = RANDOM_FLOAT( 0.0, 1.0 );
5 years ago
int iAnim;
5 years ago
if( flNextIdle <= 0.5 )
{
5 years ago
iAnim = BGRAPPLE_LONGIDLE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 10.0;
}
5 years ago
else if( flNextIdle > 0.95 )
{
5 years ago
EMIT_SOUND_DYN( ENT(m_pPlayer->pev), CHAN_STATIC, "weapons/bgrapple_cough.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
5 years ago
iAnim = BGRAPPLE_COUGH;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 4.6;
}
5 years ago
else
{
5 years ago
iAnim = BGRAPPLE_BREATHE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.566;
}
5 years ago
SendWeaponAnim( iAnim );
}
5 years ago
void CBarnacleGrapple::PrimaryAttack( void )
{
5 years ago
if( m_bMissed )
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1;
return;
}
5 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
#ifndef CLIENT_DLL
if( m_pTip )
{
5 years ago
if( m_pTip->IsStuck() )
{
CBaseEntity* pTarget = m_pTip->GetGrappleTarget();
5 years ago
if( !pTarget )
{
EndAttack();
return;
}
5 years ago
if( m_pTip->GetGrappleType() > GRAPPLE_SMALL )
{
m_pPlayer->pev->movetype = MOVETYPE_FLY;
m_pPlayer->pev->flags |= FL_IMMUNE_SLIME;
//Tells the physics code that the player is not on a ladder - Solokiller
}
5 years ago
if( m_bMomentaryStuck )
{
SendWeaponAnim( BGRAPPLE_FIRETRAVEL );
5 years ago
EMIT_SOUND_DYN( ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/bgrapple_impact.wav", 0.98, ATTN_NORM, 0, 125 );
5 years ago
if( pTarget->IsPlayer() )
{
EMIT_SOUND_DYN( ENT(pTarget->pev), CHAN_WEAPON,"weapons/bgrapple_impact.wav", 0.98, ATTN_NORM, 0, 125 );
}
5 years ago
m_bMomentaryStuck = FALSE;
}
5 years ago
switch( m_pTip->GetGrappleType() )
{
case GRAPPLE_NOT_A_TARGET: break;
case GRAPPLE_SMALL:
//pTarget->BarnacleVictimGrabbed( this );
m_pTip->pev->origin = pTarget->Center();
pTarget->pev->velocity = pTarget->pev->velocity + ( m_pPlayer->pev->origin - pTarget->pev->origin );
if( pTarget->pev->velocity.Length() > 450.0 )
{
pTarget->pev->velocity = pTarget->pev->velocity.Normalize() * 450.0;
}
break;
case GRAPPLE_MEDIUM:
case GRAPPLE_LARGE:
case GRAPPLE_FIXED:
//pTarget->BarnacleVictimGrabbed( this );
if( m_pTip->GetGrappleType() != GRAPPLE_FIXED )
UTIL_SetOrigin( m_pTip->pev, pTarget->Center() );
m_pPlayer->pev->velocity =
m_pPlayer->pev->velocity + ( m_pTip->pev->origin - m_pPlayer->pev->origin );
if( m_pPlayer->pev->velocity.Length() > 450.0 )
{
m_pPlayer->pev->velocity = m_pPlayer->pev->velocity.Normalize() * 450.0;
Vector vecPitch = UTIL_VecToAngles( m_pPlayer->pev->velocity );
if( (vecPitch.x > 55.0 && vecPitch.x < 205.0) || vecPitch.x < -55.0 )
{
m_bGrappling = FALSE;
m_pPlayer->SetAnimation( PLAYER_IDLE );
}
else
{
if (!m_bGrappling)
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/bgrapple_pull.wav", 0.98, ATTN_NORM, 0, 125 );
m_bGrappling = TRUE;
m_pPlayer->m_afPhysicsFlags |= PFLAG_LATCHING;
}
}
else
{
m_bGrappling = FALSE;
m_pPlayer->SetAnimation( PLAYER_IDLE );
}
break;
}
}
5 years ago
if( m_pTip->HasMissed() )
{
EMIT_SOUND_DYN( ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/bgrapple_release.wav", 0.98, ATTN_NORM, 0, 125 );
5 years ago
EndAttack();
return;
}
}
#endif
if( m_fireState != OFF )
{
m_pPlayer->m_iWeaponVolume = 450;
5 years ago
if( m_flShootTime != 0.0 && gpGlobals->time > m_flShootTime )
{
SendWeaponAnim( BGRAPPLE_FIREWAITING );
5 years ago
Vector vecPunchAngle = m_pPlayer->pev->punchangle;
5 years ago
vecPunchAngle.x += 2.0;
5 years ago
m_pPlayer->pev->punchangle = vecPunchAngle;
5 years ago
Fire( m_pPlayer->GetGunPosition(), gpGlobals->v_forward );
EMIT_SOUND_DYN( ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/bgrapple_pull.wav", 0.98, ATTN_NORM, 0, 125 );
m_flShootTime = 0;
}
}
else
{
m_bMomentaryStuck = TRUE;
5 years ago
SendWeaponAnim( BGRAPPLE_FIRE );
5 years ago
m_pPlayer->m_iWeaponVolume = 450;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.1;
5 years ago
#ifndef CLIENT_DLL
if( g_pGameRules->IsMultiplayer() )
{
m_flShootTime = gpGlobals->time;
}
else
{
m_flShootTime = gpGlobals->time + 0.35;
}
#endif
EMIT_SOUND_DYN( ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/bgrapple_fire.wav", 0.98, ATTN_NORM, 0, 125 );
m_fireState = CHARGE;
}
5 years ago
if( !m_pTip )
{
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.01;
5 years ago
return;
}
5 years ago
#ifndef CLIENT_DLL
if( m_pTip->GetGrappleType() != GRAPPLE_FIXED && m_pTip->IsStuck() )
{
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
5 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
5 years ago
Vector vecEnd = vecSrc + gpGlobals->v_forward * 16.0;
5 years ago
TraceResult tr;
5 years ago
UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr );
5 years ago
if( tr.flFraction >= 1.0 )
{
UTIL_TraceHull( vecSrc, vecEnd, dont_ignore_monsters, head_hull, m_pPlayer->edict(), &tr );
if( tr.flFraction < 1.0 )
{
CBaseEntity* pHit = Instance( tr.pHit );
/*
if( !pHit )
pHit = CWorld::GetInstance();
if( !pHit )
{
FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, m_pPlayer );
}
*/
}
}
5 years ago
if( tr.flFraction < 1.0 )
{
CBaseEntity* pHit = Instance( tr.pHit );
/*
if( !pHit )
pHit = CWorld::GetInstance();
*/
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
if( pHit )
{
if( m_pTip )
{
bool bValidTarget = FALSE;
#ifndef CLIENT_DLL
5 years ago
if( pHit->IsPlayer() )
{
m_pTip->SetGrappleTarget( pHit );
bValidTarget = TRUE;
}
else if( m_pTip->CheckTarget( pHit ) != GRAPPLE_NOT_A_TARGET )
{
bValidTarget = TRUE;
}
#endif
5 years ago
if( bValidTarget )
{
if( m_flDamageTime + 0.5 < gpGlobals->time )
{
#ifndef CLIENT_DLL
5 years ago
ClearMultiDamage();
5 years ago
float flDamage = gSkillData.plrDmgGrapple;
5 years ago
if( g_pGameRules->IsMultiplayer() )
{
flDamage *= 2;
}
5 years ago
pHit->TraceAttack( m_pPlayer->pev, flDamage, gpGlobals->v_forward, &tr, DMG_CLUB );
5 years ago
ApplyMultiDamage( m_pPlayer->pev, m_pPlayer->pev );
#endif
5 years ago
m_flDamageTime = gpGlobals->time;
const char* pszSample;
switch( RANDOM_LONG( 0, 2 ) )
{
default:
case 0: pszSample = "barnacle/bcl_chew1.wav"; break;
case 1: pszSample = "barnacle/bcl_chew2.wav"; break;
case 2: pszSample = "barnacle/bcl_chew3.wav"; break;
}
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_VOICE, pszSample, VOL_NORM, ATTN_NORM, 0, 125 );
}
}
}
}
}
}
#endif
5 years ago
//TODO: CTF support - Solokiller
/*
if( g_pGameRules->IsMultiplayer() && g_pGameRules->IsCTF() )
{
m_flNextPrimaryAttack = gpGlobals->time;
}
else
*/
{
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.01;
5 years ago
}
}
5 years ago
void CBarnacleGrapple::Fire( Vector vecOrigin, Vector vecDir )
{
#ifndef CLIENT_DLL
5 years ago
Vector vecSrc = vecOrigin;
5 years ago
Vector vecEnd = vecSrc + vecDir * 2048.0;
5 years ago
TraceResult tr;
5 years ago
UTIL_TraceLine( vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer->edict(), &tr );
5 years ago
if( !tr.fAllSolid )
{
5 years ago
CBaseEntity* pHit = Instance( tr.pHit );
/*
if( !pHit )
pHit = CWorld::GetInstance();
*/
if( pHit )
{
UpdateEffect();
m_flDamageTime = gpGlobals->time;
}
}
#endif
}
5 years ago
void CBarnacleGrapple::EndAttack( void )
{
5 years ago
m_fireState = OFF;
SendWeaponAnim( BGRAPPLE_FIRERELEASE );
5 years ago
EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/bgrapple_release.wav", 1, ATTN_NORM);
5 years ago
EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_WEAPON, "weapons/bgrapple_pull.wav", 0.0, ATTN_NONE, SND_STOP, 100 );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.9;
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.01;
5 years ago
DestroyEffect();
5 years ago
if( m_bGrappling && m_pPlayer->IsAlive() )
{
5 years ago
m_pPlayer->SetAnimation( PLAYER_IDLE );
}
5 years ago
m_pPlayer->pev->movetype = MOVETYPE_WALK;
m_pPlayer->pev->flags &= ~(FL_IMMUNE_SLIME);
m_pPlayer->m_afPhysicsFlags &= ~PFLAG_LATCHING;
}
5 years ago
void CBarnacleGrapple::CreateEffect( void )
{
#ifndef CLIENT_DLL
5 years ago
DestroyEffect();
5 years ago
m_pTip = GetClassPtr((CBarnacleGrappleTip *)NULL);
m_pTip->Spawn();
5 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
5 years ago
Vector vecOrigin =
m_pPlayer->GetGunPosition() +
gpGlobals->v_forward * 16.0 +
gpGlobals->v_right * 8.0 +
gpGlobals->v_up * -8.0;
5 years ago
Vector vecAngles = m_pPlayer->pev->v_angle;
vecAngles.x = -vecAngles.x;
m_pTip->SetPosition( vecOrigin, vecAngles, m_pPlayer );
5 years ago
if( !m_pBeam )
{
5 years ago
m_pBeam = CBeam::BeamCreate( "sprites/tongue.spr", 16 );
5 years ago
m_pBeam->EntsInit( m_pTip->entindex(), m_pPlayer->entindex() );
5 years ago
m_pBeam->SetFlags( BEAM_FSOLID );
5 years ago
m_pBeam->SetBrightness( 100.0 );
5 years ago
m_pBeam->SetEndAttachment( 1 );
5 years ago
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY;
}
#endif
}
5 years ago
void CBarnacleGrapple::UpdateEffect( void )
{
#ifndef CLIENT_DLL
5 years ago
if( !m_pBeam || !m_pTip )
CreateEffect();
#endif
}
5 years ago
void CBarnacleGrapple::DestroyEffect( void )
{
5 years ago
if( m_pBeam )
{
UTIL_Remove( m_pBeam );
m_pBeam = NULL;
}
#ifndef CLIENT_DLL
5 years ago
if( m_pTip )
{
5 years ago
m_pTip->Killed( NULL, GIB_NEVER );
m_pTip = NULL;
}
#endif
}