1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Remove hardcoded checks for town portal from AI code

This commit is contained in:
Ivan Savenko
2025-07-11 18:03:18 +03:00
parent f51c7c5c28
commit b1aff17e82
10 changed files with 82 additions and 54 deletions

View File

@@ -10,6 +10,8 @@
#include "StdInc.h"
#include "AdventureSpellCast.h"
#include "../AIGateway.h"
#include "../../../lib/spells/ISpellMechanics.h"
#include "../../../lib/spells/adventure/TownPortalEffect.h"
namespace NKAI
{
@@ -39,8 +41,9 @@ void AdventureSpellCast::accept(AIGateway * ai)
if(hero->mana < hero->getSpellCost(spell))
throw cannotFulfillGoalException("Hero has not enough mana to cast " + spell->getNameTranslated());
auto townPortalEffect = spell->getAdventureMechanics().getEffectAs<TownPortalEffect>(hero);
if(town && spellID == SpellID::TOWN_PORTAL)
if(town && townPortalEffect)
{
ai->selectedObject = town->id;
@@ -61,7 +64,7 @@ void AdventureSpellCast::accept(AIGateway * ai)
cb->waitTillRealize = true;
cb->castSpell(hero, spellID, tile);
if(town && spellID == SpellID::TOWN_PORTAL)
if(town && townPortalEffect)
{
// visit town
ai->moveHeroToTile(town->visitablePos(), hero);