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