CSpellHandler.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include "../lib/ConstTransitivePtr.h"
  3. #include "int3.h"
  4. #include "GameConstants.h"
  5. #include "HeroBonus.h"
  6. /*
  7. * CSpellHandler.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. class CLegacyConfigParser;
  16. struct BattleHex;
  17. class DLL_LINKAGE CSpell
  18. {
  19. public:
  20. enum ETargetType {NO_TARGET, CREATURE, CREATURE_EXPERT_MASSIVE, OBSTACLE};
  21. enum ESpellPositiveness {NEGATIVE = -1, NEUTRAL = 0, POSITIVE = 1};
  22. TSpell id;
  23. std::string identifier;
  24. std::string name;
  25. std::string abbName; //abbreviated name
  26. std::vector<std::string> descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc
  27. si32 level;
  28. bool earth;
  29. bool water;
  30. bool fire;
  31. bool air;
  32. si32 power; //spell's power
  33. std::vector<si32> costs; //per skill level: 0 - none, 1 - basic, etc
  34. std::vector<si32> powers; //[er skill level: 0 - none, 1 - basic, etc
  35. std::map<TFaction, si32> probabilities; //% chance to gain for castles
  36. std::vector<si32> AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc
  37. std::string attributes; //reference only attributes
  38. bool combatSpell; //is this spell combat (true) or adventure (false)
  39. bool creatureAbility; //if true, only creatures can use this spell
  40. si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
  41. std::vector<std::string> range; //description of spell's range in SRSL by magic school level
  42. std::vector<TSpell> counteredSpells; //spells that are removed when effect of this spell is placed on creature (for bless-curse, haste-slow, and similar pairs)
  43. CSpell();
  44. std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = NULL ) const; //convert range to specific hexes; last optional out parameter is set to true, if spell would cover unavailable hexes (that are not included in ret)
  45. si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none)
  46. ETargetType getTargetType() const;
  47. bool isPositive() const;
  48. bool isNegative() const;
  49. bool isRisingSpell() const;
  50. bool isDamageSpell() const;
  51. bool isMindSpell() const;
  52. void getEffects(std::vector<Bonus> & lst) const;
  53. template <typename Handler> void serialize(Handler &h, const int version)
  54. {
  55. h & identifier & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
  56. & powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range & counteredSpells & mainEffectAnim;
  57. h & _isRising & _isDamage & _isMind;
  58. h & _effects;
  59. }
  60. friend class CSpellHandler;
  61. private:
  62. bool _isRising;
  63. bool _isDamage;
  64. bool _isMind;
  65. std::vector<Bonus> _effects;
  66. };
  67. namespace Spells
  68. {
  69. enum
  70. {
  71. SUMMON_BOAT=0, SCUTTLE_BOAT=1, VISIONS=2, VIEW_EARTH=3, DISGUISE=4, VIEW_AIR=5,
  72. FLY=6, WATER_WALK=7, DIMENSION_DOOR=8, TOWN_PORTAL=9,
  73. QUICKSAND=10, LAND_MINE=11, FORCE_FIELD=12, FIRE_WALL=13, EARTHQUAKE=14,
  74. MAGIC_ARROW=15, ICE_BOLT=16, LIGHTNING_BOLT=17, IMPLOSION=18,
  75. CHAIN_LIGHTNING=19, FROST_RING=20, FIREBALL=21, INFERNO=22,
  76. METEOR_SHOWER=23, DEATH_RIPPLE=24, DESTROY_UNDEAD=25, ARMAGEDDON=26,
  77. SHIELD=27, AIR_SHIELD=28, FIRE_SHIELD=29, PROTECTION_FROM_AIR=30,
  78. PROTECTION_FROM_FIRE=31, PROTECTION_FROM_WATER=32,
  79. PROTECTION_FROM_EARTH=33, ANTI_MAGIC=34, DISPEL=35, MAGIC_MIRROR=36,
  80. CURE=37, RESURRECTION=38, ANIMATE_DEAD=39, SACRIFICE=40, BLESS=41,
  81. CURSE=42, BLOODLUST=43, PRECISION=44, WEAKNESS=45, STONE_SKIN=46,
  82. DISRUPTING_RAY=47, PRAYER=48, MIRTH=49, SORROW=50, FORTUNE=51,
  83. MISFORTUNE=52, HASTE=53, SLOW=54, SLAYER=55, FRENZY=56,
  84. TITANS_LIGHTNING_BOLT=57, COUNTERSTRIKE=58, BERSERK=59, HYPNOTIZE=60,
  85. FORGETFULNESS=61, BLIND=62, TELEPORT=63, REMOVE_OBSTACLE=64, CLONE=65,
  86. SUMMON_FIRE_ELEMENTAL=66, SUMMON_EARTH_ELEMENTAL=67, SUMMON_WATER_ELEMENTAL=68, SUMMON_AIR_ELEMENTAL=69,
  87. STONE_GAZE=70, POISON=71, BIND=72, DISEASE=73, PARALYZE=74, AGE=75, DEATH_CLOUD=76, THUNDERBOLT=77,
  88. DISPEL_HELPFUL_SPELLS=78, DEATH_STARE=79, ACID_BREATH_DEFENSE=80, ACID_BREATH_DAMAGE=81
  89. };
  90. }
  91. bool DLL_LINKAGE isInScreenRange(const int3 &center, const int3 &pos); //for spells like Dimension Door
  92. class DLL_LINKAGE CSpellHandler
  93. {
  94. CSpell * loadSpell(CLegacyConfigParser & parser);
  95. public:
  96. CSpellHandler();
  97. std::vector< ConstTransitivePtr<CSpell> > spells;
  98. void loadSpells();
  99. /**
  100. * Gets a list of default allowed spells. OH3 spells are all allowed by default.
  101. *
  102. * @return a list of allowed spells, the index is the spell id and the value either 0 for not allowed or 1 for allowed
  103. */
  104. std::vector<ui8> getDefaultAllowedSpells() const;
  105. template <typename Handler> void serialize(Handler &h, const int version)
  106. {
  107. h & spells ;
  108. }
  109. };