mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-01-10 05:56:45 +03:00
c448f194ae
- Added keyvalue to hl2_gamerules which allows respawning in singleplayer - Added the game instructor system (including env_instructor_hint) from later Valve games using a VDC tutorial which adjusts the version from the Alien Swarm SDK to FPS rules and a Source 2013 environment; Also added new KV and icons for further control from mappers (tutorial mentioned by Maestra Fenix) - Added L4D/TF2 glows + point_glow entity as an all-purpose SDK-based off-shoot of tf_glow - Fixed weapon pickup sound not playing (reported by Sl0th and later Cvoxulary) - Fixed env_projectedtextures not updating on save/load - Added func_fake_worldportal, a spatial point_camera inspired by linked_portal_door based on SDK code alone (WIP, may be changed a lot in future updates) - Added option for point_camera and func_reflective_glass to use different render targets, therefore allowing multiple cameras and mirrors to be active at the same time - Added additional RT camera textures to choose from with a default of 3, but also controllable through a -numcameratextures command line param - Added adjustable convars for main view NearZ and skybox NearZ (suggested by someone recently, also suggested by Klems over a year ago) - Fixed map-specific localization files, cleaned up map-specific file code - Added a new block to gameinfo.txt which allows mods to automatically append their own command line parameters - Fixed math_lightpattern corruption when setting pattern/style while active - Fixed the "Touch" input crashing when given no entity - Added a way to add EFlags via keyvalue (suggested by Niker107) - Fixed ai_script_conditions not working without a NPC actor (reported by MetroHam) - Fixed point_radiation_source causing huge problems when intensity is 0, even though it was already advised against (reported by beefbacon) - Added "Mapbase" header to Mapbase-specific code files - Fixed an issue with updating sky_camera not obtaining area correctly, causing some entities to not draw in the skybox - Added "CopyFogController" and "CopyFogControllerWithScale" inputs to sky_camera, which copy fog parameters directly from a fog controller - Added "SetScale" input to sky_camera for live scale changing - Added convar to control player crouch speed multiplier (suggested by ArtyIF) - Added a ton of fixes for people running the Debug configuration of the codebase (partial credit to stepa2) - Added support for pre-defined enums and constants in VScript, starting with various values from the SDK code (damage types, trace masks, etc.) - Added limited support for Valve's Quaternion class in VScript - Added new instance helper capabilities, destructible game instances, and other misc. changes to VScript library - Replaced most of the VScript "accessor" classes with direct references to the original classes, as they were getting complicated fast and adding new VScript-only functions to the original classes might not be as bad as previously thought - Added base NPC hooks for AI sensing in VScript (allows control over sight and hearing), also exposed CSound for it - Added various functions and hooks for VPhysics integration in VScript - Added VScript-based custom suit devices - Expanded trace info exposed to VScript to allow plane and surface access (suggested by krassell) - Added ability to insert localization strings through VScript - Added various misc. VScript functions with various purposes, including reading/writing EFlags, movetypes, collision groups, etc. - Fixed VBSP not being able to correctly parse parallax corrected cubemaps in maps with instances
663 lines
21 KiB
C++
663 lines
21 KiB
C++
//========= Mapbase - https://github.com/mapbase-source/source-sdk-2013 ============//
|
|
//
|
|
// Purpose:
|
|
//
|
|
//=============================================================================//
|
|
|
|
#ifndef AI_GRENADE_H
|
|
#define AI_GRENADE_H
|
|
#ifdef _WIN32
|
|
#pragma once
|
|
#endif
|
|
|
|
// I wish I didn't have to #include all this, but I don't really have a choice.
|
|
// I guess something similar to CAI_BehaviorHost's backbridges could be tried.
|
|
#include "cbase.h"
|
|
#include "ai_basenpc.h"
|
|
#include "npcevent.h"
|
|
#include "grenade_frag.h"
|
|
#include "basegrenade_shared.h"
|
|
#include "ai_squad.h"
|
|
#include "GlobalStrings.h"
|
|
|
|
#define COMBINE_AE_GREN_TOSS ( 7 )
|
|
|
|
#define COMBINE_GRENADE_THROW_SPEED 650
|
|
#define COMBINE_GRENADE_TIMER 3.5
|
|
#define COMBINE_GRENADE_FLUSH_TIME 3.0 // Don't try to flush an enemy who has been out of sight for longer than this.
|
|
#define COMBINE_GRENADE_FLUSH_DIST 256.0 // Don't try to flush an enemy who has moved farther than this distance from the last place I saw him.
|
|
|
|
#define COMBINE_MIN_GRENADE_CLEAR_DIST 250
|
|
|
|
#define DEFINE_AIGRENADE_DATADESC() \
|
|
DEFINE_KEYFIELD( m_iNumGrenades, FIELD_INTEGER, "NumGrenades" ), \
|
|
DEFINE_FIELD( m_flNextGrenadeCheck, FIELD_TIME ), \
|
|
DEFINE_FIELD( m_hForcedGrenadeTarget, FIELD_EHANDLE ), \
|
|
DEFINE_FIELD( m_flNextAltFireTime, FIELD_TIME ), \
|
|
DEFINE_FIELD( m_vecAltFireTarget, FIELD_VECTOR ), \
|
|
DEFINE_FIELD( m_vecTossVelocity, FIELD_VECTOR ), \
|
|
DEFINE_INPUTFUNC( FIELD_STRING, "ThrowGrenadeAtTarget", InputThrowGrenadeAtTarget ), \
|
|
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetGrenades", InputSetGrenades ), \
|
|
DEFINE_INPUTFUNC( FIELD_INTEGER, "AddGrenades", InputAddGrenades ), \
|
|
DEFINE_OUTPUT(m_OnThrowGrenade, "OnThrowGrenade"), \
|
|
DEFINE_OUTPUT(m_OnOutOfGrenades, "OnOutOfGrenades"), \
|
|
|
|
// Use extern float GetCurrentGravity( void );
|
|
#define SMGGrenadeArc(shootpos, targetpos) \
|
|
Vector vecShootPos = shootpos; \
|
|
Vector vecThrow = (targetpos - vecShootPos); \
|
|
float time = vecThrow.Length() / 600.0; \
|
|
vecThrow = vecThrow * (1.0 / time); \
|
|
vecThrow.z += (GetCurrentGravity() * 0.5) * time * 0.5; \
|
|
Vector vecFace = vecShootPos + (vecThrow * 0.5); \
|
|
AddFacingTarget(vecFace, 1.0, 0.5); \
|
|
|
|
// Mask used for Combine ball hull traces.
|
|
// This used MASK_SHOT before, but this has been changed to MASK_SHOT_HULL.
|
|
// This fixes the existing problem of soldiers trying to fire energy balls through grates,
|
|
// but it's also important to prevent soldiers from blowing themselves up with their newfound SMG grenades.
|
|
#define MASK_COMBINE_BALL_LOS MASK_SHOT_HULL
|
|
|
|
extern int COMBINE_AE_BEGIN_ALTFIRE;
|
|
extern int COMBINE_AE_ALTFIRE;
|
|
|
|
enum eGrenadeCapabilities
|
|
{
|
|
GRENCAP_GRENADE = (1 << 0),
|
|
GRENCAP_ALTFIRE = (1 << 1),
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Other classes can use this and access some CAI_GrenadeUser functions.
|
|
//-----------------------------------------------------------------------------
|
|
class CAI_GrenadeUserSink
|
|
{
|
|
public:
|
|
CAI_GrenadeUserSink() { }
|
|
|
|
virtual bool UsingOnThrowGrenade() { return false; }
|
|
};
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//
|
|
// Template class for NPCs using grenades or weapon alt-fire stuff.
|
|
// You'll still have to use DEFINE_AIGRENADE_DATADESC() in your derived class's datadesc.
|
|
//
|
|
// I wanted to have these functions defined in a CPP file, but template class definitions must be in the header.
|
|
// Please excuse the bloat below the class definition.
|
|
//
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
class CAI_GrenadeUser : public BASE_NPC, public CAI_GrenadeUserSink
|
|
{
|
|
DECLARE_CLASS_NOFRIEND( CAI_GrenadeUser, BASE_NPC );
|
|
|
|
public:
|
|
CAI_GrenadeUser() : CAI_GrenadeUserSink() { }
|
|
|
|
void AddGrenades( int inc, CBaseEntity *pLastGrenade = NULL )
|
|
{
|
|
m_iNumGrenades += inc;
|
|
if (m_iNumGrenades <= 0)
|
|
m_OnOutOfGrenades.Set( pLastGrenade, pLastGrenade, this );
|
|
}
|
|
|
|
virtual bool IsAltFireCapable() { return false; }
|
|
virtual bool IsGrenadeCapable() { return true; }
|
|
inline bool HasGrenades() { return m_iNumGrenades > 0; }
|
|
|
|
void InputSetGrenades( inputdata_t &inputdata ) { AddGrenades( inputdata.value.Int() - m_iNumGrenades ); }
|
|
void InputAddGrenades( inputdata_t &inputdata ) { AddGrenades( inputdata.value.Int() ); }
|
|
void InputThrowGrenadeAtTarget( inputdata_t &inputdata );
|
|
|
|
virtual void DelayGrenadeCheck( float delay ) { m_flNextGrenadeCheck = gpGlobals->curtime + delay; }
|
|
|
|
void HandleAnimEvent( animevent_t *pEvent );
|
|
|
|
// Soldiers use "lefthand", cops use "LHand", and citizens use "anim_attachment_LH"
|
|
virtual const char* GetGrenadeAttachment() { return "anim_attachment_LH"; }
|
|
|
|
void ClearAttackConditions( void );
|
|
|
|
Vector GetAltFireTarget() { return m_vecAltFireTarget; }
|
|
virtual bool CanAltFireEnemy( bool bUseFreeKnowledge );
|
|
void DelayAltFireAttack( float flDelay );
|
|
void DelaySquadAltFireAttack( float flDelay );
|
|
|
|
virtual bool CanGrenadeEnemy( bool bUseFreeKnowledge = true );
|
|
bool CanThrowGrenade( const Vector &vecTarget );
|
|
bool CheckCanThrowGrenade( const Vector &vecTarget );
|
|
|
|
// For OnThrowGrenade + point_entity_replace, see grenade_frag.cpp
|
|
bool UsingOnThrowGrenade() { return m_OnThrowGrenade.NumberOfElements() > 0; }
|
|
|
|
protected:
|
|
|
|
void StartTask_FaceAltFireTarget( const Task_t *pTask );
|
|
void StartTask_GetPathToForced( const Task_t *pTask );
|
|
void StartTask_DeferSquad( const Task_t *pTask );
|
|
|
|
void RunTask_FaceAltFireTarget( const Task_t *pTask );
|
|
void RunTask_GetPathToForced( const Task_t *pTask );
|
|
void RunTask_FaceTossDir( const Task_t *pTask );
|
|
|
|
protected: // We can't have any private saved variables because only derived classes use the datadescs
|
|
|
|
int m_iNumGrenades;
|
|
float m_flNextGrenadeCheck;
|
|
EHANDLE m_hForcedGrenadeTarget;
|
|
|
|
float m_flNextAltFireTime;
|
|
Vector m_vecAltFireTarget;
|
|
Vector m_vecTossVelocity;
|
|
|
|
COutputEHANDLE m_OnThrowGrenade;
|
|
COutputEHANDLE m_OnOutOfGrenades;
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Purpose: Handle animation events
|
|
//------------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::HandleAnimEvent( animevent_t *pEvent )
|
|
{
|
|
if ( pEvent->event == COMBINE_AE_BEGIN_ALTFIRE )
|
|
{
|
|
if (this->GetActiveWeapon())
|
|
this->GetActiveWeapon()->WeaponSound( SPECIAL1 );
|
|
|
|
//SpeakIfAllowed( TLK_CMB_THROWGRENADE, "altfire:1" );
|
|
return;
|
|
}
|
|
if ( pEvent->event == COMBINE_AE_ALTFIRE )
|
|
{
|
|
animevent_t fakeEvent;
|
|
|
|
fakeEvent.pSource = this;
|
|
fakeEvent.event = EVENT_WEAPON_AR2_ALTFIRE;
|
|
|
|
// Weapon could've been dropped while playing animation
|
|
if (this->GetActiveWeapon())
|
|
this->GetActiveWeapon()->Operator_HandleAnimEvent( &fakeEvent, this );
|
|
|
|
// Stop other squad members from combine balling for a while.
|
|
DelaySquadAltFireAttack( 10.0f );
|
|
|
|
AddGrenades(-1);
|
|
|
|
return;
|
|
}
|
|
|
|
if ( pEvent->event == COMBINE_AE_GREN_TOSS )
|
|
{
|
|
Vector vecSpin;
|
|
vecSpin.x = random->RandomFloat( -1000.0, 1000.0 );
|
|
vecSpin.y = random->RandomFloat( -1000.0, 1000.0 );
|
|
vecSpin.z = random->RandomFloat( -1000.0, 1000.0 );
|
|
|
|
Vector vecStart;
|
|
this->GetAttachment( GetGrenadeAttachment(), vecStart );
|
|
|
|
if( this->GetState() == NPC_STATE_SCRIPT )
|
|
{
|
|
// Use a fixed velocity for grenades thrown in scripted state.
|
|
// Grenades thrown from a script do not count against grenades remaining for the AI to use.
|
|
Vector forward, up, vecThrow;
|
|
|
|
this->GetVectors( &forward, NULL, &up );
|
|
vecThrow = forward * 750 + up * 175;
|
|
|
|
// This code is used by player allies now, so it's only "combine spawned" if the thrower isn't allied with the player.
|
|
CBaseEntity *pGrenade = Fraggrenade_Create( vecStart, vec3_angle, vecThrow, vecSpin, this, COMBINE_GRENADE_TIMER, !this->IsPlayerAlly() );
|
|
m_OnThrowGrenade.Set(pGrenade, pGrenade, this);
|
|
}
|
|
else
|
|
{
|
|
// Use the Velocity that AI gave us.
|
|
CBaseEntity *pGrenade = Fraggrenade_Create( vecStart, vec3_angle, m_vecTossVelocity, vecSpin, this, COMBINE_GRENADE_TIMER, !this->IsPlayerAlly() );
|
|
m_OnThrowGrenade.Set(pGrenade, pGrenade, this);
|
|
AddGrenades(-1, pGrenade);
|
|
}
|
|
|
|
// wait six seconds before even looking again to see if a grenade can be thrown.
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 6;
|
|
return;
|
|
}
|
|
|
|
BaseClass::HandleAnimEvent( pEvent );
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Force the combine soldier to throw a grenade at the target
|
|
// If I'm a combine elite, fire my combine ball at the target instead.
|
|
// Input : &inputdata -
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::InputThrowGrenadeAtTarget( inputdata_t &inputdata )
|
|
{
|
|
// Ignore if we're inside a scripted sequence
|
|
if ( this->GetState() == NPC_STATE_SCRIPT && this->m_hCine )
|
|
return;
|
|
|
|
CBaseEntity *pEntity = gEntList.FindEntityByName( NULL, inputdata.value.String(), this, inputdata.pActivator, inputdata.pCaller );
|
|
if ( !pEntity )
|
|
{
|
|
DevMsg("%s (%s) received ThrowGrenadeAtTarget input, but couldn't find target entity '%s'\n", this->GetClassname(), this->GetDebugName(), inputdata.value.String() );
|
|
return;
|
|
}
|
|
|
|
m_hForcedGrenadeTarget = pEntity;
|
|
m_flNextGrenadeCheck = 0;
|
|
|
|
this->ClearSchedule( "Told to throw grenade via input" );
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
bool CAI_GrenadeUser<BASE_NPC>::CanAltFireEnemy( bool bUseFreeKnowledge )
|
|
{
|
|
if (!HasGrenades())
|
|
return false;
|
|
|
|
if (!IsAltFireCapable())
|
|
return false;
|
|
|
|
if (!this->GetActiveWeapon())
|
|
return false;
|
|
|
|
if (this->IsCrouching())
|
|
return false;
|
|
|
|
if ( gpGlobals->curtime < m_flNextAltFireTime || gpGlobals->curtime < m_flNextGrenadeCheck )
|
|
return false;
|
|
|
|
if( !this->GetEnemy() )
|
|
return false;
|
|
|
|
if (!EntIsClass(this->GetActiveWeapon(), gm_isz_class_AR2) && !EntIsClass(this->GetActiveWeapon(), gm_isz_class_SMG1))
|
|
return false;
|
|
|
|
CBaseEntity *pEnemy = this->GetEnemy();
|
|
|
|
Vector vecTarget;
|
|
|
|
// Determine what point we're shooting at
|
|
if( bUseFreeKnowledge )
|
|
{
|
|
vecTarget = this->GetEnemies()->LastKnownPosition( pEnemy ) + (pEnemy->GetViewOffset()*0.75);// approximates the chest
|
|
}
|
|
else
|
|
{
|
|
vecTarget = this->GetEnemies()->LastSeenPosition( pEnemy ) + (pEnemy->GetViewOffset()*0.75);// approximates the chest
|
|
}
|
|
|
|
// Trace a hull about the size of the combine ball (don't shoot through grates!)
|
|
trace_t tr;
|
|
|
|
Vector mins( -12, -12, -12 );
|
|
Vector maxs( 12, 12, 12 );
|
|
|
|
Vector vShootPosition = this->EyePosition();
|
|
|
|
if ( this->GetActiveWeapon() )
|
|
{
|
|
this->GetActiveWeapon()->GetAttachment( "muzzle", vShootPosition );
|
|
}
|
|
|
|
// Trace a hull about the size of the combine ball.
|
|
UTIL_TraceHull( vShootPosition, vecTarget, mins, maxs, MASK_COMBINE_BALL_LOS, this, COLLISION_GROUP_NONE, &tr );
|
|
|
|
float flLength = (vShootPosition - vecTarget).Length();
|
|
|
|
flLength *= tr.fraction;
|
|
|
|
// If the ball can travel at least 65% of the distance to the player then let the NPC shoot it.
|
|
// (unless it hit the world)
|
|
if( tr.fraction >= 0.65 && (!tr.m_pEnt || !tr.m_pEnt->IsWorld()) && flLength > 128.0f )
|
|
{
|
|
// Target is valid
|
|
m_vecAltFireTarget = vecTarget;
|
|
return true;
|
|
}
|
|
|
|
|
|
// Check again later
|
|
m_vecAltFireTarget = vec3_origin;
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 1.0f;
|
|
return false;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::DelayAltFireAttack( float flDelay )
|
|
{
|
|
float flNextAltFire = gpGlobals->curtime + flDelay;
|
|
|
|
if( flNextAltFire > m_flNextAltFireTime )
|
|
{
|
|
// Don't let this delay order preempt a previous request to wait longer.
|
|
m_flNextAltFireTime = flNextAltFire;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::DelaySquadAltFireAttack( float flDelay )
|
|
{
|
|
// Make sure to delay my own alt-fire attack.
|
|
DelayAltFireAttack( flDelay );
|
|
|
|
AISquadIter_t iter;
|
|
CAI_Squad *pSquad = this->GetSquad();
|
|
CAI_BaseNPC *pSquadmate = pSquad ? pSquad->GetFirstMember( &iter ) : NULL;
|
|
while ( pSquadmate )
|
|
{
|
|
CAI_GrenadeUser *pUser = dynamic_cast<CAI_GrenadeUser*>(pSquadmate);
|
|
if( pUser && pUser->IsAltFireCapable() )
|
|
{
|
|
pUser->DelayAltFireAttack( flDelay );
|
|
}
|
|
|
|
pSquadmate = pSquad->GetNextMember( &iter );
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
bool CAI_GrenadeUser<BASE_NPC>::CanGrenadeEnemy( bool bUseFreeKnowledge )
|
|
{
|
|
CBaseEntity *pEnemy = this->GetEnemy();
|
|
|
|
Assert( pEnemy != NULL );
|
|
|
|
if( pEnemy )
|
|
{
|
|
// I'm not allowed to throw grenades during dustoff
|
|
if ( this->IsCurSchedule(SCHED_DROPSHIP_DUSTOFF) )
|
|
return false;
|
|
|
|
if( bUseFreeKnowledge )
|
|
{
|
|
// throw to where we think they are.
|
|
return CanThrowGrenade( this->GetEnemies()->LastKnownPosition( pEnemy ) );
|
|
}
|
|
else
|
|
{
|
|
// hafta throw to where we last saw them.
|
|
return CanThrowGrenade( this->GetEnemies()->LastSeenPosition( pEnemy ) );
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Return true if the combine has grenades, hasn't checked lately, and
|
|
// can throw a grenade at the target point.
|
|
// Input : &vecTarget -
|
|
// Output : Returns true on success, false on failure.
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
bool CAI_GrenadeUser<BASE_NPC>::CanThrowGrenade( const Vector &vecTarget )
|
|
{
|
|
if( m_iNumGrenades < 1 )
|
|
{
|
|
// Out of grenades!
|
|
return false;
|
|
}
|
|
|
|
if (!IsGrenadeCapable())
|
|
{
|
|
// Must be capable of throwing grenades
|
|
return false;
|
|
}
|
|
|
|
if ( gpGlobals->curtime < m_flNextGrenadeCheck )
|
|
{
|
|
// Not allowed to throw another grenade right now.
|
|
return false;
|
|
}
|
|
|
|
float flDist;
|
|
flDist = ( vecTarget - this->GetAbsOrigin() ).Length();
|
|
|
|
if( flDist > 1024 || flDist < 128 )
|
|
{
|
|
// Too close or too far!
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second.
|
|
return false;
|
|
}
|
|
|
|
// -----------------------
|
|
// If moving, don't check.
|
|
// -----------------------
|
|
if ( this->m_flGroundSpeed != 0 )
|
|
return false;
|
|
|
|
// ---------------------------------------------------------------------
|
|
// Are any of my squad members near the intended grenade impact area?
|
|
// ---------------------------------------------------------------------
|
|
CAI_Squad *pSquad = this->GetSquad();
|
|
if ( pSquad )
|
|
{
|
|
if (pSquad->SquadMemberInRange( vecTarget, COMBINE_MIN_GRENADE_CLEAR_DIST ))
|
|
{
|
|
// crap, I might blow my own guy up. Don't throw a grenade and don't check again for a while.
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second.
|
|
|
|
// Tell my squad members to clear out so I can get a grenade in
|
|
// Mapbase uses a new context here that gets all nondescript allies away since this code is shared between Combine and non-Combine now.
|
|
CSoundEnt::InsertSound( SOUND_MOVE_AWAY | SOUND_CONTEXT_OWNER_ALLIES, vecTarget, COMBINE_MIN_GRENADE_CLEAR_DIST, 0.1, this );
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return CheckCanThrowGrenade( vecTarget );
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Returns true if the combine can throw a grenade at the specified target point
|
|
// Input : &vecTarget -
|
|
// Output : Returns true on success, false on failure.
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
bool CAI_GrenadeUser<BASE_NPC>::CheckCanThrowGrenade( const Vector &vecTarget )
|
|
{
|
|
//NDebugOverlay::Line( this->EyePosition(), vecTarget, 0, 255, 0, false, 5 );
|
|
|
|
// ---------------------------------------------------------------------
|
|
// Check that throw is legal and clear
|
|
// ---------------------------------------------------------------------
|
|
// FIXME: this is only valid for hand grenades, not RPG's
|
|
Vector vecToss;
|
|
Vector vecMins = -Vector(4,4,4);
|
|
Vector vecMaxs = Vector(4,4,4);
|
|
if( this->FInViewCone( vecTarget ) && CBaseEntity::FVisible( vecTarget ) )
|
|
{
|
|
vecToss = VecCheckThrow( this, this->EyePosition(), vecTarget, COMBINE_GRENADE_THROW_SPEED, 1.0, &vecMins, &vecMaxs );
|
|
}
|
|
else
|
|
{
|
|
// Have to try a high toss. Do I have enough room?
|
|
trace_t tr;
|
|
AI_TraceLine( this->EyePosition(), this->EyePosition() + Vector( 0, 0, 64 ), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
|
|
if( tr.fraction != 1.0 )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
vecToss = VecCheckToss( this, this->EyePosition(), vecTarget, -1, 1.0, true, &vecMins, &vecMaxs );
|
|
}
|
|
|
|
if ( vecToss != vec3_origin )
|
|
{
|
|
m_vecTossVelocity = vecToss;
|
|
|
|
// don't check again for a while.
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // 1/3 second.
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
// don't check again for a while.
|
|
m_flNextGrenadeCheck = gpGlobals->curtime + 1; // one full second.
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: This was copied from soldier code for general AI grenades.
|
|
//
|
|
// "Soldiers use CAN_RANGE_ATTACK2 to indicate whether they can throw
|
|
// a grenade. Because they check only every half-second or so, this
|
|
// condition must persist until it is updated again by the code
|
|
// that determines whether a grenade can be thrown, so prevent the
|
|
// base class from clearing it out. (sjb)"
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::ClearAttackConditions()
|
|
{
|
|
bool fCanRangeAttack2 = IsGrenadeCapable() && this->HasCondition( COND_CAN_RANGE_ATTACK2 );
|
|
|
|
// Call the base class.
|
|
BaseClass::ClearAttackConditions();
|
|
|
|
if( fCanRangeAttack2 )
|
|
{
|
|
// We don't allow the base class to clear this condition because we
|
|
// don't sense for it every frame.
|
|
this->SetCondition( COND_CAN_RANGE_ATTACK2 );
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
// Purpose: Task helpers
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::StartTask_FaceAltFireTarget( const Task_t *pTask )
|
|
{
|
|
this->SetIdealActivity( (Activity)(int)pTask->flTaskData );
|
|
this->GetMotor()->SetIdealYawToTargetAndUpdate( m_vecAltFireTarget, AI_KEEP_YAW_SPEED );
|
|
}
|
|
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::StartTask_GetPathToForced( const Task_t *pTask )
|
|
{
|
|
if ( !m_hForcedGrenadeTarget )
|
|
{
|
|
this->TaskFail(FAIL_NO_ENEMY);
|
|
return;
|
|
}
|
|
|
|
float flMaxRange = 2000;
|
|
float flMinRange = 0;
|
|
|
|
Vector vecEnemy = m_hForcedGrenadeTarget->GetAbsOrigin();
|
|
Vector vecEnemyEye = vecEnemy + m_hForcedGrenadeTarget->GetViewOffset();
|
|
|
|
Vector posLos;
|
|
bool found = false;
|
|
|
|
if ( this->GetTacticalServices()->FindLateralLos( vecEnemyEye, &posLos ) )
|
|
{
|
|
float dist = ( posLos - vecEnemyEye ).Length();
|
|
if ( dist < flMaxRange && dist > flMinRange )
|
|
found = true;
|
|
}
|
|
|
|
if ( !found && this->GetTacticalServices()->FindLos( vecEnemy, vecEnemyEye, flMinRange, flMaxRange, 1.0, &posLos ) )
|
|
{
|
|
found = true;
|
|
}
|
|
|
|
if ( !found )
|
|
{
|
|
this->TaskFail( FAIL_NO_SHOOT );
|
|
}
|
|
else
|
|
{
|
|
// else drop into run task to offer an interrupt
|
|
this->m_vInterruptSavePosition = posLos;
|
|
}
|
|
}
|
|
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::StartTask_DeferSquad( const Task_t *pTask )
|
|
{
|
|
CAI_Squad *pSquad = this->GetSquad();
|
|
if ( pSquad )
|
|
{
|
|
// iterate my squad and stop everyone from throwing grenades for a little while.
|
|
AISquadIter_t iter;
|
|
|
|
CAI_BaseNPC *pSquadmate = pSquad ? pSquad->GetFirstMember( &iter ) : NULL;
|
|
while ( pSquadmate )
|
|
{
|
|
pSquadmate->DelayGrenadeCheck(5);
|
|
|
|
pSquadmate = pSquad->GetNextMember( &iter );
|
|
}
|
|
}
|
|
|
|
this->TaskComplete();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::RunTask_FaceAltFireTarget( const Task_t *pTask )
|
|
{
|
|
this->GetMotor()->SetIdealYawToTargetAndUpdate( m_vecAltFireTarget, AI_KEEP_YAW_SPEED );
|
|
|
|
// New Mapbase thing that fixes forced alt-fires not changing weapon yaw/pitch
|
|
this->SetAim( m_vecAltFireTarget - this->Weapon_ShootPosition() );
|
|
|
|
if (this->IsActivityFinished())
|
|
{
|
|
this->TaskComplete();
|
|
}
|
|
}
|
|
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::RunTask_GetPathToForced( const Task_t *pTask )
|
|
{
|
|
if ( !m_hForcedGrenadeTarget )
|
|
{
|
|
this->TaskFail(FAIL_NO_ENEMY);
|
|
return;
|
|
}
|
|
|
|
if ( this->GetTaskInterrupt() > 0 )
|
|
{
|
|
this->ClearTaskInterrupt();
|
|
|
|
Vector vecEnemy = m_hForcedGrenadeTarget->GetAbsOrigin();
|
|
AI_NavGoal_t goal( this->m_vInterruptSavePosition, ACT_RUN, AIN_HULL_TOLERANCE );
|
|
|
|
this->GetNavigator()->SetGoal( goal, AIN_CLEAR_TARGET );
|
|
this->GetNavigator()->SetArrivalDirection( vecEnemy - goal.dest );
|
|
}
|
|
else
|
|
{
|
|
this->TaskInterrupt();
|
|
}
|
|
}
|
|
|
|
template <class BASE_NPC>
|
|
void CAI_GrenadeUser<BASE_NPC>::RunTask_FaceTossDir( const Task_t *pTask )
|
|
{
|
|
// project a point along the toss vector and turn to face that point.
|
|
this->GetMotor()->SetIdealYawToTargetAndUpdate( this->GetLocalOrigin() + m_vecTossVelocity * 64, AI_KEEP_YAW_SPEED );
|
|
|
|
if ( this->FacingIdeal() )
|
|
{
|
|
this->TaskComplete( true );
|
|
}
|
|
}
|
|
|
|
#endif
|