CBonusProxy.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * CBonusProxy.cpp, 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. #include "StdInc.h"
  11. #include "CBonusProxy.h"
  12. #include "IBonusBearer.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. ///CCheckProxy
  15. CCheckProxy::CCheckProxy(const IBonusBearer * Target, BonusType bonusType):
  16. target(Target),
  17. selector(Selector::type()(bonusType)),
  18. cachingStr("type_" + std::to_string(static_cast<int>(bonusType))),
  19. cachedLast(0),
  20. hasBonus(false)
  21. {
  22. }
  23. CCheckProxy::CCheckProxy(const IBonusBearer * Target, CSelector Selector, const std::string & cachingStr):
  24. target(Target),
  25. selector(std::move(Selector)),
  26. cachedLast(0),
  27. cachingStr(cachingStr),
  28. hasBonus(false)
  29. {
  30. }
  31. //This constructor should be placed here to avoid side effects
  32. CCheckProxy::CCheckProxy(const CCheckProxy & other) = default;
  33. bool CCheckProxy::getHasBonus() const
  34. {
  35. const auto treeVersion = target->getTreeVersion();
  36. if(treeVersion != cachedLast)
  37. {
  38. hasBonus = target->hasBonus(selector, cachingStr);
  39. cachedLast = treeVersion;
  40. }
  41. return hasBonus;
  42. }
  43. VCMI_LIB_NAMESPACE_END