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.

164 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: The G-Man, misunderstood servant of the people
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. //-----------------------------------------------------------------------------
  9. // Generic NPC - purely for scripted sequence work.
  10. //-----------------------------------------------------------------------------
  11. #include "cbase.h"
  12. #include "npcevent.h"
  13. #include "ai_basenpc.h"
  14. #include "ai_hull.h"
  15. #include "ai_behavior_follow.h"
  16. #include "ai_playerally.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. //-----------------------------------------------------------------------------
  20. // NPC's Anim Events Go Here
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. class CNPC_GMan : public CAI_PlayerAlly
  26. {
  27. public:
  28. DECLARE_CLASS( CNPC_GMan, CAI_PlayerAlly );
  29. DECLARE_DATADESC();
  30. void Spawn( void );
  31. void Precache( void );
  32. Class_T Classify ( void );
  33. void HandleAnimEvent( animevent_t *pEvent );
  34. virtual Disposition_t IRelationType(CBaseEntity *pTarget);
  35. int GetSoundInterests ( void );
  36. bool CreateBehaviors( void );
  37. int SelectSchedule( void );
  38. private:
  39. CAI_FollowBehavior m_FollowBehavior;
  40. };
  41. LINK_ENTITY_TO_CLASS( npc_gman, CNPC_GMan );
  42. BEGIN_DATADESC( CNPC_GMan )
  43. // (auto saved by AI)
  44. // DEFINE_FIELD( m_FollowBehavior, FIELD_EMBEDDED ), (auto saved by AI)
  45. END_DATADESC()
  46. //-----------------------------------------------------------------------------
  47. // Classify - indicates this NPC's place in the
  48. // relationship table.
  49. //-----------------------------------------------------------------------------
  50. Class_T CNPC_GMan::Classify ( void )
  51. {
  52. return CLASS_PLAYER_ALLY_VITAL;
  53. }
  54. //-----------------------------------------------------------------------------
  55. // HandleAnimEvent - catches the NPC-specific messages
  56. // that occur when tagged animation frames are played.
  57. //-----------------------------------------------------------------------------
  58. void CNPC_GMan::HandleAnimEvent( animevent_t *pEvent )
  59. {
  60. switch( pEvent->event )
  61. {
  62. case 1:
  63. default:
  64. BaseClass::HandleAnimEvent( pEvent );
  65. break;
  66. }
  67. }
  68. //-----------------------------------------------------------------------------
  69. // GetSoundInterests - generic NPC can't hear.
  70. //-----------------------------------------------------------------------------
  71. int CNPC_GMan::GetSoundInterests ( void )
  72. {
  73. return NULL;
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Spawn
  77. //-----------------------------------------------------------------------------
  78. void CNPC_GMan::Spawn()
  79. {
  80. Precache();
  81. BaseClass::Spawn();
  82. SetModel( "models/gman.mdl" );
  83. SetHullType(HULL_HUMAN);
  84. SetHullSizeNormal();
  85. SetSolid( SOLID_BBOX );
  86. AddSolidFlags( FSOLID_NOT_STANDABLE );
  87. SetMoveType( MOVETYPE_STEP );
  88. SetBloodColor( BLOOD_COLOR_RED );
  89. m_iHealth = 8;
  90. m_flFieldOfView = 0.5;// indicates the width of this NPC's forward view cone ( as a dotproduct result )
  91. m_NPCState = NPC_STATE_NONE;
  92. SetImpactEnergyScale( 0.0f ); // no physics damage on the gman
  93. CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_OPEN_DOORS | bits_CAP_ANIMATEDFACE | bits_CAP_TURN_HEAD );
  94. CapabilitiesAdd( bits_CAP_FRIENDLY_DMG_IMMUNE );
  95. AddEFlags( EFL_NO_DISSOLVE | EFL_NO_MEGAPHYSCANNON_RAGDOLL );
  96. NPCInit();
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Precache - precaches all resources this NPC needs
  100. //-----------------------------------------------------------------------------
  101. void CNPC_GMan::Precache()
  102. {
  103. PrecacheModel( "models/gman.mdl" );
  104. BaseClass::Precache();
  105. }
  106. //-----------------------------------------------------------------------------
  107. // The G-Man isn't scared of anything.
  108. //-----------------------------------------------------------------------------
  109. Disposition_t CNPC_GMan::IRelationType(CBaseEntity *pTarget)
  110. {
  111. return D_NU;
  112. }
  113. //=========================================================
  114. // Purpose:
  115. //=========================================================
  116. bool CNPC_GMan::CreateBehaviors()
  117. {
  118. AddBehavior( &m_FollowBehavior );
  119. return BaseClass::CreateBehaviors();
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose:
  123. //-----------------------------------------------------------------------------
  124. int CNPC_GMan::SelectSchedule( void )
  125. {
  126. if ( !BehaviorSelectSchedule() )
  127. {
  128. }
  129. return BaseClass::SelectSchedule();
  130. }
  131. //-----------------------------------------------------------------------------
  132. // AI Schedules Specific to this NPC
  133. //-----------------------------------------------------------------------------