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.

288 lines
9.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef MULTIPLAY_GAMERULES_H
  7. #define MULTIPLAY_GAMERULES_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "gamerules.h"
  12. #ifdef CLIENT_DLL
  13. #define CMultiplayRules C_MultiplayRules
  14. #else
  15. extern ConVar mp_restartgame;
  16. extern ConVar mp_restartgame_immediate;
  17. extern ConVar mp_waitingforplayers_time;
  18. extern ConVar mp_waitingforplayers_restart;
  19. extern ConVar mp_waitingforplayers_cancel;
  20. extern ConVar mp_clan_readyrestart;
  21. extern ConVar mp_clan_ready_signal;
  22. extern ConVar nextlevel;
  23. extern INetworkStringTable *g_pStringTableServerMapCycle;
  24. #if defined ( TF_DLL ) || defined ( TF_CLIENT_DLL )
  25. extern INetworkStringTable *g_pStringTableServerPopFiles;
  26. extern INetworkStringTable *g_pStringTableServerMapCycleMvM;
  27. #endif
  28. #define VOICE_COMMAND_MAX_SUBTITLE_DIST 1900
  29. class CBaseMultiplayerPlayer;
  30. #endif
  31. extern ConVar mp_show_voice_icons;
  32. #define MAX_SPEAK_CONCEPT_LEN 64
  33. #define MAX_VOICE_COMMAND_SUBTITLE 256
  34. typedef struct
  35. {
  36. #ifndef CLIENT_DLL
  37. // concept to speak
  38. int m_iConcept;
  39. // play subtitle?
  40. bool m_bShowSubtitle;
  41. bool m_bDistanceBasedSubtitle;
  42. char m_szGestureActivity[64];
  43. #else
  44. // localizable subtitle
  45. char m_szSubtitle[MAX_VOICE_COMMAND_SUBTITLE];
  46. // localizable string for menu
  47. char m_szMenuLabel[MAX_VOICE_COMMAND_SUBTITLE];
  48. #endif
  49. } VoiceCommandMenuItem_t;
  50. extern ConVar mp_timelimit;
  51. //=========================================================
  52. // CMultiplayRules - rules for the basic half life multiplayer
  53. // competition
  54. //=========================================================
  55. class CMultiplayRules : public CGameRules
  56. {
  57. public:
  58. DECLARE_CLASS( CMultiplayRules, CGameRules );
  59. // Functions to verify the single/multiplayer status of a game
  60. virtual bool IsMultiplayer( void );
  61. virtual bool Init();
  62. // Damage query implementations.
  63. virtual bool Damage_IsTimeBased( int iDmgType ); // Damage types that are time-based.
  64. virtual bool Damage_ShouldGibCorpse( int iDmgType ); // Damage types that gib the corpse.
  65. virtual bool Damage_ShowOnHUD( int iDmgType ); // Damage types that have client HUD art.
  66. virtual bool Damage_NoPhysicsForce( int iDmgType ); // Damage types that don't have to supply a physics force & position.
  67. virtual bool Damage_ShouldNotBleed( int iDmgType ); // Damage types that don't make the player bleed.
  68. // TEMP: These will go away once DamageTypes become enums.
  69. virtual int Damage_GetTimeBased( void );
  70. virtual int Damage_GetShouldGibCorpse( void );
  71. virtual int Damage_GetShowOnHud( void );
  72. virtual int Damage_GetNoPhysicsForce( void );
  73. virtual int Damage_GetShouldNotBleed( void );
  74. CMultiplayRules();
  75. virtual ~CMultiplayRules() {}
  76. void LoadVoiceCommandScript( void );
  77. virtual bool ShouldDrawHeadLabels()
  78. {
  79. if ( mp_show_voice_icons.GetBool() == false )
  80. return false;
  81. return BaseClass::ShouldDrawHeadLabels();
  82. }
  83. #ifndef CLIENT_DLL
  84. virtual void FrameUpdatePostEntityThink();
  85. // GR_Think
  86. virtual void Think( void );
  87. virtual void RefreshSkillData( bool forceUpdate );
  88. virtual bool IsAllowedToSpawn( CBaseEntity *pEntity );
  89. virtual bool FAllowFlashlight( void );
  90. virtual bool FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );
  91. virtual CBaseCombatWeapon *GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon );
  92. virtual bool SwitchToNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon );
  93. // Functions to verify the single/multiplayer status of a game
  94. virtual bool IsDeathmatch( void );
  95. virtual bool IsCoOp( void );
  96. // Client connection/disconnection
  97. // If ClientConnected returns FALSE, the connection is rejected and the user is provided the reason specified in
  98. // svRejectReason
  99. // Only the client's name and remote address are provided to the dll for verification.
  100. virtual bool ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
  101. virtual void InitHUD( CBasePlayer *pl ); // the client dll is ready for updating
  102. virtual void ClientDisconnected( edict_t *pClient );
  103. // Client damage rules
  104. virtual float FlPlayerFallDamage( CBasePlayer *pPlayer );
  105. virtual bool FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker, const CTakeDamageInfo &info );
  106. virtual bool AllowDamage( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  107. // Client spawn/respawn control
  108. virtual void PlayerSpawn( CBasePlayer *pPlayer );
  109. virtual void PlayerThink( CBasePlayer *pPlayer );
  110. virtual bool FPlayerCanRespawn( CBasePlayer *pPlayer );
  111. virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer );
  112. virtual CBaseEntity *GetPlayerSpawnSpot( CBasePlayer *pPlayer );
  113. virtual bool AllowAutoTargetCrosshair( void );
  114. // Client kills/scoring
  115. virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled );
  116. virtual void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  117. virtual void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  118. CBasePlayer *GetDeathScorer( CBaseEntity *pKiller, CBaseEntity *pInflictor ); // old version of method - kept for backward compat
  119. virtual CBasePlayer *GetDeathScorer( CBaseEntity *pKiller, CBaseEntity *pInflictor, CBaseEntity *pVictim ); // new version of method
  120. // Weapon retrieval
  121. virtual bool CanHavePlayerItem( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );// The player is touching an CBaseCombatWeapon, do I give it to him?
  122. // Weapon spawn/respawn control
  123. virtual int WeaponShouldRespawn( CBaseCombatWeapon *pWeapon );
  124. virtual float FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon );
  125. virtual float FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon );
  126. virtual Vector VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon );
  127. // Item retrieval
  128. virtual bool CanHaveItem( CBasePlayer *pPlayer, CItem *pItem );
  129. virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem );
  130. // Item spawn/respawn control
  131. virtual int ItemShouldRespawn( CItem *pItem );
  132. virtual float FlItemRespawnTime( CItem *pItem );
  133. virtual Vector VecItemRespawnSpot( CItem *pItem );
  134. virtual QAngle VecItemRespawnAngles( CItem *pItem );
  135. // Ammo retrieval
  136. virtual void PlayerGotAmmo( CBaseCombatCharacter *pPlayer, char *szName, int iCount );
  137. // Healthcharger respawn control
  138. virtual float FlHealthChargerRechargeTime( void );
  139. virtual float FlHEVChargerRechargeTime( void );
  140. // What happens to a dead player's weapons
  141. virtual int DeadPlayerWeapons( CBasePlayer *pPlayer );
  142. // What happens to a dead player's ammo
  143. virtual int DeadPlayerAmmo( CBasePlayer *pPlayer );
  144. // Teamplay stuff
  145. virtual const char *GetTeamID( CBaseEntity *pEntity ) {return "";}
  146. virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget );
  147. virtual bool PlayerCanHearChat( CBasePlayer *pListener, CBasePlayer *pSpeaker );
  148. virtual bool PlayTextureSounds( void ) { return FALSE; }
  149. virtual bool PlayFootstepSounds( CBasePlayer *pl );
  150. // NPCs
  151. virtual bool FAllowNPCs( void );
  152. // Immediately end a multiplayer game
  153. virtual void EndMultiplayerGame( void ) { GoToIntermission(); }
  154. // Voice commands
  155. virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args );
  156. virtual VoiceCommandMenuItem_t *VoiceCommand( CBaseMultiplayerPlayer *pPlayer, int iMenu, int iItem );
  157. // Bugbait report
  158. bool IsLoadingBugBaitReport( void );
  159. virtual void ResetMapCycleTimeStamp( void ){ m_nMapCycleTimeStamp = 0; }
  160. virtual void HandleTimeLimitChange( void ){ return; }
  161. void IncrementMapCycleIndex();
  162. void HaveAllPlayersSpeakConceptIfAllowed( int iConcept, int iTeam = TEAM_UNASSIGNED, const char *modifiers = NULL );
  163. void RandomPlayersSpeakConceptIfAllowed( int iConcept, int iNumRandomPlayer = 1, int iTeam = TEAM_UNASSIGNED, const char *modifiers = NULL );
  164. virtual void GetTaggedConVarList( KeyValues *pCvarTagList );
  165. void SkipNextMapInCycle();
  166. virtual void ClientCommandKeyValues( edict_t *pEntity, KeyValues *pKeyValues );
  167. public:
  168. struct ResponseRules_t
  169. {
  170. CUtlVector<IResponseSystem*> m_ResponseSystems;
  171. };
  172. CUtlVector<ResponseRules_t> m_ResponseRules;
  173. virtual void InitCustomResponseRulesDicts() {}
  174. virtual void ShutdownCustomResponseRulesDicts() {}
  175. // NVNT virtual to check for haptic device
  176. virtual void ClientSettingsChanged( CBasePlayer *pPlayer );
  177. virtual void GetNextLevelName( char *szNextMap, int bufsize, bool bRandom = false );
  178. static void DetermineMapCycleFilename( char *pszResult, int nSizeResult, bool bForceSpew );
  179. virtual void LoadMapCycleFileIntoVector ( const char *pszMapCycleFile, CUtlVector<char *> &mapList );
  180. static void FreeMapCycleFileVector ( CUtlVector<char *> &mapList );
  181. // LoadMapCycleFileIntoVector without the fixups inherited versions of gamerules may provide
  182. static void RawLoadMapCycleFileIntoVector ( const char *pszMapCycleFile, CUtlVector<char *> &mapList );
  183. bool IsMapInMapCycle( const char *pszName );
  184. virtual bool IsManualMapChangeOkay( const char **pszReason ) OVERRIDE;
  185. protected:
  186. virtual bool UseSuicidePenalty() { return true; } // apply point penalty for suicide?
  187. virtual float GetLastMajorEventTime( void ){ return -1.0f; }
  188. public:
  189. virtual void ChangeLevel( void );
  190. protected:
  191. virtual void GoToIntermission( void );
  192. virtual void LoadMapCycleFile( void );
  193. void ChangeLevelToMap( const char *pszMap );
  194. float m_flIntermissionEndTime;
  195. static int m_nMapCycleTimeStamp;
  196. static int m_nMapCycleindex;
  197. static CUtlVector<char*> m_MapList;
  198. float m_flTimeLastMapChangeOrPlayerWasConnected;
  199. #else
  200. public:
  201. const char *GetVoiceCommandSubtitle( int iMenu, int iItem );
  202. bool GetVoiceMenuLabels( int iMenu, KeyValues *pKV );
  203. #endif
  204. private:
  205. CUtlVector< CUtlVector< VoiceCommandMenuItem_t > > m_VoiceCommandMenus;
  206. };
  207. inline CMultiplayRules* MultiplayRules()
  208. {
  209. return static_cast<CMultiplayRules*>(g_pGameRules);
  210. }
  211. #endif // MULTIPLAY_GAMERULES_H