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.

119 lines
3.8 KiB

  1. //========= Copyright 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. bool bDangerMemory; // Memory of danger position w/o Enemy pointer
  35. bool bEludedMe; // True if enemy not at last known location
  36. bool bUnforgettable;
  37. bool bMobbedMe; // True if enemy was part of a mob at some point
  38. DECLARE_SIMPLE_DATADESC();
  39. };
  40. //-----------------------------------------------------------------------------
  41. // CAI_Enemies
  42. //
  43. // Purpose: Stores a set of AI_EnemyInfo_t's
  44. //
  45. //-----------------------------------------------------------------------------
  46. class CAI_Enemies
  47. {
  48. public:
  49. CAI_Enemies(void);
  50. ~CAI_Enemies();
  51. AI_EnemyInfo_t *GetFirst( AIEnemiesIter_t *pIter );
  52. AI_EnemyInfo_t *GetNext( AIEnemiesIter_t *pIter );
  53. AI_EnemyInfo_t *Find( CBaseEntity *pEntity, bool bTryDangerMemory = false );
  54. AI_EnemyInfo_t *GetDangerMemory();
  55. int NumEnemies() const { return m_Map.Count(); }
  56. int GetSerialNumber() const { return m_serial; }
  57. void RefreshMemories(void);
  58. bool UpdateMemory( CAI_Network* pAINet, CBaseEntity *enemy, const Vector &vPosition, float reactionDelay, bool firstHand );
  59. void OnTookDamageFrom( CBaseEntity *pEnemy );
  60. bool HasMemory( CBaseEntity *enemy );
  61. void ClearMemory( CBaseEntity *enemy );
  62. const Vector & LastKnownPosition( CBaseEntity *pEnemy );
  63. const Vector & LastSeenPosition( CBaseEntity *pEnemy );
  64. float TimeLastReacquired( CBaseEntity *pEnemy );
  65. float LastTimeSeen( CBaseEntity *pEnemy, bool bCheckDangerMemory = true );
  66. float FirstTimeSeen( CBaseEntity *pEnemy);
  67. bool HasFreeKnowledgeOf( CBaseEntity *pEnemy );
  68. float LastTimeTookDamageFrom( CBaseEntity *pEnemy);
  69. float TimeAtFirstHand( CBaseEntity *pEnemy );
  70. void MarkAsEluded( CBaseEntity *enemy ); // Don't know where he is (whole squad)
  71. bool HasEludedMe( CBaseEntity *pEnemy );
  72. void SetTimeValidEnemy( CBaseEntity *pEnemy, float flTime );
  73. void SetUnforgettable( CBaseEntity *pEnemy, bool bUnforgettable = true );
  74. void SetMobbedMe( CBaseEntity *pEnemy, bool bMobbedMe = true );
  75. void SetFreeKnowledgeDuration( float flDuration );
  76. void SetEnemyDiscardTime( float flTime );
  77. float GetEnemyDiscardTime( void ) const { return m_flEnemyDiscardTime; }
  78. DECLARE_SIMPLE_DATADESC();
  79. typedef CUtlMap<CBaseEntity *, AI_EnemyInfo_t*, unsigned char> CMemMap;
  80. private:
  81. bool ShouldDiscardMemory( AI_EnemyInfo_t *pMemory );
  82. CMemMap m_Map;
  83. float m_flFreeKnowledgeDuration;
  84. float m_flEnemyDiscardTime;
  85. Vector m_vecDefaultLKP;
  86. Vector m_vecDefaultLSP;
  87. int m_serial;
  88. };
  89. //-----------------------------------------------------------------------------
  90. #endif // AI_MEMORY_H