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.

474 lines
13 KiB

  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Shared CS definitions.
  4. //
  5. //=============================================================================//
  6. #ifndef CS_SHAREDDEFS_H
  7. #define CS_SHAREDDEFS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #if !defined (_GAMECONSOLE) && !defined( GC_DLL )
  12. #include "econ_item_view.h"
  13. #endif
  14. #include "csgo_limits.h"
  15. /*======================*/
  16. // Menu stuff //
  17. /*======================*/
  18. #include <game/client/iviewport.h>
  19. #include "cs_achievementdefs.h"
  20. // CS-specific viewport panels
  21. #define PANEL_CHOOSE_CLASS "choose_class"
  22. // Buy sub menus
  23. // #define MENU_PISTOL "menu_pistol"
  24. // #define MENU_SHOTGUN "menu_shotgun"
  25. // #define MENU_RIFLE "menu_rifle"
  26. // #define MENU_SMG "menu_smg"
  27. // #define MENU_MACHINEGUN "menu_mg"
  28. // #define MENU_EQUIPMENT "menu_equip"
  29. #define CSTRIKE_VISUALS_DATA_BYTES 96
  30. #define MAX_HOSTAGES 12
  31. #define MAX_HOSTAGE_RESCUES 4
  32. #define HOSTAGE_RULE_CAN_PICKUP 1
  33. #define MAX_MATCH_STATS_ROUNDS 30
  34. #define MATCH_STATS_TEAM_SWAP_ROUND 15
  35. #define IRONSIGHT // Enable viewmodel ironsight feature
  36. #define GRENADE_UNDERHAND_FEATURE_ENABLED // Enable underhand grenade feature
  37. #define GRENADE_DEFAULT_SIZE 2.0
  38. // Brock H. - TR - 03/31/09
  39. // This will allow the player to control CS bots
  40. #define CS_CONTROLLABLE_BOTS_ENABLED 1
  41. // demo & press build flags
  42. #if !defined( CSTRIKE_DEMO_PRESSBUILD )
  43. #define CSTRIKE_DEMO_PRESSBUILD 0
  44. #endif
  45. // Code for subscribing to SO caches for other players is disabled on the client because
  46. // we don't use it, and the optimization to have the server send all inventory data instead
  47. // of the gc has broken it. If we need that in the future for some reason, re-enable and figure out
  48. // how to network (subscribing is expensive, probably should network from server like dota does).
  49. //#define ENABLE_CLIENT_INVENTORIES_FOR_OTHER_PLAYERS
  50. // E3
  51. #if !defined( CSTRIKE_E3_BUILD )
  52. #define CSTRIKE_E3_BUILD 0
  53. #endif
  54. //=============================================================================
  55. #define CSTRIKE_DEFAULT_AVATAR "avatar_default_64"
  56. #define CSTRIKE_DEFAULT_T_AVATAR "avatar_default-t_64"
  57. #define CSTRIKE_DEFAULT_CT_AVATAR "avatar_default_64"
  58. //=============================================================================
  59. extern const float CS_PLAYER_SPEED_RUN;
  60. extern const float CS_PLAYER_SPEED_VIP;
  61. extern const float CS_PLAYER_SPEED_SHIELD;
  62. extern const float CS_PLAYER_SPEED_STOPPED;
  63. extern const float CS_PLAYER_SPEED_HAS_HOSTAGE;
  64. extern const float CS_PLAYER_SPEED_OBSERVER;
  65. extern const float CS_PLAYER_SPEED_DUCK_MODIFIER;
  66. extern const float CS_PLAYER_SPEED_WALK_MODIFIER;
  67. extern const float CS_PLAYER_SPEED_CLIMB_MODIFIER;
  68. extern const float CS_PLAYER_HEAVYARMOR_FLINCH_MODIFIER;
  69. extern const float CS_PLAYER_DUCK_SPEED_IDEAL;
  70. #ifdef CSTRIKE15
  71. #ifdef CLIENT_DLL
  72. #define OLD_CROUCH_PROTOCOL_INDEX 13546
  73. inline bool IsPreCrouchUpdateDemo( void ) { return (engine->IsHLTV() || engine->IsPlayingDemo()) && engine->GetConnectionDataProtocol() <= OLD_CROUCH_PROTOCOL_INDEX; }
  74. #endif
  75. #endif
  76. template< class T >
  77. class CUtlVectorInitialized : public CUtlVector< T >
  78. {
  79. public:
  80. CUtlVectorInitialized( T* pMemory, int numElements ) : CUtlVector< T >( pMemory, numElements )
  81. {
  82. CUtlVector< T >::SetSize( numElements );
  83. }
  84. };
  85. namespace TeamJoinFailedReason
  86. {
  87. enum Type
  88. {
  89. CHANGED_TOO_OFTEN,
  90. BOTH_TEAMS_FULL,
  91. TERRORISTS_FULL,
  92. CTS_FULL,
  93. CANT_JOIN_SPECTATOR,
  94. HUMANS_CAN_ONLY_JOIN_TS,
  95. HUMANS_CAN_ONLY_JOIN_CTS,
  96. TOO_MANY_TS,
  97. TOO_MANY_CTS,
  98. };
  99. };
  100. #define CS_HOSTAGE_TRANSTIME_PICKUP 0.1
  101. #define CS_HOSTAGE_TRANSTIME_DROP 0.25
  102. #define CS_HOSTAGE_TRANSTIME_RESCUE 4.0
  103. enum EHostageStates_t
  104. {
  105. k_EHostageStates_Idle = 0,
  106. k_EHostageStates_BeingUntied,
  107. k_EHostageStates_GettingPickedUp,
  108. k_EHostageStates_BeingCarried,
  109. k_EHostageStates_FollowingPlayer,
  110. k_EHostageStates_GettingDropped,
  111. k_EHostageStates_Rescued,
  112. k_EHostageStates_Dead,
  113. };
  114. #define CONSTANT_UNITS_SMOKEGRENADERADIUS 166
  115. #define CONSTANT_UNITS_GENERICGRENADERADIUS 115
  116. const float SmokeGrenadeRadius = CONSTANT_UNITS_SMOKEGRENADERADIUS;
  117. const float FlashbangGrenadeRadius = CONSTANT_UNITS_GENERICGRENADERADIUS;
  118. const float HEGrenadeRadius = CONSTANT_UNITS_GENERICGRENADERADIUS;
  119. const float MolotovGrenadeRadius = CONSTANT_UNITS_GENERICGRENADERADIUS;
  120. const float DecoyGrenadeRadius = CONSTANT_UNITS_GENERICGRENADERADIUS;
  121. // These go in CCSPlayer::m_iAddonBits and get sent to the client so it can create
  122. // grenade models hanging off players.
  123. // [mlowrance] Molotov purposely left out
  124. #define ADDON_FLASHBANG_1 0x0001
  125. #define ADDON_FLASHBANG_2 0x0002
  126. #define ADDON_HE_GRENADE 0x0004
  127. #define ADDON_SMOKE_GRENADE 0x0008
  128. #define ADDON_C4 0x0010
  129. #define ADDON_DEFUSEKIT 0x0020
  130. #define ADDON_PRIMARY 0x0040
  131. #define ADDON_PISTOL 0x0080
  132. #define ADDON_PISTOL2 0x0100
  133. #define ADDON_DECOY 0x0200
  134. #define ADDON_KNIFE 0x0400
  135. #define ADDON_MASK 0x0800
  136. #define ADDON_TAGRENADE 0x1000
  137. #define NUM_ADDON_BITS 13
  138. #define ADDON_CLIENTSIDE_HOLIDAY_HAT ( 0x1 << NUM_ADDON_BITS )
  139. #define ADDON_CLIENTSIDE_GHOST ( 0x2 << NUM_ADDON_BITS )
  140. #define ADDON_CLIENTSIDE_ASSASSINATION_TARGET ( 0x4 << NUM_ADDON_BITS )
  141. #define NUM_CLIENTSIDE_ADDON_BITS 3
  142. // Indices of each weapon slot.
  143. #define WEAPON_SLOT_RIFLE 0 // (primary slot)
  144. #define WEAPON_SLOT_PISTOL 1 // (secondary slot)
  145. #define WEAPON_SLOT_KNIFE 2
  146. #define WEAPON_SLOT_GRENADES 3
  147. #define WEAPON_SLOT_C4 4
  148. #define WEAPON_SLOT_FIRST 0
  149. #define WEAPON_SLOT_LAST 4
  150. // CS Team IDs.
  151. #define TEAM_TERRORIST 2
  152. #define TEAM_CT 3
  153. #define TEAM_MAXCOUNT 4 // update this if we ever add teams (unlikely)
  154. #define TEAM_TERRORIST_BASE0 TEAM_TERRORIST - 2
  155. #define TEAM_CT_BASE0 TEAM_CT - 2
  156. // [menglish] CS specific death animation time now that freeze cam is implemented
  157. // in order to linger on the players body less
  158. #define CS_DEATH_ANIMATION_TIME 0.5
  159. // [tj] The number of times you must kill a given player to be dominating them
  160. // Should always be more than 1
  161. #define CS_KILLS_FOR_DOMINATION 4
  162. #define CS_DEATH_DOMINATION 0x0001 // killer is dominating victim
  163. #define CS_DEATH_REVENGE 0x0002 // killer got revenge on victim
  164. //--------------
  165. // CSPort Specific damage flags
  166. //--------------
  167. #define DMG_HEADSHOT (DMG_LASTGENERICFLAG<<1)
  168. struct PlayerViewmodelArmConfig
  169. {
  170. const char *szPlayerModelSearchSubStr;
  171. const char *szSkintoneIndex;
  172. const char *szAssociatedGloveModel;
  173. const char *szAssociatedSleeveModel;
  174. const char *szAssociatedSleeveModelEconOverride;
  175. };
  176. // The various states the player can be in during the join game process.
  177. enum CSPlayerState
  178. {
  179. // Happily running around in the game.
  180. // You can't move though if CSGameRules()->IsFreezePeriod() returns true.
  181. // This state can jump to a bunch of other states like STATE_PICKINGCLASS or STATE_DEATH_ANIM.
  182. STATE_ACTIVE=0,
  183. // This is the state you're in when you first enter the server.
  184. // It's switching between intro cameras every few seconds, and there's a level info
  185. // screen up.
  186. STATE_WELCOME, // Show the level intro screen.
  187. // During these states, you can either be a new player waiting to join, or
  188. // you can be a live player in the game who wants to change teams.
  189. // Either way, you can't move while choosing team or class (or while any menu is up).
  190. STATE_PICKINGTEAM, // Choosing team.
  191. STATE_PICKINGCLASS, // Choosing class.
  192. STATE_DEATH_ANIM, // Playing death anim, waiting for that to finish.
  193. STATE_DEATH_WAIT_FOR_KEY, // Done playing death anim. Waiting for keypress to go into observer mode.
  194. STATE_OBSERVER_MODE, // Noclipping around, watching players, etc.
  195. STATE_GUNGAME_RESPAWN, // Respawning the player in a gun game
  196. STATE_DORMANT, // No thinking, client updates, etc
  197. NUM_PLAYER_STATES
  198. };
  199. enum e_RoundEndReason
  200. {
  201. /*
  202. NOTE/WARNING: these enum values are stored in demo files,
  203. they are explicitly numbered for consistency and editing,
  204. do not renumber existing elements, always add new elements
  205. with different numeric values!
  206. */
  207. Invalid_Round_End_Reason = -1,
  208. RoundEndReason_StillInProgress = 0,
  209. Target_Bombed = 1,
  210. VIP_Escaped = 2,
  211. VIP_Assassinated = 3,
  212. Terrorists_Escaped = 4,
  213. CTs_PreventEscape = 5,
  214. Escaping_Terrorists_Neutralized = 6,
  215. Bomb_Defused = 7,
  216. CTs_Win = 8,
  217. Terrorists_Win = 9,
  218. Round_Draw = 10,
  219. All_Hostages_Rescued = 11,
  220. Target_Saved = 12,
  221. Hostages_Not_Rescued = 13,
  222. Terrorists_Not_Escaped = 14,
  223. VIP_Not_Escaped = 15,
  224. Game_Commencing = 16,
  225. Terrorists_Surrender = 17,
  226. CTs_Surrender = 18,
  227. Terrorists_Planted = 19,
  228. CTs_ReachedHostage = 20,
  229. RoundEndReason_Count = 21,
  230. };
  231. enum GamePhase
  232. {
  233. GAMEPHASE_WARMUP_ROUND,
  234. GAMEPHASE_PLAYING_STANDARD,
  235. GAMEPHASE_PLAYING_FIRST_HALF,
  236. GAMEPHASE_PLAYING_SECOND_HALF,
  237. GAMEPHASE_HALFTIME,
  238. GAMEPHASE_MATCH_ENDED,
  239. GAMEPHASE_MAX
  240. };
  241. enum GrenadeType_t
  242. {
  243. GRENADE_TYPE_EXPLOSIVE,
  244. GRENADE_TYPE_FLASH,
  245. GRENADE_TYPE_FIRE,
  246. GRENADE_TYPE_DECOY,
  247. GRENADE_TYPE_SMOKE,
  248. GRENADE_TYPE_SENSOR,
  249. GRENADE_TYPE_TOTAL,
  250. };
  251. #define PUSHAWAY_THINK_INTERVAL (1.0f / 20.0f)
  252. #define GLOWUPDATE_DEFAULT_THINK_INTERVAL 0.2f
  253. #define CS_MAX_PLAYER_MODELS 10
  254. #define MAX_MODEL_STRING_SIZE 256
  255. #define CS_CLASS_NONE 0
  256. #define MAX_ENDMATCH_VOTE_PANELS 10
  257. const PlayerViewmodelArmConfig *GetPlayerViewmodelArmConfigForPlayerModel( const char* szPlayerModel );
  258. class PlayerModelInfo
  259. {
  260. public:
  261. PlayerModelInfo();
  262. #if !defined( CLIENT_DLL )
  263. bool IsTClass( int classID );
  264. bool IsCTClass( int classID );
  265. int GetFirstTClass( void ) const { return 1; }
  266. int GetFirstCTClass( void ) const { return m_NumTModels + 1; }
  267. int GetFirstClass( void ) const { return GetFirstTClass(); }
  268. int GetLastTClass( void ) const { return m_NumTModels; }
  269. int GetLastCTClass( void ) const { return m_NumTModels + m_NumCTModels; }
  270. int GetLastClass( void ) const { return GetLastCTClass(); }
  271. int GetNextClassForTeam( int team );
  272. const char *GetClassName( int classID );
  273. const char *GetClassModelPath( int classID );
  274. int GetNumTModels( void ) const { return m_NumTModels; }
  275. int GetNumCTModels( void ) const { return m_NumCTModels; }
  276. void InitializeForCurrentMap( void );
  277. private:
  278. void AddModel( const char *modelName );
  279. void SetTViewModelArms( const char *modelName );
  280. void SetCTViewModelArms( const char *modelName );
  281. #endif // !CLIENT_DLL
  282. public:
  283. static const char* g_customizationModelCT;
  284. static const char* g_customizationModelT;
  285. static const char *g_defaultTModel;
  286. static const char *g_defaultCTModel;
  287. static PlayerModelInfo* GetPtr( void ) { return &s_PlayerModelInfo; }
  288. private:
  289. static PlayerModelInfo s_PlayerModelInfo;
  290. #if !defined( CLIENT_DLL )
  291. char m_ClassModelPaths[CS_MAX_PLAYER_MODELS][MAX_MODEL_STRING_SIZE];
  292. char m_ClassNames[CS_MAX_PLAYER_MODELS][MAX_MODEL_STRING_SIZE];
  293. char m_mapName[MAX_MODEL_STRING_SIZE];
  294. int m_NumTModels;
  295. int m_NumCTModels;
  296. int m_NumModels;
  297. int m_nNextClassT;
  298. int m_nNextClassCT;
  299. #endif // !CLIENT_DLL
  300. };
  301. // MVP reasons
  302. enum CSMvpReason_t
  303. {
  304. CSMVP_UNDEFINED = 0,
  305. CSMVP_ELIMINATION,
  306. CSMVP_BOMBPLANT,
  307. CSMVP_BOMBDEFUSE,
  308. CSMVP_HOSTAGERESCUE,
  309. CSMVP_GUNGAMEWINNER,
  310. };
  311. // Keep these in sync with CSClasses.
  312. #define CS_MUZZLEFLASH_NONE -1
  313. #define CS_MUZZLEFLASH_NORM 0
  314. #define CS_MUZZLEFLASH_X 1
  315. extern const char *pszWinPanelCategoryHeaders[];
  316. // Possible results for CSPlayer::CanAcquire
  317. namespace AcquireResult
  318. {
  319. enum Type
  320. {
  321. Allowed,
  322. InvalidItem,
  323. AlreadyOwned,
  324. AlreadyPurchased,
  325. ReachedGrenadeTypeLimit,
  326. ReachedGrenadeTotalLimit,
  327. NotAllowedByTeam,
  328. NotAllowedByMap,
  329. NotAllowedByMode,
  330. NotAllowedForPurchase,
  331. NotAllowedByProhibition,
  332. };
  333. }
  334. // Possible results for CSPlayer::CanAcquire
  335. namespace AcquireMethod
  336. {
  337. enum Type
  338. {
  339. PickUp,
  340. Buy,
  341. };
  342. }
  343. // Results for CSPlayer::CanProgressQuest()
  344. namespace QuestProgress
  345. {
  346. enum Reason
  347. {
  348. // Default value: not initialized yet (game rules or inventory data not yet retrieved)
  349. QUEST_NONINITIALIZED,
  350. // Quest can make progression
  351. QUEST_OK,
  352. // Quest can make progression if more humans connect to server
  353. QUEST_NOT_ENOUGH_PLAYERS,
  354. // Quest can make progression once warmup is ended.
  355. // This is only verified on client, and could be mismatched between client and server.
  356. QUEST_WARMUP,
  357. // No steam account found
  358. QUEST_NOT_CONNECTED_TO_STEAM,
  359. // Playing on community server, quests only enabled on Valve servers
  360. QUEST_NONOFFICIAL_SERVER,
  361. // Don't have the challenge coin
  362. QUEST_NO_ENTITLEMENT,
  363. // User has no active quest
  364. QUEST_NO_QUEST,
  365. // User isn't human
  366. QUEST_PLAYER_IS_BOT,
  367. // Doesn't match state required by quest
  368. QUEST_WRONG_MAP,
  369. QUEST_WRONG_MODE,
  370. // Client thinks it has quest, but the server doesn't know about it
  371. QUEST_NOT_SYNCED_WITH_SERVER,
  372. // Sentinel entry, never used except for maximum size verification
  373. QUEST_REASON_MAX,
  374. };
  375. const int QuestReasonBits = 4;
  376. COMPILE_TIME_ASSERT( QUEST_REASON_MAX <= ( 1 << QuestReasonBits ) );
  377. const char* ReasonString(Reason reason); // for use by UI code, so that values stay consistent if enum changes
  378. }
  379. #endif // CS_SHAREDDEFS_H