Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7.  
  8. #ifndef AI_SENSES_H
  9. #define AI_SENSES_H
  10.  
  11. #include "tier1/utlvector.h"
  12. #include "tier1/utlmap.h"
  13. #include "simtimer.h"
  14. #include "ai_component.h"
  15. #include "soundent.h"
  16.  
  17. #if defined( _WIN32 )
  18. #pragma once
  19. #endif
  20.  
  21. class CBaseEntity;
  22. class CSound;
  23.  
  24. //-------------------------------------
  25.  
  26. DECLARE_POINTER_HANDLE( AISightIter_t );
  27. DECLARE_POINTER_HANDLE( AISoundIter_t );
  28.  
  29. // GetFirstSeenEntity can take these as optional parameters to search for
  30. // a specific type of entity.
  31. enum seentype_t
  32. {
  33. SEEN_ALL = -1, // Default
  34. SEEN_HIGH_PRIORITY = 0,
  35. SEEN_NPCS,
  36. SEEN_MISC
  37. };
  38.  
  39. #define SENSING_FLAGS_NONE 0x00000000
  40. #define SENSING_FLAGS_DONT_LOOK 0x00000001 // Effectively makes the NPC blind
  41. #define SENSING_FLAGS_DONT_LISTEN 0x00000002 // Effectively makes the NPC deaf
  42.  
  43. //-----------------------------------------------------------------------------
  44. // class CAI_ScriptConditions
  45. //
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48.  
  49. class CAI_Senses : public CAI_Component
  50. {
  51. public:
  52. CAI_Senses()
  53. : m_LookDist(2048),
  54. m_LastLookDist(-1),
  55. m_TimeLastLook(-1),
  56. m_iAudibleList(0),
  57. m_TimeLastLookHighPriority( -1 ),
  58. m_TimeLastLookNPCs( -1 ),
  59. m_TimeLastLookMisc( -1 )
  60. {
  61. m_SeenArrays[0] = &m_SeenHighPriority;
  62. m_SeenArrays[1] = &m_SeenNPCs;
  63. m_SeenArrays[2] = &m_SeenMisc;
  64. m_iSensingFlags = SENSING_FLAGS_NONE;
  65. }
  66.  
  67. float GetDistLook() const { return m_LookDist; }
  68. void SetDistLook( float flDistLook ) { m_LookDist = flDistLook; }
  69.  
  70. void PerformSensing();
  71.  
  72. void Listen( void );
  73. void Look( int iDistance );// basic sight function for npcs
  74.  
  75. bool ShouldSeeEntity( CBaseEntity *pEntity ); // logical query
  76. bool CanSeeEntity( CBaseEntity *pSightEnt ); // more expensive cone & raycast test
  77. #ifdef PORTAL
  78. bool CanSeeEntityThroughPortal( const CProp_Portal *pPortal, CBaseEntity *pSightEnt ); // more expensive cone & raycast test
  79. #endif
  80.  
  81. bool DidSeeEntity( CBaseEntity *pSightEnt ) const; // a less expensive query that looks at cached results from recent conditionsa gathering
  82.  
  83. CBaseEntity * GetFirstSeenEntity( AISightIter_t *pIter, seentype_t iSeenType = SEEN_ALL ) const;
  84. CBaseEntity * GetNextSeenEntity( AISightIter_t *pIter ) const;
  85.  
  86. CSound * GetFirstHeardSound( AISoundIter_t *pIter );
  87. CSound * GetNextHeardSound( AISoundIter_t *pIter );
  88. CSound * GetClosestSound( bool fScent = false, int validTypes = ALL_SOUNDS | ALL_SCENTS, bool bUsePriority = true );
  89.  
  90. bool CanHearSound( CSound *pSound );
  91.  
  92. //---------------------------------
  93.  
  94. float GetTimeLastUpdate( CBaseEntity *pEntity );
  95.  
  96. //---------------------------------
  97.  
  98. void AddSensingFlags( int iFlags ) { m_iSensingFlags |= iFlags; }
  99. void RemoveSensingFlags( int iFlags ) { m_iSensingFlags &= ~iFlags; }
  100. bool HasSensingFlags( int iFlags ) { return (m_iSensingFlags & iFlags) == iFlags; }
  101.  
  102. DECLARE_SIMPLE_DATADESC();
  103.  
  104. private:
  105. int GetAudibleList() const { return m_iAudibleList; }
  106.  
  107. bool WaitingUntilSeen( CBaseEntity *pSightEnt );
  108.  
  109. void BeginGather();
  110. void NoteSeenEntity( CBaseEntity *pSightEnt );
  111. void EndGather( int nSeen, CUtlVector<EHANDLE> *pResult );
  112.  
  113. bool Look( CBaseEntity *pSightEnt );
  114. #ifdef PORTAL
  115. bool LookThroughPortal( const CProp_Portal *pPortal, CBaseEntity *pSightEnt );
  116. #endif
  117.  
  118. int LookForHighPriorityEntities( int iDistance );
  119. int LookForNPCs( int iDistance );
  120. int LookForObjects( int iDistance );
  121.  
  122. bool SeeEntity( CBaseEntity *pEntity );
  123.  
  124. float m_LookDist; // distance npc sees (Default 2048)
  125. float m_LastLookDist;
  126. float m_TimeLastLook;
  127.  
  128. int m_iAudibleList; // first index of a linked list of sounds that the npc can hear.
  129.  
  130. CUtlVector<EHANDLE> m_SeenHighPriority;
  131. CUtlVector<EHANDLE> m_SeenNPCs;
  132. CUtlVector<EHANDLE> m_SeenMisc;
  133.  
  134. CUtlVector<EHANDLE> *m_SeenArrays[3];
  135.  
  136. float m_TimeLastLookHighPriority;
  137. float m_TimeLastLookNPCs;
  138. float m_TimeLastLookMisc;
  139.  
  140. int m_iSensingFlags;
  141. };
  142.  
  143. //-----------------------------------------------------------------------------
  144.  
  145. class CAI_SensedObjectsManager : public IEntityListener
  146. {
  147. public:
  148. void Init();
  149. void Term();
  150.  
  151. CBaseEntity * GetFirst( int *pIter );
  152. CBaseEntity * GetNext( int *pIter );
  153.  
  154. virtual void AddEntity( CBaseEntity *pEntity );
  155.  
  156. private:
  157. virtual void OnEntitySpawned( CBaseEntity *pEntity );
  158. virtual void OnEntityDeleted( CBaseEntity *pEntity );
  159.  
  160. CUtlVector<EHANDLE> m_SensedObjects;
  161. };
  162.  
  163. extern CAI_SensedObjectsManager g_AI_SensedObjectsManager;
  164.  
  165. //-----------------------------------------------------------------------------
  166.  
  167.  
  168.  
  169. #endif // AI_SENSES_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement