mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
|
|
/*
|
||
|
|
* AdventureSpellEffect.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 "AdventureSpellEffect.h"
|
||
|
|
|
||
|
|
#include "../../json/JsonNode.h"
|
||
|
|
#include "../../mapObjects/CGHeroInstance.h"
|
||
|
|
#include "../../callback/IGameInfoCallback.h"
|
||
|
|
|
||
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
||
|
|
|
||
|
|
AdventureSpellRangedEffect::AdventureSpellRangedEffect(const JsonNode & config)
|
||
|
|
: rangeX(config["rangeX"].Integer())
|
||
|
|
, rangeY(config["rangeY"].Integer())
|
||
|
|
, ignoreFow(config["ignoreFow"].Bool())
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
bool AdventureSpellRangedEffect::isTargetInRange(const int3 & pos, const int3 & center) const
|
||
|
|
{
|
||
|
|
int3 diff = pos - center;
|
||
|
|
return diff.x >= -rangeX && diff.x <= rangeX && diff.y >= -rangeY && diff.y <= rangeY;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool AdventureSpellRangedEffect::canBeCastAtImpl(spells::Problem & problem, const IGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
||
|
|
{
|
||
|
|
if(!cb->isInTheMap(pos))
|
||
|
|
return false;
|
||
|
|
|
||
|
|
if(caster->getHeroCaster())
|
||
|
|
{
|
||
|
|
int3 casterPosition = caster->getHeroCaster()->getSightCenter();
|
||
|
|
|
||
|
|
if(!isTargetInRange(casterPosition, pos))
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(!ignoreFow && !cb->isVisibleFor(pos, caster->getCasterOwner()))
|
||
|
|
return false;
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
VCMI_LIB_NAMESPACE_END
|