CBonusProxy.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "HeroBonus.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class DLL_LINKAGE CBonusProxy
  14. {
  15. public:
  16. CBonusProxy(const IBonusBearer * Target, CSelector Selector);
  17. CBonusProxy(const CBonusProxy & other);
  18. CBonusProxy(CBonusProxy && other) noexcept;
  19. CBonusProxy & operator=(CBonusProxy && other) noexcept;
  20. CBonusProxy & operator=(const CBonusProxy & other);
  21. const BonusList * operator->() const;
  22. TConstBonusListPtr getBonusList() const;
  23. protected:
  24. CSelector selector;
  25. const IBonusBearer * target;
  26. mutable int64_t bonusListCachedLast;
  27. mutable TConstBonusListPtr bonusList[2];
  28. mutable int currentBonusListIndex;
  29. mutable boost::mutex swapGuard;
  30. void swapBonusList(TConstBonusListPtr other) const;
  31. };
  32. class DLL_LINKAGE CTotalsProxy : public CBonusProxy
  33. {
  34. public:
  35. CTotalsProxy(const IBonusBearer * Target, CSelector Selector, int InitialValue);
  36. CTotalsProxy(const CTotalsProxy & other);
  37. CTotalsProxy(CTotalsProxy && other) = delete;
  38. CTotalsProxy & operator=(const CTotalsProxy & other) = default;
  39. CTotalsProxy & operator=(CTotalsProxy && other) = delete;
  40. int getMeleeValue() const;
  41. int getRangedValue() const;
  42. int getValue() const;
  43. /**
  44. Returns total value of all selected bonuses and sets bonusList as a pointer to the list of selected bonuses
  45. @param bonusList is the out list of all selected bonuses
  46. @return total value of all selected bonuses and 0 otherwise
  47. */
  48. int getValueAndList(TConstBonusListPtr & bonusList) const;
  49. private:
  50. int initialValue;
  51. mutable int64_t valueCachedLast = 0;
  52. mutable int value = 0;
  53. mutable int64_t meleeCachedLast;
  54. mutable int meleeValue;
  55. mutable int64_t rangedCachedLast;
  56. mutable int rangedValue;
  57. };
  58. class DLL_LINKAGE CCheckProxy
  59. {
  60. public:
  61. CCheckProxy(const IBonusBearer * Target, CSelector Selector);
  62. CCheckProxy(const CCheckProxy & other);
  63. CCheckProxy& operator= (const CCheckProxy & other) = default;
  64. bool getHasBonus() const;
  65. private:
  66. const IBonusBearer * target;
  67. CSelector selector;
  68. mutable int64_t cachedLast;
  69. mutable bool hasBonus;
  70. };
  71. VCMI_LIB_NAMESPACE_END