HeroBonus.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include "../global.h"
  3. #include <string>
  4. /*
  5. * HeroBonus.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. struct DLL_EXPORT HeroBonus
  14. {
  15. enum BonusType
  16. {
  17. //handled
  18. NONE,
  19. MOVEMENT, //both water/land
  20. LAND_MOVEMENT,
  21. SEA_MOVEMENT,
  22. MORALE,
  23. LUCK,
  24. MORALE_AND_LUCK,
  25. PRIMARY_SKILL, //uses subtype to pick skill
  26. SIGHT_RADIOUS,
  27. MANA_REGENERATION, //points per turn apart from normal (1 + mysticism)
  28. //not handled yet:
  29. MAGIC_RESISTANCE, // %
  30. SECONDARY_SKILL_PREMY, //%
  31. SURRENDER_DISCOUNT, //%
  32. STACKS_SPEED,
  33. FLYING_MOVEMENT, SPELL_DURATION, AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY,
  34. WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, WATER_WALKING, NO_SHOTING_PENALTY, DISPEL_IMMUNITY,
  35. NEGATE_ALL_NATURAL_IMMUNITIES, STACK_HEALTH, SPELL_IMMUNITY, BLOCK_MORALE, BLOCK_LUCK, FIRE_SPELLS,
  36. AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS,
  37. GENERATE_RESOURCE, //daily value, uses subtype (resource type)
  38. CREATURE_GROWTH, //for legion artifacts: value - week growth bonus, subtype - monster level
  39. WHIRLPOOL_PROTECTION, //hero won't lose army when teleporting through whirlpool
  40. SPELL, //hero knows spell, val - skill level (0 - 3), subtype - spell id
  41. SPELLS_OF_LEVEL, //hero knows all spells of given level, val - skill level; subtype - level
  42. ENEMY_CANT_ESCAPE //for shackles of war
  43. };
  44. enum BonusDuration{PERMANENT, ONE_BATTLE, ONE_DAY, ONE_WEEK};
  45. enum BonusSource{ARTIFACT, OBJECT};
  46. ui8 duration; //uses BonusDuration values
  47. ui8 type; //uses BonusType values - says to what is this bonus
  48. si32 subtype; //-1 if not applicable
  49. ui8 source;//uses BonusSource values - what gave that bonus
  50. si32 val;//for morale/luck [-3,+3], others any
  51. ui32 id; //id of object/artifact
  52. std::string description;
  53. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1)
  54. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID), description(Desc)
  55. {}
  56. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1)
  57. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID)
  58. {}
  59. HeroBonus()
  60. {
  61. subtype = -1;
  62. }
  63. template <typename Handler> void serialize(Handler &h, const int version)
  64. {
  65. h & duration & type & source & val & id & description;
  66. }
  67. static bool OneDay(const HeroBonus &hb)
  68. {
  69. return hb.duration==HeroBonus::ONE_DAY;
  70. }
  71. static bool OneWeek(const HeroBonus &hb)
  72. {
  73. return hb.duration==HeroBonus::ONE_WEEK;
  74. }
  75. static bool OneBattle(const HeroBonus &hb)
  76. {
  77. return hb.duration==HeroBonus::ONE_BATTLE;
  78. }
  79. static bool IsFrom(const HeroBonus &hb, ui8 source, ui32 id) //if id==0xffffff then id doesn't matter
  80. {
  81. return hb.source==source && (id==0xffffff || hb.id==id);
  82. }
  83. };