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.

318 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Entities for use in the Robot Destruction TF2 game mode.
  4. //
  5. //=========================================================================//
  6. #ifndef LOGIC_ROBOT_DESTRUCTION_H
  7. #define LOGIC_ROBOT_DESTRUCTION_H
  8. #pragma once
  9. #include "cbase.h"
  10. #ifdef GAME_DLL
  11. #include "triggers.h"
  12. #include "tf_shareddefs.h"
  13. #include "GameEventListener.h"
  14. #include "entity_capture_flag.h"
  15. #else
  16. #include "c_tf_player.h"
  17. #endif
  18. #include "tf_robot_destruction_robot.h"
  19. #ifdef CLIENT_DLL
  20. #define CTFRobotDestructionLogic C_TFRobotDestructionLogic
  21. #define CTFRobotDestruction_RobotSpawn C_TFRobotDestruction_RobotSpawn
  22. #define CTFRobotDestruction_RobotGroup C_TFRobotDestruction_RobotGroup
  23. #endif
  24. #include "props_shared.h"
  25. #define RD_POINTS_STOLEN_PER_TICK 2
  26. //-----------------------------------------------------------------------------
  27. class CTFRobotDestruction_RobotSpawn : public CBaseEntity
  28. {
  29. public:
  30. DECLARE_DATADESC();
  31. DECLARE_CLASS( CTFRobotDestruction_RobotSpawn, CBaseEntity )
  32. DECLARE_NETWORKCLASS();
  33. CTFRobotDestruction_RobotSpawn();
  34. virtual void Spawn() OVERRIDE;
  35. virtual void Activate() OVERRIDE;
  36. #ifdef GAME_DLL
  37. virtual void Precache() OVERRIDE;
  38. virtual bool ShouldCollide( int collisionGroup, int contentsMask ) const OVERRIDE;
  39. CTFRobotDestruction_Robot* GetRobot() const { return m_hRobot.Get(); }
  40. void OnRobotKilled();
  41. void ClearRobot();
  42. void SpawnRobot();
  43. void SetGroup( class CTFRobotDestruction_RobotGroup* pGroup ) { m_hGroup.Set( pGroup ); }
  44. // Inputs
  45. void InputSpawnRobot( inputdata_t &inputdata );
  46. #endif
  47. private:
  48. CHandle< CTFRobotDestruction_Robot > m_hRobot;
  49. #ifdef GAME_DLL
  50. CHandle< class CTFRobotDestruction_RobotGroup > m_hGroup;
  51. RobotSpawnData_t m_spawnData;
  52. COutputEvent m_OnRobotKilled;
  53. #endif
  54. };
  55. //-----------------------------------------------------------------------------
  56. DECLARE_AUTO_LIST( IRobotDestructionGroupAutoList );
  57. class CTFRobotDestruction_RobotGroup : public CBaseEntity, public IRobotDestructionGroupAutoList
  58. {
  59. DECLARE_DATADESC();
  60. DECLARE_CLASS( CTFRobotDestruction_RobotGroup, CBaseEntity )
  61. DECLARE_NETWORKCLASS();
  62. public:
  63. virtual ~CTFRobotDestruction_RobotGroup();
  64. #ifdef GAME_DLL
  65. CTFRobotDestruction_RobotGroup();
  66. virtual int UpdateTransmitState() OVERRIDE { return SetTransmitState( FL_EDICT_ALWAYS ); }
  67. virtual void Spawn() OVERRIDE;
  68. virtual void Activate() OVERRIDE;
  69. void AddToGroup( CTFRobotDestruction_RobotSpawn * pSpawn );
  70. void RemoveFromGroup( CTFRobotDestruction_RobotSpawn * pSpawn );
  71. void UpdateState();
  72. void RespawnRobots();
  73. int GetNumAliveBots() const;
  74. float GetTeamRespawnScale() const { return m_flTeamRespawnReductionScale; }
  75. // Respawn functions
  76. void StopRespawnTimer();
  77. void StartRespawnTimerIfNeeded( CTFRobotDestruction_RobotGroup *pMasterGroup );
  78. void RespawnCountdownFinish();
  79. void EnableUberForGroup();
  80. void DisableUberForGroup();
  81. void OnRobotAttacked();
  82. void OnRobotKilled();
  83. void OnRobotSpawned();
  84. #else
  85. virtual void PostDataUpdate( DataUpdateType_t updateType ) OVERRIDE;
  86. virtual int GetTeamNumber( void ) const OVERRIDE { return m_iTeamNum; }
  87. virtual void SetDormant( bool bDormant ) OVERRIDE;
  88. #endif
  89. const char *GetHUDIcon() const { return m_pszHudIcon; }
  90. int GetGroupNumber() const { return m_nGroupNumber; }
  91. int GetState() const { return m_nState; }
  92. float GetRespawnStartTime() const { return m_flRespawnStartTime; }
  93. float GetRespawnEndTime() const { return m_flRespawnEndTime; }
  94. float GetLastAttackedTime() const { return m_flLastAttackedTime; }
  95. private:
  96. #ifdef GAME_DLL
  97. CUtlVector< CTFRobotDestruction_RobotSpawn* > m_vecSpawns;
  98. int m_nTeamNumber;
  99. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_iTeamNum );
  100. float m_flRespawnTime;
  101. static float m_sflNextAllowedAttackAlertTime[ TF_TEAM_COUNT ];
  102. string_t m_iszHudIcon;
  103. float m_flTeamRespawnReductionScale;
  104. COutputEvent m_OnRobotsRespawn;
  105. COutputEvent m_OnAllRobotsDead;
  106. #else
  107. int m_iTeamNum;
  108. #endif
  109. CNetworkString( m_pszHudIcon, MAX_PATH );
  110. CNetworkVar( int, m_nGroupNumber );
  111. CNetworkVar( int, m_nState );
  112. CNetworkVar( float, m_flRespawnStartTime );
  113. CNetworkVar( float, m_flRespawnEndTime );
  114. CNetworkVar( float, m_flLastAttackedTime );
  115. };
  116. struct RateLimitedSound_t
  117. {
  118. RateLimitedSound_t( float flPause )
  119. {
  120. m_mapNextAllowedTime.SetLessFunc( DefLessFunc( const CBaseEntity* ) );
  121. m_flPause = flPause;
  122. }
  123. float m_flPause;
  124. CUtlMap< const CBaseEntity*, float > m_mapNextAllowedTime;
  125. };
  126. struct TeamSound_t
  127. {
  128. const char *m_pszYourTeam;
  129. const char *m_pszTheirTeam;
  130. };
  131. //-----------------------------------------------------------------------------
  132. class CTFRobotDestructionLogic : public CBaseEntity
  133. #ifdef GAME_DLL
  134. , public CGameEventListener
  135. #endif
  136. {
  137. DECLARE_CLASS( CTFRobotDestructionLogic, CBaseEntity )
  138. DECLARE_NETWORKCLASS();
  139. public:
  140. enum EType
  141. {
  142. TYPE_ROBOT_DESTRUCTION,
  143. TYPE_PLAYER_DESTRUCTION,
  144. };
  145. virtual EType GetType() const { return TYPE_ROBOT_DESTRUCTION; }
  146. CTFRobotDestructionLogic();
  147. virtual ~CTFRobotDestructionLogic();
  148. static CTFRobotDestructionLogic* GetRobotDestructionLogic();
  149. virtual void Spawn() OVERRIDE;
  150. virtual void Precache() OVERRIDE;
  151. float GetRespawnScaleForTeam( int nTeam ) const;
  152. int GetScore( int nTeam ) const;
  153. int GetTargetScore( int nTeam ) const;
  154. int GetMaxPoints() const { return m_nMaxPoints.Get(); }
  155. float GetFinaleWinTime( int nTeam ) const;
  156. float GetFinaleLength() const { return m_flFinaleLength; }
  157. void PlaySoundInfoForScoreEvent( CTFPlayer* pPlayer, bool bPositive, int nNewScore, int nTeam, RDScoreMethod_t eMethod = SCORE_UNDEFINED );
  158. RDScoreMethod_t GetLastScoreMethod( int nTeam ) const { return (RDScoreMethod_t)m_eWinningMethod[ nTeam ]; }
  159. #ifdef CLIENT_DLL
  160. virtual void OnDataChanged( DataUpdateType_t type ) OVERRIDE;
  161. virtual void ClientThink() OVERRIDE;
  162. const char* GetResFile() const { return STRING( m_szResFile ); }
  163. #else
  164. DECLARE_DATADESC();
  165. virtual void Activate() OVERRIDE;
  166. virtual void FireGameEvent( IGameEvent * event ) OVERRIDE;
  167. virtual int UpdateTransmitState() OVERRIDE { return SetTransmitState( FL_EDICT_ALWAYS ); }
  168. CTFRobotDestruction_Robot * IterateRobots( CTFRobotDestruction_Robot * ) const;
  169. void RobotCreated( CTFRobotDestruction_Robot *pRobot );
  170. void RobotRemoved( CTFRobotDestruction_Robot *pRobot );
  171. void RobotAttacked( CTFRobotDestruction_Robot *pRobot );
  172. float GetScoringInterval() const { return m_flRobotScoreInterval; }
  173. void ScorePoints( int nTeam, int nPoints, RDScoreMethod_t eMethod, CTFPlayer *pPlayer );
  174. void AddRobotGroup( CTFRobotDestruction_RobotGroup* pGroup );
  175. void ManageGameState();
  176. void FlagCreated( int nTeam );
  177. void FlagDestroyed( int nTeam );
  178. void DBG_SetMaxPoints( int nNewMax ) { m_nMaxPoints.Set( nNewMax ); }
  179. void InputRoundActivate( inputdata_t &inputdata );
  180. virtual int GetHealDistance( void ) { return 64; }
  181. #endif
  182. virtual void SetCountdownEndTime( float flTime ){ m_flCountdownEndTime = flTime; }
  183. virtual float GetCountdownEndTime(){ return m_flCountdownEndTime; }
  184. virtual CTFPlayer *GetTeamLeader( int iTeam ) const { return NULL; }
  185. virtual string_t GetCountdownImage( void ) { return NULL_STRING; }
  186. virtual bool IsUsingCustomCountdownImage( void ) { return false; }
  187. protected:
  188. #ifdef GAME_DLL
  189. virtual void OnRedScoreChanged() {}
  190. virtual void OnBlueScoreChanged() {}
  191. void ApproachTargetScoresThink();
  192. int ApproachTeamTargetScore( int nTeam, int nApproachScore, int nCurrentScore );
  193. void PlaySoundInPlayersEars( CTFPlayer* pPlayer, const EmitSound_t& params ) const;
  194. void RedTeamWin();
  195. void BlueTeamWin();
  196. virtual void TeamWin( int nTeam );
  197. typedef CUtlMap< int, CTFRobotDestruction_RobotGroup* > RobotSpawnMap_t;
  198. CUtlVector< CTFRobotDestruction_Robot* > m_vecRobots;
  199. CUtlVector< CTFRobotDestruction_RobotGroup * > m_vecSpawnGroups;
  200. float m_flLoserRespawnBonusPerBot;
  201. float m_flRobotScoreInterval;
  202. float m_flNextRedRobotAttackedAlertTime;
  203. float m_flNextBlueRobotAttackedAlertTime;
  204. int m_nNumFlagsOut[ TF_TEAM_COUNT ];
  205. bool m_bEducateNewConnectors;
  206. string_t m_iszResFile;
  207. TeamSound_t m_AnnouncerProgressSound;
  208. CUtlMap< const char *, RateLimitedSound_t * > m_mapRateLimitedSounds;
  209. CUtlVector< CTFPlayer* > m_vecEducatedPlayers;
  210. // Outputs
  211. COutputEvent m_OnRedFinalePeriodEnd;
  212. COutputEvent m_OnBlueFinalePeriodEnd;
  213. COutputEvent m_OnBlueHitZeroPoints;
  214. COutputEvent m_OnRedHitZeroPoints;
  215. COutputEvent m_OnBlueHasPoints;
  216. COutputEvent m_OnRedHasPoints;
  217. COutputEvent m_OnBlueHitMaxPoints;
  218. COutputEvent m_OnRedHitMaxPoints;
  219. COutputEvent m_OnBlueLeaveMaxPoints;
  220. COutputEvent m_OnRedLeaveMaxPoints;
  221. COutputEvent m_OnRedFirstFlagStolen;
  222. COutputEvent m_OnRedFlagStolen;
  223. COutputEvent m_OnRedLastFlagReturned;
  224. COutputEvent m_OnBlueFirstFlagStolen;
  225. COutputEvent m_OnBlueFlagStolen;
  226. COutputEvent m_OnBlueLastFlagReturned;
  227. #else
  228. float m_flLastTickSoundTime;
  229. #endif
  230. static CTFRobotDestructionLogic* m_sCTFRobotDestructionLogic;
  231. CNetworkVar( int, m_nMaxPoints );
  232. CNetworkVar( float, m_flFinaleLength );
  233. CNetworkVar( float, m_flBlueFinaleEndTime );
  234. CNetworkVar( float, m_flRedFinaleEndTime );
  235. CNetworkVar( int, m_nBlueScore );
  236. CNetworkVar( int, m_nRedScore );
  237. CNetworkVar( int, m_nBlueTargetPoints );
  238. CNetworkVar( int, m_nRedTargetPoints );
  239. CNetworkVar( float, m_flBlueTeamRespawnScale );
  240. CNetworkVar( float, m_flRedTeamRespawnScale );
  241. CNetworkString( m_szResFile, MAX_PATH );
  242. CNetworkArray( int, m_eWinningMethod, TF_TEAM_COUNT );
  243. CNetworkVar( float, m_flCountdownEndTime ); // used for player destruction countdown timers
  244. };
  245. #ifdef GAME_DLL
  246. class CRobotDestructionVaultTrigger : public CBaseTrigger
  247. {
  248. DECLARE_CLASS( CRobotDestructionVaultTrigger, CBaseTrigger );
  249. DECLARE_DATADESC();
  250. public:
  251. CRobotDestructionVaultTrigger();
  252. virtual void Spawn() OVERRIDE;
  253. virtual void Precache() OVERRIDE;
  254. virtual bool PassesTriggerFilters( CBaseEntity *pOther ) OVERRIDE;
  255. virtual void StartTouch(CBaseEntity *pOther) OVERRIDE;
  256. virtual void EndTouch(CBaseEntity *pOther) OVERRIDE;
  257. private:
  258. void StealPointsThink();
  259. int StealPoints( CTFPlayer *pPlayer );
  260. bool m_bIsStealing;
  261. COutputEvent m_OnPointsStolen;
  262. COutputEvent m_OnPointsStartStealing;
  263. COutputEvent m_OnPointsEndStealing;
  264. };
  265. #endif// GAME_DLL
  266. #endif// LOGIC_ROBOT_DESTRUCTION_H