2022-07-19 14:29:44 +02:00
|
|
|
/***
|
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.
|
|
|
|
*
|
|
|
|
****/
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
#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"
|
|
|
|
|
|
|
|
#define TRIPMINE_PRIMARY_VOLUME 450
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
enum tripmine_e
|
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
TRIPMINE_IDLE1 = 0,
|
|
|
|
TRIPMINE_IDLE2,
|
|
|
|
TRIPMINE_ARM1,
|
|
|
|
TRIPMINE_ARM2,
|
|
|
|
TRIPMINE_FIDGET,
|
|
|
|
TRIPMINE_HOLSTER,
|
|
|
|
TRIPMINE_DRAW,
|
|
|
|
TRIPMINE_WORLD,
|
2016-06-25 18:33:39 +02:00
|
|
|
TRIPMINE_GROUND
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2021-06-07 02:05:58 +02:00
|
|
|
#if !CLIENT_DLL
|
2016-06-04 15:24:23 +02:00
|
|
|
class CTripmineGrenade : public CGrenade
|
|
|
|
{
|
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
2017-07-05 00:41:48 +02:00
|
|
|
void UpdateOnRemove();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int Save( CSave &save );
|
|
|
|
virtual int Restore( CRestore &restore );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
|
2016-07-31 15:48:50 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
void EXPORT WarningThink( void );
|
|
|
|
void EXPORT PowerupThink( void );
|
|
|
|
void EXPORT BeamBreakThink( void );
|
|
|
|
void EXPORT DelayDeathThink( void );
|
|
|
|
void Killed( entvars_t *pevAttacker, int iGib );
|
|
|
|
|
|
|
|
void MakeBeam( void );
|
|
|
|
void KillBeam( void );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
float m_flPowerUp;
|
|
|
|
Vector m_vecDir;
|
|
|
|
Vector m_vecEnd;
|
|
|
|
float m_flBeamLength;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
EHANDLE m_hOwner;
|
|
|
|
CBeam *m_pBeam;
|
|
|
|
Vector m_posOwner;
|
|
|
|
Vector m_angleOwner;
|
|
|
|
edict_t *m_pRealOwner;// tracelines don't hit PEV->OWNER, which means a player couldn't detonate his own trip mine, so we store the owner here.
|
2016-06-04 15:24:23 +02:00
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( monster_tripmine, CTripmineGrenade )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
TYPEDESCRIPTION CTripmineGrenade::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 ),
|
2022-07-11 22:36:25 +02:00
|
|
|
#if !TRIPMINE_BEAM_DUPLICATION_FIX
|
2016-06-04 15:24:23 +02:00
|
|
|
DEFINE_FIELD( CTripmineGrenade, m_pBeam, FIELD_CLASSPTR ),
|
2022-07-11 22:36:25 +02:00
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
DEFINE_FIELD( CTripmineGrenade, m_posOwner, FIELD_POSITION_VECTOR ),
|
|
|
|
DEFINE_FIELD( CTripmineGrenade, m_angleOwner, FIELD_VECTOR ),
|
|
|
|
DEFINE_FIELD( CTripmineGrenade, m_pRealOwner, FIELD_EDICT ),
|
|
|
|
};
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CTripmineGrenade, CGrenade )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::Spawn( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-25 18:33:39 +02:00
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
// motor
|
|
|
|
pev->movetype = MOVETYPE_FLY;
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), "models/v_tripmine.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->frame = 0;
|
|
|
|
pev->body = 3;
|
|
|
|
pev->sequence = TRIPMINE_WORLD;
|
2016-07-31 15:48:50 +02:00
|
|
|
ResetSequenceInfo();
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->framerate = 0;
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
UTIL_SetSize( pev, Vector( -8.0f, -8.0f, -8.0f ), Vector( 8.0f, 8.0f, 8.0f ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_SetOrigin( pev, pev->origin );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->spawnflags & 1 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// power up quickly
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flPowerUp = gpGlobals->time + 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// power up in 2.5 seconds
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flPowerUp = gpGlobals->time + 2.5f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetThink( &CTripmineGrenade::PowerupThink );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.2f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pev->takedamage = DAMAGE_YES;
|
|
|
|
pev->dmg = gSkillData.plrDmgTripmine;
|
|
|
|
pev->health = 1; // don't let die normally
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pev->owner != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// play deploy sound
|
2016-07-31 15:48:50 +02:00
|
|
|
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
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pRealOwner = pev->owner;// see CTripmineGrenade for why.
|
|
|
|
}
|
|
|
|
|
|
|
|
UTIL_MakeAimVectors( pev->angles );
|
|
|
|
|
|
|
|
m_vecDir = gpGlobals->v_forward;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_vecEnd = pev->origin + m_vecDir * 2048.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PRECACHE_MODEL( "models/v_tripmine.mdl" );
|
|
|
|
PRECACHE_SOUND( "weapons/mine_deploy.wav" );
|
|
|
|
PRECACHE_SOUND( "weapons/mine_activate.wav" );
|
|
|
|
PRECACHE_SOUND( "weapons/mine_charge.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2017-07-05 00:41:48 +02:00
|
|
|
void CTripmineGrenade::UpdateOnRemove()
|
|
|
|
{
|
|
|
|
CBaseEntity::UpdateOnRemove();
|
|
|
|
|
|
|
|
KillBeam();
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::WarningThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// play warning sound
|
2016-07-31 15:48:50 +02:00
|
|
|
// EMIT_SOUND( ENT( pev ), CHAN_VOICE, "buttons/Blip2.wav", 1.0, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// set to power up
|
|
|
|
SetThink( &CTripmineGrenade::PowerupThink );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 1.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::PowerupThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
TraceResult tr;
|
|
|
|
|
2017-06-29 15:56:03 +02:00
|
|
|
if( m_hOwner == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// find an owner
|
|
|
|
edict_t *oldowner = pev->owner;
|
|
|
|
pev->owner = NULL;
|
2019-10-13 13:49:25 +02:00
|
|
|
UTIL_TraceLine( pev->origin + m_vecDir * 8.0f, pev->origin - m_vecDir * 32.0f, dont_ignore_monsters, ENT( pev ), &tr );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr.fStartSolid || ( oldowner && tr.pHit == oldowner ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->owner = oldowner;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flPowerUp += 0.1f;
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-10-13 13:49:25 +02:00
|
|
|
if( tr.flFraction < 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->owner = tr.pHit;
|
|
|
|
m_hOwner = CBaseEntity::Instance( pev->owner );
|
|
|
|
m_posOwner = m_hOwner->pev->origin;
|
|
|
|
m_angleOwner = m_hOwner->pev->angles;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
STOP_SOUND( ENT( pev ), CHAN_VOICE, "weapons/mine_deploy.wav" );
|
|
|
|
STOP_SOUND( ENT( pev ), CHAN_BODY, "weapons/mine_charge.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
|
|
|
ALERT( at_console, "WARNING:Tripmine at %.0f, %.0f, %.0f removed\n", (double)pev->origin.x, (double)pev->origin.y, (double)pev->origin.z );
|
2016-06-04 15:24:23 +02:00
|
|
|
KillBeam();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( m_posOwner != m_hOwner->pev->origin || m_angleOwner != m_hOwner->pev->angles )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// disable
|
2016-07-31 15:48:50 +02:00
|
|
|
STOP_SOUND( ENT( pev ), CHAN_VOICE, "weapons/mine_deploy.wav" );
|
|
|
|
STOP_SOUND( ENT( pev ), CHAN_BODY, "weapons/mine_charge.wav" );
|
2019-10-13 13:49:25 +02:00
|
|
|
CBaseEntity *pMine = Create( "weapon_tripmine", pev->origin + m_vecDir * 24.0f, pev->angles );
|
2016-06-04 15:24:23 +02:00
|
|
|
pMine->pev->spawnflags |= SF_NORESPAWN;
|
|
|
|
|
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
|
|
|
KillBeam();
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
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 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( gpGlobals->time > m_flPowerUp )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// make solid
|
|
|
|
pev->solid = SOLID_BBOX;
|
|
|
|
UTIL_SetOrigin( pev, pev->origin );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
MakeBeam();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// play enabled sound
|
2017-06-29 15:56:03 +02:00
|
|
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "weapons/mine_activate.wav", 0.5, ATTN_NORM, 1, 75 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::KillBeam( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_Remove( m_pBeam );
|
|
|
|
m_pBeam = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::MakeBeam( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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 );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
Vector vecTmpEnd = pev->origin + m_vecDir * 2048.0f * m_flBeamLength;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pBeam = CBeam::BeamCreate( g_pModelNameLaser, 10 );
|
2022-07-11 22:36:25 +02:00
|
|
|
#if TRIPMINE_BEAM_DUPLICATION_FIX
|
|
|
|
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY;
|
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
m_pBeam->PointEntInit( vecTmpEnd, entindex() );
|
|
|
|
m_pBeam->SetColor( 0, 214, 198 );
|
|
|
|
m_pBeam->SetScrollRate( 255 );
|
|
|
|
m_pBeam->SetBrightness( 64 );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmineGrenade::BeamBreakThink( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
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.
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !m_pBeam )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2022-09-26 16:55:19 +02:00
|
|
|
#if TRIPMINE_BEAM_DUPLICATION_FIX
|
|
|
|
// Use the same trace parameters as the original trace above so the right entity is hit.
|
|
|
|
TraceResult tr2;
|
|
|
|
UTIL_TraceLine( pev->origin + m_vecDir * 8.0f, pev->origin - m_vecDir * 32.0f, dont_ignore_monsters, ENT( pev ), &tr2 );
|
|
|
|
#endif
|
2016-07-31 15:48:50 +02:00
|
|
|
MakeBeam();
|
2022-09-26 16:55:19 +02:00
|
|
|
#if TRIPMINE_BEAM_DUPLICATION_FIX
|
|
|
|
if( tr2.pHit )
|
|
|
|
{
|
|
|
|
// reset owner too
|
|
|
|
pev->owner = tr2.pHit;
|
|
|
|
m_hOwner = CBaseEntity::Instance( tr2.pHit );
|
|
|
|
}
|
|
|
|
#else
|
2016-07-31 15:48:50 +02:00
|
|
|
if( tr.pHit )
|
2016-06-04 15:24:23 +02:00
|
|
|
m_hOwner = CBaseEntity::Instance( tr.pHit ); // reset owner too
|
2022-09-26 16:55:19 +02:00
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( fabs( m_flBeamLength - tr.flFraction ) > 0.001f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
bBlowup = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-29 15:56:03 +02:00
|
|
|
if( m_hOwner == 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
bBlowup = 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( m_posOwner != m_hOwner->pev->origin )
|
2016-06-04 15:24:23 +02:00
|
|
|
bBlowup = 1;
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( m_angleOwner != m_hOwner->pev->angles )
|
2016-06-04 15:24:23 +02:00
|
|
|
bBlowup = 1;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( bBlowup )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CTripmineGrenade::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( gpGlobals->time < m_flPowerUp && flDamage < pev->health )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// disable
|
2019-10-13 13:49:25 +02:00
|
|
|
// Create( "weapon_tripmine", pev->origin + m_vecDir * 24.0f, pev->angles );
|
2016-06-04 15:24:23 +02:00
|
|
|
SetThink( &CBaseEntity::SUB_Remove );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1f;
|
2016-06-04 15:24:23 +02:00
|
|
|
KillBeam();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return CGrenade::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmineGrenade::Killed( entvars_t *pevAttacker, int iGib )
|
|
|
|
{
|
|
|
|
pev->takedamage = DAMAGE_NO;
|
2016-07-31 15:48:50 +02:00
|
|
|
|
|
|
|
if( pevAttacker && ( pevAttacker->flags & FL_CLIENT ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// some client has destroyed this mine, he'll get credit for any kills
|
|
|
|
pev->owner = ENT( pevAttacker );
|
|
|
|
}
|
|
|
|
|
|
|
|
SetThink( &CTripmineGrenade::DelayDeathThink );
|
2019-10-13 13:49:25 +02:00
|
|
|
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1f, 0.3f );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
EMIT_SOUND( ENT( pev ), CHAN_BODY, "common/null.wav", 0.5f, ATTN_NORM ); // shut off chargeup
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmineGrenade::DelayDeathThink( void )
|
|
|
|
{
|
|
|
|
KillBeam();
|
|
|
|
TraceResult tr;
|
2019-10-13 13:49:25 +02:00
|
|
|
UTIL_TraceLine( pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 64.0f, dont_ignore_monsters, ENT( pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
Explode( &tr, DMG_BLAST );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( weapon_tripmine, CTripmine )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CTripmine::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_TRIPMINE;
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), "models/v_tripmine.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->frame = 0;
|
2022-08-05 15:21:43 +02:00
|
|
|
|
|
|
|
#ifdef CLIENT_DLL
|
|
|
|
pev->body = 0;
|
|
|
|
#else
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->body = 3;
|
2022-08-05 15:21:43 +02:00
|
|
|
#endif
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->sequence = TRIPMINE_GROUND;
|
2016-07-31 15:48:50 +02:00
|
|
|
// ResetSequenceInfo();
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->framerate = 0;
|
|
|
|
|
|
|
|
FallInit();// get ready to fall down
|
|
|
|
|
|
|
|
m_iDefaultAmmo = TRIPMINE_DEFAULT_GIVE;
|
|
|
|
|
2021-06-07 02:05:58 +02:00
|
|
|
#if CLIENT_DLL
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !bIsMultiplayer() )
|
2016-06-04 15:24:23 +02:00
|
|
|
#else
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !g_pGameRules->IsDeathmatch() )
|
2016-06-04 15:24:23 +02:00
|
|
|
#endif
|
|
|
|
{
|
2019-10-13 13:49:25 +02:00
|
|
|
UTIL_SetSize( pev, Vector( -16.0f, -16.0f, 0.0f ), Vector( 16.0f, 16.0f, 28.0f ) );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmine::Precache( void )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PRECACHE_MODEL( "models/v_tripmine.mdl" );
|
|
|
|
PRECACHE_MODEL( "models/p_tripmine.mdl" );
|
2016-06-04 15:24:23 +02:00
|
|
|
UTIL_PrecacheOther( "monster_tripmine" );
|
|
|
|
|
|
|
|
m_usTripFire = PRECACHE_EVENT( 1, "events/tripfire.sc" );
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int CTripmine::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 = "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;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
BOOL CTripmine::Deploy()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->body = 0;
|
|
|
|
return DefaultDeploy( "models/v_tripmine.mdl", "models/p_tripmine.mdl", TRIPMINE_DRAW, "trip" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmine::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
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// out of mines
|
2016-07-31 15:48:50 +02:00
|
|
|
m_pPlayer->pev->weapons &= ~( 1 << WEAPON_TRIPMINE );
|
2017-07-23 18:41:05 +02:00
|
|
|
DestroyItem();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendWeaponAnim( TRIPMINE_HOLSTER );
|
2019-10-13 13:49:25 +02:00
|
|
|
EMIT_SOUND( ENT( m_pPlayer->pev ), CHAN_WEAPON, "common/null.wav", 1.0f, ATTN_NORM );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmine::PrimaryAttack( void )
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
UTIL_MakeVectors( m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle );
|
2016-07-31 15:48:50 +02:00
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition();
|
2016-06-04 15:24:23 +02:00
|
|
|
Vector vecAiming = gpGlobals->v_forward;
|
|
|
|
|
|
|
|
TraceResult tr;
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
UTIL_TraceLine( vecSrc, vecSrc + vecAiming * 128.0f, dont_ignore_monsters, ENT( m_pPlayer->pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
int flags;
|
2021-06-07 02:05:58 +02:00
|
|
|
#if CLIENT_WEAPONS
|
2016-06-04 15:24:23 +02:00
|
|
|
flags = FEV_NOTHOST;
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
2022-08-05 15:22:36 +02:00
|
|
|
PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), m_usTripFire, 0.0f, g_vecZero, g_vecZero, 0.0f, 0.0f, 0, 0, m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] == 1, 0 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
if( tr.flFraction < 1.0f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pEntity && !( pEntity->pev->flags & FL_CONVEYOR ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector angles = UTIL_VecToAngles( tr.vecPlaneNormal );
|
|
|
|
|
2019-10-13 13:49:25 +02:00
|
|
|
CBaseEntity::Create( "monster_tripmine", tr.vecEndPos + tr.vecPlaneNormal * 8.0f, angles, m_pPlayer->edict() );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
|
|
|
|
|
|
|
|
// player "shoot" animation
|
|
|
|
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// no more mines!
|
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-06-25 18:33:39 +02:00
|
|
|
/*else
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
// ALERT( at_console, "no deploy\n" );
|
2016-06-25 18:33:39 +02:00
|
|
|
}*/
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2016-06-25 18:33:39 +02:00
|
|
|
/*else
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
}*/
|
|
|
|
|
2017-06-26 02:47:19 +02:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay( 0.3 );
|
2016-06-04 15:24:23 +02:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTripmine::WeaponIdle( void )
|
|
|
|
{
|
2022-07-08 19:17:50 +02:00
|
|
|
pev->body = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
|
2016-06-04 15:24:23 +02:00
|
|
|
return;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
SendWeaponAnim( TRIPMINE_DRAW );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iAnim;
|
|
|
|
float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0, 1 );
|
2019-10-13 13:49:25 +02:00
|
|
|
if( flRand <= 0.25f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_IDLE1;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 90.0f / 30.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
2019-10-13 13:49:25 +02:00
|
|
|
else if( flRand <= 0.75f )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_IDLE2;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0f / 30.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_FIDGET;
|
2019-10-13 13:49:25 +02:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 100.0f / 30.0f;
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendWeaponAnim( iAnim );
|
|
|
|
}
|