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.

163 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Dr. Eli Vance, earths last great hope, single-handedly fighting
  4. // off both an evil alien invasion, as well as trying to stop
  5. // that idiot lab assistant from putting the moves on his daughter.
  6. //=============================================================================//
  7. //-----------------------------------------------------------------------------
  8. // Generic NPC - purely for scripted sequence work.
  9. //-----------------------------------------------------------------------------
  10. #include "cbase.h"
  11. #include "npcevent.h"
  12. #include "ai_basenpc.h"
  13. #include "ai_hull.h"
  14. #include "ai_baseactor.h"
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //-----------------------------------------------------------------------------
  18. // NPC's Anim Events Go Here
  19. //-----------------------------------------------------------------------------
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. class CNPC_Eli : public CAI_BaseActor
  24. {
  25. public:
  26. DECLARE_CLASS( CNPC_Eli, CAI_BaseActor );
  27. void Spawn( void );
  28. void Precache( void );
  29. Class_T Classify ( void );
  30. void HandleAnimEvent( animevent_t *pEvent );
  31. int GetSoundInterests( void );
  32. void SetupWithoutParent( void );
  33. void PrescheduleThink( void );
  34. };
  35. LINK_ENTITY_TO_CLASS( npc_eli, CNPC_Eli );
  36. //-----------------------------------------------------------------------------
  37. // Classify - indicates this NPC's place in the
  38. // relationship table.
  39. //-----------------------------------------------------------------------------
  40. Class_T CNPC_Eli::Classify ( void )
  41. {
  42. return CLASS_PLAYER_ALLY_VITAL;
  43. }
  44. //-----------------------------------------------------------------------------
  45. // HandleAnimEvent - catches the NPC-specific messages
  46. // that occur when tagged animation frames are played.
  47. //-----------------------------------------------------------------------------
  48. void CNPC_Eli::HandleAnimEvent( animevent_t *pEvent )
  49. {
  50. switch( pEvent->event )
  51. {
  52. case 1:
  53. default:
  54. BaseClass::HandleAnimEvent( pEvent );
  55. break;
  56. }
  57. }
  58. //-----------------------------------------------------------------------------
  59. // GetSoundInterests - generic NPC can't hear.
  60. //-----------------------------------------------------------------------------
  61. int CNPC_Eli::GetSoundInterests ( void )
  62. {
  63. return NULL;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Spawn
  67. //-----------------------------------------------------------------------------
  68. void CNPC_Eli::Spawn()
  69. {
  70. // Eli is allowed to use multiple models, because he appears in the pod.
  71. // He defaults to his normal model.
  72. char *szModel = (char *)STRING( GetModelName() );
  73. if (!szModel || !*szModel)
  74. {
  75. szModel = "models/eli.mdl";
  76. SetModelName( AllocPooledString(szModel) );
  77. }
  78. Precache();
  79. SetModel( szModel );
  80. BaseClass::Spawn();
  81. SetHullType(HULL_HUMAN);
  82. SetHullSizeNormal();
  83. // If Eli has a parent, he's currently inside a pod. Prevent him from moving.
  84. if ( GetMoveParent() )
  85. {
  86. SetSolid( SOLID_BBOX );
  87. AddSolidFlags( FSOLID_NOT_STANDABLE );
  88. SetMoveType( MOVETYPE_NONE );
  89. CapabilitiesAdd( bits_CAP_ANIMATEDFACE | bits_CAP_TURN_HEAD );
  90. CapabilitiesAdd( bits_CAP_FRIENDLY_DMG_IMMUNE );
  91. }
  92. else
  93. {
  94. SetupWithoutParent();
  95. }
  96. AddEFlags( EFL_NO_DISSOLVE | EFL_NO_MEGAPHYSCANNON_RAGDOLL | EFL_NO_PHYSCANNON_INTERACTION );
  97. SetBloodColor( BLOOD_COLOR_RED );
  98. m_iHealth = 8;
  99. m_flFieldOfView = 0.5;// indicates the width of this NPC's forward view cone ( as a dotproduct result )
  100. m_NPCState = NPC_STATE_NONE;
  101. NPCInit();
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Precache - precaches all resources this NPC needs
  105. //-----------------------------------------------------------------------------
  106. void CNPC_Eli::Precache()
  107. {
  108. PrecacheModel( STRING( GetModelName() ) );
  109. BaseClass::Precache();
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. //-----------------------------------------------------------------------------
  114. void CNPC_Eli::SetupWithoutParent( void )
  115. {
  116. SetSolid( SOLID_BBOX );
  117. AddSolidFlags( FSOLID_NOT_STANDABLE );
  118. SetMoveType( MOVETYPE_STEP );
  119. CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_OPEN_DOORS | bits_CAP_ANIMATEDFACE | bits_CAP_TURN_HEAD );
  120. CapabilitiesAdd( bits_CAP_FRIENDLY_DMG_IMMUNE );
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose:
  124. //-----------------------------------------------------------------------------
  125. void CNPC_Eli::PrescheduleThink( void )
  126. {
  127. BaseClass::PrescheduleThink();
  128. // Figure out if Eli has just been removed from his parent
  129. if ( GetMoveType() == MOVETYPE_NONE && !GetMoveParent() )
  130. {
  131. SetupWithoutParent();
  132. SetupVPhysicsHull();
  133. }
  134. }
  135. //-----------------------------------------------------------------------------
  136. // AI Schedules Specific to this NPC
  137. //-----------------------------------------------------------------------------