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.
 
 
 
 
 
 

328 lines
7.1 KiB

/*
Copyright (c) 1999, Cold Ice Modification.
This code has been written by SlimShady ( darcuri@optonline.net )
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 and from the Cold Ice team.
Please if you use this code in any public form, please give us credit.
*/
#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"
enum m16_e
{
M16_LONGIDLE = 0,
M16_IDLE1,
M16_LAUNCH,
M16_RELOAD,
M16_DEPLOY,
M16_FIRE1,
M16_FIRE2,
M16_FIRE3,
};
class CM16 : public CBasePlayerWeapon
{
public:
void Spawn( void );
void Precache( void );
int iItemSlot( void ) { return 3; }
int GetItemInfo(ItemInfo *p);
int AddToPlayer( CBasePlayer *pPlayer );
void PrimaryAttack( void );
void SecondaryAttack( void );
BOOL Deploy( void );
void Reload( void );
void WeaponIdle( void );
float m_flNextAnimTime;
int m_iShell;
int m_iShotCount;
};
LINK_ENTITY_TO_CLASS( weapon_m16, CM16 );
//=========================================================
//=========================================================
void CM16::Spawn( )
{
pev->classname = MAKE_STRING("weapon_m16");
Precache( );
SET_MODEL(ENT(pev), "models/wmodels/w_m16.mdl");
m_iId = WEAPON_M16;
m_iDefaultAmmo = M16_DEFAULT_GIVE;
FallInit();
}
void CM16::Precache( void )
{
PRECACHE_MODEL("models/vmodels/v_m16.mdl");
PRECACHE_MODEL("models/wmodels/w_m16.mdl");
PRECACHE_MODEL("models/pmodels/p_m16.mdl");
m_iShell = PRECACHE_MODEL ("models/shell.mdl");
PRECACHE_SOUND("weapons/m161.wav");
PRECACHE_SOUND("items/cliprelease1.wav");
PRECACHE_SOUND("items/clipinsert1.wav");
}
int CM16::GetItemInfo(ItemInfo *p)
{
p->pszName = STRING(pev->classname);
p->pszAmmo1 = "5.56mm";
p->iMaxAmmo1 = M16_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = M16_MAX_CLIP;
p->iSlot = 2;
p->iPosition = 0;
p->iFlags = 0;
p->iId = m_iId = WEAPON_M16;
p->iWeight = M16_WEIGHT;
return 1;
}
int CM16::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 CM16::Deploy( )
{
return DefaultDeploy( "models/vmodels/v_m16.mdl", "models/pmodels/p_m16.mdl", M16_DEPLOY, "mp5" );
}
void CM16::PrimaryAttack()
{
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound( );
m_flNextPrimaryAttack = gpGlobals->time + 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = gpGlobals->time + 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;
if (1 || m_flNextAnimTime < gpGlobals->time)
{
SendWeaponAnim( M16_FIRE1 + RANDOM_LONG(0,2));
m_flNextAnimTime = gpGlobals->time + 0.2;
}
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/m161.wav", 1, ATTN_NORM, 0, 94 + RANDOM_LONG(0,0xf));
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecShellVelocity = m_pPlayer->pev->velocity
+ gpGlobals->v_right * RANDOM_FLOAT(100,150)
+ gpGlobals->v_up * RANDOM_FLOAT(100,150)
+ gpGlobals->v_forward * 25;
EjectBrass ( pev->origin + m_pPlayer->pev->view_ofs
+ gpGlobals->v_up * -12
+ gpGlobals->v_forward * 28
+ gpGlobals->v_right * 6, vecShellVelocity, pev->angles.y, m_iShell, TE_BOUNCE_SHELL);
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
m_pPlayer->FireBullets( 1, vecSrc, vecAiming, VECTOR_CONE_6DEGREES, 8192, BULLET_PLAYER_MP5, 0 );
m_flNextPrimaryAttack = gpGlobals->time + 0.1;
m_flNextSecondaryAttack = gpGlobals->time + 0.1;
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT ( 10, 15 );
m_pPlayer->pev->punchangle.x = RANDOM_FLOAT( -2, 2 );
}
void CM16::SecondaryAttack( void )
{
if (m_pPlayer->pev->waterlevel == 3)
{
PlayEmptySound( );
m_flNextPrimaryAttack = gpGlobals->time + 0.15;
return;
}
if (m_iClip <= 0)
{
PlayEmptySound();
m_flNextPrimaryAttack = gpGlobals->time + 0.15;
return;
}
m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
m_iClip--;
m_iShotCount++;
m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;
if (1 || m_flNextAnimTime < gpGlobals->time)
{
SendWeaponAnim( M16_FIRE1 + RANDOM_LONG(0,2));
m_flNextAnimTime = gpGlobals->time + 0.2;
}
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
EMIT_SOUND_DYN(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/m161.wav", 1, ATTN_NORM, 0, 94 + RANDOM_LONG(0,0xf));
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
Vector vecShellVelocity = m_pPlayer->pev->velocity
+ gpGlobals->v_right * RANDOM_FLOAT(100,150)
+ gpGlobals->v_up * RANDOM_FLOAT(100,150)
+ gpGlobals->v_forward * 25;
EjectBrass ( pev->origin + m_pPlayer->pev->view_ofs
+ gpGlobals->v_up * -12
+ gpGlobals->v_forward * 28
+ gpGlobals->v_right * 6, vecShellVelocity, pev->angles.y, m_iShell, TE_BOUNCE_SHELL);
Vector vecSrc = m_pPlayer->GetGunPosition( );
Vector vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
m_pPlayer->FireBullets( 1, vecSrc, vecAiming, VECTOR_CONE_3DEGREES, 8192, BULLET_PLAYER_MP5, 0 );
if ( m_iShotCount == 3 )
{
m_flNextSecondaryAttack = gpGlobals->time + .3;
m_iShotCount = 0;
}
else
{
m_flNextSecondaryAttack = gpGlobals->time + .09;
}
m_flNextPrimaryAttack = gpGlobals->time + 0.1;
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT ( 10, 15 );
m_pPlayer->pev->punchangle.x = RANDOM_FLOAT( -2, 2 );
}
void CM16::Reload( void )
{
DefaultReload( M16_MAX_CLIP, M16_RELOAD, 1.5 );
}
void CM16::WeaponIdle( void )
{
ResetEmptySound( );
m_pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );
if (m_flTimeWeaponIdle > gpGlobals->time)
return;
int iAnim;
switch ( RANDOM_LONG( 0, 1 ) )
{
case 0:
iAnim = M16_LONGIDLE;
break;
default:
case 1:
iAnim = M16_IDLE1;
break;
}
SendWeaponAnim( iAnim );
m_flTimeWeaponIdle = gpGlobals->time + RANDOM_FLOAT ( 10, 15 );
}
class CM16AmmoClip : public CBasePlayerAmmo
{
void Spawn( void )
{
Precache( );
SET_MODEL(ENT(pev), "models/ammo/w_556mm.mdl");
CBasePlayerAmmo::Spawn( );
}
void Precache( void )
{
PRECACHE_MODEL ("models/ammo/w_556mm.mdl");
PRECACHE_SOUND("items/9mmclip1.wav");
}
BOOL AddAmmo( CBaseEntity *pOther )
{
int bResult = (pOther->GiveAmmo( AMMO_M16CLIP_GIVE, "5.56mm", M16_MAX_CARRY) != -1);
if (bResult)
{
EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
}
return bResult;
}
};
LINK_ENTITY_TO_CLASS( ammo_m16clip, CM16AmmoClip );