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.

530 lines
14 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.
*
****/
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 "effects.h"
#include "gamerules.h"
#include "tripmine.h"
#include "BMOD_messaging.h"
9 years ago
#define TRIPMINE_PRIMARY_VOLUME 450
extern cvar_t bm_trip_mod;
8 years ago
enum tripmine_e
{
9 years ago
TRIPMINE_IDLE1 = 0,
TRIPMINE_IDLE2,
TRIPMINE_ARM1,
TRIPMINE_ARM2,
TRIPMINE_FIDGET,
TRIPMINE_HOLSTER,
TRIPMINE_DRAW,
TRIPMINE_WORLD,
TRIPMINE_GROUND
9 years ago
};
#ifndef CLIENT_DLL
LINK_ENTITY_TO_CLASS( monster_tripmine, CTripmineGrenade )
9 years ago
TYPEDESCRIPTION CTripmineGrenade::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CTripmineGrenade, m_flPowerUp, FIELD_TIME ),
DEFINE_FIELD( CTripmineGrenade, m_vecDir, FIELD_VECTOR ),
DEFINE_FIELD( CTripmineGrenade, m_vecEnd, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CTripmineGrenade, m_flBeamLength, FIELD_FLOAT ),
DEFINE_FIELD( CTripmineGrenade, m_hOwner, FIELD_EHANDLE ),
DEFINE_FIELD( CTripmineGrenade, m_pBeam, FIELD_CLASSPTR ),
DEFINE_FIELD( CTripmineGrenade, m_posOwner, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CTripmineGrenade, m_angleOwner, FIELD_VECTOR ),
DEFINE_FIELD( CTripmineGrenade, m_pRealOwner, FIELD_EDICT ),
};
8 years ago
IMPLEMENT_SAVERESTORE( CTripmineGrenade, CGrenade )
9 years ago
8 years ago
void CTripmineGrenade::Spawn( void )
9 years ago
{
8 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_NOT;
8 years ago
SET_MODEL( ENT( pev ), "models/v_tripmine.mdl" );
9 years ago
pev->frame = 0;
pev->body = 3;
pev->sequence = TRIPMINE_WORLD;
8 years ago
ResetSequenceInfo();
9 years ago
pev->framerate = 0;
8 years ago
UTIL_SetSize( pev, Vector( -8, -8, -8 ), Vector( 8, 8, 8 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
8 years ago
if( pev->spawnflags & 1 )
9 years ago
{
// power up quickly
m_flPowerUp = gpGlobals->time + 1.0;
}
else
{
// power up in 2.5 seconds
m_flPowerUp = gpGlobals->time + 2.5;
}
SetThink( &CTripmineGrenade::PowerupThink );
pev->nextthink = gpGlobals->time + 0.2;
pev->takedamage = DAMAGE_YES;
pev->dmg = gSkillData.plrDmgTripmine;
pev->health = 1; // don't let die normally
8 years ago
if( pev->owner != NULL )
9 years ago
{
// play deploy sound
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "weapons/mine_deploy.wav", 1.0, ATTN_NORM );
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/mine_charge.wav", 0.2, ATTN_NORM ); // chargeup
9 years ago
m_pRealOwner = pev->owner;// see CTripmineGrenade for why.
}
UTIL_MakeAimVectors( pev->angles );
m_vecDir = gpGlobals->v_forward;
m_vecEnd = pev->origin + m_vecDir * 2048;
}
8 years ago
void CTripmineGrenade::Precache( void )
9 years ago
{
8 years ago
PRECACHE_MODEL( "models/v_tripmine.mdl" );
PRECACHE_SOUND( "weapons/mine_deploy.wav" );
PRECACHE_SOUND( "weapons/mine_activate.wav" );
PRECACHE_SOUND( "weapons/mine_charge.wav" );
9 years ago
}
8 years ago
void CTripmineGrenade::WarningThink( void )
9 years ago
{
// play warning sound
8 years ago
// EMIT_SOUND( ENT( pev ), CHAN_VOICE, "buttons/Blip2.wav", 1.0, ATTN_NORM );
9 years ago
// set to power up
SetThink( &CTripmineGrenade::PowerupThink );
pev->nextthink = gpGlobals->time + 1.0;
}
8 years ago
void CTripmineGrenade::PowerupThink( void )
9 years ago
{
TraceResult tr;
8 years ago
if( m_hOwner == NULL )
9 years ago
{
// find an owner
edict_t *oldowner = pev->owner;
pev->owner = NULL;
UTIL_TraceLine( pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 32, dont_ignore_monsters, ENT( pev ), &tr );
8 years ago
if( tr.fStartSolid || ( oldowner && tr.pHit == oldowner ) )
9 years ago
{
pev->owner = oldowner;
m_flPowerUp += 0.1;
pev->nextthink = gpGlobals->time + 0.1;
return;
}
8 years ago
if( tr.flFraction < 1.0 )
9 years ago
{
pev->owner = tr.pHit;
m_hOwner = CBaseEntity::Instance( pev->owner );
m_posOwner = m_hOwner->pev->origin;
m_angleOwner = m_hOwner->pev->angles;
}
else
{
8 years ago
STOP_SOUND( ENT( pev ), CHAN_VOICE, "weapons/mine_deploy.wav" );
STOP_SOUND( ENT( pev ), CHAN_BODY, "weapons/mine_charge.wav" );
9 years ago
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + 0.1;
ALERT( at_console, "WARNING:Tripmine at %.0f, %.0f, %.0f removed\n", pev->origin.x, pev->origin.y, pev->origin.z );
KillBeam();
return;
}
}
8 years ago
else if( m_posOwner != m_hOwner->pev->origin || m_angleOwner != m_hOwner->pev->angles )
9 years ago
{
// disable
8 years ago
STOP_SOUND( ENT( pev ), CHAN_VOICE, "weapons/mine_deploy.wav" );
STOP_SOUND( ENT( pev ), CHAN_BODY, "weapons/mine_charge.wav" );
9 years ago
CBaseEntity *pMine = Create( "weapon_tripmine", pev->origin + m_vecDir * 24, pev->angles );
pMine->pev->spawnflags |= SF_NORESPAWN;
SetThink( &CBaseEntity::SUB_Remove );
KillBeam();
pev->nextthink = gpGlobals->time + 0.1;
return;
}
// ALERT( at_console, "%d %.0f %.0f %0.f\n", pev->owner, m_pOwner->pev->origin.x, m_pOwner->pev->origin.y, m_pOwner->pev->origin.z );
8 years ago
if( gpGlobals->time > m_flPowerUp )
9 years ago
{
// make solid
pev->solid = SOLID_BBOX;
UTIL_SetOrigin( pev, pev->origin );
8 years ago
MakeBeam();
9 years ago
// play enabled sound
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "weapons/mine_activate.wav", 0.5, ATTN_NORM, 1.0, 75 );
9 years ago
}
pev->nextthink = gpGlobals->time + 0.1;
}
8 years ago
void CTripmineGrenade::KillBeam( void )
9 years ago
{
8 years ago
if( m_pBeam )
9 years ago
{
UTIL_Remove( m_pBeam );
m_pBeam = NULL;
}
}
8 years ago
void CTripmineGrenade::MakeBeam( void )
9 years ago
{
TraceResult tr;
// ALERT( at_console, "serverflags %f\n", gpGlobals->serverflags );
UTIL_TraceLine( pev->origin, m_vecEnd, dont_ignore_monsters, ENT( pev ), &tr );
m_flBeamLength = tr.flFraction;
// set to follow laser spot
SetThink( &CTripmineGrenade::BeamBreakThink );
pev->nextthink = gpGlobals->time + 0.1;
Vector vecTmpEnd = pev->origin + m_vecDir * 2048 * m_flBeamLength;
m_pBeam = CBeam::BeamCreate( g_pModelNameLaser, 10 );
m_pBeam->PointEntInit( vecTmpEnd, entindex() );
m_pBeam->SetColor( 0, 214, 198 );
m_pBeam->SetScrollRate( 255 );
m_pBeam->SetBrightness( 64 );
// BMOD Begin - no trip spawn mines and flashbang
if( m_bIsFlashbang )
{
m_pBeam->SetColor( 120, 180, 180 );
m_pBeam->SetBrightness( 25 );
}
if( BMOD_IsSpawnMine() )
{
pev->owner = m_pRealOwner;
pev->health = 0;
Killed( VARS( pev->owner ), GIB_NORMAL );
UTIL_SpeakBadWeapon();
if( m_bIsFlashbang )
UTIL_ClientPrintAll( HUD_PRINTTALK, UTIL_VarArgs( "%s tried to place a spawn flash mine!\n", STRING( VARS( pev->owner )->netname ) ) );
else
UTIL_ClientPrintAll( HUD_PRINTTALK, UTIL_VarArgs( "%s tried to place a spawn mine!\n", STRING( VARS( pev->owner )->netname ) ) );
}
// BMOD Begin - no trip spawn mines no trip spawn mines and flashbang
9 years ago
}
8 years ago
void CTripmineGrenade::BeamBreakThink( void )
9 years ago
{
BOOL bBlowup = 0;
TraceResult tr;
// HACKHACK Set simple box using this really nice global!
gpGlobals->trace_flags = FTRACE_SIMPLEBOX;
UTIL_TraceLine( pev->origin, m_vecEnd, dont_ignore_monsters, ENT( pev ), &tr );
// ALERT( at_console, "%f : %f\n", tr.flFraction, m_flBeamLength );
// respawn detect.
8 years ago
if( !m_pBeam )
9 years ago
{
8 years ago
MakeBeam();
if( tr.pHit )
9 years ago
m_hOwner = CBaseEntity::Instance( tr.pHit ); // reset owner too
}
8 years ago
if( fabs( m_flBeamLength - tr.flFraction ) > 0.001 )
9 years ago
{
bBlowup = 1;
}
else
{
8 years ago
if( m_hOwner == NULL )
9 years ago
bBlowup = 1;
8 years ago
else if( m_posOwner != m_hOwner->pev->origin )
9 years ago
bBlowup = 1;
8 years ago
else if( m_angleOwner != m_hOwner->pev->angles )
9 years ago
bBlowup = 1;
}
8 years ago
if( bBlowup )
9 years ago
{
// a bit of a hack, but all CGrenade code passes pev->owner along to make sure the proper player gets credit for the kill
// so we have to restore pev->owner from pRealOwner, because an entity's tracelines don't strike it's pev->owner which meant
// that a player couldn't trigger his own tripmine. Now that the mine is exploding, it's safe the restore the owner so the
// CGrenade code knows who the explosive really belongs to.
pev->owner = m_pRealOwner;
pev->health = 0;
Killed( VARS( pev->owner ), GIB_NORMAL );
return;
}
pev->nextthink = gpGlobals->time + 0.1;
}
8 years ago
int CTripmineGrenade::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
8 years ago
if( gpGlobals->time < m_flPowerUp && flDamage < pev->health )
9 years ago
{
// disable
// Create( "weapon_tripmine", pev->origin + m_vecDir * 24, pev->angles );
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + 0.1;
KillBeam();
return FALSE;
}
return CGrenade::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
void CTripmineGrenade::Killed( entvars_t *pevAttacker, int iGib )
{
pev->takedamage = DAMAGE_NO;
8 years ago
if( pevAttacker && ( pevAttacker->flags & FL_CLIENT ) )
9 years ago
{
// some client has destroyed this mine, he'll get credit for any kills
pev->owner = ENT( pevAttacker );
}
SetThink( &CTripmineGrenade::DelayDeathThink );
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1, 0.3 );
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "common/null.wav", 0.5, ATTN_NORM ); // shut off chargeup
9 years ago
}
void CTripmineGrenade::DelayDeathThink( void )
{
KillBeam();
TraceResult tr;
8 years ago
UTIL_TraceLine( pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 64, dont_ignore_monsters, ENT( pev ), &tr );
9 years ago
// BMod Begin - flashbang
if( m_bIsFlashbang )
FlashBang();
else
Explode( &tr, DMG_BLAST );
// BMod Begin - flashbang
9 years ago
}
#endif
LINK_ENTITY_TO_CLASS( weapon_tripmine, CTripmine )
9 years ago
8 years ago
void CTripmine::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
m_iId = WEAPON_TRIPMINE;
8 years ago
SET_MODEL( ENT( pev ), "models/v_tripmine.mdl" );
9 years ago
pev->frame = 0;
pev->body = 3;
pev->sequence = TRIPMINE_GROUND;
8 years ago
// ResetSequenceInfo();
9 years ago
pev->framerate = 0;
FallInit();// get ready to fall down
m_iDefaultAmmo = TRIPMINE_DEFAULT_GIVE;
#ifdef CLIENT_DLL
8 years ago
if( !bIsMultiplayer() )
9 years ago
#else
8 years ago
if( !g_pGameRules->IsDeathmatch() )
9 years ago
#endif
{
8 years ago
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 28 ) );
9 years ago
}
}
void CTripmine::Precache( void )
{
8 years ago
PRECACHE_MODEL( "models/v_tripmine.mdl" );
PRECACHE_MODEL( "models/p_tripmine.mdl" );
9 years ago
UTIL_PrecacheOther( "monster_tripmine" );
m_usTripFire = PRECACHE_EVENT( 1, "events/tripfire.sc" );
}
8 years ago
int CTripmine::GetItemInfo( ItemInfo *p )
9 years ago
{
8 years ago
p->pszName = STRING( pev->classname );
9 years ago
p->pszAmmo1 = "Trip Mine";
p->iMaxAmmo1 = TRIPMINE_MAX_CARRY;
p->pszAmmo2 = NULL;
p->iMaxAmmo2 = -1;
p->iMaxClip = WEAPON_NOCLIP;
p->iSlot = 4;
p->iPosition = 2;
p->iId = m_iId = WEAPON_TRIPMINE;
p->iWeight = TRIPMINE_WEIGHT;
p->iFlags = ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE;
return 1;
}
8 years ago
BOOL CTripmine::Deploy()
9 years ago
{
// BMOD Edit - tripmine mod
if( bm_trip_mod.value )
PrintMessage( m_pPlayer, BMOD_CHAN_WEAPON, Vector( 20, 250, 20 ), Vector( 1, 4, 2 ), "\nTRIPMINES\nSECONDAY FIRE: Place a flash mine." );
9 years ago
pev->body = 0;
return DefaultDeploy( "models/v_tripmine.mdl", "models/p_tripmine.mdl", TRIPMINE_DRAW, "trip" );
}
void CTripmine::Holster( int skiplocal /* = 0 */ )
{
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
8 years ago
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
9 years ago
{
// out of mines
8 years ago
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_TRIPMINE );
9 years ago
SetThink( &CBasePlayerItem::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
}
SendWeaponAnim( TRIPMINE_HOLSTER );
8 years ago
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM );
9 years ago
}
void CTripmine::PrimaryAttack( void )
{
BModAttack( FALSE );
}
void CTripmine::SecondaryAttack( void )
{
if( bm_trip_mod.value )
BModAttack( TRUE );
}
void CTripmine::BModAttack( BOOL flashbang )
9 years ago
{
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
return;
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
8 years ago
Vector vecSrc = m_pPlayer->GetGunPosition();
9 years ago
Vector vecAiming = gpGlobals->v_forward;
TraceResult tr;
UTIL_TraceLine( vecSrc, vecSrc + vecAiming * 128, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );
int flags;
#ifdef CLIENT_WEAPONS
flags = FEV_NOTHOST;
#else
flags = 0;
#endif
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usTripFire, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, 0.0, 0.0, 0, 0, 0, 0 );
8 years ago
if( tr.flFraction < 1.0 )
9 years ago
{
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
8 years ago
if( pEntity && !( pEntity->pev->flags & FL_CONVEYOR ) )
9 years ago
{
Vector angles = UTIL_VecToAngles( tr.vecPlaneNormal );
CBaseEntity *pEnt = CBaseEntity::Create( "monster_tripmine", tr.vecEndPos + tr.vecPlaneNormal * 8, angles, m_pPlayer->edict() );
// BMOD Begin - flshbang
CTripmineGrenade *pMine = (CTripmineGrenade *)pEnt;
pMine->m_bIsFlashbang = flashbang;
// BMOD End - flshbang
9 years ago
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
9 years ago
{
// no more mines!
RetireWeapon();
return;
}
}
/*else
9 years ago
{
// ALERT( at_console, "no deploy\n" );
}*/
9 years ago
}
/*else
9 years ago
{
}*/
m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.3;
9 years ago
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}
void CTripmine::WeaponIdle( void )
{
8 years ago
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
9 years ago
return;
8 years ago
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 )
9 years ago
{
SendWeaponAnim( TRIPMINE_DRAW );
}
else
{
RetireWeapon();
return;
}
int iAnim;
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
8 years ago
if( flRand <= 0.25 )
9 years ago
{
iAnim = TRIPMINE_IDLE1;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 90.0 / 30.0;
}
8 years ago
else if( flRand <= 0.75 )
9 years ago
{
iAnim = TRIPMINE_IDLE2;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0 / 30.0;
}
else
{
iAnim = TRIPMINE_FIDGET;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 100.0 / 30.0;
}
SendWeaponAnim( iAnim );
}