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.

76 lines
3.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Functions related to dynamic recipes
  4. //
  5. //=============================================================================
  6. #ifndef ECON_DYNAMIC_RECIPE
  7. #define ECON_DYNAMIC_RECIPE
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tf_gcmessages.h"
  12. #include "game_item_schema.h"
  13. #include "econ_item.h"
  14. extern const char *g_pszAttrEncodeSeparator;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Stores off all CAttribute_DynamicRecipeComponent attributes
  17. // that consider m_pTargetItem to be a match. If NULL is passed in for pTargetItem
  18. // then we consider all attributes to be a match
  19. //-----------------------------------------------------------------------------
  20. class CRecipeComponentMatchingIterator : public CEconItemSpecificAttributeIterator
  21. {
  22. public:
  23. CRecipeComponentMatchingIterator( const IEconItemInterface *pSourceItem,
  24. const IEconItemInterface *pTargetItem );
  25. void SetSourceItem( const IEconItemInterface *m_pSourceItem );
  26. void SetTargetItem( const IEconItemInterface *pTargetItem );
  27. void SetIgnoreCompleted( bool bIgnoreCompleted ) { m_bIgnoreCompleted = bIgnoreCompleted; }
  28. virtual bool OnIterateAttributeValue( const CEconItemAttributeDefinition *pAttrDef,
  29. const CAttribute_DynamicRecipeComponent& value ) OVERRIDE;
  30. const CUtlVector< const CEconItemAttributeDefinition* >& GetMatchingComponentInputs() const { return m_vecMatchingInputs; }
  31. const CUtlVector< const CEconItemAttributeDefinition* >& GetMatchingComponentOutputs() const { return m_vecMatchingOutputs; }
  32. int GetTotalInputs() const { return m_nInputsTotal; }
  33. int GetInputsFulfilled() const { return m_nInputsFulfilled; }
  34. int GetTotalOutputs() const { return m_nOutputsTotal; }
  35. private:
  36. const IEconItemInterface *m_pSourceItem;
  37. const IEconItemInterface *m_pTargetItem;
  38. bool m_bIgnoreCompleted;
  39. CUtlVector< const CEconItemAttributeDefinition* > m_vecMatchingInputs;
  40. CUtlVector< const CEconItemAttributeDefinition* > m_vecMatchingOutputs;
  41. int m_nInputsTotal;
  42. int m_nInputsFulfilled;
  43. int m_nOutputsTotal;
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Given a CAttribute_DynamicRecipeComponent and a IEconItemInterface,
  47. // returns whether the item pass the criteria of the attribute
  48. //-----------------------------------------------------------------------------
  49. bool DefinedItemAttribMatch( const CAttribute_DynamicRecipeComponent& attribValue, const IEconItemInterface* pItem );
  50. //-----------------------------------------------------------------------------
  51. // Purpose: Decodes the encoded attributes in attribValue and applies those attributes to pItem
  52. // Returns true on success, false if anything fails
  53. //-----------------------------------------------------------------------------
  54. bool DecodeAttributeStringIntoAttributes( const CAttribute_DynamicRecipeComponent& attribValue, CUtlVector<CEconItem::attribute_t>& vecAttribs);
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Decodes the encoded attributes in attribValue forms pItem into the
  57. // item that it describes
  58. //-----------------------------------------------------------------------------
  59. bool DecodeItemFromEncodedAttributeString( const CAttribute_DynamicRecipeComponent& attribValue, CEconItem* pItem );
  60. #endif //ECON_DYNAMIC_RECIPE