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.

184 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef MONSTERMAKER_H
  7. #define MONSTERMAKER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cbase.h"
  12. //-----------------------------------------------------------------------------
  13. // Spawnflags
  14. //-----------------------------------------------------------------------------
  15. #define SF_NPCMAKER_START_ON 1 // start active ( if has targetname )
  16. #define SF_NPCMAKER_NPCCLIP 8 // Children are blocked by NPCclip
  17. #define SF_NPCMAKER_FADE 16 // Children's corpses fade
  18. #define SF_NPCMAKER_INF_CHILD 32 // Infinite number of children
  19. #define SF_NPCMAKER_NO_DROP 64 // Do not adjust for the ground's position when checking for spawn
  20. #define SF_NPCMAKER_HIDEFROMPLAYER 128 // Don't spawn if the player's looking at me
  21. #define SF_NPCMAKER_ALWAYSUSERADIUS 256 // Use radius spawn whenever spawning
  22. #define SF_NPCMAKER_NOPRELOADMODELS 512 // Suppress preloading into the cache of all referenced .mdl files
  23. //=========================================================
  24. //=========================================================
  25. class CNPCSpawnDestination : public CPointEntity
  26. {
  27. DECLARE_CLASS( CNPCSpawnDestination, CPointEntity );
  28. public:
  29. CNPCSpawnDestination();
  30. bool IsAvailable(); // Is this spawn destination available for selection?
  31. void OnSpawnedNPC( CAI_BaseNPC *pNPC ); // Notify this spawn destination that an NPC has spawned here.
  32. float m_ReuseDelay; // How long to be unavailable after being selected
  33. string_t m_RenameNPC; // If not NULL, rename the NPC that spawns here to this.
  34. float m_TimeNextAvailable;// The time at which this destination will be available again.
  35. COutputEvent m_OnSpawnNPC;
  36. DECLARE_DATADESC();
  37. };
  38. abstract_class CBaseNPCMaker : public CBaseEntity
  39. {
  40. public:
  41. DECLARE_CLASS( CBaseNPCMaker, CBaseEntity );
  42. void Spawn( void );
  43. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
  44. void MakerThink( void );
  45. bool HumanHullFits( const Vector &vecLocation );
  46. bool CanMakeNPC( bool bIgnoreSolidEntities = false );
  47. virtual void DeathNotice( CBaseEntity *pChild );// NPC maker children use this to tell the NPC maker that they have died.
  48. virtual void MakeNPC( void ) = 0;
  49. virtual void ChildPreSpawn( CAI_BaseNPC *pChild ) {};
  50. virtual void ChildPostSpawn( CAI_BaseNPC *pChild );
  51. CBaseNPCMaker(void) {}
  52. // Input handlers
  53. void InputSpawnNPC( inputdata_t &inputdata );
  54. void InputEnable( inputdata_t &inputdata );
  55. void InputDisable( inputdata_t &inputdata );
  56. void InputToggle( inputdata_t &inputdata );
  57. void InputSetMaxChildren( inputdata_t &inputdata );
  58. void InputAddMaxChildren( inputdata_t &inputdata );
  59. void InputSetMaxLiveChildren( inputdata_t &inputdata );
  60. void InputSetSpawnFrequency( inputdata_t &inputdata );
  61. // State changers
  62. void Toggle( void );
  63. virtual void Enable( void );
  64. virtual void Disable( void );
  65. virtual bool IsDepleted( void );
  66. DECLARE_DATADESC();
  67. int m_nMaxNumNPCs; // max number of NPCs this ent can create
  68. float m_flSpawnFrequency; // delay (in secs) between spawns
  69. COutputEHANDLE m_OnSpawnNPC;
  70. COutputEvent m_OnAllSpawned;
  71. COutputEvent m_OnAllSpawnedDead;
  72. COutputEvent m_OnAllLiveChildrenDead;
  73. int m_nLiveChildren; // how many NPCs made by this NPC maker that are currently alive
  74. int m_nMaxLiveChildren; // max number of NPCs that this maker may have out at one time.
  75. bool m_bDisabled;
  76. EHANDLE m_hIgnoreEntity;
  77. string_t m_iszIngoreEnt;
  78. };
  79. class CNPCMaker : public CBaseNPCMaker
  80. {
  81. public:
  82. DECLARE_CLASS( CNPCMaker, CBaseNPCMaker );
  83. CNPCMaker( void );
  84. void Precache( void );
  85. virtual void MakeNPC( void );
  86. DECLARE_DATADESC();
  87. string_t m_iszNPCClassname; // classname of the NPC(s) that will be created.
  88. string_t m_SquadName;
  89. string_t m_strHintGroup;
  90. string_t m_spawnEquipment;
  91. string_t m_RelationshipString; // Used to load up relationship keyvalues
  92. string_t m_ChildTargetName;
  93. };
  94. class CTemplateNPCMaker : public CBaseNPCMaker
  95. {
  96. public:
  97. DECLARE_CLASS( CTemplateNPCMaker, CBaseNPCMaker );
  98. CTemplateNPCMaker( void )
  99. {
  100. m_iMinSpawnDistance = 0;
  101. }
  102. virtual void Precache();
  103. virtual CNPCSpawnDestination *FindSpawnDestination();
  104. virtual void MakeNPC( void );
  105. void MakeNPCInRadius( void );
  106. void MakeNPCInLine( void );
  107. virtual void MakeMultipleNPCS( int nNPCs );
  108. protected:
  109. virtual void PrecacheTemplateEntity( CBaseEntity *pEntity );
  110. bool PlaceNPCInRadius( CAI_BaseNPC *pNPC );
  111. bool PlaceNPCInLine( CAI_BaseNPC *pNPC );
  112. // Inputs
  113. void InputSpawnInRadius( inputdata_t &inputdata ) { MakeNPCInRadius(); }
  114. void InputSpawnInLine( inputdata_t &inputdata ) { MakeNPCInLine(); }
  115. void InputSpawnMultiple( inputdata_t &inputdata );
  116. void InputChangeDestinationGroup( inputdata_t &inputdata );
  117. void InputSetMinimumSpawnDistance( inputdata_t &inputdata );
  118. float m_flRadius;
  119. DECLARE_DATADESC();
  120. string_t m_iszTemplateName; // The name of the NPC that will be used as the template.
  121. string_t m_iszTemplateData; // The keyvalue data blob from the template NPC that will be used to spawn new ones.
  122. string_t m_iszDestinationGroup;
  123. int m_iMinSpawnDistance;
  124. enum ThreeStateYesNo_t
  125. {
  126. TS_YN_YES = 0,
  127. TS_YN_NO,
  128. TS_YN_DONT_CARE,
  129. };
  130. enum ThreeStateDist_t
  131. {
  132. TS_DIST_NEAREST = 0,
  133. TS_DIST_FARTHEST,
  134. TS_DIST_DONT_CARE,
  135. };
  136. ThreeStateYesNo_t m_CriterionVisibility;
  137. ThreeStateDist_t m_CriterionDistance;
  138. };
  139. #endif // MONSTERMAKER_H