CSpellHandler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. SpellID 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. bool combatSpell; //is this spell combat (true) or adventure (false)
  38. bool creatureAbility; //if true, only creatures can use this spell
  39. si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
  40. std::vector<std::string> range; //description of spell's range in SRSL by magic school level
  41. std::vector<SpellID> counteredSpells; //spells that are removed when effect of this spell is placed on creature (for bless-curse, haste-slow, and similar pairs)
  42. CSpell();
  43. ~CSpell();
  44. std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool *outDroppedHexes = nullptr ) 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. inline bool isCombatSpell() const;
  48. inline bool isAdventureSpell() const;
  49. inline bool isCreatureAbility() const;
  50. inline bool isPositive() const;
  51. inline bool isNegative() const;
  52. inline bool isRisingSpell() const;
  53. inline bool isDamageSpell() const;
  54. inline bool isOffensiveSpell() const;
  55. inline bool hasEffects() const;
  56. void getEffects(std::vector<Bonus> &lst, const int level) const;
  57. bool isImmuneBy(const IBonusBearer *obj) const;
  58. /**
  59. * Returns resource name of icon for SPELL_IMMUNITY bonus
  60. */
  61. inline const std::string& getIconImmune() const;
  62. template <typename Handler> void serialize(Handler &h, const int version)
  63. {
  64. h & identifier & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
  65. & powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range & counteredSpells & mainEffectAnim;
  66. h & isRising & isDamage & isOffensive;
  67. h & targetType;
  68. h & effects & immunities & limiters;
  69. h & iconImmune;
  70. }
  71. friend class CSpellHandler;
  72. private:
  73. bool isRising;
  74. bool isDamage;
  75. bool isOffensive;
  76. std::string attributes; //reference only attributes
  77. void setAttributes(const std::string& newValue);
  78. ETargetType targetType;
  79. std::vector<std::vector<Bonus *> > effects; // [level 0-3][list of effects]
  80. std::vector<Bonus::BonusType> immunities; //any of these grants immunity
  81. std::vector<Bonus::BonusType> limiters; //all of them are required to be affected
  82. ///graphics related stuff
  83. std::string iconImmune;
  84. };
  85. ///CSpell inlines
  86. bool CSpell::isCombatSpell() const
  87. {
  88. return combatSpell;
  89. }
  90. bool CSpell::isAdventureSpell() const
  91. {
  92. return !combatSpell;
  93. }
  94. bool CSpell::isCreatureAbility() const
  95. {
  96. return creatureAbility;
  97. }
  98. bool CSpell::isPositive() const
  99. {
  100. return positiveness == POSITIVE;
  101. }
  102. bool CSpell::isNegative() const
  103. {
  104. return positiveness == NEGATIVE;
  105. }
  106. bool CSpell::isRisingSpell() const
  107. {
  108. return isRising;
  109. }
  110. bool CSpell::isDamageSpell() const
  111. {
  112. return isDamage;
  113. }
  114. bool CSpell::isOffensiveSpell() const
  115. {
  116. return isOffensive;
  117. }
  118. bool CSpell::hasEffects() const
  119. {
  120. return effects.size();
  121. }
  122. const std::string& CSpell::getIconImmune() const
  123. {
  124. return iconImmune;
  125. }
  126. bool DLL_LINKAGE isInScreenRange(const int3 &center, const int3 &pos); //for spells like Dimension Door
  127. class DLL_LINKAGE CSpellHandler
  128. {
  129. CSpell * loadSpell(CLegacyConfigParser & parser, const SpellID id);
  130. public:
  131. CSpellHandler();
  132. ~CSpellHandler();
  133. std::vector< ConstTransitivePtr<CSpell> > spells;
  134. /**
  135. * Gets a list of default allowed spells. OH3 spells are all allowed by default.
  136. *
  137. * @return a list of allowed spells, the index is the spell id and the value either 0 for not allowed or 1 for allowed
  138. */
  139. std::vector<bool> getDefaultAllowed() const;
  140. template <typename Handler> void serialize(Handler &h, const int version)
  141. {
  142. h & spells ;
  143. }
  144. };