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.

526 lines
14 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: The TF Game rules object
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef DOD_GAMERULES_H
  10. #define DOD_GAMERULES_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "teamplay_gamerules.h"
  15. #include "convar.h"
  16. #include "dod_shareddefs.h"
  17. #include "gamevars_shared.h"
  18. #include "weapon_dodbase.h"
  19. #include "dod_round_timer.h"
  20. #ifdef CLIENT_DLL
  21. #include "c_baseplayer.h"
  22. #else
  23. #include "player.h"
  24. #include "dod_player.h"
  25. #include "utlqueue.h"
  26. #include "playerclass_info_parse.h"
  27. #include "voice_gamemgr.h"
  28. #include "dod_gamestats.h"
  29. #endif
  30. #ifdef CLIENT_DLL
  31. #define CDODGameRules C_DODGameRules
  32. #define CDODGameRulesProxy C_DODGameRulesProxy
  33. #else
  34. extern IVoiceGameMgrHelper *g_pVoiceGameMgrHelper;
  35. extern IUploadGameStats *gamestatsuploader;
  36. #endif
  37. #ifndef CLIENT_DLL
  38. class CSpawnPoint : public CPointEntity
  39. {
  40. public:
  41. bool IsDisabled() { return m_bDisabled; }
  42. void InputEnable( inputdata_t &inputdata ) { m_bDisabled = false; }
  43. void InputDisable( inputdata_t &inputdata ) { m_bDisabled = true; }
  44. private:
  45. bool m_bDisabled;
  46. DECLARE_DATADESC();
  47. };
  48. #endif
  49. class CDODGameRulesProxy : public CGameRulesProxy
  50. {
  51. public:
  52. DECLARE_CLASS( CDODGameRulesProxy, CGameRulesProxy );
  53. DECLARE_NETWORKCLASS();
  54. };
  55. class CDODGameRules;
  56. class CDODRoundStateInfo
  57. {
  58. public:
  59. DODRoundState m_iRoundState;
  60. const char *m_pStateName;
  61. void (CDODGameRules::*pfnEnterState)(); // Init and deinit the state.
  62. void (CDODGameRules::*pfnLeaveState)();
  63. void (CDODGameRules::*pfnThink)(); // Do a PreThink() in this state.
  64. };
  65. typedef enum
  66. {
  67. STARTROUND_ATTACK = 0,
  68. STARTROUND_DEFEND,
  69. STARTROUND_BEACH,
  70. STARTROUND_ATTACK_TIMED,
  71. STARTROUND_DEFEND_TIMED,
  72. STARTROUND_FLAGS,
  73. } startround_voice_t;
  74. class CDODGamePlayRules
  75. {
  76. public:
  77. DECLARE_CLASS_NOBASE( CDODGamePlayRules );
  78. DECLARE_EMBEDDED_NETWORKVAR();
  79. DECLARE_SIMPLE_DATADESC();
  80. CDODGamePlayRules()
  81. {
  82. Reset();
  83. }
  84. // This virtual method is necessary to generate a vtable in all cases
  85. // (DECLARE_PREDICTABLE will generate a vtable also)!
  86. virtual ~CDODGamePlayRules() {}
  87. void Reset( void )
  88. {
  89. //RespawnFactor
  90. m_fAlliesRespawnFactor = 1.0f;
  91. m_fAxisRespawnFactor = 1.0f;
  92. }
  93. //Respawn Factors
  94. float m_fAlliesRespawnFactor; //How delayed are respawning players
  95. float m_fAxisRespawnFactor; //1.0 is normal, 2.0 is twice as long
  96. int m_iAlliesStartRoundVoice; // Which voice to play at round start
  97. int m_iAxisStartRoundVoice;
  98. };
  99. //Mapper interface for gamerules
  100. class CDODDetect : public CBaseEntity
  101. {
  102. public:
  103. DECLARE_CLASS( CDODDetect, CBaseEntity );
  104. CDODDetect();
  105. void Spawn( void );
  106. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  107. bool IsMasteredOn( void );
  108. inline CDODGamePlayRules *GetGamePlay() { return &m_GamePlayRules; }
  109. CDODGamePlayRules m_GamePlayRules;
  110. private:
  111. // string_t m_sMaster;
  112. };
  113. class CDODViewVectors : public CViewVectors
  114. {
  115. public:
  116. CDODViewVectors(
  117. Vector vView,
  118. Vector vHullMin,
  119. Vector vHullMax,
  120. Vector vDuckHullMin,
  121. Vector vDuckHullMax,
  122. Vector vDuckView,
  123. Vector vObsHullMin,
  124. Vector vObsHullMax,
  125. Vector vDeadViewHeight,
  126. Vector vProneHullMin,
  127. Vector vProneHullMax ) :
  128. CViewVectors(
  129. vView,
  130. vHullMin,
  131. vHullMax,
  132. vDuckHullMin,
  133. vDuckHullMax,
  134. vDuckView,
  135. vObsHullMin,
  136. vObsHullMax,
  137. vDeadViewHeight )
  138. {
  139. m_vProneHullMin = vProneHullMin;
  140. m_vProneHullMax = vProneHullMax;
  141. }
  142. Vector m_vProneHullMin;
  143. Vector m_vProneHullMax;
  144. };
  145. //GAMERULES
  146. class CDODGameRules : public CTeamplayRules
  147. {
  148. public:
  149. DECLARE_CLASS( CDODGameRules, CTeamplayRules );
  150. virtual bool ShouldCollide( int collisionGroup0, int collisionGroup1 );
  151. inline DODRoundState State_Get( void ) { return m_iRoundState; }
  152. int GetSubTeam( int team );
  153. bool IsGameUnderTimeLimit( void );
  154. int GetTimeLeft( void );
  155. int GetReinforcementTimerSeconds( int team, float flSpawnEligibleTime );
  156. bool IsFriendlyFireOn( void );
  157. bool IsInBonusRound( void );
  158. // Get the view vectors for this mod.
  159. virtual const CViewVectors* GetViewVectors() const;
  160. virtual const CDODViewVectors *GetDODViewVectors() const;
  161. virtual const unsigned char *GetEncryptionKey( void ) { return (unsigned char *)"Wl0u5B3F"; }
  162. bool AwaitingReadyRestart( void ) { return m_bAwaitingReadyRestart; }
  163. float GetRoundRestartTime( void ) { return m_flRestartRoundTime; }
  164. bool IsInWarmup( void ) { return m_bInWarmup; }
  165. bool IsBombingTeam( int team );
  166. virtual bool IsConnectedUserInfoChangeAllowed( CBasePlayer *pPlayer );
  167. #ifndef CLIENT_DLL
  168. float GetPresentDropChance( void ); // holiday 2011, presents instead of ammo boxes
  169. #endif
  170. #ifdef CLIENT_DLL
  171. DECLARE_CLIENTCLASS_NOBASE(); // This makes datatables able to access our private vars.
  172. void SetRoundState( int iRoundState );
  173. float m_flLastRoundStateChangeTime;
  174. #else
  175. DECLARE_SERVERCLASS_NOBASE(); // This makes datatables able to access our private vars.
  176. CDODGameRules();
  177. virtual ~CDODGameRules();
  178. virtual void LevelShutdown( void );
  179. void UploadLevelStats( void );
  180. virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args );
  181. virtual void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore );
  182. virtual void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrcIn, float flRadius, int iClassIgnore, CBaseEntity *pEntityIgnore, bool bIgnoreWorld = false );
  183. void RadiusStun( const CTakeDamageInfo &info, const Vector &vecSrc, float flRadius );
  184. virtual void Think();
  185. virtual void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  186. virtual void ClientDisconnected( edict_t *pClient );
  187. virtual float FlPlayerFallDamage( CBasePlayer *pPlayer );
  188. virtual const char *GetGameDescription( void )
  189. {
  190. return "Day of Defeat: Source";
  191. }
  192. void CreateStandardEntities( void );
  193. virtual const char *GetChatPrefix( bool bTeamOnly, CBasePlayer *pPlayer );
  194. CBaseEntity *GetPlayerSpawnSpot( CBasePlayer *pPlayer );
  195. bool IsSpawnPointValid( CBaseEntity *pSpot, CBasePlayer *pPlayer );
  196. virtual void PlayerSpawn( CBasePlayer *pPlayer );
  197. int DODPointsForKill( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  198. //Round state machine
  199. void State_Transition( DODRoundState newState );
  200. void State_Enter( DODRoundState newState ); // Initialize the new state.
  201. void State_Leave(); // Cleanup the previous state.
  202. void State_Think(); // Update the current state.
  203. CDODRoundStateInfo *m_pCurStateInfo; //Fn ptrs for the current state
  204. float m_flStateTransitionTime; //Timer for round states
  205. // Find the state info for the specified state.
  206. static CDODRoundStateInfo* State_LookupInfo( DODRoundState state );
  207. //State Functions
  208. void State_Enter_INIT( void );
  209. void State_Think_INIT( void );
  210. void State_Enter_PREGAME( void );
  211. void State_Think_PREGAME( void );
  212. void State_Enter_STARTGAME( void );
  213. void State_Think_STARTGAME( void );
  214. void State_Enter_PREROUND( void );
  215. void State_Think_PREROUND( void );
  216. void State_Enter_RND_RUNNING( void );
  217. void State_Think_RND_RUNNING( void );
  218. void State_Enter_ALLIES_WIN( void );
  219. void State_Think_ALLIES_WIN( void );
  220. void State_Enter_AXIS_WIN( void );
  221. void State_Think_AXIS_WIN( void );
  222. void State_Enter_RESTART( void );
  223. void State_Think_RESTART( void );
  224. void SetInWarmup( bool bWarmup );
  225. void CheckWarmup( void );
  226. void CheckRestartRound( void );
  227. void CheckRespawnWaves( void );
  228. void InitTeams( void );
  229. void RoundRespawn( void );
  230. void CleanUpMap( void );
  231. void ResetScores( void );
  232. // Respawn everyone regardless of state - round reset
  233. inline void RespawnAllPlayers( void ) { RespawnPlayers( true ); }
  234. // Respawn only one team, players that are ready to spawn - wave reset
  235. inline void RespawnTeam( int iTeam ) { RespawnPlayers( false, true, iTeam ); }
  236. void RespawnPlayers( bool bForceRespawn, bool bTeam = false, int iTeam = TEAM_UNASSIGNED );
  237. void FailSafeSpawnPlayersOnTeam( int iTeam );
  238. bool IsPlayerClassOnTeam( int cls, int team );
  239. bool CanPlayerJoinClass( CDODPlayer *pPlayer, int cls );
  240. void ChooseRandomClass( CDODPlayer *pPlayer );
  241. bool ReachedClassLimit( int team, int cls );
  242. int CountPlayerClass( int team, int cls );
  243. int GetClassLimit( int team, int cls );
  244. int CountActivePlayers( void ); //How many players have chosen a team?
  245. void SetWinningTeam( int team );
  246. void PlayWinSong( int team );
  247. void PlayStartRoundVoice( void );
  248. void BroadcastSound( const char *sound );
  249. void PlaySpawnSoundToTeam( const char *sound, int team );
  250. int SelectDefaultTeam( void );
  251. void CopyGamePlayLogic( const CDODGamePlayRules otherGamePlay );
  252. void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  253. virtual bool CanHavePlayerItem( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );
  254. bool TeamFull( int team_id );
  255. bool TeamStacked( int iNewTeam, int iCurTeam );
  256. const char *GetPlayerClassName( int cls, int team );
  257. virtual void ClientSettingsChanged( CBasePlayer *pPlayer );
  258. void CheckChatForReadySignal( CDODPlayer *pPlayer, const char *chatmsg );
  259. bool AreAlliesReady( void ) { return m_bHeardAlliesReady; }
  260. bool AreAxisReady( void ) { return m_bHeardAxisReady; }
  261. void CreateOrJoinRespawnWave( CDODPlayer *pPlayer );
  262. virtual bool InRoundRestart( void );
  263. void SendTeamScoresEvent( void );
  264. void WriteStatsFile( const char *pszLogName );
  265. void AddTimerSeconds( int iSecondsToAdd );
  266. int GetTimerSeconds( void );
  267. void CapEvent( int event, int team );
  268. int m_iLastAlliesCapEvent;
  269. int m_iLastAxisCapEvent;
  270. // Set the time at which the map was reset to 'now'
  271. // and send an event with the time remaining until map change
  272. void ResetMapTime( void );
  273. virtual CBaseCombatWeapon *GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon );
  274. virtual bool CanEntityBeUsePushed( CBaseEntity *pEnt );
  275. virtual void CalcDominationAndRevenge( CDODPlayer *pAttacker, CDODPlayer *pVictim, int *piDeathFlags );
  276. float m_flNextFailSafeWaveCheckTime;
  277. CUtlVector<EHANDLE> *GetSpawnPointListForTeam( int iTeam );
  278. virtual void GetTaggedConVarList( KeyValues *pCvarTagList );
  279. protected:
  280. virtual void GoToIntermission( void );
  281. virtual bool UseSuicidePenalty() { return false; }
  282. void CheckPlayerPositions( void );
  283. private:
  284. bool CheckTimeLimit( void );
  285. bool CheckWinLimit( void );
  286. void RadiusDamage( const CTakeDamageInfo &info, const Vector &vecSrcIn, float flRadius, int iClassIgnore, bool bIgnoreWorld );
  287. float GetExplosionDamageAdjustment(Vector & vecSrc, Vector & vecEnd, CBaseEntity *pTarget, CBaseEntity *pEntityToIgnore); // returns multiplier between 0.0 and 1.0 that is the percentage of any damage done from vecSrc to vecEnd that actually makes it.
  288. float GetAmountOfEntityVisible(Vector & src, CBaseEntity *pTarget, CBaseEntity *pEntityToIgnore); // returns a value from 0 to 1 that is the percentage of player visible from src.
  289. void CheckLevelInitialized( void );
  290. bool m_bLevelInitialized;
  291. int m_iSpawnPointCount_Allies; //number of allies spawns on the map
  292. int m_iSpawnPointCount_Axis; //number of axis spawns on the map
  293. #define MAX_PLAYERCLASSES_PER_TEAM 16
  294. PLAYERCLASS_FILE_INFO_HANDLE m_hPlayerClassInfoHandles[2][MAX_PLAYERCLASSES_PER_TEAM];
  295. // restart and warmup variables
  296. float m_flWarmupTimeEnds;
  297. float m_flNextPeriodicThink;
  298. Vector2D m_vecPlayerPositions[MAX_PLAYERS];
  299. //BELOW HERE NEED TO BE HOOKED UP
  300. int m_iNumAlliesAlive; //the number of players alive on each team
  301. int m_iNumAxisAlive;
  302. int m_iNumAlliesOnTeam; //the number of players on each team
  303. int m_iNumAxisOnTeam;
  304. bool m_bClanMatch;
  305. bool m_bClanMatchActive;
  306. float GetMaxWaveTime( int iTeam );
  307. float GetWaveTime( int iTeam );
  308. void AddWaveTime( int team, float flTime );
  309. void PopWaveTime( int team );
  310. void DetectGameRules( void );
  311. bool m_bHeardAlliesReady;
  312. bool m_bHeardAxisReady;
  313. bool m_bUsingTimer;
  314. int m_iTimerWinTeam;
  315. CHandle< CDODRoundTimer > m_pRoundTimer;
  316. bool m_bPlayTimerWarning_1Minute;
  317. bool m_bPlayTimerWarning_2Minute;
  318. bool m_bInitialSpawn; // first time activating? longer wait time for people to join
  319. bool m_bChangeLevelOnRoundEnd;
  320. #endif //CLIENT_DLL
  321. CNetworkVarEmbedded( CDODGamePlayRules, m_GamePlayRules );
  322. CNetworkVar( DODRoundState, m_iRoundState );
  323. #define DOD_RESPAWN_QUEUE_SIZE 10
  324. CNetworkArray( float, m_AlliesRespawnQueue, DOD_RESPAWN_QUEUE_SIZE );
  325. CNetworkArray( float, m_AxisRespawnQueue, DOD_RESPAWN_QUEUE_SIZE );
  326. CNetworkVar( int, m_iAlliesRespawnHead );
  327. CNetworkVar( int, m_iAlliesRespawnTail );
  328. CNetworkVar( int, m_iAxisRespawnHead );
  329. CNetworkVar( int, m_iAxisRespawnTail );
  330. int m_iNumAlliesRespawnWaves;
  331. int m_iNumAxisRespawnWaves;
  332. CNetworkVar( bool, m_bInWarmup );
  333. CNetworkVar( bool, m_bAwaitingReadyRestart );
  334. CNetworkVar( float, m_flRestartRoundTime );
  335. CNetworkVar( float, m_flMapResetTime ); // time that the map was reset
  336. CNetworkVar( bool, m_bAlliesAreBombing );
  337. CNetworkVar( bool, m_bAxisAreBombing );
  338. #ifndef CLIENT_DLL
  339. public:
  340. // Stats
  341. void Stats_PlayerKill( int team, int cls );
  342. void Stats_PlayerCap( int team, int cls );
  343. void Stats_PlayerDefended( int team, int cls );
  344. void Stats_WeaponFired( int weaponID );
  345. void Stats_WeaponHit( int weaponID, float flDist );
  346. int Stats_WeaponDistanceToBucket( int weaponID, float flDist );
  347. float m_flSecondsPlayedPerClass_Allies[7];
  348. float m_flSecondsPlayedPerClass_Axis[7];
  349. int m_iStatsKillsPerClass_Allies[6];
  350. int m_iStatsKillsPerClass_Axis[6];
  351. int m_iStatsSpawnsPerClass_Allies[6];
  352. int m_iStatsSpawnsPerClass_Axis[6];
  353. int m_iStatsCapsPerClass_Allies[6];
  354. int m_iStatsCapsPerClass_Axis[6];
  355. int m_iStatsDefensesPerClass_Allies[6];
  356. int m_iStatsDefensesPerClass_Axis[6];
  357. int m_iWeaponShotsFired[WEAPON_MAX];
  358. int m_iWeaponShotsHit[WEAPON_MAX];
  359. int m_iWeaponDistanceBuckets[WEAPON_MAX][DOD_NUM_WEAPON_DISTANCE_BUCKETS]; // distances of buckets are defined per-weapon
  360. // List of spawn points
  361. CUtlVector<EHANDLE> m_AlliesSpawnPoints;
  362. CUtlVector<EHANDLE> m_AxisSpawnPoints;
  363. bool m_bWinterHolidayActive;
  364. #endif // ndef CLIENTDLL
  365. };
  366. //-----------------------------------------------------------------------------
  367. // Gets us at the team fortress game rules
  368. //-----------------------------------------------------------------------------
  369. inline CDODGameRules* DODGameRules()
  370. {
  371. return static_cast<CDODGameRules*>(g_pGameRules);
  372. }
  373. #ifdef CLIENT_DLL
  374. #else
  375. bool EntityPlacementTest( CBaseEntity *pMainEnt, const Vector &vOrigin, Vector &outPos, bool bDropToGround );
  376. #endif //CLIENT_DLL
  377. #endif // DOD_GAMERULES_H