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.

216 lines
4.3 KiB

/***
*
* 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 "nodes.h"
#include "player.h"
#include "gamerules.h"
#include "grapple_tonguetip.h"
5 years ago
LINK_ENTITY_TO_CLASS( grapple_tip, CBarnacleGrappleTip )
5 years ago
void CBarnacleGrappleTip::Precache()
{
5 years ago
PRECACHE_MODEL( "models/shock_effect.mdl" );
}
5 years ago
void CBarnacleGrappleTip::Spawn()
{
5 years ago
Precache();
5 years ago
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
5 years ago
SET_MODEL( ENT(pev), "models/shock_effect.mdl" );
5 years ago
UTIL_SetSize( pev, Vector(0, 0, 0), Vector(0, 0, 0) );
5 years ago
UTIL_SetOrigin( pev, pev->origin );
5 years ago
SetThink( &CBarnacleGrappleTip::FlyThink );
SetTouch( &CBarnacleGrappleTip::TongueTouch );
5 years ago
Vector vecAngles = pev->angles;
5 years ago
vecAngles.x -= 30.0;
5 years ago
pev->angles = vecAngles;
5 years ago
UTIL_MakeVectors( pev->angles );
5 years ago
vecAngles.x = -( 30.0 + vecAngles.x );
5 years ago
pev->velocity = g_vecZero;
5 years ago
pev->gravity = 1.0;
5 years ago
pev->nextthink = gpGlobals->time + 0.02;
5 years ago
m_bIsStuck = FALSE;
m_bMissed = FALSE;
}
5 years ago
void CBarnacleGrappleTip::FlyThink()
{
UTIL_MakeAimVectors( pev->angles );
pev->angles = UTIL_VecToAngles( gpGlobals->v_forward );
5 years ago
const float flNewVel = ( ( pev->velocity.Length() * 0.8 ) + 400.0 );
5 years ago
pev->velocity = pev->velocity * 0.2 + ( flNewVel * gpGlobals->v_forward );
5 years ago
if( !g_pGameRules->IsMultiplayer() )
{
5 years ago
//Note: the old grapple had a maximum velocity of 1600. - Solokiller
if( pev->velocity.Length() > 750.0 )
{
pev->velocity = pev->velocity.Normalize() * 750.0;
}
}
else
{
//TODO: should probably clamp at sv_maxvelocity to prevent the tip from going off course. - Solokiller
if( pev->velocity.Length() > 2000.0 )
{
pev->velocity = pev->velocity.Normalize() * 2000.0;
}
}
5 years ago
pev->nextthink = gpGlobals->time + 0.02;
}
5 years ago
void CBarnacleGrappleTip::OffsetThink()
{
//Nothing
}
void CBarnacleGrappleTip::TongueTouch( CBaseEntity* pOther )
{
if( !pOther )
{
targetClass = GRAPPLE_NOT_A_TARGET;
m_bMissed = TRUE;
}
else
{
5 years ago
if( pOther->IsPlayer() )
{
targetClass = GRAPPLE_MEDIUM;
m_hGrappleTarget = pOther;
5 years ago
m_bIsStuck = TRUE;
}
else
{
targetClass = CheckTarget( pOther );
if( targetClass != GRAPPLE_NOT_A_TARGET )
{
m_bIsStuck = TRUE;
}
else
{
m_bMissed = TRUE;
}
}
}
5 years ago
pev->velocity = g_vecZero;
m_GrappleType = targetClass;
SetThink( &CBarnacleGrappleTip::OffsetThink );
pev->nextthink = gpGlobals->time + 0.02;
SetTouch( NULL );
}
5 years ago
int CBarnacleGrappleTip::CheckTarget( CBaseEntity* pTarget )
{
5 years ago
if( !pTarget )
return GRAPPLE_NOT_A_TARGET;
if( pTarget->IsPlayer() )
{
5 years ago
m_hGrappleTarget = pTarget;
return pTarget->SizeForGrapple();
}
Vector vecStart = pev->origin;
Vector vecEnd = pev->origin + pev->velocity * 1024.0;
TraceResult tr;
UTIL_TraceLine( vecStart, vecEnd, ignore_monsters, edict(), &tr );
CBaseEntity* pHit = Instance( tr.pHit );
/* if( !pHit )
pHit = CWorld::GetInstance();*/
float rgfl1[3];
float rgfl2[3];
const char *pTexture;
vecStart.CopyToArray(rgfl1);
vecEnd.CopyToArray(rgfl2);
if (pHit)
pTexture = TRACE_TEXTURE(ENT(pHit->pev), rgfl1, rgfl2);
else
pTexture = TRACE_TEXTURE(ENT(0), rgfl1, rgfl2);
bool bIsFixed = false;
if( pTexture && strnicmp( pTexture, "xeno_grapple", 12 ) == 0 )
{
bIsFixed = true;
}
else if (pTarget->SizeForGrapple() != GRAPPLE_NOT_A_TARGET)
{
if (pTarget->SizeForGrapple() == GRAPPLE_FIXED) {
bIsFixed = true;
} else {
m_hGrappleTarget = pTarget;
m_vecOriginOffset = pev->origin - pTarget->pev->origin;
return pTarget->SizeForGrapple();
}
}
5 years ago
if( bIsFixed )
{
m_hGrappleTarget = pTarget;
m_vecOriginOffset = g_vecZero;
return GRAPPLE_FIXED;
}
return GRAPPLE_NOT_A_TARGET;
}
void CBarnacleGrappleTip::SetPosition( Vector vecOrigin, Vector vecAngles, CBaseEntity* pOwner )
{
UTIL_SetOrigin( pev, vecOrigin );
pev->angles = vecAngles;
pev->owner = pOwner->edict();
}