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.

350 lines
8.3 KiB

/***
*
* 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.
*
****/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "soundent.h"
#include "gamerules.h"
#include "shake.h"
enum minigun_e
{
MINIGUN_LONGIDLE = 0,
MINIGUN_IDLE1,
MINIGUN_RELOAD,
MINIGUN_DEPLOY,
MINIGUN_FIRE1,
MINIGUN_FIRE2,
MINIGUN_FIRE3
};
LINK_ENTITY_TO_CLASS( weapon_minigun, CMinigun )
//=========================================================
//=========================================================
void CMinigun::Spawn( )
{
pev->classname = MAKE_STRING("weapon_minigun"); // hack to allow for old names
Precache( );
SET_MODEL(ENT(pev), "models/w_minigun.mdl");
m_iId = WEAPON_MINIGUN;
m_iDefaultAmmo = MINIGUN_DEFAULT_GIVE;
FallInit();// get ready to fall down.
}
void CMinigun::Precache( void )
{
PRECACHE_MODEL("models/v_minigun.mdl");
PRECACHE_MODEL("models/w_minigun.mdl");
PRECACHE_MODEL("models/p_minigun.mdl");
m_iShell = PRECACHE_MODEL ("models/12mm_shell.mdl");// brass shellTE_MODEL
PRECACHE_MODEL("models/w_minigunclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
PRECACHE_SOUND("items/clipinsert1.wav");
PRECACHE_SOUND("items/cliprelease1.wav");
PRECACHE_SOUND ("weapons/minigun1.wav");// H to the K
PRECACHE_SOUND ("weapons/minigun2.wav");// H to the K
PRECACHE_SOUND ("weapons/minigun3.wav");// H to the K
PRECACHE_SOUND ("weapons/minigun.wav");
m_usminigun = PRECACHE_EVENT( 1, "events/minigun.sc" );
}
int CMinigun::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "12mm";
p->iMaxAmmo1 = _50CAL_MAX_CARRY;
p->iMaxClip = MINIGUN_MAX_CLIP;
p->iSlot = 5;
p->iPosition = 3;
p->iFlags = 0;
p->iId = m_iId = WEAPON_MINIGUN;
p->iWeight = MINIGUN_WEIGHT;
p->weaponName = "12mm Minigun";
return 1;
}
int CMinigun::AddToPlayer( CBasePlayer *pPlayer )
{
if ( CBasePlayerWeapon::AddToPlayer( pPlayer ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgWeapPickup, NULL, pPlayer->pev );
WRITE_BYTE( m_iId );
MESSAGE_END();
return TRUE;
}
return FALSE;
}
BOOL CMinigun::Deploy( )
{
return DefaultDeploy( "models/v_minigun.mdl", "models/p_minigun.mdl", MINIGUN_DEPLOY, "minigun" );
}
void CMinigun::PrimaryAttack()
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
{
PlayEmptySound( );
m_flNextPrimaryAttack = 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = 0.15;
return;
}
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecDir;
#ifdef CLIENT_DLL
if ( !bIsMultiplayer() )
#else
if ( !g_pGameRules->IsMultiplayer() )
#endif
{
// optimized multiplayer. Widened to make it easier to hit a moving player
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 8192, BULLET_PLAYER_50CAL, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
else
{
// single player spread
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_10DEGREES, 8192, BULLET_PLAYER_50CAL, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usminigun, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
m_flNextPrimaryAttack = GetNextAttackDelay( 0.05 );
if ( m_flNextPrimaryAttack < UTIL_WeaponTimeBase() )
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.05;
#ifndef CLIENT_DLL
UTIL_ScreenShake( pev->origin, 5.0, 150.0, 0.75, 250.0 );
#endif
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CMinigun::SecondaryAttack( void )
{
// don't fire underwater
if (m_pPlayer->pev->waterlevel == 3 && m_pPlayer->pev->watertype > CONTENT_FLYFIELD)
{
PlayEmptySound( );
m_flNextSecondaryAttack = 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextSecondaryAttack = 0.15;
return;
}
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip--;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
Vector vecDir;
#ifdef CLIENT_DLL
if ( !bIsMultiplayer() )
#else
if ( !g_pGameRules->IsMultiplayer() )
#endif
{
// optimized multiplayer. Widened to make it easier to hit a moving player
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_20DEGREES, 8192, BULLET_PLAYER_50CAL, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
else
{
// single player spread
vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_20DEGREES, 8192, BULLET_PLAYER_50CAL, 2, 0, m_pPlayer->pev, m_pPlayer->random_seed );
}
int flags;
#if defined( CLIENT_WEAPONS )
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usminigun, 0.0, g_vecZero, g_vecZero, vecDir.x, vecDir.y, 0, 0, 0, 0 );
if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
// HEV suit - indicate out of ammo condition
m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);
m_flNextSecondaryAttack = GetNextAttackDelay( 0.01 );
if ( m_flNextSecondaryAttack < UTIL_WeaponTimeBase() )
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.01;
#ifndef CLIENT_DLL
UTIL_ScreenShake( pev->origin, 5.0, 150.0, 0.75, 250.0 );
#endif
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CMinigun::Reload( void )
{
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == MINIGUN_MAX_CLIP )
return;
DefaultReload( MINIGUN_MAX_CLIP, MINIGUN_RELOAD, 2.5 );
}
void CMinigun::WeaponIdle( void )
{
ResetEmptySound( );
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
return;
int iAnim;
switch ( RANDOM_LONG( 0, 1 ) )
{
case 0:
iAnim = MINIGUN_LONGIDLE;
break;
default:
case 1:
iAnim = MINIGUN_IDLE1;
break;
}
SendWeaponAnim( iAnim );
m_flTimeWeaponIdle = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 ); // how long till we do this again.
}
class CMinigunAmmoClip : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/w_minigunclip.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
PRECACHE_MODEL ("models/w_minigunclip.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo( CBaseEntity *pOther )
{
int bResult = (pOther->GiveAmmo( AMMO_MINIGUNCLIP_GIVE, "12mm", _50CAL_MAX_CARRY) != -1);
if (bResult)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
}
return bResult;
}
};
LINK_ENTITY_TO_CLASS( ammo_minigun, CMinigunAmmoClip )
class CMinigunChainammo : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/w_chainammo_minigun.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
PRECACHE_MODEL ("models/w_chainammo_minigun.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo( CBaseEntity *pOther )
{
int bResult = (pOther->GiveAmmo( AMMO_CHAINBOX_GIVE, "12mm", _50CAL_MAX_CARRY) != -1);
if (bResult)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
}
return bResult;
}
};
LINK_ENTITY_TO_CLASS( ammo_minigunbox, CMinigunChainammo )