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.

453 lines
14 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: CTF Flag.
  4. //
  5. //=============================================================================//
  6. #ifndef ENTITY_CAPTURE_FLAG_H
  7. #define ENTITY_CAPTURE_FLAG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_item.h"
  12. #include "tf_shareddefs.h"
  13. #ifdef CLIENT_DLL
  14. #define CCaptureFlag C_CaptureFlag
  15. #else
  16. class CTFBot;
  17. #endif
  18. #define TF_FLAG_THINK_TIME 0.25f
  19. #define TF_FLAG_OWNER_PICKUP_TIME 3.0f
  20. #define TF_FLAG_TRAIL_ALPHA 96
  21. #define TF_FLAG_NUMBEROFSKINS 3
  22. #define TF_FLAG_MODEL "models/flag/briefcase.mdl"
  23. #define TF_FLAG_ICON "../hud/objectives_flagpanel_carried"
  24. #define TF_FLAG_EFFECT "player_intel_papertrail"
  25. #define TF_FLAG_TRAIL "flagtrail"
  26. //=============================================================================
  27. //
  28. // CTF Flag defines.
  29. //
  30. #define TF_CTF_ENEMY_STOLEN "CaptureFlag.EnemyStolen"
  31. #define TF_CTF_ENEMY_DROPPED "CaptureFlag.EnemyDropped"
  32. #define TF_CTF_ENEMY_CAPTURED "CaptureFlag.EnemyCaptured"
  33. #define TF_CTF_ENEMY_RETURNED "CaptureFlag.EnemyReturned"
  34. #define TF_CTF_TEAM_STOLEN "CaptureFlag.TeamStolen"
  35. #define TF_CTF_TEAM_DROPPED "CaptureFlag.TeamDropped"
  36. #define TF_CTF_TEAM_CAPTURED "CaptureFlag.TeamCaptured"
  37. #define TF_CTF_TEAM_RETURNED "CaptureFlag.TeamReturned"
  38. #define TF_CTF_FLAGSPAWN "CaptureFlag.FlagSpawn"
  39. #define TF_CTF_CAPTURED_TEAM_SCORE 1
  40. //=============================================================================
  41. //
  42. // Attack/Defend Flag defines.
  43. //
  44. #define TF_AD_ENEMY_STOLEN "AttackDefend.EnemyStolen"
  45. #define TF_AD_ENEMY_DROPPED "AttackDefend.EnemyDropped"
  46. #define TF_AD_ENEMY_CAPTURED "AttackDefend.EnemyCaptured"
  47. #define TF_AD_ENEMY_RETURNED "AttackDefend.EnemyReturned"
  48. #define TF_MVM_AD_ENEMY_STOLEN "MVM.AttackDefend.EnemyStolen"
  49. #define TF_MVM_AD_ENEMY_DROPPED "MVM.AttackDefend.EnemyDropped"
  50. #define TF_MVM_AD_ENEMY_CAPTURED "MVM.AttackDefend.EnemyCaptured"
  51. #define TF_MVM_AD_ENEMY_RETURNED "MVM.AttackDefend.EnemyReturned"
  52. #define TF_AD_TEAM_STOLEN "AttackDefend.TeamStolen"
  53. #define TF_AD_TEAM_DROPPED "AttackDefend.TeamDropped"
  54. #define TF_AD_TEAM_CAPTURED "AttackDefend.TeamCaptured"
  55. #define TF_AD_TEAM_RETURNED "AttackDefend.TeamReturned"
  56. #define TF_AD_CAPTURED_SOUND "AttackDefend.Captured"
  57. //=============================================================================
  58. //
  59. // Invade Flag defines.
  60. //
  61. #define TF_INVADE_ENEMY_STOLEN "Invade.EnemyStolen"
  62. #define TF_INVADE_ENEMY_DROPPED "Invade.EnemyDropped"
  63. #define TF_INVADE_ENEMY_CAPTURED "Invade.EnemyCaptured"
  64. #define TF_INVADE_TEAM_STOLEN "Invade.TeamStolen"
  65. #define TF_INVADE_TEAM_DROPPED "Invade.TeamDropped"
  66. #define TF_INVADE_TEAM_CAPTURED "Invade.TeamCaptured"
  67. #define TF_INVADE_FLAG_RETURNED "Invade.FlagReturned"
  68. #define TF_INVADE_CAPTURED_TEAM_SCORE 1
  69. #define TF_INVADE_NEUTRAL_TIME 30.0f
  70. //=============================================================================
  71. //
  72. // Resource Flag defines.
  73. //
  74. #define TF_RESOURCE_FLAGSPAWN "Resource.FlagSpawn"
  75. #define TF_RESOURCE_ENEMY_STOLEN "Announcer.SD_TheirTeamHasFlag"
  76. #define TF_RESOURCE_ENEMY_DROPPED "Announcer.SD_TheirTeamDroppedFlag"
  77. #define TF_RESOURCE_ENEMY_CAPTURED "Announcer.SD_TheirTeamCapped"
  78. #define TF_RESOURCE_TEAM_STOLEN "Announcer.SD_OurTeamHasFlag"
  79. #define TF_RESOURCE_TEAM_DROPPED "Announcer.SD_OurTeamDroppedFlag"
  80. #define TF_RESOURCE_TEAM_CAPTURED "Announcer.SD_OurTeamCapped"
  81. #define TF_RESOURCE_RETURNED "Announcer.SD_FlagReturned"
  82. // Halloween event strings
  83. #define TF_RESOURCE_EVENT_ENEMY_STOLEN "Announcer.SD_Event_TheirTeamHasFlag"
  84. #define TF_RESOURCE_EVENT_ENEMY_DROPPED "Announcer.SD_Event_TheirTeamDroppedFlag"
  85. #define TF_RESOURCE_EVENT_TEAM_STOLEN "Announcer.SD_Event_OurTeamHasFlag"
  86. #define TF_RESOURCE_EVENT_TEAM_DROPPED "Announcer.SD_Event_OurTeamDroppedFlag"
  87. #define TF_RESOURCE_EVENT_RETURNED "Announcer.SD_Event_FlagReturned"
  88. #define TF_RESOURCE_EVENT_NAGS "Announcer.SD_Event_FlagNags"
  89. #define TF_RESOURCE_EVENT_RED_CAPPED "Announcer.SD_Event_CappedRed"
  90. #define TF_RESOURCE_EVENT_BLUE_CAPPED "Announcer.SD_Event_CappedBlu"
  91. //=============================================================================
  92. //
  93. // Robot Destruction Flag defines.
  94. //
  95. #define TF_RD_ENEMY_STOLEN "RD.EnemyStolen"
  96. #define TF_RD_ENEMY_DROPPED "RD.EnemyDropped"
  97. #define TF_RD_ENEMY_CAPTURED "RD.EnemyCaptured"
  98. #define TF_RD_ENEMY_RETURNED "RD.EnemyReturned"
  99. #define TF_RD_TEAM_STOLEN "RD.TeamStolen"
  100. #define TF_RD_TEAM_DROPPED "RD.TeamDropped"
  101. #define TF_RD_TEAM_CAPTURED "RD.TeamCaptured"
  102. #define TF_RD_TEAM_RETURNED "RD.TeamReturned"
  103. #define TF_RESOURCE_CAPTURED_TEAM_SCORE 1
  104. //=============================================================================
  105. //
  106. // Powerup mode defines.
  107. //
  108. #define TF_RUNE_INTEL_CAPTURED "CaptureFlag.TeamCapturedExcited"
  109. //=============================================================================
  110. //
  111. // Robot Destruction defines
  112. //
  113. #ifdef CLIENT_DLL
  114. #define CCaptureFlagReturnIcon C_CaptureFlagReturnIcon
  115. #define CBaseAnimating C_BaseAnimating
  116. #endif
  117. class CCaptureFlagReturnIcon: public CBaseAnimating
  118. {
  119. public:
  120. DECLARE_CLASS( CCaptureFlagReturnIcon, CBaseEntity );
  121. DECLARE_NETWORKCLASS();
  122. CCaptureFlagReturnIcon();
  123. #ifdef CLIENT_DLL
  124. virtual int DrawModel( int flags );
  125. void DrawReturnProgressBar( void );
  126. virtual RenderGroup_t GetRenderGroup( void );
  127. virtual bool ShouldDraw( void ) { return true; }
  128. virtual void GetRenderBounds( Vector& theMins, Vector& theMaxs );
  129. private:
  130. IMaterial *m_pReturnProgressMaterial_Empty; // For labels above players' heads.
  131. IMaterial *m_pReturnProgressMaterial_Full;
  132. #else
  133. public:
  134. virtual void Spawn( void );
  135. virtual int UpdateTransmitState( void );
  136. #endif
  137. };
  138. //=============================================================================
  139. //
  140. // CTF Flag class.
  141. //
  142. DECLARE_AUTO_LIST( ICaptureFlagAutoList );
  143. class CCaptureFlag : public CTFItem, public ICaptureFlagAutoList
  144. {
  145. public:
  146. DECLARE_CLASS( CCaptureFlag, CTFItem );
  147. DECLARE_NETWORKCLASS();
  148. CCaptureFlag();
  149. ~CCaptureFlag();
  150. unsigned int GetItemID( void ) const OVERRIDE;
  151. void Precache( void );
  152. void Spawn( void );
  153. virtual void UpdateOnRemove( void );
  154. void FlagTouch( CBaseEntity *pOther );
  155. bool IsDisabled( void ) const;
  156. void SetDisabled( bool bDisabled );
  157. void SetVisibleWhenDisabled( bool bVisible );
  158. bool IsPoisonous( void ) { return m_flTimeToSetPoisonous > 0 && gpGlobals->curtime > m_flTimeToSetPoisonous; }
  159. float GetPoisonTime( void ) const { return m_flTimeToSetPoisonous; }
  160. bool IsVisibleWhenDisabled( void ) { return m_bVisibleWhenDisabled; }
  161. CBaseEntity *GetPrevOwner( void ) { return m_hPrevOwner.Get(); }
  162. //-----------------------------------------------------------------------------
  163. // Purpose: Sets the flag status
  164. //-----------------------------------------------------------------------------
  165. void SetFlagStatus( int iStatus, CBasePlayer *pNewOwner = NULL );
  166. // Game DLL Functions
  167. #ifdef GAME_DLL
  168. CCaptureFlag &operator=( const CCaptureFlag& rhs );
  169. virtual void Activate( void );
  170. static CCaptureFlag* Create( const Vector& vecOrigin, const char *pszModelName, ETFFlagType type );
  171. // Input handlers
  172. void InputEnable( inputdata_t &inputdata );
  173. void InputDisable( inputdata_t &inputdata );
  174. void InputRoundActivate( inputdata_t &inputdata );
  175. void InputForceDrop( inputdata_t &inputdata );
  176. void InputForceReset( inputdata_t &inputdata );
  177. void InputForceResetSilent( inputdata_t &inputdata );
  178. void InputForceResetAndDisableSilent( inputdata_t &inputdata );
  179. void InputSetReturnTime( inputdata_t &inputdata );
  180. void InputShowTimer( inputdata_t &inputdata );
  181. void InputForceGlowDisabled( inputdata_t &inputdata );
  182. void Think( void );
  183. void CreateReturnIcon( void );
  184. void DestroyReturnIcon( void );
  185. void ResetFlagReturnTime( void ) { m_flResetTime = 0; }
  186. void SetFlagReturnIn( float flTime )
  187. {
  188. m_flResetTime = gpGlobals->curtime + flTime;
  189. m_flMaxResetTime = flTime;
  190. }
  191. void SetFlagReturnIn( float flTime, float flMaxResetTime )
  192. {
  193. m_flResetTime = gpGlobals->curtime + flTime;
  194. m_flMaxResetTime = flMaxResetTime;
  195. }
  196. void ResetFlagNeutralTime( void ) { m_flNeutralTime = 0; }
  197. void SetFlagNeutralIn( float flTime )
  198. {
  199. m_flNeutralTime = gpGlobals->curtime + flTime;
  200. m_flMaxResetTime = flTime;
  201. }
  202. bool IsCaptured( void ){ return m_bCaptured; }
  203. int UpdateTransmitState();
  204. void StartFlagTrail ( void );
  205. void RemoveFlagTrail ( void );
  206. EHANDLE m_pFlagTrail;
  207. float m_flFlagTrailLife;
  208. bool m_bInstantTrailRemove;
  209. int GetNumTags() const { return m_tags.Count(); }
  210. const char* GetTag( int i ) const { return m_tags[i]; }
  211. void AddFollower( CTFBot* pBot );
  212. void RemoveFollower( CTFBot* pBot );
  213. int GetNumFollowers() const { return m_followers.Count(); }
  214. void AddPointValue( int nPoints );
  215. #else // CLIENT DLL Functions
  216. virtual bool ShouldDraw() OVERRIDE;
  217. virtual bool IsVisibleToTargetID() const OVERRIDE;
  218. virtual const char *GetIDString( void ) { return "entity_capture_flag"; };
  219. virtual void OnPreDataChanged( DataUpdateType_t updateType );
  220. virtual void OnDataChanged( DataUpdateType_t updateType );
  221. void CreateSiren( void );
  222. void DestroySiren( void );
  223. void ManageTrailEffects( void );
  224. CNewParticleEffect *m_pGlowTrailEffect;
  225. CNewParticleEffect *m_pPaperTrailEffect;
  226. virtual void Simulate( void );
  227. float GetMaxResetTime() { return m_flMaxResetTime; }
  228. float GetReturnProgress( void );
  229. public:
  230. void UpdateGlowEffect( void );
  231. virtual bool ShouldHideGlowEffect( void );
  232. #endif
  233. // TODO: Both of these should be updated to work with floats instead of ints.
  234. int GetReturnTime( int nMaxReturnTime );
  235. int GetMaxReturnTime( void );
  236. void Capture( CTFPlayer *pPlayer, int nCapturePoint );
  237. virtual void PickUp( CTFPlayer *pPlayer, bool bInvisible );
  238. virtual void Drop( CTFPlayer *pPlayer, bool bVisible, bool bThrown = false, bool bMessage = true );
  239. ETFFlagType GetType( void ) const { return (ETFFlagType)m_nType.Get(); }
  240. bool IsDropped( void );
  241. bool IsHome( void );
  242. bool IsStolen( void );
  243. void ResetFlag( void )
  244. {
  245. Reset();
  246. ResetMessage();
  247. }
  248. const char *GetFlagModel( void );
  249. void GetHudIcon( int nTeam, char *pchName, int nBuffSize );
  250. const char *GetPaperEffect( void );
  251. void GetTrailEffect( int nTeam, char *pchName, int nBuffSize );
  252. int GetPointValue() const { return m_nPointValue.Get(); }
  253. private:
  254. void Reset( void );
  255. void ResetMessage( void );
  256. void InternalForceReset( bool bSilent = false );
  257. #ifdef GAME_DLL
  258. void PlaySound( IRecipientFilter& filter, const char *pszString, int iTeam = TEAM_ANY );
  259. float m_flNextTeamSoundTime[TF_TEAM_COUNT];
  260. void SetGlowEnabled( bool bGlowEnabled ){ m_bGlowEnabled = bGlowEnabled; }
  261. #endif
  262. bool IsGlowEnabled( void ){ return m_bGlowEnabled; }
  263. private:
  264. CNetworkVar( bool, m_bDisabled ); // Enabled/Disabled?
  265. CNetworkVar( bool, m_bVisibleWhenDisabled );
  266. CNetworkVar( int, m_nType ); // Type of game this flag will be used for.
  267. CNetworkVar( int, m_nFlagStatus );
  268. CNetworkVar( float, m_flResetTime ); // Time until the flag is placed back at spawn.
  269. CNetworkVar( float, m_flMaxResetTime ); // Time the flag takes to return in the current mode
  270. CNetworkVar( float, m_flNeutralTime ); // Time until the flag becomes neutral (used for the invade gametype)
  271. CNetworkHandle( CBaseEntity, m_hPrevOwner );
  272. CNetworkVar( int, m_nPointValue ); // How many points this flag is worth when scored. Used in Robot Destruction mode.
  273. CNetworkVar( float, m_flAutoCapTime );
  274. CNetworkVar( bool, m_bGlowEnabled );
  275. #ifdef GAME_DLL
  276. string_t m_iszModel;
  277. string_t m_iszHudIcon;
  278. string_t m_iszPaperEffect;
  279. string_t m_iszTrailEffect;
  280. string_t m_iszTags;
  281. CUtlStringList m_tags;
  282. CUtlVector< CHandle< CTFBot > > m_followers;
  283. #endif
  284. CNetworkString( m_szModel, MAX_PATH );
  285. CNetworkString( m_szHudIcon, MAX_PATH );
  286. CNetworkString( m_szPaperEffect, MAX_PATH );
  287. CNetworkString( m_szTrailEffect, MAX_PATH );
  288. CNetworkVar( int, m_nUseTrailEffect );
  289. int m_iOriginalTeam;
  290. float m_flOwnerPickupTime;
  291. int GetReturnTimeShotClockMode( int nStartReturnTime );
  292. inline bool IsFlagShotClockModePossible() const
  293. {
  294. return m_nType == TF_FLAGTYPE_CTF
  295. || m_nType == TF_FLAGTYPE_ROBOT_DESTRUCTION
  296. || m_nType == TF_FLAGTYPE_RESOURCE_CONTROL;
  297. }
  298. float m_flLastPickupTime; // What the time was of the last pickup by any player.
  299. float m_flLastResetDuration; // How long was the last time to reset before being picked up?
  300. int m_nReturnTime; // Length of time (in seconds) before dropped flag/intelligence returns to base.
  301. int m_nNeutralType; // Type of neutral flag (only used for Invade game type).
  302. int m_nScoringType; // Type of scoring for flag capture (only used for Invade game type).
  303. bool m_bReturnBetweenWaves; // Used in MvM mode to determine if the flag should return between waves.
  304. bool m_bUseShotClockMode; // Used to determine whether we should be using shot clock mode or not.
  305. CNetworkVar( float, m_flTimeToSetPoisonous ); // Time to set the flag as poisonous
  306. EHANDLE m_hReturnIcon;
  307. #ifdef GAME_DLL
  308. Vector m_vecResetPos; // The position the flag should respawn (reset) at.
  309. QAngle m_vecResetAng; // The angle the flag should respawn (reset) at.
  310. COutputEvent m_outputOnReturn; // Fired when the flag is returned via timer.
  311. COutputEvent m_outputOnPickUp; // Fired when the flag is picked up.
  312. COutputEvent m_outputOnPickUpTeam1; // Fired when the flag is picked up by RED.
  313. COutputEvent m_outputOnPickUpTeam2; // Fired when the flag is picked up by BLU.
  314. COutputEvent m_outputOnDrop; // Fired when the flag is dropped.
  315. COutputEvent m_outputOnCapture; // Fired when the flag is captured.
  316. COutputEvent m_OnCapTeam1;
  317. COutputEvent m_OnCapTeam2;
  318. COutputEvent m_OnTouchSameTeam;
  319. bool m_bAllowOwnerPickup;
  320. bool m_bCaptured;
  321. EHANDLE m_hInitialPlayer;
  322. EHANDLE m_hInitialParent;
  323. Vector m_vecOffset;
  324. #else
  325. IMaterial *m_pReturnProgressMaterial_Empty; // For labels above players' heads.
  326. IMaterial *m_pReturnProgressMaterial_Full;
  327. int m_nOldTeamNumber;
  328. EHANDLE m_hOldOwner;
  329. CGlowObject *m_pGlowEffect;
  330. CGlowObject *m_pCarrierGlowEffect;
  331. HPARTICLEFFECT m_hSirenEffect;
  332. bool m_bOldGlowEnabled;
  333. #endif
  334. DECLARE_DATADESC();
  335. };
  336. #endif // ENTITY_CAPTURE_FLAG_H