ISpellMechanics.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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 "../CRandomGenerator.h"
  13. #include "../VCMI_Lib.h"
  14. #include "../HeroBonus.h"
  15. #include "../battle/CBattleInfoCallback.h"
  16. #include "../battle/IBattleState.h"
  17. #include "../battle/Unit.h"
  18. #include "../mapObjects/CGHeroInstance.h"
  19. #include "../serializer/JsonDeserializer.h"
  20. #include "../serializer/JsonSerializer.h"
  21. #include "TargetCondition.h"
  22. #include "Problem.h"
  23. #include "AdventureSpellMechanics.h"
  24. #include "BattleSpellMechanics.h"
  25. #include "effects/Effects.h"
  26. #include "effects/Registry.h"
  27. #include "effects/Damage.h"
  28. #include "effects/Timed.h"
  29. #include "CSpellHandler.h"
  30. #include "../NetPacks.h"
  31. #include "../CHeroHandler.h"//todo: remove
  32. #include "../IGameCallback.h"//todo: remove
  33. #include "../BattleFieldHandler.h"
  34. VCMI_LIB_NAMESPACE_BEGIN
  35. namespace spells
  36. {
  37. static std::shared_ptr<TargetCondition> makeCondition(const CSpell * s)
  38. {
  39. std::shared_ptr<TargetCondition> res = std::make_shared<TargetCondition>();
  40. JsonDeserializer deser(nullptr, s->targetCondition);
  41. res->serializeJson(deser, TargetConditionItemFactory::getDefault());
  42. return res;
  43. }
  44. class CustomMechanicsFactory : public ISpellMechanicsFactory
  45. {
  46. public:
  47. std::unique_ptr<Mechanics> create(const IBattleCast * event) const override
  48. {
  49. BattleSpellMechanics * ret = new BattleSpellMechanics(event, effects, targetCondition);
  50. return std::unique_ptr<Mechanics>(ret);
  51. }
  52. protected:
  53. std::shared_ptr<effects::Effects> effects;
  54. CustomMechanicsFactory(const CSpell * s)
  55. : ISpellMechanicsFactory(s), effects(new effects::Effects)
  56. {
  57. targetCondition = makeCondition(s);
  58. }
  59. void loadEffects(const JsonNode & config, const int level)
  60. {
  61. JsonDeserializer deser(nullptr, config);
  62. effects->serializeJson(VLC->spellEffects(), deser, level);
  63. }
  64. private:
  65. std::shared_ptr<IReceptiveCheck> targetCondition;
  66. };
  67. class ConfigurableMechanicsFactory : public CustomMechanicsFactory
  68. {
  69. public:
  70. ConfigurableMechanicsFactory(const CSpell * s)
  71. : CustomMechanicsFactory(s)
  72. {
  73. for(int level = 0; level < GameConstants::SPELL_SCHOOL_LEVELS; level++)
  74. loadEffects(s->getLevelInfo(level).battleEffects, level);
  75. }
  76. };
  77. //to be used for spells configured with old format
  78. class FallbackMechanicsFactory : public CustomMechanicsFactory
  79. {
  80. public:
  81. FallbackMechanicsFactory(const CSpell * s)
  82. : CustomMechanicsFactory(s)
  83. {
  84. for(int level = 0; level < GameConstants::SPELL_SCHOOL_LEVELS; level++)
  85. {
  86. const CSpell::LevelInfo & levelInfo = s->getLevelInfo(level);
  87. assert(levelInfo.battleEffects.isNull());
  88. if(s->isOffensive())
  89. {
  90. //default constructed object should be enough
  91. effects->add("directDamage", std::make_shared<effects::Damage>(), level);
  92. }
  93. std::shared_ptr<effects::Effect> effect;
  94. if(!levelInfo.effects.empty())
  95. {
  96. auto timed = new effects::Timed();
  97. timed->cumulative = false;
  98. timed->bonus = levelInfo.effects;
  99. effect.reset(timed);
  100. }
  101. if(!levelInfo.cumulativeEffects.empty())
  102. {
  103. auto timed = new effects::Timed();
  104. timed->cumulative = true;
  105. timed->bonus = levelInfo.cumulativeEffects;
  106. effect.reset(timed);
  107. }
  108. if(effect)
  109. effects->add("timed", effect, level);
  110. }
  111. }
  112. };
  113. BattleCast::BattleCast(const CBattleInfoCallback * cb_, const Caster * caster_, const Mode mode_, const CSpell * spell_)
  114. : spell(spell_),
  115. cb(cb_),
  116. caster(caster_),
  117. mode(mode_),
  118. magicSkillLevel(),
  119. effectPower(),
  120. effectDuration(),
  121. effectValue(),
  122. smart(boost::logic::indeterminate),
  123. massive(boost::logic::indeterminate)
  124. {
  125. gameCb = IObjectInterface::cb; //FIXME: pass player callback (problem is that BattleAI do not have one)
  126. }
  127. BattleCast::BattleCast(const BattleCast & orig, const Caster * caster_)
  128. : spell(orig.spell),
  129. cb(orig.cb),
  130. gameCb(orig.gameCb),
  131. caster(caster_),
  132. mode(Mode::MAGIC_MIRROR),
  133. magicSkillLevel(orig.magicSkillLevel),
  134. effectPower(orig.effectPower),
  135. effectDuration(orig.effectDuration),
  136. effectValue(orig.effectValue),
  137. smart(true),
  138. massive(false)
  139. {
  140. }
  141. BattleCast::~BattleCast() = default;
  142. const CSpell * BattleCast::getSpell() const
  143. {
  144. return spell;
  145. }
  146. Mode BattleCast::getMode() const
  147. {
  148. return mode;
  149. }
  150. const Caster * BattleCast::getCaster() const
  151. {
  152. return caster;
  153. }
  154. const CBattleInfoCallback * BattleCast::getBattle() const
  155. {
  156. return cb;
  157. }
  158. const IGameInfoCallback * BattleCast::getGame() const
  159. {
  160. return gameCb;
  161. }
  162. BattleCast::OptionalValue BattleCast::getSpellLevel() const
  163. {
  164. return magicSkillLevel;
  165. }
  166. BattleCast::OptionalValue BattleCast::getEffectPower() const
  167. {
  168. return effectPower;
  169. }
  170. BattleCast::OptionalValue BattleCast::getEffectDuration() const
  171. {
  172. return effectDuration;
  173. }
  174. BattleCast::OptionalValue64 BattleCast::getEffectValue() const
  175. {
  176. return effectValue;
  177. }
  178. boost::logic::tribool BattleCast::isSmart() const
  179. {
  180. return smart;
  181. }
  182. boost::logic::tribool BattleCast::isMassive() const
  183. {
  184. return massive;
  185. }
  186. void BattleCast::setSpellLevel(BattleCast::Value value)
  187. {
  188. magicSkillLevel = boost::make_optional(value);
  189. }
  190. void BattleCast::setEffectPower(BattleCast::Value value)
  191. {
  192. effectPower = boost::make_optional(value);
  193. }
  194. void BattleCast::setEffectDuration(BattleCast::Value value)
  195. {
  196. effectDuration = boost::make_optional(value);
  197. }
  198. void BattleCast::setEffectValue(BattleCast::Value64 value)
  199. {
  200. effectValue = boost::make_optional(value);
  201. }
  202. void BattleCast::applyEffects(ServerCallback * server, Target target, bool indirect, bool ignoreImmunity) const
  203. {
  204. auto m = spell->battleMechanics(this);
  205. m->applyEffects(server, target, indirect, ignoreImmunity);
  206. }
  207. void BattleCast::cast(ServerCallback * server, Target target)
  208. {
  209. if(target.empty())
  210. target.emplace_back();
  211. auto m = spell->battleMechanics(this);
  212. const battle::Unit * mainTarget = nullptr;
  213. if(target.front().unitValue)
  214. {
  215. mainTarget = target.front().unitValue;
  216. }
  217. else if(target.front().hexValue.isValid())
  218. {
  219. mainTarget = cb->battleGetUnitByPos(target.front().hexValue, true);
  220. }
  221. bool tryMagicMirror = (mainTarget != nullptr) && (mode == Mode::HERO || mode == Mode::CREATURE_ACTIVE);//TODO: recheck
  222. tryMagicMirror = tryMagicMirror && (mainTarget->unitOwner() != caster->getCasterOwner()) && !spell->isPositive();//TODO: recheck
  223. m->cast(server, target);
  224. //Magic Mirror effect
  225. if(tryMagicMirror)
  226. {
  227. const std::string magicMirrorCacheStr = "type_MAGIC_MIRROR";
  228. static const auto magicMirrorSelector = Selector::type()(Bonus::MAGIC_MIRROR);
  229. auto rangeGen = server->getRNG()->getInt64Range(0, 99);
  230. const int mirrorChance = mainTarget->valOfBonuses(magicMirrorSelector, magicMirrorCacheStr);
  231. if(rangeGen() < mirrorChance)
  232. {
  233. auto mirrorTargets = cb->battleGetUnitsIf([this](const battle::Unit * unit)
  234. {
  235. //Get all caster stacks. Magic mirror can reflect to immune creature (with no effect)
  236. return unit->unitOwner() == caster->getCasterOwner() && unit->isValidTarget(true);
  237. });
  238. if(!mirrorTargets.empty())
  239. {
  240. auto mirrorDestination = (*RandomGeneratorUtil::nextItem(mirrorTargets, *server->getRNG()));
  241. Target mirrorTarget;
  242. mirrorTarget.emplace_back(mirrorDestination);
  243. BattleCast mirror(*this, mainTarget);
  244. mirror.cast(server, mirrorTarget);
  245. }
  246. }
  247. }
  248. }
  249. void BattleCast::castEval(ServerCallback * server, Target target)
  250. {
  251. //TODO: make equivalent to normal cast
  252. if(target.empty())
  253. target.emplace_back();
  254. auto m = spell->battleMechanics(this);
  255. //TODO: reflection
  256. //TODO: random effects evaluation
  257. m->castEval(server, target);
  258. }
  259. bool BattleCast::castIfPossible(ServerCallback * server, Target target)
  260. {
  261. if(spell->canBeCast(cb, mode, caster))
  262. {
  263. cast(server, target);
  264. return true;
  265. }
  266. return false;
  267. }
  268. std::vector<Target> BattleCast::findPotentialTargets() const
  269. {
  270. //TODO: for more than 2 destinations per target much more efficient algorithm is required
  271. auto m = spell->battleMechanics(this);
  272. auto targetTypes = m->getTargetTypes();
  273. if(targetTypes.empty() || targetTypes.size() > 2)
  274. {
  275. return std::vector<Target>();
  276. }
  277. else
  278. {
  279. std::vector<Target> previous;
  280. std::vector<Target> next;
  281. for(size_t index = 0; index < targetTypes.size(); index++)
  282. {
  283. std::swap(previous, next);
  284. next.clear();
  285. std::vector<Destination> destinations;
  286. if(previous.empty())
  287. {
  288. Target empty;
  289. destinations = m->getPossibleDestinations(index, targetTypes.at(index), empty);
  290. for(auto & destination : destinations)
  291. {
  292. Target target;
  293. target.emplace_back(destination);
  294. next.push_back(target);
  295. }
  296. }
  297. else
  298. {
  299. for(const Target & current : previous)
  300. {
  301. destinations = m->getPossibleDestinations(index, targetTypes.at(index), current);
  302. for(auto & destination : destinations)
  303. {
  304. Target target = current;
  305. target.emplace_back(destination);
  306. next.push_back(target);
  307. }
  308. }
  309. }
  310. if(next.empty())
  311. break;
  312. }
  313. return next;
  314. }
  315. }
  316. ///ISpellMechanicsFactory
  317. ISpellMechanicsFactory::ISpellMechanicsFactory(const CSpell * s)
  318. : spell(s)
  319. {
  320. }
  321. ISpellMechanicsFactory::~ISpellMechanicsFactory()
  322. {
  323. }
  324. std::unique_ptr<ISpellMechanicsFactory> ISpellMechanicsFactory::get(const CSpell * s)
  325. {
  326. if(s->hasBattleEffects())
  327. return make_unique<ConfigurableMechanicsFactory>(s);
  328. else
  329. return make_unique<FallbackMechanicsFactory>(s);
  330. }
  331. ///Mechanics
  332. Mechanics::Mechanics()
  333. : caster(nullptr),
  334. casterSide(0)
  335. {
  336. }
  337. Mechanics::~Mechanics() = default;
  338. BaseMechanics::BaseMechanics(const IBattleCast * event)
  339. : Mechanics(),
  340. owner(event->getSpell()),
  341. mode(event->getMode()),
  342. smart(event->isSmart()),
  343. massive(event->isMassive())
  344. {
  345. cb = event->getBattle();
  346. gameCb = event->getGame();
  347. caster = event->getCaster();
  348. //FIXME: do not crash on invalid side
  349. casterSide = cb->playerToSide(caster->getCasterOwner()).get();
  350. {
  351. auto value = event->getSpellLevel();
  352. if(value)
  353. rangeLevel = value.get();
  354. else
  355. rangeLevel = caster->getSpellSchoolLevel(owner);
  356. vstd::abetween(rangeLevel, 0, 3);
  357. }
  358. {
  359. auto value = event->getSpellLevel();
  360. if(value)
  361. effectLevel = value.get();
  362. else
  363. effectLevel = caster->getEffectLevel(owner);
  364. vstd::abetween(effectLevel, 0, 3);
  365. }
  366. {
  367. auto value = event->getEffectPower();
  368. if(value)
  369. effectPower = value.get();
  370. else
  371. effectPower = caster->getEffectPower(owner);
  372. vstd::amax(effectPower, 0);
  373. }
  374. {
  375. auto value = event->getEffectDuration();
  376. if(value)
  377. effectDuration = value.get();
  378. else
  379. effectDuration = caster->getEnchantPower(owner);
  380. vstd::amax(effectDuration, 0); //???
  381. }
  382. {
  383. auto value = event->getEffectValue();
  384. if(value)
  385. {
  386. effectValue = value.get();
  387. }
  388. else
  389. {
  390. auto casterValue = caster->getEffectValue(owner);
  391. if(casterValue == 0)
  392. effectValue = owner->calculateRawEffectValue(effectLevel, effectPower, 1);
  393. else
  394. effectValue = casterValue;
  395. }
  396. vstd::amax(effectValue, 0);
  397. }
  398. }
  399. BaseMechanics::~BaseMechanics() = default;
  400. bool BaseMechanics::adaptGenericProblem(Problem & target) const
  401. {
  402. MetaString text;
  403. // %s recites the incantations but they seem to have no effect.
  404. text.addTxt(MetaString::GENERAL_TXT, 541);
  405. caster->getCasterName(text);
  406. target.add(std::move(text), spells::Problem::NORMAL);
  407. return false;
  408. }
  409. bool BaseMechanics::adaptProblem(ESpellCastProblem::ESpellCastProblem source, Problem & target) const
  410. {
  411. if(source == ESpellCastProblem::OK)
  412. return true;
  413. switch(source)
  414. {
  415. case ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED:
  416. {
  417. MetaString text;
  418. //TODO: refactor
  419. auto hero = dynamic_cast<const CGHeroInstance *>(caster);
  420. if(!hero)
  421. return adaptGenericProblem(target);
  422. //Recanter's Cloak or similar effect. Try to retrieve bonus
  423. const auto b = hero->getBonusLocalFirst(Selector::type()(Bonus::BLOCK_MAGIC_ABOVE));
  424. //TODO what about other values and non-artifact sources?
  425. if(b && b->val == 2 && b->source == Bonus::ARTIFACT)
  426. {
  427. //The %s prevents %s from casting 3rd level or higher spells.
  428. text.addTxt(MetaString::GENERAL_TXT, 536);
  429. text.addReplacement(MetaString::ART_NAMES, b->sid);
  430. caster->getCasterName(text);
  431. target.add(std::move(text), spells::Problem::NORMAL);
  432. }
  433. else if(b && b->source == Bonus::TERRAIN_OVERLAY && VLC->battlefields()->getByIndex(b->sid)->identifier == "cursed_ground")
  434. {
  435. text.addTxt(MetaString::GENERAL_TXT, 537);
  436. target.add(std::move(text), spells::Problem::NORMAL);
  437. }
  438. else
  439. {
  440. return adaptGenericProblem(target);
  441. }
  442. }
  443. break;
  444. case ESpellCastProblem::WRONG_SPELL_TARGET:
  445. case ESpellCastProblem::STACK_IMMUNE_TO_SPELL:
  446. case ESpellCastProblem::NO_APPROPRIATE_TARGET:
  447. {
  448. MetaString text;
  449. text.addTxt(MetaString::GENERAL_TXT, 185);
  450. target.add(std::move(text), spells::Problem::NORMAL);
  451. }
  452. break;
  453. case ESpellCastProblem::INVALID:
  454. {
  455. MetaString text;
  456. text.addReplacement("Internal error during check of spell cast.");
  457. target.add(std::move(text), spells::Problem::CRITICAL);
  458. }
  459. break;
  460. default:
  461. return adaptGenericProblem(target);
  462. }
  463. return false;
  464. }
  465. int32_t BaseMechanics::getSpellIndex() const
  466. {
  467. return getSpellId().toEnum();
  468. }
  469. SpellID BaseMechanics::getSpellId() const
  470. {
  471. return owner->getId();
  472. }
  473. std::string BaseMechanics::getSpellName() const
  474. {
  475. return owner->getName();
  476. }
  477. int32_t BaseMechanics::getSpellLevel() const
  478. {
  479. return owner->getLevel();
  480. }
  481. bool BaseMechanics::isSmart() const
  482. {
  483. if(boost::logic::indeterminate(smart))
  484. {
  485. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  486. return targetInfo.smart;
  487. }
  488. else
  489. {
  490. return (bool)smart;
  491. }
  492. }
  493. bool BaseMechanics::isMassive() const
  494. {
  495. if(boost::logic::indeterminate(massive))
  496. {
  497. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  498. return targetInfo.massive;
  499. }
  500. else
  501. {
  502. return (bool)massive;
  503. }
  504. }
  505. bool BaseMechanics::requiresClearTiles() const
  506. {
  507. const CSpell::TargetInfo targetInfo(owner, getRangeLevel(), mode);
  508. return targetInfo.clearAffected;
  509. }
  510. bool BaseMechanics::alwaysHitFirstTarget() const
  511. {
  512. return mode == Mode::SPELL_LIKE_ATTACK;
  513. }
  514. bool BaseMechanics::isNegativeSpell() const
  515. {
  516. return owner->isNegative();
  517. }
  518. bool BaseMechanics::isPositiveSpell() const
  519. {
  520. return owner->isPositive();
  521. }
  522. int64_t BaseMechanics::adjustEffectValue(const battle::Unit * target) const
  523. {
  524. return owner->adjustRawDamage(caster, target, getEffectValue());
  525. }
  526. int64_t BaseMechanics::applySpellBonus(int64_t value, const battle::Unit * target) const
  527. {
  528. return caster->getSpellBonus(owner, value, target);
  529. }
  530. int64_t BaseMechanics::applySpecificSpellBonus(int64_t value) const
  531. {
  532. return caster->getSpecificSpellBonus(owner, value);
  533. }
  534. int64_t BaseMechanics::calculateRawEffectValue(int32_t basePowerMultiplier, int32_t levelPowerMultiplier) const
  535. {
  536. return owner->calculateRawEffectValue(getEffectLevel(), basePowerMultiplier, levelPowerMultiplier);
  537. }
  538. std::vector<Bonus::BonusType> BaseMechanics::getElementalImmunity() const
  539. {
  540. std::vector<Bonus::BonusType> ret;
  541. owner->forEachSchool([&](const SchoolInfo & cnf, bool & stop)
  542. {
  543. ret.push_back(cnf.immunityBonus);
  544. });
  545. return ret;
  546. }
  547. bool BaseMechanics::ownerMatches(const battle::Unit * unit) const
  548. {
  549. return ownerMatches(unit, owner->getPositiveness());
  550. }
  551. bool BaseMechanics::ownerMatches(const battle::Unit * unit, const boost::logic::tribool positivness) const
  552. {
  553. return cb->battleMatchOwner(caster->getCasterOwner(), unit, positivness);
  554. }
  555. IBattleCast::Value BaseMechanics::getEffectLevel() const
  556. {
  557. return effectLevel;
  558. }
  559. IBattleCast::Value BaseMechanics::getRangeLevel() const
  560. {
  561. return rangeLevel;
  562. }
  563. IBattleCast::Value BaseMechanics::getEffectPower() const
  564. {
  565. return effectPower;
  566. }
  567. IBattleCast::Value BaseMechanics::getEffectDuration() const
  568. {
  569. return effectDuration;
  570. }
  571. IBattleCast::Value64 BaseMechanics::getEffectValue() const
  572. {
  573. return effectValue;
  574. }
  575. PlayerColor BaseMechanics::getCasterColor() const
  576. {
  577. return caster->getCasterOwner();
  578. }
  579. std::vector<AimType> BaseMechanics::getTargetTypes() const
  580. {
  581. std::vector<AimType> ret;
  582. detail::ProblemImpl ingored;
  583. if(canBeCast(ingored))
  584. {
  585. auto spellTargetType = owner->getTargetType();
  586. if(isMassive())
  587. spellTargetType = AimType::NO_TARGET;
  588. else if(spellTargetType == AimType::OBSTACLE)
  589. spellTargetType = AimType::LOCATION;
  590. ret.push_back(spellTargetType);
  591. }
  592. return ret;
  593. }
  594. const CreatureService * BaseMechanics::creatures() const
  595. {
  596. return VLC->creatures(); //todo: redirect
  597. }
  598. #if SCRIPTING_ENABLED
  599. const scripting::Service * BaseMechanics::scripts() const
  600. {
  601. return VLC->scripts(); //todo: redirect
  602. }
  603. #endif
  604. const Service * BaseMechanics::spells() const
  605. {
  606. return VLC->spells(); //todo: redirect
  607. }
  608. const IGameInfoCallback * BaseMechanics::game() const
  609. {
  610. return gameCb;
  611. }
  612. const CBattleInfoCallback * BaseMechanics::battle() const
  613. {
  614. return cb;
  615. }
  616. } //namespace spells
  617. ///IAdventureSpellMechanics
  618. IAdventureSpellMechanics::IAdventureSpellMechanics(const CSpell * s)
  619. : owner(s)
  620. {
  621. }
  622. std::unique_ptr<IAdventureSpellMechanics> IAdventureSpellMechanics::createMechanics(const CSpell * s)
  623. {
  624. switch (s->id)
  625. {
  626. case SpellID::SUMMON_BOAT:
  627. return make_unique<SummonBoatMechanics>(s);
  628. case SpellID::SCUTTLE_BOAT:
  629. return make_unique<ScuttleBoatMechanics>(s);
  630. case SpellID::DIMENSION_DOOR:
  631. return make_unique<DimensionDoorMechanics>(s);
  632. case SpellID::FLY:
  633. case SpellID::WATER_WALK:
  634. case SpellID::VISIONS:
  635. case SpellID::DISGUISE:
  636. return make_unique<AdventureSpellMechanics>(s); //implemented using bonus system
  637. case SpellID::TOWN_PORTAL:
  638. return make_unique<TownPortalMechanics>(s);
  639. case SpellID::VIEW_EARTH:
  640. return make_unique<ViewEarthMechanics>(s);
  641. case SpellID::VIEW_AIR:
  642. return make_unique<ViewAirMechanics>(s);
  643. default:
  644. return std::unique_ptr<IAdventureSpellMechanics>();
  645. }
  646. }
  647. VCMI_LIB_NAMESPACE_END