HeroBonus.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /*
  2. * HeroBonus.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 "../JsonNode.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. struct Bonus;
  14. class IBonusBearer;
  15. class CBonusSystemNode;
  16. class ILimiter;
  17. class IPropagator;
  18. class IUpdater;
  19. class BonusList;
  20. using TBonusSubtype = int32_t;
  21. using TBonusListPtr = std::shared_ptr<BonusList>;
  22. using TConstBonusListPtr = std::shared_ptr<const BonusList>;
  23. using TLimiterPtr = std::shared_ptr<ILimiter>;
  24. using TPropagatorPtr = std::shared_ptr<IPropagator>;
  25. using TUpdaterPtr = std::shared_ptr<IUpdater>;
  26. class DLL_LINKAGE CAddInfo : public std::vector<si32>
  27. {
  28. public:
  29. enum { NONE = -1 };
  30. CAddInfo();
  31. CAddInfo(si32 value);
  32. bool operator==(si32 value) const;
  33. bool operator!=(si32 value) const;
  34. si32 & operator[](size_type pos);
  35. si32 operator[](size_type pos) const;
  36. std::string toString() const;
  37. JsonNode toJsonNode() const;
  38. };
  39. #define BONUS_TREE_DESERIALIZATION_FIX if(!h.saving && h.smartPointerSerialization) deserializationFix();
  40. #define BONUS_LIST \
  41. BONUS_NAME(NONE) \
  42. BONUS_NAME(LEVEL_COUNTER) /* for commander artifacts*/ \
  43. BONUS_NAME(MOVEMENT) /*Subtype is 1 - land, 0 - sea*/ \
  44. BONUS_NAME(MORALE) \
  45. BONUS_NAME(LUCK) \
  46. BONUS_NAME(PRIMARY_SKILL) /*uses subtype to pick skill; additional info if set: 1 - only melee, 2 - only distance*/ \
  47. BONUS_NAME(SIGHT_RADIUS) \
  48. BONUS_NAME(MANA_REGENERATION) /*points per turn apart from normal (1 + mysticism)*/ \
  49. BONUS_NAME(FULL_MANA_REGENERATION) /*all mana points are replenished every day*/ \
  50. BONUS_NAME(NONEVIL_ALIGNMENT_MIX) /*good and neutral creatures can be mixed without morale penalty*/ \
  51. BONUS_NAME(SURRENDER_DISCOUNT) /*%*/ \
  52. BONUS_NAME(STACKS_SPEED) /*additional info - percent of speed bonus applied after direct bonuses; >0 - added, <0 - subtracted to this part*/ \
  53. BONUS_NAME(FLYING_MOVEMENT) /*value - penalty percentage*/ \
  54. BONUS_NAME(SPELL_DURATION) \
  55. BONUS_NAME(AIR_SPELL_DMG_PREMY) \
  56. BONUS_NAME(EARTH_SPELL_DMG_PREMY) \
  57. BONUS_NAME(FIRE_SPELL_DMG_PREMY) \
  58. BONUS_NAME(WATER_SPELL_DMG_PREMY) \
  59. BONUS_NAME(WATER_WALKING) /*value - penalty percentage*/ \
  60. BONUS_NAME(NEGATE_ALL_NATURAL_IMMUNITIES) \
  61. BONUS_NAME(STACK_HEALTH) \
  62. BONUS_NAME(FIRE_SPELLS) \
  63. BONUS_NAME(AIR_SPELLS) \
  64. BONUS_NAME(WATER_SPELLS) \
  65. BONUS_NAME(EARTH_SPELLS) \
  66. BONUS_NAME(GENERATE_RESOURCE) /*daily value, uses subtype (resource type)*/ \
  67. BONUS_NAME(CREATURE_GROWTH) /*for legion artifacts: value - week growth bonus, subtype - monster level if aplicable*/ \
  68. BONUS_NAME(WHIRLPOOL_PROTECTION) /*hero won't lose army when teleporting through whirlpool*/ \
  69. BONUS_NAME(SPELL) /*hero knows spell, val - skill level (0 - 3), subtype - spell id*/ \
  70. BONUS_NAME(SPELLS_OF_LEVEL) /*hero knows all spells of given level, val - skill level; subtype - level*/ \
  71. BONUS_NAME(BATTLE_NO_FLEEING) /*for shackles of war*/ \
  72. BONUS_NAME(MAGIC_SCHOOL_SKILL) /* //eg. for magic plains terrain, subtype: school of magic (0 - all, 1 - fire, 2 - air, 4 - water, 8 - earth), value - level*/ \
  73. BONUS_NAME(FREE_SHOOTING) /*stacks can shoot even if otherwise blocked (sharpshooter's bow effect)*/ \
  74. BONUS_NAME(OPENING_BATTLE_SPELL) /*casts a spell at expert level at beginning of battle, val - spell power, subtype - spell id*/ \
  75. BONUS_NAME(IMPROVED_NECROMANCY) /* raise more powerful creatures: subtype - creature type raised, addInfo - [required necromancy level, required stack level], val - necromancy level for this purpose */ \
  76. BONUS_NAME(CREATURE_GROWTH_PERCENT) /*increases growth of all units in all towns, val - percentage*/ \
  77. BONUS_NAME(FREE_SHIP_BOARDING) /*movement points preserved with ship boarding and landing*/ \
  78. BONUS_NAME(FLYING) \
  79. BONUS_NAME(SHOOTER) \
  80. BONUS_NAME(CHARGE_IMMUNITY) \
  81. BONUS_NAME(ADDITIONAL_ATTACK) \
  82. BONUS_NAME(UNLIMITED_RETALIATIONS) \
  83. BONUS_NAME(NO_MELEE_PENALTY) \
  84. BONUS_NAME(JOUSTING) /*for champions*/ \
  85. BONUS_NAME(HATE) /*eg. angels hate devils, subtype - ID of hated creature, val - damage bonus percent */ \
  86. BONUS_NAME(KING) /* val - required slayer bonus val to affect */\
  87. BONUS_NAME(MAGIC_RESISTANCE) /*in % (value)*/ \
  88. BONUS_NAME(CHANGES_SPELL_COST_FOR_ALLY) /*in mana points (value) , eg. mage*/ \
  89. BONUS_NAME(CHANGES_SPELL_COST_FOR_ENEMY) /*in mana points (value) , eg. pegasus */ \
  90. BONUS_NAME(SPELL_AFTER_ATTACK) /* subtype - spell id, value - chance %, addInfo[0] - level, addInfo[1] -> [0 - all attacks, 1 - shot only, 2 - melee only] */ \
  91. BONUS_NAME(SPELL_BEFORE_ATTACK) /* subtype - spell id, value - chance %, addInfo[0] - level, addInfo[1] -> [0 - all attacks, 1 - shot only, 2 - melee only] */ \
  92. BONUS_NAME(SPELL_RESISTANCE_AURA) /*eg. unicorns, value - resistance bonus in % for adjacent creatures*/ \
  93. BONUS_NAME(LEVEL_SPELL_IMMUNITY) /*creature is immune to all spell with level below or equal to value of this bonus */ \
  94. BONUS_NAME(BLOCK_MAGIC_ABOVE) /*blocks casting spells of the level > value */ \
  95. BONUS_NAME(BLOCK_ALL_MAGIC) /*blocks casting spells*/ \
  96. BONUS_NAME(TWO_HEX_ATTACK_BREATH) /*eg. dragons*/ \
  97. BONUS_NAME(SPELL_DAMAGE_REDUCTION) /*eg. golems; value - reduction in %, subtype - spell school; -1 - all, 0 - air, 1 - fire, 2 - water, 3 - earth*/ \
  98. BONUS_NAME(NO_WALL_PENALTY) \
  99. BONUS_NAME(NON_LIVING) /*eg. golems, cannot be rised or healed, only neutral morale */ \
  100. BONUS_NAME(RANDOM_SPELLCASTER) /*eg. master genie, val - level*/ \
  101. BONUS_NAME(BLOCKS_RETALIATION) /*eg. naga*/ \
  102. BONUS_NAME(SPELL_IMMUNITY) /*subid - spell id*/ \
  103. BONUS_NAME(MANA_CHANNELING) /*value in %, eg. familiar*/ \
  104. BONUS_NAME(SPELL_LIKE_ATTACK) /*subtype - spell, value - spell level; range is taken from spell, but damage from creature; eg. magog*/ \
  105. BONUS_NAME(THREE_HEADED_ATTACK) /*eg. cerberus*/ \
  106. BONUS_NAME(GENERAL_DAMAGE_PREMY) \
  107. BONUS_NAME(FIRE_IMMUNITY) /*subtype 0 - all, 1 - all except positive, 2 - only damage spells*/ \
  108. BONUS_NAME(WATER_IMMUNITY) \
  109. BONUS_NAME(EARTH_IMMUNITY) \
  110. BONUS_NAME(AIR_IMMUNITY) \
  111. BONUS_NAME(MIND_IMMUNITY) \
  112. BONUS_NAME(FIRE_SHIELD) \
  113. BONUS_NAME(UNDEAD) \
  114. BONUS_NAME(HP_REGENERATION) /*creature regenerates val HP every new round*/ \
  115. BONUS_NAME(MANA_DRAIN) /*value - spell points per turn*/ \
  116. BONUS_NAME(LIFE_DRAIN) \
  117. BONUS_NAME(DOUBLE_DAMAGE_CHANCE) /*value in %, eg. dread knight*/ \
  118. BONUS_NAME(RETURN_AFTER_STRIKE) \
  119. BONUS_NAME(SPELLCASTER) /*subtype - spell id, value - level of school, additional info - weighted chance. use SPECIFIC_SPELL_POWER, CREATURE_SPELL_POWER or CREATURE_ENCHANT_POWER for calculating the power*/ \
  120. BONUS_NAME(CATAPULT) \
  121. BONUS_NAME(ENEMY_DEFENCE_REDUCTION) /*in % (value) eg. behemots*/ \
  122. BONUS_NAME(GENERAL_DAMAGE_REDUCTION) /* shield / air shield effect, also armorer skill/petrify effect for subtype -1*/ \
  123. BONUS_NAME(GENERAL_ATTACK_REDUCTION) /*eg. while stoned or blinded - in %,// subtype not used, use ONLY_MELEE_FIGHT / DISTANCE_FIGHT*/ \
  124. BONUS_NAME(DEFENSIVE_STANCE) /* val - bonus to defense while defending */ \
  125. BONUS_NAME(ATTACKS_ALL_ADJACENT) /*eg. hydra*/ \
  126. BONUS_NAME(MORE_DAMAGE_FROM_SPELL) /*value - damage increase in %, subtype - spell id*/ \
  127. BONUS_NAME(FEAR) \
  128. BONUS_NAME(FEARLESS) \
  129. BONUS_NAME(NO_DISTANCE_PENALTY) \
  130. BONUS_NAME(ENCHANTER)/* for Enchanter spells, val - skill level, subtype - spell id, additionalInfo - cooldown */ \
  131. BONUS_NAME(HEALER) \
  132. BONUS_NAME(SIEGE_WEAPON) \
  133. BONUS_NAME(HYPNOTIZED) \
  134. BONUS_NAME(NO_RETALIATION) /*temporary bonus for basilisk, unicorn and scorpicore paralyze*/\
  135. BONUS_NAME(ADDITIONAL_RETALIATION) /*value - number of additional retaliations*/ \
  136. BONUS_NAME(MAGIC_MIRROR) /* value - chance of redirecting in %*/ \
  137. BONUS_NAME(ALWAYS_MINIMUM_DAMAGE) /*unit does its minimum damage from range; subtype: -1 - any attack, 0 - melee, 1 - ranged, value: additional damage penalty (it'll subtracted from dmg), additional info - multiplicative anti-bonus for dmg in % [eg 20 means that creature will inflict 80% of normal minimal dmg]*/ \
  138. BONUS_NAME(ALWAYS_MAXIMUM_DAMAGE) /*eg. bless effect, subtype: -1 - any attack, 0 - melee, 1 - ranged, value: additional damage, additional info - multiplicative bonus for dmg in %*/ \
  139. BONUS_NAME(ATTACKS_NEAREST_CREATURE) /*while in berserk*/ \
  140. BONUS_NAME(IN_FRENZY) /*value - level*/ \
  141. BONUS_NAME(SLAYER) /*value - level*/ \
  142. BONUS_NAME(FORGETFULL) /*forgetfulness spell effect, value - level*/ \
  143. BONUS_NAME(NOT_ACTIVE) /* subtype - spell ID (paralyze, blind, stone gaze) for graphical effect*/ \
  144. BONUS_NAME(NO_LUCK) /*eg. when fighting on cursed ground*/ \
  145. BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \
  146. BONUS_NAME(DARKNESS) /*val = radius */ \
  147. BONUS_NAME(SPECIAL_SPELL_LEV) /*subtype = id, val = value per level in percent*/\
  148. BONUS_NAME(SPELL_DAMAGE) /*val = value, now works for sorcery*/\
  149. BONUS_NAME(SPECIFIC_SPELL_DAMAGE) /*subtype = id of spell, val = value*/\
  150. BONUS_NAME(SPECIAL_PECULIAR_ENCHANT) /*blesses and curses with id = val dependent on unit's level, subtype = 0 or 1 for Coronius*/\
  151. BONUS_NAME(SPECIAL_UPGRADE) /*subtype = base, additionalInfo = target */\
  152. BONUS_NAME(DRAGON_NATURE) \
  153. BONUS_NAME(CREATURE_DAMAGE)/*subtype 0 = both, 1 = min, 2 = max*/\
  154. BONUS_NAME(EXP_MULTIPLIER)/* val - percent of additional exp gained by stack/commander (base value 100)*/\
  155. BONUS_NAME(SHOTS)\
  156. BONUS_NAME(DEATH_STARE) /*subtype 0 - gorgon, 1 - commander*/\
  157. BONUS_NAME(POISON) /*val - max health penalty from poison possible*/\
  158. BONUS_NAME(BIND_EFFECT) /*doesn't do anything particular, works as a marker)*/\
  159. BONUS_NAME(ACID_BREATH) /*additional val damage per creature after attack, additional info - chance in percent*/\
  160. BONUS_NAME(RECEPTIVE) /*accepts friendly spells even with immunity*/\
  161. BONUS_NAME(DIRECT_DAMAGE_IMMUNITY) /*direct damage spells, that is*/\
  162. BONUS_NAME(CASTS) /*how many times creature can cast activated spell*/ \
  163. BONUS_NAME(SPECIFIC_SPELL_POWER) /* value used for Thunderbolt and Resurrection cast by units, subtype - spell id */\
  164. BONUS_NAME(CREATURE_SPELL_POWER) /* value per unit, divided by 100 (so faerie Dragons have 800)*/ \
  165. BONUS_NAME(CREATURE_ENCHANT_POWER) /* total duration of spells cast by creature */ \
  166. BONUS_NAME(ENCHANTED) /* permanently enchanted with spell subID of level = val, if val > 3 then spell is mass and has level of val-3*/ \
  167. BONUS_NAME(REBIRTH) /* val - percent of life restored, subtype = 0 - regular, 1 - at least one unit (sacred Phoenix) */\
  168. BONUS_NAME(ADDITIONAL_UNITS) /*val of units with id = subtype will be added to hero's army at the beginning of battle */\
  169. BONUS_NAME(SPOILS_OF_WAR) /*val * 10^-6 * gained exp resources of subtype will be given to hero after battle*/\
  170. BONUS_NAME(BLOCK)\
  171. BONUS_NAME(DISGUISED) /* subtype - spell level */\
  172. BONUS_NAME(VISIONS) /* subtype - spell level */\
  173. BONUS_NAME(NO_TERRAIN_PENALTY) /* subtype - terrain type */\
  174. BONUS_NAME(SOUL_STEAL) /*val - number of units gained per enemy killed, subtype = 0 - gained units survive after battle, 1 - they do not*/ \
  175. BONUS_NAME(TRANSMUTATION) /*val - chance to trigger in %, subtype = 0 - resurrection based on HP, 1 - based on unit count, additional info - target creature ID (attacker default)*/\
  176. BONUS_NAME(SUMMON_GUARDIANS) /*val - amount in % of stack count, subtype = creature ID*/\
  177. BONUS_NAME(CATAPULT_EXTRA_SHOTS) /*val - power of catapult effect, requires CATAPULT bonus to work*/\
  178. BONUS_NAME(RANGED_RETALIATION) /*allows shooters to perform ranged retaliation*/\
  179. BONUS_NAME(BLOCKS_RANGED_RETALIATION) /*disallows ranged retaliation for shooter unit, BLOCKS_RETALIATION bonus is for melee retaliation only*/\
  180. BONUS_NAME(MANUAL_CONTROL) /* manually control warmachine with id = subtype, chance = val */ \
  181. BONUS_NAME(WIDE_BREATH) /* initial desigh: dragon breath affecting multiple nearby hexes */\
  182. BONUS_NAME(FIRST_STRIKE) /* first counterattack, then attack if possible */\
  183. BONUS_NAME(SYNERGY_TARGET) /* dummy skill for alternative upgrades mod */\
  184. BONUS_NAME(SHOOTS_ALL_ADJACENT) /* H4 Cyclops-like shoot (attacks all hexes neighboring with target) without spell-like mechanics */\
  185. BONUS_NAME(BLOCK_MAGIC_BELOW) /*blocks casting spells of the level < value */ \
  186. BONUS_NAME(DESTRUCTION) /*kills extra units after hit, subtype = 0 - kill percentage of units, 1 - kill amount, val = chance in percent to trigger, additional info - amount/percentage to kill*/ \
  187. BONUS_NAME(SPECIAL_CRYSTAL_GENERATION) /*crystal dragon crystal generation*/ \
  188. BONUS_NAME(NO_SPELLCAST_BY_DEFAULT) /*spellcast will not be default attack option for this creature*/ \
  189. BONUS_NAME(GARGOYLE) /* gargoyle is special than NON_LIVING, cannot be rised or healed */ \
  190. BONUS_NAME(SPECIAL_ADD_VALUE_ENCHANT) /*specialty spell like Aenin has, increased effect of spell, additionalInfo = value to add*/\
  191. BONUS_NAME(SPECIAL_FIXED_VALUE_ENCHANT) /*specialty spell like Melody has, constant spell effect (i.e. 3 luck), additionalInfo = value to fix.*/\
  192. BONUS_NAME(TOWN_MAGIC_WELL) /*one-time pseudo-bonus to implement Magic Well in the town*/\
  193. BONUS_NAME(LIMITED_SHOOTING_RANGE) /*limits range of shooting creatures, doesn't adjust any other mechanics (half vs full damage etc). val - range in hexes, additional info - optional new range for broken arrow mechanic */\
  194. BONUS_NAME(LEARN_BATTLE_SPELL_CHANCE) /*skill-agnostic eagle eye chance. subtype = 0 - from enemy, 1 - TODO: from entire battlefield*/\
  195. BONUS_NAME(LEARN_BATTLE_SPELL_LEVEL_LIMIT) /*skill-agnostic eagle eye limit, subtype - school (-1 for all), others TODO*/\
  196. BONUS_NAME(PERCENTAGE_DAMAGE_BOOST) /*skill-agnostic archery and offence, subtype is 0 for offence and 1 for archery*/\
  197. BONUS_NAME(LEARN_MEETING_SPELL_LIMIT) /*skill-agnostic scholar, subtype is -1 for all, TODO for others (> 0)*/\
  198. BONUS_NAME(ROUGH_TERRAIN_DISCOUNT) /*skill-agnostic pathfinding*/\
  199. BONUS_NAME(WANDERING_CREATURES_JOIN_BONUS) /*skill-agnostic diplomacy*/\
  200. BONUS_NAME(BEFORE_BATTLE_REPOSITION) /*skill-agnostic tactics, bonus for allowing tactics*/\
  201. BONUS_NAME(BEFORE_BATTLE_REPOSITION_BLOCK) /*skill-agnostic tactics, bonus for blocking opposite tactics. For now donble side tactics is TODO.*/\
  202. BONUS_NAME(HERO_EXPERIENCE_GAIN_PERCENT) /*skill-agnostic learning, and we can use it as a global effect also*/\
  203. BONUS_NAME(UNDEAD_RAISE_PERCENTAGE) /*Percentage of killed enemy creatures to be raised after battle as undead*/\
  204. BONUS_NAME(MANA_PER_KNOWLEDGE) /*Percentage rate of translating 10 hero knowledge to mana, used to intelligence and global bonus*/\
  205. BONUS_NAME(HERO_GRANTS_ATTACKS) /*If hero can grant additional attacks to creature, value is number of attacks, subtype is creatureID*/\
  206. BONUS_NAME(BONUS_DAMAGE_PERCENTAGE) /*If hero can grant conditional damage to creature, value is percentage, subtype is creatureID*/\
  207. BONUS_NAME(BONUS_DAMAGE_CHANCE) /*If hero can grant additional damage to creature, value is chance, subtype is creatureID*/\
  208. BONUS_NAME(MAX_LEARNABLE_SPELL_LEVEL) /*This can work as wisdom before. val = max learnable spell level*/\
  209. /* end of list */
  210. #define BONUS_SOURCE_LIST \
  211. BONUS_SOURCE(ARTIFACT)\
  212. BONUS_SOURCE(ARTIFACT_INSTANCE)\
  213. BONUS_SOURCE(OBJECT)\
  214. BONUS_SOURCE(CREATURE_ABILITY)\
  215. BONUS_SOURCE(TERRAIN_NATIVE)\
  216. BONUS_SOURCE(TERRAIN_OVERLAY)\
  217. BONUS_SOURCE(SPELL_EFFECT)\
  218. BONUS_SOURCE(TOWN_STRUCTURE)\
  219. BONUS_SOURCE(HERO_BASE_SKILL)\
  220. BONUS_SOURCE(SECONDARY_SKILL)\
  221. BONUS_SOURCE(HERO_SPECIAL)\
  222. BONUS_SOURCE(ARMY)\
  223. BONUS_SOURCE(CAMPAIGN_BONUS)\
  224. BONUS_SOURCE(SPECIAL_WEEK)\
  225. BONUS_SOURCE(STACK_EXPERIENCE)\
  226. BONUS_SOURCE(COMMANDER) /*TODO: consider using simply STACK_INSTANCE */\
  227. BONUS_SOURCE(GLOBAL) /*used for base bonuses which all heroes or all stacks should have*/\
  228. BONUS_SOURCE(OTHER) /*used for defensive stance and default value of spell level limit*/
  229. #define BONUS_VALUE_LIST \
  230. BONUS_VALUE(ADDITIVE_VALUE)\
  231. BONUS_VALUE(BASE_NUMBER)\
  232. BONUS_VALUE(PERCENT_TO_ALL)\
  233. BONUS_VALUE(PERCENT_TO_BASE)\
  234. BONUS_VALUE(PERCENT_TO_SOURCE) /*Adds value only to bonuses with same source*/\
  235. BONUS_VALUE(PERCENT_TO_TARGET_TYPE) /*Adds value only to bonuses with SourceType target*/\
  236. BONUS_VALUE(INDEPENDENT_MAX) /*used for SPELL bonus */\
  237. BONUS_VALUE(INDEPENDENT_MIN) //used for SECONDARY_SKILL_PREMY bonus
  238. /// Struct for handling bonuses of several types. Can be transferred to any hero
  239. struct DLL_LINKAGE Bonus : public std::enable_shared_from_this<Bonus>
  240. {
  241. enum BonusType
  242. {
  243. #define BONUS_NAME(x) x,
  244. BONUS_LIST
  245. #undef BONUS_NAME
  246. };
  247. enum BonusDuration //when bonus is automatically removed
  248. {
  249. PERMANENT = 1,
  250. ONE_BATTLE = 2, //at the end of battle
  251. ONE_DAY = 4, //at the end of day
  252. ONE_WEEK = 8, //at the end of week (bonus lasts till the end of week, thats NOT 7 days
  253. N_TURNS = 16, //used during battles, after battle bonus is always removed
  254. N_DAYS = 32,
  255. UNTIL_BEING_ATTACKED = 64, /*removed after attack and counterattacks are performed*/
  256. UNTIL_ATTACK = 128, /*removed after attack and counterattacks are performed*/
  257. STACK_GETS_TURN = 256, /*removed when stack gets its turn - used for defensive stance*/
  258. COMMANDER_KILLED = 512
  259. };
  260. enum BonusSource
  261. {
  262. #define BONUS_SOURCE(x) x,
  263. BONUS_SOURCE_LIST
  264. #undef BONUS_SOURCE
  265. NUM_BONUS_SOURCE /*This is a dummy value, which will be always last*/
  266. };
  267. enum LimitEffect
  268. {
  269. NO_LIMIT = 0,
  270. ONLY_DISTANCE_FIGHT=1, ONLY_MELEE_FIGHT, //used to mark bonuses for attack/defense primary skills from spells like Precision (distance only)
  271. };
  272. enum ValueType
  273. {
  274. #define BONUS_VALUE(x) x,
  275. BONUS_VALUE_LIST
  276. #undef BONUS_VALUE
  277. };
  278. ui16 duration = PERMANENT; //uses BonusDuration values
  279. si16 turnsRemain = 0; //used if duration is N_TURNS, N_DAYS or ONE_WEEK
  280. BonusType type = NONE; //uses BonusType values - says to what is this bonus - 1 byte
  281. TBonusSubtype subtype = -1; //-1 if not applicable - 4 bytes
  282. BonusSource source = OTHER; //source type" uses BonusSource values - what gave that bonus
  283. BonusSource targetSourceType;//Bonuses of what origin this amplifies, uses BonusSource values. Needed for PERCENT_TO_TARGET_TYPE.
  284. si32 val = 0;
  285. ui32 sid = 0; //source id: id of object/artifact/spell
  286. ValueType valType = ADDITIVE_VALUE;
  287. std::string stacking; // bonuses with the same stacking value don't stack (e.g. Angel/Archangel morale bonus)
  288. CAddInfo additionalInfo;
  289. LimitEffect effectRange = NO_LIMIT; //if not NO_LIMIT, bonus will be omitted by default
  290. TLimiterPtr limiter;
  291. TPropagatorPtr propagator;
  292. TUpdaterPtr updater;
  293. TUpdaterPtr propagationUpdater;
  294. std::string description;
  295. Bonus(BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1);
  296. Bonus(BonusDuration Duration, BonusType Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype=-1, ValueType ValType = ADDITIVE_VALUE);
  297. Bonus() = default;
  298. template <typename Handler> void serialize(Handler &h, const int version)
  299. {
  300. h & duration;
  301. h & type;
  302. h & subtype;
  303. h & source;
  304. h & val;
  305. h & sid;
  306. h & description;
  307. h & additionalInfo;
  308. h & turnsRemain;
  309. h & valType;
  310. h & stacking;
  311. h & effectRange;
  312. h & limiter;
  313. h & propagator;
  314. h & updater;
  315. h & propagationUpdater;
  316. h & targetSourceType;
  317. }
  318. template <typename Ptr>
  319. static bool compareByAdditionalInfo(const Ptr& a, const Ptr& b)
  320. {
  321. return a->additionalInfo < b->additionalInfo;
  322. }
  323. static bool NDays(const Bonus *hb)
  324. {
  325. return hb->duration & Bonus::N_DAYS;
  326. }
  327. static bool NTurns(const Bonus *hb)
  328. {
  329. return hb->duration & Bonus::N_TURNS;
  330. }
  331. static bool OneDay(const Bonus *hb)
  332. {
  333. return hb->duration & Bonus::ONE_DAY;
  334. }
  335. static bool OneWeek(const Bonus *hb)
  336. {
  337. return hb->duration & Bonus::ONE_WEEK;
  338. }
  339. static bool OneBattle(const Bonus *hb)
  340. {
  341. return hb->duration & Bonus::ONE_BATTLE;
  342. }
  343. static bool Permanent(const Bonus *hb)
  344. {
  345. return hb->duration & Bonus::PERMANENT;
  346. }
  347. static bool UntilGetsTurn(const Bonus *hb)
  348. {
  349. return hb->duration & Bonus::STACK_GETS_TURN;
  350. }
  351. static bool UntilAttack(const Bonus *hb)
  352. {
  353. return hb->duration & Bonus::UNTIL_ATTACK;
  354. }
  355. static bool UntilBeingAttacked(const Bonus *hb)
  356. {
  357. return hb->duration & Bonus::UNTIL_BEING_ATTACKED;
  358. }
  359. static bool UntilCommanderKilled(const Bonus *hb)
  360. {
  361. return hb->duration & Bonus::COMMANDER_KILLED;
  362. }
  363. inline bool operator == (const BonusType & cf) const
  364. {
  365. return type == cf;
  366. }
  367. inline void operator += (const ui32 Val) //no return
  368. {
  369. val += Val;
  370. }
  371. STRONG_INLINE static ui32 getSid32(ui32 high, ui32 low)
  372. {
  373. return (high << 16) + low;
  374. }
  375. STRONG_INLINE static ui32 getHighFromSid32(ui32 sid)
  376. {
  377. return sid >> 16;
  378. }
  379. STRONG_INLINE static ui32 getLowFromSid32(ui32 sid)
  380. {
  381. return sid & 0x0000FFFF;
  382. }
  383. std::string Description(std::optional<si32> customValue = {}) const;
  384. JsonNode toJsonNode() const;
  385. std::string nameForBonus() const; // generate suitable name for bonus - e.g. for storing in json struct
  386. std::shared_ptr<Bonus> addLimiter(const TLimiterPtr & Limiter); //returns this for convenient chain-calls
  387. std::shared_ptr<Bonus> addPropagator(const TPropagatorPtr & Propagator); //returns this for convenient chain-calls
  388. std::shared_ptr<Bonus> addUpdater(const TUpdaterPtr & Updater); //returns this for convenient chain-calls
  389. };
  390. DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const Bonus &bonus);
  391. extern DLL_LINKAGE const std::map<std::string, Bonus::BonusType> bonusNameMap;
  392. extern DLL_LINKAGE const std::map<std::string, Bonus::ValueType> bonusValueMap;
  393. extern DLL_LINKAGE const std::map<std::string, Bonus::BonusSource> bonusSourceMap;
  394. extern DLL_LINKAGE const std::map<std::string, ui16> bonusDurationMap;
  395. extern DLL_LINKAGE const std::map<std::string, Bonus::LimitEffect> bonusLimitEffect;
  396. extern DLL_LINKAGE const std::set<std::string> deprecatedBonusSet;
  397. VCMI_LIB_NAMESPACE_END