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.

151 lines
5.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // Author: Michael S. Booth ([email protected]), 2003
  8. #ifndef _GAME_STATE_H_
  9. #define _GAME_STATE_H_
  10. #include "bot_util.h"
  11. class CHostage;
  12. class CCSBot;
  13. /**
  14. * This class represents the game state as known by a particular bot
  15. */
  16. class CSGameState
  17. {
  18. public:
  19. CSGameState( CCSBot *owner );
  20. void Reset( void );
  21. // Event handling
  22. void OnHostageRescuedAll( IGameEvent *event );
  23. void OnRoundEnd( IGameEvent *event );
  24. void OnRoundStart( IGameEvent *event );
  25. void OnBombPlanted( IGameEvent *event );
  26. void OnBombDefused( IGameEvent *event );
  27. void OnBombExploded( IGameEvent *event );
  28. bool IsRoundOver( void ) const; ///< true if round has been won or lost (but not yet reset)
  29. // bomb defuse scenario -----------------------------------------------------------------------------
  30. enum BombState
  31. {
  32. MOVING, ///< being carried by a Terrorist
  33. LOOSE, ///< loose on the ground somewhere
  34. PLANTED, ///< planted and ticking
  35. DEFUSED, ///< the bomb has been defused
  36. EXPLODED ///< the bomb has exploded
  37. };
  38. bool IsBombMoving( void ) const { return (m_bombState == MOVING); }
  39. bool IsBombLoose( void ) const { return (m_bombState == LOOSE); }
  40. bool IsBombPlanted( void ) const { return (m_bombState == PLANTED); }
  41. bool IsBombDefused( void ) const { return (m_bombState == DEFUSED); }
  42. bool IsBombExploded( void ) const { return (m_bombState == EXPLODED); }
  43. void UpdateLooseBomb( const Vector &pos ); ///< we see the loose bomb
  44. float TimeSinceLastSawLooseBomb( void ) const; ///< how long has is been since we saw the loose bomb
  45. bool IsLooseBombLocationKnown( void ) const; ///< do we know where the loose bomb is
  46. void UpdateBomber( const Vector &pos ); ///< we see the bomber
  47. float TimeSinceLastSawBomber( void ) const; ///< how long has is been since we saw the bomber
  48. void UpdatePlantedBomb( const Vector &pos ); ///< we see the planted bomb
  49. bool IsPlantedBombLocationKnown( void ) const; ///< do we know where the bomb was planted
  50. void MarkBombsiteAsPlanted( int zoneIndex ); ///< mark bombsite as the location of the planted bomb
  51. enum { UNKNOWN = -1 };
  52. int GetPlantedBombsite( void ) const; ///< return the zone index of the planted bombsite, or UNKNOWN
  53. bool IsAtPlantedBombsite( void ) const; ///< return true if we are currently in the bombsite where the bomb is planted
  54. int GetNextBombsiteToSearch( void ); ///< return the zone index of the next bombsite to search
  55. bool IsBombsiteClear( int zoneIndex ) const; ///< return true if given bombsite has been cleared
  56. void ClearBombsite( int zoneIndex ); ///< mark bombsite as clear
  57. const Vector *GetBombPosition( void ) const; ///< return where we think the bomb is, or NULL if we don't know
  58. // hostage rescue scenario ------------------------------------------------------------------------
  59. CHostage *GetNearestFreeHostage( Vector *knowPos = NULL ) const; ///< return the closest free hostage, and where we think it is (knowPos)
  60. const Vector *GetRandomFreeHostagePosition( void ) const;
  61. bool AreAllHostagesBeingRescued( void ) const; ///< return true if there are no free hostages
  62. bool AreAllHostagesGone( void ) const; ///< all hostages have been rescued or are dead
  63. void AllHostagesGone( void ); ///< someone told us all the hostages are gone
  64. bool HaveSomeHostagesBeenTaken( void ) const ///< return true if one or more hostages have been moved by the CT's
  65. {
  66. return m_haveSomeHostagesBeenTaken;
  67. }
  68. void HostageWasTaken( void ) ///< someone told us a CT is talking to a hostage
  69. {
  70. m_haveSomeHostagesBeenTaken = true;
  71. }
  72. CHostage *GetNearestVisibleFreeHostage( void ) const;
  73. enum ValidateStatusType
  74. {
  75. NO_CHANGE = 0x00,
  76. HOSTAGE_DIED = 0x01,
  77. HOSTAGE_GONE = 0x02,
  78. HOSTAGES_ALL_GONE = 0x04
  79. };
  80. unsigned char ValidateHostagePositions( void ); ///< update our knowledge with what we currently see - returns bitflag events
  81. private:
  82. CCSBot *m_owner; ///< who owns this gamestate
  83. bool m_isRoundOver; ///< true if round is over, but no yet reset
  84. // bomb defuse scenario ---------------------------------------------------------------------------
  85. void SetBombState( BombState state );
  86. BombState GetBombState( void ) const { return m_bombState; }
  87. BombState m_bombState; ///< what we think the bomb is doing
  88. IntervalTimer m_lastSawBomber;
  89. Vector m_bomberPos;
  90. IntervalTimer m_lastSawLooseBomb;
  91. Vector m_looseBombPos;
  92. bool m_isBombsiteClear[ CCSBotManager::MAX_ZONES ]; ///< corresponds to zone indices in CCSBotManager
  93. int m_bombsiteSearchOrder[ CCSBotManager::MAX_ZONES ]; ///< randomized order of bombsites to search
  94. int m_bombsiteCount;
  95. int m_bombsiteSearchIndex; ///< the next step in the search
  96. int m_plantedBombsite; ///< zone index of the bombsite where the planted bomb is
  97. bool m_isPlantedBombPosKnown; ///< if true, we know the exact location of the bomb
  98. Vector m_plantedBombPos;
  99. // hostage rescue scenario ------------------------------------------------------------------------
  100. struct HostageInfo
  101. {
  102. CHandle<CHostage> hostage;
  103. Vector knownPos;
  104. bool isValid;
  105. bool isAlive;
  106. bool isFree; ///< not being escorted by a CT
  107. }
  108. m_hostage[ MAX_HOSTAGES ];
  109. int m_hostageCount; ///< number of hostages left in map
  110. CountdownTimer m_validateInterval;
  111. CBaseEntity *GetNearestHostage( void ) const; ///< return the closest live hostage
  112. void InitializeHostageInfo( void ); ///< initialize our knowledge of the number and location of hostages
  113. bool m_allHostagesRescued;
  114. bool m_haveSomeHostagesBeenTaken; ///< true if a hostage has been moved by a CT (and we've seen it)
  115. };
  116. #endif // _GAME_STATE_