CBonusProxy.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * CBonusProxy.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "Bonus.h"
  12. #include "BonusSelector.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class DLL_LINKAGE CBonusProxy
  15. {
  16. public:
  17. CBonusProxy(const IBonusBearer * Target, CSelector Selector);
  18. CBonusProxy(const CBonusProxy & other);
  19. CBonusProxy(CBonusProxy && other) noexcept;
  20. CBonusProxy & operator=(CBonusProxy && other) noexcept;
  21. CBonusProxy & operator=(const CBonusProxy & other);
  22. const BonusList * operator->() const;
  23. TConstBonusListPtr getBonusList() const;
  24. protected:
  25. CSelector selector;
  26. const IBonusBearer * target;
  27. mutable int64_t bonusListCachedLast;
  28. mutable TConstBonusListPtr bonusList[2];
  29. mutable int currentBonusListIndex;
  30. mutable boost::mutex swapGuard;
  31. void swapBonusList(TConstBonusListPtr other) const;
  32. };
  33. class DLL_LINKAGE CTotalsProxy : public CBonusProxy
  34. {
  35. public:
  36. CTotalsProxy(const IBonusBearer * Target, CSelector Selector, int InitialValue);
  37. CTotalsProxy(const CTotalsProxy & other);
  38. CTotalsProxy(CTotalsProxy && other) = delete;
  39. CTotalsProxy & operator=(const CTotalsProxy & other) = default;
  40. CTotalsProxy & operator=(CTotalsProxy && other) = delete;
  41. int getMeleeValue() const;
  42. int getRangedValue() const;
  43. int getValue() const;
  44. /**
  45. Returns total value of all selected bonuses and sets bonusList as a pointer to the list of selected bonuses
  46. @param bonusList is the out list of all selected bonuses
  47. @return total value of all selected bonuses and 0 otherwise
  48. */
  49. int getValueAndList(TConstBonusListPtr & bonusList) const;
  50. private:
  51. int initialValue;
  52. mutable int64_t valueCachedLast = 0;
  53. mutable int value = 0;
  54. mutable int64_t meleeCachedLast;
  55. mutable int meleeValue;
  56. mutable int64_t rangedCachedLast;
  57. mutable int rangedValue;
  58. };
  59. class DLL_LINKAGE CCheckProxy
  60. {
  61. public:
  62. CCheckProxy(const IBonusBearer * Target, CSelector Selector, const std::string & cachingStr);
  63. CCheckProxy(const IBonusBearer * Target, BonusType bonusType);
  64. CCheckProxy(const CCheckProxy & other);
  65. CCheckProxy& operator= (const CCheckProxy & other) = default;
  66. bool getHasBonus() const;
  67. private:
  68. const IBonusBearer * target;
  69. std::string cachingStr;
  70. CSelector selector;
  71. mutable int64_t cachedLast;
  72. mutable bool hasBonus;
  73. };
  74. VCMI_LIB_NAMESPACE_END