Counter Strike : Global Offensive Source Code
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.

261 lines
8.6 KiB

  1. //========= Copyright � 1996-2005, 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_waitingforplayers_time;
  17. extern ConVar mp_waitingforplayers_restart;
  18. extern ConVar mp_waitingforplayers_cancel;
  19. extern ConVar mp_clan_readyrestart;
  20. extern ConVar mp_clan_ready_signal;
  21. extern ConVar nextlevel;
  22. #define VOICE_COMMAND_MAX_SUBTITLE_DIST 1900
  23. class CBaseMultiplayerPlayer;
  24. #endif
  25. #define MAX_SPEAK_CONCEPT_LEN 64
  26. #define MAX_VOICE_COMMAND_SUBTITLE 256
  27. typedef struct
  28. {
  29. #ifndef CLIENT_DLL
  30. // concept to speak
  31. int m_iConcept;
  32. // play subtitle?
  33. bool m_bShowSubtitle;
  34. bool m_bDistanceBasedSubtitle;
  35. char m_szGestureActivity[64];
  36. #else
  37. // localizable subtitle
  38. char m_szSubtitle[MAX_VOICE_COMMAND_SUBTITLE];
  39. // localizable string for menu
  40. char m_szMenuLabel[MAX_VOICE_COMMAND_SUBTITLE];
  41. #endif
  42. } VoiceCommandMenuItem_t;
  43. extern ConVar mp_timelimit;
  44. //
  45. class CBaseMultiplayerPlayer;
  46. class CSameTeamGroup
  47. {
  48. public:
  49. CSameTeamGroup();
  50. CSameTeamGroup( const CSameTeamGroup &src );
  51. // Different users will require different logic for whom to add (e.g., all SplitScreen players on same team, or all Steam Friends on same team)
  52. virtual void Build( CGameRules *pGameRules, CBasePlayer *pl ) = 0;
  53. virtual void MaybeAddPlayer( CBasePlayer *pl ) = 0;
  54. CBasePlayer *GetPlayer( int idx );
  55. int Count() const;
  56. int Score() const;
  57. static bool Less( const CSameTeamGroup &p1, const CSameTeamGroup &p2 );
  58. protected:
  59. CUtlVector< CBasePlayer * > m_Players;
  60. int m_nScore;
  61. };
  62. //=========================================================
  63. // CMultiplayRules - rules for the basic half life multiplayer
  64. // competition
  65. //=========================================================
  66. class CMultiplayRules : public CGameRules
  67. {
  68. public:
  69. DECLARE_CLASS( CMultiplayRules, CGameRules );
  70. // Functions to verify the single/multiplayer status of a game
  71. virtual bool IsMultiplayer( void );
  72. // Damage query implementations.
  73. virtual bool Damage_IsTimeBased( int iDmgType ); // Damage types that are time-based.
  74. virtual bool Damage_ShouldGibCorpse( int iDmgType ); // Damage types that gib the corpse.
  75. virtual bool Damage_ShowOnHUD( int iDmgType ); // Damage types that have client HUD art.
  76. virtual bool Damage_NoPhysicsForce( int iDmgType ); // Damage types that don't have to supply a physics force & position.
  77. virtual bool Damage_ShouldNotBleed( int iDmgType ); // Damage types that don't make the player bleed.
  78. // TEMP: These will go away once DamageTypes become enums.
  79. virtual int Damage_GetTimeBased( void );
  80. virtual int Damage_GetShouldGibCorpse( void );
  81. virtual int Damage_GetShowOnHud( void );
  82. virtual int Damage_GetNoPhysicsForce( void );
  83. virtual int Damage_GetShouldNotBleed( void );
  84. CMultiplayRules();
  85. virtual ~CMultiplayRules() {}
  86. void LoadVoiceCommandScript( void );
  87. #ifndef CLIENT_DLL
  88. // GR_Think
  89. virtual void Think( void );
  90. virtual void RefreshSkillData( bool forceUpdate );
  91. virtual bool IsAllowedToSpawn( CBaseEntity *pEntity );
  92. virtual bool FAllowFlashlight( void );
  93. virtual bool FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );
  94. virtual CBaseCombatWeapon *GetNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon );
  95. bool SwitchToNextBestWeapon( CBaseCombatCharacter *pPlayer, CBaseCombatWeapon *pCurrentWeapon );
  96. // Functions to verify the single/multiplayer status of a game
  97. virtual bool IsDeathmatch( void );
  98. virtual bool IsCoOp( void );
  99. // Client connection/disconnection
  100. // If ClientConnected returns FALSE, the connection is rejected and the user is provided the reason specified in
  101. // svRejectReason
  102. // Only the client's name and remote address are provided to the dll for verification.
  103. virtual bool ClientConnected( edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
  104. virtual void InitHUD( CBasePlayer *pl ); // the client dll is ready for updating
  105. virtual void ClientDisconnected( edict_t *pClient );
  106. // Client damage rules
  107. virtual float FlPlayerFallDamage( CBasePlayer *pPlayer );
  108. virtual bool FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker );
  109. virtual bool AllowDamage( CBaseEntity *pVictim, const CTakeDamageInfo &info );
  110. // Client spawn/respawn control
  111. virtual void PlayerSpawn( CBasePlayer *pPlayer );
  112. virtual void PlayerThink( CBasePlayer *pPlayer );
  113. virtual bool FPlayerCanRespawn( CBasePlayer *pPlayer );
  114. virtual float FlPlayerSpawnTime( CBasePlayer *pPlayer );
  115. virtual CBaseEntity *GetPlayerSpawnSpot( CBasePlayer *pPlayer );
  116. virtual bool AllowAutoTargetCrosshair( void );
  117. // Client kills/scoring
  118. virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled );
  119. virtual void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  120. virtual void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info );
  121. CBasePlayer *GetDeathScorer( CBaseEntity *pKiller, CBaseEntity *pInflictor ); // old version of method - kept for backward compat
  122. virtual CBasePlayer *GetDeathScorer( CBaseEntity *pKiller, CBaseEntity *pInflictor, CBaseEntity *pVictim ); // new version of method
  123. // Weapon retrieval
  124. virtual bool CanHavePlayerItem( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );// The player is touching an CBaseCombatWeapon, do I give it to him?
  125. // Weapon spawn/respawn control
  126. virtual int WeaponShouldRespawn( CBaseCombatWeapon *pWeapon );
  127. virtual float FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon );
  128. virtual float FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon );
  129. virtual Vector VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon );
  130. // Item retrieval
  131. virtual bool CanHaveItem( CBasePlayer *pPlayer, CItem *pItem );
  132. virtual void PlayerGotItem( CBasePlayer *pPlayer, CItem *pItem );
  133. // Item spawn/respawn control
  134. virtual int ItemShouldRespawn( CItem *pItem );
  135. virtual float FlItemRespawnTime( CItem *pItem );
  136. virtual Vector VecItemRespawnSpot( CItem *pItem );
  137. virtual QAngle VecItemRespawnAngles( CItem *pItem );
  138. // Ammo retrieval
  139. virtual void PlayerGotAmmo( CBaseCombatCharacter *pPlayer, char *szName, int iCount );
  140. // Healthcharger respawn control
  141. virtual float FlHealthChargerRechargeTime( void );
  142. virtual float FlHEVChargerRechargeTime( void );
  143. // What happens to a dead player's weapons
  144. virtual int DeadPlayerWeapons( CBasePlayer *pPlayer );
  145. // What happens to a dead player's ammo
  146. virtual int DeadPlayerAmmo( CBasePlayer *pPlayer );
  147. // Teamplay stuff
  148. virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget );
  149. virtual bool PlayerCanHearChat( CBasePlayer *pListener, CBasePlayer *pSpeaker, bool bTeamOnly );
  150. virtual bool PlayTextureSounds( void ) { return FALSE; }
  151. virtual bool PlayFootstepSounds( CBasePlayer *pl );
  152. // NPCs
  153. virtual bool FAllowNPCs( void );
  154. // Immediately end a multiplayer game
  155. virtual void EndMultiplayerGame( void ) { GoToIntermission(); }
  156. // Voice commands
  157. virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args );
  158. virtual VoiceCommandMenuItem_t *VoiceCommand( CBaseMultiplayerPlayer *pPlayer, int iMenu, int iItem );
  159. // Bugbait report
  160. bool IsLoadingBugBaitReport( void );
  161. virtual void ResetMapCycleTimeStamp( void ){ m_nMapCycleTimeStamp = 0; }
  162. virtual void HandleTimeLimitChange( void ){ return; }
  163. void IncrementMapCycleIndex();
  164. void HaveAllPlayersSpeakConceptIfAllowed( int iConcept );
  165. virtual void GetTaggedConVarList( KeyValues *pCvarTagList );
  166. void SkipNextMapInCycle();
  167. virtual float GetIntermissionStartTime() const { return m_flIntermissionStartTime; };
  168. virtual bool OnReplayPrompt( CBasePlayer *pVictim, CBasePlayer *pScorer );
  169. protected:
  170. virtual bool UseSuicidePenalty() { return true; } // apply point penalty for suicide?
  171. virtual void GetNextLevelName( char *szNextMap, int bufsize, bool bRandom = false );
  172. virtual void ChangeLevel( void );
  173. virtual void GoToIntermission( void );
  174. float GetIntermissionDuration() const;
  175. float m_flIntermissionStartTime;
  176. static int m_nMapCycleTimeStamp;
  177. static int m_nMapCycleindex;
  178. static CUtlStringList m_MapList;
  179. const char* m_szNextLevelName;
  180. #else
  181. public:
  182. const char *GetVoiceCommandSubtitle( int iMenu, int iItem );
  183. bool GetVoiceMenuLabels( int iMenu, KeyValues *pKV );
  184. #endif
  185. private:
  186. CUtlVector< CUtlVector< VoiceCommandMenuItem_t > > m_VoiceCommandMenus;
  187. };
  188. inline CMultiplayRules* MultiplayRules()
  189. {
  190. return static_cast<CMultiplayRules*>(g_pGameRules);
  191. }
  192. #endif // MULTIPLAY_GAMERULES_H