ISpellMechanics.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * ISpellMechanics.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ISpellMechanics.h"
  12. #include "../BattleState.h"
  13. #include "../NetPacks.h"
  14. #include "CDefaultSpellMechanics.h"
  15. #include "AdventureSpellMechanics.h"
  16. #include "BattleSpellMechanics.h"
  17. #include "CreatureSpellMechanics.h"
  18. BattleSpellCastParameters::Destination::Destination(const CStack * destination):
  19. stackValue(destination),
  20. hexValue(destination->position)
  21. {
  22. }
  23. BattleSpellCastParameters::Destination::Destination(const BattleHex & destination):
  24. stackValue(nullptr),
  25. hexValue(destination)
  26. {
  27. }
  28. BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_)
  29. : spell(spell_), cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
  30. casterHero(nullptr),
  31. mode(ECastingMode::HERO_CASTING), casterStack(nullptr),
  32. spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
  33. {
  34. casterStack = dynamic_cast<const CStack *>(caster);
  35. casterHero = dynamic_cast<const CGHeroInstance *>(caster);
  36. spellLvl = caster->getSpellSchoolLevel(spell);
  37. effectLevel = caster->getEffectLevel(spell);
  38. effectPower = caster->getEffectPower(spell);
  39. effectValue = caster->getEffectValue(spell);
  40. enchantPower = caster->getEnchantPower(spell);
  41. vstd::amax(spellLvl, 0);
  42. vstd::amax(effectLevel, 0);
  43. vstd::amax(enchantPower, 0);
  44. vstd::amax(enchantPower, 0);
  45. vstd::amax(effectValue, 0);
  46. }
  47. void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
  48. {
  49. destinations.push_back(Destination(destination));
  50. }
  51. void BattleSpellCastParameters::aimToStack(const CStack * destination)
  52. {
  53. if(nullptr == destination)
  54. logGlobal->error("BattleSpellCastParameters::aimToStack invalid stack.");
  55. else
  56. destinations.push_back(Destination(destination));
  57. }
  58. void BattleSpellCastParameters::cast(const SpellCastEnvironment * env)
  59. {
  60. spell->battleCast(env, *this);
  61. }
  62. BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
  63. {
  64. return destinations.at(0).hexValue;
  65. }
  66. ///ISpellMechanics
  67. ISpellMechanics::ISpellMechanics(CSpell * s):
  68. owner(s)
  69. {
  70. }
  71. std::unique_ptr<ISpellMechanics> ISpellMechanics::createMechanics(CSpell * s)
  72. {
  73. switch (s->id)
  74. {
  75. case SpellID::ANTI_MAGIC:
  76. return make_unique<AntimagicMechanics>(s);
  77. case SpellID::ACID_BREATH_DAMAGE:
  78. return make_unique<AcidBreathDamageMechanics>(s);
  79. case SpellID::CHAIN_LIGHTNING:
  80. return make_unique<ChainLightningMechanics>(s);
  81. case SpellID::CLONE:
  82. return make_unique<CloneMechanics>(s);
  83. case SpellID::CURE:
  84. return make_unique<CureMechanics>(s);
  85. case SpellID::DEATH_STARE:
  86. return make_unique<DeathStareMechanics>(s);
  87. case SpellID::DISPEL:
  88. return make_unique<DispellMechanics>(s);
  89. case SpellID::DISPEL_HELPFUL_SPELLS:
  90. return make_unique<DispellHelpfulMechanics>(s);
  91. case SpellID::EARTHQUAKE:
  92. return make_unique<EarthquakeMechanics>(s);
  93. case SpellID::FIRE_WALL:
  94. return make_unique<FireWallMechanics>(s);
  95. case SpellID::FORCE_FIELD:
  96. return make_unique<ForceFieldMechanics>(s);
  97. case SpellID::HYPNOTIZE:
  98. return make_unique<HypnotizeMechanics>(s);
  99. case SpellID::LAND_MINE:
  100. return make_unique<LandMineMechanics>(s);
  101. case SpellID::QUICKSAND:
  102. return make_unique<QuicksandMechanics>(s);
  103. case SpellID::REMOVE_OBSTACLE:
  104. return make_unique<RemoveObstacleMechanics>(s);
  105. case SpellID::SACRIFICE:
  106. return make_unique<SacrificeMechanics>(s);
  107. case SpellID::SUMMON_FIRE_ELEMENTAL:
  108. return make_unique<SummonMechanics>(s, CreatureID::FIRE_ELEMENTAL);
  109. case SpellID::SUMMON_EARTH_ELEMENTAL:
  110. return make_unique<SummonMechanics>(s, CreatureID::EARTH_ELEMENTAL);
  111. case SpellID::SUMMON_WATER_ELEMENTAL:
  112. return make_unique<SummonMechanics>(s, CreatureID::WATER_ELEMENTAL);
  113. case SpellID::SUMMON_AIR_ELEMENTAL:
  114. return make_unique<SummonMechanics>(s, CreatureID::AIR_ELEMENTAL);
  115. case SpellID::TELEPORT:
  116. return make_unique<TeleportMechanics>(s);
  117. default:
  118. if(s->isRisingSpell())
  119. return make_unique<SpecialRisingSpellMechanics>(s);
  120. else
  121. return make_unique<DefaultSpellMechanics>(s);
  122. }
  123. }
  124. //IAdventureSpellMechanics
  125. IAdventureSpellMechanics::IAdventureSpellMechanics(CSpell * s):
  126. owner(s)
  127. {
  128. }
  129. std::unique_ptr<IAdventureSpellMechanics> IAdventureSpellMechanics::createMechanics(CSpell * s)
  130. {
  131. switch (s->id)
  132. {
  133. case SpellID::SUMMON_BOAT:
  134. return make_unique<SummonBoatMechanics>(s);
  135. case SpellID::SCUTTLE_BOAT:
  136. return make_unique<ScuttleBoatMechanics>(s);
  137. case SpellID::DIMENSION_DOOR:
  138. return make_unique<DimensionDoorMechanics>(s);
  139. case SpellID::FLY:
  140. case SpellID::WATER_WALK:
  141. case SpellID::VISIONS:
  142. case SpellID::DISGUISE:
  143. return make_unique<AdventureSpellMechanics>(s); //implemented using bonus system
  144. case SpellID::TOWN_PORTAL:
  145. return make_unique<TownPortalMechanics>(s);
  146. case SpellID::VIEW_EARTH:
  147. return make_unique<ViewEarthMechanics>(s);
  148. case SpellID::VIEW_AIR:
  149. return make_unique<ViewAirMechanics>(s);
  150. default:
  151. return std::unique_ptr<IAdventureSpellMechanics>();
  152. }
  153. }