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.

234 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef TEAM_TRAIN_WATCHER_H
  7. #define TEAM_TRAIN_WATCHER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cbase.h"
  12. #include "trigger_area_capture.h"
  13. #include "shareddefs.h"
  14. #include "envspark.h"
  15. #include "GameEventListener.h"
  16. class CFuncTrackTrain;
  17. class CPathTrack;
  18. class CTeamControlPoint;
  19. #define TEAM_TRAIN_ALERT_DISTANCE 750 // alert is the VO warning
  20. #define TEAM_TRAIN_ALARM_DISTANCE 200 // alarm is the looping sound played at the control point
  21. #define TEAM_TRAIN_ALERT "Announcer.Cart.Warning"
  22. #define TEAM_TRAIN_FINAL_ALERT "Announcer.Cart.FinalWarning"
  23. #define TEAM_TRAIN_ALARM "Cart.Warning"
  24. #define TEAM_TRAIN_ALARM_SINGLE "Cart.WarningSingle"
  25. #define TW_THINK "CTeamTrainWatcherThink"
  26. #define TW_ALARM_THINK "CTeamTrainWatcherAlarmThink"
  27. #define TW_ALARM_THINK_INTERVAL 8.0
  28. // #define TWMASTER_THINK "CTeamTrainWatcherMasterThink"
  29. DECLARE_AUTO_LIST( ITFTeamTrainWatcher );
  30. class CTeamTrainWatcher : public CBaseEntity, public CGameEventListener, public ITFTeamTrainWatcher
  31. {
  32. DECLARE_CLASS( CTeamTrainWatcher, CBaseEntity );
  33. public:
  34. DECLARE_SERVERCLASS();
  35. DECLARE_DATADESC();
  36. CTeamTrainWatcher();
  37. ~CTeamTrainWatcher();
  38. virtual void UpdateOnRemove( void );
  39. virtual int UpdateTransmitState();
  40. void InputRoundActivate( inputdata_t &inputdata );
  41. void InputEnable( inputdata_t &inputdata );
  42. void InputDisable( inputdata_t &inputdata );
  43. void InputSetNumTrainCappers( inputdata_t &inputdata );
  44. void InputOnStartOvertime( inputdata_t &inputdata );
  45. void InputSetSpeedForwardModifier( inputdata_t &inputdata );
  46. void InputSetTrainRecedeTime( inputdata_t &inputdata );
  47. void InputSetTrainCanRecede( inputdata_t &inputdata );
  48. void InputSetTrainRecedeTimeAndUpdate( inputdata_t &inputdata );
  49. // ==========================================================
  50. // given a start node and a list of goal nodes
  51. // calculate the distance between each
  52. // ==========================================================
  53. void WatcherActivate( void );
  54. void WatcherThink( void );
  55. void WatcherAlarmThink( void );
  56. CBaseEntity *GetTrainEntity( void );
  57. bool IsDisabled( void ) { return m_bDisabled; }
  58. bool TimerMayExpire( void );
  59. void StopCaptureAlarm( void );
  60. void SetNumTrainCappers( int iNumCappers, CBaseEntity *pTrigger ); // only used for train watchers that control the train movement
  61. virtual void FireGameEvent( IGameEvent * event );
  62. int GetCapturerCount( void ) const; // return the number of players who are "capturing" the payload, or -1 if the payload is blocked
  63. void ProjectPointOntoPath( const Vector &pos, Vector *posOnPath, float *distanceAlongPath ) const; // project the given position onto the track and return the point and how far along that projected position is
  64. bool IsAheadOfTrain( const Vector &pos ) const; // return true if the given position is farther down the track than the train is
  65. bool IsTrainAtStart( void ) const; // return true if the train hasn't left its starting position yet
  66. bool IsTrainNearCheckpoint( void ) const; // return true if the train is almost at the next checkpoint
  67. float GetTrainDistanceAlongTrack( void ) const;
  68. Vector GetNextCheckpointPosition( void ) const; // return world space location of next checkpoint along the path
  69. #if defined( STAGING_ONLY ) && defined( TF_DLL )
  70. void DumpStats( void );
  71. #endif // STAGING_ONLY && TF_DLL
  72. float GetTrainProgress() { return m_flTotalProgress; }
  73. private:
  74. void StartCaptureAlarm( CTeamControlPoint *pPoint );
  75. void PlayCaptureAlert( CTeamControlPoint *pPoint, bool bFinalPointInMap );
  76. void InternalSetNumTrainCappers( int iNumCappers, CBaseEntity *pTrigger );
  77. void InternalSetSpeedForwardModifier( float flModifier );
  78. #ifdef GLOWS_ENABLE
  79. void FindGlowEntity( void );
  80. #endif // GLOWS_ENABLE
  81. void HandleTrainMovement( bool bStartReceding = false );
  82. void HandleSparks( bool bSparks );
  83. private:
  84. bool m_bDisabled;
  85. bool m_bTrainCanRecede;
  86. // === Data ===
  87. // pointer to the train that we're checking
  88. CHandle<CFuncTrackTrain> m_hTrain;
  89. // start node
  90. CHandle<CPathTrack> m_hStartNode;
  91. // goal node
  92. CHandle<CPathTrack> m_hGoalNode;
  93. string_t m_iszTrain;
  94. string_t m_iszStartNode;
  95. string_t m_iszGoalNode;
  96. // list of node associations with control points
  97. typedef struct
  98. {
  99. CHandle<CPathTrack> hPathTrack;
  100. CHandle<CTeamControlPoint> hCP;
  101. float flDistanceFromStart;
  102. bool bAlertPlayed;
  103. } node_cp_pair_t;
  104. node_cp_pair_t m_CPLinks[MAX_CONTROL_POINTS];
  105. int m_iNumCPLinks;
  106. string_t m_iszLinkedPathTracks[MAX_CONTROL_POINTS];
  107. string_t m_iszLinkedCPs[MAX_CONTROL_POINTS];
  108. float m_flTotalPathDistance; // calculated only at round start, node graph
  109. // may get chopped as the round progresses
  110. float m_flTrainDistanceAccumulator;
  111. float m_flTrainDistanceFromStart; // actual distance along path of train, for comparing against m_CPLinks[].flDistanceFromStart
  112. float m_flSpeedLevels[3];
  113. // === Networked Data ===
  114. // current total progress, percentage
  115. CNetworkVar( float, m_flTotalProgress );
  116. CNetworkVar( int, m_iTrainSpeedLevel );
  117. CNetworkVar( int, m_nNumCappers );
  118. bool m_bWaitingToRecede;
  119. CNetworkVar( float, m_flRecedeTime );
  120. float m_flRecedeTotalTime;
  121. float m_flRecedeStartTime;
  122. COutputEvent m_OnTrainStartRecede;
  123. bool m_bCapBlocked;
  124. float m_flNextSpeakForwardConceptTime; // used to have players speak the forward concept every X seconds
  125. CHandle<CTriggerAreaCapture> m_hAreaCap;
  126. CSoundPatch *m_pAlarm;
  127. float m_flAlarmEndTime;
  128. bool m_bAlarmPlayed;
  129. // added for new mode where the train_watcher handles the train movement
  130. bool m_bHandleTrainMovement;
  131. string_t m_iszSparkName;
  132. CUtlVector< CHandle<CEnvSpark> > m_Sparks;
  133. float m_flSpeedForwardModifier;
  134. int m_iCurrentHillType;
  135. float m_flCurrentSpeed;
  136. bool m_bReceding;
  137. int m_nTrainRecedeTime;
  138. #ifdef GLOWS_ENABLE
  139. CNetworkVar( EHANDLE, m_hGlowEnt );
  140. #endif // GLOWS_ENABLE
  141. };
  142. inline float CTeamTrainWatcher::GetTrainDistanceAlongTrack( void ) const
  143. {
  144. return m_flTrainDistanceFromStart;
  145. }
  146. inline int CTeamTrainWatcher::GetCapturerCount( void ) const
  147. {
  148. return m_nNumCappers;
  149. }
  150. /*
  151. class CTeamTrainWatcherMaster : public CBaseEntity, public CGameEventListener
  152. {
  153. DECLARE_CLASS( CTeamTrainWatcherMaster, CBaseEntity );
  154. public:
  155. CTeamTrainWatcherMaster();
  156. ~CTeamTrainWatcherMaster();
  157. void Precache( void );
  158. private:
  159. void TWMThink( void );
  160. void FireGameEvent( IGameEvent *event );
  161. bool FindTrainWatchers( void );
  162. private:
  163. CTeamTrainWatcher *m_pBlueWatcher;
  164. CTeamTrainWatcher *m_pRedWatcher;
  165. float m_flBlueProgress;
  166. float m_flRedProgress;
  167. };
  168. extern EHANDLE g_hTeamTrainWatcherMaster;
  169. */
  170. #endif //TEAM_TRAIN_WATCHER_H