ISpellMechanics.cpp 17 KB

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