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.

469 lines
14 KiB

  1. //====== Copyright (c), Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Holds constants for the econ item system
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. // memdbgon must be the last include file in a .cpp file!!!
  8. #include "tier0/memdbgon.h"
  9. //-----------------------------------------------------------------------------
  10. // Purpose:
  11. //-----------------------------------------------------------------------------
  12. const char *g_szQualityStrings[] =
  13. {
  14. "normal",
  15. "genuine",
  16. "vintage",
  17. "unusual",
  18. "unique",
  19. "community",
  20. "developer",
  21. "selfmade",
  22. "customized",
  23. "strange",
  24. "completed",
  25. "haunted",
  26. "tournament",
  27. "favored"
  28. };
  29. COMPILE_TIME_ASSERT( ARRAYSIZE( g_szQualityStrings ) == AE_MAX_TYPES );
  30. const char *EconQuality_GetQualityString( EEconItemQuality eQuality )
  31. {
  32. // This is a runtime check and not an assert because we could theoretically bounce the GC with new
  33. // qualities while the client is running.
  34. if ( eQuality >= 0 && eQuality < AE_MAX_TYPES )
  35. return g_szQualityStrings[ eQuality ];
  36. return NULL;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. const char *g_szQualityColorStrings[] =
  42. {
  43. "QualityColorNormal",
  44. "QualityColorGenuine",
  45. "QualityColorVintage",
  46. "QualityColorUnusual",
  47. "QualityColorUnique",
  48. "QualityColorCommunity",
  49. "QualityColorDeveloper",
  50. "QualityColorSelfMade",
  51. "QualityColorSelfMadeCustomized",
  52. "QualityColorStrange",
  53. "QualityColorCompleted",
  54. "QualityColorHaunted", // AE_HAUNTED, // same as AE_UNUSUAL
  55. "QualityColorTournament",
  56. "QualityColorFavored",
  57. };
  58. COMPILE_TIME_ASSERT( ARRAYSIZE( g_szQualityColorStrings ) == AE_MAX_TYPES );
  59. const char *EconQuality_GetColorString( EEconItemQuality eQuality )
  60. {
  61. if ( eQuality >= 0 && eQuality < AE_MAX_TYPES )
  62. return g_szQualityColorStrings[ eQuality ];
  63. return NULL;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Purpose:
  67. //-----------------------------------------------------------------------------
  68. const char *g_szQualityLocalizationStrings[] =
  69. {
  70. "#normal",
  71. "#genuine",
  72. "#vintage",
  73. "#unusual",
  74. "#unique",
  75. "#community",
  76. "#developer",
  77. "#selfmade",
  78. "#customized",
  79. "#strange",
  80. "#completed",
  81. "#haunted",
  82. "#tournament",
  83. "#favored"
  84. };
  85. COMPILE_TIME_ASSERT( ARRAYSIZE( g_szQualityLocalizationStrings ) == AE_MAX_TYPES );
  86. const char *EconQuality_GetLocalizationString( EEconItemQuality eQuality )
  87. {
  88. if ( eQuality >= 0 && eQuality < AE_MAX_TYPES )
  89. return g_szQualityLocalizationStrings[ eQuality ];
  90. return NULL;
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Sort order for rarities
  94. //-----------------------------------------------------------------------------
  95. int g_nRarityScores[] =
  96. {
  97. 11, // AE_NORMAL = 0,
  98. 9, // AE_GENUINE = 1,
  99. 5, // AE_VINTAGE
  100. 7, // AE_UNUSUAL,
  101. 0, // AE_UNIQUE,
  102. 2, // AE_COMMUNITY,
  103. 3, // AE_DEVELOPER,
  104. -1, // AE_SELFMADE,
  105. 4, // AE_CUSTOMIZED,
  106. 10, // AE_STRANGE,
  107. 12, // AE_COMPLETED,
  108. 1, // AE_HAUNTED, // same as AE_UNIQUE
  109. 13, // AE_TOURNAMENT,
  110. 14, // AE_FAVORED
  111. };
  112. COMPILE_TIME_ASSERT( ARRAYSIZE( g_nRarityScores ) == AE_MAX_TYPES );
  113. int EconQuality_GetRarityScore( EEconItemQuality eQuality )
  114. {
  115. if ( eQuality >= 0 && eQuality < AE_MAX_TYPES )
  116. return g_nRarityScores[ eQuality ];
  117. return 0;
  118. }
  119. int EconRarity_CombinedItemAndPaintRarity( int nItemDefRarity, int nPaintRarity )
  120. {
  121. return clamp( ( nItemDefRarity + nPaintRarity ) - 1, 0, ( nPaintRarity == 7 ) ? 7 : 6 );
  122. }
  123. int EconWear_ToIntCategory( float flWear )
  124. {
  125. if ( flWear < 0.07f )
  126. {
  127. return 0;
  128. }
  129. else if ( flWear < 0.15f )
  130. {
  131. return 1;
  132. }
  133. else if ( flWear < 0.38f )
  134. {
  135. return 2;
  136. }
  137. else if ( flWear < 0.45f )
  138. {
  139. return 3;
  140. }
  141. else
  142. {
  143. return 4;
  144. }
  145. }
  146. float EconWear_FromIntCategory( int nWearCategory )
  147. {
  148. if ( nWearCategory <= 0 )
  149. return 0.05f;
  150. else if ( nWearCategory == 1 )
  151. return 0.14f;
  152. else if ( nWearCategory == 2 )
  153. return 0.37f;
  154. else if ( nWearCategory == 3 )
  155. return 0.44f;
  156. else
  157. return 0.5f;
  158. }
  159. int EconMinutes_ToRoundMinHrsCategory( float flMinutes )
  160. {
  161. int32 iMinutes = int32( flMinutes );
  162. if ( iMinutes <= 120 )
  163. return iMinutes;
  164. iMinutes /= 60;
  165. iMinutes *= 60;
  166. ++ iMinutes; // this way we round up all minutes above 2 hours to a whole number of hours + 1 minute
  167. return iMinutes;
  168. }
  169. float EconMinutes_FromRoundMinHrsCategory( int nRoundMinHrsCategory )
  170. {
  171. return nRoundMinHrsCategory;
  172. }
  173. int EconTintID_ToRoundCategory( uint32 unTintID )
  174. {
  175. return unTintID & 0xFF;
  176. }
  177. uint32 EconTintID_FromRoundCategory( int nRoundCategory )
  178. {
  179. return nRoundCategory;
  180. }
  181. //-----------------------------------------------------------------------------
  182. // Purpose:
  183. //-----------------------------------------------------------------------------
  184. CSchemaColorDefHandle g_AttribColorDefs[] =
  185. {
  186. CSchemaColorDefHandle( "desc_level" ), // ATTRIB_COL_LEVEL
  187. CSchemaColorDefHandle( "desc_attrib_neutral" ), // ATTRIB_COL_NEUTRAL
  188. CSchemaColorDefHandle( "desc_attrib_positive" ), // ATTRIB_COL_POSITIVE
  189. CSchemaColorDefHandle( "desc_attrib_negative" ), // ATTRIB_COL_NEGATIVE
  190. CSchemaColorDefHandle( "desc_itemset_name" ), // ATTRIB_COL_ITEMSET_NAME
  191. CSchemaColorDefHandle( "desc_itemset_equipped" ), // ATTRIB_COL_ITEMSET_EQUIPPED
  192. CSchemaColorDefHandle( "desc_itemset_missing" ), // ATTRIB_COL_ITEMSET_MISSING
  193. CSchemaColorDefHandle( "desc_bundle" ), // ATTRIB_COL_BUNDLE_ITEM
  194. CSchemaColorDefHandle( "desc_limited_use" ), // ATTRIB_COL_LIMITED_USE
  195. CSchemaColorDefHandle( "desc_flags" ), // ATTRIB_COL_ITEM_FLAGS
  196. CSchemaColorDefHandle( "desc_default" ), // ATTRIB_COL_RARITY_DEFAULT
  197. CSchemaColorDefHandle( "desc_common" ), // ATTRIB_COL_RARITY_COMMON
  198. CSchemaColorDefHandle( "desc_uncommon" ), // ATTRIB_COL_RARITY_UNCOMMON
  199. CSchemaColorDefHandle( "desc_rare" ), // ATTRIB_COL_RARITY_RARE
  200. CSchemaColorDefHandle( "desc_mythical" ), // ATTRIB_COL_RARITY_MYTHICAL
  201. CSchemaColorDefHandle( "desc_legendary" ), // ATTRIB_COL_RARITY_LEGENDARY
  202. CSchemaColorDefHandle( "desc_ancient" ), // ATTRIB_COL_RARITY_ANCIENT
  203. CSchemaColorDefHandle( "desc_immortal" ), // ATTRIB_COL_RARITY_IMMORTAL
  204. CSchemaColorDefHandle( "desc_arcana" ), // ATTRIB_COL_RARITY_ARCANA
  205. CSchemaColorDefHandle( "desc_strange" ), // ATTRIB_COL_STRANGE
  206. CSchemaColorDefHandle( "desc_unusual" ), // ATTRIB_COL_UNUSUAL
  207. };
  208. COMPILE_TIME_ASSERT( ARRAYSIZE( g_AttribColorDefs ) == NUM_ATTRIB_COLORS );
  209. attrib_colors_t GetAttribColorIndexForName( const char* pszName )
  210. {
  211. for ( int i=0; i<NUM_ATTRIB_COLORS; ++i )
  212. {
  213. if ( !Q_strcmp( g_AttribColorDefs[i].GetName(), pszName ) )
  214. return (attrib_colors_t) i;
  215. }
  216. return (attrib_colors_t) 0;
  217. }
  218. const char *GetColorNameForAttribColor( attrib_colors_t unAttribColor )
  219. {
  220. Assert( unAttribColor >= 0 );
  221. Assert( unAttribColor < NUM_ATTRIB_COLORS );
  222. return g_AttribColorDefs[unAttribColor]
  223. ? g_AttribColorDefs[unAttribColor]->GetColorName()
  224. : "ItemAttribNeutral";
  225. }
  226. const char *GetHexColorForAttribColor( attrib_colors_t unAttribColor )
  227. {
  228. Assert( unAttribColor >= 0 );
  229. Assert( unAttribColor < NUM_ATTRIB_COLORS );
  230. return g_AttribColorDefs[unAttribColor]
  231. ? g_AttribColorDefs[unAttribColor]->GetHexColor()
  232. : "#ebe2ca";
  233. }
  234. entityquality_t GetItemQualityFromString( const char *sQuality )
  235. {
  236. for ( int i = 0; i < AE_MAX_TYPES; i++ )
  237. {
  238. if ( !Q_strnicmp( sQuality, g_szQualityStrings[i], 16 ) )
  239. return (entityquality_t)i;
  240. }
  241. return AE_NORMAL;
  242. }
  243. const char *g_szRecipeCategoryStrings[] =
  244. {
  245. "crafting", // RECIPE_CATEGORY_CRAFTINGITEMS = 0,
  246. "commonitem", // RECIPE_CATEGORY_COMMONITEMS,
  247. "rareitem", // RECIPE_CATEGORY_RAREITEMS,
  248. "special", // RECIPE_CATEGORY_SPECIAL,
  249. };
  250. COMPILE_TIME_ASSERT( ARRAYSIZE( g_szRecipeCategoryStrings ) == NUM_RECIPE_CATEGORIES );
  251. //-----------------------------------------------------------------------------
  252. // Item acquisition.
  253. //-----------------------------------------------------------------------------
  254. // Strings shown to the local player in the pickup dialog
  255. const char *g_pszItemPickupMethodStrings[] =
  256. {
  257. "#NewItemMethod_Dropped", // UNACK_ITEM_DROPPED = 1,
  258. "#NewItemMethod_Crafted", // UNACK_ITEM_CRAFTED,
  259. "#NewItemMethod_Traded", // UNACK_ITEM_TRADED,
  260. "#NewItemMethod_Purchased", // UNACK_ITEM_PURCHASED,
  261. "#NewItemMethod_FoundInCrate", // UNACK_ITEM_FOUND_IN_CRATE,
  262. "#NewItemMethod_Gifted", // UNACK_ITEM_GIFTED,
  263. "#NewItemMethod_Support", // UNACK_ITEM_SUPPORT,
  264. "#NewItemMethod_Promotion", // UNACK_ITEM_PROMOTION,
  265. "#NewItemMethod_Earned", // UNACK_ITEM_EARNED,
  266. "#NewItemMethod_Refunded", // UNACK_ITEM_REFUNDED,
  267. "#NewItemMethod_GiftWrapped", // UNACK_ITEM_GIFT_WRAPPED,
  268. "#NewItemMethod_Foreign", // UNACK_ITEM_FOREIGN,
  269. "#NewItemMethod_CollectionReward", // UNACK_ITEM_COLLECTION_REWARD
  270. "#NewItemMethod_PreviewItem", // UNACK_ITEM_PREVIEW_ITEM
  271. "#NewItemMethod_PreviewItemPurchased", // UNACK_ITEM_PREVIEW_ITEM_PURCHASED
  272. "#NewItemMethod_PeriodicScoreReward",// UNACK_ITEM_PERIODIC_SCORE_REWARD
  273. "#NewItemMethod_Recycling", // UNACK_ITEM_RECYCLING
  274. "#NewItemMethod_TournamentDrop", // UNACK_ITEM_TOURNAMENT_DROP
  275. "#NewItemMethod_QuestReward", // UNACK_ITEM_QUEST_REWARD
  276. "#NewItemMethod_LevelUpReward", // UNACK_ITEM_LEVEL_UP_REWARD
  277. #ifdef ENABLE_STORE_RENTAL_BACKEND
  278. "#NewItemMethod_RentalPurchase", // UNACK_ITEM_RENTAL_PURCHASE
  279. #endif
  280. };
  281. COMPILE_TIME_ASSERT( ARRAYSIZE( g_pszItemPickupMethodStrings ) == UNACK_NUM_METHODS );
  282. const char *g_pszItemPickupMethodStringsUnloc[] =
  283. {
  284. "dropped", // UNACK_ITEM_DROPPED = 1,
  285. "crafted", // UNACK_ITEM_CRAFTED,
  286. "traded", // UNACK_ITEM_TRADED,
  287. "purchased", // UNACK_ITEM_PURCHASED,
  288. "found_in_crate", // UNACK_ITEM_FOUND_IN_CRATE,
  289. "gifted", // UNACK_ITEM_GIFTED,
  290. "support", // UNACK_ITEM_SUPPORT,
  291. "promotion", // UNACK_ITEM_PROMOTION,
  292. "earned", // UNACK_ITEM_EARNED,
  293. "refunded", // UNACK_ITEM_REFUNDED,
  294. "gift_wrapped", // UNACK_ITEM_GIFT_WRAPPED
  295. "foreign", // UNACK_ITEM_FOREIGN
  296. "collection_reward",// UNACK_ITEM_COLLECTION_REWARD
  297. "preview_item", // UNACK_ITEM_PREVIEW_ITEM
  298. "preview_item_purchased", // UNACK_ITEM_PREVIEW_ITEM_PURCHASED
  299. "periodic_score_reward", // UNACK_ITEM_PERIODIC_SCORE_REWARD
  300. "recycling", // UNACK_ITEM_RECYCLING
  301. "tournament_drop", // UNACK_ITEM_TOURNAMENT_DROP
  302. "quest_reward", // UNACK_ITEM_QUEST_REWARD
  303. "level_up_reward", // UNACK_ITEM_LEVEL_UP_REWARD
  304. #ifdef ENABLE_STORE_RENTAL_BACKEND
  305. "rental_purchase", // UNACK_ITEM_RENTAL_PURCHASE
  306. #endif
  307. };
  308. COMPILE_TIME_ASSERT( ARRAYSIZE( g_pszItemPickupMethodStringsUnloc ) == UNACK_NUM_METHODS );
  309. // Strings shown to other players in the chat dialog
  310. const char *g_pszItemFoundMethodStrings[] =
  311. {
  312. "#Item_Found", // UNACK_ITEM_DROPPED = 1,
  313. "#Item_Crafted", // UNACK_ITEM_CRAFTED,
  314. "#Item_Traded", // UNACK_ITEM_TRADED,
  315. NULL, // UNACK_ITEM_PURCHASED,
  316. "#Item_FoundInCrate", // UNACK_ITEM_FOUND_IN_CRATE,
  317. "#Item_Gifted", // UNACK_ITEM_GIFTED,
  318. NULL, // UNACK_ITEM_SUPPORT,
  319. NULL, // UNACK_ITEM_PROMOTION
  320. "#Item_Earned", // UNACK_ITEM_EARNED
  321. "#Item_Refunded", // UNACK_ITEM_REFUNDED
  322. "#Item_GiftWrapped", // UNACK_ITEM_GIFT_WRAPPED
  323. "#Item_Foreign", // UNACK_ITEM_FOREIGN
  324. "#Item_CollectionReward", // UNACK_ITEM_COLLECTION_REWARD
  325. "#Item_PreviewItem", // UNACK_ITEM_PREVIEW_ITEM
  326. "#Item_PreviewItemPurchased",// UNACK_ITEM_PREVIEW_ITEM_PURCHASED
  327. "#Item_PeriodicScoreReward",// UNACK_ITEM_PERIODIC_SCORE_REWARD
  328. "#Item_Recycling", // UNACK_ITEM_RECYCLING
  329. "#Item_TournamentDrop", // UNACK_ITEM_TOURNAMENT_DROP
  330. "#Item_QuestReward", // UNACK_ITEM_QUEST_REWARD
  331. "#Item_LevelUpReward", // UNACK_ITEM_LEVEL_UP_REWARD
  332. #ifdef ENABLE_STORE_RENTAL_BACKEND
  333. NULL, // UNACK_ITEM_RENTAL_PURCHASE
  334. #endif
  335. };
  336. //-----------------------------------------------------------------------------
  337. // Purpose:
  338. //-----------------------------------------------------------------------------
  339. struct kill_eater_attr_pair_t
  340. {
  341. kill_eater_attr_pair_t( const char *pScoreAttrName, const char *pTypeAttrName, bool bIsUserCustomizable )
  342. : m_attrScore( pScoreAttrName )
  343. , m_attrType( pTypeAttrName )
  344. , m_bIsUserCustomizable( bIsUserCustomizable )
  345. {
  346. //
  347. }
  348. CSchemaAttributeDefHandle m_attrScore;
  349. CSchemaAttributeDefHandle m_attrType;
  350. bool m_bIsUserCustomizable;
  351. };
  352. kill_eater_attr_pair_t g_KillEaterAttr[] =
  353. {
  354. kill_eater_attr_pair_t( "kill eater", "kill eater score type", false ),
  355. // kill_eater_attr_pair_t( "kill eater 2", "kill eater score type 2", false ),
  356. //
  357. // // assumption: all of the user-customizable attributes will follow all of the schema-specified attributes
  358. // kill_eater_attr_pair_t( "kill eater user 1", "kill eater user score type 1", true ),
  359. // kill_eater_attr_pair_t( "kill eater user 2", "kill eater user score type 2", true ),
  360. // kill_eater_attr_pair_t( "kill eater user 3", "kill eater user score type 3", true ),
  361. };
  362. int GetKillEaterAttrPairCount()
  363. {
  364. return ARRAYSIZE( g_KillEaterAttr );
  365. }
  366. const CEconItemAttributeDefinition *GetKillEaterAttrPair_Score( int i )
  367. {
  368. Assert( i >= 0 );
  369. Assert( i < GetKillEaterAttrPairCount() );
  370. return g_KillEaterAttr[i].m_attrScore;
  371. }
  372. const CEconItemAttributeDefinition *GetKillEaterAttrPair_Type( int i )
  373. {
  374. Assert( i >= 0 );
  375. Assert( i < GetKillEaterAttrPairCount() );
  376. return g_KillEaterAttr[i].m_attrType;
  377. }
  378. bool GetKillEaterAttrPair_IsUserCustomizable( int i )
  379. {
  380. Assert( i >= 0 );
  381. Assert( i < GetKillEaterAttrPairCount() );
  382. return g_KillEaterAttr[i].m_bIsUserCustomizable;
  383. }
  384. bool EventRequiresVictim( kill_eater_event_t ke_event )
  385. {
  386. switch( ke_event )
  387. {
  388. case kKillEaterEvent_MVPs:
  389. return false;
  390. default:
  391. break;
  392. }
  393. return true;
  394. }
  395. // -----------------------------------------------------------------------------
  396. // Purpose: convert the paint color float into rgb string. Char buffer should be at least 7 char long
  397. // -----------------------------------------------------------------------------
  398. void GetHexStringFromPaintColor( float flPaint, char *pszRGB )
  399. {
  400. uint32 unValue = (uint32)flPaint;
  401. Color rgb;
  402. rgb.SetRawColor( unValue );
  403. // it appears to be in bgr instead of rgb, so reverse the values when we read them out here
  404. byte b = rgb.r();
  405. byte g = rgb.g();
  406. byte r = rgb.b();
  407. V_binarytohex( &r, 1, pszRGB, 3 );
  408. V_binarytohex( &g, 1, pszRGB + 2, 3 );
  409. V_binarytohex( &b, 1, pszRGB + 4, 3 );
  410. }