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.

398 lines
8.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CSLOADOUT_H
  8. #define CSLOADOUT_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. const int cMaxEquipment = 6; // if this # changes, bump version # cl_titledataversionblock3 and loadoutData in TitleData1 block for title data storageCCSSteamStats::SyncCSLoadoutsToTitleData
  13. const int cMaxLoadouts = 4; // if this # changes, bump version # cl_titledataversionblock3 and loadoutData in TitleData1 block for title data storageCCSSteamStats::SyncCSLoadoutsToTitleData
  14. class CCSEquipmentLoadout
  15. {
  16. public:
  17. CCSEquipmentLoadout()
  18. {
  19. ClearLoadout();
  20. }
  21. void ClearLoadout( void )
  22. {
  23. SetEquipmentID( WEAPON_NONE );
  24. }
  25. CCSEquipmentLoadout& operator=( const CCSEquipmentLoadout& in_rhs )
  26. {
  27. m_EquipmentID = in_rhs.m_EquipmentID;
  28. m_EquipmentPos = in_rhs.m_EquipmentPos;
  29. m_Quantity = in_rhs.m_Quantity;
  30. return *this;
  31. }
  32. bool isEmpty() const
  33. {
  34. return ( ( GetEquipmentID() == WEAPON_NONE ) || ( GetQuantity() == 0 ) );
  35. }
  36. CSWeaponID GetEquipmentID() const
  37. {
  38. return m_EquipmentID;
  39. }
  40. void SetEquipmentID( CSWeaponID newid )
  41. {
  42. m_EquipmentID = newid;
  43. if ( newid == WEAPON_NONE )
  44. {
  45. m_Quantity = 0;
  46. }
  47. }
  48. int GetEquipmentPos() const
  49. {
  50. return m_EquipmentPos;
  51. }
  52. void SetEquipmentPos( int pos )
  53. {
  54. m_EquipmentPos = pos;
  55. }
  56. int GetQuantity() const
  57. {
  58. return m_Quantity;
  59. }
  60. void SetQuantity( int value )
  61. {
  62. m_Quantity = value;
  63. if ( !m_Quantity )
  64. {
  65. m_EquipmentID = WEAPON_NONE;
  66. m_EquipmentPos = 0;
  67. }
  68. }
  69. CSWeaponID m_EquipmentID;
  70. int m_EquipmentPos;
  71. int m_Quantity;
  72. };
  73. inline const bool operator==( const CCSEquipmentLoadout& me, const CCSEquipmentLoadout& them )
  74. {
  75. return ( ( me.GetEquipmentID() == them.GetEquipmentID() ) && ( me.GetQuantity() == them.GetQuantity() ) );
  76. }
  77. inline const bool operator!=( const CCSEquipmentLoadout& me, const CCSEquipmentLoadout& them )
  78. {
  79. return !( me == them );
  80. }
  81. class CCSLoadout
  82. {
  83. protected:
  84. enum
  85. {
  86. HAS_TASER = 0x1,
  87. HAS_BOMB = 0x2,
  88. HAS_DEFUSE = 0x4,
  89. };
  90. bool GetFlag( uint8 flag ) const
  91. {
  92. return ( m_flags & flag ) != 0;
  93. }
  94. void SetFlag( uint8 flag, bool setIt )
  95. {
  96. m_flags &= ~flag;
  97. if ( setIt )
  98. m_flags |= flag;
  99. }
  100. public:
  101. CCSLoadout()
  102. {
  103. ClearLoadout();
  104. }
  105. void ClearLoadout( void )
  106. {
  107. m_primaryWeaponID = WEAPON_NONE;
  108. m_secondaryWeaponID = WEAPON_NONE;
  109. m_primaryWeaponItemPos = 0;
  110. m_secondaryWeaponItemPos = 0;
  111. m_flags = 0;
  112. for ( int i = 0; i < cMaxEquipment; i++ )
  113. {
  114. m_EquipmentArray[i].ClearLoadout();
  115. }
  116. }
  117. CCSLoadout& operator=( const CCSLoadout& in_rhs )
  118. {
  119. m_primaryWeaponID = in_rhs.m_primaryWeaponID;
  120. m_secondaryWeaponID = in_rhs.m_secondaryWeaponID;
  121. m_primaryWeaponItemPos = in_rhs.m_primaryWeaponItemPos;
  122. m_secondaryWeaponItemPos = in_rhs.m_secondaryWeaponItemPos;
  123. m_flags = in_rhs.m_flags;
  124. for ( int i = 0; i < cMaxEquipment; i++ )
  125. {
  126. m_EquipmentArray[i] = in_rhs.m_EquipmentArray[i];
  127. }
  128. return *this;
  129. }
  130. bool operator==( const CCSLoadout& in_rhs ) const
  131. {
  132. if ( m_primaryWeaponID != in_rhs.m_primaryWeaponID )
  133. {
  134. return false;
  135. }
  136. if ( m_secondaryWeaponID != in_rhs.m_secondaryWeaponID )
  137. {
  138. return false;
  139. }
  140. if ( m_flags != in_rhs.m_flags )
  141. {
  142. return false;
  143. }
  144. for ( int i = 0; i < cMaxEquipment; i++ )
  145. {
  146. if ( m_EquipmentArray[i].GetEquipmentID() != WEAPON_NONE )
  147. {
  148. bool bMatch = false;
  149. for ( int j = 0; j < cMaxEquipment; j++ )
  150. {
  151. if ( in_rhs.m_EquipmentArray[j] == m_EquipmentArray[i] )
  152. bMatch = true;
  153. }
  154. if ( bMatch == false )
  155. {
  156. return false;
  157. }
  158. }
  159. }
  160. for ( int i = 0; i < cMaxEquipment; i++ )
  161. {
  162. if ( in_rhs.m_EquipmentArray[i].GetEquipmentID() != WEAPON_NONE )
  163. {
  164. bool bMatch = false;
  165. for ( int j = 0; j < cMaxEquipment; j++ )
  166. {
  167. if ( m_EquipmentArray[j] == in_rhs.m_EquipmentArray[i] )
  168. bMatch = true;
  169. }
  170. if ( bMatch == false )
  171. {
  172. return false;
  173. }
  174. }
  175. }
  176. return true;
  177. }
  178. inline bool operator!=( const CCSLoadout& in_rhs ) const
  179. {
  180. return !( *this == in_rhs );
  181. }
  182. bool isEmpty() const
  183. {
  184. if ( m_primaryWeaponID != WEAPON_NONE )
  185. {
  186. return false;
  187. }
  188. if ( m_secondaryWeaponID != WEAPON_NONE )
  189. {
  190. return false;
  191. }
  192. for ( int i = 0; i < cMaxEquipment; i++ )
  193. {
  194. if ( !m_EquipmentArray[i].isEmpty() )
  195. return false;
  196. }
  197. if ( m_flags )
  198. {
  199. return false;
  200. }
  201. return true;
  202. }
  203. int CountUniqueEquipment( void ) const
  204. {
  205. int result = 0;
  206. for ( result = 0; result < cMaxEquipment; result++ )
  207. {
  208. if ( m_EquipmentArray[result].isEmpty() )
  209. return result;
  210. }
  211. return 0;
  212. }
  213. bool GetHasTaser( void ) const
  214. {
  215. return GetFlag( HAS_TASER );
  216. }
  217. void SetHasTaser( bool value )
  218. {
  219. SetFlag( HAS_TASER, value );
  220. }
  221. bool GetHasBomb( void ) const
  222. {
  223. return GetFlag( HAS_BOMB );
  224. }
  225. void SetHasBomb( bool value )
  226. {
  227. SetFlag( HAS_BOMB, value );
  228. }
  229. bool GetHasDefuser( void ) const
  230. {
  231. return GetFlag( HAS_DEFUSE );
  232. }
  233. void SetHasDefuser( bool value )
  234. {
  235. SetFlag( HAS_DEFUSE, value );
  236. }
  237. CSWeaponID ReportFirstWeapon( void )
  238. {
  239. if ( m_primaryWeaponID )
  240. return m_primaryWeaponID;
  241. else if ( m_secondaryWeaponID )
  242. return m_secondaryWeaponID;
  243. else if ( GetHasTaser() )
  244. return WEAPON_TASER;
  245. else
  246. return m_EquipmentArray[0].GetEquipmentID();
  247. }
  248. // Data fields
  249. CSWeaponID m_primaryWeaponID;
  250. CSWeaponID m_secondaryWeaponID;
  251. int m_primaryWeaponItemPos;
  252. int m_secondaryWeaponItemPos;
  253. CCSEquipmentLoadout m_EquipmentArray[cMaxEquipment];
  254. uint8 m_flags;
  255. };
  256. class CCSBuyMenuLoadout
  257. {
  258. public:
  259. CCSBuyMenuLoadout()
  260. {
  261. ClearLoadout();
  262. }
  263. void ClearLoadout( void )
  264. {
  265. for ( int i = 0; i < ARRAYSIZE( m_WeaponID ); i++ )
  266. {
  267. m_WeaponID[ i ] = WEAPON_NONE;
  268. }
  269. }
  270. CCSBuyMenuLoadout& operator=( const CCSBuyMenuLoadout& in_rhs )
  271. {
  272. for ( int i = 0; i < ARRAYSIZE( m_WeaponID ); i++ )
  273. {
  274. m_WeaponID[ i ] = in_rhs.m_WeaponID[ i ];
  275. }
  276. return *this;
  277. }
  278. bool operator==( const CCSBuyMenuLoadout& in_rhs ) const
  279. {
  280. for ( int i = 0; i < ARRAYSIZE( m_WeaponID ); i++ )
  281. {
  282. if ( m_WeaponID[ i ] != in_rhs.m_WeaponID[ i ] )
  283. {
  284. return false;
  285. }
  286. }
  287. return true;
  288. }
  289. inline bool operator!=( const CCSBuyMenuLoadout& in_rhs ) const
  290. {
  291. return !( *this == in_rhs );
  292. }
  293. CEconItemView * GetWeaponView( loadout_positions_t pos, int nTeamNumber ) const;
  294. // Data fields
  295. itemid_t m_WeaponID[ LOADOUT_POSITION_COUNT ];
  296. };
  297. inline CEconItemView * CCSBuyMenuLoadout::GetWeaponView( loadout_positions_t pos, int nTeamNumber ) const
  298. {
  299. int nPos = pos;
  300. if ( ( nPos < 0 ) || ( nPos >= LOADOUT_POSITION_COUNT ) )
  301. return NULL;
  302. if ( !CSInventoryManager() || !CSInventoryManager()->GetLocalCSInventory() )
  303. return NULL;
  304. if ( m_WeaponID[ nPos ] == INVALID_ITEM_ID )
  305. return NULL;
  306. CEconItemView * pItemView = CSInventoryManager()->GetLocalCSInventory()->GetInventoryItemByItemID( m_WeaponID[ nPos ] );
  307. if ( pItemView && pItemView->IsValid() )
  308. {
  309. return pItemView;
  310. }
  311. else if ( CombinedItemIdIsDefIndexAndPaint( m_WeaponID[ nPos ] ) )
  312. {
  313. return CSInventoryManager()->FindOrCreateReferenceEconItem( m_WeaponID[ nPos ] );
  314. }
  315. else if ( CEconItemView * pItemView = CSInventoryManager()->GetItemInLoadoutForTeam( nTeamNumber, nPos ) )
  316. {
  317. return pItemView;
  318. }
  319. else
  320. return NULL;
  321. }
  322. extern CCSLoadout* GetBuyMenuLoadoutData( int in_teamID );
  323. #endif //CSLOADOUT_H