HeroBonus.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. FULL_MANA_REGENERATION, //all mana points are replenished every day
  29. NONEVIL_ALIGNMENT_MIX, //good and neutral creatures can be mixed without morale penalty
  30. HP_REGENERATION, //regenerates a certain amount of hp for the top of each stack every turn, val - hp regained
  31. LEVEL_SPELL_IMMUNITY, //val - spell level creatures become immune to and below
  32. //not handled yet:
  33. MAGIC_RESISTANCE, // %
  34. SECONDARY_SKILL_PREMY, //%
  35. SURRENDER_DISCOUNT, //%
  36. STACKS_SPEED,
  37. FLYING_MOVEMENT, SPELL_DURATION, AIR_SPELL_DMG_PREMY, EARTH_SPELL_DMG_PREMY, FIRE_SPELL_DMG_PREMY,
  38. WATER_SPELL_DMG_PREMY, BLOCK_SPELLS_ABOVE_LEVEL, WATER_WALKING, NO_SHOTING_PENALTY, DISPEL_IMMUNITY,
  39. NEGATE_ALL_NATURAL_IMMUNITIES, STACK_HEALTH, STACK_HEALTH_PERCENT, //the second one of stack health - value in % of base HP to be added to overall stack HP
  40. SPELL_IMMUNITY, BLOCK_MORALE, BLOCK_LUCK, FIRE_SPELLS,
  41. AIR_SPELLS, WATER_SPELLS, EARTH_SPELLS,
  42. GENERATE_RESOURCE, //daily value, uses subtype (resource type)
  43. CREATURE_GROWTH, //for legion artifacts: value - week growth bonus, subtype - monster level
  44. WHIRLPOOL_PROTECTION, //hero won't lose army when teleporting through whirlpool
  45. SPELL, //hero knows spell, val - skill level (0 - 3), subtype - spell id
  46. SPELLS_OF_LEVEL, //hero knows all spells of given level, val - skill level; subtype - level
  47. ENEMY_CANT_ESCAPE, //for shackles of war
  48. MAGIC_SCHOOL_SKILL, //eg. for magic plains terrain, subtype: school of magic (0 - all, 1 - fire, 2 - air, 4 - water, 8 - earth), value - level
  49. FREE_SHOOTING, //stacks can shoot even if otherwise blocked (sharpshooter's bow effect)
  50. OPENING_BATTLE_SPELL, //casts a spell at expert level at beginning of battle, val - spell power, subtype - spell id
  51. IMPROVED_NECROMANCY, //allows Necropolis units other than skeletons to be raised by necromancy
  52. CREATURE_GROWTH_PERCENT, //increases growth of all units in all towns, val - percentage
  53. FREE_SHIP_BOARDING //movement points preserved with ship boarding and landing
  54. };
  55. enum BonusDuration{PERMANENT, ONE_BATTLE, ONE_DAY, ONE_WEEK};
  56. enum BonusSource{ARTIFACT, OBJECT};
  57. ui8 duration; //uses BonusDuration values
  58. ui8 type; //uses BonusType values - says to what is this bonus
  59. si32 subtype; //-1 if not applicable
  60. ui8 source;//uses BonusSource values - what gave that bonus
  61. si32 val;//for morale/luck [-3,+3], others any
  62. ui32 id; //id of object/artifact
  63. std::string description;
  64. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1)
  65. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID), description(Desc)
  66. {}
  67. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1)
  68. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID)
  69. {}
  70. HeroBonus()
  71. {
  72. subtype = -1;
  73. }
  74. template <typename Handler> void serialize(Handler &h, const int version)
  75. {
  76. h & duration & type & subtype & source & val & id & description;
  77. }
  78. static bool OneDay(const HeroBonus &hb)
  79. {
  80. return hb.duration==HeroBonus::ONE_DAY;
  81. }
  82. static bool OneWeek(const HeroBonus &hb)
  83. {
  84. return hb.duration==HeroBonus::ONE_WEEK;
  85. }
  86. static bool OneBattle(const HeroBonus &hb)
  87. {
  88. return hb.duration==HeroBonus::ONE_BATTLE;
  89. }
  90. static bool IsFrom(const HeroBonus &hb, ui8 source, ui32 id) //if id==0xffffff then id doesn't matter
  91. {
  92. return hb.source==source && (id==0xffffff || hb.id==id);
  93. }
  94. };