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

Removed hardcoded checks for Summon Boat spell

This commit is contained in:
Ivan Savenko
2025-07-11 17:11:01 +03:00
parent 7a1ede1e38
commit b0c511149d
10 changed files with 68 additions and 26 deletions

View File

@@ -92,7 +92,7 @@ namespace AIPathfinding
void SummonBoatAction::execute(AIGateway * ai, const CGHeroInstance * hero) const
{
Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT).accept(ai);
Goals::AdventureSpellCast(hero, usedSpell).accept(ai);
}
const ChainActor * SummonBoatAction::getActor(const ChainActor * sourceActor) const
@@ -139,10 +139,8 @@ namespace AIPathfinding
int32_t SummonBoatAction::getManaCost(const CGHeroInstance * hero) const
{
SpellID summonBoat = SpellID::SUMMON_BOAT;
// FIXME: this should be hero->getSpellCost, however currently queries to bonus system are too slow
return summonBoat.toSpell()->getCost(0);
return usedSpell.toSpell()->getCost(0);
}
}

View File

@@ -24,7 +24,13 @@ namespace AIPathfinding
class SummonBoatAction : public VirtualBoatAction
{
SpellID usedSpell;
public:
SummonBoatAction(SpellID usedSpell)
: usedSpell(usedSpell)
{
}
void execute(AIGateway * ai, const CGHeroInstance * hero) const override;
virtual void applyOnDestination(

View File

@@ -12,6 +12,8 @@
#include "../../Engine/Nullkiller.h"
#include "../../../../lib/pathfinder/CPathfinder.h"
#include "../../../../lib/pathfinder/TurnInfo.h"
#include "../../../../lib/spells/ISpellMechanics.h"
#include "../../../../lib/spells/adventure/SummonBoatEffect.h"
namespace NKAI
{
@@ -159,13 +161,21 @@ namespace AIPathfinding
for(const CGHeroInstance * hero : nodeStorage->getAllHeroes())
{
auto summonBoatSpell = SpellID(SpellID::SUMMON_BOAT).toSpell();
if(hero->canCastThisSpell(summonBoatSpell)
&& hero->getSpellSchoolLevel(summonBoatSpell) >= MasteryLevel::ADVANCED)
for (const auto & spell : LIBRARY->spellh->objects)
{
// TODO: For lower school level we might need to check the existence of some boat
summonableVirtualBoats[hero] = std::make_shared<SummonBoatAction>();
if (!spell || !spell->isAdventure())
continue;
auto effect = spell->getAdventureMechanics().getEffectAs<SummonBoatEffect>(hero);
if (!effect || !hero->canCastThisSpell(spell.get()))
continue;
if (effect->canCreateNewBoat() && effect->getSuccessChance(hero) == 100)
{
// TODO: For lower school level we might need to check the existence of some boat
summonableVirtualBoats[hero] = std::make_shared<SummonBoatAction>(spell->id);
}
}
}
}

View File

@@ -23,7 +23,7 @@ namespace AIPathfinding
Goals::TSubgoal SummonBoatAction::whatToDo(const HeroPtr & hero) const
{
return Goals::sptr(Goals::AdventureSpellCast(hero, SpellID::SUMMON_BOAT));
return Goals::sptr(Goals::AdventureSpellCast(hero, usedSpell));
}
void SummonBoatAction::applyOnDestination(
@@ -53,8 +53,6 @@ namespace AIPathfinding
uint32_t SummonBoatAction::getManaCost(const CGHeroInstance * hero) const
{
SpellID summonBoat = SpellID::SUMMON_BOAT;
return hero->getSpellCost(summonBoat.toSpell());
return hero->getSpellCost(usedSpell.toSpell());
}
}

View File

@@ -34,9 +34,11 @@ namespace AIPathfinding
class SummonBoatAction : public VirtualBoatAction
{
SpellID usedSpell;
public:
SummonBoatAction()
SummonBoatAction(SpellID usedSpell)
:VirtualBoatAction(AINodeStorage::CAST_CHAIN)
,usedSpell(usedSpell)
{
}

View File

@@ -10,6 +10,9 @@
#include "StdInc.h"
#include "AILayerTransitionRule.h"
#include "../../../../lib/spells/ISpellMechanics.h"
#include "../../../../lib/spells/adventure/SummonBoatEffect.h"
namespace AIPathfinding
{
AILayerTransitionRule::AILayerTransitionRule(CPlayerSpecificInfoCallback * cb, VCAI * ai, std::shared_ptr<AINodeStorage> nodeStorage)
@@ -74,13 +77,22 @@ namespace AIPathfinding
}
auto hero = nodeStorage->getHero();
auto summonBoatSpell = SpellID(SpellID::SUMMON_BOAT).toSpell();
if(hero->canCastThisSpell(summonBoatSpell)
&& hero->getSpellSchoolLevel(summonBoatSpell) >= MasteryLevel::ADVANCED)
for (const auto & spell : LIBRARY->spellh->objects)
{
// TODO: For lower school level we might need to check the existence of some boat
summonableVirtualBoat.reset(new SummonBoatAction());
if (!spell || !spell->isAdventure())
continue;
auto effect = spell->getAdventureMechanics().getEffectAs<SummonBoatEffect>(hero);
if (!effect || !hero->canCastThisSpell(spell.get()))
continue;
if (effect->canCreateNewBoat() && effect->getSuccessChance(hero) == 100)
{
// TODO: For lower school level we might need to check the existence of some boat
summonableVirtualBoat.reset(new SummonBoatAction(spell->id));
}
}
}