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.

219 lines
5.6 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.
*
****/
#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"
#include "crossbow.h"
9 years ago
#ifndef CLIENT_DLL
LINK_ENTITY_TO_CLASS( crossbow_bolt, CCrossbowBolt )
9 years ago
CCrossbowBolt *CCrossbowBolt::BoltCreate( void )
{
// Create a new entity with CCrossbowBolt private data
CCrossbowBolt *pBolt = GetClassPtr( (CCrossbowBolt *)NULL );
8 years ago
pBolt->pev->classname = MAKE_STRING( "crossbow_bolt" ); // g-cont. enable save\restore
9 years ago
pBolt->Spawn();
return pBolt;
}
8 years ago
void CCrossbowBolt::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
pev->gravity = 0.5;
8 years ago
SET_MODEL( ENT( pev ), "models/crossbow_bolt.mdl" );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
8 years ago
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
SetTouch( &CCrossbowBolt::BoltTouch );
SetThink( &CCrossbowBolt::BubbleThink );
pev->nextthink = gpGlobals->time + 0.2;
}
8 years ago
void CCrossbowBolt::Precache()
9 years ago
{
8 years ago
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" );
9 years ago
}
8 years ago
int CCrossbowBolt::Classify( void )
9 years ago
{
8 years ago
return CLASS_NONE;
9 years ago
}
void CCrossbowBolt::BoltTouch( CBaseEntity *pOther )
{
SetTouch( NULL );
SetThink( NULL );
8 years ago
if( pOther->pev->takedamage )
9 years ago
{
8 years ago
TraceResult tr = UTIL_GetGlobalTrace();
entvars_t *pevOwner;
9 years ago
pevOwner = VARS( pev->owner );
// UNDONE: this needs to call TraceAttack instead
8 years ago
ClearMultiDamage();
9 years ago
8 years ago
if( pOther->IsPlayer() )
9 years ago
{
8 years ago
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowClient, pev->velocity.Normalize(), &tr, DMG_NEVERGIB );
9 years ago
}
else
{
8 years ago
pOther->TraceAttack( pevOwner, gSkillData.plrDmgCrossbowMonster, pev->velocity.Normalize(), &tr, DMG_BULLET | DMG_NEVERGIB );
9 years ago
}
ApplyMultiDamage( pev, pevOwner );
pev->velocity = Vector( 0, 0, 0 );
// play body "thwack" sound
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
case 0:
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod1.wav", 1, ATTN_NORM );
break;
9 years ago
case 1:
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_BODY, "weapons/xbow_hitbod2.wav", 1, ATTN_NORM );
break;
9 years ago
}
8 years ago
if( !g_pGameRules->IsMultiplayer() )
9 years ago
{
Killed( pev, GIB_NEVER );
}
}
else
{
8 years ago
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 ) );
9 years ago
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time;// this will get changed below if the bolt is allowed to stick in what it hit.
8 years ago
if( FClassnameIs( pOther->pev, "worldspawn" ) )
9 years ago
{
// if what we hit is static architecture, can stay around for a while.
8 years ago
Vector vecDir = pev->velocity.Normalize();
9 years ago
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;
8 years ago
pev->angles.z = RANDOM_LONG( 0, 360 );
9 years ago
pev->nextthink = gpGlobals->time + 10.0;
}
8 years ago
else if( pOther->pev->movetype == MOVETYPE_PUSH || pOther->pev->movetype == MOVETYPE_PUSHSTEP )
9 years ago
{
8 years ago
Vector vecDir = pev->velocity.Normalize();
9 years ago
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;
8 years ago
pev->angles.z = RANDOM_LONG( 0, 360 );
9 years ago
pev->nextthink = gpGlobals->time + 10.0;
if (gPhysicsInterfaceInitialized) {
// g-cont. Setup movewith feature
pev->movetype = MOVETYPE_COMPOUND; // set movewith type
pev->aiment = ENT( pOther->pev ); // set parent
}
9 years ago
}
8 years ago
if( UTIL_PointContents( pev->origin ) != CONTENTS_WATER )
9 years ago
{
UTIL_Sparks( pev->origin );
}
}
8 years ago
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
SetThink( &CCrossbowBolt::ExplodeThink );
pev->nextthink = gpGlobals->time + 0.1;
}
}
void CCrossbowBolt::BubbleThink( void )
{
pev->nextthink = gpGlobals->time + 0.1;
8 years ago
if( pev->waterlevel == 0 )
9 years ago
return;
UTIL_BubbleTrail( pev->origin - pev->velocity * 0.1, pev->origin, 1 );
}
void CCrossbowBolt::ExplodeThink( void )
{
8 years ago
int iContents = UTIL_PointContents( pev->origin );
9 years ago
int iScale;
8 years ago
9 years ago
pev->dmg = 40;
iScale = 10;
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
8 years ago
WRITE_BYTE( TE_EXPLOSION );
9 years ago
WRITE_COORD( pev->origin.x );
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
8 years ago
if( iContents != CONTENTS_WATER )
9 years ago
{
WRITE_SHORT( g_sModelIndexFireball );
}
else
{
WRITE_SHORT( g_sModelIndexWExplosion );
}
8 years ago
WRITE_BYTE( iScale ); // scale * 10
WRITE_BYTE( 15 ); // framerate
9 years ago
WRITE_BYTE( TE_EXPLFLAG_NONE );
MESSAGE_END();
entvars_t *pevOwner;
8 years ago
if( pev->owner )
9 years ago
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 );
8 years ago
UTIL_Remove( this );
9 years ago
}
#endif
#endif