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.

190 lines
5.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TRIGGER_AREA_CAPTURE_H
  7. #define TRIGGER_AREA_CAPTURE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "basemultiplayerplayer.h"
  12. #include "triggers.h"
  13. #include "team_control_point.h"
  14. class CTeamTrainWatcher;
  15. #define AREA_ATTEND_TIME 0.7f
  16. #define AREA_THINK_TIME 0.1f
  17. #define CAPTURE_NORMAL 0
  18. #define CAPTURE_CATCHUP_ALIVEPLAYERS 1
  19. #define MAX_CLIENT_AREAS 128
  20. #define MAX_AREA_CAPPERS 9
  21. //-----------------------------------------------------------------------------
  22. // Purpose: An area entity that players must remain in in order to active another entity
  23. // Triggers are fired on start of capture, on end of capture and on broken capture
  24. // Can either be capped by both teams at once, or just by one
  25. // Time to capture and number of people required to capture are both passed by the mapper
  26. //-----------------------------------------------------------------------------
  27. // This class is to get around the fact that DEFINE_FUNCTION doesn't like multiple inheritance
  28. class CTriggerAreaCaptureShim : public CBaseTrigger
  29. {
  30. virtual void AreaTouch( CBaseEntity *pOther ) = 0;
  31. public:
  32. void Touch( CBaseEntity *pOther ) { return AreaTouch( pOther ) ; }
  33. };
  34. DECLARE_AUTO_LIST( ITriggerAreaCaptureAutoList );
  35. class CTriggerAreaCapture : public CTriggerAreaCaptureShim, public ITriggerAreaCaptureAutoList
  36. {
  37. DECLARE_CLASS( CTriggerAreaCapture, CTriggerAreaCaptureShim );
  38. public:
  39. CTriggerAreaCapture();
  40. // Derived, game-specific area triggers must override these functions
  41. public:
  42. // Display a hint about capturing zones to the player
  43. virtual void DisplayCapHintTo( CBaseMultiplayerPlayer *pPlayer ) { return; }
  44. // A team has finished capturing the zone.
  45. virtual void OnEndCapture( int iTeam ) { return; }
  46. virtual void OnStartCapture( int iTeam ) { return; }
  47. public:
  48. virtual void Spawn( void );
  49. virtual void Precache( void );
  50. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  51. bool IsActive( void );
  52. bool CheckIfDeathCausesBlock( CBaseMultiplayerPlayer *pVictim, CBaseMultiplayerPlayer *pKiller );
  53. void UpdateNumPlayers( bool bBlocked = false );
  54. void UpdateOwningTeam( void );
  55. void UpdateCappingTeam( int iTeam );
  56. void UpdateTeamInZone( void );
  57. void UpdateBlocked( void );
  58. void ForceOwner( int team ); // by the control_point_round to force an owner of this point (so we can play a specific round)
  59. bool TeamCanCap( int iTeam ){ return m_TeamData[iTeam].bCanCap; }
  60. CHandle<CTeamControlPoint> GetControlPoint( void ){ return m_hPoint; }
  61. int GetOwningTeam( void ) { return m_nOwningTeam; }
  62. bool IsBlocked( void ) { return m_bBlocked; }
  63. void SetTrainWatcher( CTeamTrainWatcher *pTrainWatcher ){ m_hTrainWatcher = pTrainWatcher; } // used for train watchers that control train movement
  64. CTeamTrainWatcher *GetTrainWatcher( void ) const { return m_hTrainWatcher; }
  65. virtual void StartTouch(CBaseEntity *pOther) OVERRIDE;
  66. virtual void EndTouch(CBaseEntity *pOther) OVERRIDE;
  67. float GetCapTime() const { return m_flCapTime; }
  68. protected:
  69. virtual bool CaptureModeScalesWithPlayers() const;
  70. private:
  71. virtual void AreaTouch( CBaseEntity *pOther ) OVERRIDE;
  72. void CaptureThink( void );
  73. void StartCapture( int team, int capmode );
  74. void EndCapture( int team );
  75. void BreakCapture( bool bNotEnoughPlayers );
  76. void IncrementCapAttemptNumber( void );
  77. void SwitchCapture( int team );
  78. void SendNumPlayers( void );
  79. void SetOwner( int team ); //sets the owner of this point - useful for resetting all to -1
  80. void InputRoundSpawn( inputdata_t &inputdata );
  81. void InputCaptureCurrentCP( inputdata_t &inputdata );
  82. void InputSetTeamCanCap( inputdata_t &inputdata );
  83. void InputSetControlPoint( inputdata_t &inputdata );
  84. void SetCapTimeRemaining( float flTime );
  85. void HandleRespawnTimeAdjustments( int oldTeam, int newTeam );
  86. void GetNumCappingPlayers( int team, int &numcappers, int *cappingplayers );
  87. void SetNumCappers( int nNumCappers, bool bBlocked = false );
  88. private:
  89. int m_iCapMode; //which capture mode we're in
  90. bool m_bCapturing;
  91. int m_nCapturingTeam; //the team that is capturing this point
  92. int m_nOwningTeam; //the team that has captured this point
  93. int m_nTeamInZone; //if there's one team in the zone, this is it.
  94. float m_flCapTime; //the total time it takes to capture the area, in seconds
  95. float m_fTimeRemaining; //the time left in the capture
  96. float m_flLastReductionTime;
  97. bool m_bBlocked;
  98. struct perteamdata_t
  99. {
  100. perteamdata_t()
  101. {
  102. iNumRequiredToCap = 0;
  103. iNumTouching = 0;
  104. iBlockedTouching = 0;
  105. bCanCap = false;
  106. iSpawnAdjust = 0;
  107. iNumRequiredToStartCap = 0;
  108. }
  109. int iNumRequiredToCap;
  110. int iNumTouching;
  111. int iBlockedTouching; // Number of capping players on the cap while it's being blocked
  112. bool bCanCap;
  113. int iSpawnAdjust;
  114. int iNumRequiredToStartCap;
  115. };
  116. CUtlVector<perteamdata_t> m_TeamData;
  117. struct blockers_t
  118. {
  119. CHandle<CBaseMultiplayerPlayer> hPlayer;
  120. int iCapAttemptNumber;
  121. float flNextBlockTime;
  122. };
  123. CUtlVector<blockers_t> m_Blockers;
  124. bool m_bActive;
  125. COutputEvent m_OnStartTeam1;
  126. COutputEvent m_OnStartTeam2;
  127. COutputEvent m_OnBreakTeam1;
  128. COutputEvent m_OnBreakTeam2;
  129. COutputEvent m_OnCapTeam1;
  130. COutputEvent m_OnCapTeam2;
  131. COutputEvent m_StartOutput;
  132. COutputEvent m_BreakOutput;
  133. COutputEvent m_CapOutput;
  134. COutputInt m_OnNumCappersChanged;
  135. COutputInt m_OnNumCappersChanged2;
  136. CHandle<CTeamControlPoint> m_hPoint; //the capture point that we are linked to!
  137. bool m_bRequiresObject;
  138. string_t m_iszCapPointName; //name of the cap point that we're linked to
  139. int m_iCapAttemptNumber; // number used to keep track of discrete cap attempts, for block tracking
  140. bool m_bStartTouch;
  141. CHandle<CTeamTrainWatcher> m_hTrainWatcher; // used for train watchers that control train movement
  142. DECLARE_DATADESC();
  143. };
  144. #endif // TRIGGER_AREA_CAPTURE_H