Reward.h 3.7 KB

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