Reward.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Reward.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 "../ResourceSet.h"
  12. #include "../bonuses/Bonus.h"
  13. #include "../CCreatureSet.h"
  14. #include "../networkPacks/Component.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. struct Bonus;
  17. struct Component;
  18. class CStackBasicDescriptor;
  19. class CGHeroInstance;
  20. namespace Rewardable
  21. {
  22. struct Reward;
  23. using RewardsList = std::vector<std::shared_ptr<Rewardable::Reward>>;
  24. struct RewardRevealTiles
  25. {
  26. /// Reveal distance, if not positive - reveal entire map
  27. int radius;
  28. /// Reveal score of terrains with "surface" flag set
  29. int scoreSurface;
  30. /// Reveal score of terrains with "subterra" flag set
  31. int scoreSubterra;
  32. /// Reveal score of terrains with "water" flag set
  33. int scoreWater;
  34. /// Reveal score of terrains with "rock" flag set
  35. int scoreRock;
  36. /// If set, then terrain will be instead hidden for all enemies (Cover of Darkness)
  37. bool hide;
  38. void serializeJson(JsonSerializeFormat & handler);
  39. template <typename Handler> void serialize(Handler &h)
  40. {
  41. h & radius;
  42. h & scoreSurface;
  43. h & scoreSubterra;
  44. h & scoreWater;
  45. h & scoreRock;
  46. h & hide;
  47. }
  48. };
  49. /// Reward that can be granted to a hero
  50. /// NOTE: eventually should replace seer hut rewards and events/pandoras
  51. struct DLL_LINKAGE Reward final
  52. {
  53. /// resources that will be given to player
  54. TResources resources;
  55. /// received experience
  56. si32 heroExperience;
  57. /// received levels (converted into XP during grant)
  58. si32 heroLevel;
  59. /// mana given to/taken from hero, fixed value
  60. si32 manaDiff;
  61. /// if giving mana points puts hero above mana pool, any overflow will be multiplied by specified percentage
  62. si32 manaOverflowFactor;
  63. /// fixed value, in form of percentage from max
  64. si32 manaPercentage;
  65. /// movement points, only for current day. Bonuses should be used to grant MP on any other day
  66. si32 movePoints;
  67. /// fixed value, in form of percentage from max
  68. si32 movePercentage;
  69. /// Guards that must be defeated in order to access this reward, empty if not guarded
  70. std::vector<CStackBasicDescriptor> guards;
  71. /// list of bonuses, e.g. morale/luck
  72. std::vector<Bonus> bonuses;
  73. /// skills that hero may receive or lose
  74. std::vector<si32> primary;
  75. std::map<SecondarySkill, si32> secondary;
  76. /// creatures that will be changed in hero's army
  77. std::map<CreatureID, CreatureID> creaturesChange;
  78. /// objects that hero may receive
  79. std::vector<ArtifactID> artifacts;
  80. std::vector<SpellID> spells;
  81. std::vector<CStackBasicDescriptor> creatures;
  82. /// actions that hero may execute and object caster. Pair of spellID and school level
  83. std::pair<SpellID, int> spellCast;
  84. /// list of components that will be added to reward description. First entry in list will override displayed component
  85. std::vector<Component> extraComponents;
  86. std::optional<RewardRevealTiles> revealTiles;
  87. /// if set to true, object will be removed after granting reward
  88. bool removeObject;
  89. /// Generates list of components that describes reward for a specific hero
  90. /// If hero is nullptr, then rewards will be generated without accounting for hero
  91. void loadComponents(std::vector<Component> & comps, const CGHeroInstance * h) const;
  92. Component getDisplayedComponent(const CGHeroInstance * h) const;
  93. si32 calculateManaPoints(const CGHeroInstance * h) const;
  94. Reward();
  95. ~Reward();
  96. template <typename Handler> void serialize(Handler &h)
  97. {
  98. h & resources;
  99. h & extraComponents;
  100. h & removeObject;
  101. h & manaPercentage;
  102. h & movePercentage;
  103. if (h.version >= Handler::Version::REWARDABLE_GUARDS)
  104. h & guards;
  105. h & heroExperience;
  106. h & heroLevel;
  107. h & manaDiff;
  108. h & manaOverflowFactor;
  109. h & movePoints;
  110. h & primary;
  111. h & secondary;
  112. h & bonuses;
  113. h & artifacts;
  114. h & spells;
  115. h & creatures;
  116. h & creaturesChange;
  117. h & revealTiles;
  118. h & spellCast;
  119. }
  120. void serializeJson(JsonSerializeFormat & handler);
  121. };
  122. }
  123. VCMI_LIB_NAMESPACE_END