Team Fortress 2 Source Code as on 22/4/2020
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.

5745 lines
163 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Giant walking strider thing!
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "npc_strider.h"
  9. #include "ai_senses.h"
  10. #include "ai_task.h"
  11. #include "ai_default.h"
  12. #include "ai_schedule.h"
  13. #include "ai_hull.h"
  14. #include "ai_basenpc.h"
  15. #include "ai_pathfinder.h"
  16. #include "ai_waypoint.h"
  17. #include "ai_link.h"
  18. #include "ai_hint.h"
  19. #include "ai_tacticalservices.h"
  20. #include "ai_behavior_follow.h"
  21. #include "simtimer.h"
  22. #include "trains.h"
  23. #include "npcevent.h"
  24. #include "te_particlesystem.h"
  25. #include "shake.h"
  26. #include "soundent.h"
  27. #include "IEffects.h"
  28. #include "engine/IEngineSound.h"
  29. #include "bone_setup.h"
  30. #include "vcollide_parse.h"
  31. #include "studio.h"
  32. #include "physics_bone_follower.h"
  33. #include "ai_navigator.h"
  34. #include "ai_route.h"
  35. #include "ammodef.h"
  36. #include "npc_bullseye.h"
  37. #include "rope.h"
  38. #include "ai_memory.h"
  39. #include "player_pickup.h"
  40. #include "collisionutils.h"
  41. #include "in_buttons.h"
  42. #include "steamjet.h"
  43. #include "physics_prop_ragdoll.h"
  44. #include "vehicle_base.h"
  45. #include "coordsize.h"
  46. #include "hl2_shareddefs.h"
  47. #include "te_effect_dispatch.h"
  48. #include "beam_flags.h"
  49. #include "prop_combine_ball.h"
  50. #include "explode.h"
  51. #include "filters.h"
  52. #include "saverestore_utlvector.h"
  53. #include "eventqueue.h"
  54. // memdbgon must be the last include file in a .cpp file!!!
  55. #include "tier0/memdbgon.h"
  56. int g_interactionPlayerLaunchedRPG = 0;
  57. // Changing this classname avoids bugs where ai_relationship entities that change the
  58. // strider's relationship with bullseyes would affect its relationship with the focus
  59. LINK_ENTITY_TO_CLASS( bullseye_strider_focus, CNPC_Bullseye );
  60. //-----------------------------------------------------------------------------
  61. ConVar strider_immolate( "strider_immolate", "0" );
  62. ConVar sk_strider_health( "sk_strider_health", "350" );
  63. ConVar npc_strider_height_adj("npc_strider_height_adj", "0" );
  64. ConVar strider_eyepositions( "strider_eyepositions", "0" );
  65. ConVar strider_show_focus( "strider_show_focus", "0" );
  66. ConVar strider_distributed_fire( "strider_distributed_fire", "1" );
  67. ConVar strider_show_cannonlos( "strider_show_cannonlos", "0" );
  68. ConVar strider_show_weapon_los_z( "strider_show_weapon_los_z", "0" );
  69. ConVar strider_show_weapon_los_condition( "strider_show_weapon_los_condition", "0" );
  70. ConVar strider_idle_test( "strider_idle_test", "0" );
  71. ConVar strider_always_use_procedural_height( "strider_always_use_procedural_height", "0" );
  72. ConVar strider_test_height( "strider_test_height", "0" );
  73. ConVar strider_pct_height_no_crouch_move( "strider_pct_height_no_crouch_move", "90" );
  74. ConVar strider_peek_time( "strider_peek_time", "0.75" );
  75. ConVar strider_peek_time_after_damage( "strider_peek_time_after_damage", "4.0" );
  76. ConVar strider_peek_eye_dist( "strider_peek_eye_dist", "1.75" );
  77. ConVar strider_peek_eye_dist_z( "strider_peek_eye_dist_z", "4.0" );
  78. ConVar strider_free_pass_start_time( "strider_free_pass_start_time", "3" );
  79. ConVar strider_free_pass_cover_dist( "strider_free_pass_cover_dist", "120" );
  80. ConVar strider_free_pass_duration( "strider_free_pass_duration", "2" );
  81. ConVar strider_free_pass_refill_rate( "strider_free_pass_refill_rate", "0.5" );
  82. ConVar strider_free_pass_move_tolerance( "strider_free_pass_move_tolerance", "320" );
  83. ConVar strider_free_knowledge( "strider_free_knowledge", "0.5" );
  84. ConVar strider_free_pass_after_escorts_dead( "strider_free_pass_after_escorts_dead", "2.5" );
  85. ConVar strider_free_pass_tolerance_after_escorts_dead( "strider_free_pass_tolerance_after_escorts_dead", "600" );
  86. ConVar npc_strider_shake_ropes_radius( "npc_strider_shake_ropes_radius", "1200" );
  87. ConVar npc_strider_shake_ropes_magnitude( "npc_strider_shake_ropes_magnitude", "150" );
  88. ConVar strider_ar2_altfire_dmg( "strider_ar2_altfire_dmg", "25" );
  89. // Number of RPG hits it takes to kill a strider on each skill level.
  90. ConVar sk_strider_num_missiles1("sk_strider_num_missiles1", "5");
  91. ConVar sk_strider_num_missiles2("sk_strider_num_missiles2", "7");
  92. ConVar sk_strider_num_missiles3("sk_strider_num_missiles3", "7");
  93. ConVar strider_missile_suppress_dist( "strider_missile_suppress_dist", "240" );
  94. ConVar strider_missile_suppress_time( "strider_missile_suppress_time", "3" );
  95. //-----------------------------------------------------------------------------
  96. float GetCurrentGravity( void );
  97. extern void CreateConcussiveBlast( const Vector &origin, const Vector &surfaceNormal, CBaseEntity *pOwner, float magnitude );
  98. //-----------------------------------------------------------------------------
  99. enum bodygroups
  100. {
  101. STRIDER_BODYGROUP_VENT = 1,
  102. };
  103. //-----------------------------------------------------------------------------
  104. #define STRIDER_DEFAULT_SHOOT_DURATION 2.5 // spend this much time stitching to each target.
  105. #define STRIDER_SHOOT_ON_TARGET_TIME 0.5 // How much of DEFAULT_SHOOT_DURATION is spent on-target (vs. stitching up to a target)
  106. #define STRIDER_SHOOT_VARIATION 1.0 // up to 1 second of variance
  107. #define STRIDER_SHOOT_DOWNTIME 1.0 // This much downtime between bursts
  108. #define STRIDER_SUBSEQUENT_TARGET_DURATION 1.5 // Spend this much time stitching to targets chosen by distributed fire.
  109. #define STRIDER_IGNORE_TARGET_DURATION 1.0
  110. #define STRIDER_IGNORE_PLAYER_DURATION 1.5
  111. #define STRIDER_DEFAULT_RATE_OF_FIRE 5 // Rounds per second
  112. #define STRIDER_EP1_RATE_OF_FIRE 10.0f
  113. #define STRIDER_EP1_SHOOT_ON_TARGET_TIME 0.3f
  114. #define STRIDER_EP1_SHOOT_DURATION 1.1f
  115. #define STRIDER_EP1_SHOOT_DOWNTIME 1.0f
  116. #define STRIDER_EP1_SHOOT_VARIATION 0.3f
  117. //Animation events
  118. #define STRIDER_AE_FOOTSTEP_LEFT 1
  119. #define STRIDER_AE_FOOTSTEP_RIGHT 2
  120. #define STRIDER_AE_FOOTSTEP_BACK 3
  121. #define STRIDER_AE_FOOTSTEP_LEFTM 4
  122. #define STRIDER_AE_FOOTSTEP_RIGHTM 5
  123. #define STRIDER_AE_FOOTSTEP_BACKM 6
  124. #define STRIDER_AE_FOOTSTEP_LEFTL 7
  125. #define STRIDER_AE_FOOTSTEP_RIGHTL 8
  126. #define STRIDER_AE_FOOTSTEP_BACKL 9
  127. #define STRIDER_AE_WHOOSH_LEFT 11
  128. #define STRIDER_AE_WHOOSH_RIGHT 12
  129. #define STRIDER_AE_WHOOSH_BACK 13
  130. #define STRIDER_AE_CREAK_LEFT 21
  131. #define STRIDER_AE_CREAK_RIGHT 22
  132. #define STRIDER_AE_CREAK_BACK 23
  133. #define STRIDER_AE_SHOOTCANNON 100
  134. #define STRIDER_AE_CANNONHIT 101
  135. #define STRIDER_AE_SHOOTMINIGUN 105
  136. #define STRIDER_AE_STOMPHITL 110
  137. #define STRIDER_AE_STOMPHITR 111
  138. #define STRIDER_AE_FLICKL 112
  139. #define STRIDER_AE_FLICKR 113
  140. #define STRIDER_AE_WINDUPCANNON 114
  141. #define STRIDER_AE_DIE 999
  142. // UNDONE: Share properly with the client code!!!
  143. #define STRIDER_MSG_BIG_SHOT 1
  144. #define STRIDER_MSG_STREAKS 2
  145. #define STRIDER_MSG_DEAD 3
  146. #define STOMP_IK_SLOT 11
  147. // can hit anything within this range
  148. #define STRIDER_STOMP_RANGE 260
  149. // Crouch down if trying to shoot an enemy that's this close
  150. #define STRIDER_CROUCH_RANGE 4000.0f
  151. // Stand up again if crouched and engaging an enemy at this distance
  152. #define STRIDER_STAND_RANGE 6000.0f
  153. #define STRIDER_NO_TRACK_NAME "null"
  154. // Time after which if you haven't seen your enemy you stop facing him
  155. #define STRIDER_TIME_STOP_FACING_ENEMY 3.0
  156. // Spawnflags
  157. enum
  158. {
  159. SF_CAN_STOMP_PLAYER = 0x10000,
  160. SF_TAKE_MINIMAL_DAMAGE_FROM_NPCS = 0x20000
  161. };
  162. const float STRIDER_SPEED = 500;
  163. const float STRIDER_SPEED_CHANGE = .0067; // per think
  164. static void MoveToGround( Vector *position, CBaseEntity *ignore, const Vector &mins, const Vector &maxs );
  165. int s_iImpactEffectTexture = -1;
  166. //==================================================
  167. // Custom Activities
  168. //==================================================
  169. int ACT_STRIDER_LOOKL;
  170. int ACT_STRIDER_LOOKR;
  171. int ACT_STRIDER_DEPLOYRA1;
  172. int ACT_STRIDER_AIMRA1;
  173. int ACT_STRIDER_FINISHRA1;
  174. int ACT_STRIDER_DODGER;
  175. int ACT_STRIDER_DODGEL;
  176. int ACT_STRIDER_STOMPL;
  177. int ACT_STRIDER_STOMPR;
  178. int ACT_STRIDER_FLICKL;
  179. int ACT_STRIDER_FLICKR;
  180. int ACT_STRIDER_CARRIED;
  181. int ACT_STRIDER_DEPLOY;
  182. int ACT_STRIDER_GESTURE_DEATH;
  183. // UNDONE: Split sleep into 3 activities (start, loop, end)
  184. int ACT_STRIDER_SLEEP;
  185. // These bones have physics shadows
  186. // It allows a one-way interaction between the strider and
  187. // the physics world
  188. static const char *pFollowerBoneNames[] =
  189. {
  190. // Head
  191. "Combine_Strider.Body_Bone",
  192. #ifdef HL2_EPISODIC
  193. "Combine_Strider.Neck_Bone",
  194. "Combine_Strider.Gun_Bone1",
  195. "Combine_Strider.Gun_Bone2",
  196. #endif //HL2_EPISODIC
  197. // lower legs
  198. "Combine_Strider.Leg_Left_Bone1",
  199. "Combine_Strider.Leg_Right_Bone1",
  200. "Combine_Strider.Leg_Hind_Bone1",
  201. // upper legs
  202. "Combine_Strider.Leg_Left_Bone",
  203. "Combine_Strider.Leg_Right_Bone",
  204. "Combine_Strider.Leg_Hind_Bone",
  205. };
  206. // NOTE: These indices must directly correlate with the above list!
  207. enum
  208. {
  209. STRIDER_BODY_FOLLOWER_INDEX = 0,
  210. #ifdef HL2_EPISODIC
  211. STRIDER_NECK_FOLLOWER_INDEX,
  212. STRIDER_GUN1_FOLLOWER_INDEX,
  213. STRIDER_GUN2_FOLLOWER_INDEX,
  214. #endif //HL2_EPISODIC
  215. STRIDER_LEFT_LEG_FOLLOWER_INDEX,
  216. STRIDER_RIGHT_LEG_FOLLOWER_INDEX,
  217. STRIDER_BACK_LEG_FOLLOWER_INDEX,
  218. STRIDER_LEFT_UPPERLEG_FOLLOWER_INDEX,
  219. STRIDER_RIGHT_UPPERLEG_FOLLOWER_INDEX,
  220. STRIDER_BACK_UPPERLEG_FOLLOWER_INDEX,
  221. };
  222. #define MINIGUN_MAX_YAW 90.0f
  223. #define MINIGUN_MIN_YAW -90.0f
  224. #define MINIGUN_MAX_PITCH 45.0f
  225. #define MINIGUN_MIN_PITCH -45.0f
  226. //-----------------------------------------------------------------------------
  227. //
  228. // CNPC_Strider
  229. //
  230. //-----------------------------------------------------------------------------
  231. IMPLEMENT_SERVERCLASS_ST(CNPC_Strider, DT_NPC_Strider)
  232. SendPropVector(SENDINFO(m_vecHitPos), -1, SPROP_COORD),
  233. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 0 ), -1, SPROP_COORD ),
  234. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 1 ), -1, SPROP_COORD ),
  235. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 2 ), -1, SPROP_COORD ),
  236. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 3 ), -1, SPROP_COORD ),
  237. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 4 ), -1, SPROP_COORD ),
  238. SendPropVector( SENDINFO_NETWORKARRAYELEM( m_vecIKTarget, 5 ), -1, SPROP_COORD ),
  239. END_SEND_TABLE()
  240. //-------------------------------------
  241. LINK_ENTITY_TO_CLASS( npc_strider, CNPC_Strider );
  242. //-------------------------------------
  243. BEGIN_DATADESC( CNPC_Strider )
  244. #ifdef HL2_EPISODIC
  245. DEFINE_UTLVECTOR( m_hAttachedBusters, FIELD_EHANDLE ),
  246. #endif // HL2_EPISODIC
  247. DEFINE_EMBEDDED( m_EnemyUpdatedTimer ),
  248. DEFINE_EMBEDDEDBYREF( m_pMinigun ),
  249. DEFINE_FIELD( m_miniGunAmmo, FIELD_INTEGER ),
  250. DEFINE_FIELD( m_miniGunDirectAmmo, FIELD_INTEGER ),
  251. DEFINE_FIELD( m_nextStompTime, FIELD_TIME ),
  252. DEFINE_FIELD( m_nextShootTime, FIELD_TIME ),
  253. DEFINE_FIELD( m_ragdollTime, FIELD_TIME ),
  254. DEFINE_FIELD( m_miniGunShootDuration, FIELD_FLOAT ),
  255. DEFINE_FIELD( m_aimYaw, FIELD_FLOAT ),
  256. DEFINE_FIELD( m_aimPitch, FIELD_FLOAT ),
  257. DEFINE_FIELD( m_blastHit, FIELD_VECTOR ),
  258. DEFINE_FIELD( m_blastNormal, FIELD_VECTOR ),
  259. DEFINE_FIELD( m_vecHitPos, FIELD_POSITION_VECTOR ),
  260. DEFINE_AUTO_ARRAY( m_vecIKTarget, FIELD_POSITION_VECTOR ),
  261. DEFINE_EMBEDDED( m_PlayerFreePass ),
  262. DEFINE_EMBEDDED( m_PostureAnimationTimer ),
  263. DEFINE_EMBEDDED( m_BoneFollowerManager ),
  264. // m_iszStriderBusterName - recreated at load time
  265. // m_iszMagnadeClassname - recreated at load time
  266. // m_iszHunterClassname - recreated at load time
  267. DEFINE_FIELD( m_hRagdoll, FIELD_EHANDLE ),
  268. DEFINE_FIELD( m_hCannonTarget, FIELD_EHANDLE ),
  269. DEFINE_EMBEDDED( m_AttemptCannonLOSTimer ),
  270. DEFINE_FIELD( m_flSpeedScale, FIELD_FLOAT ),
  271. DEFINE_FIELD( m_flTargetSpeedScale, FIELD_FLOAT ),
  272. DEFINE_EMBEDDED( m_LowZCorrectionTimer ),
  273. DEFINE_FIELD( m_BodyTargetBone, FIELD_INTEGER ),
  274. DEFINE_FIELD( m_iVisibleEnemies, FIELD_INTEGER ),
  275. DEFINE_FIELD( m_flTargetAcquiredTime, FIELD_FLOAT ),
  276. DEFINE_FIELD( m_bCrouchLocked, FIELD_BOOLEAN ),
  277. DEFINE_FIELD( m_bNoCrouchWalk, FIELD_BOOLEAN ),
  278. DEFINE_FIELD( m_bDontCrouch, FIELD_BOOLEAN ),
  279. DEFINE_FIELD( m_bNoMoveToLOS, FIELD_BOOLEAN ),
  280. DEFINE_KEYFIELD( m_bDisableBoneFollowers, FIELD_BOOLEAN, "disablephysics" ),
  281. DEFINE_FIELD( m_idealHeight, FIELD_FLOAT ),
  282. DEFINE_FIELD( m_HeightVelocity, FIELD_FLOAT ),
  283. DEFINE_FIELD( m_prevYaw, FIELD_FLOAT ),
  284. DEFINE_FIELD( m_doTurn, FIELD_FLOAT ),
  285. DEFINE_FIELD( m_doLeft, FIELD_FLOAT ),
  286. DEFINE_FIELD( m_doRight, FIELD_FLOAT ),
  287. DEFINE_FIELD( m_flNextTurnAct, FIELD_TIME ),
  288. DEFINE_FIELD( m_strTrackName, FIELD_STRING ),
  289. DEFINE_FIELD( m_hFocus, FIELD_EHANDLE ),
  290. DEFINE_FIELD( m_hSmoke, FIELD_EHANDLE ),
  291. DEFINE_FIELD( m_flTimeLastAlertSound, FIELD_TIME ),
  292. DEFINE_FIELD( m_flTimeNextHuntSound, FIELD_TIME ),
  293. DEFINE_FIELD( m_flTimePlayerMissileDetected, FIELD_TIME ),
  294. DEFINE_FIELD( m_hPlayersMissile, FIELD_EHANDLE ),
  295. DEFINE_FIELD( m_bMinigunUseDirectFire, FIELD_BOOLEAN ),
  296. DEFINE_FIELD( m_bUseAggressiveBehavior, FIELD_BOOLEAN ),
  297. DEFINE_FIELD( m_bFastCrouch, FIELD_BOOLEAN ),
  298. DEFINE_FIELD( m_bMinigunEnabled, FIELD_BOOLEAN ),
  299. DEFINE_FIELD( m_bExploding, FIELD_BOOLEAN ),
  300. // inputs
  301. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetMinigunTime", InputSetMinigunTime ),
  302. DEFINE_INPUTFUNC( FIELD_STRING, "SetMinigunTarget", InputSetMinigunTarget ),
  303. DEFINE_INPUTFUNC( FIELD_STRING, "SetCannonTarget", InputSetCannonTarget ),
  304. DEFINE_INPUTFUNC( FIELD_STRING, "FlickRagdoll", InputFlickRagdoll ),
  305. DEFINE_INPUTFUNC( FIELD_VOID, "Crouch", InputCrouch ),
  306. DEFINE_INPUTFUNC( FIELD_VOID, "CrouchInstantly", InputCrouchInstantly ),
  307. DEFINE_INPUTFUNC( FIELD_VOID, "Stand", InputStand ),
  308. DEFINE_INPUTFUNC( FIELD_FLOAT, "SetHeight", InputSetHeight ),
  309. DEFINE_INPUTFUNC( FIELD_STRING, "SetTargetPath", InputSetTargetPath ),
  310. DEFINE_INPUTFUNC( FIELD_STRING, "ClearTargetPath", InputClearTargetPath ),
  311. DEFINE_INPUTFUNC( FIELD_VOID, "DisableCrouchWalk", InputDisableCrouchWalk ),
  312. DEFINE_INPUTFUNC( FIELD_VOID, "EnableCrouchWalk", InputEnableCrouchWalk ),
  313. DEFINE_INPUTFUNC( FIELD_VOID, "EnableAggressiveBehavior", InputEnableAggressiveBehavior ),
  314. DEFINE_INPUTFUNC( FIELD_VOID, "DisableAggressiveBehavior", InputDisableAggressiveBehavior ),
  315. DEFINE_INPUTFUNC( FIELD_VOID, "DisableMinigun", InputDisableMinigun ),
  316. DEFINE_INPUTFUNC( FIELD_VOID, "EnableMinigun", InputEnableMinigun ),
  317. DEFINE_INPUTFUNC( FIELD_FLOAT, "StopShootingMinigunForSeconds", InputStopShootingMinigunForSeconds ),
  318. DEFINE_INPUTFUNC( FIELD_VOID, "DisableCrouch", InputDisableCrouch ),
  319. DEFINE_INPUTFUNC( FIELD_VOID, "DisableMoveToLOS", InputDisableMoveToLOS ),
  320. DEFINE_INPUTFUNC( FIELD_STRING, "DisableCollisionWith", InputDisableCollisionWith ),
  321. DEFINE_INPUTFUNC( FIELD_STRING, "EnableCollisionWith", InputEnableCollisionWith ),
  322. DEFINE_INPUTFUNC( FIELD_VOID, "Explode", InputExplode ),
  323. DEFINE_INPUTFUNC( FIELD_FLOAT, "ScaleGroundSpeed", InputScaleGroundSpeed ),
  324. // Function Pointers
  325. // DEFINE_FUNCTION( JumpTouch ),
  326. DEFINE_THINKFUNC( CarriedThink ),
  327. DEFINE_THINKFUNC( CannonHitThink ),
  328. END_DATADESC()
  329. //---------------------------------------------------------
  330. float CNPC_Strider::gm_strideLength;
  331. int CNPC_Strider::gm_BodyHeightPoseParam;
  332. int CNPC_Strider::gm_YawControl;
  333. int CNPC_Strider::gm_PitchControl;
  334. int CNPC_Strider::gm_CannonAttachment;
  335. float CNPC_Strider::gm_zCannonDist;
  336. float CNPC_Strider::gm_zMinigunDist;
  337. Vector CNPC_Strider::gm_vLocalRelativePositionCannon;
  338. Vector CNPC_Strider::gm_vLocalRelativePositionMinigun;
  339. //---------------------------------------------------------
  340. //---------------------------------------------------------
  341. CNPC_Strider::CNPC_Strider()
  342. {
  343. m_strTrackName = MAKE_STRING( STRIDER_NO_TRACK_NAME );
  344. m_hFocus = NULL;
  345. m_pMinigun = new CStriderMinigun;
  346. m_hSmoke = NULL;
  347. m_PlayerFreePass.SetOuter( this );
  348. m_bExploding = false;
  349. }
  350. //---------------------------------------------------------
  351. //---------------------------------------------------------
  352. CNPC_Strider::~CNPC_Strider()
  353. {
  354. delete m_pMinigun;
  355. }
  356. //---------------------------------------------------------
  357. //---------------------------------------------------------
  358. void CNPC_Strider::Precache()
  359. {
  360. if ( !GetModelName() )
  361. {
  362. SetModelName( MAKE_STRING( "models/combine_strider.mdl" ) );
  363. }
  364. PrecacheModel( STRING( GetModelName() ) );
  365. PropBreakablePrecacheAll( GetModelName() );
  366. PrecacheScriptSound( "NPC_Strider.StriderBusterExplode" );
  367. PrecacheScriptSound( "explode_5" );
  368. PrecacheScriptSound( "NPC_Strider.Charge" );
  369. PrecacheScriptSound( "NPC_Strider.RagdollDetach" );
  370. PrecacheScriptSound( "NPC_Strider.Whoosh" );
  371. PrecacheScriptSound( "NPC_Strider.Creak" );
  372. PrecacheScriptSound( "NPC_Strider.Alert" );
  373. PrecacheScriptSound( "NPC_Strider.Pain" );
  374. PrecacheScriptSound( "NPC_Strider.Death" );
  375. PrecacheScriptSound( "NPC_Strider.FireMinigun" );
  376. PrecacheScriptSound( "NPC_Strider.Shoot" );
  377. PrecacheScriptSound( "NPC_Strider.OpenHatch" );
  378. PrecacheScriptSound( "NPC_Strider.Footstep" );
  379. PrecacheScriptSound( "NPC_Strider.Skewer" );
  380. PrecacheScriptSound( "NPC_Strider.Hunt" );
  381. PrecacheMaterial( "effects/water_highlight" );
  382. s_iImpactEffectTexture = PrecacheModel( "sprites/physbeam.vmt" );
  383. PrecacheMaterial( "sprites/bluelaser1" );
  384. PrecacheMaterial( "effects/blueblacklargebeam" );
  385. PrecacheMaterial( "effects/strider_pinch_dudv" );
  386. PrecacheMaterial( "effects/blueblackflash" );
  387. PrecacheMaterial( "effects/strider_bulge_dudv" );
  388. PrecacheMaterial( "effects/strider_muzzle" );
  389. PrecacheModel( "models/chefhat.mdl" );
  390. UTIL_PrecacheOther( "sparktrail" );
  391. BaseClass::Precache();
  392. }
  393. //---------------------------------------------------------
  394. //---------------------------------------------------------
  395. void CNPC_Strider::Spawn()
  396. {
  397. Precache();
  398. m_miniGunAmmo = GetAmmoDef()->Index("StriderMinigun");
  399. m_miniGunDirectAmmo = GetAmmoDef()->Index("StriderMinigunDirect");
  400. m_pMinigun->Init();
  401. EnableServerIK();
  402. SetModel( STRING( GetModelName() ) );
  403. BaseClass::Spawn();
  404. //m_debugOverlays |= OVERLAY_NPC_ROUTE_BIT | OVERLAY_BBOX_BIT;
  405. SetHullType( HULL_LARGE_CENTERED );
  406. SetHullSizeNormal();
  407. SetDefaultEyeOffset();
  408. SetNavType( NAV_FLY );
  409. m_flGroundSpeed = STRIDER_SPEED;
  410. m_flSpeedScale = m_flTargetSpeedScale = 1.0;
  411. m_NPCState = NPC_STATE_NONE;
  412. m_bloodColor = DONT_BLEED;
  413. m_iHealth = sk_strider_health.GetFloat();
  414. m_iMaxHealth = 500;
  415. m_flFieldOfView = 0.0; // 180 degrees
  416. AddFlag( FL_FLY );
  417. SetCollisionGroup( HL2COLLISION_GROUP_STRIDER );
  418. SetSolid( SOLID_BBOX );
  419. AddSolidFlags( FSOLID_NOT_STANDABLE );
  420. SetMoveType( MOVETYPE_STEP );
  421. AddEFlags( EFL_NO_DISSOLVE | EFL_NO_MEGAPHYSCANNON_RAGDOLL );
  422. // Cached for quick comparisons
  423. m_iszStriderBusterName = AllocPooledString( "weapon_striderbuster" );
  424. m_iszMagnadeClassname = AllocPooledString( "npc_grenade_magna" );
  425. m_iszHunterClassname = AllocPooledString( "npc_hunter" );
  426. // BMCD: Force collision hooks
  427. AddSolidFlags( FSOLID_CUSTOMRAYTEST | FSOLID_CUSTOMBOXTEST );
  428. SetupGlobalModelData();
  429. CapabilitiesAdd( bits_CAP_MOVE_FLY | bits_CAP_INNATE_RANGE_ATTACK2 | bits_CAP_INNATE_MELEE_ATTACK1 | bits_CAP_INNATE_MELEE_ATTACK2 | bits_CAP_SQUAD );
  430. // Don't allow us to skip animation setup because our attachments are critical to us!
  431. SetBoneCacheFlags( BCF_NO_ANIMATION_SKIP );
  432. // find the ground, move up to strider stand height
  433. Vector mins(-16,-16,-16), maxs(16,16,16);
  434. Vector origin = GetLocalOrigin();
  435. MoveToGround( &origin, this, mins, maxs );
  436. origin.z += GetMaxHeight();//(GetAbsOrigin().z - vecSurroundMins.z) + mins.z;
  437. SetLocalOrigin( origin );
  438. NPCInit();
  439. // Strider doesn't care about missiles for now.
  440. AddClassRelationship( CLASS_MISSILE, D_NU, 0 );
  441. m_bCrouchLocked = false;
  442. m_bMinigunEnabled = true;
  443. m_PostureAnimationTimer.Set( 8, 16 );
  444. m_BodyTargetBone = -1;
  445. CreateFocus();
  446. m_EnemyUpdatedTimer.Set( 0 );
  447. // Don't minigun things farther than 500 feet away.
  448. m_flDistTooFar = 500.0f * 12.0f;
  449. GetEnemies()->SetFreeKnowledgeDuration( strider_free_knowledge.GetFloat() );
  450. m_hPlayersMissile.Set( NULL );
  451. m_flTimeNextHuntSound = gpGlobals->curtime - 1.0f;
  452. }
  453. void CNPC_Strider::SetupGlobalModelData()
  454. {
  455. gm_BodyHeightPoseParam = LookupPoseParameter( "body_height" );
  456. gm_YawControl = LookupPoseParameter( "yaw" );
  457. gm_PitchControl = LookupPoseParameter( "pitch" );
  458. gm_CannonAttachment = LookupAttachment( "BigGun" );
  459. // BMCD: Get the conservative boxes from sequences
  460. Vector mins, maxs;
  461. ExtractBbox( SelectHeaviestSequence( ACT_WALK ), mins, maxs );
  462. CNPC_Strider::gm_strideLength = (maxs.x - mins.x) * 0.5;
  463. // UNDONE: use crouch when crouched
  464. CollisionProp()->SetSurroundingBoundsType( USE_HITBOXES );
  465. }
  466. void CNPC_Strider::OnRestore()
  467. {
  468. BaseClass::OnRestore();
  469. SetupGlobalModelData();
  470. CreateVPhysics();
  471. // Cached for quick comparisons
  472. m_iszStriderBusterName = FindPooledString( "weapon_striderbuster" );
  473. m_iszMagnadeClassname = FindPooledString( "npc_grenade_magna" );
  474. }
  475. bool CNPC_Strider::m_sbStaticPoseParamsLoaded = false;
  476. int CNPC_Strider::m_poseMiniGunYaw = 0;
  477. int CNPC_Strider::m_poseMiniGunPitch = 0;
  478. //-----------------------------------------------------------------------------
  479. // Purpose: Cache whatever pose parameters we intend to use
  480. //-----------------------------------------------------------------------------
  481. void CNPC_Strider::PopulatePoseParameters( void )
  482. {
  483. if (!m_sbStaticPoseParamsLoaded)
  484. {
  485. m_poseMiniGunYaw = LookupPoseParameter( "miniGunYaw");
  486. m_poseMiniGunPitch = LookupPoseParameter( "miniGunPitch" );
  487. m_sbStaticPoseParamsLoaded = true;
  488. }
  489. BaseClass::PopulatePoseParameters();
  490. }
  491. //---------------------------------------------------------
  492. //---------------------------------------------------------
  493. bool CNPC_Strider::CreateVPhysics()
  494. {
  495. // The strider has bone followers for every solid part of its body,
  496. // so there's no reason for the bounding box to be solid.
  497. //BaseClass::CreateVPhysics();
  498. if ( !m_bDisableBoneFollowers )
  499. {
  500. InitBoneFollowers();
  501. }
  502. return true;
  503. }
  504. //-----------------------------------------------------------------------------
  505. // Purpose:
  506. //-----------------------------------------------------------------------------
  507. void CNPC_Strider::InitBoneFollowers( void )
  508. {
  509. // Don't do this if we're already loaded
  510. if ( m_BoneFollowerManager.GetNumBoneFollowers() != 0 )
  511. return;
  512. // Init our followers
  513. m_BoneFollowerManager.InitBoneFollowers( this, ARRAYSIZE(pFollowerBoneNames), pFollowerBoneNames );
  514. }
  515. //---------------------------------------------------------
  516. //---------------------------------------------------------
  517. void CNPC_Strider::PostNPCInit()
  518. {
  519. BaseClass::PostNPCInit();
  520. if( CarriedByDropship() )
  521. {
  522. SetMoveType( MOVETYPE_NONE );
  523. SetActivity( (Activity)ACT_STRIDER_CARRIED );
  524. SetThink( &CNPC_Strider::CarriedThink );
  525. RemoveFlag( FL_FLY );
  526. }
  527. m_PlayerFreePass.SetPassTarget( UTIL_PlayerByIndex(1) );
  528. AI_FreePassParams_t freePassParams =
  529. {
  530. strider_free_pass_start_time.GetFloat(), // timeToTrigger
  531. strider_free_pass_duration.GetFloat(), // duration
  532. strider_free_pass_move_tolerance.GetFloat(), // moveTolerance
  533. strider_free_pass_refill_rate.GetFloat(), // refillRate
  534. strider_free_pass_cover_dist.GetFloat(), // coverDist
  535. strider_peek_time.GetFloat(), // peekTime
  536. strider_peek_time_after_damage.GetFloat(), // peekTimeAfterDamage
  537. strider_peek_eye_dist.GetFloat(), // peekEyeDist
  538. strider_peek_eye_dist_z.GetFloat(), // peekEyeDistZ
  539. };
  540. m_PlayerFreePass.SetParams( freePassParams );
  541. }
  542. //---------------------------------------------------------
  543. //---------------------------------------------------------
  544. void CNPC_Strider::Activate()
  545. {
  546. BaseClass::Activate();
  547. const char *pszBodyTargetBone = "combine_strider.neck_bone";
  548. m_BodyTargetBone = LookupBone( pszBodyTargetBone );
  549. if ( m_BodyTargetBone == -1 )
  550. {
  551. DevMsg( "Couldn't find npc_strider bone %s, which is used as target for others\n", pszBodyTargetBone );
  552. }
  553. gm_BodyHeightPoseParam = LookupPoseParameter( "body_height" );
  554. gm_YawControl = LookupPoseParameter( "yaw" );
  555. gm_PitchControl = LookupPoseParameter( "pitch" );
  556. gm_CannonAttachment = LookupAttachment( "BigGun" );
  557. if ( gm_zCannonDist == 0 )
  558. {
  559. // Have to create a virgin strider to ensure proper pose
  560. CNPC_Strider *pStrider = (CNPC_Strider *)CreateEntityByName( "npc_strider" );
  561. Assert(pStrider);
  562. pStrider->m_bDisableBoneFollowers = true; // don't create these since we're just going to destroy him
  563. DispatchSpawn( pStrider );
  564. pStrider->SetActivity( ACT_DIERAGDOLL );
  565. pStrider->InvalidateBoneCache();
  566. gm_zCannonDist = pStrider->CannonPosition().z - pStrider->GetAbsOrigin().z;
  567. // Currently just using the gun for the vertical component!
  568. Vector defEyePos;
  569. pStrider->GetAttachment( "minigunbase", defEyePos );
  570. gm_zMinigunDist = defEyePos.z - pStrider->GetAbsOrigin().z;
  571. Vector position;
  572. pStrider->GetAttachment( "biggun", position );
  573. VectorITransform( position, pStrider->EntityToWorldTransform(), gm_vLocalRelativePositionCannon );
  574. pStrider->GetAttachment( "minigun", position );
  575. VectorITransform( position, pStrider->EntityToWorldTransform(), gm_vLocalRelativePositionMinigun );
  576. UTIL_Remove( pStrider );
  577. }
  578. }
  579. //---------------------------------------------------------
  580. //---------------------------------------------------------
  581. void CNPC_Strider::UpdateOnRemove()
  582. {
  583. m_BoneFollowerManager.DestroyBoneFollowers();
  584. #ifdef HL2_EPISODIC
  585. m_hAttachedBusters.Purge();
  586. #endif // HL2_EPISODIC
  587. BaseClass::UpdateOnRemove();
  588. }
  589. //---------------------------------------------------------
  590. //---------------------------------------------------------
  591. void CNPC_Strider::InitBoneControllers()
  592. {
  593. BaseClass::InitBoneControllers( );
  594. SetHeight( GetMaxHeight() );
  595. SetIdealHeight( GetMaxHeight() );
  596. }
  597. //---------------------------------------------------------
  598. //---------------------------------------------------------
  599. Class_T CNPC_Strider::Classify()
  600. {
  601. if( CarriedByDropship() )
  602. return CLASS_NONE;
  603. return CLASS_COMBINE;
  604. }
  605. //---------------------------------------------------------
  606. //---------------------------------------------------------
  607. bool CNPC_Strider::ShouldAttractAutoAim( CBaseEntity *pAimingEnt )
  608. {
  609. #ifdef HL2_EPISODIC
  610. if( m_hAttachedBusters.Count() > 0 )
  611. return false;
  612. #endif//HL2_EPISODIC
  613. return BaseClass::ShouldAttractAutoAim( pAimingEnt );
  614. }
  615. //---------------------------------------------------------
  616. //---------------------------------------------------------
  617. int CNPC_Strider::DrawDebugTextOverlays()
  618. {
  619. int text_offset = BaseClass::DrawDebugTextOverlays();
  620. if (m_debugOverlays & OVERLAY_TEXT_BIT)
  621. {
  622. EntityText(text_offset,CFmtStr("Ideal Height: %.1f; Height: %.1f", GetIdealHeight(), GetHeight()),0);
  623. text_offset++;
  624. if ( m_PlayerFreePass.HasPass() )
  625. {
  626. EntityText(text_offset,CFmtStr("Free pass: %.1f", m_PlayerFreePass.GetTimeRemaining()),0);
  627. text_offset++;
  628. }
  629. CBaseEntity *pPlayer = UTIL_PlayerByIndex(1);
  630. if ( pPlayer )
  631. {
  632. if ( GetSenses()->ShouldSeeEntity( pPlayer ) && GetSenses()->CanSeeEntity( pPlayer ) )
  633. {
  634. EntityText(text_offset,"See player",0);
  635. text_offset++;
  636. }
  637. else
  638. {
  639. float temp = m_PlayerFreePass.GetTimeRemaining();
  640. m_PlayerFreePass.SetTimeRemaining( 0 );
  641. if ( BaseClass::FVisible( pPlayer ) && !FVisible( pPlayer ) )
  642. {
  643. EntityText(text_offset,"Player peeking",0);
  644. text_offset++;
  645. }
  646. m_PlayerFreePass.SetTimeRemaining( temp );
  647. }
  648. }
  649. if ( m_flTargetSpeedScale != 1.0 )
  650. {
  651. EntityText(text_offset,CFmtStr( "Speed scaled to %.1f", m_flGroundSpeed ),0);
  652. text_offset++;
  653. }
  654. }
  655. return text_offset;
  656. }
  657. //---------------------------------------------------------
  658. //---------------------------------------------------------
  659. Vector CNPC_Strider::EyePosition()
  660. {
  661. Vector eyePosition = GetAdjustedOrigin();
  662. eyePosition.z += gm_zMinigunDist;
  663. return eyePosition;
  664. }
  665. //---------------------------------------------------------
  666. //---------------------------------------------------------
  667. const Vector &CNPC_Strider::GetViewOffset()
  668. {
  669. Vector vOffset;
  670. vOffset.x = 0;
  671. vOffset.y = 0;
  672. vOffset.z = ( GetHeight() - GetMaxHeightModel() ) + gm_zMinigunDist;
  673. Assert( VectorsAreEqual( GetAbsOrigin() + vOffset, EyePosition(), 0.1 ));
  674. SetViewOffset( vOffset );
  675. return BaseClass::GetViewOffset();
  676. }
  677. //---------------------------------------------------------
  678. //---------------------------------------------------------
  679. void CNPC_Strider::CalculateIKLocks( float currentTime )
  680. {
  681. BaseClass::CalculateIKLocks( currentTime );
  682. if ( m_pIk && m_pIk->m_target.Count() )
  683. {
  684. Assert(m_pIk->m_target.Count() > STOMP_IK_SLOT);
  685. // HACKHACK: Hardcoded 11??? Not a cleaner way to do this
  686. CIKTarget &target = m_pIk->m_target[STOMP_IK_SLOT];
  687. target.SetPos( m_vecHitPos.Get() );
  688. for ( int i = 0; i < NUM_STRIDER_IK_TARGETS; i++ )
  689. {
  690. target = m_pIk->m_target[i];
  691. if (!target.IsActive())
  692. continue;
  693. m_vecIKTarget.Set( i, target.est.pos );
  694. #if 0
  695. // yellow box at target pos - helps debugging
  696. //if (i == 0)
  697. NDebugOverlay::Line( GetAbsOrigin(), m_vecIKTarget[i], 255, 255, 0, 0, 0.1 );
  698. NDebugOverlay::Box( m_vecIKTarget[i], Vector(-8,-8,-8), Vector(8,8,8), 255, 255, 0, 0, 4.0 );
  699. #endif
  700. }
  701. }
  702. }
  703. //---------------------------------------------------------
  704. //---------------------------------------------------------
  705. void CNPC_Strider::NPCThink(void)
  706. {
  707. if ( m_hRagdoll.Get() )
  708. {
  709. m_nextStompTime = gpGlobals->curtime + 5;
  710. }
  711. if ( m_flTargetSpeedScale > 0.01 )
  712. {
  713. float deltaSpeedScale = m_flSpeedScale - m_flTargetSpeedScale;
  714. if ( fabsf( deltaSpeedScale ) > .01 )
  715. {
  716. if ( deltaSpeedScale < 0 )
  717. {
  718. m_flSpeedScale += STRIDER_SPEED_CHANGE;
  719. if ( m_flSpeedScale > m_flTargetSpeedScale )
  720. {
  721. m_flSpeedScale = m_flTargetSpeedScale;
  722. }
  723. }
  724. else
  725. {
  726. m_flSpeedScale -= STRIDER_SPEED_CHANGE;
  727. if ( m_flSpeedScale < m_flTargetSpeedScale )
  728. {
  729. m_flSpeedScale = m_flTargetSpeedScale;
  730. }
  731. }
  732. }
  733. else
  734. {
  735. m_flSpeedScale = m_flTargetSpeedScale;
  736. }
  737. }
  738. else
  739. {
  740. m_flTargetSpeedScale = 1.0;
  741. }
  742. BaseClass::NPCThink();
  743. m_pMinigun->Think( this, 0.1 );
  744. // update follower bones
  745. m_BoneFollowerManager.UpdateBoneFollowers(this);
  746. }
  747. //---------------------------------------------------------
  748. //---------------------------------------------------------
  749. void CNPC_Strider::PrescheduleThink()
  750. {
  751. if( IsUsingAggressiveBehavior() && GetEnemy() && GetEnemy()->IsPlayer() )
  752. {
  753. AddFacingTarget( GetEnemy(), GetEnemies()->LastKnownPosition( GetEnemy() ) , 1.0, 2.0 );
  754. }
  755. // Next missile will kill me!
  756. if( GetHealth() <= 50 && random->RandomInt( 0, 20 ) == 0 )
  757. {
  758. CBaseEntity *pTrail = CreateEntityByName( "sparktrail" );
  759. pTrail->SetOwnerEntity( this );
  760. pTrail->Spawn();
  761. }
  762. #if 0
  763. NDebugOverlay::Cross3D( GetAdjustedOrigin(), 16, 128, 128, 128, false, .1 );
  764. Vector vIdealOrigin = GetAbsOrigin();
  765. vIdealOrigin.z -= GetMaxHeightModel() - GetIdealHeight();
  766. NDebugOverlay::Cross3D( vIdealOrigin, 16, 255, 255, 255, false, .1 );
  767. #endif
  768. if( strider_eyepositions.GetBool() )
  769. {
  770. NDebugOverlay::Cross3D( EyePosition(), 16, 0, 255, 0, false, 0.1 );
  771. NDebugOverlay::Cross3D( EyePositionCrouched(), 16, 255, 255, 0, false, 0.1 );
  772. }
  773. if( strider_show_focus.GetBool() )
  774. {
  775. QAngle angles;
  776. angles.x = gpGlobals->curtime * 20.0f;
  777. angles.y = angles.x * 0.5f;
  778. angles.z = 0.0f;
  779. NDebugOverlay::Cross3DOriented( GetFocus()->GetAbsOrigin(), angles, 24, 255, 255, 0, false, 0.1 );
  780. }
  781. }
  782. //---------------------------------------------------------
  783. //---------------------------------------------------------
  784. void CNPC_Strider::GatherConditions()
  785. {
  786. if ( AIGetNumFollowers( this, m_iszHunterClassname ) == 0 )
  787. {
  788. // This works with old data because need to do before base class so as to not choose as enemy
  789. if ( m_PlayerFreePass.HasPass() || ( !m_pMinigun->IsShooting() || GetEnemy() != m_PlayerFreePass.GetPassTarget() ) ) // no free pass when in midst of shooting at target
  790. m_PlayerFreePass.Update();
  791. }
  792. else
  793. {
  794. m_PlayerFreePass.Reset( strider_free_pass_after_escorts_dead.GetFloat(), strider_free_pass_tolerance_after_escorts_dead.GetFloat() );
  795. }
  796. if( IsUsingAggressiveBehavior() )
  797. {
  798. if( m_PlayerFreePass.HasPass() && !m_pMinigun->IsShooting() )
  799. {
  800. // Make the minigun stitch
  801. m_bMinigunUseDirectFire = false;
  802. }
  803. }
  804. //---------------------------------
  805. BaseClass::GatherConditions();
  806. if( IsUsingAggressiveBehavior() )
  807. {
  808. if( GetEnemy() )
  809. {
  810. if( HasCondition( COND_SEE_ENEMY ) )
  811. {
  812. // Keep setting up to play my hunt sound at some random time after losing sight of my enemy.
  813. m_flTimeNextHuntSound = gpGlobals->curtime + 1.0f;
  814. }
  815. else
  816. {
  817. if( gpGlobals->curtime >= m_flTimeNextHuntSound && !m_pMinigun->IsShooting() )
  818. {
  819. HuntSound();
  820. }
  821. }
  822. }
  823. if( m_hPlayersMissile )
  824. {
  825. if( !m_pMinigun->IsShooting() && GetEnemy() && GetEnemy()->IsPlayer() )
  826. {
  827. // If the missile is closer to the player than I am, stay suppressed. This is essentially
  828. // allowing the missile to strike me if it was fired off before I started shooting.
  829. // If the missile passes me or goes way off course, I can shoot.
  830. float flPlayerMissileDist;
  831. float flPlayerStriderDist;
  832. flPlayerMissileDist = GetEnemy()->GetAbsOrigin().DistTo( m_hPlayersMissile->GetAbsOrigin() );
  833. flPlayerStriderDist = GetEnemy()->GetAbsOrigin().DistTo( EyePosition() );
  834. float flDiff = flPlayerMissileDist - flPlayerStriderDist;
  835. // Figure out how long it's been since I've fired my cannon because of a player's missile.
  836. float flTimeSuppressed = gpGlobals->curtime - m_flTimePlayerMissileDetected;
  837. if( flDiff < strider_missile_suppress_dist.GetFloat() && flTimeSuppressed < strider_missile_suppress_time.GetFloat() )
  838. {
  839. // Defer the minigun until/unless the missile has passed me by 10 feet
  840. m_pMinigun->StopShootingForSeconds( this, GetEnemy(), 0.5f );
  841. }
  842. }
  843. }
  844. }
  845. // This pair of conditions is nice to have around...
  846. if( m_pMinigun->IsShooting() )
  847. {
  848. SetCondition( COND_STRIDER_MINIGUN_SHOOTING );
  849. }
  850. else
  851. {
  852. SetCondition( COND_STRIDER_MINIGUN_NOT_SHOOTING );
  853. }
  854. if( GetCannonTarget() )
  855. {
  856. SetCondition( COND_STRIDER_HAS_CANNON_TARGET );
  857. if( strider_show_cannonlos.GetBool() )
  858. {
  859. trace_t tr;
  860. UTIL_TraceLine( CannonPosition(), GetCannonTarget()->WorldSpaceCenter(), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
  861. NDebugOverlay::Line( tr.startpos, tr.endpos, 0, 255, 0, false, 0.1 );
  862. if( tr.fraction != 1.0 )
  863. NDebugOverlay::Line( tr.endpos, GetCannonTarget()->WorldSpaceCenter(), 255, 0, 0, false, 0.1 );
  864. }
  865. }
  866. else
  867. {
  868. ClearCondition( COND_STRIDER_HAS_CANNON_TARGET );
  869. }
  870. ClearCondition( COND_CAN_RANGE_ATTACK2 );
  871. ClearCondition( COND_STRIDER_HAS_LOS_Z );
  872. // If not locked into a crouch, look into adjusting height to attack targets.
  873. if( !m_bCrouchLocked && !m_bDontCrouch )
  874. {
  875. if( m_hCannonTarget != NULL )
  876. {
  877. if( !IsStriderCrouching() && !IsStriderStanding() )
  878. {
  879. if ( WeaponLOSCondition( GetAdjustedOrigin(), m_hCannonTarget->GetAbsOrigin(), false ) )
  880. {
  881. SetCondition( COND_CAN_RANGE_ATTACK2 );
  882. }
  883. else
  884. {
  885. GatherHeightConditions( GetAdjustedOrigin(), m_hCannonTarget );
  886. }
  887. }
  888. }
  889. else if( GetEnemy() )
  890. {
  891. if ( strider_distributed_fire.GetBool() && !IsUsingAggressiveBehavior() )
  892. {
  893. m_iVisibleEnemies = 0;
  894. AIEnemiesIter_t iter;
  895. for( AI_EnemyInfo_t *pEMemory = GetEnemies()->GetFirst(&iter); pEMemory != NULL; pEMemory = GetEnemies()->GetNext(&iter) )
  896. {
  897. if( IRelationType( pEMemory->hEnemy ) != D_NU && IRelationType( pEMemory->hEnemy ) != D_LI )
  898. {
  899. if( pEMemory->timeLastSeen == gpGlobals->curtime )
  900. {
  901. m_iVisibleEnemies++;
  902. }
  903. }
  904. }
  905. // If I'm on target and see more targets than just this one, move on to another target for a bit!
  906. // Because the Mingun's state will stay "on target" until the minigun gets a chance to think,
  907. // and this function may be called several times per strider think, don't call this code anymore in the same
  908. // think when a new enemy is chosen.
  909. //
  910. // Don't switch targets if shooting at a bullseye! Level designers depend on bullseyes.
  911. if( GetEnemy() && m_pMinigun->IsShooting() && GetTimeEnemyAcquired() != gpGlobals->curtime )
  912. {
  913. if( m_pMinigun->IsOnTarget( 3 ) && !FClassnameIs( GetEnemy(), "npc_bullseye" ) )
  914. {
  915. if( m_iVisibleEnemies > 1 )
  916. {
  917. // Time to ignore this guy for a little while and switch targets.
  918. GetEnemies()->SetTimeValidEnemy( GetEnemy(), gpGlobals->curtime + ( STRIDER_IGNORE_TARGET_DURATION * m_iVisibleEnemies ) );
  919. SetEnemy( NULL, false );
  920. ChooseEnemy();
  921. }
  922. else if( GetEnemy()->IsPlayer() && GetEnemy() == m_pMinigun->GetTarget() )
  923. {
  924. // Give the poor target a break.
  925. m_pMinigun->StopShootingForSeconds( this, GetEnemy(), GetMinigunShootDowntime() );
  926. }
  927. }
  928. }
  929. }
  930. if ( GetEnemy() ) // Can go null above
  931. {
  932. if ( !IsStriderCrouching() && !IsStriderStanding() &&
  933. ( !HasCondition( COND_SEE_ENEMY ) ||
  934. !WeaponLOSCondition( GetAdjustedOrigin(), GetEnemy()->BodyTarget( GetAdjustedOrigin() ), false ) ) )
  935. {
  936. #if 0
  937. if ( !HasCondition( COND_STRIDER_SHOULD_CROUCH ) )
  938. SetIdealHeight( MIN( GetMaxHeight(), GetHeight() + 75.0 * 0.1 ) ); // default to rising up
  939. #endif
  940. GatherHeightConditions( GetAdjustedOrigin(), GetEnemy() );
  941. }
  942. }
  943. }
  944. else
  945. SetIdealHeight( GetMaxHeight() );
  946. }
  947. else
  948. {
  949. if( m_hCannonTarget != NULL && CurrentWeaponLOSCondition( m_hCannonTarget->GetAbsOrigin(), false ) )
  950. SetCondition( COND_CAN_RANGE_ATTACK2 );
  951. }
  952. if( m_bDontCrouch )
  953. {
  954. if( HasCondition( COND_STRIDER_SHOULD_CROUCH ) )
  955. {
  956. Msg("TELL WEDGE I'M TRYING TO CROUCH!\n");
  957. }
  958. ClearCondition( COND_STRIDER_SHOULD_CROUCH );
  959. }
  960. }
  961. //---------------------------------------------------------
  962. //---------------------------------------------------------
  963. void CNPC_Strider::GatherHeightConditions( const Vector &vTestPos, CBaseEntity *pEntity )
  964. {
  965. if ( HasCondition( COND_STRIDER_SHOULD_CROUCH ) )
  966. return;
  967. float maxZ = (GetAbsOrigin().z - (GetMaxHeightModel() - GetMaxHeight()));
  968. float minZ = (maxZ - ( GetMaxHeight() - GetMinHeight()));;
  969. float newHeight = FLT_MAX;
  970. if( FInViewCone( pEntity ) && GetWeaponLosZ( vTestPos, minZ, maxZ, GetHeightRange() * .1, pEntity, &newHeight ) )
  971. {
  972. bool bDoProceduralHeightChange = true;
  973. newHeight = GetMaxHeightModel() - ( GetAbsOrigin().z - newHeight);
  974. if ( m_LowZCorrectionTimer.Expired() )
  975. {
  976. // Hack to handle discrepency between ideal gun pos and actual pos due to strider head tilt in crouch pos
  977. if ( pEntity && fabs( newHeight - GetHeight() ) < 12 && newHeight < GetMinHeight() + GetHeightRange() * .33 )
  978. {
  979. Vector muzzlePos;
  980. Vector targetPos = pEntity->BodyTarget( GetAdjustedOrigin() );
  981. GetAttachment( "minigun", muzzlePos );
  982. trace_t tr;
  983. AI_TraceLine( muzzlePos, targetPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr);
  984. if ( ( tr.m_pEnt != pEntity) && tr.fraction != 1.0 && !CanShootThrough( tr, targetPos ) )
  985. {
  986. if ( !GetWeaponLosZ( vTestPos, minZ + GetHeightRange() * .33, maxZ, GetHeightRange() * .1, pEntity, &newHeight ) )
  987. {
  988. return;
  989. }
  990. newHeight = GetMaxHeightModel() - ( GetAbsOrigin().z - newHeight);
  991. }
  992. else
  993. {
  994. m_LowZCorrectionTimer.Set( 5.0 );
  995. }
  996. }
  997. }
  998. if ( !strider_always_use_procedural_height.GetBool() )
  999. {
  1000. // If going from max to min, or min to max, use animations 60% of the time
  1001. if ( fabsf(GetMaxHeight() - GetHeight()) < 0.1 && fabsf(GetMinHeight() - newHeight) < 0.1 )
  1002. {
  1003. if ( random->RandomInt(1, 10 ) <= 6 )
  1004. {
  1005. SetCondition( COND_STRIDER_SHOULD_CROUCH );
  1006. bDoProceduralHeightChange = false;
  1007. }
  1008. }
  1009. else if ( fabsf(GetMinHeight() - GetHeight()) < 0.1 && fabsf(GetMaxHeight() - newHeight) < 0.1 )
  1010. {
  1011. if ( random->RandomInt(1, 10 ) <= 6 )
  1012. {
  1013. SetCondition( COND_STRIDER_SHOULD_STAND );
  1014. bDoProceduralHeightChange = false;
  1015. }
  1016. }
  1017. // Otherwise, if going from near max or near min to the other, use animations based on time
  1018. if ( bDoProceduralHeightChange && m_PostureAnimationTimer.Expired() )
  1019. {
  1020. if ( GetHeight() - GetMinHeight() > GetHeightRange() * .85 && newHeight - GetMinHeight() < GetHeightRange() * .15 )
  1021. {
  1022. m_PostureAnimationTimer.Reset();
  1023. SetCondition( COND_STRIDER_SHOULD_CROUCH );
  1024. bDoProceduralHeightChange = false;
  1025. }
  1026. else if ( newHeight - GetMinHeight() > GetHeightRange() * .85 && GetHeight() - GetMinHeight() < GetHeightRange() * .15 )
  1027. {
  1028. m_PostureAnimationTimer.Reset();
  1029. SetCondition( COND_STRIDER_SHOULD_STAND );
  1030. bDoProceduralHeightChange = false;
  1031. }
  1032. }
  1033. }
  1034. if ( bDoProceduralHeightChange )
  1035. {
  1036. SetCondition( COND_STRIDER_HAS_LOS_Z );
  1037. SetIdealHeight( newHeight );
  1038. if ( strider_test_height.GetFloat() > .1 )
  1039. SetIdealHeight( strider_test_height.GetFloat() );
  1040. }
  1041. else
  1042. SetIdealHeight( GetHeight() );
  1043. }
  1044. }
  1045. //---------------------------------------------------------
  1046. //---------------------------------------------------------
  1047. void CNPC_Strider::OnStateChange( NPC_STATE oldState, NPC_STATE newState )
  1048. {
  1049. if ( oldState == NPC_STATE_SCRIPT )
  1050. {
  1051. m_pMinigun->Enable( this, m_bMinigunEnabled );
  1052. }
  1053. else if ( newState == NPC_STATE_SCRIPT )
  1054. {
  1055. m_pMinigun->Enable( this, false );
  1056. }
  1057. }
  1058. //---------------------------------------------------------
  1059. //---------------------------------------------------------
  1060. void CNPC_Strider::BuildScheduleTestBits()
  1061. {
  1062. BaseClass::BuildScheduleTestBits();
  1063. if (m_NPCState != NPC_STATE_SCRIPT)
  1064. {
  1065. SetCustomInterruptCondition( COND_STRIDER_DO_FLICK );
  1066. }
  1067. if( IsCurSchedule( SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK, false ) || IsCurSchedule( SCHED_ESTABLISH_LINE_OF_FIRE, false ) )
  1068. {
  1069. SetCustomInterruptCondition( COND_STRIDER_MINIGUN_SHOOTING );
  1070. }
  1071. if( IsCurSchedule( SCHED_IDLE_STAND ) )
  1072. {
  1073. SetCustomInterruptCondition( COND_STRIDER_HAS_CANNON_TARGET );
  1074. }
  1075. // If our base-class schedule breaks on CAN_RANGE_ATTACK1, then also break
  1076. // on HAS_CANNON_TARGET.
  1077. if( GetCurSchedule()->HasInterrupt( COND_CAN_RANGE_ATTACK1 ) && HasCondition( COND_STRIDER_HAS_CANNON_TARGET ) )
  1078. {
  1079. SetCustomInterruptCondition( COND_STRIDER_HAS_CANNON_TARGET );
  1080. }
  1081. if( IsCurSchedule( SCHED_IDLE_WALK ) || ( IsCurSchedule( SCHED_IDLE_STAND ) && hl2_episodic.GetBool() ) )
  1082. {
  1083. SetCustomInterruptCondition(COND_STRIDER_SHOULD_CROUCH);
  1084. }
  1085. }
  1086. //---------------------------------------------------------
  1087. //---------------------------------------------------------
  1088. int CNPC_Strider::SelectSchedule()
  1089. {
  1090. /*
  1091. if( GetMoveType() != MOVETYPE_FLY )
  1092. {
  1093. // Dropship just released me.
  1094. SetMoveType( MOVETYPE_FLY );
  1095. return SCHED_STRIDER_FALL_TO_GROUND;
  1096. }
  1097. */
  1098. if ( strider_idle_test.GetBool() )
  1099. {
  1100. m_pMinigun->Enable( this, false );
  1101. return SCHED_IDLE_STAND;
  1102. }
  1103. else
  1104. {
  1105. m_pMinigun->Enable( this, m_bMinigunEnabled );
  1106. }
  1107. if( m_NPCState == NPC_STATE_SCRIPT )
  1108. return BaseClass::SelectSchedule();
  1109. // If we're starting to die, then just wait for this to happen
  1110. if ( m_lifeState == LIFE_DYING )
  1111. return SCHED_IDLE_STAND;
  1112. if( m_NPCState == NPC_STATE_DEAD )
  1113. return SCHED_STRIDER_DIE;
  1114. if( HasPendingTargetPath() )
  1115. {
  1116. #if 0
  1117. if( IsInCrouchedPosture() && !m_bCrouchLocked )
  1118. {
  1119. // Make the strider stand!
  1120. return SCHED_STRIDER_STAND;
  1121. }
  1122. else
  1123. {
  1124. SetTargetPath();
  1125. }
  1126. #else
  1127. SetTargetPath();
  1128. #endif
  1129. }
  1130. //---------------------------------
  1131. if( HasCondition( COND_STRIDER_SHOULD_CROUCH ) && GetHeight() - GetMinHeight() > GetHeightRange() * .5 )
  1132. {
  1133. return SCHED_STRIDER_CROUCH;
  1134. }
  1135. if( HasCondition( COND_STRIDER_SHOULD_STAND ) && !m_bCrouchLocked && GetHeight() - GetMinHeight() < GetHeightRange() * .5 )
  1136. {
  1137. return SCHED_STRIDER_STAND;
  1138. }
  1139. if( HasCondition( COND_CAN_RANGE_ATTACK2 ) )
  1140. {
  1141. return SCHED_STRIDER_RANGE_ATTACK2;
  1142. }
  1143. else if( m_AttemptCannonLOSTimer.Expired() && HasCondition( COND_STRIDER_HAS_CANNON_TARGET ) )
  1144. {
  1145. m_AttemptCannonLOSTimer.Set( 5 );
  1146. return SCHED_STRIDER_ESTABLISH_LINE_OF_FIRE_CANNON;
  1147. }
  1148. //---------------------------------
  1149. if( m_NPCState == NPC_STATE_COMBAT )
  1150. {
  1151. if ( !HasCondition( COND_NEW_ENEMY ) )
  1152. {
  1153. if ( m_hRagdoll.Get() && (gpGlobals->curtime > m_ragdollTime || HasCondition( COND_STRIDER_DO_FLICK ) ) )
  1154. {
  1155. return SCHED_STRIDER_FLICKL;
  1156. }
  1157. }
  1158. if ( HasCondition( COND_STRIDER_SHOULD_CROUCH ) )
  1159. {
  1160. return SCHED_STRIDER_CROUCH;
  1161. }
  1162. if ( HasCondition( COND_STRIDER_SHOULD_STAND ) )
  1163. {
  1164. return SCHED_STRIDER_STAND;
  1165. }
  1166. if ( HasCondition( COND_CAN_MELEE_ATTACK1 ) )
  1167. {
  1168. return SCHED_MELEE_ATTACK1;
  1169. }
  1170. if ( HasCondition( COND_CAN_RANGE_ATTACK1 ) )
  1171. {
  1172. return SCHED_STRIDER_RANGE_ATTACK1;
  1173. }
  1174. ClearCondition( COND_STRIDER_ENEMY_UPDATED );
  1175. if ( !m_EnemyUpdatedTimer.Expired() )
  1176. {
  1177. int baseResult = BaseClass::SelectSchedule();
  1178. if ( baseResult != SCHED_COMBAT_FACE || !GetGoalEnt() )
  1179. return baseResult;
  1180. }
  1181. if ( !GetGoalEnt() )
  1182. return BaseClass::SelectSchedule();
  1183. return SCHED_STRIDER_HUNT;
  1184. }
  1185. //---------------------------------
  1186. if ( !GetGoalEnt() )
  1187. return SCHED_IDLE_STAND;
  1188. return SCHED_STRIDER_HUNT;
  1189. }
  1190. //---------------------------------------------------------
  1191. //---------------------------------------------------------
  1192. #define TIME_CARE_ENEMY 7.0
  1193. int CNPC_Strider::TranslateSchedule( int scheduleType )
  1194. {
  1195. switch( scheduleType )
  1196. {
  1197. case SCHED_RANGE_ATTACK1:
  1198. return SCHED_STRIDER_RANGE_ATTACK1;
  1199. case SCHED_RANGE_ATTACK2:
  1200. return SCHED_STRIDER_RANGE_ATTACK2;
  1201. case SCHED_MELEE_ATTACK1:
  1202. return SCHED_STRIDER_STOMPL;
  1203. case SCHED_MELEE_ATTACK2:
  1204. return SCHED_STRIDER_STOMPR;
  1205. case SCHED_CHASE_ENEMY:
  1206. {
  1207. if( HasCondition( COND_SEE_ENEMY ) )
  1208. {
  1209. return SCHED_STRIDER_COMBAT_FACE;
  1210. }
  1211. return SCHED_STRIDER_CHASE_ENEMY;
  1212. }
  1213. case SCHED_ESTABLISH_LINE_OF_FIRE:
  1214. case SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK:
  1215. if ( m_bNoMoveToLOS )
  1216. {
  1217. return SCHED_COMBAT_FACE;
  1218. }
  1219. if ( !m_bCrouchLocked )
  1220. {
  1221. if( IsInCrouchedPosture() )
  1222. {
  1223. if( m_pMinigun->IsShooting() )
  1224. {
  1225. // Don't stand yet.
  1226. return SCHED_STRIDER_COMBAT_FACE;
  1227. }
  1228. }
  1229. else if ( HasCondition( COND_STRIDER_HAS_LOS_Z ) && HasCondition( COND_SEE_ENEMY ) )
  1230. {
  1231. return SCHED_STRIDER_COMBAT_FACE;
  1232. }
  1233. }
  1234. if ( scheduleType == SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK )
  1235. {
  1236. if ( gpGlobals->curtime - GetEnemyLastTimeSeen() < TIME_CARE_ENEMY )
  1237. return SCHED_STRIDER_COMBAT_FACE;
  1238. else if ( GetGoalEnt() )
  1239. return SCHED_STRIDER_HUNT;
  1240. else
  1241. {
  1242. if( IsUsingAggressiveBehavior() )
  1243. {
  1244. return SCHED_STRIDER_AGGRESSIVE_COMBAT_STAND;
  1245. }
  1246. return SCHED_COMBAT_PATROL;
  1247. }
  1248. }
  1249. break;
  1250. case SCHED_COMBAT_FACE:
  1251. return SCHED_STRIDER_COMBAT_FACE;
  1252. break;
  1253. }
  1254. return BaseClass::TranslateSchedule( scheduleType );
  1255. }
  1256. //---------------------------------------------------------
  1257. //---------------------------------------------------------
  1258. void CNPC_Strider::StartTask( const Task_t *pTask )
  1259. {
  1260. switch ( pTask->iTask )
  1261. {
  1262. case TASK_GET_PATH_TO_ENEMY_LOS:
  1263. ChainStartTask( TASK_GET_PATH_TO_ENEMY_LKP_LOS, pTask->flTaskData );
  1264. break;
  1265. case TASK_STRIDER_FALL_TO_GROUND:
  1266. break;
  1267. case TASK_STRIDER_FIRE_CANNON:
  1268. FireCannon();
  1269. TaskComplete();
  1270. break;
  1271. case TASK_STRIDER_SET_CANNON_HEIGHT:
  1272. {
  1273. if ( m_hCannonTarget )
  1274. SetAbsIdealHeight( m_hCannonTarget->WorldSpaceCenter().z );
  1275. TaskComplete();
  1276. }
  1277. break;
  1278. case TASK_STRIDER_AIM:
  1279. {
  1280. // Stop the minigun for a bit, the big gun's about to shoot!
  1281. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 5 );
  1282. //SetIdealActivity( (Activity)ACT_STRIDER_AIMRA1 );
  1283. SetWait( pTask->flTaskData );
  1284. m_aimYaw = 0;
  1285. m_aimPitch = 0;
  1286. // clear out the previous shooting
  1287. SetPoseParameter( gm_YawControl, m_aimYaw );
  1288. SetPoseParameter( gm_PitchControl, m_aimPitch );
  1289. Vector vecShootPos;
  1290. GetAttachment( gm_CannonAttachment, vecShootPos );
  1291. // tell the client side effect to complete
  1292. EntityMessageBegin( this, true );
  1293. WRITE_BYTE( STRIDER_MSG_STREAKS );
  1294. WRITE_VEC3COORD( vecShootPos );
  1295. MessageEnd();
  1296. CPASAttenuationFilter filter2( this, "NPC_Strider.Charge" );
  1297. EmitSound( filter2, entindex(), "NPC_Strider.Charge" );
  1298. // CPVSFilter filter( vecShootPos );
  1299. //te->StreakSphere( filter, 0, 0, 150, 100, entindex(), gm_CannonAttachment );
  1300. }
  1301. break;
  1302. case TASK_STRIDER_DODGE:
  1303. break;
  1304. case TASK_STRIDER_STOMP:
  1305. {
  1306. m_nextStompTime = gpGlobals->curtime + 5;
  1307. Activity stompAct = (Activity) ( pTask->flTaskData > 0 ? ACT_STRIDER_STOMPR : ACT_STRIDER_STOMPL );
  1308. ResetIdealActivity( stompAct );
  1309. }
  1310. break;
  1311. case TASK_RANGE_ATTACK1:
  1312. CBaseCombatWeapon *pWeapon;
  1313. pWeapon = GetActiveWeapon();
  1314. if( pWeapon )
  1315. {
  1316. pWeapon->PrimaryAttack();
  1317. }
  1318. else
  1319. {
  1320. TaskFail("no primary weapon");
  1321. }
  1322. TaskComplete();
  1323. break;
  1324. case TASK_STRIDER_BREAKDOWN:
  1325. SetIdealActivity( (Activity)ACT_STRIDER_SLEEP );
  1326. break;
  1327. case TASK_STRIDER_REFRESH_HUNT_PATH:
  1328. Assert( GetGoalEnt() );
  1329. if ( GetGoalEnt() )
  1330. {
  1331. AI_NavGoal_t goal(GOALTYPE_PATHCORNER, GetGoalEnt()->GetLocalOrigin(), ACT_WALK, AIN_DEF_TOLERANCE, AIN_YAW_TO_DEST);
  1332. TranslateNavGoal( GetGoalEnt(), goal.dest );
  1333. if ( ( m_debugOverlays & OVERLAY_NPC_SELECTED_BIT ) && ( m_debugOverlays & OVERLAY_NPC_ROUTE_BIT ) )
  1334. {
  1335. NDebugOverlay::Line( GetAbsOrigin() + Vector( 0, 0, 4), goal.dest, 255, 0, 255, true, 3 );
  1336. }
  1337. if ( GetNavigator()->SetGoal( goal ) )
  1338. {
  1339. TaskComplete();
  1340. break;
  1341. }
  1342. TaskFail( FAIL_NO_ROUTE );
  1343. }
  1344. break;
  1345. case TASK_STRIDER_START_MOVING:
  1346. TaskComplete();
  1347. break;
  1348. case TASK_STRIDER_GET_PATH_TO_CANNON_LOS:
  1349. {
  1350. if ( GetCannonTarget() == NULL )
  1351. {
  1352. TaskFail("No Cannon Target");
  1353. return;
  1354. }
  1355. AI_PROFILE_SCOPE(CAI_BaseNPC_FindLosToEnemy);
  1356. Vector vecEnemy = GetCannonTarget()->WorldSpaceCenter();
  1357. float flMaxRange = 4096;
  1358. float flMinRange = 0;
  1359. Vector posLos;
  1360. bool found = false;
  1361. if ( GetTacticalServices()->FindLateralLos( vecEnemy, &posLos ) )
  1362. {
  1363. found = true;
  1364. }
  1365. if ( !found && GetTacticalServices()->FindLos( vecEnemy, vecEnemy, flMinRange, flMaxRange, 1.0, &posLos ) )
  1366. {
  1367. found = true;
  1368. }
  1369. if ( found )
  1370. {
  1371. AI_NavGoal_t goal( posLos, ACT_RUN, AIN_HULL_TOLERANCE );
  1372. GetNavigator()->SetGoal( goal, AIN_CLEAR_TARGET );
  1373. GetNavigator()->SetArrivalDirection( vecEnemy - goal.dest );
  1374. // Add the cannon target as a high priority facing entity.
  1375. AddFacingTarget( GetCannonTarget(), GetCannonTarget()->WorldSpaceCenter(), 5.0, 5.0 );
  1376. }
  1377. else
  1378. {
  1379. TaskFail( "Can't get LOS to Cannon Target" );
  1380. }
  1381. }
  1382. break;
  1383. case TASK_STRIDER_GET_PATH_TO_CANNON_TARGET:
  1384. {
  1385. if( !m_hCannonTarget )
  1386. {
  1387. TaskFail( "No cannon target!\n" );
  1388. return;
  1389. }
  1390. AI_NavGoal_t goal( m_hCannonTarget->GetAbsOrigin() );
  1391. TranslateNavGoal( m_hCannonTarget, goal.dest );
  1392. if ( GetNavigator()->SetGoal( goal, AIN_CLEAR_TARGET ) )
  1393. {
  1394. TaskComplete();
  1395. }
  1396. else
  1397. {
  1398. DevWarning( 2, "GetPathToCannonTarget failed!!\n" );
  1399. TaskFail(FAIL_NO_ROUTE);
  1400. }
  1401. }
  1402. break;
  1403. case TASK_STRIDER_FACE_CANNON_TARGET:
  1404. if ( m_hCannonTarget != NULL )
  1405. {
  1406. GetMotor()->SetIdealYawToTarget( m_hCannonTarget->WorldSpaceCenter() );
  1407. SetTurnActivity();
  1408. }
  1409. else
  1410. {
  1411. TaskFail(FAIL_NO_TARGET);
  1412. }
  1413. break;
  1414. case TASK_STRIDER_SET_HEIGHT:
  1415. SetIdealHeight( pTask->flTaskData );
  1416. TaskComplete();
  1417. break;
  1418. default:
  1419. BaseClass::StartTask( pTask );
  1420. break;
  1421. }
  1422. }
  1423. //---------------------------------------------------------
  1424. //---------------------------------------------------------
  1425. void CNPC_Strider::RunTask( const Task_t *pTask )
  1426. {
  1427. switch ( pTask->iTask )
  1428. {
  1429. case TASK_GET_PATH_TO_ENEMY_LOS:
  1430. ChainRunTask( TASK_GET_PATH_TO_ENEMY_LKP_LOS, pTask->flTaskData );
  1431. break;
  1432. case TASK_STRIDER_FALL_TO_GROUND:
  1433. {
  1434. // This doesn't work right now. (sjb)
  1435. Vector vecVelocity = GetAbsVelocity();
  1436. vecVelocity.z -= (GetCurrentGravity() * 0.1);
  1437. SetAbsVelocity( vecVelocity );
  1438. Vector pos = GetAbsOrigin();
  1439. TranslateNavGoal( NULL, pos );
  1440. if( GetAbsOrigin().z - pos.z <= 0.0f )
  1441. {
  1442. SetAbsVelocity( vec3_origin );
  1443. TaskComplete();
  1444. }
  1445. }
  1446. break;
  1447. case TASK_STRIDER_AIM:
  1448. {
  1449. // BUGBUG: Need the real flInterval here, not just 0.1
  1450. AimCannonAt( GetCannonTarget(), 0.1 );
  1451. if ( IsWaitFinished() )
  1452. {
  1453. TaskComplete();
  1454. }
  1455. }
  1456. break;
  1457. case TASK_STRIDER_DODGE:
  1458. TaskComplete();
  1459. break;
  1460. case TASK_STRIDER_STOMP:
  1461. if ( IsActivityFinished() )
  1462. {
  1463. TaskComplete();
  1464. }
  1465. if ( GetEnemy() )
  1466. {
  1467. m_vecHitPos = CalculateStompHitPosition( GetEnemy() );
  1468. }
  1469. break;
  1470. case TASK_STRIDER_BREAKDOWN:
  1471. if ( IsActivityFinished() )
  1472. {
  1473. // UNDONE: Fix this bug!
  1474. //Assert(!IsMarkedForDeletion());
  1475. if ( !IsMarkedForDeletion() )
  1476. {
  1477. CTakeDamageInfo info;
  1478. CreateServerRagdoll( this, 0, info, COLLISION_GROUP_NONE );
  1479. TaskComplete();
  1480. UTIL_Remove(this);
  1481. }
  1482. }
  1483. break;
  1484. case TASK_STRIDER_FACE_CANNON_TARGET:
  1485. GetMotor()->UpdateYaw();
  1486. if ( FacingIdeal() )
  1487. {
  1488. TaskComplete();
  1489. }
  1490. break;
  1491. case TASK_PLAY_SEQUENCE:
  1492. if( m_bFastCrouch && pTask->flTaskData == ACT_CROUCH )
  1493. {
  1494. SetPlaybackRate( 10.0f );
  1495. if( IsSequenceFinished() )
  1496. {
  1497. m_bFastCrouch = false;
  1498. }
  1499. }
  1500. // Hack to make sure client doesn't pop after stand/crouch is done
  1501. if ( GetCycle() > 0.5 )
  1502. {
  1503. if ( IsStriderStanding() && GetHeight() != GetMaxHeight() )
  1504. SetHeight( GetMaxHeight() );
  1505. else if ( IsStriderCrouching() && GetHeight() != GetMinHeight() )
  1506. SetHeight( GetMinHeight() );
  1507. SetIdealHeight( GetHeight() );
  1508. }
  1509. BaseClass::RunTask( pTask );
  1510. break;
  1511. default:
  1512. BaseClass::RunTask( pTask );
  1513. break;
  1514. }
  1515. }
  1516. //-----------------------------------------------------------------------------
  1517. // Purpose:
  1518. //-----------------------------------------------------------------------------
  1519. void CNPC_Strider::Explode( void )
  1520. {
  1521. Vector velocity = vec3_origin;
  1522. AngularImpulse angVelocity = RandomAngularImpulse( -150, 150 );
  1523. // Break into pieces
  1524. breakablepropparams_t params( EyePosition(), GetAbsAngles(), velocity, angVelocity );
  1525. params.impactEnergyScale = 1.0f;
  1526. params.defBurstScale = 600.0f;
  1527. params.defCollisionGroup = COLLISION_GROUP_NPC;
  1528. PropBreakableCreateAll( GetModelIndex(), NULL, params, this, -1, true, true );
  1529. // Go away
  1530. m_lifeState = LIFE_DEAD;
  1531. SetThink( &CNPC_Strider::SUB_Remove );
  1532. SetNextThink( gpGlobals->curtime + 0.1f );
  1533. AddEffects( EF_NODRAW );
  1534. StopSmoking();
  1535. m_BoneFollowerManager.DestroyBoneFollowers();
  1536. }
  1537. //-----------------------------------------------------------------------------
  1538. //-----------------------------------------------------------------------------
  1539. bool CNPC_Strider::HandleInteraction( int interactionType, void *data, CBaseCombatCharacter* sourceEnt )
  1540. {
  1541. if ( interactionType == g_interactionPlayerLaunchedRPG )
  1542. {
  1543. m_flTimePlayerMissileDetected = gpGlobals->curtime;
  1544. m_hPlayersMissile = sourceEnt;
  1545. return true;
  1546. }
  1547. return BaseClass::HandleInteraction( interactionType, data, sourceEnt );
  1548. }
  1549. //---------------------------------------------------------
  1550. //---------------------------------------------------------
  1551. void CNPC_Strider::HandleAnimEvent( animevent_t *pEvent )
  1552. {
  1553. Vector footPosition;
  1554. switch( pEvent->event )
  1555. {
  1556. case STRIDER_AE_DIE:
  1557. {
  1558. Explode();
  1559. }
  1560. break;
  1561. case STRIDER_AE_SHOOTCANNON:
  1562. {
  1563. FireCannon();
  1564. }
  1565. break;
  1566. case STRIDER_AE_WINDUPCANNON:
  1567. {
  1568. AimCannonAt( GetCannonTarget(), 0.1 );
  1569. // Stop the minigun for a bit, the big gun's about to shoot!
  1570. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 5 );
  1571. m_aimYaw = 0;
  1572. m_aimPitch = 0;
  1573. // clear out the previous shooting
  1574. SetPoseParameter( gm_YawControl, m_aimYaw );
  1575. SetPoseParameter( gm_PitchControl, m_aimPitch );
  1576. Vector vecShootPos;
  1577. GetAttachment( gm_CannonAttachment, vecShootPos );
  1578. // tell the client side effect to start
  1579. EntityMessageBegin( this, true );
  1580. WRITE_BYTE( STRIDER_MSG_STREAKS );
  1581. WRITE_VEC3COORD( vecShootPos );
  1582. MessageEnd();
  1583. CPASAttenuationFilter filter2( this, "NPC_Strider.Charge" );
  1584. EmitSound( filter2, entindex(), "NPC_Strider.Charge" );
  1585. }
  1586. break;
  1587. case STRIDER_AE_CANNONHIT:
  1588. CreateConcussiveBlast( m_blastHit, m_blastNormal, this, 2.5 );
  1589. break;
  1590. case STRIDER_AE_SHOOTMINIGUN:
  1591. {
  1592. CBaseEntity *pTarget = gEntList.FindEntityGeneric( NULL, pEvent->options, this, this );
  1593. if ( pTarget )
  1594. {
  1595. Vector vecTarget = pTarget->CollisionProp()->WorldSpaceCenter();
  1596. ShootMinigun( &vecTarget, 0 );
  1597. }
  1598. break;
  1599. }
  1600. case STRIDER_AE_STOMPHITL:
  1601. StompHit( STRIDER_LEFT_LEG_FOLLOWER_INDEX );
  1602. break;
  1603. case STRIDER_AE_STOMPHITR:
  1604. StompHit( STRIDER_RIGHT_LEG_FOLLOWER_INDEX );
  1605. break;
  1606. case STRIDER_AE_FLICKL:
  1607. case STRIDER_AE_FLICKR:
  1608. {
  1609. CBaseEntity *pRagdoll = m_hRagdoll;
  1610. if ( pRagdoll )
  1611. {
  1612. CPASAttenuationFilter filter( pRagdoll, "NPC_Strider.RagdollDetach" );
  1613. EmitSound( filter, pRagdoll->entindex(), "NPC_Strider.RagdollDetach" );
  1614. DetachAttachedRagdoll( pRagdoll );
  1615. }
  1616. m_hRagdoll = NULL;
  1617. }
  1618. break;
  1619. case STRIDER_AE_FOOTSTEP_LEFT:
  1620. case STRIDER_AE_FOOTSTEP_LEFTM:
  1621. case STRIDER_AE_FOOTSTEP_LEFTL:
  1622. LeftFootHit( pEvent->eventtime );
  1623. break;
  1624. case STRIDER_AE_FOOTSTEP_RIGHT:
  1625. case STRIDER_AE_FOOTSTEP_RIGHTM:
  1626. case STRIDER_AE_FOOTSTEP_RIGHTL:
  1627. RightFootHit( pEvent->eventtime );
  1628. break;
  1629. case STRIDER_AE_FOOTSTEP_BACK:
  1630. case STRIDER_AE_FOOTSTEP_BACKM:
  1631. case STRIDER_AE_FOOTSTEP_BACKL:
  1632. BackFootHit( pEvent->eventtime );
  1633. break;
  1634. case STRIDER_AE_WHOOSH_LEFT:
  1635. {
  1636. GetAttachment( "left foot", footPosition );
  1637. CPASAttenuationFilter filter( this, "NPC_Strider.Whoosh" );
  1638. EmitSound( filter, 0, "NPC_Strider.Whoosh", &footPosition );
  1639. }
  1640. break;
  1641. case STRIDER_AE_WHOOSH_RIGHT:
  1642. {
  1643. GetAttachment( "right foot", footPosition );
  1644. CPASAttenuationFilter filter( this, "NPC_Strider.Whoosh" );
  1645. EmitSound( filter, 0, "NPC_Strider.Whoosh", &footPosition );
  1646. }
  1647. break;
  1648. case STRIDER_AE_WHOOSH_BACK:
  1649. {
  1650. GetAttachment( "back foot", footPosition );
  1651. CPASAttenuationFilter filter( this, "NPC_Strider.Whoosh" );
  1652. EmitSound( filter, 0, "NPC_Strider.Whoosh", &footPosition );
  1653. }
  1654. break;
  1655. case STRIDER_AE_CREAK_LEFT:
  1656. case STRIDER_AE_CREAK_BACK:
  1657. case STRIDER_AE_CREAK_RIGHT:
  1658. {
  1659. EmitSound( "NPC_Strider.Creak" );
  1660. }
  1661. break;
  1662. default:
  1663. BaseClass::HandleAnimEvent( pEvent );
  1664. break;
  1665. }
  1666. }
  1667. //---------------------------------------------------------
  1668. //---------------------------------------------------------
  1669. Disposition_t CNPC_Strider::IRelationType( CBaseEntity *pTarget )
  1670. {
  1671. if ( IsCannonTarget( pTarget ) )
  1672. return D_HT;
  1673. return BaseClass::IRelationType( pTarget );
  1674. }
  1675. //---------------------------------------------------------
  1676. //---------------------------------------------------------
  1677. void CNPC_Strider::AddEntityRelationship( CBaseEntity *pEntity, Disposition_t nDisposition, int nPriority )
  1678. {
  1679. if ( nDisposition == D_HT && pEntity->ClassMatches("npc_bullseye") )
  1680. UpdateEnemyMemory( pEntity, pEntity->GetAbsOrigin() );
  1681. BaseClass::AddEntityRelationship( pEntity, nDisposition, nPriority );
  1682. }
  1683. //---------------------------------------------------------
  1684. //---------------------------------------------------------
  1685. bool CNPC_Strider::ScheduledMoveToGoalEntity( int scheduleType, CBaseEntity *pGoalEntity, Activity movementActivity )
  1686. {
  1687. if ( IsCurSchedule( SCHED_STRIDER_RANGE_ATTACK2, false ) )
  1688. {
  1689. SetGoalEnt( pGoalEntity );
  1690. return true;
  1691. }
  1692. return BaseClass::ScheduledMoveToGoalEntity( scheduleType, pGoalEntity, movementActivity );
  1693. }
  1694. //---------------------------------------------------------
  1695. //---------------------------------------------------------
  1696. bool CNPC_Strider::ScheduledFollowPath( int scheduleType, CBaseEntity *pPathStart, Activity movementActivity )
  1697. {
  1698. m_strTrackName = pPathStart->GetEntityName();
  1699. if ( IsCurSchedule( SCHED_STRIDER_RANGE_ATTACK2, false ) )
  1700. {
  1701. SetGoalEnt( pPathStart );
  1702. return true;
  1703. }
  1704. return BaseClass::ScheduledFollowPath( scheduleType, pPathStart, movementActivity );
  1705. }
  1706. //---------------------------------------------------------
  1707. // Disables the minigun until EnableMinigun input is received.
  1708. //---------------------------------------------------------
  1709. void CNPC_Strider::InputDisableMinigun( inputdata_t &inputdata )
  1710. {
  1711. m_bMinigunEnabled = false;
  1712. m_pMinigun->Enable( this, false );
  1713. }
  1714. //---------------------------------------------------------
  1715. // Enables the minigun.
  1716. //---------------------------------------------------------
  1717. void CNPC_Strider::InputEnableMinigun( inputdata_t &inputdata )
  1718. {
  1719. m_bMinigunEnabled = true;
  1720. m_pMinigun->Enable( this, true );
  1721. }
  1722. //---------------------------------------------------------
  1723. //---------------------------------------------------------
  1724. void CNPC_Strider::InputSetMinigunTime( inputdata_t &inputdata )
  1725. {
  1726. m_miniGunShootDuration = inputdata.value.Float();
  1727. m_pMinigun->SetShootDuration( m_miniGunShootDuration );
  1728. }
  1729. //---------------------------------------------------------
  1730. //---------------------------------------------------------
  1731. void CNPC_Strider::InputSetMinigunTarget( inputdata_t &inputdata )
  1732. {
  1733. CBaseEntity *pTargetEntity = gEntList.FindEntityByName( NULL, inputdata.value.String(), NULL, inputdata.pActivator, inputdata.pCaller );
  1734. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 0 );
  1735. m_pMinigun->ShootAtTarget( this, pTargetEntity, m_miniGunShootDuration );
  1736. m_miniGunShootDuration = 0;
  1737. }
  1738. //---------------------------------------------------------
  1739. //---------------------------------------------------------
  1740. void CNPC_Strider::InputSetCannonTarget( inputdata_t &inputdata )
  1741. {
  1742. CBaseEntity *pTarget = gEntList.FindEntityByName( NULL, inputdata.value.String(), NULL, inputdata.pActivator, inputdata.pCaller );
  1743. if ( pTarget )
  1744. {
  1745. if ( m_hCannonTarget == pTarget )
  1746. return;
  1747. CAI_BaseNPC **ppAIs = g_AI_Manager.AccessAIs();
  1748. CNPC_Strider *pStrider;
  1749. for ( int i = 0; i < g_AI_Manager.NumAIs(); i++ )
  1750. {
  1751. if ( ppAIs[i] != this && ppAIs[i]->ClassMatches( GetClassname() ) )
  1752. {
  1753. pStrider = (CNPC_Strider *)(ppAIs[i]);
  1754. if ( pStrider->GetCannonTarget() == pTarget )
  1755. return; // Already accounted for
  1756. }
  1757. }
  1758. if( pTarget->MyCombatCharacterPointer() && pTarget->IsAlive() )
  1759. {
  1760. m_hCannonTarget = pTarget;
  1761. m_AttemptCannonLOSTimer.Force();
  1762. return;
  1763. }
  1764. }
  1765. m_hCannonTarget = NULL;
  1766. }
  1767. //---------------------------------------------------------
  1768. //---------------------------------------------------------
  1769. void CNPC_Strider::InputFlickRagdoll( inputdata_t &inputdata )
  1770. {
  1771. if ( m_hRagdoll.Get() )
  1772. {
  1773. SetCondition( COND_STRIDER_DO_FLICK );
  1774. }
  1775. }
  1776. /*
  1777. IPhysicsObject *pPhysics0 = FindPhysicsObjectByName( STRING(m_nameAttach1), this );
  1778. IPhysicsObject *pPhysics1 = FindPhysicsObjectByName( STRING(m_nameAttach2), this );
  1779. if ( !pPhysics0 )
  1780. {
  1781. pPhysics0 = g_PhysWorldObject;
  1782. }
  1783. if ( !pPhysics1 )
  1784. {
  1785. pPhysics1 = g_PhysWorldObject;
  1786. }
  1787. if ( pPhysics0 != pPhysics1 )
  1788. {
  1789. m_disabled = !bEnable;
  1790. m_succeeded = true;
  1791. if ( bEnable )
  1792. {
  1793. PhysEnableEntityCollisions( pPhysics0, pPhysics1 );
  1794. }
  1795. else
  1796. {
  1797. PhysDisableEntityCollisions( pPhysics0, pPhysics1 );
  1798. }
  1799. }
  1800. else
  1801. {
  1802. m_succeeded = false;
  1803. }
  1804. */
  1805. /*
  1806. #pragma warning(push)
  1807. #pragma warning(disable : 4706) // I know what I'm doing
  1808. //---------------------------------------------------------
  1809. //---------------------------------------------------------
  1810. void CNPC_Strider::InputDisableCollisionWith( inputdata_t &inputdata )
  1811. {
  1812. IPhysicsObject *pIgnorePhys = FindPhysicsObjectByName( inputdata.value.String(), this );
  1813. if ( !pIgnorePhys )
  1814. return;
  1815. int idx;
  1816. CBoneFollower *pFol;
  1817. for (idx = 0 ; pFol = GetBoneFollowerByIndex(idx) ; ++idx) // stop when the function starts returning null (idx is no longer good)
  1818. {
  1819. IPhysicsObject *pFollowPhys = pFol->VPhysicsGetObject();
  1820. Assert(pFollowPhys);
  1821. PhysDisableEntityCollisions( pIgnorePhys, pFollowPhys );
  1822. }
  1823. }
  1824. #pragma warning(pop)
  1825. */
  1826. //---------------------------------------------------------
  1827. //---------------------------------------------------------
  1828. void CNPC_Strider::InputDisableCollisionWith( inputdata_t &inputdata )
  1829. {
  1830. IPhysicsObject *pIgnorePhys = FindPhysicsObjectByName( inputdata.value.String(), this );
  1831. if ( !pIgnorePhys )
  1832. return;
  1833. // CBoneFollower *pFol;
  1834. for (int idx = m_BoneFollowerManager.GetNumBoneFollowers() - 1 ; idx >= 0 ; --idx) // stop when the function starts returning null (idx is no longer good)
  1835. {
  1836. IPhysicsObject *pFollowPhys = GetBoneFollowerByIndex(idx)->VPhysicsGetObject();
  1837. Assert(pFollowPhys);
  1838. PhysDisableEntityCollisions( pIgnorePhys, pFollowPhys );
  1839. }
  1840. }
  1841. //---------------------------------------------------------
  1842. //---------------------------------------------------------
  1843. void CNPC_Strider::InputEnableCollisionWith( inputdata_t &inputdata )
  1844. {
  1845. IPhysicsObject *pIgnorePhys = FindPhysicsObjectByName( inputdata.value.String(), this );
  1846. if ( !pIgnorePhys )
  1847. return;
  1848. int idx;
  1849. // CBoneFollower *pFol;
  1850. for (idx = m_BoneFollowerManager.GetNumBoneFollowers() - 1 ; idx >= 0 ; --idx) // stop when the function starts returning null (idx is no longer good)
  1851. {
  1852. /*
  1853. pFol = GetBoneFollowerByIndex(idx);
  1854. Assert(pFol);
  1855. IPhysicsObject *pFollowPhys = pFol->VPhysicsGetObject();
  1856. Assert(pFollowPhys);
  1857. */
  1858. IPhysicsObject *pFollowPhys = GetBoneFollowerByIndex(idx)->VPhysicsGetObject();
  1859. PhysEnableEntityCollisions( pIgnorePhys, pFollowPhys );
  1860. }
  1861. }
  1862. //---------------------------------------------------------
  1863. //---------------------------------------------------------
  1864. void CNPC_Strider::InputCrouch( inputdata_t &inputdata )
  1865. {
  1866. if ( !IsCurSchedule( SCHED_STRIDER_CROUCH ) && !IsInCrouchedPosture() )
  1867. SetCondition( COND_STRIDER_SHOULD_CROUCH );
  1868. m_bCrouchLocked = true;
  1869. }
  1870. //---------------------------------------------------------
  1871. //---------------------------------------------------------
  1872. void CNPC_Strider::InputCrouchInstantly( inputdata_t &inputdata )
  1873. {
  1874. if ( !IsCurSchedule( SCHED_STRIDER_CROUCH ) && !IsInCrouchedPosture() )
  1875. {
  1876. m_bFastCrouch = true;
  1877. SetCondition( COND_STRIDER_SHOULD_CROUCH );
  1878. }
  1879. m_bCrouchLocked = true;
  1880. }
  1881. //---------------------------------------------------------
  1882. //---------------------------------------------------------
  1883. void CNPC_Strider::InputStand( inputdata_t &inputdata )
  1884. {
  1885. if ( !IsCurSchedule( SCHED_STRIDER_STAND ) && !IsInStandingPosture() )
  1886. SetCondition( COND_STRIDER_SHOULD_STAND );
  1887. m_bCrouchLocked = false;
  1888. }
  1889. //---------------------------------------------------------
  1890. //---------------------------------------------------------
  1891. void CNPC_Strider::InputSetHeight( inputdata_t &inputdata )
  1892. {
  1893. SetIdealHeight( inputdata.value.Float() );
  1894. }
  1895. //---------------------------------------------------------
  1896. //---------------------------------------------------------
  1897. void CNPC_Strider::InputSetTargetPath( inputdata_t &inputdata )
  1898. {
  1899. m_strTrackName = MAKE_STRING( inputdata.value.String() );
  1900. SetGoalEnt( NULL );
  1901. if( !IsStriderCrouching() && !IsStriderStanding() && !IsInCrouchedPosture() )
  1902. {
  1903. SetTargetPath();
  1904. }
  1905. // Otherwise, we just leave the track name set and the AI will
  1906. // get to it as soon as possible (as soon as the strider can be
  1907. // made to stand).
  1908. }
  1909. //---------------------------------------------------------
  1910. //---------------------------------------------------------
  1911. void CNPC_Strider::InputClearTargetPath( inputdata_t &inputdata )
  1912. {
  1913. if (GetNavigator()->IsGoalActive() && GetNavigator()->GetGoalType() == GOALTYPE_PATHCORNER )
  1914. {
  1915. GetNavigator()->ClearGoal();
  1916. ClearSchedule( "Target path cleared via input" );
  1917. }
  1918. m_strTrackName = MAKE_STRING( STRIDER_NO_TRACK_NAME );
  1919. SetGoalEnt(NULL);
  1920. }
  1921. //---------------------------------------------------------
  1922. //---------------------------------------------------------
  1923. void CNPC_Strider::InputDisableCrouchWalk( inputdata_t &inputdata )
  1924. {
  1925. m_bNoCrouchWalk = true;
  1926. }
  1927. //---------------------------------------------------------
  1928. //---------------------------------------------------------
  1929. void CNPC_Strider::InputEnableCrouchWalk( inputdata_t &inputdata )
  1930. {
  1931. m_bNoCrouchWalk = false;
  1932. }
  1933. //---------------------------------------------------------
  1934. //---------------------------------------------------------
  1935. void CNPC_Strider::InputEnableAggressiveBehavior( inputdata_t &inputdata )
  1936. {
  1937. m_bUseAggressiveBehavior = true;
  1938. GetEnemies()->SetEnemyDiscardTime( 601.0f ); // Make the assert in SetFreeKnowledgeDuration() happy.
  1939. GetEnemies()->SetFreeKnowledgeDuration( 600.0f );
  1940. AI_FreePassParams_t params = m_PlayerFreePass.GetParams();
  1941. params.duration = 0.8f;
  1942. params.coverDist = 1200.0f;
  1943. m_PlayerFreePass.SetParams( params );
  1944. GetTacticalServices()->AllowFindLateralLos( false );
  1945. }
  1946. //---------------------------------------------------------
  1947. //---------------------------------------------------------
  1948. void CNPC_Strider::InputDisableAggressiveBehavior( inputdata_t &inputdata )
  1949. {
  1950. m_bUseAggressiveBehavior = false;
  1951. GetEnemies()->SetFreeKnowledgeDuration( strider_free_knowledge.GetFloat() );
  1952. GetEnemies()->SetEnemyDiscardTime( AI_DEF_ENEMY_DISCARD_TIME );
  1953. AI_FreePassParams_t params = m_PlayerFreePass.GetParams();
  1954. params.duration = strider_free_pass_duration.GetFloat();
  1955. params.coverDist = strider_free_pass_cover_dist.GetFloat();
  1956. m_PlayerFreePass.SetParams( params );
  1957. GetTacticalServices()->AllowFindLateralLos( true );
  1958. }
  1959. //---------------------------------------------------------
  1960. //---------------------------------------------------------
  1961. void CNPC_Strider::InputStopShootingMinigunForSeconds( inputdata_t &inputdata )
  1962. {
  1963. m_pMinigun->StopShootingForSeconds( this, NULL, inputdata.value.Float() );
  1964. }
  1965. //---------------------------------------------------------
  1966. //---------------------------------------------------------
  1967. void CNPC_Strider::InputDisableCrouch( inputdata_t &inputdata )
  1968. {
  1969. m_bDontCrouch = true;
  1970. }
  1971. //---------------------------------------------------------
  1972. //---------------------------------------------------------
  1973. void CNPC_Strider::InputDisableMoveToLOS( inputdata_t &inputdata )
  1974. {
  1975. m_bNoMoveToLOS = true;
  1976. }
  1977. //---------------------------------------------------------
  1978. //---------------------------------------------------------
  1979. void CNPC_Strider::InputExplode( inputdata_t &inputdata )
  1980. {
  1981. CTakeDamageInfo killInfo;
  1982. killInfo.SetAttacker( this );
  1983. killInfo.SetInflictor( this );
  1984. killInfo.SetDamage( GetHealth() );
  1985. TakeDamage( killInfo );
  1986. }
  1987. //---------------------------------------------------------
  1988. //---------------------------------------------------------
  1989. void CNPC_Strider::InputScaleGroundSpeed( inputdata_t &inputdata )
  1990. {
  1991. m_flTargetSpeedScale = inputdata.value.Float();
  1992. }
  1993. //---------------------------------------------------------
  1994. //---------------------------------------------------------
  1995. bool CNPC_Strider::FVisible( CBaseEntity *pEntity, int traceMask, CBaseEntity **ppBlocker )
  1996. {
  1997. bool bIsVisible = BaseClass::FVisible( pEntity, traceMask, ppBlocker );
  1998. if ( bIsVisible && pEntity == m_PlayerFreePass.GetPassTarget() )
  1999. {
  2000. bIsVisible = m_PlayerFreePass.ShouldAllowFVisible( bIsVisible );
  2001. if( !bIsVisible && IsUsingAggressiveBehavior() && FInViewCone(pEntity) )
  2002. {
  2003. AlertSound();
  2004. }
  2005. }
  2006. return bIsVisible;
  2007. }
  2008. //---------------------------------------------------------
  2009. //---------------------------------------------------------
  2010. Vector CNPC_Strider::BodyTarget( const Vector &posSrc, bool bNoisy )
  2011. {
  2012. if ( m_BodyTargetBone != -1 )
  2013. {
  2014. Vector position;
  2015. QAngle angles;
  2016. GetBonePosition( m_BodyTargetBone, position, angles );
  2017. return position;
  2018. }
  2019. return BaseClass::BodyTarget( posSrc, bNoisy );
  2020. }
  2021. //---------------------------------------------------------
  2022. //---------------------------------------------------------
  2023. bool CNPC_Strider::IsValidEnemy( CBaseEntity *pTarget )
  2024. {
  2025. if ( HasCannonTarget() )
  2026. {
  2027. return IsCannonTarget(pTarget);
  2028. }
  2029. if ( pTarget->IsPlayer() )
  2030. {
  2031. if ( AIGetNumFollowers( this, m_iszHunterClassname ) > 0 )
  2032. return false;
  2033. }
  2034. CBaseCombatCharacter *pEnemy = ToBaseCombatCharacter( pTarget );
  2035. if ( pEnemy )
  2036. {
  2037. // Test our enemy filter
  2038. if ( m_hEnemyFilter.Get()!= NULL && m_hEnemyFilter->PassesFilter( this, pEnemy ) == false )
  2039. return false;
  2040. return true;
  2041. }
  2042. return BaseClass::IsValidEnemy( pTarget );
  2043. }
  2044. //---------------------------------------------------------
  2045. //---------------------------------------------------------
  2046. bool CNPC_Strider::UpdateEnemyMemory( CBaseEntity *pEnemy, const Vector &position, CBaseEntity *pInformer )
  2047. {
  2048. if( pInformer && FClassnameIs( pInformer, "npc_cscanner" ) )
  2049. {
  2050. EmitSound( "NPC_Strider.Alert" );
  2051. // Move Strider's focus to this location and make strider mad at it
  2052. // (but less mad than at any other potential entities in the scene).
  2053. #if 1
  2054. GetFocus()->SetAbsOrigin( position + Vector( 0, 0, 32 ) );
  2055. #else
  2056. trace_t tr;
  2057. AI_TraceLine( EyePosition(), position + Vector( 0, 0, 32 ), MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
  2058. GetFocus()->SetAbsOrigin( tr.endpos );
  2059. #endif
  2060. SetCondition( COND_STRIDER_ENEMY_UPDATED );
  2061. m_EnemyUpdatedTimer.Set( 20 );
  2062. AddEntityRelationship( GetFocus(), D_HT, -1 );
  2063. if( pEnemy->IsPlayer() )
  2064. {
  2065. m_PlayerFreePass.Revoke();
  2066. }
  2067. BaseClass::UpdateEnemyMemory( GetFocus(), GetFocus()->GetAbsOrigin(), pInformer );
  2068. // Change the informer to myself so that information provided by a scanner is
  2069. // as good as firsthand knowledge insofar as enemy memory is concerned.
  2070. pInformer = this;
  2071. }
  2072. return BaseClass::UpdateEnemyMemory( pEnemy, position, pInformer );
  2073. }
  2074. //---------------------------------------------------------
  2075. // HACKHACK: The base class looks at distance from the head of the strider
  2076. // But when stomping, we need distance from the feet. Recompute it here.
  2077. // UNDONE: make enemy distance aware of strider
  2078. //---------------------------------------------------------
  2079. float CNPC_Strider::StriderEnemyDistance( CBaseEntity *pEnemy )
  2080. {
  2081. Vector enemyDelta = pEnemy->WorldSpaceCenter() - WorldSpaceCenter();
  2082. // NOTE: We ignore rotation for computing height. Assume it isn't an effect
  2083. // we care about, so we simply use OBBSize().z for height.
  2084. // Otherwise you'd do this:
  2085. // float enemyHeight = enemyMaxs.z - enemyMins.z;
  2086. float enemyHeight = pEnemy->CollisionProp()->OBBSize().z;
  2087. Vector striderSurroundMins, striderSurroundMaxs;
  2088. CollisionProp()->WorldSpaceSurroundingBounds( &striderSurroundMins, &striderSurroundMaxs );
  2089. float myHeight = striderSurroundMaxs.z - striderSurroundMins.z;
  2090. // max distance our centers can be apart with the boxes still overlapping
  2091. float flMaxZDist = ( enemyHeight + myHeight ) * 0.5f;
  2092. // see if the enemy is closer to my head, feet or in between
  2093. if ( enemyDelta.z > flMaxZDist )
  2094. {
  2095. // enemy feet above my head, compute distance from my head to his feet
  2096. enemyDelta.z -= flMaxZDist;
  2097. }
  2098. else if ( enemyDelta.z < -flMaxZDist )
  2099. {
  2100. // enemy head below my feet, return distance between my feet and his head
  2101. enemyDelta.z += flMaxZDist;
  2102. }
  2103. else
  2104. {
  2105. // boxes overlap in Z, no delta
  2106. enemyDelta.z = 0;
  2107. }
  2108. return enemyDelta.Length();
  2109. }
  2110. //---------------------------------------------------------
  2111. //---------------------------------------------------------
  2112. bool CNPC_Strider::FCanCheckAttacks()
  2113. {
  2114. // Strider has direct and indirect attacks, so he's always checking
  2115. // as long as the enemy is in front of him.
  2116. if( FInViewCone( GetEnemy() ) )
  2117. {
  2118. return true;
  2119. }
  2120. return false;
  2121. }
  2122. //---------------------------------------------------------
  2123. //---------------------------------------------------------
  2124. int CNPC_Strider::RangeAttack2Conditions( float flDot, float flDist )
  2125. {
  2126. // All of this code has moved to GatherConditions(), since the
  2127. // strider uses the cannon on things that aren't the enemy!
  2128. return COND_NONE;
  2129. }
  2130. //---------------------------------------------------------
  2131. //---------------------------------------------------------
  2132. int CNPC_Strider::MeleeAttack1Conditions( float flDot, float flDist )
  2133. {
  2134. if ( m_bDisableBoneFollowers )
  2135. {
  2136. return COND_NONE;
  2137. }
  2138. if (gpGlobals->curtime < m_nextStompTime)
  2139. {
  2140. return COND_NONE;
  2141. }
  2142. if ( IsInCrouchedPosture() )
  2143. {
  2144. return COND_NONE;
  2145. }
  2146. CBaseEntity *pEnemy = GetEnemy();
  2147. if ( !pEnemy )
  2148. return COND_NONE;
  2149. // No more stabbing players.
  2150. if ( pEnemy->IsPlayer() && !HasSpawnFlags(SF_CAN_STOMP_PLAYER) )
  2151. return COND_NONE;
  2152. if( !HasCondition( COND_SEE_ENEMY ) )
  2153. {
  2154. return COND_NONE;
  2155. }
  2156. // recompute this because the base class function does not work for the strider
  2157. flDist = StriderEnemyDistance( pEnemy );
  2158. if ( flDist > STRIDER_STOMP_RANGE )
  2159. {
  2160. return COND_NONE;
  2161. }
  2162. // strider will cross his feet, but only 6ft over
  2163. Vector right;
  2164. GetVectors( NULL, &right, NULL );
  2165. if ( DotProduct( pEnemy->GetAbsOrigin() - GetAbsOrigin(), right ) > 72 )
  2166. {
  2167. return COND_NONE;
  2168. }
  2169. // Don't skewer if crouched too low.
  2170. if( GetHeight() < GetMaxHeight() - ( (GetMaxHeight()-GetMinHeight()) / 2 ) )
  2171. {
  2172. return COND_NONE;
  2173. }
  2174. // Don't skewer if target is too high above or below ground.
  2175. Vector vecGround = GetAbsOrigin();
  2176. MoveToGround( &vecGround, this, Vector( -16, -16, -16 ), Vector( 16, 16, 16 ) );
  2177. if( fabs( vecGround.z - GetEnemy()->GetAbsOrigin().z ) > 64.0f )
  2178. {
  2179. return COND_NONE;
  2180. }
  2181. // too far, but don't change schedules/movement
  2182. return COND_CAN_MELEE_ATTACK1;
  2183. }
  2184. //---------------------------------------------------------
  2185. //---------------------------------------------------------
  2186. int CNPC_Strider::MeleeAttack2Conditions( float flDot, float flDist )
  2187. {
  2188. // HACKHACK: Disabled until we get a good right-leg animation
  2189. return COND_NONE;
  2190. }
  2191. //---------------------------------------------------------
  2192. //---------------------------------------------------------
  2193. bool CNPC_Strider::WeaponLOSCondition(const Vector &ownerPos, const Vector &targetPos, bool bSetConditions)
  2194. {
  2195. CBaseEntity *pTargetEnt;
  2196. Vector vRootOffset;
  2197. Vector vBarrelOffset;
  2198. vRootOffset.x = vRootOffset.y = 0;
  2199. if ( GetCannonTarget() )
  2200. {
  2201. //Assert( targetPos == GetCannonTarget()->GetAbsOrigin() );
  2202. pTargetEnt = GetCannonTarget();
  2203. vRootOffset.z = gm_zCannonDist;
  2204. vBarrelOffset = gm_vLocalRelativePositionCannon;
  2205. }
  2206. else
  2207. {
  2208. pTargetEnt = GetEnemy();
  2209. vRootOffset.z = gm_zMinigunDist;
  2210. vBarrelOffset = gm_vLocalRelativePositionMinigun;
  2211. }
  2212. trace_t tr;
  2213. AI_TraceLine( ownerPos + vRootOffset, targetPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr);
  2214. // Hit the enemy, or hit nothing (traced all the way to a nonsolid enemy like a bullseye)
  2215. if ( ( pTargetEnt && tr.m_pEnt == pTargetEnt) || tr.fraction == 1.0 || CanShootThrough( tr, targetPos ) )
  2216. {
  2217. Vector vBarrelPos;
  2218. matrix3x4_t losTestToWorld;
  2219. Vector xaxis;
  2220. VectorSubtract( targetPos, ownerPos, xaxis );
  2221. // @TODO (toml 03-07-04): Add an angle test
  2222. //float flAngle = acos( xaxis.z / xaxis.Length() );
  2223. xaxis.z = 0.0f;
  2224. float flLength = VectorNormalize( xaxis );
  2225. if ( flLength < 1e-3 )
  2226. return false;
  2227. Vector yaxis( -xaxis.y, xaxis.x, 0.0f );
  2228. MatrixInitialize( losTestToWorld, ownerPos, xaxis, yaxis, Vector(0,0,1) );
  2229. VectorTransform( vBarrelOffset, losTestToWorld, vBarrelPos );
  2230. AI_TraceLine( vBarrelPos, targetPos, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr);
  2231. if ( ( pTargetEnt && tr.m_pEnt == pTargetEnt) || tr.fraction == 1.0 || CanShootThrough( tr, targetPos ) )
  2232. {
  2233. if ( strider_show_weapon_los_condition.GetBool() )
  2234. {
  2235. NDebugOverlay::Line( ownerPos + vRootOffset, targetPos, 255, 0, 255, false, 0.1 );
  2236. NDebugOverlay::Line( vBarrelPos, targetPos, 128, 0, 128, false, 0.1 );
  2237. }
  2238. return true;
  2239. }
  2240. else
  2241. {
  2242. if ( strider_show_weapon_los_condition.GetBool() )
  2243. {
  2244. NDebugOverlay::Line( ownerPos + vRootOffset, targetPos, 255, 0, 255, false, 0.1 );
  2245. NDebugOverlay::Line( vBarrelPos, tr.endpos, 128, 0, 0, false, 0.1 );
  2246. }
  2247. }
  2248. }
  2249. else
  2250. {
  2251. if ( strider_show_weapon_los_condition.GetBool() )
  2252. {
  2253. NDebugOverlay::Line( ownerPos + vRootOffset, tr.endpos, 255, 0, 0, false, 0.1 );
  2254. }
  2255. }
  2256. return false;
  2257. }
  2258. //---------------------------------------------------------
  2259. //---------------------------------------------------------
  2260. bool CNPC_Strider::CurrentWeaponLOSCondition(const Vector &targetPos, bool bSetConditions)
  2261. {
  2262. return WeaponLOSCondition( GetAdjustedOrigin(), targetPos, bSetConditions );
  2263. }
  2264. //---------------------------------------------------------
  2265. //---------------------------------------------------------
  2266. bool CNPC_Strider::IsValidShootPosition( const Vector &vecCoverLocation, CAI_Node *pNode, CAI_Hint const *pHint )
  2267. {
  2268. if ( ( pNode && !pHint ) || ( pHint && pHint->HintType() != HINT_STRIDER_NODE ) )
  2269. return false;
  2270. return BaseClass::IsValidShootPosition( vecCoverLocation, pNode, pHint );
  2271. }
  2272. //---------------------------------------------------------
  2273. //---------------------------------------------------------
  2274. bool CNPC_Strider::TestShootPosition(const Vector &vecShootPos, const Vector &targetPos )
  2275. {
  2276. if ( BaseClass::TestShootPosition( vecShootPos, targetPos ) )
  2277. {
  2278. return true;
  2279. }
  2280. // What if I crouched?
  2281. float zDelta = ( ( vecShootPos.z - targetPos.z ) + gm_vLocalRelativePositionMinigun.z ) - 12;
  2282. if ( zDelta > 0 )
  2283. {
  2284. if ( zDelta > GetHeightRange() )
  2285. zDelta = GetHeightRange();
  2286. Vector vecTestPos = vecShootPos;
  2287. vecTestPos.z -= zDelta;
  2288. if ( BaseClass::TestShootPosition( vecTestPos, targetPos ) )
  2289. {
  2290. return true;
  2291. }
  2292. }
  2293. return false;
  2294. }
  2295. //---------------------------------------------------------
  2296. //---------------------------------------------------------
  2297. Vector CNPC_Strider::Weapon_ShootPosition( )
  2298. {
  2299. Vector vecShootPos;
  2300. GetAttachment( gm_CannonAttachment, vecShootPos );
  2301. return vecShootPos;
  2302. }
  2303. //---------------------------------------------------------
  2304. //---------------------------------------------------------
  2305. void CNPC_Strider::MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType )
  2306. {
  2307. float flTracerDist;
  2308. Vector vecDir;
  2309. Vector vecEndPos;
  2310. vecDir = tr.endpos - vecTracerSrc;
  2311. flTracerDist = VectorNormalize( vecDir );
  2312. UTIL_Tracer( vecTracerSrc, tr.endpos, 0, TRACER_DONT_USE_ATTACHMENT, 5000, true, "StriderTracer" );
  2313. }
  2314. //---------------------------------------------------------
  2315. //---------------------------------------------------------
  2316. void CNPC_Strider::DoImpactEffect( trace_t &tr, int nDamageType )
  2317. {
  2318. BaseClass::DoImpactEffect( tr, nDamageType );
  2319. // Add a halo
  2320. CBroadcastRecipientFilter filter;
  2321. te->BeamRingPoint( filter, 0.0,
  2322. tr.endpos, //origin
  2323. 0, //start radius
  2324. 64, //end radius
  2325. s_iImpactEffectTexture, //texture
  2326. 0, //halo index
  2327. 0, //start frame
  2328. 0, //framerate
  2329. 0.2, //life
  2330. 10, //width
  2331. 0, //spread
  2332. 0, //amplitude
  2333. 255, //r
  2334. 255, //g
  2335. 255, //b
  2336. 50, //a
  2337. 0, //speed
  2338. FBEAM_FADEOUT
  2339. );
  2340. g_pEffects->EnergySplash( tr.endpos, tr.plane.normal );
  2341. // Punch the effect through?
  2342. if( tr.m_pEnt && !tr.m_pEnt->MyNPCPointer() )
  2343. {
  2344. Vector vecDir = tr.endpos - tr.startpos;
  2345. VectorNormalize( vecDir );
  2346. trace_t retrace;
  2347. Vector vecReTrace = tr.endpos + vecDir * 12;
  2348. if( UTIL_PointContents( vecReTrace ) == CONTENTS_EMPTY )
  2349. {
  2350. AI_TraceLine( vecReTrace, vecReTrace - vecDir * 24, MASK_SHOT, NULL, COLLISION_GROUP_NONE, &retrace );
  2351. BaseClass::DoImpactEffect( retrace, nDamageType );
  2352. }
  2353. }
  2354. }
  2355. //---------------------------------------------------------
  2356. // Trace didn't hit the intended target, but should the strider
  2357. // shoot anyway? We use this to get the strider to destroy
  2358. // breakables that are between him and his target.
  2359. //---------------------------------------------------------
  2360. bool CNPC_Strider::CanShootThrough( const trace_t &tr, const Vector &vecTarget )
  2361. {
  2362. if( GetCannonTarget() )
  2363. {
  2364. // Cannon does not have this behavior.
  2365. return false;
  2366. }
  2367. if( !tr.m_pEnt )
  2368. {
  2369. return false;
  2370. }
  2371. if( !tr.m_pEnt->GetHealth() )
  2372. {
  2373. return false;
  2374. }
  2375. // Would a trace ignoring this entity continue to the target?
  2376. trace_t continuedTrace;
  2377. AI_TraceLine( tr.endpos, vecTarget, MASK_SHOT, tr.m_pEnt, COLLISION_GROUP_NONE, &continuedTrace );
  2378. if( continuedTrace.fraction != 1.0 )
  2379. {
  2380. if( continuedTrace.m_pEnt != GetEnemy() )
  2381. {
  2382. return false;
  2383. }
  2384. }
  2385. return true;
  2386. }
  2387. //---------------------------------------------------------
  2388. //---------------------------------------------------------
  2389. void CNPC_Strider::CreateFocus()
  2390. {
  2391. m_hFocus = CreateEntityByName( "bullseye_strider_focus" );
  2392. ASSERT( m_hFocus != NULL );
  2393. m_hFocus->AddSpawnFlags( SF_BULLSEYE_NONSOLID | SF_BULLSEYE_NODAMAGE );
  2394. m_hFocus->SetAbsOrigin( GetAbsOrigin() );
  2395. m_hFocus->Spawn();
  2396. }
  2397. //---------------------------------------------------------
  2398. //---------------------------------------------------------
  2399. CNPC_Bullseye *CNPC_Strider::GetFocus()
  2400. {
  2401. ASSERT( m_hFocus != NULL );
  2402. CNPC_Bullseye *pBull = dynamic_cast<CNPC_Bullseye*>(m_hFocus.Get());
  2403. return pBull;
  2404. }
  2405. //---------------------------------------------------------
  2406. //---------------------------------------------------------
  2407. bool CNPC_Strider::GetWeaponLosZ( const Vector &vOrigin, float minZ, float maxZ, float increment, CBaseEntity *pTarget, float *pResult )
  2408. {
  2409. Vector vTestPos;
  2410. Vector vTargetPos = pTarget->BodyTarget(vOrigin, false);
  2411. Vector vIncrement( 0, 0, increment );
  2412. // Try right where am
  2413. if ( vOrigin.z >= minZ && vOrigin.z <= maxZ )
  2414. {
  2415. vTestPos = vOrigin;
  2416. if ( WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2417. {
  2418. if ( strider_show_weapon_los_z.GetBool() )
  2419. NDebugOverlay::Line( vTestPos, vTargetPos, 0, 255, 0, false, 0.1 );
  2420. *pResult = vTestPos.z;
  2421. return true;
  2422. }
  2423. }
  2424. // Try at adjusted height of target
  2425. vTestPos.z = ( vTargetPos.z - gm_vLocalRelativePositionMinigun.z ) + 12;
  2426. if ( vTestPos.z >= minZ && vTestPos.z <= maxZ )
  2427. {
  2428. if ( WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2429. {
  2430. if ( strider_show_weapon_los_z.GetBool() )
  2431. NDebugOverlay::Line( vTestPos, vTargetPos, 0, 255, 0, false, 0.1 );
  2432. *pResult = vTestPos.z;
  2433. return true;
  2434. }
  2435. }
  2436. // Try at max height
  2437. vTestPos.z = maxZ;
  2438. if ( WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2439. {
  2440. if ( strider_show_weapon_los_z.GetBool() )
  2441. NDebugOverlay::Line( vOrigin, vTargetPos, 0, 255, 0, false, 0.1 );
  2442. *pResult = vTestPos.z;
  2443. return true;
  2444. }
  2445. // Try min height
  2446. vTestPos.z = minZ;
  2447. if ( WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2448. {
  2449. if ( strider_show_weapon_los_z.GetBool() )
  2450. NDebugOverlay::Line( vTestPos, vTargetPos, 0, 255, 0, false, 0.1 );
  2451. *pResult = vTestPos.z;
  2452. return true;
  2453. }
  2454. // Test up from min
  2455. vTestPos = vOrigin + vIncrement;
  2456. while ( vTestPos.z <= maxZ && !WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2457. {
  2458. vTestPos += vIncrement;
  2459. }
  2460. if ( vTestPos.z <= maxZ )
  2461. {
  2462. if ( strider_show_weapon_los_z.GetBool() )
  2463. NDebugOverlay::Line( vTestPos, vTargetPos, 0, 255, 0, false, 0.1 );
  2464. *pResult = vTestPos.z;
  2465. return true;
  2466. }
  2467. // Test down
  2468. vTestPos = vOrigin - vIncrement;
  2469. while ( vTestPos.z >= minZ && !WeaponLOSCondition( vTestPos, vTargetPos, false ) )
  2470. {
  2471. vTestPos -= vIncrement;
  2472. }
  2473. if ( vTestPos.z >= minZ )
  2474. {
  2475. if ( strider_show_weapon_los_z.GetBool() )
  2476. NDebugOverlay::Line( vTestPos, vTargetPos, 0, 255, 0, false, 0.1 );
  2477. *pResult = vTestPos.z;
  2478. return true;
  2479. }
  2480. return false;
  2481. }
  2482. //---------------------------------------------------------
  2483. //---------------------------------------------------------
  2484. void CNPC_Strider::AlertSound()
  2485. {
  2486. if( ( gpGlobals->curtime - m_flTimeLastAlertSound ) > 2.0f )
  2487. {
  2488. EmitSound( "NPC_Strider.Alert" );
  2489. m_flTimeLastAlertSound = gpGlobals->curtime;
  2490. }
  2491. }
  2492. //---------------------------------------------------------
  2493. //---------------------------------------------------------
  2494. void CNPC_Strider::PainSound( const CTakeDamageInfo &info )
  2495. {
  2496. // This means that we've exploded into pieces and have no way to whimper
  2497. if ( ShouldExplodeFromDamage( info ) )
  2498. return;
  2499. EmitSound( "NPC_Strider.Pain" );
  2500. }
  2501. //---------------------------------------------------------
  2502. //---------------------------------------------------------
  2503. void CNPC_Strider::DeathSound( const CTakeDamageInfo &info )
  2504. {
  2505. // This means that we've exploded into pieces and have no way to whimper
  2506. if ( m_bExploding )
  2507. {
  2508. EmitSound( "NPC_Strider.StriderBusterExplode" );
  2509. EmitSound( "explode_5" );
  2510. return;
  2511. }
  2512. EmitSound( "NPC_Strider.Death" );
  2513. }
  2514. //---------------------------------------------------------
  2515. //---------------------------------------------------------
  2516. void CNPC_Strider::HuntSound()
  2517. {
  2518. if( m_PlayerFreePass.HasPass() )
  2519. {
  2520. EmitSound( "NPC_Strider.Hunt" );
  2521. m_flTimeNextHuntSound = gpGlobals->curtime + random->RandomFloat( 8.0f, 12.0f );
  2522. }
  2523. }
  2524. //---------------------------------------------------------
  2525. //---------------------------------------------------------
  2526. void CNPC_Strider::TraceAttack( const CTakeDamageInfo &inputInfo, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
  2527. {
  2528. CTakeDamageInfo info = inputInfo;
  2529. bool ricochetBullets = true;
  2530. if ( info.GetAttacker()->IsPlayer() )
  2531. {
  2532. if ( !HasMemory( bits_MEMORY_PROVOKED ) )
  2533. {
  2534. GetEnemies()->ClearMemory( info.GetAttacker() );
  2535. Remember( bits_MEMORY_PROVOKED );
  2536. SetCondition( COND_LIGHT_DAMAGE );
  2537. }
  2538. }
  2539. #ifdef HL2_EPISODIC
  2540. // Attempt to hit strider busters in the area
  2541. float flDistSqr;
  2542. for ( int i = 0; i < m_hAttachedBusters.Count(); i++ )
  2543. {
  2544. if ( m_hAttachedBusters[i] == NULL )
  2545. continue;
  2546. flDistSqr = ( m_hAttachedBusters[i]->WorldSpaceCenter() - inputInfo.GetDamagePosition() ).LengthSqr();
  2547. if ( flDistSqr < Square( 50.0f ) )
  2548. {
  2549. // Kill the buster and stop the trace going through
  2550. CTakeDamageInfo killInfo = inputInfo;
  2551. killInfo.SetDamage( 100 );
  2552. m_hAttachedBusters[i]->TakeDamage( killInfo );
  2553. return;
  2554. }
  2555. }
  2556. #endif //HL2_EPISODIC
  2557. if ( (info.GetDamageType() & DMG_BULLET) && ricochetBullets )
  2558. {
  2559. g_pEffects->Ricochet(ptr->endpos,ptr->plane.normal);
  2560. if ( ptr->hitgroup != HITGROUP_HEAD )
  2561. {
  2562. info.SetDamage( 0.01 );
  2563. }
  2564. }
  2565. BaseClass::TraceAttack( info, vecDir, ptr, pAccumulator );
  2566. }
  2567. //---------------------------------------------------------
  2568. //---------------------------------------------------------
  2569. int CNPC_Strider::OnTakeDamage_Alive( const CTakeDamageInfo &info )
  2570. {
  2571. // don't take damage from my own weapons!!!
  2572. if ( info.GetInflictor() && info.GetInflictor()->GetOwnerEntity() == this )
  2573. return 0;
  2574. // special interaction with combine balls
  2575. if ( UTIL_IsCombineBall( info.GetInflictor() ) )
  2576. return TakeDamageFromCombineBall( info );
  2577. if ( info.GetDamageType() == DMG_GENERIC )
  2578. return BaseClass::OnTakeDamage_Alive( info );
  2579. if( IsUsingAggressiveBehavior() )
  2580. {
  2581. // Any damage the player inflicts gets my attention, even if it doesn't actually harm me.
  2582. if ( info.GetAttacker()->IsPlayer() )
  2583. {
  2584. UpdateEnemyMemory( info.GetAttacker(), info.GetAttacker()->GetAbsOrigin() );
  2585. }
  2586. }
  2587. //int healthIncrement = 5 - ( m_iHealth / ( m_iMaxHealth / 5 ) );
  2588. if ( (info.GetDamageType() & DMG_BLAST) && info.GetMaxDamage() > 50 )
  2589. {
  2590. Vector headPos = BodyTarget( info.GetDamagePosition(), false );
  2591. float dist = CalcDistanceToAABB( WorldAlignMins(), WorldAlignMaxs(), info.GetDamagePosition() - headPos );
  2592. // close enough to do damage?
  2593. if ( dist < 200 )
  2594. {
  2595. bool bPlayer = info.GetAttacker()->IsPlayer();
  2596. if ( bPlayer )
  2597. {
  2598. m_PlayerFreePass.Revoke();
  2599. AddFacingTarget( info.GetAttacker(), info.GetAttacker()->GetAbsOrigin(), 1.0, 2.0 );
  2600. UpdateEnemyMemory( info.GetAttacker(), info.GetAttacker()->GetAbsOrigin() );
  2601. }
  2602. else
  2603. AddFacingTarget( info.GetAttacker(), info.GetAttacker()->GetAbsOrigin(), 0.5, 2.0 );
  2604. // Default to NPC damage value
  2605. int damage = 20;
  2606. if( HasSpawnFlags(SF_TAKE_MINIMAL_DAMAGE_FROM_NPCS) )
  2607. damage = 1;
  2608. if( bPlayer )
  2609. {
  2610. if( g_pGameRules->IsSkillLevel(SKILL_EASY) )
  2611. {
  2612. damage = GetMaxHealth() / sk_strider_num_missiles1.GetFloat();
  2613. }
  2614. else if( g_pGameRules->IsSkillLevel(SKILL_HARD) )
  2615. {
  2616. damage = GetMaxHealth() / sk_strider_num_missiles3.GetFloat();
  2617. }
  2618. else // Medium, or unspecified
  2619. {
  2620. damage = GetMaxHealth() / sk_strider_num_missiles2.GetFloat();
  2621. }
  2622. }
  2623. m_iHealth -= damage;
  2624. m_OnDamaged.FireOutput( info.GetAttacker(), this);
  2625. if( info.GetAttacker()->IsPlayer() )
  2626. {
  2627. m_OnDamagedByPlayer.FireOutput( info.GetAttacker(), this );
  2628. // This also counts as being harmed by player's squad.
  2629. m_OnDamagedByPlayerSquad.FireOutput( info.GetAttacker(), this );
  2630. }
  2631. else
  2632. {
  2633. // See if the person that injured me is an NPC.
  2634. CAI_BaseNPC *pAttacker = dynamic_cast<CAI_BaseNPC *>( info.GetAttacker() );
  2635. CBasePlayer *pPlayer = AI_GetSinglePlayer();
  2636. if( pAttacker && pAttacker->IsAlive() && pPlayer )
  2637. {
  2638. if( pAttacker->GetSquad() != NULL && pAttacker->IsInPlayerSquad() )
  2639. {
  2640. m_OnDamagedByPlayerSquad.FireOutput( info.GetAttacker(), this );
  2641. }
  2642. }
  2643. }
  2644. if ( m_iHealth <= ( m_iMaxHealth / 2 ) )
  2645. {
  2646. m_OnHalfHealth.FireOutput(this, this);
  2647. }
  2648. RestartGesture( ACT_GESTURE_SMALL_FLINCH );
  2649. PainSound( info );
  2650. // Interrupt our gun during the flinch
  2651. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 1.1f );
  2652. GetEnemies()->OnTookDamageFrom( info.GetAttacker() );
  2653. if( !IsSmoking() && m_iHealth <= sk_strider_health.GetInt() / 2 )
  2654. {
  2655. StartSmoking();
  2656. }
  2657. return damage;
  2658. }
  2659. // NOTE: Currently radius damage doesn't even call this because it uses the origin, not the box for distance
  2660. #if 0
  2661. NDebugOverlay::Box( headPos, WorldAlignMins(), WorldAlignMaxs(), 255, 0, 0, 0, 5.0 );
  2662. NDebugOverlay::Cross3D( inf
  2663. o.GetDamagePosition(), 24, 0, 255, 0, false, 5.0 );
  2664. // too far from head, apply damage to nearest leg?
  2665. #endif
  2666. }
  2667. #if 0
  2668. if ( (info.GetDamageType() & DMG_BULLET) && info.GetDamage() > 1 && m_iHealth > 1 )
  2669. {
  2670. m_iHealth -= 1;
  2671. return 1;
  2672. }
  2673. #endif
  2674. return 0;
  2675. }
  2676. //---------------------------------------------------------
  2677. //---------------------------------------------------------
  2678. int CNPC_Strider::TakeDamageFromCombineBall( const CTakeDamageInfo &info )
  2679. {
  2680. float damage = info.GetDamage();
  2681. // If it's only an AR2 alt-fire, we don't take much damage
  2682. if ( UTIL_IsAR2CombineBall( info.GetInflictor() ) )
  2683. {
  2684. damage = strider_ar2_altfire_dmg.GetFloat();
  2685. }
  2686. else
  2687. {
  2688. // Always start smoking when we're struck by a normal combine ball
  2689. StartSmoking();
  2690. }
  2691. if( info.GetAttacker() && info.GetAttacker()->IsPlayer() )
  2692. {
  2693. // Route combine ball damage through the regular skill level code.
  2694. damage = g_pGameRules->AdjustPlayerDamageInflicted(damage);
  2695. }
  2696. AddFacingTarget( info.GetInflictor(), info.GetInflictor()->GetAbsOrigin(), 0.5, 2.0 );
  2697. if ( !UTIL_IsAR2CombineBall( info.GetInflictor() ) )
  2698. RestartGesture( ACT_GESTURE_BIG_FLINCH );
  2699. else
  2700. RestartGesture( ACT_GESTURE_SMALL_FLINCH );
  2701. PainSound( info );
  2702. m_iHealth -= damage;
  2703. return damage;
  2704. }
  2705. //---------------------------------------------------------
  2706. //---------------------------------------------------------
  2707. void CNPC_Strider::Event_Killed( const CTakeDamageInfo &info )
  2708. {
  2709. // Do a special death if we're killed by a combine ball in the Citadel
  2710. if ( info.GetInflictor() && UTIL_IsCombineBall( info.GetInflictor() ) )
  2711. {
  2712. if ( m_lifeState == LIFE_DYING )
  2713. return;
  2714. // Tracker 23610: Strider playing death sounds twice (AI_BaseNPC calls it in Event_Killed, too)
  2715. // DeathSound( info );
  2716. m_lifeState = LIFE_DYING;
  2717. // Start dying
  2718. RestartGesture( (Activity) ACT_STRIDER_GESTURE_DEATH );
  2719. // Stop our mini-cannon
  2720. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 100.0f );
  2721. }
  2722. else
  2723. {
  2724. StopSmoking();
  2725. m_BoneFollowerManager.DestroyBoneFollowers();
  2726. }
  2727. if( IsUsingAggressiveBehavior() )
  2728. {
  2729. // Lifted this code from the gunship.
  2730. Vector vecExplode;
  2731. GetAttachment( "minigun", vecExplode );
  2732. ExplosionCreate( vecExplode, QAngle(0,0,1), this, 100, 128, false );
  2733. }
  2734. // Determine if we're going to explode into pieces
  2735. m_bExploding = ShouldExplodeFromDamage( info );
  2736. BaseClass::Event_Killed( info );
  2737. // Stop our large cannon
  2738. EntityMessageBegin( this, true );
  2739. WRITE_BYTE( STRIDER_MSG_DEAD );
  2740. MessageEnd();
  2741. }
  2742. //---------------------------------------------------------
  2743. //---------------------------------------------------------
  2744. void CNPC_Strider::RagdollDeathEffect( CRagdollProp *pRagdoll, float flDuration )
  2745. {
  2746. UTIL_ScreenShake( EyePosition(), 50, 150.0, 1.0, 1024, SHAKE_START );
  2747. int i;
  2748. for( i = 0 ; i < 2 ; i++ )
  2749. {
  2750. SmokeTrail *pSmoke = SmokeTrail::CreateSmokeTrail();
  2751. if ( pSmoke )
  2752. {
  2753. if( i == 0 )
  2754. {
  2755. pSmoke->m_SpawnRate = 16;
  2756. pSmoke->m_Opacity = 0.25;
  2757. pSmoke->m_StartColor.Init( 0.45f, 0.45f, 0.45f );
  2758. }
  2759. else
  2760. {
  2761. pSmoke->m_SpawnRate = 32;
  2762. pSmoke->m_Opacity = 0.3;
  2763. pSmoke->m_StartColor.Init( 0.5f, 0.5f, 0.5f );
  2764. }
  2765. pSmoke->m_ParticleLifetime = 3.0;
  2766. pSmoke->m_StartSize = 16;
  2767. pSmoke->m_EndSize = 64;
  2768. pSmoke->m_SpawnRadius = 20;
  2769. pSmoke->m_MinSpeed = 8;
  2770. pSmoke->m_MaxSpeed = 64;
  2771. pSmoke->m_EndColor.Init( 0, 0, 0 );
  2772. pSmoke->SetLifetime( flDuration );
  2773. if( i == 0 )
  2774. {
  2775. pSmoke->FollowEntity( pRagdoll, "MiniGunBase" );
  2776. }
  2777. else
  2778. {
  2779. pSmoke->FollowEntity( pRagdoll, "vehicle_driver_eyes" );
  2780. }
  2781. }
  2782. }
  2783. }
  2784. //-----------------------------------------------------------------------------
  2785. // Purpose:
  2786. // Input : &info -
  2787. // Output : Returns true on success, false on failure.
  2788. //-----------------------------------------------------------------------------
  2789. bool CNPC_Strider::ShouldExplodeFromDamage( const CTakeDamageInfo &info )
  2790. {
  2791. CBaseEntity *pInflictor = info.GetInflictor();
  2792. if ( pInflictor == NULL )
  2793. return false;
  2794. // Combine balls make us explode
  2795. if ( UTIL_IsCombineBall( info.GetInflictor() ) )
  2796. return true;
  2797. // Stickybombs make us explode
  2798. CBaseEntity *pAttacker = info.GetAttacker();
  2799. if ( pAttacker != NULL && (FClassnameIs( pAttacker, "weapon_striderbuster" ) ||
  2800. FClassnameIs( pAttacker, "npc_grenade_magna" )))
  2801. return true;
  2802. if ( pInflictor == this && pAttacker == this )
  2803. return true;
  2804. return false;
  2805. }
  2806. //---------------------------------------------------------
  2807. //---------------------------------------------------------
  2808. ConVarRef mat_dxlevel( "mat_dxlevel" );
  2809. bool CNPC_Strider::BecomeRagdoll( const CTakeDamageInfo &info, const Vector &forceVector )
  2810. {
  2811. // Combine balls make us explode
  2812. if ( m_bExploding )
  2813. {
  2814. Explode();
  2815. }
  2816. else
  2817. {
  2818. // Otherwise just keel over
  2819. CRagdollProp *pRagdoll = NULL;
  2820. CBasePlayer *pPlayer = AI_GetSinglePlayer();
  2821. if ( pPlayer && mat_dxlevel.GetInt() > 0 )
  2822. {
  2823. int dxlevel = mat_dxlevel.GetInt();
  2824. int maxRagdolls = ( dxlevel >= 90 ) ? 2 : ( dxlevel >= 80 ) ? 1 : 0;
  2825. if ( maxRagdolls > 0 )
  2826. {
  2827. CUtlVectorFixed<CRagdollProp *, 2> striderRagdolls;
  2828. while ( ( pRagdoll = gEntList.NextEntByClass( pRagdoll ) ) != NULL )
  2829. {
  2830. if ( pRagdoll->GetModelName() == GetModelName() && !pRagdoll->IsFading() )
  2831. {
  2832. Assert( striderRagdolls.Count() < striderRagdolls.NumAllocated() );
  2833. if ( striderRagdolls.Count() < striderRagdolls.NumAllocated() )
  2834. striderRagdolls.AddToTail( pRagdoll );
  2835. }
  2836. }
  2837. if ( striderRagdolls.Count() >= maxRagdolls )
  2838. {
  2839. float distSqrFurthest = FLT_MAX;
  2840. CRagdollProp *pFurthest = NULL;
  2841. for ( int i = 0; i < striderRagdolls.Count(); i++ )
  2842. {
  2843. float distSqrCur = CalcSqrDistanceToAABB( striderRagdolls[i]->WorldAlignMins(), striderRagdolls[i]->WorldAlignMaxs(), pPlayer->GetAbsOrigin() );
  2844. if ( distSqrCur < distSqrFurthest )
  2845. {
  2846. distSqrFurthest = distSqrCur;
  2847. pFurthest = striderRagdolls[i];
  2848. }
  2849. }
  2850. if ( pFurthest )
  2851. pFurthest->FadeOut( 0.75, 1.5 );
  2852. }
  2853. }
  2854. pRagdoll = assert_cast<CRagdollProp *>( CreateServerRagdoll( this, m_nForceBone, info, HL2COLLISION_GROUP_STRIDER ) );
  2855. pRagdoll->DisableAutoFade();
  2856. if ( maxRagdolls == 0 )
  2857. {
  2858. pRagdoll->FadeOut( 6.0, .75 );
  2859. RagdollDeathEffect( pRagdoll, 6.0f );
  2860. }
  2861. else
  2862. {
  2863. RagdollDeathEffect( pRagdoll, 600.0f );
  2864. }
  2865. }
  2866. else
  2867. {
  2868. // Otherwise just keel over
  2869. pRagdoll = assert_cast<CRagdollProp *>( CreateServerRagdoll( this, m_nForceBone, info, HL2COLLISION_GROUP_STRIDER ) );
  2870. pRagdoll->DisableAutoFade();
  2871. }
  2872. }
  2873. UTIL_Remove(this);
  2874. return true;
  2875. }
  2876. //---------------------------------------------------------
  2877. //---------------------------------------------------------
  2878. void CNPC_Strider::StartSmoking( void )
  2879. {
  2880. if ( m_hSmoke != NULL )
  2881. return;
  2882. m_hSmoke = SmokeTrail::CreateSmokeTrail();
  2883. if ( m_hSmoke )
  2884. {
  2885. m_hSmoke->m_SpawnRate = 32;
  2886. m_hSmoke->m_ParticleLifetime = 3.0;
  2887. m_hSmoke->m_StartSize = 16;
  2888. m_hSmoke->m_EndSize = 64;
  2889. m_hSmoke->m_SpawnRadius = 20;
  2890. m_hSmoke->m_MinSpeed = 8;
  2891. m_hSmoke->m_MaxSpeed = 64;
  2892. m_hSmoke->m_Opacity = 0.3;
  2893. m_hSmoke->m_StartColor.Init( 0.25f, 0.25f, 0.25f );
  2894. m_hSmoke->m_EndColor.Init( 0, 0, 0 );
  2895. m_hSmoke->SetLifetime( 500.0f );
  2896. m_hSmoke->FollowEntity( this, "MiniGunBase" );
  2897. }
  2898. }
  2899. //---------------------------------------------------------
  2900. //---------------------------------------------------------
  2901. void CNPC_Strider::StopSmoking( float flDelay )
  2902. {
  2903. if ( m_hSmoke )
  2904. {
  2905. m_hSmoke->SetLifetime( flDelay );
  2906. }
  2907. }
  2908. //---------------------------------------------------------
  2909. //---------------------------------------------------------
  2910. void CNPC_Strider::SetHeight( float h )
  2911. {
  2912. if ( h > GetMaxHeight() )
  2913. h = GetMaxHeight();
  2914. else if ( h < GetMinHeight() )
  2915. h = GetMinHeight();
  2916. SetPoseParameter( gm_BodyHeightPoseParam, h );
  2917. }
  2918. //---------------------------------------------------------
  2919. //---------------------------------------------------------
  2920. void CNPC_Strider::SetIdealHeight( float h )
  2921. {
  2922. if ( h > GetMaxHeight() )
  2923. h = GetMaxHeight();
  2924. else if ( h < GetMinHeight() )
  2925. h = GetMinHeight();
  2926. m_idealHeight = h;
  2927. }
  2928. //---------------------------------------------------------
  2929. //---------------------------------------------------------
  2930. void CNPC_Strider::SetAbsIdealHeight( float z )
  2931. {
  2932. float h = GetMaxHeight() - ( z - GetAbsOrigin().z );
  2933. SetIdealHeight( h );
  2934. }
  2935. //---------------------------------------------------------
  2936. // At this moment, am I in the PROCESS of crouching?
  2937. // as in, and I transitioning from standing to crouch?
  2938. //---------------------------------------------------------
  2939. bool CNPC_Strider::IsStriderCrouching()
  2940. {
  2941. if( IsCurSchedule( SCHED_STRIDER_CROUCH, false ) )
  2942. return true;
  2943. return false;
  2944. }
  2945. //---------------------------------------------------------
  2946. // As IsStriderCrouching(), but for obvious differences.
  2947. //---------------------------------------------------------
  2948. bool CNPC_Strider::IsStriderStanding()
  2949. {
  2950. if( IsCurSchedule( SCHED_STRIDER_STAND, false ) )
  2951. return true;
  2952. return false;
  2953. }
  2954. //---------------------------------------------------------
  2955. //---------------------------------------------------------
  2956. bool CNPC_Strider::OverrideMove( float flInterval )
  2957. {
  2958. if ( GetCannonTarget() )
  2959. {
  2960. AddFacingTarget( GetCannonTarget(), GetCannonTarget()->GetAbsOrigin(), 1.0, 0.5 );
  2961. }
  2962. else if ( GetEnemy() )
  2963. {
  2964. bool bPlayer = GetEnemy()->IsPlayer();
  2965. float timeSinceSeenEnemy = gpGlobals->curtime - GetEnemyLastTimeSeen();
  2966. if ( ( !bPlayer && timeSinceSeenEnemy < STRIDER_TIME_STOP_FACING_ENEMY ) ||
  2967. ( bPlayer && !m_PlayerFreePass.HasPass() ) )
  2968. {
  2969. AddFacingTarget( GetEnemy(), GetEnemies()->LastKnownPosition( GetEnemy() ), 1.0, 0.5 );
  2970. }
  2971. if ( !m_bCrouchLocked && !m_hCannonTarget && GetIdealHeight() < GetMaxHeight() && timeSinceSeenEnemy > TIME_CARE_ENEMY )
  2972. SetIdealHeight( GetMaxHeight() );
  2973. }
  2974. else if ( !m_bCrouchLocked && !m_hCannonTarget )
  2975. SetIdealHeight( GetMaxHeight() );
  2976. if ( strider_test_height.GetFloat() > .1 )
  2977. SetIdealHeight( strider_test_height.GetFloat() );
  2978. // If we're not supposed to crouch walk and we're under the threshold for what we consider crouch walking, stand back up!
  2979. if ( !m_bCrouchLocked && m_bNoCrouchWalk && IsMoving() && ( GetIdealHeight() < ( GetMinHeight() + GetHeightRange() * ( strider_pct_height_no_crouch_move.GetFloat() / 100.0 ) ) ) )
  2980. {
  2981. SetIdealHeight( GetMinHeight() + GetHeightRange() * ( strider_pct_height_no_crouch_move.GetFloat() / 100.0 ) );
  2982. }
  2983. float heightMove = GetIdealHeight() - GetHeight();
  2984. float heightMoveSign = ( heightMove < 0 ) ? -1 : 1;
  2985. heightMove = fabsf( heightMove );
  2986. if ( heightMove > 0.01 )
  2987. {
  2988. const float maxVelocity = 300;
  2989. const float minVelocity = 10;
  2990. #define HEIGHTINVDECAY 0.8 // maintain X percent of velocity when slowing down
  2991. #define HEIGHTDECAYTIME 0.4161 // Sum( 1..cycle, HEIGHTINVDECAY^cycle )
  2992. #define HEIGHTACCEL 0.5 // accel toward maxVelocity by X percent each cycle
  2993. if (fabsf( m_HeightVelocity ) < minVelocity)
  2994. m_HeightVelocity = minVelocity * heightMoveSign;
  2995. if (heightMove < m_HeightVelocity * heightMoveSign * HEIGHTDECAYTIME )
  2996. {
  2997. m_HeightVelocity = m_HeightVelocity * HEIGHTINVDECAY;
  2998. if (heightMove < m_HeightVelocity * heightMoveSign * flInterval)
  2999. {
  3000. m_HeightVelocity = heightMove * heightMoveSign / flInterval;
  3001. }
  3002. }
  3003. else
  3004. {
  3005. m_HeightVelocity = m_HeightVelocity * (1.0f - HEIGHTACCEL) + maxVelocity * HEIGHTACCEL * heightMoveSign;
  3006. if (heightMove < m_HeightVelocity * heightMoveSign * HEIGHTDECAYTIME)
  3007. {
  3008. m_HeightVelocity = heightMove * heightMoveSign / HEIGHTDECAYTIME;
  3009. }
  3010. }
  3011. float newHeight = GetHeight() + m_HeightVelocity * flInterval;
  3012. SetHeight( newHeight );
  3013. }
  3014. // FIXME: where should this go?
  3015. MaintainTurnActivity( );
  3016. return false;
  3017. }
  3018. void CNPC_Strider::MaintainTurnActivity( void )
  3019. {
  3020. // detect that the npc has turned
  3021. if (m_prevYaw != GetAbsAngles().y)
  3022. {
  3023. float diff = UTIL_AngleDiff( m_prevYaw, GetAbsAngles().y );
  3024. if (diff < 0.0)
  3025. {
  3026. m_doLeft += -diff;
  3027. }
  3028. else
  3029. {
  3030. m_doRight += diff;
  3031. }
  3032. m_prevYaw = GetAbsAngles().y;
  3033. }
  3034. // accumulate turn angle, delay response for short turns
  3035. m_doTurn += m_doRight + m_doLeft;
  3036. if (!IsMoving() && m_doTurn > 180.0f && m_flNextTurnAct < gpGlobals->curtime )
  3037. {
  3038. int iSeq = ACT_INVALID;
  3039. if (m_doLeft > m_doRight)
  3040. {
  3041. iSeq = SelectWeightedSequence( ACT_GESTURE_TURN_LEFT );
  3042. }
  3043. else
  3044. {
  3045. iSeq = SelectWeightedSequence( ACT_GESTURE_TURN_RIGHT );
  3046. }
  3047. if (iSeq != ACT_INVALID)
  3048. {
  3049. int iLayer = AddGestureSequence( iSeq );
  3050. if (iLayer != -1)
  3051. {
  3052. SetLayerPriority( iLayer, 100 );
  3053. // increase speed if we're getting behind or they're turning quickly
  3054. if (m_doTurn > 360.0)
  3055. {
  3056. SetLayerPlaybackRate( iLayer, 1.5 );
  3057. }
  3058. m_flNextTurnAct = gpGlobals->curtime + GetLayerDuration( iLayer );
  3059. }
  3060. else
  3061. {
  3062. // too busy, try again in half a second
  3063. m_flNextTurnAct = gpGlobals->curtime + 0.5;
  3064. }
  3065. }
  3066. m_doTurn = m_doLeft = m_doRight = 0.0;
  3067. }
  3068. }
  3069. //---------------------------------------------------------
  3070. //---------------------------------------------------------
  3071. bool CNPC_Strider::IsUnusableNode(int iNodeID, CAI_Hint *pHint)
  3072. {
  3073. if ( !BaseClass::IsUnusableNode(iNodeID, pHint) )
  3074. {
  3075. if ( pHint && pHint->HintType() == HINT_STRIDER_NODE )
  3076. return false;
  3077. }
  3078. return true;
  3079. }
  3080. //---------------------------------------------------------
  3081. // Purpose: Compute the nav position for the strider's origin relative to this enemy.
  3082. //---------------------------------------------------------
  3083. void CNPC_Strider::TranslateNavGoal( CBaseEntity *pEnemy, Vector &chasePosition )
  3084. {
  3085. if ( pEnemy )
  3086. {
  3087. if ( ! (pEnemy->GetFlags() & FL_ONGROUND) )
  3088. {
  3089. MoveToGround( &chasePosition, pEnemy, pEnemy->WorldAlignMins(), pEnemy->WorldAlignMaxs() );
  3090. }
  3091. // move down to enemy's feet for enemy origin at chasePosition
  3092. chasePosition.z += pEnemy->WorldAlignMins().z;
  3093. }
  3094. else
  3095. {
  3096. MoveToGround( &chasePosition, NULL, Vector( -16, -16, 0 ), Vector( 16, 16, 32 ) );
  3097. }
  3098. // move up to strider stand height
  3099. chasePosition.z += GetMaxHeight() + npc_strider_height_adj.GetFloat();
  3100. }
  3101. //---------------------------------------------------------
  3102. //---------------------------------------------------------
  3103. bool CNPC_Strider::HasPendingTargetPath()
  3104. {
  3105. bool bReturn = ( !FStrEq( STRING(m_strTrackName), STRIDER_NO_TRACK_NAME ) && !GetGoalEnt() );
  3106. return bReturn;
  3107. }
  3108. //---------------------------------------------------------
  3109. //---------------------------------------------------------
  3110. void CNPC_Strider::SetTargetPath()
  3111. {
  3112. SetGoalEnt( NULL );
  3113. CBaseEntity *pGoalEnt = gEntList.FindEntityByName( NULL, m_strTrackName );
  3114. if ( pGoalEnt == NULL )
  3115. {
  3116. DevWarning( "%s: Could not find target path '%s'!\n", GetClassname(), STRING( m_strTrackName ) );
  3117. // Don't try anymore. It just hurts the AI.
  3118. m_strTrackName = MAKE_STRING( STRIDER_NO_TRACK_NAME );
  3119. UTIL_Remove( this );
  3120. return;
  3121. }
  3122. const Vector &absOrigin = GetAbsOrigin();
  3123. CBaseEntity *pClosestEnt = NULL;
  3124. CBaseEntity *pCurEnt = pGoalEnt;
  3125. float distClosestSq = FLT_MAX;
  3126. CUtlRBTree<CBaseEntity *> visits;
  3127. SetDefLessFunc(visits);
  3128. while ( pCurEnt && visits.Find( pCurEnt ) == visits.InvalidIndex() )
  3129. {
  3130. float distCurSq = ( pCurEnt->GetAbsOrigin() - absOrigin ).LengthSqr();
  3131. if ( distCurSq < distClosestSq )
  3132. {
  3133. distClosestSq = distCurSq;
  3134. pClosestEnt = pCurEnt;
  3135. }
  3136. visits.Insert( pCurEnt );
  3137. pCurEnt = GetNavigator()->GetNextPathcorner( pCurEnt );
  3138. }
  3139. ScheduledFollowPath( SCHED_IDLE_WALK, pClosestEnt, ACT_WALK );
  3140. }
  3141. //---------------------------------------------------------
  3142. //---------------------------------------------------------
  3143. float CNPC_Strider::GetDefaultNavGoalTolerance()
  3144. {
  3145. return 64;
  3146. }
  3147. //---------------------------------------------------------
  3148. //---------------------------------------------------------
  3149. void CNPC_Strider::OnMovementComplete()
  3150. {
  3151. if ( GetGoalEnt() &&
  3152. ( IsCurSchedule( SCHED_IDLE_WALK ) ||
  3153. IsCurSchedule( SCHED_ALERT_WALK ) ||
  3154. IsCurSchedule( SCHED_COMBAT_WALK ) ||
  3155. IsCurSchedule( SCHED_STRIDER_HUNT ) ) )
  3156. {
  3157. m_strTrackName = MAKE_STRING( STRIDER_NO_TRACK_NAME );
  3158. SetGoalEnt( NULL );
  3159. }
  3160. BaseClass::OnMovementComplete();
  3161. }
  3162. //---------------------------------------------------------
  3163. //---------------------------------------------------------
  3164. float CNPC_Strider::GetSequenceGroundSpeed( CStudioHdr *pStudioHdr, int iSequence )
  3165. {
  3166. return ( BaseClass::GetSequenceGroundSpeed( pStudioHdr, iSequence ) * m_flSpeedScale );
  3167. }
  3168. //---------------------------------------------------------
  3169. //---------------------------------------------------------
  3170. float CNPC_Strider::MaxYawSpeed()
  3171. {
  3172. switch( GetActivity() )
  3173. {
  3174. case ACT_90_LEFT:
  3175. case ACT_90_RIGHT:
  3176. return 10;
  3177. case ACT_TURN_LEFT:
  3178. case ACT_TURN_RIGHT:
  3179. return 10;
  3180. case ACT_WALK:
  3181. return 10;
  3182. default:
  3183. return 10; // should be zero, but this makes it easy to see when he's turning with default AI code
  3184. break;
  3185. }
  3186. }
  3187. //-----------------------------------------------------------------------------
  3188. // Purpose:
  3189. //-----------------------------------------------------------------------------
  3190. void CNPC_Strider::DoMuzzleFlash( void )
  3191. {
  3192. BaseClass::DoMuzzleFlash();
  3193. CEffectData data;
  3194. data.m_nAttachmentIndex = LookupAttachment( "MiniGun" );
  3195. data.m_nEntIndex = entindex();
  3196. DispatchEffect( "StriderMuzzleFlash", data );
  3197. }
  3198. //---------------------------------------------------------
  3199. //---------------------------------------------------------
  3200. void CNPC_Strider::ShootMinigun( const Vector *pTarget, float aimError, const Vector &vecSpread )
  3201. {
  3202. if ( pTarget )
  3203. {
  3204. Vector muzzlePos;
  3205. QAngle muzzleAng;
  3206. GetAttachment( "minigun", muzzlePos, muzzleAng );
  3207. Vector vecShootDir = *pTarget - muzzlePos;
  3208. VectorNormalize( vecShootDir );
  3209. if( m_bMinigunUseDirectFire )
  3210. {
  3211. // exactly on target w/tracer
  3212. FireBullets( 1, muzzlePos, vecShootDir, vecSpread, 8192, m_miniGunDirectAmmo, 1 );
  3213. }
  3214. else
  3215. {
  3216. // exactly on target w/tracer
  3217. FireBullets( 1, muzzlePos, vecShootDir, vecSpread, 8192, m_miniGunAmmo, 1 );
  3218. }
  3219. //g_pEffects->MuzzleFlash( muzzlePos, muzzleAng, random->RandomFloat( 2.0f, 4.0f ) , MUZZLEFLASH_TYPE_STRIDER );
  3220. DoMuzzleFlash();
  3221. EmitSound( "NPC_Strider.FireMinigun" );
  3222. }
  3223. }
  3224. //---------------------------------------------------------
  3225. //---------------------------------------------------------
  3226. void CNPC_Strider::UpdateMinigunControls( float &yaw, float &pitch )
  3227. {
  3228. SetPoseParameter( m_poseMiniGunYaw, yaw );
  3229. SetPoseParameter( m_poseMiniGunPitch, pitch );
  3230. yaw = GetPoseParameter( m_poseMiniGunYaw );
  3231. pitch = GetPoseParameter( m_poseMiniGunPitch );
  3232. }
  3233. //---------------------------------------------------------
  3234. //---------------------------------------------------------
  3235. void CNPC_Strider::GetViewCone( StriderMinigunViewcone_t &cone )
  3236. {
  3237. cone.origin = EyePosition();
  3238. GetVectors( &cone.axis, NULL, NULL );
  3239. cone.cosAngle = 0.5; // 60 degree cone
  3240. cone.length = 2048;
  3241. }
  3242. //---------------------------------------------------------
  3243. //---------------------------------------------------------
  3244. void CNPC_Strider::OnMinigunStopShooting( CBaseEntity *pTarget )
  3245. {
  3246. // Stop hating the focus.
  3247. if( GetFocus() && pTarget == GetFocus() )
  3248. {
  3249. AddEntityRelationship( GetFocus(), D_NU, 0 );
  3250. }
  3251. if( IsUsingAggressiveBehavior() )
  3252. {
  3253. // From now on, direct fire.
  3254. m_bMinigunUseDirectFire = true;
  3255. }
  3256. }
  3257. //---------------------------------------------------------
  3258. // How fast the minigun fires (rounds per second)
  3259. //---------------------------------------------------------
  3260. float CNPC_Strider::GetMinigunRateOfFire()
  3261. {
  3262. if( IsUsingAggressiveBehavior() && m_bMinigunUseDirectFire )
  3263. return STRIDER_EP1_RATE_OF_FIRE;
  3264. return STRIDER_DEFAULT_RATE_OF_FIRE;
  3265. }
  3266. //---------------------------------------------------------
  3267. // How much of shoot duration is spent firing directly at
  3268. // the target (the balance of time is spent stitching towards)
  3269. //---------------------------------------------------------
  3270. float CNPC_Strider::GetMinigunOnTargetTime()
  3271. {
  3272. if( IsUsingAggressiveBehavior() )
  3273. {
  3274. if( m_bMinigunUseDirectFire )
  3275. {
  3276. // On target the whole time. Just send a large number that
  3277. // will be clipped, since shooting duration is random and
  3278. // we don't know how long the burst will actually be.
  3279. return 100.0f;
  3280. }
  3281. return STRIDER_EP1_SHOOT_ON_TARGET_TIME;
  3282. }
  3283. return STRIDER_SHOOT_ON_TARGET_TIME;
  3284. }
  3285. //---------------------------------------------------------
  3286. // How long (seconds) a burst of minigun fire lasts.
  3287. //---------------------------------------------------------
  3288. float CNPC_Strider::GetMinigunShootDuration()
  3289. {
  3290. if( IsUsingAggressiveBehavior() )
  3291. return STRIDER_EP1_SHOOT_DURATION;
  3292. return STRIDER_DEFAULT_SHOOT_DURATION;
  3293. }
  3294. //---------------------------------------------------------
  3295. // How long (seconds) a strider must wait between bursts
  3296. //---------------------------------------------------------
  3297. float CNPC_Strider::GetMinigunShootDowntime()
  3298. {
  3299. if( IsUsingAggressiveBehavior() )
  3300. return STRIDER_EP1_SHOOT_DOWNTIME;
  3301. return STRIDER_SHOOT_DOWNTIME;
  3302. }
  3303. //---------------------------------------------------------
  3304. //---------------------------------------------------------
  3305. float CNPC_Strider::GetMinigunShootVariation()
  3306. {
  3307. if( IsUsingAggressiveBehavior() )
  3308. {
  3309. if( m_bMinigunUseDirectFire )
  3310. return 0.0f;
  3311. return STRIDER_EP1_SHOOT_VARIATION;
  3312. }
  3313. return STRIDER_SHOOT_VARIATION;
  3314. }
  3315. //---------------------------------------------------------
  3316. //---------------------------------------------------------
  3317. Vector CNPC_Strider::CannonPosition()
  3318. {
  3319. Vector position;
  3320. // Currently just using the gun for the vertical component!
  3321. GetAttachment( "biggun", position );
  3322. position.x = GetAbsOrigin().x;
  3323. position.y = GetAbsOrigin().y;
  3324. return position;
  3325. }
  3326. //---------------------------------------------------------
  3327. //---------------------------------------------------------
  3328. CBaseEntity *CNPC_Strider::GetCannonTarget()
  3329. {
  3330. CBaseEntity *pTarget = m_hCannonTarget;
  3331. return pTarget;
  3332. }
  3333. //---------------------------------------------------------
  3334. //---------------------------------------------------------
  3335. bool CNPC_Strider::HasCannonTarget() const
  3336. {
  3337. return ( m_hCannonTarget.Get() != NULL );
  3338. }
  3339. //---------------------------------------------------------
  3340. //---------------------------------------------------------
  3341. bool CNPC_Strider::IsCannonTarget( CBaseEntity *pTarget ) const
  3342. {
  3343. CBaseEntity *pCannonTarget = m_hCannonTarget;
  3344. if ( pCannonTarget && pCannonTarget == pTarget )
  3345. {
  3346. return true;
  3347. }
  3348. return false;
  3349. }
  3350. //---------------------------------------------------------
  3351. // Purpose: Aim Gun at a target
  3352. // Output : Returns true if you hit the target, false if not there yet
  3353. //---------------------------------------------------------
  3354. bool CNPC_Strider::AimCannonAt( CBaseEntity *pEntity, float flInterval )
  3355. {
  3356. if ( !pEntity )
  3357. return true;
  3358. matrix3x4_t gunMatrix;
  3359. GetAttachment( gm_CannonAttachment, gunMatrix );
  3360. // transform the enemy into gun space
  3361. m_vecHitPos = pEntity->GetAbsOrigin();
  3362. Vector localEnemyPosition;
  3363. VectorITransform( pEntity->GetAbsOrigin(), gunMatrix, localEnemyPosition );
  3364. // do a look at in gun space (essentially a delta-lookat)
  3365. QAngle localEnemyAngles;
  3366. VectorAngles( localEnemyPosition, localEnemyAngles );
  3367. // convert to +/- 180 degrees
  3368. localEnemyAngles.x = UTIL_AngleDiff( localEnemyAngles.x, 0 );
  3369. localEnemyAngles.y = UTIL_AngleDiff( localEnemyAngles.y, 0 );
  3370. float targetYaw = m_aimYaw + localEnemyAngles.y;
  3371. float targetPitch = m_aimPitch + localEnemyAngles.x;
  3372. Vector unitAngles = Vector( localEnemyAngles.x, localEnemyAngles.y, localEnemyAngles.z );
  3373. float angleDiff = VectorNormalize(unitAngles);
  3374. const float aimSpeed = 16;
  3375. // Exponentially approach the target
  3376. float yawSpeed = fabsf(aimSpeed*flInterval*localEnemyAngles.y);
  3377. float pitchSpeed = fabsf(aimSpeed*flInterval*localEnemyAngles.x);
  3378. yawSpeed = MAX(yawSpeed,5);
  3379. pitchSpeed = MAX(pitchSpeed,5);
  3380. m_aimYaw = UTIL_Approach( targetYaw, m_aimYaw, yawSpeed );
  3381. m_aimPitch = UTIL_Approach( targetPitch, m_aimPitch, pitchSpeed );
  3382. SetPoseParameter( gm_YawControl, m_aimYaw );
  3383. SetPoseParameter( gm_PitchControl, m_aimPitch );
  3384. // read back to avoid drift when hitting limits
  3385. // as long as the velocity is less than the delta between the limit and 180, this is fine.
  3386. m_aimPitch = GetPoseParameter( gm_PitchControl );
  3387. m_aimYaw = GetPoseParameter( gm_YawControl );
  3388. // UNDONE: Zero out any movement past the limit and go ahead and fire if the strider hit its
  3389. // target except for clamping. Need to clamp targets to limits and compare?
  3390. if ( angleDiff < 1 )
  3391. return true;
  3392. return false;
  3393. }
  3394. //---------------------------------------------------------
  3395. //---------------------------------------------------------
  3396. void CNPC_Strider::FireCannon()
  3397. {
  3398. ASSERT( m_hCannonTarget != NULL );
  3399. if ( !m_hCannonTarget )
  3400. {
  3401. DevMsg( "Strider firing cannon at NULL target\n" );
  3402. // Turn the cannon off
  3403. EntityMessageBegin( this, true );
  3404. WRITE_BYTE( STRIDER_MSG_DEAD );
  3405. MessageEnd();
  3406. return;
  3407. }
  3408. if ( GetNextThink( "CANNON_HIT" ) > gpGlobals->curtime )
  3409. {
  3410. DevMsg( "Strider refiring cannon?\n" );
  3411. return;
  3412. }
  3413. m_nextShootTime = gpGlobals->curtime + 5;
  3414. trace_t tr;
  3415. Vector vecShootPos;
  3416. GetAttachment( gm_CannonAttachment, vecShootPos );
  3417. Vector vecShootDir;
  3418. vecShootDir = m_hCannonTarget->WorldSpaceCenter() - vecShootPos;
  3419. float flDist = VectorNormalize( vecShootDir );
  3420. AI_TraceLine( vecShootPos, vecShootPos + vecShootDir * flDist, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );
  3421. m_blastHit = tr.endpos;
  3422. m_blastHit += tr.plane.normal * 16;
  3423. m_blastNormal = tr.plane.normal;
  3424. // tell the client side effect to complete
  3425. EntityMessageBegin( this, true );
  3426. WRITE_BYTE( STRIDER_MSG_BIG_SHOT );
  3427. WRITE_VEC3COORD( tr.endpos );
  3428. MessageEnd();
  3429. CPASAttenuationFilter filter2( this, "NPC_Strider.Shoot" );
  3430. EmitSound( filter2, entindex(), "NPC_Strider.Shoot");
  3431. SetContextThink( &CNPC_Strider::CannonHitThink, gpGlobals->curtime + 0.2f, "CANNON_HIT" );
  3432. }
  3433. void CNPC_Strider::CannonHitThink()
  3434. {
  3435. CBaseEntity *pCannonTarget = m_hCannonTarget;
  3436. if ( pCannonTarget )
  3437. {
  3438. bool fAlive = pCannonTarget->IsAlive();
  3439. CreateConcussiveBlast( m_blastHit, m_blastNormal, this, 2.5 );
  3440. // If the target was alive, check to make sure it is now dead. If not,
  3441. // Kill it and warn the designer.
  3442. if( fAlive && pCannonTarget->IsAlive() )
  3443. {
  3444. DevWarning("* * * * * * * * * * * * * * *\n");
  3445. DevWarning("NASTYGRAM: STRIDER failed to kill its cannon target. Killing directly...\n");
  3446. DevWarning("* * * * * * * * * * * * * * *\n");
  3447. CTakeDamageInfo info;
  3448. info.SetDamage( pCannonTarget->GetHealth() );
  3449. info.SetDamageType( DMG_GENERIC );
  3450. info.SetAttacker( this );
  3451. info.SetInflictor( this );
  3452. pCannonTarget->TakeDamage( info );
  3453. }
  3454. // Clear this guy now that we've shot him
  3455. m_hCannonTarget = NULL;
  3456. }
  3457. // Allow the cannon back on.
  3458. m_pMinigun->StopShootingForSeconds( this, m_pMinigun->GetTarget(), 1 );
  3459. }
  3460. //---------------------------------------------------------
  3461. //---------------------------------------------------------
  3462. void CNPC_Strider::VPhysicsShadowCollision( int index, gamevcollisionevent_t *pEvent )
  3463. {
  3464. if ( !HasMemory( bits_MEMORY_PROVOKED ) )
  3465. {
  3466. // if the player threw this in the last 1 seconds
  3467. CBasePlayer *pPlayer = pEvent->pEntities[!index]->HasPhysicsAttacker( 1 );
  3468. if ( pPlayer )
  3469. {
  3470. GetEnemies()->ClearMemory( pPlayer );
  3471. Remember( bits_MEMORY_PROVOKED );
  3472. SetCondition( COND_LIGHT_DAMAGE );
  3473. }
  3474. }
  3475. int otherIndex = !index;
  3476. CBaseEntity *pOther = pEvent->pEntities[otherIndex];
  3477. if ( pOther && UTIL_IsCombineBall( pOther ) )
  3478. {
  3479. Vector damagePos;
  3480. pEvent->pInternalData->GetContactPoint( damagePos );
  3481. CTakeDamageInfo dmgInfo( pOther, pOther, vec3_origin, damagePos, (m_iMaxHealth / 3) + 1, DMG_BLAST | DMG_PREVENT_PHYSICS_FORCE );
  3482. // FIXME: is there a better way for physics objects to keep track of what root entity responsible for them moving?
  3483. CBasePlayer *pPlayer = pOther->HasPhysicsAttacker( 1.0 );
  3484. if (pPlayer)
  3485. {
  3486. dmgInfo.SetAttacker( pPlayer );
  3487. }
  3488. // UNDONE: Find one near damagePos?
  3489. m_nForceBone = 0;
  3490. PhysCallbackDamage( this, dmgInfo, *pEvent, index );
  3491. return;
  3492. }
  3493. BaseClass::VPhysicsShadowCollision( index, pEvent );
  3494. }
  3495. //---------------------------------------------------------
  3496. //---------------------------------------------------------
  3497. bool CNPC_Strider::TestCollision( const Ray_t &ray, unsigned int mask, trace_t& trace )
  3498. {
  3499. // Let normal hitbox code handle rays
  3500. if ( mask & CONTENTS_HITBOX )
  3501. {
  3502. return BaseClass::TestCollision( ray, mask, trace );
  3503. }
  3504. if ( IntersectRayWithBox( ray, WorldAlignMins() + GetAbsOrigin(), WorldAlignMaxs() + GetAbsOrigin(), DIST_EPSILON, &trace ) )
  3505. {
  3506. trace.hitbox = 0;
  3507. trace.hitgroup = HITGROUP_HEAD;
  3508. return true;
  3509. }
  3510. return false;
  3511. }
  3512. //---------------------------------------------------------
  3513. //---------------------------------------------------------
  3514. bool CNPC_Strider::CarriedByDropship()
  3515. {
  3516. if( GetOwnerEntity() && FClassnameIs( GetOwnerEntity(), "npc_combinedropship" ) )
  3517. return true;
  3518. return false;
  3519. }
  3520. //---------------------------------------------------------
  3521. // Carried by a dropship
  3522. //---------------------------------------------------------
  3523. void CNPC_Strider::CarriedThink()
  3524. {
  3525. SetNextThink( gpGlobals->curtime + 0.05 );
  3526. StudioFrameAdvance();
  3527. Vector vecGround = GetAbsOrigin();
  3528. TranslateNavGoal( NULL, vecGround );
  3529. if( !CarriedByDropship() )
  3530. {
  3531. SetSolid( SOLID_BBOX );
  3532. SetThink ( &CAI_BaseNPC::CallNPCThink );
  3533. }
  3534. }
  3535. //---------------------------------------------------------
  3536. //---------------------------------------------------------
  3537. Vector CNPC_Strider::LeftFootHit( float eventtime )
  3538. {
  3539. Vector footPosition;
  3540. QAngle angles;
  3541. GetAttachment( "left foot", footPosition, angles );
  3542. if ( hl2_episodic.GetBool() )
  3543. {
  3544. CPASAttenuationFilter filter( this, "NPC_Strider.FootstepEverywhere" );
  3545. EmitSound( filter, 0, "NPC_Strider.FootstepEverywhere", &footPosition, eventtime );
  3546. }
  3547. else
  3548. {
  3549. CPASAttenuationFilter filter( this, "NPC_Strider.Footstep" );
  3550. EmitSound( filter, 0, "NPC_Strider.Footstep", &footPosition, eventtime );
  3551. }
  3552. FootFX( footPosition );
  3553. return footPosition;
  3554. }
  3555. //---------------------------------------------------------
  3556. //---------------------------------------------------------
  3557. Vector CNPC_Strider::RightFootHit( float eventtime )
  3558. {
  3559. Vector footPosition;
  3560. GetAttachment( "right foot", footPosition );
  3561. if ( hl2_episodic.GetBool() )
  3562. {
  3563. CPASAttenuationFilter filter( this, "NPC_Strider.FootstepEverywhere" );
  3564. EmitSound( filter, 0, "NPC_Strider.FootstepEverywhere", &footPosition, eventtime );
  3565. }
  3566. else
  3567. {
  3568. CPASAttenuationFilter filter( this, "NPC_Strider.Footstep" );
  3569. EmitSound( filter, 0, "NPC_Strider.Footstep", &footPosition, eventtime );
  3570. }
  3571. FootFX( footPosition );
  3572. return footPosition;
  3573. }
  3574. //---------------------------------------------------------
  3575. //---------------------------------------------------------
  3576. Vector CNPC_Strider::BackFootHit( float eventtime )
  3577. {
  3578. Vector footPosition;
  3579. GetAttachment( "back foot", footPosition );
  3580. if ( hl2_episodic.GetBool() )
  3581. {
  3582. CPASAttenuationFilter filter( this, "NPC_Strider.FootstepEverywhere" );
  3583. EmitSound( filter, 0, "NPC_Strider.FootstepEverywhere", &footPosition, eventtime );
  3584. }
  3585. else
  3586. {
  3587. CPASAttenuationFilter filter( this, "NPC_Strider.Footstep" );
  3588. EmitSound( filter, 0, "NPC_Strider.Footstep", &footPosition, eventtime );
  3589. }
  3590. FootFX( footPosition );
  3591. return footPosition;
  3592. }
  3593. //---------------------------------------------------------
  3594. //---------------------------------------------------------
  3595. static Vector GetAttachmentPositionInSpaceOfBone( CStudioHdr *pStudioHdr, const char *pAttachmentName, int outputBoneIndex )
  3596. {
  3597. int attachment = Studio_FindAttachment( pStudioHdr, pAttachmentName );
  3598. Vector localAttach;
  3599. const mstudioattachment_t &pAttachment = pStudioHdr->pAttachment(attachment);
  3600. int iBone = pStudioHdr->GetAttachmentBone( attachment );
  3601. MatrixGetColumn( pAttachment.local, 3, localAttach );
  3602. matrix3x4_t inputToOutputBone;
  3603. Studio_CalcBoneToBoneTransform( pStudioHdr, iBone, outputBoneIndex, inputToOutputBone );
  3604. Vector out;
  3605. VectorTransform( localAttach, inputToOutputBone, out );
  3606. return out;
  3607. }
  3608. //-------------------------------------
  3609. void CNPC_Strider::StompHit( int followerBoneIndex )
  3610. {
  3611. CStudioHdr *pStudioHdr = GetModelPtr();
  3612. physfollower_t *bone = m_BoneFollowerManager.GetBoneFollower( followerBoneIndex );
  3613. if ( !bone )
  3614. return;
  3615. const char *pBoneNames[] = {"left skewer", "right skewer" };
  3616. int nameIndex = followerBoneIndex == STRIDER_LEFT_LEG_FOLLOWER_INDEX ? 0 : 1;
  3617. Vector localHit = GetAttachmentPositionInSpaceOfBone( pStudioHdr, pBoneNames[nameIndex], bone->boneIndex );
  3618. IPhysicsObject *pLegPhys = bone->hFollower->VPhysicsGetObject();
  3619. // now transform into the worldspace of the current position of the leg's physics
  3620. matrix3x4_t legToWorld;
  3621. pLegPhys->GetPositionMatrix( &legToWorld );
  3622. Vector hitPosition;
  3623. VectorTransform( localHit, legToWorld, hitPosition );
  3624. //NDebugOverlay::Box( hitPosition, Vector(-16,-16,-16), Vector(16,16,16), 0, 255, 0, 255, 1.0 );
  3625. CBaseEntity *pEnemy = GetEnemy();
  3626. CAI_BaseNPC *pNPC = pEnemy ? pEnemy->MyNPCPointer() : NULL;
  3627. bool bIsValidTarget = pNPC && pNPC->GetModelPtr();
  3628. if ( HasSpawnFlags( SF_CAN_STOMP_PLAYER ) )
  3629. {
  3630. bIsValidTarget = bIsValidTarget || ( pEnemy && pEnemy->IsPlayer() );
  3631. }
  3632. if ( !bIsValidTarget )
  3633. return;
  3634. Vector delta;
  3635. VectorSubtract( pEnemy->GetAbsOrigin(), hitPosition, delta );
  3636. if ( delta.LengthSqr() > (STRIDER_STOMP_RANGE * STRIDER_STOMP_RANGE) )
  3637. return;
  3638. // DVS E3 HACK: Assume we stab our victim midway between their eyes and their center.
  3639. Vector vecStabPos = ( pEnemy->WorldSpaceCenter() + pEnemy->EyePosition() ) * 0.5f;
  3640. hitPosition = pEnemy->GetAbsOrigin();
  3641. Vector footPosition;
  3642. GetAttachment( "left foot", footPosition );
  3643. CPASAttenuationFilter filter( this, "NPC_Strider.Skewer" );
  3644. EmitSound( filter, 0, "NPC_Strider.Skewer", &hitPosition );
  3645. CTakeDamageInfo damageInfo( this, this, 500, DMG_CRUSH );
  3646. Vector forward;
  3647. pEnemy->GetVectors( &forward, NULL, NULL );
  3648. damageInfo.SetDamagePosition( hitPosition );
  3649. damageInfo.SetDamageForce( -50 * 300 * forward );
  3650. pEnemy->TakeDamage( damageInfo );
  3651. if ( !pNPC || pNPC->IsAlive() )
  3652. return;
  3653. Vector vecBloodDelta = footPosition - vecStabPos;
  3654. vecBloodDelta.z = 0; // effect looks better
  3655. VectorNormalize( vecBloodDelta );
  3656. UTIL_BloodSpray( vecStabPos + vecBloodDelta * 4, vecBloodDelta, BLOOD_COLOR_RED, 8, FX_BLOODSPRAY_ALL );
  3657. UTIL_BloodSpray( vecStabPos + vecBloodDelta * 4, vecBloodDelta, BLOOD_COLOR_RED, 11, FX_BLOODSPRAY_DROPS );
  3658. CBaseEntity *pRagdoll = CreateServerRagdollAttached( pNPC, vec3_origin, -1, COLLISION_GROUP_DEBRIS, pLegPhys, this, bone->boneIndex, vecStabPos, -1, localHit );
  3659. if ( pRagdoll )
  3660. {
  3661. // the strider might drag this through the world
  3662. pRagdoll->AddSolidFlags( FSOLID_NOT_SOLID );
  3663. m_hRagdoll = pRagdoll;
  3664. m_ragdollTime = gpGlobals->curtime + 10;
  3665. UTIL_Remove( pNPC );
  3666. }
  3667. }
  3668. //---------------------------------------------------------
  3669. //---------------------------------------------------------
  3670. void CNPC_Strider::FootFX( const Vector &origin )
  3671. {
  3672. trace_t tr;
  3673. AI_TraceLine( origin + Vector(0, 0, 48), origin - Vector(0,0,100), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
  3674. float yaw = random->RandomInt(0,120);
  3675. if ( UTIL_PointContents( tr.endpos + Vector( 0, 0, 1 ) ) & MASK_WATER )
  3676. {
  3677. float flWaterZ = UTIL_FindWaterSurface( tr.endpos, tr.endpos.z, tr.endpos.z + 100.0f );
  3678. CEffectData data;
  3679. data.m_fFlags = 0;
  3680. data.m_vOrigin = tr.endpos;
  3681. data.m_vOrigin.z = flWaterZ;
  3682. data.m_vNormal = Vector( 0, 0, 1 );
  3683. data.m_flScale = random->RandomFloat( 10.0, 14.0 );
  3684. DispatchEffect( "watersplash", data );
  3685. }
  3686. else
  3687. {
  3688. for ( int i = 0; i < 3; i++ )
  3689. {
  3690. Vector dir = UTIL_YawToVector( yaw + i*120 ) * 10;
  3691. VectorNormalize( dir );
  3692. dir.z = 0.25;
  3693. VectorNormalize( dir );
  3694. g_pEffects->Dust( tr.endpos, dir, 12, 50 );
  3695. }
  3696. }
  3697. UTIL_ScreenShake( tr.endpos, 4.0, 1.0, 0.5, 1000, SHAKE_START, false );
  3698. if ( npc_strider_shake_ropes_radius.GetInt() )
  3699. {
  3700. CRopeKeyframe::ShakeRopes( tr.endpos, npc_strider_shake_ropes_radius.GetFloat(), npc_strider_shake_ropes_magnitude.GetFloat() );
  3701. }
  3702. //
  3703. // My feet are scary things! NOTE: We might want to make danger sounds as the feet move
  3704. // through the air. Then soldiers could run from the feet, which would look cool.
  3705. //
  3706. CSoundEnt::InsertSound( SOUND_DANGER|SOUND_CONTEXT_EXCLUDE_COMBINE, tr.endpos, 512, 1.0f, this );
  3707. }
  3708. //---------------------------------------------------------
  3709. //---------------------------------------------------------
  3710. Vector CNPC_Strider::CalculateStompHitPosition( CBaseEntity *pEnemy )
  3711. {
  3712. Vector skewerPosition, footPosition;
  3713. GetAttachment( "left skewer", skewerPosition );
  3714. GetAttachment( "left foot", footPosition );
  3715. Vector vecStabPos = ( pEnemy->WorldSpaceCenter() + pEnemy->EyePosition() ) * 0.5f;
  3716. return vecStabPos - skewerPosition + footPosition;
  3717. }
  3718. //-----------------------------------------------------------------------------
  3719. // Strider Navigation
  3720. //-----------------------------------------------------------------------------
  3721. static void MoveToGround( Vector *position, CBaseEntity *ignore, const Vector &mins, const Vector &maxs )
  3722. {
  3723. trace_t tr;
  3724. // Find point on floor where enemy would stand at chasePosition
  3725. Vector floor = *position;
  3726. floor.z -= 1024;
  3727. AI_TraceHull( *position, floor, mins, maxs, MASK_NPCSOLID_BRUSHONLY, ignore, COLLISION_GROUP_NONE, &tr );
  3728. if ( tr.fraction < 1 )
  3729. {
  3730. position->z = tr.endpos.z;
  3731. }
  3732. }
  3733. //---------------------------------------------------------
  3734. //---------------------------------------------------------
  3735. void AdjustStriderNodePosition( CAI_Network *pNetwork, CAI_Node *pNode )
  3736. {
  3737. if ( pNode->GetHint() && pNode->GetHint()->HintType() == HINT_STRIDER_NODE )
  3738. {
  3739. CNPC_Strider *pStrider = (CNPC_Strider *)gEntList.FindEntityByClassname( NULL, "npc_strider" );
  3740. bool bCreated = false;
  3741. if ( !pStrider )
  3742. {
  3743. bool allowPrecache = CBaseEntity::IsPrecacheAllowed();
  3744. CBaseEntity::SetAllowPrecache( true );
  3745. pStrider = (CNPC_Strider *)CreateEntityByName( "npc_strider" );
  3746. pStrider->m_bDisableBoneFollowers = true; // don't create these since we're just going to destroy him
  3747. DispatchSpawn( pStrider );
  3748. CBaseEntity::SetAllowPrecache( allowPrecache );
  3749. bCreated = true;
  3750. }
  3751. if ( pStrider )
  3752. {
  3753. pStrider->TranslateNavGoal( NULL, pNode->AccessOrigin() );
  3754. if ( bCreated )
  3755. UTIL_Remove( pStrider );
  3756. }
  3757. }
  3758. }
  3759. //---------------------------------------------------------
  3760. // Implement a navigator so that the strider can get closer to the ground when he's walking on a slope
  3761. // This gives him enough reach for his legs to IK to lower ground points
  3762. //---------------------------------------------------------
  3763. void LookaheadPath( const Vector &current, AI_Waypoint_t *pWaypoint, float dist, Vector &nextPos )
  3764. {
  3765. if ( !pWaypoint )
  3766. return;
  3767. Vector dir = pWaypoint->GetPos() - current;
  3768. float dist2D = dir.Length2D();
  3769. if ( dist2D > 0.1 )
  3770. {
  3771. if ( dist <= dist2D )
  3772. {
  3773. nextPos = ((dist / dist2D) * dir) + current;
  3774. return;
  3775. }
  3776. }
  3777. nextPos = pWaypoint->GetPos();
  3778. dist -= dist2D;
  3779. dir = nextPos;
  3780. LookaheadPath( dir, pWaypoint->GetNext(), dist, nextPos );
  3781. }
  3782. //---------------------------------------------------------
  3783. // Find the forward slope and lower the strider height when moving downward
  3784. //---------------------------------------------------------
  3785. void CNPC_Strider::CNavigator::MoveCalcBaseGoal( AILocalMoveGoal_t *pMoveGoal )
  3786. {
  3787. BaseClass::MoveCalcBaseGoal( pMoveGoal );
  3788. Vector dest = pMoveGoal->target;
  3789. LookaheadPath( GetAbsOrigin(), pMoveGoal->pPath->GetCurWaypoint(), CNPC_Strider::gm_strideLength, dest );
  3790. //NDebugOverlay::Box( dest, Vector(-16,-16,-16), Vector(16,16,16), 0, 255, 0, 255, 0.1 );
  3791. Vector unitDir = pMoveGoal->dir * CNPC_Strider::gm_strideLength;
  3792. unitDir.z = dest.z - GetAbsOrigin().z;
  3793. VectorNormalize( unitDir );
  3794. float heightAdj = unitDir.z * CNPC_Strider::gm_strideLength;
  3795. pMoveGoal->flags |= ( AILMG_NO_STEER | AILMG_NO_AVOIDANCE_PATHS );
  3796. if ( heightAdj < -1 )
  3797. {
  3798. heightAdj = clamp( heightAdj, -192, 0 );
  3799. pMoveGoal->target.z += heightAdj;
  3800. pMoveGoal->dir = unitDir * CNPC_Strider::gm_strideLength * 0.1;
  3801. pMoveGoal->dir.z += heightAdj;
  3802. VectorNormalize( pMoveGoal->dir );
  3803. }
  3804. }
  3805. //---------------------------------------------------------
  3806. //---------------------------------------------------------
  3807. bool CNPC_Strider::CNavigator::MoveUpdateWaypoint( AIMoveResult_t *pResult )
  3808. {
  3809. // Note that goal & waypoint tolerances are handled in progress blockage cases (e.g., OnObstructionPreSteer)
  3810. AI_Waypoint_t *pCurWaypoint = GetPath()->GetCurWaypoint();
  3811. float waypointDist = (pCurWaypoint->GetPos() - GetAbsOrigin()).Length2D();
  3812. bool bIsGoal = CurWaypointIsGoal();
  3813. // HACKHACK: adjust this tolerance
  3814. // The strider is following paths most of the time, but he needs a bunch of freedom
  3815. // to adjust himself to make his feet look good.
  3816. float tolerance = 10.0;
  3817. if ( waypointDist <= tolerance )
  3818. {
  3819. if ( bIsGoal )
  3820. {
  3821. OnNavComplete();
  3822. *pResult = AIMR_OK;
  3823. }
  3824. else
  3825. {
  3826. AdvancePath();
  3827. *pResult = AIMR_CHANGE_TYPE;
  3828. }
  3829. return true;
  3830. }
  3831. return false;
  3832. }
  3833. //---------------------------------------------------------
  3834. //---------------------------------------------------------
  3835. bool CNPC_Strider::CNavigator::DoFindPathToPos()
  3836. {
  3837. DbgNavMsg( GetOuter(), "Strider overriding DoFindPathToPos\n");
  3838. if ( BaseClass::DoFindPathToPos() )
  3839. {
  3840. // Do special optimization on our first path segment
  3841. DbgNavMsg( GetOuter(), "Strider base pathfind worked\n");
  3842. CAI_WaypointList waypoints( GetPath()->GetCurWaypoint() );
  3843. AI_Waypoint_t *pFirstWaypoint = waypoints.GetFirst();
  3844. AI_Waypoint_t *pLast = waypoints.GetLast();
  3845. if ( pFirstWaypoint->IsReducible() &&
  3846. pFirstWaypoint->GetNext() &&
  3847. pFirstWaypoint->GetNext()->iNodeID != NO_NODE &&
  3848. pFirstWaypoint->GetNext()->NavType() == GetNavType() )
  3849. {
  3850. // Find nearest point on the line segment of our path
  3851. Vector vOrigin = GetOuter()->GetAbsOrigin();
  3852. Vector vClosest;
  3853. CalcClosestPointOnLineSegment( vOrigin,
  3854. pFirstWaypoint->GetPos(),
  3855. pFirstWaypoint->GetNext()->GetPos(),
  3856. vClosest );
  3857. // Find both these positions as offset from the ground
  3858. TranslateNavGoal( GetPath()->GetTarget(), vClosest );
  3859. TranslateNavGoal( GetPath()->GetTarget(), vOrigin );
  3860. // If we're seemingly beyond the waypoint and our hull is near enough to the path segment, advance to the next node
  3861. const float EPS = 0.1f;
  3862. bool bPastStartNode = ( ( pFirstWaypoint->GetPos() - vClosest ).Length() > EPS );
  3863. bool bNearPathSegment = ( ( vOrigin - vClosest ).Length() < GetHullWidth() * 0.5f );
  3864. if ( bPastStartNode && bNearPathSegment )
  3865. {
  3866. GetPath()->Advance();
  3867. }
  3868. }
  3869. if ( pLast->iNodeID == NO_NODE )
  3870. {
  3871. AI_Waypoint_t *pLastNodeWaypoint = pLast->GetPrev();
  3872. if ( pLastNodeWaypoint && pLastNodeWaypoint->iNodeID == NO_NODE )
  3873. {
  3874. // Pathfinder triangulated to goal
  3875. Assert( pLastNodeWaypoint->GetPrev() );
  3876. if ( pLastNodeWaypoint->GetPrev() )
  3877. {
  3878. pLastNodeWaypoint->GetPrev()->SetNext( pLast );
  3879. delete pLastNodeWaypoint;
  3880. pLastNodeWaypoint = pLast->GetPrev();
  3881. }
  3882. }
  3883. Assert( pLastNodeWaypoint );
  3884. if ( pLastNodeWaypoint )
  3885. {
  3886. Assert( pLastNodeWaypoint->iNodeID != NO_NODE );
  3887. if ( pLastNodeWaypoint->iNodeID != NO_NODE )
  3888. {
  3889. CAI_Node *pLastNode = GetNetwork()->GetNode( pLastNodeWaypoint->iNodeID );
  3890. float bestDistSq = ( pLast->vecLocation - pLastNodeWaypoint->vecLocation ).LengthSqr();
  3891. Vector vNewEnd = vec3_invalid;
  3892. int segmentDestClosest = NO_NODE;
  3893. for (int link=0; link < pLastNode->NumLinks();link++)
  3894. {
  3895. CAI_Link *pLink = pLastNode->GetLinkByIndex(link);
  3896. if ( !( pLink->m_LinkInfo & bits_LINK_OFF ) && (pLink->m_iAcceptedMoveTypes[GetHullType()] & bits_CAP_MOVE_FLY) )
  3897. {
  3898. CAI_Node *pTestNode = GetNetwork()->GetNode( pLink->DestNodeID( pLastNodeWaypoint->iNodeID ) );
  3899. if ( pTestNode->GetHint() && pTestNode->GetHint()->HintType() == HINT_STRIDER_NODE )
  3900. {
  3901. Vector vClosest;
  3902. CalcClosestPointOnLineSegment( pLast->vecLocation,
  3903. pLastNodeWaypoint->vecLocation, pTestNode->GetPosition(GetHullType()),
  3904. vClosest );
  3905. float distTestSq = ( pLast->vecLocation - vClosest ).LengthSqr();
  3906. if ( distTestSq < bestDistSq )
  3907. {
  3908. bestDistSq = distTestSq;
  3909. vNewEnd = vClosest;
  3910. segmentDestClosest = pTestNode->GetId();
  3911. }
  3912. }
  3913. }
  3914. }
  3915. if ( vNewEnd == vec3_invalid )
  3916. {
  3917. DbgNavMsg( GetOuter(), "Strider resetting goal to last node waypoint\n");
  3918. pLastNodeWaypoint->SetNext( NULL );
  3919. pLastNodeWaypoint->ModifyFlags( bits_WP_TO_GOAL, true );
  3920. delete pLast;
  3921. }
  3922. else if ( !pLastNodeWaypoint->GetPrev() || pLastNodeWaypoint->GetPrev()->iNodeID != segmentDestClosest )
  3923. {
  3924. DbgNavMsg( GetOuter(), "Strider resetting goal to nearest point on graph\n");
  3925. pLast->vecLocation = vNewEnd;
  3926. }
  3927. else
  3928. {
  3929. DbgNavMsg( GetOuter(), "Strider resetting goal to nearest point on graph, on node\n");
  3930. pLastNodeWaypoint->vecLocation = vNewEnd;
  3931. pLastNodeWaypoint->SetNext( NULL );
  3932. pLastNodeWaypoint->ModifyFlags( bits_WP_TO_GOAL, true );
  3933. delete pLast;
  3934. }
  3935. GetPath()->ResetGoalPosition( GetPath()->GetGoalWaypoint()->vecLocation );
  3936. }
  3937. }
  3938. }
  3939. else
  3940. DbgNavMsg( GetOuter(), "Goal ended on node\n");
  3941. return true;
  3942. }
  3943. else
  3944. DbgNavMsg( GetOuter(), "Strider base pathfind failed\n");
  3945. return false;
  3946. }
  3947. //---------------------------------------------------------
  3948. //---------------------------------------------------------
  3949. bool CNPC_Strider::CNavigator::ShouldOptimizeInitialPathSegment( AI_Waypoint_t *pFirstWaypoint )
  3950. {
  3951. // We do our own special initial path optimization DoFindPathToPos()
  3952. return false;
  3953. }
  3954. //---------------------------------------------------------
  3955. //---------------------------------------------------------
  3956. bool CNPC_Strider::CNavigator::GetStoppingPath( CAI_WaypointList *pClippedWaypoints )
  3957. {
  3958. return false;
  3959. }
  3960. //-----------------------------------------------------------------------------
  3961. // Purpose: Returns if a bone follower is a leg piece or not
  3962. // Input : *pFollower - Bone follower we're testing
  3963. // Output : Returns true if the bone follower is a part of the strider's legs
  3964. //-----------------------------------------------------------------------------
  3965. bool CNPC_Strider::IsLegBoneFollower( CBoneFollower *pFollower )
  3966. {
  3967. // Find the index of this bone follower, if we have it
  3968. int nFollowerIndex = GetBoneFollowerIndex( pFollower );
  3969. if ( nFollowerIndex == -1 )
  3970. return false;
  3971. // See if we're a leg
  3972. if ( nFollowerIndex >= STRIDER_LEFT_LEG_FOLLOWER_INDEX &&
  3973. nFollowerIndex <= STRIDER_BACK_UPPERLEG_FOLLOWER_INDEX )
  3974. return true;
  3975. // We're something else
  3976. return false;
  3977. }
  3978. //-----------------------------------------------------------------------------
  3979. // Purpose: Finds a bone follower via a supplied index
  3980. // Input : nIndex - index our bone follower manager will use to retrieve the follower
  3981. // Output : NULL if not found, otherwise the bone follower we were seeking
  3982. //-----------------------------------------------------------------------------
  3983. CBoneFollower *CNPC_Strider::GetBoneFollowerByIndex( int nIndex )
  3984. {
  3985. physfollower_t *pFollower = m_BoneFollowerManager.GetBoneFollower( nIndex );
  3986. if ( pFollower != NULL )
  3987. return pFollower->hFollower;
  3988. return NULL;
  3989. }
  3990. //-----------------------------------------------------------------------------
  3991. // Purpose: Returns the index of a bone follower in our system
  3992. // Input : *pFollower - Follower we're looking for
  3993. // Output : -1 if not found, otherwise the index of the follower
  3994. //-----------------------------------------------------------------------------
  3995. int CNPC_Strider::GetBoneFollowerIndex( CBoneFollower *pFollower )
  3996. {
  3997. return m_BoneFollowerManager.GetBoneFollowerIndex( pFollower );
  3998. }
  3999. //-----------------------------------------------------------------------------
  4000. // Purpose: The strider ignores certain entities this way
  4001. // Input : *pEntity - Entity in question
  4002. // Output : Returns true if we should collide with the entity
  4003. //-----------------------------------------------------------------------------
  4004. bool CNPC_Strider::ShouldProbeCollideAgainstEntity( CBaseEntity *pEntity )
  4005. {
  4006. if ( pEntity->m_iClassname == m_iszStriderBusterName )
  4007. return false;
  4008. return BaseClass::ShouldProbeCollideAgainstEntity( pEntity );
  4009. }
  4010. //-----------------------------------------------------------------------------
  4011. // Purpose: Lets us keep track of attached Strider busters
  4012. // Input : *pAttached - strider buster that is attached
  4013. //-----------------------------------------------------------------------------
  4014. #ifdef HL2_EPISODIC
  4015. void CNPC_Strider::StriderBusterAttached( CBaseEntity *pAttached )
  4016. {
  4017. // Add another to the list
  4018. m_hAttachedBusters.AddToTail( pAttached );
  4019. m_PlayerFreePass.Revoke();
  4020. variant_t target;
  4021. target.SetString( AllocPooledString( "!player" ) );
  4022. g_EventQueue.AddEvent( this, "UpdateEnemyMemory", target, 1.0, this, this );
  4023. }
  4024. void CNPC_Strider::StriderBusterDetached( CBaseEntity *pAttached )
  4025. {
  4026. int elem = m_hAttachedBusters.Find(pAttached);
  4027. if (elem >= 0)
  4028. {
  4029. m_hAttachedBusters.FastRemove(elem);
  4030. }
  4031. }
  4032. #endif // HL2_EPISODIC
  4033. //-----------------------------------------------------------------------------
  4034. //
  4035. // Strider Minigun
  4036. //
  4037. //-----------------------------------------------------------------------------
  4038. BEGIN_DATADESC_NO_BASE( CStriderMinigun )
  4039. DEFINE_FIELD( m_enable, FIELD_BOOLEAN ),
  4040. DEFINE_FIELD( m_minigunState, FIELD_INTEGER ),
  4041. DEFINE_FIELD( m_nextBulletTime, FIELD_TIME ),
  4042. DEFINE_FIELD( m_burstTime, FIELD_TIME ),
  4043. DEFINE_FIELD( m_nextTwitchTime, FIELD_TIME ),
  4044. DEFINE_FIELD( m_randomState, FIELD_INTEGER ),
  4045. DEFINE_FIELD( m_hTarget, FIELD_EHANDLE ),
  4046. DEFINE_FIELD( m_bWarnedAI, FIELD_BOOLEAN ),
  4047. DEFINE_FIELD( m_shootDuration, FIELD_TIME ),
  4048. DEFINE_FIELD( m_vecAnchor, FIELD_VECTOR ),
  4049. DEFINE_FIELD( m_bOverrideEnemy, FIELD_BOOLEAN ),
  4050. DEFINE_FIELD( m_vecLastTargetPos, FIELD_VECTOR ),
  4051. DEFINE_FIELD( m_iOnTargetShots, FIELD_INTEGER ),
  4052. // Silence, Classcheck!
  4053. // DEFINE_FIELD( m_yaw, StriderMinigunAnimController_t ),
  4054. // DEFINE_FIELD( m_pitch, StriderMinigunAnimController_t ),
  4055. DEFINE_FIELD( m_yaw.current, FIELD_FLOAT ),
  4056. DEFINE_FIELD( m_yaw.target, FIELD_FLOAT ),
  4057. DEFINE_FIELD( m_yaw.rate, FIELD_FLOAT ),
  4058. DEFINE_FIELD( m_pitch.current, FIELD_FLOAT ),
  4059. DEFINE_FIELD( m_pitch.target, FIELD_FLOAT ),
  4060. DEFINE_FIELD( m_pitch.rate, FIELD_FLOAT ),
  4061. END_DATADESC()
  4062. //---------------------------------------------------------
  4063. //---------------------------------------------------------
  4064. void CStriderMinigun::Init()
  4065. {
  4066. m_enable = true;
  4067. m_nextTwitchTime = gpGlobals->curtime;
  4068. m_randomState = 0;
  4069. m_yaw.current = m_yaw.target = 0;
  4070. m_pitch.current = m_pitch.target = 0;
  4071. m_yaw.rate = 360;
  4072. m_pitch.rate = 180;
  4073. SetState( MINIGUN_OFF );
  4074. m_burstTime = gpGlobals->curtime;
  4075. m_nextBulletTime = FLT_MAX;
  4076. m_vecAnchor = vec3_invalid;
  4077. m_shootDuration = STRIDER_DEFAULT_SHOOT_DURATION;
  4078. m_bOverrideEnemy = false;
  4079. }
  4080. //---------------------------------------------------------
  4081. //---------------------------------------------------------
  4082. bool CStriderMinigun::ShouldFindTarget( IMinigunHost *pHost )
  4083. {
  4084. ASSERT( pHost != NULL );
  4085. if( !GetTarget() )
  4086. {
  4087. // No target. Find one.
  4088. return true;
  4089. }
  4090. if( m_bOverrideEnemy )
  4091. {
  4092. return false;
  4093. }
  4094. if( pHost->GetEntity()->GetEnemy() )
  4095. {
  4096. return GetTarget() != pHost->GetEntity()->GetEnemy();
  4097. }
  4098. return true;
  4099. }
  4100. //---------------------------------------------------------
  4101. //---------------------------------------------------------
  4102. float CStriderMinigun::GetAimError()
  4103. {
  4104. return fabs(m_yaw.target-m_yaw.current) + fabs(m_pitch.target-m_pitch.current);
  4105. }
  4106. //---------------------------------------------------------
  4107. //---------------------------------------------------------
  4108. void CStriderMinigun::AimAtPoint( IStriderMinigunHost *pHost, const Vector &vecPoint, bool bSnap )
  4109. {
  4110. matrix3x4_t gunMatrix;
  4111. CAI_BaseNPC *pOwner = pHost->GetEntity();
  4112. int mingunAttachment = pOwner->LookupAttachment( "minigunbase" );
  4113. pOwner->GetAttachment( mingunAttachment, gunMatrix );
  4114. Vector forward, pos;
  4115. MatrixGetColumn( gunMatrix, 0, forward );
  4116. MatrixGetColumn( gunMatrix, 3, pos );
  4117. // transform the point into gun space
  4118. Vector localPointPosition;
  4119. VectorITransform( vecPoint, gunMatrix, localPointPosition );
  4120. // do a look at in gun space (essentially a delta-lookat)
  4121. QAngle localPointAngles;
  4122. VectorAngles( localPointPosition, localPointAngles );
  4123. // convert to +/- 180 degrees
  4124. float pdiff, ydiff;
  4125. pdiff = UTIL_AngleDiff( localPointAngles.x, 0 );
  4126. ydiff = UTIL_AngleDiff( localPointAngles.y, 0 );
  4127. m_pitch.target += 0.5 * pdiff;
  4128. m_yaw.target -= 0.5 * ydiff;
  4129. m_pitch.target = MAX( MINIGUN_MIN_PITCH, m_pitch.target );
  4130. m_pitch.target = MIN( MINIGUN_MAX_PITCH, m_pitch.target );
  4131. m_yaw.target = MAX( MINIGUN_MIN_YAW, m_yaw.target );
  4132. m_yaw.target = MIN( MINIGUN_MAX_YAW, m_yaw.target );
  4133. }
  4134. //---------------------------------------------------------
  4135. //---------------------------------------------------------
  4136. void CStriderMinigun::AimAtTarget( IStriderMinigunHost *pHost, CBaseEntity *pTarget, bool bSnap )
  4137. {
  4138. if ( pTarget && !(CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI) )
  4139. {
  4140. Vector vecTargetPos = pTarget->BodyTarget( pHost->GetEntity()->EyePosition() );
  4141. AimAtPoint( pHost, vecTargetPos, bSnap );
  4142. }
  4143. }
  4144. //---------------------------------------------------------
  4145. //---------------------------------------------------------
  4146. void CStriderMinigun::ShootAtTarget( IStriderMinigunHost *pHost, CBaseEntity *pTarget, float shootTime )
  4147. {
  4148. if ( !pTarget && !(CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI) )
  4149. return;
  4150. variant_t emptyVariant;
  4151. pTarget->AcceptInput( "InputTargeted", pHost->GetEntity(), pHost->GetEntity(), emptyVariant, 0 );
  4152. Enable( NULL, true );
  4153. if ( shootTime <= 0 )
  4154. {
  4155. shootTime = random->RandomFloat( 4, 8 );
  4156. }
  4157. SetTarget( pHost, pTarget, true );
  4158. StartShooting( pHost, pTarget, shootTime );
  4159. }
  4160. //---------------------------------------------------------
  4161. //---------------------------------------------------------
  4162. void CStriderMinigun::StartShooting( IStriderMinigunHost *pHost, CBaseEntity *pTarget, float duration )
  4163. {
  4164. bool bHasSetAnchor = false;
  4165. SetState( MINIGUN_SHOOTING );
  4166. m_nextBulletTime = gpGlobals->curtime;
  4167. m_burstTime = gpGlobals->curtime + duration;
  4168. m_shootDuration = duration;
  4169. // don't twitch while shooting
  4170. m_nextTwitchTime = FLT_MAX;
  4171. if( pTarget->IsPlayer() )
  4172. {
  4173. // Don't shoot a player in the back if they aren't looking.
  4174. // Give them a chance to see they're being fired at.
  4175. CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>(pTarget);
  4176. if( !pPlayer->FInViewCone( pHost->GetEntity() ) )
  4177. {
  4178. // Player doesn't see me. Try to start shooting so that they can see
  4179. // the bullet impacts.
  4180. m_vecAnchor = pPlayer->EyePosition();
  4181. Vector vecPlayerLook;
  4182. Vector vecToPlayer;
  4183. // Check in 2D.
  4184. vecPlayerLook = pPlayer->EyeDirection3D();
  4185. vecPlayerLook.z = 0.0;
  4186. VectorNormalize( vecPlayerLook );
  4187. vecToPlayer = pPlayer->EyePosition() - pHost->GetEntity()->EyePosition();
  4188. vecToPlayer.z = 0.0;
  4189. VectorNormalize( vecToPlayer );
  4190. float flDot = DotProduct( vecToPlayer, vecPlayerLook );
  4191. if( flDot < 0.95 )
  4192. {
  4193. // If the player is looking sufficiently to a side, start 30 feet out in that direction.
  4194. m_vecAnchor += pPlayer->EyeDirection3D() * 320;
  4195. bHasSetAnchor = true;
  4196. }
  4197. else
  4198. {
  4199. // Start over their head, cause firing the direction they are looking will drill them.
  4200. // in the back!
  4201. m_vecAnchor += Vector( 0, 0, random->RandomFloat( 160, 240 ) );
  4202. // Move it to one side of the other randomly, just to get it off center.
  4203. Vector right;
  4204. pPlayer->GetVectors( NULL, &right, NULL );
  4205. m_vecAnchor += right * random->RandomFloat( -100, 100 );
  4206. bHasSetAnchor = true;
  4207. }
  4208. }
  4209. }
  4210. if( !bHasSetAnchor )
  4211. {
  4212. m_vecAnchor = pTarget->WorldSpaceCenter();
  4213. Vector right;
  4214. pTarget->GetVectors( NULL, &right, NULL );
  4215. // Start 5 or 10 feet off target.
  4216. Vector offset = right * random->RandomFloat( 60, 120 );
  4217. // Flip a coin to decide left or right.
  4218. if( random->RandomInt( 0, 1 ) == 0 )
  4219. {
  4220. offset *= -1;
  4221. }
  4222. m_vecAnchor += offset;
  4223. // Start below them, too.
  4224. m_vecAnchor.z -= random->RandomFloat( 80, 200 );
  4225. }
  4226. pHost->OnMinigunStartShooting( pTarget );
  4227. }
  4228. //---------------------------------------------------------
  4229. // Fixes up the math for stitching.
  4230. //---------------------------------------------------------
  4231. void CStriderMinigun::ExtendShooting( float timeExtend )
  4232. {
  4233. m_burstTime = gpGlobals->curtime + timeExtend;
  4234. m_shootDuration = timeExtend;
  4235. m_bWarnedAI = false;
  4236. }
  4237. //---------------------------------------------------------
  4238. //---------------------------------------------------------
  4239. void CStriderMinigun::SetShootDuration( float duration )
  4240. {
  4241. }
  4242. //---------------------------------------------------------
  4243. // Is the gun turned as far as it can go?
  4244. //---------------------------------------------------------
  4245. bool CStriderMinigun::IsPegged( int dir )
  4246. {
  4247. bool up, down, left, right, any;
  4248. up = down = left = right = any = false;
  4249. if( m_yaw.current >= 89.0 )
  4250. any = right = true;
  4251. if( m_yaw.current <= -89.0 )
  4252. any = left = true;
  4253. if( m_pitch.current >= 44.0 )
  4254. any = down = true;
  4255. if( m_pitch.current <= -44.0 )
  4256. any = up = true;
  4257. switch( dir )
  4258. {
  4259. case MINIGUN_PEGGED_UP:
  4260. return up;
  4261. case MINIGUN_PEGGED_DOWN:
  4262. return down;
  4263. case MINIGUN_PEGGED_LEFT:
  4264. return left;
  4265. case MINIGUN_PEGGED_RIGHT:
  4266. return right;
  4267. default:
  4268. return (any && !up);
  4269. }
  4270. }
  4271. //---------------------------------------------------------
  4272. //---------------------------------------------------------
  4273. void CStriderMinigun::StopShootingForSeconds( IStriderMinigunHost *pHost, CBaseEntity *pTarget, float duration )
  4274. {
  4275. if ( IsShooting() )
  4276. {
  4277. SetState( MINIGUN_OFF );
  4278. }
  4279. m_burstTime = gpGlobals->curtime + duration;
  4280. m_nextBulletTime = FLT_MAX;
  4281. ClearOnTarget();
  4282. m_nextTwitchTime = gpGlobals->curtime + random->RandomFloat( 2.0, 4.0 );
  4283. pHost->OnMinigunStopShooting( pTarget );
  4284. }
  4285. //---------------------------------------------------------
  4286. //---------------------------------------------------------
  4287. void CStriderMinigun::SetState( int newState )
  4288. {
  4289. m_minigunState = newState;
  4290. }
  4291. //---------------------------------------------------------
  4292. //---------------------------------------------------------
  4293. void CStriderMinigun::SetTarget( IStriderMinigunHost *pHost, CBaseEntity *pTarget, bool bOverrideEnemy )
  4294. {
  4295. m_hTarget = pTarget;
  4296. if( pTarget )
  4297. {
  4298. // New target, we haven't scared this guy yet!
  4299. m_bWarnedAI = false;
  4300. if( m_vecAnchor == vec3_invalid )
  4301. {
  4302. Vector right;
  4303. pHost->GetEntity()->GetVectors( NULL, &right, NULL );
  4304. m_vecAnchor = pTarget->GetAbsOrigin() - Vector( 0, 0, 256 );
  4305. m_vecAnchor += right * random->RandomFloat( -60.0f, 60.0f );
  4306. }
  4307. }
  4308. ClearOnTarget();
  4309. m_bOverrideEnemy = bOverrideEnemy;
  4310. }
  4311. //---------------------------------------------------------
  4312. // The strider minigun can track and fire at targets in a fairly
  4313. // large arc. It looks unnatural for a Strider to acquire a target
  4314. // off to one side and begin firing at it, so we don't let the
  4315. // minigun BEGIN shooting at a target unless the target is fairly
  4316. // well in front of the Strider. Once firing, the gun is allowed
  4317. // to track the target anywhere for the duration of that burst of
  4318. // minigun fire. This is tuned by eye. (sjb)
  4319. //---------------------------------------------------------
  4320. bool CStriderMinigun::CanStartShooting( IStriderMinigunHost *pHost, CBaseEntity *pTargetEnt )
  4321. {
  4322. if ( CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI )
  4323. return false;
  4324. if( !pTargetEnt )
  4325. return false;
  4326. if( gpGlobals->curtime < m_burstTime )
  4327. return false;
  4328. CNPC_Strider *pStrider = dynamic_cast<CNPC_Strider *>(pHost->GetEntity() );
  4329. if ( pTargetEnt->IsPlayer() && pStrider->HasPass() )
  4330. return false;
  4331. if( !m_bOverrideEnemy )
  4332. {
  4333. if( pTargetEnt != pHost->GetEntity()->GetEnemy() )
  4334. {
  4335. return false;
  4336. }
  4337. // If the strider can't see the enemy, this may be because the enemy is
  4338. // hiding behind something breakable. If the weapon has LOS, fire away.
  4339. if( !pHost->GetEntity()->HasCondition( COND_SEE_ENEMY ) )
  4340. {
  4341. Assert( pStrider != NULL );
  4342. if( !pStrider->WeaponLOSCondition( pStrider->GetAdjustedOrigin(), pTargetEnt->WorldSpaceCenter(), false ) )
  4343. {
  4344. if( pStrider->IsUsingAggressiveBehavior() && pTargetEnt->IsPlayer() && !pStrider->HasPass() )
  4345. {
  4346. // I can shoot the player's cover until he hides long enough to earn a free pass.
  4347. float flTimeSinceLastSeen = gpGlobals->curtime - pStrider->GetEnemies()->LastTimeSeen(pTargetEnt);
  4348. if( flTimeSinceLastSeen <= 2.0f )
  4349. return true;
  4350. }
  4351. return false;
  4352. }
  4353. }
  4354. }
  4355. Vector los = ( pTargetEnt->WorldSpaceCenter() - pHost->GetEntity()->EyePosition() );
  4356. // Following code stolen from FVisible. This check done in 2d intentionally.
  4357. los.z = 0;
  4358. VectorNormalize( los );
  4359. Vector facingDir = pHost->GetEntity()->EyeDirection2D( );
  4360. float flDot = DotProduct( los, facingDir );
  4361. // Too far to a side.
  4362. if ( flDot <= .707 )
  4363. return false;
  4364. return true;
  4365. }
  4366. //---------------------------------------------------------
  4367. //---------------------------------------------------------
  4368. void CStriderMinigun::Enable( IMinigunHost *pHost, bool enable )
  4369. {
  4370. m_enable = enable;
  4371. if ( !m_enable )
  4372. {
  4373. m_yaw.current = m_yaw.target = 0;
  4374. m_pitch.current = m_pitch.target = 0;
  4375. if ( pHost )
  4376. {
  4377. // KENB pHost->UpdateMinigunControls( m_yaw.current, m_pitch.current );
  4378. }
  4379. }
  4380. }
  4381. //---------------------------------------------------------
  4382. //---------------------------------------------------------
  4383. void CStriderMinigun::Think( IStriderMinigunHost *pHost, float dt )
  4384. {
  4385. if ( !m_enable )
  4386. return;
  4387. if ( CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI )
  4388. return;
  4389. if( ShouldFindTarget( pHost ) )
  4390. {
  4391. CBaseEntity *pOldTarget = GetTarget();
  4392. // Take my host's enemy.
  4393. SetTarget( pHost, pHost->GetEntity()->GetEnemy() );
  4394. if( IsShooting() )
  4395. {
  4396. // Changing targets hot!
  4397. if( pOldTarget )
  4398. {
  4399. m_vecAnchor = pOldTarget->WorldSpaceCenter();
  4400. }
  4401. ExtendShooting( STRIDER_SUBSEQUENT_TARGET_DURATION + random->RandomFloat( 0, 0.5 ) );
  4402. }
  4403. pHost->NewTarget();
  4404. }
  4405. if ( !GetTarget() && m_nextTwitchTime <= gpGlobals->curtime )
  4406. {
  4407. // invert one and randomize the other.
  4408. // This has the effect of making the gun cross the field of
  4409. // view more often - like he's looking around
  4410. m_randomState = !m_randomState;
  4411. if ( m_randomState )
  4412. {
  4413. m_yaw.Random( MINIGUN_MIN_YAW, MINIGUN_MAX_YAW, 360, 720 );
  4414. m_pitch.target = -m_pitch.target;
  4415. }
  4416. else
  4417. {
  4418. m_pitch.Random( MINIGUN_MIN_PITCH, MINIGUN_MAX_PITCH, 270, 360 );
  4419. m_yaw.target = -m_yaw.target;
  4420. }
  4421. m_nextTwitchTime = gpGlobals->curtime + random->RandomFloat( 0.3, 2 );
  4422. }
  4423. CBaseEntity *pTargetEnt = m_hTarget.Get();
  4424. if ( pTargetEnt )
  4425. {
  4426. pHost->GetEntity()->InvalidateBoneCache();
  4427. AimAtTarget( pHost, pTargetEnt );
  4428. }
  4429. // Update the minigun's pose parameters using approaching.
  4430. m_yaw.Update( dt );
  4431. m_pitch.Update( dt );
  4432. pHost->UpdateMinigunControls( m_yaw.current, m_pitch.current );
  4433. // Start or stop shooting.
  4434. if( IsShooting() )
  4435. {
  4436. if( gpGlobals->curtime > m_burstTime || !pTargetEnt )
  4437. {
  4438. // Time to stop firing.
  4439. if( m_bOverrideEnemy )
  4440. {
  4441. // Get rid of this target.
  4442. SetTarget( pHost, NULL );
  4443. }
  4444. StopShootingForSeconds( pHost, pTargetEnt, pHost->GetMinigunShootDowntime() );
  4445. }
  4446. }
  4447. else
  4448. {
  4449. if( CanStartShooting( pHost, pTargetEnt ) )
  4450. {
  4451. StartShooting( pHost, pTargetEnt, pHost->GetMinigunShootDuration() + random->RandomFloat( 0, pHost->GetMinigunShootVariation() ) );
  4452. }
  4453. }
  4454. // Fire the next bullet!
  4455. if ( m_nextBulletTime <= gpGlobals->curtime && !IsPegged() )
  4456. {
  4457. if( pTargetEnt && pTargetEnt == pHost->GetEntity()->GetEnemy() )
  4458. {
  4459. // Shooting at the Strider's enemy. Strafe to target!
  4460. float flRemainingShootTime = m_burstTime - gpGlobals->curtime;
  4461. // Skim a little time off of the factor, leave a moment of on-target
  4462. // time. This guarantees that the minigun will strike the target a few times.
  4463. float flFactor = (flRemainingShootTime - pHost->GetMinigunOnTargetTime() ) / m_shootDuration;
  4464. flFactor = MAX( 0.0f, flFactor );
  4465. Vector vecTarget = pTargetEnt->BodyTarget( assert_cast<CNPC_Strider *>(pHost->GetEntity())->GetAdjustedOrigin());
  4466. Vector vecLine = m_vecAnchor - vecTarget;
  4467. float flDist = VectorNormalize( vecLine );
  4468. vecTarget += vecLine * flDist * flFactor;
  4469. if( flFactor == 0.0 )
  4470. {
  4471. m_vecAnchor = vecTarget;
  4472. RecordShotOnTarget();
  4473. }
  4474. if ( GetTarget() )
  4475. {
  4476. pHost->ShootMinigun( &vecTarget, GetAimError(), vec3_origin );
  4477. if( flFactor <= 0.5 && !m_bWarnedAI )
  4478. {
  4479. m_bWarnedAI = true;
  4480. CSoundEnt::InsertSound( SOUND_DANGER | SOUND_CONTEXT_REACT_TO_SOURCE, pTargetEnt->EarPosition() + Vector( 0, 0, 1 ), 120, MAX( 1.0, flRemainingShootTime ), pHost->GetEntity() );
  4481. }
  4482. }
  4483. }
  4484. else
  4485. {
  4486. const Vector *pTargetPoint = pTargetEnt ? &pTargetEnt->GetAbsOrigin() : NULL;
  4487. pHost->ShootMinigun( pTargetPoint, GetAimError() );
  4488. }
  4489. m_nextBulletTime = gpGlobals->curtime + (1.0f / pHost->GetMinigunRateOfFire() );
  4490. }
  4491. }
  4492. LINK_ENTITY_TO_CLASS( sparktrail, CSparkTrail );
  4493. void CSparkTrail::Precache()
  4494. {
  4495. BaseClass::Precache();
  4496. PrecacheScriptSound( "DoSpark" );
  4497. }
  4498. void CSparkTrail::Spawn()
  4499. {
  4500. Precache();
  4501. EmitSound( "DoSpark" );
  4502. m_iHealth = 20 + random->RandomInt( 0, 5 );
  4503. UTIL_SetOrigin( this, GetOwnerEntity()->EyePosition() );
  4504. Vector vecVelocity;
  4505. vecVelocity.x = random->RandomFloat( 100, 400 );
  4506. vecVelocity.y = random->RandomFloat( 100, 400 );
  4507. vecVelocity.z = random->RandomFloat( 0, 100 );
  4508. if( random->RandomInt( 0, 1 ) == 0 )
  4509. vecVelocity.x *= -1;
  4510. if( random->RandomInt( 0, 1 ) == 0 )
  4511. vecVelocity.y *= -1;
  4512. UTIL_SetSize( this, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
  4513. SetMoveType( MOVETYPE_FLYGRAVITY );
  4514. SetSolid( SOLID_NONE );
  4515. if( random->RandomInt( 0, 2 ) == 0 )
  4516. {
  4517. vecVelocity *= 2.0;
  4518. m_iHealth /= 2;
  4519. SetMoveType( MOVETYPE_FLY );
  4520. }
  4521. SetAbsVelocity( vecVelocity );
  4522. SetThink( &CSparkTrail::SparkThink );
  4523. SetNextThink( gpGlobals->curtime );
  4524. }
  4525. void CSparkTrail::SparkThink()
  4526. {
  4527. SetNextThink( gpGlobals->curtime + 0.05 );
  4528. g_pEffects->Sparks( GetAbsOrigin() );
  4529. if( m_iHealth-- < 1 )
  4530. {
  4531. UTIL_Remove( this );
  4532. }
  4533. }
  4534. BEGIN_DATADESC( CSparkTrail )
  4535. DEFINE_THINKFUNC( SparkThink ),
  4536. END_DATADESC()
  4537. //-----------------------------------------------------------------------------
  4538. //
  4539. // Schedules
  4540. //
  4541. //-----------------------------------------------------------------------------
  4542. AI_BEGIN_CUSTOM_NPC( npc_strider, CNPC_Strider )
  4543. DECLARE_TASK( TASK_STRIDER_AIM )
  4544. DECLARE_TASK( TASK_STRIDER_DODGE )
  4545. DECLARE_TASK( TASK_STRIDER_STOMP )
  4546. DECLARE_TASK( TASK_STRIDER_BREAKDOWN )
  4547. DECLARE_TASK( TASK_STRIDER_START_MOVING )
  4548. DECLARE_TASK( TASK_STRIDER_REFRESH_HUNT_PATH )
  4549. DECLARE_TASK( TASK_STRIDER_GET_PATH_TO_CANNON_TARGET )
  4550. DECLARE_TASK( TASK_STRIDER_FACE_CANNON_TARGET )
  4551. DECLARE_TASK( TASK_STRIDER_SET_HEIGHT )
  4552. DECLARE_TASK( TASK_STRIDER_GET_PATH_TO_CANNON_LOS )
  4553. DECLARE_TASK( TASK_STRIDER_FIRE_CANNON )
  4554. DECLARE_TASK( TASK_STRIDER_SET_CANNON_HEIGHT )
  4555. DECLARE_TASK( TASK_STRIDER_FALL_TO_GROUND )
  4556. DECLARE_ACTIVITY( ACT_STRIDER_LOOKL )
  4557. DECLARE_ACTIVITY( ACT_STRIDER_LOOKR )
  4558. DECLARE_ACTIVITY( ACT_STRIDER_DEPLOYRA1 )
  4559. DECLARE_ACTIVITY( ACT_STRIDER_AIMRA1 )
  4560. DECLARE_ACTIVITY( ACT_STRIDER_FINISHRA1 )
  4561. DECLARE_ACTIVITY( ACT_STRIDER_DODGER )
  4562. DECLARE_ACTIVITY( ACT_STRIDER_DODGEL )
  4563. DECLARE_ACTIVITY( ACT_STRIDER_STOMPL )
  4564. DECLARE_ACTIVITY( ACT_STRIDER_STOMPR )
  4565. DECLARE_ACTIVITY( ACT_STRIDER_FLICKL )
  4566. DECLARE_ACTIVITY( ACT_STRIDER_FLICKR )
  4567. DECLARE_ACTIVITY( ACT_STRIDER_SLEEP )
  4568. DECLARE_ACTIVITY( ACT_STRIDER_CARRIED )
  4569. DECLARE_ACTIVITY( ACT_STRIDER_DEPLOY )
  4570. DECLARE_ACTIVITY( ACT_STRIDER_GESTURE_DEATH )
  4571. DECLARE_CONDITION( COND_STRIDER_DO_FLICK )
  4572. DECLARE_CONDITION( COND_TRACK_PATH_GO )
  4573. DECLARE_CONDITION( COND_STRIDER_SHOULD_CROUCH )
  4574. DECLARE_CONDITION( COND_STRIDER_SHOULD_STAND )
  4575. DECLARE_CONDITION( COND_STRIDER_MINIGUN_SHOOTING )
  4576. DECLARE_CONDITION( COND_STRIDER_MINIGUN_NOT_SHOOTING )
  4577. DECLARE_CONDITION( COND_STRIDER_HAS_CANNON_TARGET )
  4578. DECLARE_CONDITION( COND_STRIDER_ENEMY_UPDATED )
  4579. DECLARE_CONDITION( COND_STRIDER_HAS_LOS_Z )
  4580. DECLARE_INTERACTION( g_interactionPlayerLaunchedRPG )
  4581. //=========================================================
  4582. // Hunt (Basic logic for strider thinking)
  4583. //=========================================================
  4584. DEFINE_SCHEDULE
  4585. (
  4586. SCHED_STRIDER_HUNT,
  4587. " Tasks"
  4588. " TASK_STRIDER_REFRESH_HUNT_PATH 0"
  4589. " TASK_STRIDER_START_MOVING 0"
  4590. " TASK_WAIT 4"
  4591. " "
  4592. " Interrupts"
  4593. " COND_NEW_ENEMY"
  4594. " COND_CAN_MELEE_ATTACK1"
  4595. " COND_CAN_RANGE_ATTACK1"
  4596. " COND_CAN_RANGE_ATTACK2"
  4597. " COND_STRIDER_SHOULD_CROUCH"
  4598. " COND_STRIDER_HAS_CANNON_TARGET"
  4599. " COND_STRIDER_ENEMY_UPDATED"
  4600. )
  4601. //=========================================================
  4602. // Attack (Deploy/shoot/finish)
  4603. //=========================================================
  4604. DEFINE_SCHEDULE
  4605. (
  4606. SCHED_STRIDER_RANGE_ATTACK1,
  4607. " Tasks"
  4608. " TASK_STOP_MOVING 0"
  4609. " TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
  4610. " TASK_FACE_ENEMY 0"
  4611. " TASK_RANGE_ATTACK1 0"
  4612. " TASK_WAIT 5" // let the immolator work its magic
  4613. " "
  4614. " Interrupts"
  4615. )
  4616. //=========================================================
  4617. // Attack (Deploy/shoot/finish)
  4618. //=========================================================
  4619. DEFINE_SCHEDULE
  4620. (
  4621. SCHED_STRIDER_RANGE_ATTACK2,
  4622. " Tasks"
  4623. " TASK_STOP_MOVING 0"
  4624. " TASK_STRIDER_FACE_CANNON_TARGET 0"
  4625. " TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
  4626. " TASK_WAIT 1"
  4627. " TASK_STRIDER_AIM 1.25"
  4628. " TASK_STRIDER_FIRE_CANNON 0"
  4629. " TASK_WAIT 1"
  4630. " "
  4631. " Interrupts"
  4632. )
  4633. //=========================================================
  4634. //=========================================================
  4635. DEFINE_SCHEDULE
  4636. (
  4637. SCHED_STRIDER_CROUCH,
  4638. " Tasks"
  4639. " TASK_STOP_MOVING 0"
  4640. " TASK_PLAY_SEQUENCE ACTIVITY:ACT_CROUCH"
  4641. " "
  4642. " Interrupts"
  4643. )
  4644. //=========================================================
  4645. //=========================================================
  4646. DEFINE_SCHEDULE
  4647. (
  4648. SCHED_STRIDER_STAND,
  4649. " Tasks"
  4650. " TASK_STOP_MOVING 0"
  4651. " TASK_PLAY_SEQUENCE ACTIVITY:ACT_STAND"
  4652. " TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
  4653. " TASK_STRIDER_SET_HEIGHT 500"
  4654. " "
  4655. " Interrupts"
  4656. )
  4657. //=========================================================
  4658. // Dodge Incoming missile
  4659. //=========================================================
  4660. DEFINE_SCHEDULE
  4661. (
  4662. SCHED_STRIDER_DODGE,
  4663. " Tasks"
  4664. " TASK_STRIDER_DODGE 0"
  4665. " "
  4666. " Interrupts"
  4667. )
  4668. //=========================================================
  4669. // Break down and die
  4670. //=========================================================
  4671. DEFINE_SCHEDULE
  4672. (
  4673. SCHED_STRIDER_DIE,
  4674. " Tasks"
  4675. " TASK_STRIDER_BREAKDOWN 0"
  4676. " "
  4677. " Interrupts"
  4678. )
  4679. //=========================================================
  4680. // Stomp on an enemy
  4681. //=========================================================
  4682. DEFINE_SCHEDULE
  4683. (
  4684. SCHED_STRIDER_STOMPL,
  4685. " Tasks"
  4686. " TASK_STOP_MOVING 0"
  4687. " TASK_STRIDER_STOMP 0"
  4688. " "
  4689. " Interrupts"
  4690. );
  4691. // Stomp on an enemy
  4692. //=========================================================
  4693. DEFINE_SCHEDULE
  4694. (
  4695. SCHED_STRIDER_STOMPR,
  4696. " Tasks"
  4697. " TASK_STOP_MOVING 0"
  4698. " TASK_STRIDER_STOMP 1"
  4699. " "
  4700. " Interrupts"
  4701. )
  4702. DEFINE_SCHEDULE
  4703. (
  4704. SCHED_STRIDER_FLICKL,
  4705. " Tasks"
  4706. " TASK_PLAY_SEQUENCE ACTIVITY:ACT_STRIDER_FLICKL"
  4707. " "
  4708. " Interrupts"
  4709. )
  4710. DEFINE_SCHEDULE
  4711. (
  4712. SCHED_STRIDER_FLICKR,
  4713. " Tasks"
  4714. " TASK_PLAY_SEQUENCE ACTIVITY:ACT_STRIDER_FLICKR"
  4715. " "
  4716. " Interrupts"
  4717. )
  4718. DEFINE_SCHEDULE
  4719. (
  4720. SCHED_STRIDER_ATTACK_CANNON_TARGET,
  4721. " Tasks"
  4722. " TASK_STOP_MOVING 0"
  4723. " TASK_STRIDER_GET_PATH_TO_CANNON_TARGET 0"
  4724. " TASK_WALK_PATH 0"
  4725. " TASK_WAIT_FOR_MOVEMENT 0"
  4726. " "
  4727. " Interrupts"
  4728. " COND_CAN_RANGE_ATTACK2"
  4729. " COND_STRIDER_SHOULD_CROUCH"
  4730. )
  4731. DEFINE_SCHEDULE
  4732. (
  4733. SCHED_STRIDER_CHASE_ENEMY,
  4734. " Tasks"
  4735. " TASK_STOP_MOVING 0"
  4736. " TASK_GET_CHASE_PATH_TO_ENEMY 300"
  4737. " TASK_RUN_PATH 0"
  4738. " TASK_WAIT_FOR_MOVEMENT 0"
  4739. " TASK_FACE_ENEMY 0"
  4740. ""
  4741. " Interrupts"
  4742. " COND_NEW_ENEMY"
  4743. " COND_ENEMY_DEAD"
  4744. " COND_ENEMY_UNREACHABLE"
  4745. " COND_CAN_RANGE_ATTACK1"
  4746. " COND_CAN_MELEE_ATTACK1"
  4747. " COND_CAN_RANGE_ATTACK2"
  4748. " COND_CAN_MELEE_ATTACK2"
  4749. " COND_TOO_CLOSE_TO_ATTACK"
  4750. " COND_LOST_ENEMY"
  4751. " COND_STRIDER_HAS_CANNON_TARGET"
  4752. )
  4753. DEFINE_SCHEDULE
  4754. (
  4755. SCHED_STRIDER_COMBAT_FACE,
  4756. " Tasks"
  4757. " TASK_STOP_MOVING 0"
  4758. " TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
  4759. " TASK_WAIT_FACE_ENEMY 1"
  4760. ""
  4761. " Interrupts"
  4762. " COND_CAN_RANGE_ATTACK1"
  4763. " COND_CAN_RANGE_ATTACK2"
  4764. " COND_CAN_MELEE_ATTACK1"
  4765. " COND_CAN_MELEE_ATTACK2"
  4766. " COND_NEW_ENEMY"
  4767. " COND_ENEMY_DEAD"
  4768. " COND_STRIDER_HAS_CANNON_TARGET"
  4769. )
  4770. DEFINE_SCHEDULE
  4771. (
  4772. SCHED_STRIDER_AGGRESSIVE_COMBAT_STAND,
  4773. " Tasks"
  4774. " TASK_STOP_MOVING 0"
  4775. " TASK_SET_ACTIVITY ACTIVITY:ACT_IDLE"
  4776. " TASK_WAIT 1"
  4777. ""
  4778. " Interrupts"
  4779. " COND_NEW_ENEMY"
  4780. " COND_ENEMY_DEAD"
  4781. " COND_LIGHT_DAMAGE"
  4782. " COND_HEAVY_DAMAGE"
  4783. " COND_SEE_ENEMY"
  4784. " COND_CAN_RANGE_ATTACK1"
  4785. " COND_CAN_RANGE_ATTACK2"
  4786. " COND_CAN_MELEE_ATTACK1"
  4787. " COND_CAN_MELEE_ATTACK2"
  4788. " COND_IDLE_INTERRUPT"
  4789. )
  4790. DEFINE_SCHEDULE
  4791. (
  4792. SCHED_STRIDER_ESTABLISH_LINE_OF_FIRE_CANNON,
  4793. " Tasks "
  4794. " TASK_STRIDER_GET_PATH_TO_CANNON_LOS 0"
  4795. " TASK_RUN_PATH 0"
  4796. " TASK_WAIT_FOR_MOVEMENT 0"
  4797. " TASK_STRIDER_FACE_CANNON_TARGET 0"
  4798. ""
  4799. " Interrupts "
  4800. " COND_CAN_RANGE_ATTACK2"
  4801. " COND_STRIDER_SHOULD_CROUCH"
  4802. " COND_STRIDER_SHOULD_STAND"
  4803. )
  4804. DEFINE_SCHEDULE
  4805. (
  4806. SCHED_STRIDER_FALL_TO_GROUND,
  4807. " Tasks "
  4808. " TASK_STRIDER_FALL_TO_GROUND 0"
  4809. ""
  4810. " Interrupts "
  4811. )
  4812. AI_END_CUSTOM_NPC()
  4813. //=============================================================================