Counter Strike : Global Offensive Source Code
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.

120 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: An NPC's memory of potential enemies
  4. //
  5. //=============================================================================//
  6. #include "mempool.h"
  7. #include "utlmap.h"
  8. #ifndef AI_MEMORY_H
  9. #define AI_MEMORY_H
  10. #pragma once
  11. class CAI_Network;
  12. DECLARE_POINTER_HANDLE(AIEnemiesIter_t);
  13. const float AI_DEF_ENEMY_DISCARD_TIME = 60.0;
  14. #define AI_UNKNOWN_ENEMY (((CBaseEntity *)NULL)+1) // use this to probe for unseen attackers
  15. #define AI_INVALID_TIME (FLT_MAX * -1.0)
  16. //-----------------------------------------------------------------------------
  17. // AI_EnemyInfo_t
  18. //
  19. // Purpose: Stores relevant tactical information about an enemy
  20. //
  21. //-----------------------------------------------------------------------------
  22. struct AI_EnemyInfo_t
  23. {
  24. AI_EnemyInfo_t();
  25. EHANDLE hEnemy; // Pointer to the enemy
  26. Vector vLastKnownLocation;
  27. Vector vLastSeenLocation;
  28. float timeLastSeen; // Last time enemy was seen
  29. float timeFirstSeen; // First time enemy was seen
  30. float timeLastReacquired;
  31. float timeValidEnemy; // First time can be selected (reaction delay)
  32. float timeLastReceivedDamageFrom;
  33. float timeAtFirstHand; // Time at which the enemy was seen firsthand
  34. int nFaction; // The faction the enemy belongs to
  35. bool bDangerMemory; // Memory of danger position w/o Enemy pointer
  36. bool bEludedMe; // True if enemy not at last known location
  37. bool bUnforgettable;
  38. bool bMobbedMe; // True if enemy was part of a mob at some point
  39. DECLARE_SIMPLE_DATADESC();
  40. };
  41. //-----------------------------------------------------------------------------
  42. // CAI_Enemies
  43. //
  44. // Purpose: Stores a set of AI_EnemyInfo_t's
  45. //
  46. //-----------------------------------------------------------------------------
  47. class CAI_Enemies
  48. {
  49. public:
  50. CAI_Enemies(void);
  51. ~CAI_Enemies();
  52. AI_EnemyInfo_t *GetFirst( AIEnemiesIter_t *pIter );
  53. AI_EnemyInfo_t *GetNext( AIEnemiesIter_t *pIter );
  54. AI_EnemyInfo_t *Find( CBaseEntity *pEntity, bool bTryDangerMemory = false );
  55. AI_EnemyInfo_t *GetDangerMemory();
  56. int NumEnemies() const { return m_Map.Count(); }
  57. int GetSerialNumber() const { return m_serial; }
  58. void RefreshMemories(void);
  59. bool UpdateMemory( CAI_Network* pAINet, CBaseEntity *enemy, const Vector &vPosition, float reactionDelay, bool firstHand );
  60. void OnTookDamageFrom( CBaseEntity *pEnemy );
  61. bool HasMemory( CBaseEntity *enemy );
  62. void ClearMemory( CBaseEntity *enemy );
  63. const Vector & LastKnownPosition( CBaseEntity *pEnemy );
  64. const Vector & LastSeenPosition( CBaseEntity *pEnemy );
  65. float TimeLastReacquired( CBaseEntity *pEnemy );
  66. float LastTimeSeen( CBaseEntity *pEnemy, bool bCheckDangerMemory = true );
  67. float FirstTimeSeen( CBaseEntity *pEnemy);
  68. bool HasFreeKnowledgeOf( CBaseEntity *pEnemy );
  69. float LastTimeTookDamageFrom( CBaseEntity *pEnemy);
  70. float TimeAtFirstHand( CBaseEntity *pEnemy );
  71. void MarkAsEluded( CBaseEntity *enemy ); // Don't know where he is (whole squad)
  72. bool HasEludedMe( CBaseEntity *pEnemy );
  73. void SetTimeValidEnemy( CBaseEntity *pEnemy, float flTime );
  74. void SetUnforgettable( CBaseEntity *pEnemy, bool bUnforgettable = true );
  75. void SetMobbedMe( CBaseEntity *pEnemy, bool bMobbedMe = true );
  76. void SetFreeKnowledgeDuration( float flDuration );
  77. void SetEnemyDiscardTime( float flTime );
  78. float GetEnemyDiscardTime( void ) const { return m_flEnemyDiscardTime; }
  79. DECLARE_SIMPLE_DATADESC();
  80. typedef CUtlMap<CBaseEntity *, AI_EnemyInfo_t*, unsigned char> CMemMap;
  81. private:
  82. bool ShouldDiscardMemory( AI_EnemyInfo_t *pMemory );
  83. CMemMap m_Map;
  84. float m_flFreeKnowledgeDuration;
  85. float m_flEnemyDiscardTime;
  86. Vector m_vecDefaultLKP;
  87. Vector m_vecDefaultLSP;
  88. int m_serial;
  89. };
  90. //-----------------------------------------------------------------------------
  91. #endif // AI_MEMORY_H