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.

946 lines
34 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TFITEMSCHEMA_H
  8. #define TFITEMSCHEMA_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "econ_item_schema.h"
  13. #include "tf_item_constants.h"
  14. #include "tf_shareddefs.h"
  15. #include "tf_matchmaking_shared.h"
  16. #ifndef GC_DLL
  17. #include "util_shared.h"
  18. #endif
  19. const int k_iMvmMissionIndex_Any = -1;
  20. const int k_iMvmMissionIndex_NotInSchema = -2;
  21. //#ifndef STAGING_ONLY
  22. #define USE_MVM_TOUR 1
  23. //#endif // !STAGING_ONLY
  24. const int k_iMvmTourIndex_Empty = -1; // empty tour name
  25. const int k_iMvmTourIndex_NotInSchema = -2;
  26. const int k_iMvmTourIndex_NotMannedUp = -3; // special value used when asking for the selected tour when not manned up
  27. const uint32 k_unMvMMaxPointsPerBadgeLevel = 3; // require 3 missions to level up a badge
  28. class CRandomChanceString
  29. {
  30. public:
  31. CRandomChanceString();
  32. void AddString( const char *pszString, int nChance );
  33. const char *GetRandomString() const;
  34. private:
  35. CUtlVector< std::pair< const char *, int > > m_vecChoices;
  36. int m_unTotalChance;
  37. };
  38. class CTFTauntInfo
  39. {
  40. public:
  41. CTFTauntInfo();
  42. bool BInitFromKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  43. int GetIntroSceneCount( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_vecIntroScenes[iClass].Count(); }
  44. const char *GetIntroScene( int iClass, int iSceneIndex ) const
  45. {
  46. Assert( iSceneIndex >= 0 && iSceneIndex < GetIntroSceneCount( iClass ) );
  47. return m_vecIntroScenes[iClass][iSceneIndex];
  48. }
  49. int GetOutroSceneCount( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_vecOutroScenes[iClass].Count(); }
  50. const char *GetOutroScene( int iClass, int iSceneIndex ) const
  51. {
  52. Assert( iSceneIndex >= 0 && iSceneIndex < GetOutroSceneCount( iClass ) );
  53. return m_vecOutroScenes[iClass][iSceneIndex];
  54. }
  55. int GetPartnerTauntInitiatorSceneCount( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_vecPartnerTauntInitiatorScenes[iClass].Count(); }
  56. const char *GetPartnerTauntInitiatorScene( int iClass, int iSceneIndex ) const
  57. {
  58. Assert( iSceneIndex >= 0 && iSceneIndex < GetPartnerTauntInitiatorSceneCount( iClass ) );
  59. return m_vecPartnerTauntInitiatorScenes[iClass][iSceneIndex];
  60. }
  61. int GetPartnerTauntReceiverSceneCount( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_vecPartnerTauntReceiverScenes[iClass].Count(); }
  62. const char *GetPartnerTauntReceiverScene( int iClass, int iSceneIndex ) const
  63. {
  64. Assert( iSceneIndex >= 0 && iSceneIndex < GetPartnerTauntReceiverSceneCount( iClass ) );
  65. return m_vecPartnerTauntReceiverScenes[iClass][iSceneIndex];
  66. }
  67. const char *GetProp( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_pszProp[iClass]; }
  68. const char *GetPropIntroScene( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_pszPropIntroScene[iClass]; }
  69. const char *GetPropOutroScene( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_pszPropOutroScene[iClass]; }
  70. float GetTauntSeparationForwardDistance() const { return m_flTauntSeparationForwardDistance; }
  71. float GetTauntSeparationRightDistance() const { return m_flTauntSeparationRightDistance; }
  72. float GetMinTauntTime() const { return m_flMinTauntTime; }
  73. bool IsPartnerTaunt() const { return m_bIsPartnerTaunt; }
  74. bool ShouldStopTauntIfMoved() const { return m_bStopTauntIfMoved; }
  75. int GetFOV() const { return m_nFOV; }
  76. float GetCameraDist() const { return m_flCameraDist; }
  77. float GetCameraDistUp() const { return m_flCameraDistUp; }
  78. const char *GetParticleAttachment() const { return m_pszParticleAttachment; }
  79. struct TauntInputRemap_t
  80. {
  81. TauntInputRemap_t()
  82. {
  83. m_iButton = 0;
  84. }
  85. int m_iButton;
  86. CUtlVector< const char* > m_vecButtonPressedScenes[LOADOUT_COUNT];
  87. CUtlVector< const char* > m_vecButtonReleasedScenes[LOADOUT_COUNT];
  88. };
  89. int GetTauntInputRemapCount() const { return m_vecTauntInputRemap.Count(); }
  90. const TauntInputRemap_t &GetTauntInputRemapScene( int iButtonIndex ) const
  91. {
  92. return m_vecTauntInputRemap[iButtonIndex];
  93. }
  94. private:
  95. bool InitTauntInputRemap( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  96. CUtlVector< const char* > m_vecIntroScenes[LOADOUT_COUNT];
  97. CUtlVector< const char* > m_vecOutroScenes[LOADOUT_COUNT];
  98. CUtlVector< const char* > m_vecPartnerTauntInitiatorScenes[LOADOUT_COUNT];
  99. CUtlVector< const char* > m_vecPartnerTauntReceiverScenes[LOADOUT_COUNT];
  100. CUtlVector< TauntInputRemap_t > m_vecTauntInputRemap;
  101. const char *m_pszProp[LOADOUT_COUNT];
  102. const char *m_pszPropIntroScene[LOADOUT_COUNT];
  103. const char *m_pszPropOutroScene[LOADOUT_COUNT];
  104. const char *m_pszParticleAttachment;
  105. float m_flTauntSeparationForwardDistance;
  106. float m_flTauntSeparationRightDistance;
  107. float m_flMinTauntTime;
  108. bool m_bIsPartnerTaunt;
  109. bool m_bStopTauntIfMoved;
  110. int m_nFOV;
  111. float m_flCameraDist;
  112. float m_flCameraDistUp;
  113. };
  114. class CQuestThemeDefinition
  115. {
  116. public:
  117. CQuestThemeDefinition( void );
  118. virtual ~CQuestThemeDefinition( void );
  119. bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  120. const char *GetName() const { return m_pszName; }
  121. const char *GetNotificationResFile() const { return m_pszNotificationRes; }
  122. const char *GetQuestItemResFile() const { return m_pszQuestItemRes; }
  123. const char *GetInGameTrackerResFile() const { return m_pszInGameTrackerRes; }
  124. unacknowledged_item_inventory_positions_t GetUnackPos() const { return m_eUnackPos; }
  125. #ifndef GC_DLL
  126. const char *GetGiveSoundForClass( int iClass ) const { return UTIL_GetRandomSoundFromEntry( m_vecGiveStrings[ iClass ].GetRandomString() ); }
  127. const char *GetCompleteSoundForClass( int iClass ) const { return UTIL_GetRandomSoundFromEntry( m_vecCompleteStrings[ iClass ].GetRandomString() ); }
  128. const char *GetFullyCompleteSoundForClass( int iClass ) const { return UTIL_GetRandomSoundFromEntry( m_vecFullyCompleteStrings[ iClass ].GetRandomString() ); }
  129. const char *GetDiscardSound() const { return UTIL_GetRandomSoundFromEntry( m_pszDiscardString ); }
  130. const char *GetRewardSound() const { return UTIL_GetRandomSoundFromEntry( m_pszRewardString ); }
  131. const char *GetRevealSound() const { return UTIL_GetRandomSoundFromEntry( m_pszOnRevealText ); }
  132. #endif
  133. private:
  134. KeyValues *m_pRawKVs;
  135. const char *m_pszName;
  136. // UI
  137. const char* m_pszNotificationRes;
  138. const char* m_pszQuestItemRes;
  139. const char* m_pszInGameTrackerRes;
  140. unacknowledged_item_inventory_positions_t m_eUnackPos;
  141. // Sounds
  142. CRandomChanceString m_vecGiveStrings[LOADOUT_COUNT]; // Per class
  143. CRandomChanceString m_vecCompleteStrings[LOADOUT_COUNT]; // Per class
  144. CRandomChanceString m_vecFullyCompleteStrings[LOADOUT_COUNT]; // Per class
  145. const char* m_pszRewardString;
  146. const char* m_pszDiscardString;
  147. const char* m_pszOnRevealText;
  148. };
  149. typedef CUtlVector< const class CTFQuestObjectiveDefinition* > QuestObjectiveDefVec_t;
  150. typedef CUtlVector< const char * > QuestDescriptionVec_t;
  151. typedef CUtlVector< const char * > QuestNameVec_t;
  152. //-----------------------------------------------------------------------------
  153. // CTFRequiredQuestItemsSet
  154. //-----------------------------------------------------------------------------
  155. class CTFRequiredQuestItemsSet
  156. {
  157. public:
  158. CTFRequiredQuestItemsSet( void ) {}
  159. bool BInitFromKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors = NULL );
  160. bool BPostInit( CUtlVector<CUtlString> *pVecErrors = NULL );
  161. bool OwnsRequiredItems( const CUtlVector< item_definition_index_t >& vecOwnedItemDefs ) const;
  162. const item_definition_index_t& GetLoanerItemDef() const { return m_LoanerItemDef; }
  163. private:
  164. CUtlVector< item_definition_index_t > m_vecQualifyingItemDefs;
  165. item_definition_index_t m_LoanerItemDef;
  166. };
  167. //-----------------------------------------------------------------------------
  168. // CQuestDefinition
  169. //-----------------------------------------------------------------------------
  170. class CQuestDefinition
  171. {
  172. public:
  173. CQuestDefinition( void );
  174. bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  175. uint32 GetMaxStandardPoints() const { return m_nMaxStandardPoints; }
  176. uint32 GetMaxBonusPoints() const { return m_nMaxBonusPoints; }
  177. const char *GetRewardLootlistName() const { return m_pszRewardLootlistName; }
  178. const char *GetQuickplayMapName() const { return m_pszQuickplayMapName; }
  179. const char *GetMatchmakingGroupName() const { return m_strMatchmakingGroupName.Get(); }
  180. const char *GetMatchmakingCategoryName() const { return m_strMatchmakingCategoryName.Get(); }
  181. const char *GetMatchmakingMapName() const { return m_strMatchmakingMapName.Get(); }
  182. const QuestObjectiveDefVec_t& GetObjectives() const { return m_vecObjectiveDefinitions; }
  183. void GetRolledObjectivesForItem( QuestObjectiveDefVec_t& vecRolledObjectives, const CEconItem* pItem ) const;
  184. const CQuestThemeDefinition *GetQuestTheme() const;
  185. const char *GetRolledDescriptionForItem( const CEconItem* pItem ) const;
  186. const char *GetRolledNameForItem( const CEconItem* pItem ) const;
  187. const char *GetCorrespondingOperationName() const { return m_pszCorrespondingOperationName; }
  188. const CUtlVector< CTFRequiredQuestItemsSet >& GetRequiredItemSets() const { return m_vecRequiredItemSets; }
  189. private:
  190. QuestObjectiveDefVec_t m_vecObjectiveDefinitions;
  191. uint32 m_nMaxStandardPoints;
  192. uint32 m_nMaxBonusPoints;
  193. const char *m_pszRewardLootlistName;
  194. uint16 m_nNumObjectivesToRoll;
  195. const char *m_pszQuestThemeName;
  196. const char *m_pszCorrespondingOperationName;
  197. const char *m_pszQuickplayMapName;
  198. CUtlString m_strMatchmakingGroupName;
  199. CUtlString m_strMatchmakingCategoryName;
  200. CUtlString m_strMatchmakingMapName;
  201. QuestDescriptionVec_t m_vecQuestDescriptions;
  202. QuestNameVec_t m_vecQuestNames;
  203. CEconItemDefinition *m_pOperationBadgeDef;
  204. // loaner items for this quest
  205. CUtlVector< CTFRequiredQuestItemsSet > m_vecRequiredItemSets;
  206. };
  207. //-----------------------------------------------------------------------------
  208. // Wars
  209. //-----------------------------------------------------------------------------
  210. class CWarDefinition
  211. {
  212. public:
  213. CWarDefinition();
  214. bool BInitFromKV( KeyValues *pKV, CUtlVector<CUtlString> *pVecErrors );
  215. struct CWarSideDefinition_t
  216. {
  217. CWarSideDefinition_t()
  218. : m_pszLeaderboardName( NULL )
  219. , m_pszLocalizedName( NULL )
  220. , m_nSideIndex( INVALID_WAR_SIDE )
  221. {}
  222. bool BInitFromKV( const char* pszContainingWarName, KeyValues *pKVSide, CUtlVector<CUtlString> *pVecErrors );
  223. const char* m_pszLocalizedName;
  224. const char* m_pszLeaderboardName;
  225. war_side_t m_nSideIndex;
  226. };
  227. typedef CUtlMap< war_side_t, CWarSideDefinition_t > SidesMap_t;
  228. const SidesMap_t& GetSides() const { return m_mapSides; }
  229. const CWarSideDefinition_t* GetSide( war_side_t nSide ) const;
  230. war_definition_index_t GetDefIndex() const { return m_nDefIndex; }
  231. const char* GetDefName() const { return m_pszDefName; }
  232. bool IsActive() const;
  233. bool IsValidSide( war_side_t nSide ) const;
  234. RTime32 GetStartDate() const { return m_rtTimeStart; }
  235. RTime32 GetEndDate() const { return m_rtTimeEnd; }
  236. private:
  237. const char* m_pszLocalizedWarname;
  238. const char* m_pszDefName;
  239. SidesMap_t m_mapSides;
  240. RTime32 m_rtTimeStart;
  241. RTime32 m_rtTimeEnd;
  242. war_definition_index_t m_nDefIndex;
  243. };
  244. typedef CUtlMap< war_definition_index_t, CWarDefinition* > WarDefinitionMap_t;
  245. const char *GetPlayerClassName( int iClass );
  246. const char *GetPlayerClassLocalizationKey( int iClass );
  247. itemid_t GetAssociatedQuestItemID( const IEconItemInterface *pEconItem );
  248. class CTFItemDefinition : public CEconItemDefinition
  249. {
  250. public:
  251. CTFItemDefinition()
  252. {
  253. InternalInitialize();
  254. }
  255. ~CTFItemDefinition()
  256. {
  257. if ( m_pTauntData )
  258. {
  259. delete m_pTauntData;
  260. m_pTauntData = NULL;
  261. }
  262. }
  263. // CEconItemDefinition interface.
  264. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL ) OVERRIDE;
  265. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  266. virtual bool BInitFromTestItemKVs( int iNewDefIndex, KeyValues *pKVItem, CUtlVector<CUtlString>* pVecErrors = NULL ) OVERRIDE;
  267. virtual void CopyPolymorphic( const CEconItemDefinition *pSourceDef );
  268. virtual void GeneratePrecacheModelStrings( bool bDynamicLoad, CUtlVector<const char *> *out_pVecModelStrings ) const;
  269. #endif // defined(CLIENT_DLL) || defined(GAME_DLL)
  270. int GetAnimSlot( void ) const { return m_iAnimationSlot; }
  271. // Class & Slot handling
  272. int GetDefaultLoadoutSlot( void ) const { return m_iDefaultLoadoutSlot; }
  273. int GetAccountLoadoutSlot( void ) const { return m_iDefaultLoadoutSlot; }
  274. const CBitVec<LOADOUT_COUNT> *GetClassUsability( void ) const { return &m_vbClassUsability; }
  275. void FilloutSlotUsage( CBitVec<LOADOUT_COUNT> *pBV ) const;
  276. bool CanBeUsedByClass( int iClass ) const { return iClass == GEconItemSchema().GetAccountIndex() ? m_eEquipType == EQUIP_TYPE_ACCOUNT : m_vbClassUsability.IsBitSet( iClass ); }
  277. bool CanBeUsedByAllClasses( void ) const;
  278. EEquipType_t GetEquipType( void ) const { return m_eEquipType; }
  279. bool CanBePlacedInSlot( int nSlot ) const;
  280. const char *GetPlayerDisplayModel( int iClass ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_pszPlayerDisplayModel[iClass]; }
  281. virtual const char *GetPlayerDisplayModelAlt( int iClass = 0 ) const { Assert( iClass >= 0 && iClass < LOADOUT_COUNT ); return m_pszPlayerDisplayModelAlt[iClass]; }
  282. int GetLoadoutSlot( int iLoadoutClass ) const;
  283. #ifndef GC_DLL
  284. bool IsAWearable() const;
  285. bool IsContentStreamable() const;
  286. const char* GetAdTextToken() const { return m_pszAdText; }
  287. const char* GetAdResFile() const { return m_pszAdResFile; }
  288. #endif // !GC_DLL
  289. CTFTauntInfo *GetTauntData() const { return m_pTauntData; }
  290. const CQuestDefinition *GetQuestDef() const { return m_pQuestData; }
  291. KeyValues *GetPaintKitWearDefinition( int nWear ) const;
  292. const char *GetPaintKitName( ) const;
  293. #ifdef CLIENT_DLL
  294. bool HasDetailedIcon() const { return m_bHasDetailedIcon; }
  295. #endif // CLIENT_DLL
  296. private:
  297. void InternalInitialize();
  298. // The load-out slot that this item can be placed into.
  299. int m_iDefaultLoadoutSlot;
  300. int m_iAnimationSlot;
  301. // taunt item data
  302. CTFTauntInfo *m_pTauntData;
  303. // Quest data
  304. CQuestDefinition *m_pQuestData;
  305. // The .mdl file used for this item when it's being carried by a player.
  306. const char *m_pszPlayerDisplayModel[LOADOUT_COUNT];
  307. const char *m_pszPlayerDisplayModelAlt[LOADOUT_COUNT];
  308. #ifndef GC_DLL
  309. const char* m_pszAdText;
  310. const char* m_pszAdResFile;
  311. #endif
  312. // Specifies which class can use this item.
  313. CBitVec<LOADOUT_COUNT> m_vbClassUsability;
  314. int m_iLoadoutSlots[LOADOUT_COUNT]; // Slot that each class places the item into.
  315. EEquipType_t m_eEquipType;
  316. #ifdef CLIENT_DLL
  317. bool m_bHasDetailedIcon;
  318. #endif // CLIENT_DLL
  319. };
  320. class CTFStyleInfo : public CEconStyleInfo
  321. {
  322. public:
  323. CTFStyleInfo()
  324. {
  325. for ( int i = 0; i < ARRAYSIZE( m_pszPlayerDisplayModel ); i++ )
  326. {
  327. for ( int j = 0; j < ARRAYSIZE( m_pszPlayerDisplayModel[i] ); j++ )
  328. {
  329. m_pszPlayerDisplayModel[i][j] = NULL;
  330. }
  331. }
  332. }
  333. virtual void BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors ) OVERRIDE;
  334. #if defined(CLIENT_DLL) || defined(GAME_DLL)
  335. virtual void GeneratePrecacheModelStringsForStyle( CUtlVector<const char *> *out_pVecModelStrings ) const OVERRIDE;
  336. #endif
  337. const char *GetPlayerDisplayModel( int iClass, int iTeam ) const;
  338. private:
  339. // The .mdl file used for this item when it's being carried by a player.
  340. const char *m_pszPlayerDisplayModel[2][LOADOUT_COUNT];
  341. };
  342. class CTFCraftingRecipeDefinition : public CEconCraftingRecipeDefinition
  343. {
  344. public:
  345. virtual bool ItemListMatchesInputs( CUtlVector<CEconItem*> *vecCraftingItems, KeyValues *out_pkvCraftParams, bool bIgnoreSlop, CUtlVector<uint64> *vecChosenItems ) const OVERRIDE;
  346. // A client function for testing to see if the contents of the player's backpack can match against this recipe.
  347. // Broken out into a separate function so we don't run the risk of its thorny logic introducing bugs into the backend crafting logic.
  348. bool CanMatchAgainstBackpack( CUtlVector<CEconItem*> *vecAllItems, CUtlVector<CEconItem*> vecItemsByClass[LOADOUT_COUNT], CUtlVector<CEconItem*> vecItemsBySlot[ CLASS_LOADOUT_POSITION_COUNT ], CUtlVector<uint64> *vecChosenItems ) const;
  349. private:
  350. bool CheckSubItemListAgainstBackpack( CUtlVector<CEconItem*> *vecCraftingItems, CUtlVector<uint64> *vecChosenItems ) const;
  351. };
  352. typedef uint32 ObjectiveConditionDefIndex_t;
  353. const ObjectiveConditionDefIndex_t INVALID_QUEST_OBJECTIVE_CONDITIONS_INDEX = ObjectiveConditionDefIndex_t(-1);
  354. //-----------------------------------------------------------------------------
  355. // CTFQuestObjectiveConditionsDefinition
  356. // These contain the actual logic that can be used by multiple objectives.
  357. //-----------------------------------------------------------------------------
  358. class CTFQuestObjectiveConditionsDefinition
  359. {
  360. public:
  361. CTFQuestObjectiveConditionsDefinition( void );
  362. virtual ~CTFQuestObjectiveConditionsDefinition( void );
  363. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL );
  364. bool BPostInit( CUtlVector<CUtlString> *pVecErrors = NULL );
  365. ObjectiveConditionDefIndex_t GetDefIndex() const { return m_nDefIndex; }
  366. #ifndef GC_DLL
  367. KeyValues *GetKeyValues() const { return m_pConditionsKey; }
  368. #endif
  369. const CUtlVector< CTFRequiredQuestItemsSet >& GetRequiredItemSets() const { return m_vecRequiredItemSets; }
  370. private:
  371. ObjectiveConditionDefIndex_t m_nDefIndex;
  372. #ifndef GC_DLL
  373. KeyValues *m_pConditionsKey;
  374. #endif
  375. CUtlVector< CTFRequiredQuestItemsSet > m_vecRequiredItemSets;
  376. };
  377. //-----------------------------------------------------------------------------
  378. // CQuestObjectiveDefinition
  379. //-----------------------------------------------------------------------------
  380. class CTFQuestObjectiveDefinition : public CQuestObjectiveDefinition
  381. {
  382. public:
  383. CTFQuestObjectiveDefinition( void );
  384. virtual ~CTFQuestObjectiveDefinition( void );
  385. virtual bool BInitFromKV( KeyValues *pKVItem, CUtlVector<CUtlString> *pVecErrors = NULL ) OVERRIDE;
  386. #ifndef GC_DLL
  387. KeyValues *GetConditionsKeyValues() const;
  388. #endif
  389. const CTFQuestObjectiveConditionsDefinition* GetConditions() const;
  390. private:
  391. ObjectiveConditionDefIndex_t m_nConditionDefIndex;
  392. };
  393. //-----------------------------------------------------------------------------
  394. // MvMMap_t
  395. //-----------------------------------------------------------------------------
  396. struct MvMMap_t
  397. {
  398. CUtlConstString m_sMap; // name of the map file
  399. CUtlConstString m_sDisplayName; // Localization tag starting with '#'
  400. CUtlVector<int> m_vecMissions; // indexes into the schema's challenge list
  401. };
  402. enum EMvMChallengeDifficulty
  403. {
  404. k_EMvMChallengeDifficulty_Invalid = -1,
  405. k_EMvMChallengeDifficulty_Normal = 1,
  406. k_EMvMChallengeDifficulty_Intermediate = 2,
  407. k_EMvMChallengeDifficulty_Advanced = 3,
  408. k_EMvMChallengeDifficulty_Expert = 4,
  409. k_EMvMChallengeDifficulty_Haunted = 5,
  410. k_EMvMChallengeDifficultyFirstValid = k_EMvMChallengeDifficulty_Normal,
  411. k_EMvMChallengeDifficultyLastValid = k_EMvMChallengeDifficulty_Haunted
  412. };
  413. extern EMvMChallengeDifficulty GetMvMChallengeDifficultyByInternalName( const char *pszEnglishID );
  414. extern const char *GetMvMChallengeDifficultyLocName( EMvMChallengeDifficulty eDifficulty );
  415. //-----------------------------------------------------------------------------
  416. // MvMMission_t
  417. //-----------------------------------------------------------------------------
  418. struct MvMMission_t
  419. {
  420. int m_iDisplayMapIndex; // Index into the schema's map list, for UI purposes
  421. CUtlConstString m_sPop; // name of the pop file
  422. CUtlConstString m_sDisplayName; // Localization tag starting with '#'
  423. CUtlConstString m_sMode; // Localization tag starting with '#'
  424. CUtlConstString m_sMapNameActual; // name of the map file to really load
  425. EMvMChallengeDifficulty m_eDifficulty;
  426. uint32 m_unMannUpPoints; // points for completing mission
  427. };
  428. //-----------------------------------------------------------------------------
  429. // MvMTour_t
  430. //-----------------------------------------------------------------------------
  431. struct MvMTourMission_t
  432. {
  433. int m_iMissionIndex; // index to the schema's challenge list
  434. int m_iBadgeSlot; // *index* (0...31) of the slot on the badge. -1 if not assigned a slot. (No bragging rights for this challenge.)
  435. };
  436. struct MvMTour_t
  437. {
  438. CUtlConstString m_sTourInternalName;
  439. CUtlConstString m_sTourNameLocalizationToken; // Localization tag starting with '#', shown to clients
  440. CUtlConstString m_sLootImageName;
  441. const CEconItemDefinition *m_pBadgeItemDef; // can be NULL if there is no badge reward. Implies all badge slots will be -1. Only really valid for practice tours.
  442. #ifdef GC
  443. const CEconLootListDefinition *m_pMissionCompleteLootList; // can be NULL, but really only makes sense if there is no badge reward.
  444. const CEconLootListDefinition *m_pTourCompleteLootList; // can be NULL, but really only makes sense if there is no badge reward.
  445. #endif
  446. CCopyableUtlVector<MvMTourMission_t> m_vecMissions; // indexes into the schema's challenge list
  447. uint32 m_nAllChallengesBits;
  448. EMvMChallengeDifficulty m_eDifficulty;
  449. bool m_bIsNew;
  450. };
  451. //-----------------------------------------------------------------------------
  452. // Maps
  453. //-----------------------------------------------------------------------------
  454. enum EGameCategory
  455. {
  456. kGameCategory_Escort = 0,
  457. kGameCategory_CTF,
  458. kGameCategory_AttackDefense,
  459. kGameCategory_Koth,
  460. kGameCategory_CP,
  461. kGameCategory_EscortRace,
  462. kGameCategory_EventMix,
  463. kGameCategory_SD,
  464. kGameCategory_Quickplay,
  465. kGameCategory_Event247,
  466. kGameCategory_Arena,
  467. kGameCategory_RobotDestruction,
  468. kGameCategory_Powerup,
  469. kGameCategory_Featured,
  470. kGameCategory_Passtime,
  471. kGameCategory_Community_Update,
  472. kGameCategory_Misc,
  473. kGameCategory_Competitive_6v6,
  474. kGameCategory_Other,
  475. kGameCategory_Halloween,
  476. // Note: Don't reorder this list. Only add to the end
  477. eNumGameCategories,
  478. };
  479. typedef uint32 map_identifier_t;
  480. enum eQuickplayMatchType
  481. {
  482. kQuickplay_AdvancedUsersOnly,
  483. kQuickplay_AllUsers, // everyone
  484. kQuickplay_Disabled, // no-one
  485. kQuickplayTypeCount
  486. };
  487. enum EMatchmakingGroupType
  488. {
  489. kMatchmakingType_None = -1,
  490. kMatchmakingType_SpecialEvents,
  491. kMatchmakingType_Core,
  492. kMatchmakingType_Alternative,
  493. kMatchmakingType_Competitive_6v6,
  494. kMatchmakingTypeCount
  495. };
  496. enum EMatchmakingGameModeRestrictionType
  497. {
  498. kMatchmakingGameModeRestrictionType_None = -1,
  499. kMatchmakingGameModeRestrictionType_Holiday,
  500. kMatchmakingGameModeRestrictionType_Operation,
  501. kMatchmakingGameModeRestrictionTypeCount
  502. };
  503. typedef uint32 MapDefIndex_t;
  504. struct MapDef_t
  505. {
  506. MapDef_t( const char* pszMapStampDefName )
  507. : mapStampDef( pszMapStampDefName )
  508. , m_nStatsIdentifier( (MapDefIndex_t)-1 )
  509. {}
  510. CSchemaItemDefHandle mapStampDef;
  511. MapDefIndex_t m_nDefIndex;
  512. const char* pszMapName;
  513. const char* pszMapNameLocKey;
  514. const char* pszAuthorsLocKey; // if set, will be considered a community map in the UI
  515. const char* pszStrangePrefixLocKey;
  516. // The m_nStatsIdentifier field is used when looking up a map in a user's gamestats.
  517. // It's a relic from the quickplay days and how the maps were defined in the schema back then.
  518. // We've since switched to using a map defindex, which is easier to read and manage, but this
  519. // field still needs to be used to lookup map gamestats because millions of customers
  520. // have these maps identified by those numbers in their gamestats. The old numbers for existing
  521. // maps is already defined in _maps.txt newly defined maps don't need to specify a "statsidentifier"
  522. // field, because they will generate their own unique identifier.
  523. map_identifier_t m_nStatsIdentifier;
  524. map_identifier_t GetStatsIdentifier() const { return m_nStatsIdentifier == -1 ? (m_nDefIndex << 16) : m_nStatsIdentifier; }
  525. bool IsCommunityMap() const { return pszAuthorsLocKey != NULL; }
  526. CUtlVector< EGameCategory > m_vecAssociatedGameCategories;
  527. CUtlVector<econ_tag_handle_t> vecTags;
  528. // The rolling match tags for this map. When a rolling match vote happens, only allow voting on
  529. // maps that have at least one matching tag with this map.
  530. struct WeightedNextMapCandidates_t
  531. {
  532. MapDefIndex_t m_nDefIndex;
  533. float m_flWeight;
  534. };
  535. CUtlVector< WeightedNextMapCandidates_t > m_vecRollingMatchMaps;
  536. void AddMapAsTargetWithWeight( const WeightedNextMapCandidates_t& target )
  537. {
  538. FOR_EACH_VEC( m_vecRollingMatchMaps, i )
  539. {
  540. if ( m_vecRollingMatchMaps[ i ].m_nDefIndex == target.m_nDefIndex )
  541. {
  542. m_vecRollingMatchMaps[ i ].m_flWeight = Max( m_vecRollingMatchMaps[ i ].m_flWeight, target.m_flWeight );
  543. return;
  544. }
  545. }
  546. m_vecRollingMatchMaps.AddToTail( target );
  547. }
  548. CUtlVector< econ_tag_handle_t > m_vecRollingMatchTags;
  549. bool BHasRollingMatchTag( econ_tag_handle_t tag ) const
  550. {
  551. FOR_EACH_VEC( m_vecRollingMatchTags, i )
  552. {
  553. if ( m_vecRollingMatchTags[ i ] == tag )
  554. return true;
  555. }
  556. return false;
  557. }
  558. struct WeightedNextMapTargets_t
  559. {
  560. econ_tag_handle_t m_tag;
  561. float m_flWeight;
  562. };
  563. CUtlVector< WeightedNextMapTargets_t > m_vecRollingMatchTargets;
  564. };
  565. struct SchemaMMGameModeRestriction_t
  566. {
  567. SchemaMMGameModeRestriction_t()
  568. {
  569. m_eType = kMatchmakingGameModeRestrictionType_None;
  570. m_nValue = -1;
  571. }
  572. EMatchmakingGameModeRestrictionType m_eType;
  573. int m_nValue;
  574. CUtlString m_strValue;
  575. };
  576. struct SchemaMMGroup_t;
  577. struct SchemaGameCategory_t
  578. {
  579. SchemaGameCategory_t()
  580. : m_eGameCategory( eNumGameCategories )
  581. , m_pszLocalizedName( NULL )
  582. , m_pMMGroup( NULL )
  583. , m_pszLocalizedDesc( NULL )
  584. , m_pszListImage( NULL )
  585. {}
  586. SchemaGameCategory_t( const SchemaGameCategory_t& other )
  587. {
  588. m_eGameCategory = other.m_eGameCategory;
  589. m_pMMGroup = other.m_pMMGroup;
  590. m_pszLocalizedName = other.m_pszLocalizedName;
  591. m_pszLocalizedDesc = other.m_pszLocalizedDesc;
  592. m_pszListImage = other.m_pszListImage;
  593. m_vecMaps.Purge();
  594. m_vecMaps.CopyArray( other.m_vecMaps.Base(), other.m_vecMaps.Count() );
  595. m_vecRestrictions.Purge();
  596. m_vecRestrictions.CopyArray( other.m_vecRestrictions.Base(), other.m_vecRestrictions.Count() );
  597. }
  598. ~SchemaGameCategory_t()
  599. {}
  600. void AddMap( const MapDef_t *pMap, bool bEnabled )
  601. {
  602. if ( !pMap )
  603. return;
  604. m_vecMaps.AddToTail( pMap );
  605. if ( bEnabled )
  606. {
  607. m_vecEnabledMaps.AddToTail( pMap );
  608. }
  609. }
  610. const MapDef_t *GetRandomMap( void ) const
  611. {
  612. Assert( m_vecEnabledMaps.Count() );
  613. return m_vecEnabledMaps[RandomInt( 0, m_vecEnabledMaps.Count() - 1 )];
  614. }
  615. bool PassesRestrictions() const;
  616. //void SerializeToKVs( KeyValues* pKV );
  617. EGameCategory m_eGameCategory;
  618. const SchemaMMGroup_t* m_pMMGroup;
  619. const char* m_pszName;
  620. const char* m_pszLocalizedName;
  621. const char* m_pszLocalizedDesc;
  622. const char* m_pszListImage;
  623. const char* m_pszMMType;
  624. CUtlVector< const MapDef_t* > m_vecEnabledMaps;
  625. CUtlVector< SchemaMMGameModeRestriction_t > m_vecRestrictions;
  626. CUtlVector< const MapDef_t* > m_vecMaps;
  627. };
  628. typedef CUtlMap< EGameCategory, SchemaGameCategory_t* > GameCategoryMap_t;
  629. struct SchemaMMGroup_t
  630. {
  631. SchemaMMGroup_t()
  632. : m_eMMGroup( kMatchmakingType_None )
  633. , m_pszLocalizedName( NULL )
  634. , m_nMaxExcludes( 0 )
  635. {}
  636. SchemaMMGroup_t( const SchemaMMGroup_t& other )
  637. {
  638. m_eMMGroup = other.m_eMMGroup;
  639. m_pszLocalizedName = other.m_pszLocalizedName;
  640. m_nMaxExcludes = other.m_nMaxExcludes;
  641. m_vecModes.Purge();
  642. m_vecModes.CopyArray( other.m_vecModes.Base(), other.m_vecModes.Count() );
  643. }
  644. bool IsCategoryValid() const;
  645. ~SchemaMMGroup_t()
  646. {}
  647. EMatchmakingGroupType m_eMMGroup;
  648. const char* m_pszName;
  649. const char* m_pszLocalizedName;
  650. int m_nMaxExcludes;
  651. CBitVec<k_nMatchGroup_Count> m_bitsValidMMGroups;
  652. CUtlVector< const SchemaGameCategory_t* > m_vecModes;
  653. };
  654. typedef CUtlMap< EMatchmakingGroupType, SchemaMMGroup_t* > MMGroupMap_t;
  655. //-----------------------------------------------------------------------------
  656. // CTFItemSchema
  657. //-----------------------------------------------------------------------------
  658. class CTFItemSchema : public CEconItemSchema
  659. {
  660. public:
  661. CTFItemSchema();
  662. virtual void Reset();
  663. CTFItemDefinition *GetTFItemDefinition( int iItemIndex )
  664. {
  665. return (CTFItemDefinition *)GetItemDefinition( iItemIndex );
  666. }
  667. CTFCraftingRecipeDefinition *GetTFCraftingRecipeDefinition( int iRecipeIndex )
  668. {
  669. return (CTFCraftingRecipeDefinition *)GetRecipeDefinition( iRecipeIndex );
  670. }
  671. const CQuestThemeDefinition *GetQuestThemeByName( const char *pszDefName ) const;
  672. const CUtlMap<const char*, CQuestThemeDefinition*, int >& GetQuestThemes() const { return m_mapQuestThemes; }
  673. const CTFQuestObjectiveConditionsDefinition* GetQuestObjectiveConditionByDefIndex( ObjectiveConditionDefIndex_t nDefIndex );
  674. const CWarDefinition *GetWarDefinitionByIndex( war_definition_index_t nDefIndex ) const;
  675. const CWarDefinition *GetWarDefinitionByName( const char* pszDefName ) const;
  676. const WarDefinitionMap_t& GetWarDefinitions() const { return m_mapWars; }
  677. const CUtlVector<const char *>& GetClassUsabilityStrings() const { return m_vecClassUsabilityStrings; }
  678. const CUtlVector<const char *>& GetLoadoutStrings( EEquipType_t eType ) const { return eType == EQUIP_TYPE_CLASS ? m_vecClassLoadoutStrings : m_vecAccountLoadoutStrings; }
  679. const CUtlVector<const char *>& GetLoadoutStringsForDisplay( EEquipType_t eType ) const { return eType == EQUIP_TYPE_CLASS ? m_vecClassLoadoutStringsForDisplay : m_vecAccountLoadoutStringsForDisplay; }
  680. const CUtlVector<const char *>& GetWeaponTypeSubstrings() const { return m_vecWeaponTypeSubstrings; }
  681. static const char k_rchOverrideItemLevelDescStringAttribName[];
  682. static const char k_rchMvMTicketItemDefName[];
  683. static const char k_rchMvMSquadSurplusVoucherItemDefName[];
  684. static const char k_rchMvMPowerupBottleItemDefName[];
  685. static const char k_rchMvMChallengeCompletedMaskAttribName[];
  686. static const char k_rchLadderPassItemDefName[];
  687. static const char *GetMvMBadgeContractPointsAttributeName( EMvMChallengeDifficulty difficulty );
  688. static const char *GetMvMBadgeContractLevelAttributeName( EMvMChallengeDifficulty difficulty );
  689. const CUtlVector<MvMMap_t>& GetMvmMaps() const { return m_vecMvMMaps; }
  690. const CUtlVector<MvMMission_t>& GetMvmMissions() const { return m_vecMvMMissions; }
  691. const CUtlVector<MvMTour_t>& GetMvmTours() const { return m_vecMvMTours; }
  692. //
  693. /// Return index into mission list, or one of these special values:
  694. /// k_iMvmMissionIndex_Any if empty string is passed
  695. /// k_iMvmMissionIndex_NotInSchema if not found
  696. ///
  697. /// Input is the full pop filename, but without the directory or extension
  698. int FindMvmMissionByName( const char *pszChallengeName ) const;
  699. /// Get pop filename (without extension) given the challenge index.
  700. /// Handles k_iMvmMissionIndex_Any and k_iMvmMissionIndex_NotInSchema
  701. const char *GetMvmMissionName( int iChallengeIndex ) const;
  702. /// Return index into tour list, or one of these special values:
  703. /// k_iMvmTourIndex_Any if empty string is passed
  704. /// k_iMvmTourIndex_NotInSchema if not found
  705. ///
  706. /// Input is the value of MvMTour_t::m_sTourInternalName
  707. int FindMvmTourByName( const char *pszTourName ) const;
  708. /// Find mission within a particular tour, and return index into MvMTour_t::m_vecMissions.
  709. /// Returns -1 if invalid tour index or mission is not part of the tour
  710. int FindMvmMissionInTour( int idxTour, int idxMissionInSchema ) const;
  711. /// Get badge slot corresponding to particular mission, for a given tour.
  712. /// Returns bit index MvMTourMission_t::m_iBadgeSlot (NOT BITMASK), or -1 if
  713. /// invalid tour index of mission is not part of the tour
  714. int GetMvmMissionBadgeSlotForTour( int idxTour, int idxMissionInSchema ) const;
  715. int GetMapCount() const { return m_vecMasterListOfMaps.Count(); }
  716. const MapDef_t *GetMasterMapDefByName( const char *pszSearchName ) const;
  717. const MapDef_t *GetMasterMapDefByIndex( MapDefIndex_t unIndex ) const;
  718. const CUtlVector<MapDef_t*>& GetMasterMapsList() const { return m_vecMasterListOfMaps; }
  719. const GameCategoryMap_t& GetGameCategoryMap() const { return m_mapGameCategories; }
  720. const SchemaGameCategory_t* GetGameCategory( EGameCategory eType ) const;
  721. const MMGroupMap_t& GetMMGroupMap() const { return m_mapMMGroups; }
  722. const SchemaMMGroup_t* GetMMGroup( EMatchmakingGroupType eCat ) const;
  723. public:
  724. // CEconItemSchema interface.
  725. virtual CEconItemDefinition *CreateEconItemDefinition() { return new CTFItemDefinition; }
  726. virtual CEconCraftingRecipeDefinition *CreateCraftingRecipeDefinition() { return new CTFCraftingRecipeDefinition; }
  727. virtual CEconStyleInfo *CreateEconStyleInfo() { return new CTFStyleInfo; }
  728. virtual CQuestObjectiveDefinition *CreateQuestDefinition() { return new CTFQuestObjectiveDefinition; }
  729. virtual bool BCanStrangeFilterApplyToStrangeSlotInItem( uint32 /*strange_event_restriction_t*/ unRestrictionType, uint32 unRestrictionValue, const IEconItemInterface *pItem, int iStrangeSlot, uint32 *out_pOptionalScoreType ) const;
  730. virtual IEconTool *CreateEconToolImpl( const char *pszToolType, const char *pszUseString, const char *pszUsageRestriction, item_capabilities_t unCapabilities, KeyValues *pUsageKV ) OVERRIDE;
  731. virtual bool BInitSchema( KeyValues *pKVRawDefinition, CUtlVector<CUtlString> *pVecErrors = NULL );
  732. virtual RTime32 GetCustomExpirationDate( const char *pszExpirationDate ) const OVERRIDE;
  733. protected:
  734. #ifdef TF_CLIENT_DLL
  735. virtual int CalculateNumberOfConcreteItems( const CEconItemDefinition *pItemDef );
  736. #endif // TF_CLIENT_DLL
  737. private:
  738. void InitializeStringTable( const char **ppStringTable, unsigned int unStringCount, CUtlVector<const char *> *out_pvecStringTable );
  739. bool BInitMvmMissions( KeyValues *pKVMvmMaps, CUtlVector<CUtlString> *pVecErrors );
  740. bool BInitMvmTours( KeyValues *pKVMvmTours, CUtlVector<CUtlString> *pVecErrors );
  741. bool BInitGameModes( KeyValues *pKVMaps, CUtlVector<CUtlString> *pVecErrors );
  742. bool BInitMaps( KeyValues *pKVMaps, CUtlVector<CUtlString> *pVecErrors );
  743. bool BInitMMCategories( KeyValues *pKVCategories, CUtlVector<CUtlString> *pVecErrors );
  744. bool BInitQuestThemes( KeyValues *pKVThemes, CUtlVector<CUtlString> *pVecErrors );
  745. bool BInitQuestObjectiveConditions( KeyValues *pKVConditionsBlock, CUtlVector<CUtlString> *pVecErrors );
  746. bool BObjectiveConditionsPostInit( CUtlVector<CUtlString> *pVecErrors );
  747. bool BInitWarDefs( KeyValues *pKVWarDefs, CUtlVector<CUtlString> *pVecErrors );
  748. bool BPostInitMaps( CUtlVector<CUtlString> *pVecErrors );
  749. CUtlVector<const char *> m_vecClassUsabilityStrings;
  750. CUtlVector<const char *> m_vecClassLoadoutStrings;
  751. CUtlVector<const char *> m_vecClassLoadoutStringsForDisplay;
  752. CUtlVector<const char *> m_vecAccountLoadoutStrings;
  753. CUtlVector<const char *> m_vecAccountLoadoutStringsForDisplay;
  754. CUtlVector<const char *> m_vecWeaponTypeSubstrings;
  755. CUtlVector<MvMMap_t> m_vecMvMMaps;
  756. CUtlVector<MvMMission_t> m_vecMvMMissions;
  757. CUtlVector<MvMTour_t> m_vecMvMTours;
  758. // Contains the list of the quest themes
  759. CUtlMap<const char*, CQuestThemeDefinition*, int > m_mapQuestThemes;
  760. CUtlMap< ObjectiveConditionDefIndex_t, CTFQuestObjectiveConditionsDefinition* > m_mapQuestObjectiveConditions;
  761. CUtlVector<MapDef_t*> m_vecMasterListOfMaps;
  762. GameCategoryMap_t m_mapGameCategories;
  763. MMGroupMap_t m_mapMMGroups;
  764. WarDefinitionMap_t m_mapWars;
  765. };
  766. #endif // TFITEMSCHEMA_H