2018-12-09 15:20:46 +02:00
|
|
|
/*
|
|
|
|
* AdventureSpellCast.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "AdventureSpellCast.h"
|
|
|
|
#include "../VCAI.h"
|
|
|
|
#include "../FuzzyHelper.h"
|
|
|
|
#include "../AIhelper.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../../../lib/mapObjects/CGTownInstance.h"
|
2019-04-07 06:31:47 +02:00
|
|
|
#include "../../../lib/CPathfinder.h"
|
2018-12-09 15:20:46 +02:00
|
|
|
|
|
|
|
extern boost::thread_specific_ptr<CCallback> cb;
|
|
|
|
extern boost::thread_specific_ptr<VCAI> ai;
|
|
|
|
extern FuzzyHelper * fh;
|
|
|
|
|
|
|
|
using namespace Goals;
|
|
|
|
|
|
|
|
bool AdventureSpellCast::operator==(const AdventureSpellCast & other) const
|
|
|
|
{
|
|
|
|
return hero.h == other.hero.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
TSubgoal AdventureSpellCast::whatToDoToAchieve()
|
|
|
|
{
|
|
|
|
if(!hero.validAndSet())
|
|
|
|
throw cannotFulfillGoalException("Invalid hero!");
|
|
|
|
|
2019-01-07 23:33:31 +02:00
|
|
|
auto spell = getSpell();
|
2018-12-09 15:20:46 +02:00
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
logAi->trace("Decomposing adventure spell cast of %s for hero %s", spell->getNameTranslated(), hero->getNameTranslated());
|
2018-12-09 15:20:46 +02:00
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(!spell->isAdventure())
|
2023-01-18 23:56:01 +02:00
|
|
|
throw cannotFulfillGoalException(spell->getNameTranslated() + " is not an adventure spell.");
|
2018-12-09 15:20:46 +02:00
|
|
|
|
2018-12-20 23:42:31 +02:00
|
|
|
if(!hero->canCastThisSpell(spell))
|
2023-01-18 23:56:01 +02:00
|
|
|
throw cannotFulfillGoalException("Hero can not cast " + spell->getNameTranslated());
|
2018-12-09 15:20:46 +02:00
|
|
|
|
2018-12-20 23:42:31 +02:00
|
|
|
if(hero->mana < hero->getSpellCost(spell))
|
2023-01-18 23:56:01 +02:00
|
|
|
throw cannotFulfillGoalException("Hero has not enough mana to cast " + spell->getNameTranslated());
|
2018-12-09 15:20:46 +02:00
|
|
|
|
2019-02-24 17:45:53 +02:00
|
|
|
if(spellID == SpellID::TOWN_PORTAL && town && town->visitingHero)
|
2023-01-02 13:27:03 +02:00
|
|
|
throw cannotFulfillGoalException("The town is already occupied by " + town->visitingHero->getNameTranslated());
|
2019-02-24 17:45:53 +02:00
|
|
|
|
2018-12-09 15:20:46 +02:00
|
|
|
return iAmElementar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureSpellCast::accept(VCAI * ai)
|
|
|
|
{
|
2019-01-07 23:33:31 +02:00
|
|
|
if(town && spellID == SpellID::TOWN_PORTAL)
|
|
|
|
{
|
|
|
|
ai->selectedObject = town->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto wait = cb->waitTillRealize;
|
|
|
|
|
|
|
|
cb->waitTillRealize = true;
|
2018-12-09 15:20:46 +02:00
|
|
|
cb->castSpell(hero.h, spellID, tile);
|
2019-01-07 23:33:31 +02:00
|
|
|
|
|
|
|
if(town && spellID == SpellID::TOWN_PORTAL)
|
|
|
|
{
|
|
|
|
// visit town
|
|
|
|
ai->moveHeroToTile(town->visitablePos(), hero);
|
|
|
|
}
|
|
|
|
|
|
|
|
cb->waitTillRealize = wait;
|
|
|
|
|
|
|
|
throw goalFulfilledException(sptr(*this));
|
2018-12-09 15:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AdventureSpellCast::name() const
|
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return "AdventureSpellCast " + getSpell()->getNameTranslated();
|
2018-12-09 15:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string AdventureSpellCast::completeMessage() const
|
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return "Spell cast successfully " + getSpell()->getNameTranslated();
|
2018-12-09 15:20:46 +02:00
|
|
|
}
|