2015-02-02 10:40:06 +02:00
|
|
|
/*
|
|
|
|
* AdventureSpellMechanics.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 "AdventureSpellMechanics.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "CSpellHandler.h"
|
2024-04-10 17:19:48 +02:00
|
|
|
#include "Problem.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../CGameInfoCallback.h"
|
|
|
|
#include "../CPlayerState.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
#include "../CRandomGenerator.h"
|
2024-04-01 18:12:38 +02:00
|
|
|
#include "../GameSettings.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
#include "../mapObjects/CGHeroInstance.h"
|
2024-01-09 16:43:36 +02:00
|
|
|
#include "../mapObjects/CGTownInstance.h"
|
|
|
|
#include "../mapObjects/MiscObjects.h"
|
2015-12-02 21:05:10 +02:00
|
|
|
#include "../mapping/CMap.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../networkPacks/PacksForClient.h"
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2016-09-04 07:19:28 +02:00
|
|
|
///AdventureSpellMechanics
|
2017-06-06 06:53:51 +02:00
|
|
|
AdventureSpellMechanics::AdventureSpellMechanics(const CSpell * s):
|
|
|
|
IAdventureSpellMechanics(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool AdventureSpellMechanics::canBeCast(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster) const
|
2016-09-04 07:19:28 +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(!owner->isAdventure())
|
2016-09-04 07:19:28 +02:00
|
|
|
return false;
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const auto * heroCaster = dynamic_cast<const CGHeroInstance *>(caster);
|
|
|
|
|
|
|
|
if (heroCaster)
|
2016-09-04 07:19:28 +02:00
|
|
|
{
|
2023-04-09 23:06:02 +02:00
|
|
|
if(heroCaster->inTownGarrison)
|
|
|
|
return false;
|
2016-09-04 07:19:28 +02:00
|
|
|
|
2023-04-09 23:06:02 +02:00
|
|
|
const auto level = heroCaster->getSpellSchoolLevel(owner);
|
|
|
|
const auto cost = owner->getCost(level);
|
2016-09-04 07:19:28 +02:00
|
|
|
|
2023-04-09 23:06:02 +02:00
|
|
|
if(!heroCaster->canCastThisSpell(owner))
|
|
|
|
return false;
|
2016-09-04 07:19:28 +02:00
|
|
|
|
2023-04-09 23:06:02 +02:00
|
|
|
if(heroCaster->mana < cost)
|
|
|
|
return false;
|
2016-09-04 07:19:28 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
return canBeCastImpl(problem, cb, caster);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureSpellMechanics::canBeCastAt(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
|
|
|
{
|
|
|
|
return canBeCast(problem, cb, caster) && canBeCastAtImpl(problem, cb, caster, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureSpellMechanics::canBeCastImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureSpellMechanics::canBeCastAtImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureSpellMechanics::adventureCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
|
|
|
spells::detail::ProblemImpl problem;
|
|
|
|
|
|
|
|
if (!canBeCastAt(problem, env->getCb(), parameters.caster, parameters.pos))
|
|
|
|
return false;
|
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
ESpellCastResult result = beginCast(env, parameters);
|
2016-09-04 07:19:28 +02:00
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
if(result == ESpellCastResult::OK)
|
|
|
|
performCast(env, parameters);
|
|
|
|
|
|
|
|
return result != ESpellCastResult::ERROR;
|
2016-09-04 07:19:28 +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
|
|
|
ESpellCastResult AdventureSpellMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2016-09-04 07:19:28 +02:00
|
|
|
{
|
|
|
|
if(owner->hasEffects())
|
|
|
|
{
|
2016-11-02 19:11:01 +02:00
|
|
|
//todo: cumulative effects support
|
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
|
|
|
const auto schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
|
2016-09-04 07:19:28 +02:00
|
|
|
|
|
|
|
std::vector<Bonus> bonuses;
|
|
|
|
|
2016-11-02 19:11:01 +02:00
|
|
|
owner->getEffects(bonuses, schoolLevel, false, parameters.caster->getEnchantPower(owner));
|
2016-09-04 07:19:28 +02:00
|
|
|
|
2023-02-11 17:18:05 +02:00
|
|
|
for(const Bonus & b : bonuses)
|
2016-09-04 07:19:28 +02:00
|
|
|
{
|
|
|
|
GiveBonus gb;
|
2023-11-06 18:27:16 +02:00
|
|
|
gb.id = ObjectInstanceID(parameters.caster->getCasterUnitId());
|
2016-09-04 07:19:28 +02:00
|
|
|
gb.bonus = b;
|
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
|
|
|
env->apply(&gb);
|
2016-09-04 07:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ESpellCastResult::OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//There is no generic algorithm of adventure cast
|
|
|
|
env->complain("Unimplemented adventure spell");
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ESpellCastResult AdventureSpellMechanics::beginCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2024-04-10 17:42:31 +02:00
|
|
|
return ESpellCastResult::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureSpellMechanics::endCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
|
|
|
// no-op, only for implementation in derived classes
|
2017-07-03 20:09:27 +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
|
|
|
void AdventureSpellMechanics::performCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2024-04-10 17:42:31 +02:00
|
|
|
const auto level = parameters.caster->getSpellSchoolLevel(owner);
|
|
|
|
const auto cost = owner->getCost(level);
|
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
AdvmapSpellCast asc;
|
2023-04-09 23:06:02 +02:00
|
|
|
asc.casterID = ObjectInstanceID(parameters.caster->getCasterUnitId());
|
2017-07-03 20:09:27 +02:00
|
|
|
asc.spellID = owner->id;
|
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
|
|
|
env->apply(&asc);
|
2017-07-03 20:09:27 +02:00
|
|
|
|
|
|
|
ESpellCastResult result = applyAdventureEffects(env, parameters);
|
|
|
|
|
|
|
|
switch(result)
|
|
|
|
{
|
|
|
|
case ESpellCastResult::OK:
|
2023-04-10 15:08:24 +02:00
|
|
|
parameters.caster->spendMana(env, cost);
|
2024-04-10 17:42:31 +02:00
|
|
|
endCast(env, parameters);
|
2017-07-03 20:09:27 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
///SummonBoatMechanics
|
2017-06-06 06:53:51 +02:00
|
|
|
SummonBoatMechanics::SummonBoatMechanics(const CSpell * s):
|
|
|
|
AdventureSpellMechanics(s)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool SummonBoatMechanics::canBeCastImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!caster->getHeroCaster())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(caster->getHeroCaster()->boat)
|
2017-07-22 22:47:29 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
MetaString message = MetaString::createFromTextID("core.genrltxt.333");
|
|
|
|
caster->getCasterName(message);
|
|
|
|
problem.add(std::move(message));
|
|
|
|
return false;
|
2017-07-22 22:47:29 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
int3 summonPos = caster->getHeroCaster()->bestLocation();
|
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
if(summonPos.x < 0)
|
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
MetaString message = MetaString::createFromTextID("core.genrltxt.334");
|
|
|
|
caster->getCasterName(message);
|
|
|
|
problem.add(std::move(message));
|
|
|
|
return false;
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ESpellCastResult SummonBoatMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
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
|
|
|
const auto schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
//check if spell works at all
|
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(env->getRNG()->getInt64Range(0, 99)() >= owner->getLevelPower(schoolLevel)) //power is % chance of success
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:06:02 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 336); //%s tried to summon a boat, but failed.
|
2023-04-09 23:06:02 +02:00
|
|
|
parameters.caster->getCasterName(iw.text);
|
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
|
|
|
env->apply(&iw);
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::OK;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//try to find unoccupied boat to summon
|
|
|
|
const CGBoat * nearest = nullptr;
|
|
|
|
double dist = 0;
|
2023-04-09 23:31:41 +02:00
|
|
|
for(const CGObjectInstance * obj : env->getMap()->objects)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2023-04-20 19:20:51 +02:00
|
|
|
if(obj && obj->ID == Obj::BOAT)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2023-04-09 23:31:41 +02:00
|
|
|
const auto * b = dynamic_cast<const CGBoat *>(obj);
|
2023-04-18 20:21:26 +02:00
|
|
|
if(b->hero || b->layer != EPathfindingLayer::SAIL)
|
2023-04-09 23:31:41 +02:00
|
|
|
continue; //we're looking for unoccupied boat
|
|
|
|
|
|
|
|
double nDist = b->pos.dist2d(parameters.caster->getHeroCaster()->visitablePos());
|
|
|
|
if(!nearest || nDist < dist) //it's first boat or closer than previous
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2023-04-09 23:31:41 +02:00
|
|
|
nearest = b;
|
|
|
|
dist = nDist;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
int3 summonPos = parameters.caster->getHeroCaster()->bestLocation();
|
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
if(nullptr != nearest) //we found boat to summon
|
|
|
|
{
|
|
|
|
ChangeObjPos cop;
|
|
|
|
cop.objid = nearest->id;
|
2023-06-20 21:06:45 +02:00
|
|
|
cop.nPos = summonPos;
|
2023-09-18 21:09:55 +02:00
|
|
|
cop.initiator = parameters.caster->getCasterOwner();
|
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
|
|
|
env->apply(&cop);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
else if(schoolLevel < 2) //none or basic level -> cannot create boat :(
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:06:02 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 335); //There are no boats to summon.
|
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
|
|
|
env->apply(&iw);
|
2024-04-10 17:19:48 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2023-04-09 23:31:41 +02:00
|
|
|
else //create boat
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
NewObject no;
|
2023-04-20 19:20:51 +02:00
|
|
|
no.ID = Obj::BOAT;
|
2023-08-18 12:38:19 +02:00
|
|
|
no.subID = BoatId::NECROPOLIS;
|
2023-06-20 21:06:45 +02:00
|
|
|
no.targetPos = summonPos;
|
2023-09-18 21:09:55 +02:00
|
|
|
no.initiator = parameters.caster->getCasterOwner();
|
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
|
|
|
env->apply(&no);
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::OK;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///ScuttleBoatMechanics
|
2017-06-06 06:53:51 +02:00
|
|
|
ScuttleBoatMechanics::ScuttleBoatMechanics(const CSpell * s):
|
|
|
|
AdventureSpellMechanics(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool ScuttleBoatMechanics::canBeCastAtImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
|
|
|
{
|
|
|
|
if(!cb->isInTheMap(pos))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (caster->getHeroCaster())
|
|
|
|
{
|
|
|
|
int3 casterPosition = caster->getHeroCaster()->getSightCenter();
|
|
|
|
|
|
|
|
if(!isInScreenRange(casterPosition, pos))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cb->isVisible(pos, caster->getCasterOwner()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const TerrainTile * t = cb->getTile(pos);
|
|
|
|
if(!t || t->visitableObjects.empty() || t->visitableObjects.back()->ID != Obj::BOAT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ESpellCastResult ScuttleBoatMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2015-02-02 11:22:19 +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
|
|
|
const auto schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
|
2015-02-02 11:22:19 +02:00
|
|
|
//check if spell works at all
|
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(env->getRNG()->getInt64Range(0, 99)() >= owner->getLevelPower(schoolLevel)) //power is % chance of success
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:06:02 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 337); //%s tried to scuttle the boat, but failed
|
2023-04-09 23:06:02 +02:00
|
|
|
parameters.caster->getCasterName(iw.text);
|
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
|
|
|
env->apply(&iw);
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::OK;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const TerrainTile & t = env->getMap()->getTile(parameters.pos);
|
2015-02-02 11:22:19 +02:00
|
|
|
|
|
|
|
RemoveObject ro;
|
2023-09-18 21:09:55 +02:00
|
|
|
ro.initiator = parameters.caster->getCasterOwner();
|
2024-04-10 17:19:48 +02:00
|
|
|
ro.objectID = t.visitableObjects.back()->id;
|
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
|
|
|
env->apply(&ro);
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::OK;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///DimensionDoorMechanics
|
2017-06-06 06:53:51 +02:00
|
|
|
DimensionDoorMechanics::DimensionDoorMechanics(const CSpell * s):
|
|
|
|
AdventureSpellMechanics(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool DimensionDoorMechanics::canBeCastImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster) const
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!caster->getHeroCaster())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(caster->getHeroCaster()->movementPointsRemaining() <= 0) //unlike town portal non-zero MP is enough
|
2023-04-09 23:37:46 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
problem.add(MetaString::createFromTextID("core.genrltxt.125"));
|
|
|
|
return false;
|
2023-04-09 23:37:46 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const auto schoolLevel = caster->getSpellSchoolLevel(owner);
|
2024-04-01 18:12:38 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
std::stringstream cachingStr;
|
|
|
|
cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << owner->id.num;
|
2015-02-02 11:22:19 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
int castsAlreadyPerformedThisTurn = caster->getHeroCaster()->getBonuses(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(owner->id)), Selector::all, cachingStr.str())->size();
|
|
|
|
int castsLimit = owner->getLevelPower(schoolLevel);
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool isTournamentRulesLimitEnabled = VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_TOURNAMENT_RULES_LIMIT);
|
|
|
|
if(isTournamentRulesLimitEnabled)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
int3 mapSize = cb->getMapSize();
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
bool meetsTournamentRulesTwoCastsRequirements = mapSize.x * mapSize.y * mapSize.z >= GameConstants::TOURNAMENT_RULES_DD_MAP_TILES_THRESHOLD
|
|
|
|
&& schoolLevel == MasteryLevel::EXPERT;
|
|
|
|
|
|
|
|
castsLimit = meetsTournamentRulesTwoCastsRequirements ? 2 : 1;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(castsAlreadyPerformedThisTurn >= castsLimit) //limit casts per turn
|
2024-04-01 18:12:38 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
MetaString message = MetaString::createFromTextID("core.genrltxt.338");
|
|
|
|
caster->getCasterName(message);
|
|
|
|
problem.add(std::move(message));
|
|
|
|
return false;
|
2024-04-01 18:12:38 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DimensionDoorMechanics::canBeCastAtImpl(spells::Problem & problem, const CGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
|
|
|
{
|
|
|
|
if(!cb->isInTheMap(pos))
|
|
|
|
return false;
|
|
|
|
|
2024-04-01 18:12:38 +02:00
|
|
|
if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_ONLY_TO_UNCOVERED_TILES))
|
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!cb->isVisible(pos, caster->getCasterOwner()))
|
|
|
|
return false;
|
2024-04-01 18:12:38 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
int3 casterPosition = caster->getHeroCaster()->getSightCenter();
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
const TerrainTile * dest = cb->getTileUnchecked(pos);
|
|
|
|
const TerrainTile * curr = cb->getTileUnchecked(casterPosition);
|
2016-10-01 05:51:12 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!dest)
|
|
|
|
return false;
|
2024-04-01 21:52:11 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!curr)
|
|
|
|
return false;
|
2024-04-01 21:52:11 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!isInScreenRange(casterPosition, pos))
|
|
|
|
return false;
|
2024-04-01 21:52:11 +02:00
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_EXPOSES_TERRAIN_TYPE))
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2024-04-10 17:19:48 +02:00
|
|
|
if(!dest->isClear(curr))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dest->blocked)
|
|
|
|
return false;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ESpellCastResult DimensionDoorMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
|
|
|
const auto schoolLevel = parameters.caster->getSpellSchoolLevel(owner);
|
|
|
|
const int movementCost = GameConstants::BASE_MOVEMENT_COST * ((schoolLevel >= 3) ? 2 : 3);
|
|
|
|
|
|
|
|
int3 casterPosition = parameters.caster->getHeroCaster()->getSightCenter();
|
|
|
|
const TerrainTile * dest = env->getCb()->getTile(parameters.pos);
|
|
|
|
const TerrainTile * curr = env->getCb()->getTile(casterPosition);
|
|
|
|
|
|
|
|
if(!dest->isClear(curr))
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:06:02 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2024-04-10 17:19:48 +02:00
|
|
|
|
|
|
|
// tile is either blocked or not possible to move (e.g. water <-> land)
|
|
|
|
if(VLC->settings()->getBoolean(EGameSettings::DIMENSION_DOOR_FAILURE_SPENDS_POINTS))
|
|
|
|
{
|
|
|
|
// SOD: DD to such "wrong" terrain results in mana and move points spending, but fails to move hero
|
|
|
|
iw.text = MetaString::createFromTextID("core.genrltxt.70"); // Dimension Door failed!
|
|
|
|
env->apply(&iw);
|
|
|
|
// no return - resources will be spent
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// HotA: game will show error message without taking mana or move points, even when DD into terra incognita
|
|
|
|
iw.text = MetaString::createFromTextID("vcmi.dimensionDoor.seaToLandError");
|
|
|
|
env->apply(&iw);
|
|
|
|
return ESpellCastResult::CANCEL;
|
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2024-04-01 18:12:38 +02:00
|
|
|
|
|
|
|
GiveBonus gb;
|
|
|
|
gb.id = ObjectInstanceID(parameters.caster->getCasterUnitId());
|
|
|
|
gb.bonus = Bonus(BonusDuration::ONE_DAY, BonusType::NONE, BonusSource::SPELL_EFFECT, 0, BonusSourceID(owner->id));
|
|
|
|
env->apply(&gb);
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
SetMovePoints smp;
|
|
|
|
smp.hid = ObjectInstanceID(parameters.caster->getCasterUnitId());
|
|
|
|
if(movementCost < static_cast<int>(parameters.caster->getHeroCaster()->movementPointsRemaining()))
|
|
|
|
smp.val = parameters.caster->getHeroCaster()->movementPointsRemaining() - movementCost;
|
|
|
|
else
|
|
|
|
smp.val = 0;
|
|
|
|
env->apply(&smp);
|
|
|
|
|
2024-04-10 17:42:31 +02:00
|
|
|
return ESpellCastResult::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DimensionDoorMechanics::endCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
|
|
|
int3 casterPosition = parameters.caster->getHeroCaster()->getSightCenter();
|
|
|
|
const TerrainTile * dest = env->getCb()->getTile(parameters.pos);
|
|
|
|
const TerrainTile * curr = env->getCb()->getTile(casterPosition);
|
|
|
|
|
2024-04-10 17:19:48 +02:00
|
|
|
if(dest->isClear(curr))
|
|
|
|
env->moveHero(ObjectInstanceID(parameters.caster->getCasterUnitId()), parameters.caster->getHeroCaster()->convertFromVisitablePos(parameters.pos), true);
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///TownPortalMechanics
|
2017-06-06 06:53:51 +02:00
|
|
|
TownPortalMechanics::TownPortalMechanics(const CSpell * s):
|
|
|
|
AdventureSpellMechanics(s)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +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
|
|
|
ESpellCastResult TownPortalMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
const CGTownInstance * destination = nullptr;
|
2017-07-03 20:09:27 +02:00
|
|
|
const int moveCost = movementCost(parameters);
|
2023-04-09 23:46:37 +02:00
|
|
|
|
|
|
|
if(!parameters.caster->getHeroCaster())
|
|
|
|
{
|
|
|
|
env->complain("Not a hero caster!");
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
2016-02-15 12:34:37 +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(parameters.caster->getSpellSchoolLevel(owner) < 2)
|
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
std::vector <const CGTownInstance*> pool = getPossibleTowns(env, parameters);
|
|
|
|
destination = findNearestTown(env, parameters, pool);
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
if(nullptr == destination)
|
2017-07-03 20:09:27 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-06-21 19:38:26 +02:00
|
|
|
if(static_cast<int>(parameters.caster->getHeroCaster()->movementPointsRemaining()) < moveCost)
|
2017-07-03 20:09:27 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
if(destination->visitingHero)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:46:37 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 123);
|
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
|
|
|
env->apply(&iw);
|
2017-06-06 06:53:51 +02:00
|
|
|
return ESpellCastResult::CANCEL;
|
|
|
|
}
|
2024-04-10 17:19:48 +02:00
|
|
|
}
|
|
|
|
else if(env->getMap()->isInTheMap(parameters.pos))
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
const TerrainTile & tile = env->getMap()->getTile(parameters.pos);
|
2019-02-23 19:51:03 +02:00
|
|
|
|
2023-02-11 17:18:05 +02:00
|
|
|
auto * const topObj = tile.topVisitableObj(false);
|
2019-02-23 19:51:03 +02:00
|
|
|
|
|
|
|
if(!topObj)
|
|
|
|
{
|
|
|
|
env->complain("Destination tile is not visitable" + parameters.pos.toString());
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
else if(topObj->ID == Obj::HERO)
|
|
|
|
{
|
|
|
|
env->complain("Can't teleport to occupied town at " + parameters.pos.toString());
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
else if(topObj->ID != Obj::TOWN)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2019-02-23 19:51:03 +02:00
|
|
|
env->complain("No town at destination tile " + parameters.pos.toString());
|
2017-06-06 06:53:51 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2019-02-23 19:51:03 +02:00
|
|
|
destination = dynamic_cast<const CGTownInstance*>(topObj);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
|
|
|
if(nullptr == destination)
|
2015-02-02 11:22:19 +02:00
|
|
|
{
|
2019-02-23 19:51:03 +02:00
|
|
|
env->complain("[Internal error] invalid town object at " + parameters.pos.toString());
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-04-09 23:46:37 +02:00
|
|
|
const auto relations = env->getCb()->getPlayerRelations(destination->tempOwner, parameters.caster->getCasterOwner());
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
if(relations == PlayerRelations::ENEMIES)
|
|
|
|
{
|
|
|
|
env->complain("Can't teleport to enemy!");
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
|
2023-06-21 19:38:26 +02:00
|
|
|
if(static_cast<int>(parameters.caster->getHeroCaster()->movementPointsRemaining()) < moveCost)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
env->complain("This hero has not enough movement points!");
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
if(destination->visitingHero)
|
|
|
|
{
|
2019-02-23 19:51:03 +02:00
|
|
|
env->complain("[Internal error] Can't teleport to occupied town");
|
2017-06-06 06:53:51 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-04-01 03:48:50 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
env->complain("Invalid destination tile");
|
2016-02-15 12:34:37 +02:00
|
|
|
return ESpellCastResult::ERROR;
|
2015-04-01 03:48:50 +02:00
|
|
|
}
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2024-04-10 18:04:09 +02:00
|
|
|
const TerrainTile & from = env->getMap()->getTile(parameters.caster->getHeroCaster()->visitablePos());
|
|
|
|
const TerrainTile & dest = env->getMap()->getTile(destination->visitablePos());
|
|
|
|
|
|
|
|
if(!dest.isClear(&from))
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 135);
|
|
|
|
env->apply(&iw);
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
|
|
|
|
2024-04-10 17:42:31 +02:00
|
|
|
return ESpellCastResult::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TownPortalMechanics::endCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
|
|
|
{
|
|
|
|
const int moveCost = movementCost(parameters);
|
|
|
|
const CGTownInstance * destination = nullptr;
|
|
|
|
|
|
|
|
if(parameters.caster->getSpellSchoolLevel(owner) < 2)
|
|
|
|
{
|
|
|
|
std::vector <const CGTownInstance*> pool = getPossibleTowns(env, parameters);
|
|
|
|
destination = findNearestTown(env, parameters, pool);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TerrainTile & tile = env->getMap()->getTile(parameters.pos);
|
|
|
|
auto * const topObj = tile.topVisitableObj(false);
|
|
|
|
destination = dynamic_cast<const CGTownInstance*>(topObj);
|
|
|
|
}
|
|
|
|
|
2023-04-09 23:46:37 +02:00
|
|
|
if(env->moveHero(ObjectInstanceID(parameters.caster->getCasterUnitId()), parameters.caster->getHeroCaster()->convertFromVisitablePos(destination->visitablePos()), true))
|
2015-04-01 03:48:50 +02:00
|
|
|
{
|
|
|
|
SetMovePoints smp;
|
2023-04-09 23:46:37 +02:00
|
|
|
smp.hid = ObjectInstanceID(parameters.caster->getCasterUnitId());
|
2023-06-21 19:38:26 +02:00
|
|
|
smp.val = std::max<ui32>(0, parameters.caster->getHeroCaster()->movementPointsRemaining() - moveCost);
|
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
|
|
|
env->apply(&smp);
|
2015-04-01 03:48:50 +02:00
|
|
|
}
|
2015-02-02 11:22:19 +02:00
|
|
|
}
|
2015-02-02 14:02:27 +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
|
|
|
ESpellCastResult TownPortalMechanics::beginCast(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
|
|
|
std::vector<const CGTownInstance *> towns = getPossibleTowns(env, parameters);
|
2023-04-09 23:46:37 +02:00
|
|
|
|
|
|
|
if(!parameters.caster->getHeroCaster())
|
|
|
|
{
|
|
|
|
env->complain("Not a hero caster!");
|
|
|
|
return ESpellCastResult::ERROR;
|
|
|
|
}
|
2017-07-03 20:09:27 +02:00
|
|
|
|
|
|
|
if(towns.empty())
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:46:37 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 124);
|
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
|
|
|
env->apply(&iw);
|
2017-07-03 20:09:27 +02:00
|
|
|
return ESpellCastResult::CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int moveCost = movementCost(parameters);
|
|
|
|
|
2023-06-21 19:38:26 +02:00
|
|
|
if(static_cast<int>(parameters.caster->getHeroCaster()->movementPointsRemaining()) < moveCost)
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:46:37 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 125);
|
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
|
|
|
env->apply(&iw);
|
2017-07-03 20:09:27 +02:00
|
|
|
return ESpellCastResult::CANCEL;
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:32:40 +02:00
|
|
|
if(!parameters.pos.valid() && parameters.caster->getSpellSchoolLevel(owner) >= 2)
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2023-09-19 22:17:25 +02:00
|
|
|
auto queryCallback = [=](std::optional<int32_t> reply) -> void
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2023-09-19 22:17:25 +02:00
|
|
|
if(reply.has_value())
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2023-09-19 22:17:25 +02:00
|
|
|
ObjectInstanceID townId(*reply);
|
2017-07-03 20:09:27 +02:00
|
|
|
|
|
|
|
const CGObjectInstance * o = env->getCb()->getObj(townId, true);
|
|
|
|
if(o == nullptr)
|
|
|
|
{
|
|
|
|
env->complain("Invalid object instance selected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!dynamic_cast<const CGTownInstance *>(o))
|
|
|
|
{
|
|
|
|
env->complain("Object instance is not town");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AdventureSpellCastParameters p;
|
|
|
|
p.caster = parameters.caster;
|
|
|
|
p.pos = o->visitablePos();
|
|
|
|
performCast(env, p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MapObjectSelectDialog request;
|
|
|
|
|
2023-02-11 17:18:05 +02:00
|
|
|
for(const auto * t : towns)
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2017-07-04 00:32:40 +02:00
|
|
|
if(t->visitingHero == nullptr) //empty town
|
2017-07-03 20:09:27 +02:00
|
|
|
request.objects.push_back(t->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(request.objects.empty())
|
|
|
|
{
|
|
|
|
InfoWindow iw;
|
2023-04-09 23:46:37 +02:00
|
|
|
iw.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
iw.text.appendLocalString(EMetaText::GENERAL_TXT, 124);
|
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
|
|
|
env->apply(&iw);
|
2017-07-03 20:09:27 +02:00
|
|
|
return ESpellCastResult::CANCEL;
|
|
|
|
}
|
|
|
|
|
2023-04-09 23:46:37 +02:00
|
|
|
request.player = parameters.caster->getCasterOwner();
|
2023-06-18 11:18:25 +02:00
|
|
|
request.title.appendLocalString(EMetaText::JK_TXT, 40);
|
|
|
|
request.description.appendLocalString(EMetaText::JK_TXT, 41);
|
2023-10-31 11:09:56 +02:00
|
|
|
request.icon = Component(ComponentType::SPELL, owner->id);
|
2017-07-03 20:09:27 +02:00
|
|
|
|
|
|
|
env->genericQuery(&request, request.player, queryCallback);
|
|
|
|
|
|
|
|
return ESpellCastResult::PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ESpellCastResult::OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
const CGTownInstance * TownPortalMechanics::findNearestTown(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters, const std::vector <const CGTownInstance *> & pool) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
if(pool.empty())
|
|
|
|
return nullptr;
|
2023-04-09 23:46:37 +02:00
|
|
|
|
|
|
|
if(!parameters.caster->getHeroCaster())
|
|
|
|
return nullptr;
|
2017-06-06 06:53:51 +02:00
|
|
|
|
|
|
|
auto nearest = pool.cbegin(); //nearest town's iterator
|
2023-04-09 23:46:37 +02:00
|
|
|
si32 dist = (*nearest)->pos.dist2dSQ(parameters.caster->getHeroCaster()->pos);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-04 00:32:40 +02:00
|
|
|
for(auto i = nearest + 1; i != pool.cend(); ++i)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
2023-04-09 23:46:37 +02:00
|
|
|
si32 curDist = (*i)->pos.dist2dSQ(parameters.caster->getHeroCaster()->pos);
|
2017-06-06 06:53:51 +02:00
|
|
|
|
2017-07-04 00:32:40 +02:00
|
|
|
if(curDist < dist)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
nearest = i;
|
|
|
|
dist = curDist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return *nearest;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
std::vector <const CGTownInstance*> TownPortalMechanics::getPossibleTowns(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
std::vector <const CGTownInstance*> ret;
|
|
|
|
|
2023-04-09 23:46:37 +02:00
|
|
|
const TeamState * team = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner());
|
2017-06-06 06:53:51 +02:00
|
|
|
|
|
|
|
for(const auto & color : team->players)
|
|
|
|
{
|
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
|
|
|
for(auto currTown : env->getCb()->getPlayerState(color)->towns)
|
2017-06-06 06:53:51 +02:00
|
|
|
{
|
|
|
|
ret.push_back(currTown.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
int32_t TownPortalMechanics::movementCost(const AdventureSpellCastParameters & parameters) const
|
2017-07-03 20:09:27 +02:00
|
|
|
{
|
2023-04-10 15:08:24 +02:00
|
|
|
if(parameters.caster != parameters.caster->getHeroCaster()) //if caster is not hero
|
|
|
|
return 0;
|
|
|
|
|
2017-07-03 20:09:27 +02:00
|
|
|
return GameConstants::BASE_MOVEMENT_COST * ((parameters.caster->getSpellSchoolLevel(owner) >= 3) ? 2 : 3);
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
///ViewMechanics
|
|
|
|
ViewMechanics::ViewMechanics(const CSpell * s):
|
|
|
|
AdventureSpellMechanics(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ESpellCastResult ViewMechanics::applyAdventureEffects(SpellCastEnvironment * env, const AdventureSpellCastParameters & parameters) const
|
2015-02-26 16:15:17 +02:00
|
|
|
{
|
|
|
|
ShowWorldViewEx pack;
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-04-09 23:46:37 +02:00
|
|
|
pack.player = parameters.caster->getCasterOwner();
|
2015-02-26 19:59:18 +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
|
|
|
const auto spellLevel = parameters.caster->getSpellSchoolLevel(owner);
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2023-11-13 12:09:55 +02:00
|
|
|
const auto & fowMap = env->getCb()->getPlayerTeam(parameters.caster->getCasterOwner())->fogOfWarMap;
|
2016-09-28 06:58:15 +02:00
|
|
|
|
2015-02-26 16:15:17 +02:00
|
|
|
for(const CGObjectInstance * obj : env->getMap()->objects)
|
|
|
|
{
|
2016-09-28 06:58:15 +02:00
|
|
|
//deleted object remain as empty pointer
|
|
|
|
if(obj && filterObject(obj, spellLevel))
|
|
|
|
{
|
|
|
|
ObjectPosInfo posInfo(obj);
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2023-01-19 20:19:29 +02:00
|
|
|
if((*fowMap)[posInfo.pos.z][posInfo.pos.x][posInfo.pos.y] == 0)
|
2016-09-28 06:58:15 +02:00
|
|
|
pack.objectPositions.push_back(posInfo);
|
|
|
|
}
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2023-02-21 14:38:08 +02:00
|
|
|
pack.showTerrain = showTerrain(spellLevel);
|
2015-02-26 19:59:18 +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
|
|
|
env->apply(&pack);
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2015-04-13 05:12:23 +02:00
|
|
|
return ESpellCastResult::OK;
|
2015-02-26 16:15:17 +02:00
|
|
|
}
|
2015-02-02 14:02:27 +02:00
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
///ViewAirMechanics
|
|
|
|
ViewAirMechanics::ViewAirMechanics(const CSpell * s):
|
|
|
|
ViewMechanics(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bool ViewAirMechanics::filterObject(const CGObjectInstance * obj, const int32_t spellLevel) const
|
2015-02-02 14:02:27 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
return (obj->ID == Obj::ARTIFACT) || (spellLevel > 1 && obj->ID == Obj::HERO) || (spellLevel > 2 && obj->ID == Obj::TOWN);
|
|
|
|
}
|
|
|
|
|
2023-02-21 14:38:08 +02:00
|
|
|
bool ViewAirMechanics::showTerrain(const int32_t spellLevel) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:53:51 +02:00
|
|
|
///ViewEarthMechanics
|
|
|
|
ViewEarthMechanics::ViewEarthMechanics(const CSpell * s):
|
|
|
|
ViewMechanics(s)
|
|
|
|
{
|
2015-02-02 14:02:27 +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
|
|
|
bool ViewEarthMechanics::filterObject(const CGObjectInstance * obj, const int32_t spellLevel) const
|
2015-02-02 14:02:27 +02:00
|
|
|
{
|
2017-06-06 06:53:51 +02:00
|
|
|
return (obj->ID == Obj::RESOURCE) || (spellLevel > 1 && obj->ID == Obj::MINE);
|
2015-02-02 14:02:27 +02:00
|
|
|
}
|
2015-02-26 16:15:17 +02:00
|
|
|
|
2023-02-21 14:38:08 +02:00
|
|
|
bool ViewEarthMechanics::showTerrain(const int32_t spellLevel) const
|
|
|
|
{
|
|
|
|
return spellLevel > 2;
|
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|