hlsdk-xash3d/dlls/hornetgun.cpp

286 lines
6.8 KiB
C++
Raw Normal View History

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