ISpellMechanics.cpp 17 KB

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