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.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
/*
|
|
|
|
|
|
|
|
===== mortar.cpp ========================================================
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
the "LaBuznik" mortar device
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "extdll.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "cbase.h"
|
|
|
|
#include "saverestore.h"
|
|
|
|
#include "weapons.h"
|
|
|
|
#include "decals.h"
|
|
|
|
#include "soundent.h"
|
|
|
|
|
|
|
|
class CFuncMortarField : public CBaseToggle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
void KeyValue( KeyValueData *pkvd );
|
|
|
|
|
|
|
|
// Bmodels don't go across transitions
|
2016-07-31 15:48:50 +02:00
|
|
|
virtual int ObjectCaps( void ) { return CBaseToggle::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
|
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
|
|
|
|
|
|
|
void EXPORT FieldUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
|
|
|
|
|
|
|
|
int m_iszXController;
|
|
|
|
int m_iszYController;
|
|
|
|
float m_flSpread;
|
|
|
|
float m_flDelay;
|
|
|
|
int m_iCount;
|
|
|
|
int m_fControl;
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( func_mortar_field, CFuncMortarField )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
TYPEDESCRIPTION CFuncMortarField::m_SaveData[] =
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_iszXController, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_iszYController, FIELD_STRING ),
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_flSpread, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_flDelay, FIELD_FLOAT ),
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_iCount, FIELD_INTEGER ),
|
|
|
|
DEFINE_FIELD( CFuncMortarField, m_fControl, FIELD_INTEGER ),
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
IMPLEMENT_SAVERESTORE( CFuncMortarField, CBaseToggle )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CFuncMortarField::KeyValue( KeyValueData *pkvd )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
if( FStrEq( pkvd->szKeyName, "m_iszXController" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iszXController = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_iszYController" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iszYController = ALLOC_STRING( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_flSpread" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_flSpread = atof( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_fControl" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_fControl = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
else if( FStrEq( pkvd->szKeyName, "m_iCount" ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
m_iCount = atoi( pkvd->szValue );
|
2016-06-04 15:24:23 +02:00
|
|
|
pkvd->fHandled = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop bombs from above
|
2016-07-31 15:48:50 +02:00
|
|
|
void CFuncMortarField::Spawn( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
pev->solid = SOLID_NOT;
|
2016-07-31 15:48:50 +02:00
|
|
|
SET_MODEL( ENT( pev ), STRING( pev->model ) ); // set size and link into world
|
2016-06-04 15:24:23 +02:00
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
SetBits( pev->effects, EF_NODRAW );
|
|
|
|
SetUse( &CFuncMortarField::FieldUse );
|
|
|
|
Precache();
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CFuncMortarField::Precache( void )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
PRECACHE_SOUND( "weapons/mortar.wav" );
|
|
|
|
PRECACHE_SOUND( "weapons/mortarhit.wav" );
|
2016-06-04 15:24:23 +02:00
|
|
|
PRECACHE_MODEL( "sprites/lgtning.spr" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// If connected to a table, then use the table controllers, else hit where the trigger is.
|
2016-07-31 15:48:50 +02:00
|
|
|
void CFuncMortarField::FieldUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector vecStart;
|
|
|
|
|
|
|
|
vecStart.x = RANDOM_FLOAT( pev->mins.x, pev->maxs.x );
|
|
|
|
vecStart.y = RANDOM_FLOAT( pev->mins.y, pev->maxs.y );
|
|
|
|
vecStart.z = pev->maxs.z;
|
|
|
|
|
|
|
|
switch( m_fControl )
|
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
case 0:
|
|
|
|
// random
|
2016-06-04 15:24:23 +02:00
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case 1:
|
|
|
|
// Trigger Activator
|
|
|
|
if( pActivator != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
vecStart.x = pActivator->pev->origin.x;
|
|
|
|
vecStart.y = pActivator->pev->origin.y;
|
|
|
|
}
|
|
|
|
break;
|
2016-07-31 15:48:50 +02:00
|
|
|
case 2:
|
|
|
|
// table
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
CBaseEntity *pController;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( m_iszXController ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pController = UTIL_FindEntityByTargetname( NULL, STRING( m_iszXController ) );
|
|
|
|
if( pController != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vecStart.x = pev->mins.x + pController->pev->ideal_yaw * ( pev->size.x );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-31 15:48:50 +02:00
|
|
|
if( !FStringNull( m_iszYController ) )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pController = UTIL_FindEntityByTargetname( NULL, STRING( m_iszYController ) );
|
|
|
|
if( pController != NULL )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
vecStart.y = pev->mins.y + pController->pev->ideal_yaw * ( pev->size.y );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
int pitch = RANDOM_LONG( 95,124 );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "weapons/mortar.wav", 1.0, ATTN_NONE, 0, pitch );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
float t = 2.5;
|
2016-07-31 15:48:50 +02:00
|
|
|
for( int i = 0; i < m_iCount; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
Vector vecSpot = vecStart;
|
|
|
|
vecSpot.x += RANDOM_FLOAT( -m_flSpread, m_flSpread );
|
|
|
|
vecSpot.y += RANDOM_FLOAT( -m_flSpread, m_flSpread );
|
|
|
|
|
|
|
|
TraceResult tr;
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( vecSpot, vecSpot + Vector( 0, 0, -1 ) * 4096, ignore_monsters, ENT( pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
edict_t *pentOwner = NULL;
|
2016-07-31 15:48:50 +02:00
|
|
|
if( pActivator )
|
|
|
|
pentOwner = pActivator->edict();
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
CBaseEntity *pMortar = Create( "monster_mortar", tr.vecEndPos, Vector( 0, 0, 0 ), pentOwner );
|
2016-06-04 15:24:23 +02:00
|
|
|
pMortar->pev->nextthink = gpGlobals->time + t;
|
|
|
|
t += RANDOM_FLOAT( 0.2, 0.5 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
if( i == 0 )
|
|
|
|
CSoundEnt::InsertSound( bits_SOUND_DANGER, tr.vecEndPos, 400, 0.3 );
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CMortar : public CGrenade
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Spawn( void );
|
|
|
|
void Precache( void );
|
|
|
|
|
|
|
|
void EXPORT MortarExplode( void );
|
|
|
|
|
|
|
|
int m_spriteTexture;
|
|
|
|
};
|
|
|
|
|
2016-06-25 18:33:39 +02:00
|
|
|
LINK_ENTITY_TO_CLASS( monster_mortar, CMortar )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMortar::Spawn()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->movetype = MOVETYPE_NONE;
|
|
|
|
pev->solid = SOLID_NOT;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
pev->dmg = 200;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
SetThink( &CMortar::MortarExplode );
|
|
|
|
pev->nextthink = 0;
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
Precache();
|
2016-06-04 15:24:23 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
void CMortar::Precache()
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
m_spriteTexture = PRECACHE_MODEL( "sprites/lgtning.spr" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMortar::MortarExplode( void )
|
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
// mortar beam
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
|
|
|
WRITE_BYTE( TE_BEAMPOINTS );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_COORD( pev->origin.x );
|
|
|
|
WRITE_COORD( pev->origin.y );
|
|
|
|
WRITE_COORD( pev->origin.z );
|
|
|
|
WRITE_COORD( pev->origin.x );
|
|
|
|
WRITE_COORD( pev->origin.y );
|
|
|
|
WRITE_COORD( pev->origin.z + 1024 );
|
|
|
|
WRITE_SHORT( m_spriteTexture );
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( 0 ); // framerate
|
|
|
|
WRITE_BYTE( 0 ); // framerate
|
|
|
|
WRITE_BYTE( 1 ); // life
|
|
|
|
WRITE_BYTE( 40 ); // width
|
|
|
|
WRITE_BYTE( 0 ); // noise
|
|
|
|
WRITE_BYTE( 255 ); // r, g, b
|
|
|
|
WRITE_BYTE( 160 ); // r, g, b
|
|
|
|
WRITE_BYTE( 100 ); // r, g, b
|
|
|
|
WRITE_BYTE( 128 ); // brightness
|
|
|
|
WRITE_BYTE( 0 ); // speed
|
|
|
|
MESSAGE_END();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// blast circle
|
|
|
|
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
|
2016-07-31 15:48:50 +02:00
|
|
|
WRITE_BYTE( TE_BEAMTORUS );
|
|
|
|
WRITE_COORD( pev->origin.x );
|
|
|
|
WRITE_COORD( pev->origin.y );
|
|
|
|
WRITE_COORD( pev->origin.z + 32 );
|
|
|
|
WRITE_COORD( pev->origin.x );
|
|
|
|
WRITE_COORD( pev->origin.y );
|
|
|
|
WRITE_COORD( pev->origin.z + 32 + pev->dmg * 2 / .2 ); // reach damage radius over .3 seconds
|
|
|
|
WRITE_SHORT( m_spriteTexture );
|
2016-06-04 15:24:23 +02:00
|
|
|
WRITE_BYTE( 0 ); // startframe
|
|
|
|
WRITE_BYTE( 0 ); // framerate
|
|
|
|
WRITE_BYTE( 2 ); // life
|
|
|
|
WRITE_BYTE( 12 ); // width
|
|
|
|
WRITE_BYTE( 0 ); // noise
|
|
|
|
WRITE_BYTE( 255 ); // r, g, b
|
|
|
|
WRITE_BYTE( 160 ); // r, g, b
|
|
|
|
WRITE_BYTE( 100 ); // r, g, b
|
|
|
|
WRITE_BYTE( 255 ); // brightness
|
|
|
|
WRITE_BYTE( 0 ); // speed
|
|
|
|
MESSAGE_END();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TraceResult tr;
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( pev->origin + Vector( 0, 0, 1024 ), pev->origin - Vector( 0, 0, 1024 ), dont_ignore_monsters, ENT( pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
Explode( &tr, DMG_BLAST | DMG_MORTAR );
|
|
|
|
UTIL_ScreenShake( tr.vecEndPos, 25.0, 150.0, 1.0, 750 );
|
|
|
|
#if 0
|
2016-07-31 15:48:50 +02:00
|
|
|
int pitch = RANDOM_LONG( 95, 124 );
|
|
|
|
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "weapons/mortarhit.wav", 1.0, 0.55, 0, pitch );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
// ForceSound( SNDRADIUS_MP5, bits_SOUND_COMBAT );
|
|
|
|
|
|
|
|
// ExplodeModel( pev->origin, 400, g_sModelIndexShrapnel, 30 );
|
|
|
|
|
2016-07-31 15:48:50 +02:00
|
|
|
RadiusDamage( pev, VARS( pev->owner ), pev->dmg, CLASS_NONE, DMG_BLAST );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
/*
|
2016-07-31 15:48:50 +02:00
|
|
|
if( RANDOM_FLOAT( 0, 1 ) < 0.5 )
|
2016-06-04 15:24:23 +02:00
|
|
|
{
|
|
|
|
UTIL_DecalTrace( pTrace, DECAL_SCORCH1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UTIL_DecalTrace( pTrace, DECAL_SCORCH2 );
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
SetThink( &SUB_Remove );
|
|
|
|
pev->nextthink = gpGlobals->time + 0.1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
void CMortar::ShootTimed( EVARS *pevOwner, Vector vecStart, float time )
|
|
|
|
{
|
|
|
|
CMortar *pMortar = GetClassPtr( (CMortar *)NULL );
|
|
|
|
pMortar->Spawn();
|
|
|
|
|
|
|
|
TraceResult tr;
|
2016-07-31 15:48:50 +02:00
|
|
|
UTIL_TraceLine( vecStart, vecStart + Vector( 0, 0, -1 ) * 4096, ignore_monsters, ENT( pMortar->pev ), &tr );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
pMortar->pev->nextthink = gpGlobals->time + time;
|
|
|
|
|
|
|
|
UTIL_SetOrigin( pMortar->pev, tr.vecEndPos );
|
|
|
|
}
|
2016-04-17 22:30:05 +02:00
|
|
|
#endif
|