HeroBonus.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. MAGIC_SCHOOL_SKILL, //eg. for magic plains terrain, subtype: school of magic (0 - all, 1 - fire, 2 - air, 4 - water, 8 - earth), value - level
  44. };
  45. enum BonusDuration{PERMANENT, ONE_BATTLE, ONE_DAY, ONE_WEEK};
  46. enum BonusSource{ARTIFACT, OBJECT};
  47. ui8 duration; //uses BonusDuration values
  48. ui8 type; //uses BonusType values - says to what is this bonus
  49. si32 subtype; //-1 if not applicable
  50. ui8 source;//uses BonusSource values - what gave that bonus
  51. si32 val;//for morale/luck [-3,+3], others any
  52. ui32 id; //id of object/artifact
  53. std::string description;
  54. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1)
  55. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID), description(Desc)
  56. {}
  57. HeroBonus(ui8 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1)
  58. :duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), id(ID)
  59. {}
  60. HeroBonus()
  61. {
  62. subtype = -1;
  63. }
  64. template <typename Handler> void serialize(Handler &h, const int version)
  65. {
  66. h & duration & type & subtype & source & val & id & description;
  67. }
  68. static bool OneDay(const HeroBonus &hb)
  69. {
  70. return hb.duration==HeroBonus::ONE_DAY;
  71. }
  72. static bool OneWeek(const HeroBonus &hb)
  73. {
  74. return hb.duration==HeroBonus::ONE_WEEK;
  75. }
  76. static bool OneBattle(const HeroBonus &hb)
  77. {
  78. return hb.duration==HeroBonus::ONE_BATTLE;
  79. }
  80. static bool IsFrom(const HeroBonus &hb, ui8 source, ui32 id) //if id==0xffffff then id doesn't matter
  81. {
  82. return hb.source==source && (id==0xffffff || hb.id==id);
  83. }
  84. };