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.

286 lines
6.7 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 && !HLDEMO_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 "hornet.h"
#include "gamerules.h"
8 years ago
enum hgun_e
{
9 years ago
HGUN_IDLE1 = 0,
HGUN_FIDGETSWAY,
HGUN_FIDGETSHAKE,
HGUN_DOWN,
HGUN_UP,
HGUN_SHOOT
};
enum firemode_e
{
FIREMODE_TRACK = 0,
FIREMODE_FAST
};
LINK_ENTITY_TO_CLASS( weapon_hornetgun, CHgun )
9 years ago
BOOL CHgun::IsUseable( void )
{
return TRUE;
}
8 years ago
void CHgun::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_HORNETGUN;
8 years ago
SET_MODEL( ENT( pev ), "models/w_hgun.mdl" );
9 years ago
m_iDefaultAmmo = HIVEHAND_DEFAULT_GIVE;
m_iFirePhase = 0;
FallInit();// get ready to fall down.
}
void CHgun::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/v_hgun.mdl" );
PRECACHE_MODEL( "models/w_hgun.mdl" );
PRECACHE_MODEL( "models/p_hgun.mdl" );
9 years ago
8 years ago
m_usHornetFire = PRECACHE_EVENT( 1, "events/firehornet.sc" );
9 years ago
8 years ago
UTIL_PrecacheOther( "hornet" );
9 years ago
}
int CHgun::AddToPlayer( CBasePlayer *pPlayer )
{
8 years ago
if( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
9 years ago
{
4 years ago
#if !CLIENT_DLL
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// in multiplayer, all hivehands come full.
8 years ago
pPlayer->m_rgAmmo[PrimaryAmmoIndex()] = HORNET_MAX_CARRY;
9 years ago
}
#endif
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
8 years ago
int CHgun::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "Hornets";
p->iMaxAmmo1 = HORNET_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 3;
p->iPosition = 3;
p->iId = m_iId = WEAPON_HORNETGUN;
p->iFlags = ITEM_FLAG_NOAUTOSWITCHEMPTY | ITEM_FLAG_NOAUTORELOAD;
p->iWeight = HORNETGUN_WEIGHT;
return 1;
}
8 years ago
BOOL CHgun::Deploy()
9 years ago
{
return DefaultDeploy( "models/v_hgun.mdl", "models/p_hgun.mdl", HGUN_UP, "hive" );
}
void CHgun::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5f;
9 years ago
SendWeaponAnim( HGUN_DOWN );
//!!!HACKHACK - can't select hornetgun if it's empty! no way to get ammo for it, either.
8 years ago
if( !m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] )
9 years ago
{
8 years ago
m_pPlayer->m_rgAmmo[PrimaryAmmoIndex()] = 1;
9 years ago
}
}
void CHgun::PrimaryAttack()
{
8 years ago
Reload();
9 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
{
return;
}
4 years ago
#if !CLIENT_DLL
9 years ago
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
CBaseEntity *pHornet = CBaseEntity::Create( "hornet", m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16.0f + gpGlobals->v_right * 8.0f + gpGlobals->v_up * -12.0f, m_pPlayer->pev->v_angle, m_pPlayer->edict() );
pHornet->pev->velocity = gpGlobals->v_forward * 300.0f;
9 years ago
m_flRechargeTime = gpGlobals->time + 0.5f;
9 years ago
#endif
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
int flags;
#if CLIENT_WEAPONS
9 years ago
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usHornetFire, 0.0f, g_vecZero, g_vecZero, 0.0f, 0.0f, 0, 0, 0, 0 );
9 years ago
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = m_flNextPrimaryAttack + 0.25f;
9 years ago
8 years ago
if( m_flNextPrimaryAttack < UTIL_WeaponTimeBase() )
9 years ago
{
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.25f;
9 years ago
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CHgun::SecondaryAttack( void )
{
Reload();
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
{
return;
}
//Wouldn't be a bad idea to completely predict these, since they fly so fast...
4 years ago
#if !CLIENT_DLL
9 years ago
CBaseEntity *pHornet;
Vector vecSrc;
UTIL_MakeVectors( m_pPlayer->pev->v_angle );
vecSrc = m_pPlayer->GetGunPosition() + gpGlobals->v_forward * 16.0f + gpGlobals->v_right * 8.0f + gpGlobals->v_up * -12.0f;
9 years ago
m_iFirePhase++;
8 years ago
switch( m_iFirePhase )
9 years ago
{
case 1:
vecSrc = vecSrc + gpGlobals->v_up * 8.0f;
9 years ago
break;
case 2:
vecSrc = vecSrc + gpGlobals->v_up * 8.0f;
vecSrc = vecSrc + gpGlobals->v_right * 8.0f;
9 years ago
break;
case 3:
vecSrc = vecSrc + gpGlobals->v_right * 8.0f;
9 years ago
break;
case 4:
vecSrc = vecSrc + gpGlobals->v_up * -8.0f;
vecSrc = vecSrc + gpGlobals->v_right * 8.0f;
9 years ago
break;
case 5:
vecSrc = vecSrc + gpGlobals->v_up * -8.0f;
9 years ago
break;
case 6:
vecSrc = vecSrc + gpGlobals->v_up * -8.0f;
vecSrc = vecSrc + gpGlobals->v_right * -8.0f;
9 years ago
break;
case 7:
vecSrc = vecSrc + gpGlobals->v_right * -8.0f;
9 years ago
break;
case 8:
vecSrc = vecSrc + gpGlobals->v_up * 8.0f;
vecSrc = vecSrc + gpGlobals->v_right * -8.0f;
9 years ago
m_iFirePhase = 0;
break;
}
pHornet = CBaseEntity::Create( "hornet", vecSrc, m_pPlayer->pev->v_angle, m_pPlayer->edict() );
pHornet->pev->velocity = gpGlobals->v_forward * 1200.0f;
9 years ago
pHornet->pev->angles = UTIL_VecToAngles( pHornet->pev->velocity );
pHornet->SetThink( &CHornet::StartDart );
m_flRechargeTime = gpGlobals->time + 0.5f;
9 years ago
#endif
int flags;
#if CLIENT_WEAPONS
9 years ago
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usHornetFire, 0.0f, g_vecZero, g_vecZero, 0.0f, 0.0f, 0, 0, 0, 0 );
9 years ago
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
8 years ago
// player "shoot" animation
9 years ago
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.1f;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10.0f, 15.0f );
9 years ago
}
void CHgun::Reload( void )
{
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] >= HORNET_MAX_CARRY )
9 years ago
return;
8 years ago
while( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] < HORNET_MAX_CARRY && m_flRechargeTime < gpGlobals->time )
9 years ago
{
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]++;
m_flRechargeTime += 0.5f;
9 years ago
}
}
void CHgun::WeaponIdle( void )
{
8 years ago
Reload();
9 years ago
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0f, 1.0f );
if( flRand <= 0.75f )
9 years ago
{
iAnim = HGUN_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 30.0f / 16.0f * 2.0f;
9 years ago
}
else if( flRand <= 0.875f )
9 years ago
{
iAnim = HGUN_FIDGETSWAY;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 40.0f / 16.0f;
9 years ago
}
else
{
iAnim = HGUN_FIDGETSHAKE;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 35.0f / 16.0f;
9 years ago
}
SendWeaponAnim( iAnim );
}
#endif