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.

623 lines
15 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, 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.
*
****/
#if !OEM_BUILD
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"
int rocketMode;
8 years ago
enum rpg_e
{
9 years ago
RPG_IDLE = 0,
RPG_FIDGET,
RPG_RELOAD, // to reload
RPG_FIRE2, // to empty
RPG_HOLSTER1, // loaded
RPG_DRAW1, // loaded
RPG_HOLSTER2, // unloaded
RPG_DRAW_UL, // unloaded
RPG_IDLE_UL, // unloaded idle
RPG_FIDGET_UL // unloaded fidget
9 years ago
};
LINK_ENTITY_TO_CLASS( weapon_rpg, CRpg )
9 years ago
4 years ago
#if !CLIENT_DLL
9 years ago
LINK_ENTITY_TO_CLASS( laser_spot, CLaserSpot )
9 years ago
//=========================================================
//=========================================================
CLaserSpot *CLaserSpot::CreateSpot( void )
{
CLaserSpot *pSpot = GetClassPtr( (CLaserSpot *)NULL );
pSpot->Spawn();
8 years ago
pSpot->pev->classname = MAKE_STRING( "laser_spot" );
9 years ago
return pSpot;
}
//=========================================================
//=========================================================
void CLaserSpot::Spawn( void )
{
8 years ago
Precache();
9 years ago
pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_NOT;
pev->rendermode = kRenderGlow;
pev->renderfx = kRenderFxNoDissipation;
pev->renderamt = 255;
8 years ago
SET_MODEL( ENT( pev ), "sprites/laserdot.spr" );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
}
9 years ago
//=========================================================
// Suspend- make the laser sight invisible.
//=========================================================
void CLaserSpot::Suspend( float flSuspendTime )
{
pev->effects |= EF_NODRAW;
8 years ago
9 years ago
SetThink( &CLaserSpot::Revive );
pev->nextthink = gpGlobals->time + flSuspendTime;
}
//=========================================================
// Revive - bring a suspended laser sight back.
//=========================================================
void CLaserSpot::Revive( void )
{
pev->effects &= ~EF_NODRAW;
SetThink( NULL );
}
void CLaserSpot::Precache( void )
{
8 years ago
PRECACHE_MODEL( "sprites/laserdot.spr" );
}
9 years ago
LINK_ENTITY_TO_CLASS( rpg_rocket, CRpgRocket )
9 years ago
//=========================================================
//=========================================================
CRpgRocket *CRpgRocket::CreateRpgRocket( Vector vecOrigin, Vector vecAngles, int mode, CBaseEntity *pOwner, CRpg *pLauncher )
9 years ago
{
CRpgRocket *pRocket = GetClassPtr( (CRpgRocket *)NULL );
rocketMode = mode;
9 years ago
UTIL_SetOrigin( pRocket->pev, vecOrigin );
pRocket->pev->angles = vecAngles;
pRocket->Spawn();
pRocket->SetTouch( &CRpgRocket::RocketTouch );
pRocket->m_hLauncher = pLauncher;// remember what RPG fired me.
pLauncher->m_cActiveRockets++;// register this missile as active for the launcher
9 years ago
pRocket->pev->owner = pOwner->edict();
return pRocket;
}
//=========================================================
//=========================================================
8 years ago
void CRpgRocket::Spawn( void )
9 years ago
{
8 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_BOUNCE;
pev->solid = SOLID_BBOX;
if( !rocketMode )
{
SET_MODEL( ENT( pev ), "models/bulletbill.mdl" );
}
else if( rocketMode )
{
SET_MODEL( ENT( pev ), "models/rpgrockethy.mdl" );
}
8 years ago
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
8 years ago
pev->classname = MAKE_STRING( "rpg_rocket" );
9 years ago
SetThink( &CRpgRocket::IgniteThink );
SetTouch( &CGrenade::ExplodeTouch3 );
9 years ago
pev->angles.x -= 30.0f;
9 years ago
UTIL_MakeVectors( pev->angles );
pev->angles.x = -( pev->angles.x + 30.0f );
9 years ago
pev->velocity = gpGlobals->v_forward * 250.0f;
pev->gravity = 0.5f;
9 years ago
pev->nextthink = gpGlobals->time + 0.4f;
9 years ago
pev->dmg = gSkillData.plrDmgRPG;
}
//=========================================================
//=========================================================
8 years ago
void CRpgRocket::RocketTouch( CBaseEntity *pOther )
9 years ago
{
if( CRpg* pLauncher = (CRpg*)( (CBaseEntity*)( m_hLauncher ) ) )
9 years ago
{
// my launcher is still around, tell it I'm dead.
pLauncher->m_cActiveRockets--;
9 years ago
}
//STOP_SOUND( edict(), CHAN_VOICE, "weapons/rocket1.wav" );
ExplodeTouch3( pOther );
9 years ago
}
//=========================================================
//=========================================================
8 years ago
void CRpgRocket::Precache( void )
9 years ago
{
PRECACHE_MODEL( "models/bulletbill.mdl" );
PRECACHE_MODEL( "models/rpgrockethy.mdl" );
8 years ago
m_iTrail = PRECACHE_MODEL( "sprites/smoke.spr" );
PRECACHE_SOUND( "weapons/smbexplode.wav" );
PRECACHE_SOUND( "weapons/wheredahoodat.wav" );
9 years ago
}
8 years ago
void CRpgRocket::IgniteThink( void )
9 years ago
{
// pev->movetype = MOVETYPE_TOSS;
pev->movetype = MOVETYPE_FLY;
pev->effects |= EF_LIGHT;
if( rocketMode )
{
// make rocket sound
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/wheredahoodat.wav", 1, 0.5 );
}
9 years ago
// rocket trail
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMFOLLOW );
8 years ago
WRITE_SHORT( entindex() ); // entity
WRITE_SHORT( m_iTrail ); // model
WRITE_BYTE( 60 ); // life
WRITE_BYTE( 15 ); // width
9 years ago
WRITE_BYTE( 224 ); // r, g, b
WRITE_BYTE( 224 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
MESSAGE_END(); // move PHS/PVS data sending into here (SEND_ALL, SEND_PVS, SEND_PHS)
m_flIgniteTime = gpGlobals->time;
// set to follow laser spot
SetThink( &CRpgRocket::FollowThink );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
8 years ago
void CRpgRocket::FollowThink( void )
9 years ago
{
CBaseEntity *pOther = NULL;
Vector vecTarget;
Vector vecDir;
float flDist, flMax, flDot;
TraceResult tr;
UTIL_MakeAimVectors( pev->angles );
vecTarget = gpGlobals->v_forward;
flMax = 4096;
// Examine all entities within a reasonable radius
8 years ago
while( ( pOther = UTIL_FindEntityByClassname( pOther, "laser_spot" ) ) != NULL )
9 years ago
{
8 years ago
UTIL_TraceLine( pev->origin, pOther->pev->origin, dont_ignore_monsters, ENT( pev ), &tr );
9 years ago
// ALERT( at_console, "%f\n", tr.flFraction );
if( tr.flFraction >= 0.9f )
9 years ago
{
vecDir = pOther->pev->origin - pev->origin;
8 years ago
flDist = vecDir.Length();
vecDir = vecDir.Normalize();
9 years ago
flDot = DotProduct( gpGlobals->v_forward, vecDir );
8 years ago
if( ( flDot > 0 ) && ( flDist * ( 1 - flDot ) < flMax ) )
9 years ago
{
8 years ago
flMax = flDist * ( 1 - flDot );
9 years ago
vecTarget = vecDir;
}
}
}
pev->angles = UTIL_VecToAngles( vecTarget );
// this acceleration and turning math is totally wrong, but it seems to respond well so don't change it.
float flSpeed = pev->velocity.Length();
if( gpGlobals->time - m_flIgniteTime < 1.0f )
9 years ago
{
pev->velocity = pev->velocity * 0.2f + vecTarget * ( flSpeed * 0.8f + 400.0f );
8 years ago
if( pev->waterlevel == 3 )
9 years ago
{
// go slow underwater
if( pev->velocity.Length() > 300.0f )
9 years ago
{
pev->velocity = pev->velocity.Normalize() * 300.0f;
9 years ago
}
UTIL_BubbleTrail( pev->origin - pev->velocity * 0.1f, pev->origin, 4 );
9 years ago
}
else
{
if( pev->velocity.Length() > 2000.0f )
9 years ago
{
pev->velocity = pev->velocity.Normalize() * 2000.0f;
9 years ago
}
}
}
else
{
8 years ago
if( pev->effects & EF_LIGHT )
9 years ago
{
pev->effects = 0;
STOP_SOUND( ENT( pev ), CHAN_VOICE, "weapons/wheredahoodat.wav" );
9 years ago
}
pev->velocity = pev->velocity * 0.2f + vecTarget * flSpeed * 0.798f;
if( pev->waterlevel == 0 && pev->velocity.Length() < 1500.0f )
9 years ago
{
if( CRpg *pLauncher = (CRpg*)( (CBaseEntity*)( m_hLauncher ) ) )
{
// my launcher is still around, tell it I'm dead.
pLauncher->m_cActiveRockets--;
}
Detonate3();
9 years ago
}
}
// ALERT( at_console, "%.0f\n", flSpeed );
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
}
#endif
void CRpg::Reload( void )
{
int iResult = 0;
// don't bother with any of this if don't need to reload.
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == RPG_MAX_CLIP )
9 years ago
return;
// because the RPG waits to autoreload when no missiles are active while the LTD is on, the
// weapons code is constantly calling into this function, but is often denied because
// a) missiles are in flight, but the LTD is on
// or
// b) player is totally out of ammo and has nothing to switch to, and should be allowed to
// shine the designator around
//
// Set the next attack time into the future so that WeaponIdle will get called more often
// than reload, allowing the RPG LTD to be updated
m_flNextPrimaryAttack = GetNextAttackDelay( 0.5f );
9 years ago
8 years ago
if( m_cActiveRockets && m_fSpotActive )
9 years ago
{
// no reloading when there are active missiles tracking the designator.
// ward off future autoreload attempts by setting next attack time into the future for a bit.
return;
}
4 years ago
#if !CLIENT_DLL
8 years ago
if( m_pSpot && m_fSpotActive )
9 years ago
{
m_pSpot->Suspend( 2.1f );
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 2.1f;
9 years ago
}
#endif
8 years ago
if( m_iClip == 0 )
9 years ago
iResult = DefaultReload( RPG_MAX_CLIP, RPG_RELOAD, 2 );
8 years ago
if( iResult )
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
8 years ago
void CRpg::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_RPG;
8 years ago
SET_MODEL( ENT( pev ), "models/w_rpg.mdl" );
modo = 0;
9 years ago
m_fSpotActive = 1;
4 years ago
#if CLIENT_DLL
8 years ago
if( bIsMultiplayer() )
9 years ago
#else
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
#endif
{
// more default ammo in multiplay.
m_iDefaultAmmo = RPG_DEFAULT_GIVE * 2;
}
else
{
m_iDefaultAmmo = RPG_DEFAULT_GIVE;
}
FallInit();// get ready to fall down.
}
void CRpg::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_rpg.mdl" );
PRECACHE_MODEL( "models/v_rpg.mdl" );
PRECACHE_MODEL( "models/p_rpg.mdl" );
9 years ago
8 years ago
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
UTIL_PrecacheOther( "laser_spot" );
UTIL_PrecacheOther( "rpg_rocket" );
PRECACHE_SOUND( "weapons/bbill.wav" );
//PRECACHE_SOUND( "weapons/glauncher.wav" ); // alternative fire sound
9 years ago
8 years ago
m_usRpg = PRECACHE_EVENT( 1, "events/rpg.sc" );
9 years ago
}
8 years ago
int CRpg::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "rockets";
p->iMaxAmmo1 = ROCKET_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = RPG_MAX_CLIP;
p->iSlot = 3;
p->iPosition = 0;
p->iId = m_iId = WEAPON_RPG;
p->iFlags = 0;
p->iWeight = RPG_WEIGHT;
return 1;
}
int CRpg::AddToPlayer( CBasePlayer *pPlayer )
{
8 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
9 years ago
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
8 years ago
BOOL CRpg::Deploy()
9 years ago
{
8 years ago
if( m_iClip == 0 )
9 years ago
{
return DefaultDeploy( "models/v_rpg.mdl", "models/p_rpg.mdl", RPG_DRAW_UL, "rpg" );
}
ClientPrint( m_pPlayer->pev, HUD_PRINTCENTER, "RIGHT CLICK to change Rockets!" ); //digamos al cliente
9 years ago
return DefaultDeploy( "models/v_rpg.mdl", "models/p_rpg.mdl", RPG_DRAW1, "rpg" );
}
BOOL CRpg::CanHolster( void )
{
8 years ago
if( m_fSpotActive && m_cActiveRockets )
9 years ago
{
// can't put away while guiding a missile.
return FALSE;
}
return TRUE;
}
void CRpg::Holster( int skiplocal /* = 0 */ )
{
m_fInReload = FALSE;// cancel any reload in progress.
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
8 years ago
9 years ago
SendWeaponAnim( RPG_HOLSTER1 );
4 years ago
#if !CLIENT_DLL
8 years ago
if( m_pSpot )
9 years ago
{
m_pSpot->Killed( NULL, GIB_NEVER );
m_pSpot = NULL;
}
#endif
}
void CRpg::PrimaryAttack()
{
8 years ago
if( m_iClip )
9 years ago
{
m_pPlayer->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;
4 years ago
#if !CLIENT_DLL
9 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
Vector vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16.0f + gpGlobals->v_right * 8.0f + gpGlobals->v_up * -8.0f;
8 years ago
CRpgRocket *pRocket = CRpgRocket::CreateRpgRocket( vecSrc, m_pPlayer->pev->v_angle, modo, m_pPlayer, this );
9 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle );// RpgRocket::Create stomps on globals, so remake.
pRocket->pev->velocity = pRocket->pev->velocity + gpGlobals->v_forward * DotProduct( m_pPlayer->pev->velocity, gpGlobals->v_forward );
#endif
// firing RPG no longer turns on the designator. ALT fire is a toggle switch for the LTD.
// Ken signed up for this as a global change (sjb)
int flags;
#if CLIENT_WEAPONS
9 years ago
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT( flags, m_pPlayer->edict(), m_usRpg );
m_iClip--;
8 years ago
m_flNextPrimaryAttack = GetNextAttackDelay( 1.5f );
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.5f;
ResetEmptySound();
9 years ago
}
else
{
8 years ago
PlayEmptySound();
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.2f;
9 years ago
}
8 years ago
UpdateSpot();
9 years ago
}
void CRpg::SecondaryAttack()
{
if( !modo )
9 years ago
{
ClientPrint( m_pPlayer->pev, HUD_PRINTCENTER, "Rocket Type: Hell Yeah Rockets" ); //digamos al cliente
modo = 1;
9 years ago
}
else
{
ClientPrint( m_pPlayer->pev, HUD_PRINTCENTER, "Rocket Type: Bullet Bills" ); //digamos al cliente
modo = 0;
}
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.2f;
9 years ago
}
void CRpg::WeaponIdle( void )
{
8 years ago
UpdateSpot();
9 years ago
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
ResetEmptySound();
9 years ago
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0f, 1.0f );
if( flRand <= 0.75f || m_fSpotActive )
9 years ago
{
8 years ago
if( m_iClip == 0 )
9 years ago
iAnim = RPG_IDLE_UL;
else
iAnim = RPG_IDLE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 90.0f / 15.0f;
9 years ago
}
else
{
8 years ago
if( m_iClip == 0 )
9 years ago
iAnim = RPG_FIDGET_UL;
else
iAnim = RPG_FIDGET;
#if WEAPONS_ANIMATION_TIMES_FIX
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 6.1f;
#else
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3.0f;
#endif
9 years ago
}
SendWeaponAnim( iAnim );
}
else
{
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0f;
9 years ago
}
}
void CRpg::UpdateSpot( void )
{
4 years ago
#if !CLIENT_DLL
8 years ago
if( m_fSpotActive )
9 years ago
{
if (m_pPlayer->pev->viewmodel == 0)
return;
8 years ago
if( !m_pSpot )
9 years ago
{
m_pSpot = CLaserSpot::CreateSpot();
}
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
8 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
9 years ago
Vector vecAiming = gpGlobals->v_forward;
TraceResult tr;
UTIL_TraceLine( vecSrc, vecSrc + vecAiming * 8192.0f, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );
8 years ago
9 years ago
UTIL_SetOrigin( m_pSpot->pev, tr.vecEndPos );
}
#endif
}
class CRpgAmmo : public CBasePlayerAmmo
{
void Spawn( void )
8 years ago
{
Precache();
SET_MODEL( ENT( pev ), "models/w_rpgammo.mdl" );
CBasePlayerAmmo::Spawn();
9 years ago
}
void Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/w_rpgammo.mdl" );
PRECACHE_SOUND( "items/9mmclip1.wav" );
9 years ago
}
BOOL AddAmmo( CBaseEntity *pOther )
{
int iGive;
4 years ago
#if CLIENT_DLL
8 years ago
if( bIsMultiplayer() )
9 years ago
#else
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
#endif
{
// hand out more ammo per rocket in multiplayer.
iGive = AMMO_RPGCLIP_GIVE * 2;
}
else
{
iGive = AMMO_RPGCLIP_GIVE;
}
8 years ago
if( pOther->GiveAmmo( iGive, "rockets", ROCKET_MAX_CARRY ) != -1 )
9 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
9 years ago
return TRUE;
}
return FALSE;
}
};
LINK_ENTITY_TO_CLASS( ammo_rpgclip, CRpgAmmo )
#endif