2025-07-08 19:20:13 +03:00
|
|
|
/*
|
|
|
|
|
* 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())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 16:47:37 +03:00
|
|
|
bool AdventureSpellRangedEffect::isTargetInRange(const IGameInfoCallback * cb, const spells::Caster * caster, const int3 & pos) const
|
2025-07-08 19:20:13 +03:00
|
|
|
{
|
|
|
|
|
if(!cb->isInTheMap(pos))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if(caster->getHeroCaster())
|
|
|
|
|
{
|
2025-07-10 17:27:27 +03:00
|
|
|
int3 center = caster->getHeroCaster()->getSightCenter();
|
2025-07-08 19:20:13 +03:00
|
|
|
|
2025-07-10 17:27:27 +03:00
|
|
|
int3 diff = pos - center;
|
|
|
|
|
return diff.x >= -rangeX && diff.x <= rangeX && diff.y >= -rangeY && diff.y <= rangeY;
|
2025-07-08 19:20:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!ignoreFow && !cb->isVisibleFor(pos, caster->getCasterOwner()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|