2022-12-17 13:32:43 +01:00
|
|
|
/***
|
2013-08-30 13:34:05 -07:00
|
|
|
*
|
|
|
|
* Copyright (c) 1996-2001, 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 "player.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "gamerules.h"
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
#define TRIPMINE_PRIMARY_VOLUME 450
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
|
|
|
|
class CTripmineGrenade : public CGrenade
|
|
|
|
{
|
2021-03-05 23:07:22 +01:00
|
|
|
void Spawn() override;
|
|
|
|
void Precache() override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
bool Save(CSave& save) override;
|
|
|
|
bool Restore(CRestore& restore) override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
static TYPEDESCRIPTION m_SaveData[];
|
|
|
|
|
|
|
|
bool TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType) override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void EXPORT WarningThink();
|
|
|
|
void EXPORT PowerupThink();
|
|
|
|
void EXPORT BeamBreakThink();
|
|
|
|
void EXPORT DelayDeathThink();
|
2021-11-28 16:54:48 +01:00
|
|
|
void Killed(entvars_t* pevAttacker, int iGib) override;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void MakeBeam();
|
|
|
|
void KillBeam();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
float m_flPowerUp;
|
|
|
|
Vector m_vecDir;
|
|
|
|
Vector m_vecEnd;
|
|
|
|
float m_flBeamLength;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01: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.
|
2013-08-30 13:34:05 -07:00
|
|
|
};
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
LINK_ENTITY_TO_CLASS(monster_tripmine, CTripmineGrenade);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
TYPEDESCRIPTION CTripmineGrenade::m_SaveData[] =
|
|
|
|
{
|
|
|
|
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-02-10 15:42:58 +01:00
|
|
|
//Don't save, recreate.
|
|
|
|
//DEFINE_FIELD(CTripmineGrenade, m_pBeam, FIELD_CLASSPTR),
|
2021-11-28 16:54:48 +01:00
|
|
|
DEFINE_FIELD(CTripmineGrenade, m_posOwner, FIELD_POSITION_VECTOR),
|
|
|
|
DEFINE_FIELD(CTripmineGrenade, m_angleOwner, FIELD_VECTOR),
|
|
|
|
DEFINE_FIELD(CTripmineGrenade, m_pRealOwner, FIELD_EDICT),
|
2013-08-30 13:34:05 -07:00
|
|
|
};
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
IMPLEMENT_SAVERESTORE(CTripmineGrenade, CGrenade);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::Spawn()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
Precache();
|
2013-08-30 13:34:05 -07:00
|
|
|
// motor
|
|
|
|
pev->movetype = MOVETYPE_FLY;
|
|
|
|
pev->solid = SOLID_NOT;
|
|
|
|
|
|
|
|
SET_MODEL(ENT(pev), "models/v_tripmine.mdl");
|
|
|
|
pev->frame = 0;
|
|
|
|
pev->body = 3;
|
|
|
|
pev->sequence = TRIPMINE_WORLD;
|
2021-11-28 16:54:48 +01:00
|
|
|
ResetSequenceInfo();
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->framerate = 0;
|
2021-11-28 16:54:48 +01:00
|
|
|
|
|
|
|
UTIL_SetSize(pev, Vector(-8, -8, -8), Vector(8, 8, 8));
|
|
|
|
UTIL_SetOrigin(pev, pev->origin);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 15:32:26 +01:00
|
|
|
//TODO: define constant
|
|
|
|
if ((pev->spawnflags & 1) != 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
// power up quickly
|
|
|
|
m_flPowerUp = gpGlobals->time + 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// power up in 2.5 seconds
|
|
|
|
m_flPowerUp = gpGlobals->time + 2.5;
|
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::PowerupThink);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 0.2;
|
|
|
|
|
|
|
|
pev->takedamage = DAMAGE_YES;
|
|
|
|
pev->dmg = gSkillData.plrDmgTripmine;
|
|
|
|
pev->health = 1; // don't let die normally
|
|
|
|
|
|
|
|
if (pev->owner != NULL)
|
|
|
|
{
|
|
|
|
// play deploy sound
|
2021-11-28 16:54:48 +01: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
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
m_pRealOwner = pev->owner; // see CTripmineGrenade for why.
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_MakeAimVectors(pev->angles);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
m_vecDir = gpGlobals->v_forward;
|
|
|
|
m_vecEnd = pev->origin + m_vecDir * 2048;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::Precache()
|
2013-08-30 13:34:05 -07: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");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::WarningThink()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
// play warning sound
|
|
|
|
// EMIT_SOUND( ENT(pev), CHAN_VOICE, "buttons/Blip2.wav", 1.0, ATTN_NORM );
|
|
|
|
|
|
|
|
// set to power up
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::PowerupThink);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::PowerupThink()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
TraceResult tr;
|
|
|
|
|
|
|
|
if (m_hOwner == NULL)
|
|
|
|
{
|
|
|
|
// find an owner
|
2021-11-28 16:54:48 +01:00
|
|
|
edict_t* oldowner = pev->owner;
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->owner = NULL;
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_TraceLine(pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 32, dont_ignore_monsters, ENT(pev), &tr);
|
2021-11-28 15:32:26 +01:00
|
|
|
if (0 != tr.fStartSolid || (oldowner && tr.pHit == oldowner))
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->owner = oldowner;
|
|
|
|
m_flPowerUp += 0.1;
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tr.flFraction < 1.0)
|
|
|
|
{
|
|
|
|
pev->owner = tr.pHit;
|
2021-11-28 16:54:48 +01:00
|
|
|
m_hOwner = CBaseEntity::Instance(pev->owner);
|
2013-08-30 13:34:05 -07:00
|
|
|
m_posOwner = m_hOwner->pev->origin;
|
|
|
|
m_angleOwner = m_hOwner->pev->angles;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
STOP_SOUND(ENT(pev), CHAN_VOICE, "weapons/mine_deploy.wav");
|
|
|
|
STOP_SOUND(ENT(pev), CHAN_BODY, "weapons/mine_charge.wav");
|
|
|
|
SetThink(&CTripmineGrenade::SUB_Remove);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
2021-11-28 16:54:48 +01:00
|
|
|
ALERT(at_console, "WARNING:Tripmine at %.0f, %.0f, %.0f removed\n", pev->origin.x, pev->origin.y, pev->origin.z);
|
2013-08-30 13:34:05 -07:00
|
|
|
KillBeam();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_posOwner != m_hOwner->pev->origin || m_angleOwner != m_hOwner->pev->angles)
|
|
|
|
{
|
|
|
|
// disable
|
2021-11-28 16:54:48 +01:00
|
|
|
STOP_SOUND(ENT(pev), CHAN_VOICE, "weapons/mine_deploy.wav");
|
|
|
|
STOP_SOUND(ENT(pev), CHAN_BODY, "weapons/mine_charge.wav");
|
|
|
|
CBaseEntity* pMine = Create("weapon_tripmine", pev->origin + m_vecDir * 24, pev->angles);
|
2013-08-30 13:34:05 -07:00
|
|
|
pMine->pev->spawnflags |= SF_NORESPAWN;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::SUB_Remove);
|
2013-08-30 13:34:05 -07:00
|
|
|
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 );
|
2021-11-28 16:54:48 +01:00
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
if (gpGlobals->time > m_flPowerUp)
|
|
|
|
{
|
|
|
|
// make solid
|
|
|
|
pev->solid = SOLID_BBOX;
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_SetOrigin(pev, pev->origin);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
MakeBeam();
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
// play enabled sound
|
2021-11-28 16:54:48 +01:00
|
|
|
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "weapons/mine_activate.wav", 0.5, ATTN_NORM, 1.0, 75);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::KillBeam()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
if (m_pBeam)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_Remove(m_pBeam);
|
2013-08-30 13:34:05 -07:00
|
|
|
m_pBeam = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::MakeBeam()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
TraceResult tr;
|
|
|
|
|
|
|
|
// ALERT( at_console, "serverflags %f\n", gpGlobals->serverflags );
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_TraceLine(pev->origin, m_vecEnd, dont_ignore_monsters, ENT(pev), &tr);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
m_flBeamLength = tr.flFraction;
|
|
|
|
|
|
|
|
// set to follow laser spot
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::BeamBreakThink);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
|
|
|
|
Vector vecTmpEnd = pev->origin + m_vecDir * 2048 * m_flBeamLength;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
m_pBeam = CBeam::BeamCreate(g_pModelNameLaser, 10);
|
2022-02-10 15:42:58 +01:00
|
|
|
//Mark as temporary so the beam will be recreated on save game load and level transitions.
|
|
|
|
m_pBeam->pev->spawnflags |= SF_BEAM_TEMPORARY;
|
2022-02-09 14:06:37 +01:00
|
|
|
//PointEntInit causes clients to use the position of whatever the previous entity to use this edict had until the server updates them.
|
|
|
|
//m_pBeam->PointEntInit(vecTmpEnd, entindex());
|
|
|
|
m_pBeam->PointsInit(pev->origin, vecTmpEnd);
|
2021-11-28 16:54:48 +01:00
|
|
|
m_pBeam->SetColor(0, 214, 198);
|
|
|
|
m_pBeam->SetScrollRate(255);
|
|
|
|
m_pBeam->SetBrightness(64);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
void CTripmineGrenade::BeamBreakThink()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 15:32:26 +01:00
|
|
|
bool bBlowup = false;
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
TraceResult tr;
|
|
|
|
|
|
|
|
// HACKHACK Set simple box using this really nice global!
|
|
|
|
gpGlobals->trace_flags = FTRACE_SIMPLEBOX;
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_TraceLine(pev->origin, m_vecEnd, dont_ignore_monsters, ENT(pev), &tr);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
// ALERT( at_console, "%f : %f\n", tr.flFraction, m_flBeamLength );
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
// respawn detect.
|
|
|
|
if (!m_pBeam)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2022-09-26 10:32:39 +02:00
|
|
|
// Use the same trace parameters as the original trace above so the right entity is hit.
|
|
|
|
TraceResult tr2;
|
2023-03-01 19:15:24 +01:00
|
|
|
// Clear out old owner so it can be hit by traces.
|
|
|
|
pev->owner = nullptr;
|
2022-09-26 10:32:39 +02:00
|
|
|
UTIL_TraceLine(pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 32, dont_ignore_monsters, ENT(pev), &tr2);
|
2021-11-28 16:54:48 +01:00
|
|
|
MakeBeam();
|
2022-09-26 10:32:39 +02:00
|
|
|
if (tr2.pHit)
|
|
|
|
{
|
|
|
|
// reset owner too
|
|
|
|
pev->owner = tr2.pHit;
|
|
|
|
m_hOwner = CBaseEntity::Instance(tr2.pHit);
|
|
|
|
}
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
if (fabs(m_flBeamLength - tr.flFraction) > 0.001)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 15:32:26 +01:00
|
|
|
bBlowup = true;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_hOwner == NULL)
|
2021-11-28 15:32:26 +01:00
|
|
|
bBlowup = true;
|
2013-08-30 13:34:05 -07:00
|
|
|
else if (m_posOwner != m_hOwner->pev->origin)
|
2021-11-28 15:32:26 +01:00
|
|
|
bBlowup = true;
|
2013-08-30 13:34:05 -07:00
|
|
|
else if (m_angleOwner != m_hOwner->pev->angles)
|
2021-11-28 15:32:26 +01:00
|
|
|
bBlowup = true;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bBlowup)
|
|
|
|
{
|
|
|
|
// 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
|
2021-11-28 16:54:48 +01:00
|
|
|
// that a player couldn't trigger his own tripmine. Now that the mine is exploding, it's safe the restore the owner so the
|
2013-08-30 13:34:05 -07:00
|
|
|
// CGrenade code knows who the explosive really belongs to.
|
|
|
|
pev->owner = m_pRealOwner;
|
|
|
|
pev->health = 0;
|
2021-11-28 16:54:48 +01:00
|
|
|
Killed(VARS(pev->owner), GIB_NORMAL);
|
2013-08-30 13:34:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
|
2021-11-29 20:31:17 +01:00
|
|
|
bool CTripmineGrenade::TakeDamage(entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
if (gpGlobals->time < m_flPowerUp && flDamage < pev->health)
|
|
|
|
{
|
|
|
|
// disable
|
|
|
|
// Create( "weapon_tripmine", pev->origin + m_vecDir * 24, pev->angles );
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::SUB_Remove);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
KillBeam();
|
2021-11-19 13:43:33 +01:00
|
|
|
return false;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
2021-11-28 16:54:48 +01:00
|
|
|
return CGrenade::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void CTripmineGrenade::Killed(entvars_t* pevAttacker, int iGib)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
pev->takedamage = DAMAGE_NO;
|
2021-11-28 16:54:48 +01:00
|
|
|
|
|
|
|
if (pevAttacker && (pevAttacker->flags & FL_CLIENT) != 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
// some client has destroyed this mine, he'll get credit for any kills
|
2021-11-28 16:54:48 +01:00
|
|
|
pev->owner = ENT(pevAttacker);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmineGrenade::DelayDeathThink);
|
|
|
|
pev->nextthink = gpGlobals->time + RANDOM_FLOAT(0.1, 0.3);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
EMIT_SOUND(ENT(pev), CHAN_BODY, "common/null.wav", 0.5, ATTN_NORM); // shut off chargeup
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void CTripmineGrenade::DelayDeathThink()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
KillBeam();
|
|
|
|
TraceResult tr;
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_TraceLine(pev->origin + m_vecDir * 8, pev->origin - m_vecDir * 64, dont_ignore_monsters, ENT(pev), &tr);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
Explode(&tr, DMG_BLAST);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
LINK_ENTITY_TO_CLASS(weapon_tripmine, CTripmine);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
void CTripmine::Spawn()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
Precache();
|
2013-08-30 13:34:05 -07:00
|
|
|
m_iId = WEAPON_TRIPMINE;
|
|
|
|
SET_MODEL(ENT(pev), "models/v_tripmine.mdl");
|
|
|
|
pev->frame = 0;
|
|
|
|
pev->body = 3;
|
|
|
|
pev->sequence = TRIPMINE_GROUND;
|
|
|
|
// ResetSequenceInfo( );
|
|
|
|
pev->framerate = 0;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
FallInit(); // get ready to fall down
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
m_iDefaultAmmo = TRIPMINE_DEFAULT_GIVE;
|
|
|
|
|
2022-01-19 16:58:35 +01:00
|
|
|
//HACK: force the body to the first person view by default so it doesn't show up as a huge tripmine for a second.
|
|
|
|
#ifdef CLIENT_DLL
|
|
|
|
pev->body = 0;
|
|
|
|
#endif
|
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
#ifdef CLIENT_DLL
|
2021-11-28 16:54:48 +01:00
|
|
|
if (!bIsMultiplayer())
|
2013-08-30 13:34:05 -07:00
|
|
|
#else
|
2021-11-28 16:54:48 +01:00
|
|
|
if (!g_pGameRules->IsDeathmatch())
|
2013-08-30 13:34:05 -07:00
|
|
|
#endif
|
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_SetSize(pev, Vector(-16, -16, 0), Vector(16, 16, 28));
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void CTripmine::Precache()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
PRECACHE_MODEL("models/v_tripmine.mdl");
|
|
|
|
PRECACHE_MODEL("models/p_tripmine.mdl");
|
|
|
|
UTIL_PrecacheOther("monster_tripmine");
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
m_usTripFire = PRECACHE_EVENT(1, "events/tripfire.sc");
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
bool CTripmine::GetItemInfo(ItemInfo* p)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
p->pszName = STRING(pev->classname);
|
|
|
|
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;
|
|
|
|
|
2021-11-28 15:32:26 +01:00
|
|
|
return true;
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
bool CTripmine::Deploy()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-01-31 15:29:40 +01:00
|
|
|
pev->body = 0;
|
2021-11-28 16:54:48 +01:00
|
|
|
return DefaultDeploy("models/v_tripmine.mdl", "models/p_tripmine.mdl", TRIPMINE_DRAW, "trip");
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-21 14:00:29 +02:00
|
|
|
void CTripmine::Holster()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 0.5;
|
|
|
|
|
2021-11-28 15:32:26 +01:00
|
|
|
if (0 == m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType])
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
// out of mines
|
2021-12-02 13:49:56 +01:00
|
|
|
m_pPlayer->ClearWeaponBit(m_iId);
|
2021-11-28 16:54:48 +01:00
|
|
|
SetThink(&CTripmine::DestroyItem);
|
2013-08-30 13:34:05 -07:00
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
SendWeaponAnim(TRIPMINE_HOLSTER);
|
2013-08-30 13:34:05 -07:00
|
|
|
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);
|
|
|
|
}
|
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void CTripmine::PrimaryAttack()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
|
|
|
return;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_MakeVectors(m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle);
|
|
|
|
Vector vecSrc = m_pPlayer->GetGunPosition();
|
2013-08-30 13:34:05 -07:00
|
|
|
Vector vecAiming = gpGlobals->v_forward;
|
|
|
|
|
|
|
|
TraceResult tr;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
UTIL_TraceLine(vecSrc, vecSrc + vecAiming * 128, dont_ignore_monsters, ENT(m_pPlayer->pev), &tr);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
int flags;
|
|
|
|
#ifdef CLIENT_WEAPONS
|
|
|
|
flags = FEV_NOTHOST;
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usTripFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
if (tr.flFraction < 1.0)
|
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
CBaseEntity* pEntity = CBaseEntity::Instance(tr.pHit);
|
|
|
|
if (pEntity && (pEntity->pev->flags & FL_CONVEYOR) == 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
Vector angles = UTIL_VecToAngles(tr.vecPlaneNormal);
|
2013-08-30 13:34:05 -07:00
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
CBaseEntity* pEnt = CBaseEntity::Create("monster_tripmine", tr.vecEndPos + tr.vecPlaneNormal * 8, angles, m_pPlayer->edict());
|
2013-08-30 13:34:05 -07:00
|
|
|
|
|
|
|
m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;
|
|
|
|
|
|
|
|
// player "shoot" animation
|
2021-11-28 16:54:48 +01:00
|
|
|
m_pPlayer->SetAnimation(PLAYER_ATTACK1);
|
|
|
|
|
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
// no more mines!
|
2013-08-30 13:34:05 -07:00
|
|
|
RetireWeapon();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ALERT( at_console, "no deploy\n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
2021-11-28 16:54:48 +01:00
|
|
|
|
2013-08-30 13:34:05 -07:00
|
|
|
m_flNextPrimaryAttack = GetNextAttackDelay(0.3);
|
2021-11-28 16:54:48 +01:00
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat(m_pPlayer->random_seed, 10, 15);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
|
2021-03-05 20:54:33 +01:00
|
|
|
void CTripmine::WeaponIdle()
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-02-27 12:59:51 +01:00
|
|
|
//If we're here then we're in a player's inventory, and need to use this body
|
|
|
|
pev->body = 0;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())
|
2013-08-30 13:34:05 -07:00
|
|
|
return;
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0)
|
2013-08-30 13:34:05 -07:00
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
SendWeaponAnim(TRIPMINE_DRAW);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-28 16:54:48 +01:00
|
|
|
RetireWeapon();
|
2013-08-30 13:34:05 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iAnim;
|
2021-11-28 16:54:48 +01:00
|
|
|
float flRand = UTIL_SharedRandomFloat(m_pPlayer->random_seed, 0, 1);
|
2013-08-30 13:34:05 -07:00
|
|
|
if (flRand <= 0.25)
|
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_IDLE1;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 90.0 / 30.0;
|
|
|
|
}
|
|
|
|
else if (flRand <= 0.75)
|
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_IDLE2;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 60.0 / 30.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iAnim = TRIPMINE_FIDGET;
|
|
|
|
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 100.0 / 30.0;
|
|
|
|
}
|
|
|
|
|
2021-11-28 16:54:48 +01:00
|
|
|
SendWeaponAnim(iAnim);
|
2013-08-30 13:34:05 -07:00
|
|
|
}
|