hlsdk-portable/dlls/crossbow.cpp

217 lines
5.5 KiB
C++
Raw Normal View History

2016-06-04 13:24:23 +00: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.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"
#include "gamerules.h"
2016-08-27 19:39:01 +00:00
#include "crossbow.h"
2016-06-04 13:24:23 +00:00
#ifndef CLIENT_DLL
2016-06-25 18:21:01 +00:00
LINK_ENTITY_TO_CLASS( crossbow_bolt, CCrossbowBolt )
2016-06-04 13:24:23 +00:00
CCrossbowBolt *CCrossbowBolt::BoltCreate( void )
{
// Create a new entity with CCrossbowBolt private data
CCrossbowBolt *pBolt = GetClassPtr( (CCrossbowBolt *)NULL );
2016-07-31 13:48:50 +00:00
pBolt->pev->classname = MAKE_STRING( "crossbow_bolt" ); // g-cont. enable save\restore
2016-06-04 13:24:23 +00:00
pBolt->Spawn();
return pBolt;
}
2016-07-31 13:48:50 +00:00
void CCrossbowBolt::Spawn()
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
Precache();
2016-06-04 13:24:23 +00:00
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
pev->gravity = 0.5;
2016-07-31 13:48:50 +00:00
SET_MODEL( ENT( pev ), "models/crossbow_bolt.mdl" );
2016-06-04 13:24:23 +00:00
UTIL_SetOrigin( pev, pev->origin );
2016-07-31 13:48:50 +00:00
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2016-06-04 13:24:23 +00:00
SetTouch( &CCrossbowBolt::BoltTouch );
SetThink( &CCrossbowBolt::BubbleThink );
pev->nextthink = gpGlobals->time + 0.2;
}
2016-07-31 13:48:50 +00:00
void CCrossbowBolt::Precache()
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
PRECACHE_MODEL( "models/crossbow_bolt.mdl" );
PRECACHE_SOUND( "weapons/xbow_hitbod1.wav" );
PRECACHE_SOUND( "weapons/xbow_hitbod2.wav" );
PRECACHE_SOUND( "weapons/xbow_fly1.wav" );
PRECACHE_SOUND( "weapons/xbow_hit1.wav" );
PRECACHE_SOUND( "fvox/beep.wav" );
m_iTrail = PRECACHE_MODEL( "sprites/streak.spr" );
2016-06-04 13:24:23 +00:00
}
2016-07-31 13:48:50 +00:00
int CCrossbowBolt::Classify( void )
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
return CLASS_NONE;
2016-06-04 13:24:23 +00:00
}
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
{
SetTouch( NULL );
SetThink( NULL );
2016-07-31 13:48:50 +00:00
if( pOther->pev->takedamage )
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
TraceResult tr = UTIL_GetGlobalTrace();
entvars_t *pevOwner;
2016-06-04 13:24:23 +00:00
pevOwner = VARS( pev->owner );
// UNDONE: this needs to call TraceAttack instead
2016-07-31 13:48:50 +00:00
ClearMultiDamage();
2016-06-04 13:24:23 +00:00
2016-07-31 13:48:50 +00:00
if( pOther->IsPlayer() )
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowClient, pev->velocity.Normalize(), &tr, DMG_NEVERGIB );
2016-06-04 13:24:23 +00:00
}
else
{
2016-07-31 13:48:50 +00:00
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowMonster, pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB );
2016-06-04 13:24:23 +00:00
}
ApplyMultiDamage( pev, pevOwner );
pev->velocity = Vector( 0, 0, 0 );
// play body "thwack" sound
2016-07-31 13:48:50 +00:00
switch( RANDOM_LONG( 0, 1 ) )
2016-06-04 13:24:23 +00:00
{
case 0:
2016-07-31 13:48:50 +00:00
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod1.wav", 1, ATTN_NORM );
break;
2016-06-04 13:24:23 +00:00
case 1:
2016-07-31 13:48:50 +00:00
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod2.wav", 1, ATTN_NORM );
break;
2016-06-04 13:24:23 +00:00
}
2016-07-31 13:48:50 +00:00
if( !g_pGameRules->IsMultiplayer() )
2016-06-04 13:24:23 +00:00
{
Killed( pev, GIB_NEVER );
}
}
else
{
2016-07-31 13:48:50 +00:00
EMIT_SOUND_DYN( ENT( pev ), CHAN_BODY, "weapons/xbow_hit1.wav", RANDOM_FLOAT( 0.95, 1.0 ), ATTN_NORM, 0, 98 + RANDOM_LONG( 0, 7 ) );
2016-06-04 13:24:23 +00:00
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time;// this will get changed below if the bolt is allowed to stick in what it hit.
2016-07-31 13:48:50 +00:00
if( FClassnameIs( pOther->pev, "worldspawn" ) )
2016-06-04 13:24:23 +00:00
{
// if what we hit is static architecture, can stay around for a while.
2016-07-31 13:48:50 +00:00
Vector vecDir = pev->velocity.Normalize();
2016-06-04 13:24:23 +00:00
UTIL_SetOrigin( pev, pev->origin - vecDir * 12 );
pev->angles = UTIL_VecToAngles( vecDir );
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_FLY;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity.z = 0;
2016-07-31 13:48:50 +00:00
pev->angles.z = RANDOM_LONG( 0, 360 );
2016-06-04 13:24:23 +00:00
pev->nextthink = gpGlobals->time + 10.0;
}
2016-07-31 13:48:50 +00:00
else if( pOther->pev->movetype == MOVETYPE_PUSH || pOther->pev->movetype == MOVETYPE_PUSHSTEP )
2016-06-04 13:24:23 +00:00
{
2016-07-31 13:48:50 +00:00
Vector vecDir = pev->velocity.Normalize();
2016-06-04 13:24:23 +00:00
UTIL_SetOrigin( pev, pev->origin - vecDir * 12 );
pev->angles = UTIL_VecToAngles( vecDir );
pev->solid = SOLID_NOT;
pev->velocity = Vector( 0, 0, 0 );
pev->avelocity.z = 0;
2016-07-31 13:48:50 +00:00
pev->angles.z = RANDOM_LONG( 0, 360 );
2016-06-04 13:24:23 +00:00
pev->nextthink = gpGlobals->time + 10.0;
// g-cont. Setup movewith feature
pev->movetype = MOVETYPE_COMPOUND; // set movewith type
pev->aiment = ENT( pOther->pev ); // set parent
}
2016-07-31 13:48:50 +00:00
if( UTIL_PointContents( pev->origin ) != CONTENTS_WATER )
2016-06-04 13:24:23 +00:00
{
UTIL_Sparks( pev->origin );
}
}
2016-07-31 13:48:50 +00:00
if( g_pGameRules->IsMultiplayer() )
2016-06-04 13:24:23 +00:00
{
SetThink( &CCrossbowBolt::ExplodeThink );
pev->nextthink = gpGlobals->time + 0.1;
}
}
void CCrossbowBolt::BubbleThink( void )
{
pev->nextthink = gpGlobals->time + 0.1;
2016-07-31 13:48:50 +00:00
if( pev->waterlevel == 0 )
2016-06-04 13:24:23 +00:00
return;
UTIL_BubbleTrail( pev->origin - pev->velocity * 0.1, pev->origin, 1 );
}
void CCrossbowBolt::ExplodeThink( void )
{
2016-07-31 13:48:50 +00:00
int iContents = UTIL_PointContents( pev->origin );
2016-06-04 13:24:23 +00:00
int iScale;
2016-07-31 13:48:50 +00:00
2016-06-04 13:24:23 +00:00
pev->dmg = 40;
iScale = 10;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
2016-07-31 13:48:50 +00:00
WRITE_BYTE( TE_EXPLOSION );
2016-06-04 13:24:23 +00:00
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
2016-07-31 13:48:50 +00:00
if( iContents != CONTENTS_WATER )
2016-06-04 13:24:23 +00:00
{
WRITE_SHORT( g_sModelIndexFireball );
}
else
{
WRITE_SHORT( g_sModelIndexWExplosion );
}
2016-07-31 13:48:50 +00:00
WRITE_BYTE( iScale ); // scale * 10
WRITE_BYTE( 15 ); // framerate
2016-06-04 13:24:23 +00:00
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();
entvars_t *pevOwner;
2016-07-31 13:48:50 +00:00
if( pev->owner )
2016-06-04 13:24:23 +00:00
pevOwner = VARS( pev->owner );
else
pevOwner = NULL;
pev->owner = NULL; // can't traceline attack owner if this is set
::RadiusDamage( pev->origin, pev, pevOwner, pev->dmg, 128, CLASS_NONE, DMG_BLAST | DMG_ALWAYSGIB );
2016-07-31 13:48:50 +00:00
UTIL_Remove( this );
2016-06-04 13:24:23 +00:00
}
#endif
2016-04-17 20:30:05 +00:00
#endif