CSpellHandler.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #pragma once
  2. #include "IHandlerBase.h"
  3. #include "../lib/ConstTransitivePtr.h"
  4. #include "int3.h"
  5. #include "GameConstants.h"
  6. #include "HeroBonus.h"
  7. /*
  8. * CSpellHandler.h, part of VCMI engine
  9. *
  10. * Authors: listed in file AUTHORS in main folder
  11. *
  12. * License: GNU General Public License v2.0 or later
  13. * Full text of license available in license.txt file, in main folder
  14. *
  15. */
  16. class CLegacyConfigParser;
  17. struct BattleHex;
  18. class DLL_LINKAGE CSpell
  19. {
  20. public:
  21. // struct LevelInfo
  22. // {
  23. //
  24. // };
  25. //
  26. // /** \brief Low level accessor. Don`t use it if absolutely necessary
  27. // *
  28. // * \param level. spell school level
  29. // * \return Spell level info structure
  30. // *
  31. // */
  32. // const LevelInfo& getLevelInfo(const int level);
  33. public:
  34. enum ETargetType {NO_TARGET, CREATURE, CREATURE_EXPERT_MASSIVE, OBSTACLE};
  35. enum ESpellPositiveness {NEGATIVE = -1, NEUTRAL = 0, POSITIVE = 1};
  36. SpellID id;
  37. std::string identifier; //???
  38. std::string name;
  39. std::string abbName; //abbreviated name
  40. std::vector<std::string> descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc
  41. si32 level;
  42. bool earth;
  43. bool water;
  44. bool fire;
  45. bool air;
  46. si32 power; //spell's power
  47. std::map<TFaction, si32> probabilities; //% chance to gain for castles
  48. bool combatSpell; //is this spell combat (true) or adventure (false)
  49. bool creatureAbility; //if true, only creatures can use this spell
  50. si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
  51. std::vector<std::string> range; //description of spell's range in SRSL by magic school level
  52. 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)
  53. CSpell();
  54. ~CSpell();
  55. 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)
  56. si16 mainEffectAnim; //main spell effect animation, in AC format (or -1 when none)
  57. ETargetType getTargetType() const;
  58. bool isCombatSpell() const;
  59. bool isAdventureSpell() const;
  60. bool isCreatureAbility() const;
  61. bool isPositive() const;
  62. bool isNegative() const;
  63. bool isRisingSpell() const;
  64. bool isDamageSpell() const;
  65. bool isOffensiveSpell() const;
  66. bool isSpecialSpell() const;
  67. bool hasEffects() const;
  68. void getEffects(std::vector<Bonus> &lst, const int level) const;
  69. bool isImmuneBy(const IBonusBearer *obj) const;
  70. si32 getCost(const int skillLevel) const;
  71. /**
  72. * Returns spell level power, base power ignored
  73. */
  74. si32 getPower(const int skillLevel) const;
  75. // /**
  76. // * Returns spell power, taking base power into account
  77. // */
  78. // si32 calculatePower(const int skillLevel) const;
  79. si32 getProbability(const TFaction factionId) const;
  80. /**
  81. * Returns resource name of icon for SPELL_IMMUNITY bonus
  82. */
  83. const std::string& getIconImmune() const;
  84. const std::string& getCastSound() const;
  85. template <typename Handler> void serialize(Handler &h, const int version)
  86. {
  87. h & identifier & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
  88. & powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness & range & counteredSpells & mainEffectAnim;
  89. h & isRising & isDamage & isOffensive;
  90. h & targetType;
  91. h & effects & immunities & limiters;
  92. h & iconImmune;
  93. h & absoluteImmunities & defaultProbability;
  94. h & isSpecial;
  95. h & castSound & iconBook & iconEffect & iconScenarioBonus & iconScroll ;
  96. }
  97. friend class CSpellHandler;
  98. friend class Graphics;
  99. private:
  100. void setIsOffensive(const bool val);
  101. void setIsRising(const bool val);
  102. void setAttributes(const std::string& newValue);
  103. private:
  104. si32 defaultProbability;
  105. std::vector<si32> costs; //per skill level: 0 - none, 1 - basic, etc
  106. std::vector<si32> powers; //per skill level: 0 - none, 1 - basic, etc
  107. std::vector<si32> AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc
  108. bool isRising;
  109. bool isDamage;
  110. bool isOffensive;
  111. bool isSpecial;
  112. std::string attributes; //reference only attributes //todo: remove or include in configuration format, currently unused
  113. ETargetType targetType;
  114. std::vector<std::vector<Bonus *> > effects; // [level 0-3][list of effects]
  115. std::vector<Bonus::BonusType> immunities; //any of these grants immunity
  116. std::vector<Bonus::BonusType> absoluteImmunities; //any of these grants immunity, cant be negated
  117. std::vector<Bonus::BonusType> limiters; //all of them are required to be affected
  118. ///graphics related stuff
  119. std::string iconImmune;
  120. std::string iconBook;
  121. std::string iconEffect;
  122. std::string iconScenarioBonus;
  123. std::string iconScroll;
  124. ///sound related stuff
  125. std::string castSound;
  126. };
  127. bool DLL_LINKAGE isInScreenRange(const int3 &center, const int3 &pos); //for spells like Dimension Door
  128. class DLL_LINKAGE CSpellHandler: public CHandlerBase<SpellID, CSpell>
  129. {
  130. //CSpell * loadSpell(CLegacyConfigParser & parser, const SpellID id);
  131. public:
  132. CSpellHandler();
  133. virtual ~CSpellHandler();
  134. ///IHandler base
  135. std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
  136. void afterLoadFinalization() override;
  137. /**
  138. * Gets a list of default allowed spells. OH3 spells are all allowed by default.
  139. *
  140. * @return a list of allowed spells, the index is the spell id and the value either 0 for not allowed or 1 for allowed
  141. */
  142. std::vector<bool> getDefaultAllowed() const override;
  143. const std::string getTypeName() const override;
  144. template <typename Handler> void serialize(Handler &h, const int version)
  145. {
  146. h & objects ;
  147. }
  148. protected:
  149. CSpell * loadFromJson(const JsonNode & json) override;
  150. };