ISpellMechanics.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. : cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
  30. casterHero(nullptr),
  31. mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(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. prepare(spell);
  37. }
  38. void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
  39. {
  40. destinations.push_back(Destination(destination));
  41. }
  42. void BattleSpellCastParameters::aimToStack(const CStack * destination)
  43. {
  44. destinations.push_back(Destination(destination));
  45. }
  46. BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
  47. {
  48. return destinations.at(0).hexValue;
  49. }
  50. void BattleSpellCastParameters::prepare(const CSpell * spell)
  51. {
  52. spellLvl = caster->getSpellSchoolLevel(spell);
  53. effectLevel = caster->getEffectLevel(spell);
  54. effectPower = caster->getEffectPower(spell);
  55. effectValue = caster->getEffectValue(spell);
  56. enchantPower = caster->getEnchantPower(spell);
  57. vstd::amax(spellLvl, 0);
  58. vstd::amax(effectLevel, 0);
  59. vstd::amax(enchantPower, 0);
  60. vstd::amax(enchantPower, 0);
  61. vstd::amax(effectValue, 0);
  62. }
  63. ///ISpellMechanics
  64. ISpellMechanics::ISpellMechanics(CSpell * s):
  65. owner(s)
  66. {
  67. }
  68. ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
  69. {
  70. switch (s->id)
  71. {
  72. case SpellID::ANTI_MAGIC:
  73. return new AntimagicMechanics(s);
  74. case SpellID::ACID_BREATH_DAMAGE:
  75. return new AcidBreathDamageMechanics(s);
  76. case SpellID::CHAIN_LIGHTNING:
  77. return new ChainLightningMechanics(s);
  78. case SpellID::CLONE:
  79. return new CloneMechanics(s);
  80. case SpellID::CURE:
  81. return new CureMechanics(s);
  82. case SpellID::DEATH_STARE:
  83. return new DeathStareMechanics(s);
  84. case SpellID::DISPEL:
  85. return new DispellMechanics(s);
  86. case SpellID::DISPEL_HELPFUL_SPELLS:
  87. return new DispellHelpfulMechanics(s);
  88. case SpellID::EARTHQUAKE:
  89. return new EarthquakeMechanics(s);
  90. case SpellID::FIRE_WALL:
  91. case SpellID::FORCE_FIELD:
  92. return new WallMechanics(s);
  93. case SpellID::HYPNOTIZE:
  94. return new HypnotizeMechanics(s);
  95. case SpellID::LAND_MINE:
  96. case SpellID::QUICKSAND:
  97. return new ObstacleMechanics(s);
  98. case SpellID::REMOVE_OBSTACLE:
  99. return new RemoveObstacleMechanics(s);
  100. case SpellID::SACRIFICE:
  101. return new SacrificeMechanics(s);
  102. case SpellID::SUMMON_FIRE_ELEMENTAL:
  103. return new SummonMechanics(s, CreatureID::FIRE_ELEMENTAL);
  104. case SpellID::SUMMON_EARTH_ELEMENTAL:
  105. return new SummonMechanics(s, CreatureID::EARTH_ELEMENTAL);
  106. case SpellID::SUMMON_WATER_ELEMENTAL:
  107. return new SummonMechanics(s, CreatureID::WATER_ELEMENTAL);
  108. case SpellID::SUMMON_AIR_ELEMENTAL:
  109. return new SummonMechanics(s, CreatureID::AIR_ELEMENTAL);
  110. case SpellID::TELEPORT:
  111. return new TeleportMechanics(s);
  112. case SpellID::SUMMON_BOAT:
  113. return new SummonBoatMechanics(s);
  114. case SpellID::SCUTTLE_BOAT:
  115. return new ScuttleBoatMechanics(s);
  116. case SpellID::DIMENSION_DOOR:
  117. return new DimensionDoorMechanics(s);
  118. case SpellID::FLY:
  119. case SpellID::WATER_WALK:
  120. case SpellID::VISIONS:
  121. case SpellID::DISGUISE:
  122. return new DefaultSpellMechanics(s); //implemented using bonus system
  123. case SpellID::TOWN_PORTAL:
  124. return new TownPortalMechanics(s);
  125. case SpellID::VIEW_EARTH:
  126. return new ViewEarthMechanics(s);
  127. case SpellID::VIEW_AIR:
  128. return new ViewAirMechanics(s);
  129. default:
  130. if(s->isRisingSpell())
  131. return new SpecialRisingSpellMechanics(s);
  132. else
  133. return new DefaultSpellMechanics(s);
  134. }
  135. }