2017-03-17 17:48:44 +02:00
|
|
|
/*
|
|
|
|
* CStack.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 "CStack.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include <vstd/RNG.h>
|
|
|
|
|
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
|
|
|
#include <vcmi/ServerCallback.h>
|
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
#include "CGeneralTextHandler.h"
|
2017-06-24 16:42:05 +02:00
|
|
|
#include "battle/BattleInfo.h"
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "spells/CSpellHandler.h"
|
|
|
|
#include "NetPacks.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
///CStack
|
2023-03-13 23:26:44 +02:00
|
|
|
CStack::CStack(const CStackInstance * Base, const PlayerColor & O, int I, ui8 Side, const SlotID & S):
|
|
|
|
CBonusSystemNode(STACK_BATTLE),
|
2017-07-20 06:08:49 +02:00
|
|
|
base(Base),
|
|
|
|
ID(I),
|
|
|
|
type(Base->type),
|
|
|
|
baseAmount(base->count),
|
|
|
|
owner(O),
|
|
|
|
slot(S),
|
2023-03-13 23:26:44 +02:00
|
|
|
side(Side)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-09 18:49:52 +02:00
|
|
|
health.init(); //???
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CStack::CStack():
|
|
|
|
CBonusSystemNode(STACK_BATTLE),
|
|
|
|
owner(PlayerColor::NEUTRAL),
|
|
|
|
slot(SlotID(255)),
|
|
|
|
initialPosition(BattleHex())
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
|
|
|
}
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
CStack::CStack(const CStackBasicDescriptor * stack, const PlayerColor & O, int I, ui8 Side, const SlotID & S):
|
|
|
|
CBonusSystemNode(STACK_BATTLE),
|
2017-07-20 06:08:49 +02:00
|
|
|
ID(I),
|
|
|
|
type(stack->type),
|
|
|
|
baseAmount(stack->count),
|
|
|
|
owner(O),
|
|
|
|
slot(S),
|
2023-03-13 23:26:44 +02:00
|
|
|
side(Side)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-09 18:49:52 +02:00
|
|
|
health.init(); //???
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CCreature * CStack::getCreature() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStack::localInit(BattleInfo * battleInfo)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-04 13:24:46 +02:00
|
|
|
battle = battleInfo;
|
2017-03-17 17:48:44 +02:00
|
|
|
assert(type);
|
|
|
|
|
2017-07-04 13:24:46 +02:00
|
|
|
exportBonuses();
|
|
|
|
if(base) //stack originating from "real" stack in garrison -> attach to it
|
|
|
|
{
|
2022-11-06 01:26:13 +02:00
|
|
|
attachTo(const_cast<CStackInstance&>(*base));
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
|
|
|
else //attach directly to obj to which stack belongs and creature type
|
|
|
|
{
|
|
|
|
CArmedInstance * army = battle->battleGetArmyObject(side);
|
2022-11-06 01:26:13 +02:00
|
|
|
assert(army);
|
|
|
|
attachTo(*army);
|
|
|
|
attachTo(const_cast<CCreature&>(*type));
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
2020-12-10 03:05:37 +02:00
|
|
|
nativeTerrain = type->getNativeTerrain(); //save nativeTerrain in the variable on the battle start to avoid dead lock
|
|
|
|
CUnitState::localInit(this); //it causes execution of the CStack::isOnNativeTerrain where nativeTerrain will be considered
|
2017-07-20 06:08:49 +02:00
|
|
|
position = initialPosition;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ui32 CStack::level() const
|
|
|
|
{
|
2017-07-09 14:49:37 +02:00
|
|
|
if(base)
|
2017-07-20 06:08:49 +02:00
|
|
|
return base->getLevel(); //creature or commander
|
2017-03-17 17:48:44 +02:00
|
|
|
else
|
2023-03-13 23:26:44 +02:00
|
|
|
return std::max(1, static_cast<int>(getCreature()->level)); //war machine, clone etc
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
si32 CStack::magicResistance() const
|
|
|
|
{
|
2023-03-20 21:26:55 +02:00
|
|
|
auto magicResistance = IBonusBearer::magicResistance();
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
si32 auraBonus = 0;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto * one : battle->battleAdjacentUnits(this))
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(one->unitOwner() == owner)
|
|
|
|
vstd::amax(auraBonus, one->valOfBonuses(Bonus::SPELL_RESISTANCE_AURA)); //max value
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
2023-03-20 21:26:55 +02:00
|
|
|
vstd::abetween(auraBonus, 0, 100);
|
|
|
|
vstd::abetween(magicResistance, 0, 100);
|
|
|
|
float castChance = (100 - magicResistance) * (100 - auraBonus)/100.0;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2023-03-20 21:26:55 +02:00
|
|
|
return static_cast<si32>(100 - castChance);
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 10:34:00 +02:00
|
|
|
BattleHex::EDir CStack::destShiftDir() const
|
|
|
|
{
|
|
|
|
if(doubleWide())
|
|
|
|
{
|
|
|
|
if(side == BattleSide::ATTACKER)
|
|
|
|
return BattleHex::EDir::RIGHT;
|
|
|
|
else
|
|
|
|
return BattleHex::EDir::LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return BattleHex::EDir::NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
std::vector<si32> CStack::activeSpells() const
|
|
|
|
{
|
|
|
|
std::vector<si32> ret;
|
|
|
|
|
|
|
|
std::stringstream cachingStr;
|
|
|
|
cachingStr << "!type_" << Bonus::NONE << "source_" << Bonus::SPELL_EFFECT;
|
2020-11-11 21:43:40 +02:00
|
|
|
CSelector selector = Selector::sourceType()(Bonus::SPELL_EFFECT)
|
2017-07-09 14:49:37 +02:00
|
|
|
.And(CSelector([](const Bonus * b)->bool
|
|
|
|
{
|
|
|
|
return b->type != Bonus::NONE;
|
|
|
|
}));
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr spellEffects = getBonuses(selector, Selector::all, cachingStr.str());
|
|
|
|
for(const auto & it : *spellEffects)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-09 14:49:37 +02:00
|
|
|
if(!vstd::contains(ret, it->sid)) //do not duplicate spells with multiple effects
|
2017-03-17 17:48:44 +02:00
|
|
|
ret.push_back(it->sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CStack::~CStack()
|
|
|
|
{
|
|
|
|
detachFromAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
const CGHeroInstance * CStack::getMyHero() const
|
|
|
|
{
|
|
|
|
if(base)
|
|
|
|
return dynamic_cast<const CGHeroInstance *>(base->armyObj);
|
|
|
|
else //we are attached directly?
|
2017-07-09 14:49:37 +02:00
|
|
|
for(const CBonusSystemNode * n : getParentNodes())
|
2017-03-17 17:48:44 +02:00
|
|
|
if(n->getNodeType() == HERO)
|
|
|
|
return dynamic_cast<const CGHeroInstance *>(n);
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CStack::nodeName() const
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
2017-07-20 06:08:49 +02:00
|
|
|
oss << owner.getStr();
|
|
|
|
oss << " battle stack [" << ID << "]: " << getCount() << " of ";
|
2017-03-17 17:48:44 +02:00
|
|
|
if(type)
|
2023-01-02 18:00:51 +02:00
|
|
|
oss << type->getNamePluralTextID();
|
2017-03-17 17:48:44 +02:00
|
|
|
else
|
|
|
|
oss << "[UNDEFINED TYPE]";
|
|
|
|
|
|
|
|
oss << " from slot " << slot;
|
|
|
|
if(base && base->armyObj)
|
|
|
|
oss << " of armyobj=" << base->armyObj->id.getNum();
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand) const
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto newState = acquireState();
|
|
|
|
prepareAttacked(bsa, rand, newState);
|
2017-07-09 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, const std::shared_ptr<battle::CUnitState> & customState)
|
2017-07-09 18:49:52 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto initialCount = customState->getCount();
|
|
|
|
|
2022-12-18 17:38:14 +02:00
|
|
|
// compute damage and update bsa.damageAmount
|
2017-07-20 06:08:49 +02:00
|
|
|
customState->damage(bsa.damageAmount);
|
2017-07-09 18:49:52 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bsa.killedAmount = initialCount - customState->getCount();
|
|
|
|
|
|
|
|
if(!customState->alive() && customState->isClone())
|
2017-07-09 18:49:52 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
bsa.flags |= BattleStackAttacked::CLONE_KILLED;
|
2017-07-09 18:49:52 +02:00
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
else if(!customState->alive()) //stack killed
|
2017-07-09 18:49:52 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
bsa.flags |= BattleStackAttacked::KILLED;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto resurrectValue = customState->valOfBonuses(Bonus::REBIRTH);
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(resurrectValue > 0 && customState->canCast()) //there must be casts left
|
|
|
|
{
|
2018-02-08 13:37:52 +02:00
|
|
|
double resurrectFactor = resurrectValue / 100.0;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto baseAmount = customState->unitBaseAmount();
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
double resurrectedRaw = baseAmount * resurrectFactor;
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto resurrectedCount = static_cast<int32_t>(floor(resurrectedRaw));
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto resurrectedAdd = static_cast<int32_t>(baseAmount - (resurrectedCount / resurrectFactor));
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
auto rangeGen = rand.getInt64Range(0, 99);
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
for(int32_t i = 0; i < resurrectedAdd; i++)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(resurrectValue > rangeGen())
|
|
|
|
resurrectedCount += 1;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(customState->hasBonusOfType(Bonus::REBIRTH, 1))
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
|
|
|
// resurrect at least one Sacred Phoenix
|
2017-07-20 06:08:49 +02:00
|
|
|
vstd::amax(resurrectedCount, 1);
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(resurrectedCount > 0)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
customState->casts.use();
|
2017-03-17 17:48:44 +02:00
|
|
|
bsa.flags |= BattleStackAttacked::REBIRTH;
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t toHeal = customState->MaxHealth() * resurrectedCount;
|
|
|
|
//TODO: add one-battle rebirth?
|
|
|
|
customState->heal(toHeal, EHealLevel::RESURRECT, EHealPower::PERMANENT);
|
|
|
|
customState->counterAttacks.use(customState->counterAttacks.available());
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
customState->save(bsa.newState.data);
|
|
|
|
bsa.newState.healthDelta = -bsa.damageAmount;
|
|
|
|
bsa.newState.id = customState->unitId();
|
|
|
|
bsa.newState.operation = UnitChanges::EOperation::RESET_STATE;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2019-06-28 20:05:25 +02:00
|
|
|
std::vector<BattleHex> CStack::meleeAttackHexes(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos, BattleHex defenderPos)
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2019-06-28 20:05:25 +02:00
|
|
|
int mask = 0;
|
|
|
|
std::vector<BattleHex> res;
|
|
|
|
|
|
|
|
if (!attackerPos.isValid())
|
2017-07-20 06:08:49 +02:00
|
|
|
attackerPos = attacker->getPosition();
|
2019-06-28 20:05:25 +02:00
|
|
|
if (!defenderPos.isValid())
|
2017-07-20 06:08:49 +02:00
|
|
|
defenderPos = defender->getPosition();
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2019-06-28 20:05:25 +02:00
|
|
|
BattleHex otherAttackerPos = attackerPos + (attacker->unitSide() == BattleSide::ATTACKER ? -1 : 1);
|
|
|
|
BattleHex otherDefenderPos = defenderPos + (defender->unitSide() == BattleSide::ATTACKER ? -1 : 1);
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2020-05-17 10:21:49 +02:00
|
|
|
if(BattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front
|
|
|
|
{
|
|
|
|
if((mask & 1) == 0)
|
|
|
|
{
|
2019-06-28 20:05:25 +02:00
|
|
|
mask |= 1;
|
|
|
|
res.push_back(defenderPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (attacker->doubleWide() //back <=> front
|
2020-05-17 10:21:49 +02:00
|
|
|
&& BattleHex::mutualPosition(otherAttackerPos, defenderPos) >= 0)
|
|
|
|
{
|
|
|
|
if((mask & 1) == 0)
|
|
|
|
{
|
2019-06-28 20:05:25 +02:00
|
|
|
mask |= 1;
|
|
|
|
res.push_back(defenderPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defender->doubleWide()//front <=> back
|
2020-05-17 10:21:49 +02:00
|
|
|
&& BattleHex::mutualPosition(attackerPos, otherDefenderPos) >= 0)
|
|
|
|
{
|
|
|
|
if((mask & 2) == 0)
|
|
|
|
{
|
2019-06-28 20:05:25 +02:00
|
|
|
mask |= 2;
|
|
|
|
res.push_back(otherDefenderPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (defender->doubleWide() && attacker->doubleWide()//back <=> back
|
2020-05-17 10:21:49 +02:00
|
|
|
&& BattleHex::mutualPosition(otherAttackerPos, otherDefenderPos) >= 0)
|
|
|
|
{
|
|
|
|
if((mask & 2) == 0)
|
|
|
|
{
|
2019-06-28 20:05:25 +02:00
|
|
|
mask |= 2;
|
|
|
|
res.push_back(otherDefenderPos);
|
|
|
|
}
|
|
|
|
}
|
2022-12-07 18:06:47 +02:00
|
|
|
MAYBE_UNUSED(mask);
|
2019-06-28 20:05:25 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CStack::isMeleeAttackPossible(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos, BattleHex defenderPos)
|
|
|
|
{
|
|
|
|
return !meleeAttackHexes(attacker, defender, attackerPos, defenderPos).empty();
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CStack::getName() const
|
|
|
|
{
|
2023-01-02 18:00:51 +02:00
|
|
|
return (getCount() == 1) ? type->getNameSingularTranslated() : type->getNamePluralTranslated(); //War machines can't use base
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CStack::canBeHealed() const
|
|
|
|
{
|
2023-03-13 23:26:44 +02:00
|
|
|
return getFirstHPleft() < static_cast<int32_t>(MaxHealth()) && isValidTarget() && !hasBonusOfType(Bonus::SIEGE_WEAPON);
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:59:30 +02:00
|
|
|
bool CStack::isOnNativeTerrain() const
|
|
|
|
{
|
2020-12-10 03:05:37 +02:00
|
|
|
//this code is called from CreatureTerrainLimiter::limit on battle start
|
2022-12-20 18:35:40 +02:00
|
|
|
auto res = nativeTerrain == ETerrainId::ANY_TERRAIN || nativeTerrain == battle->getTerrainType();
|
2020-12-10 03:05:37 +02:00
|
|
|
return res;
|
2018-04-17 14:59:30 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
bool CStack::isOnTerrain(TerrainId terrain) const
|
2018-04-17 14:59:30 +02:00
|
|
|
{
|
|
|
|
return battle->getTerrainType() == terrain;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CCreature * CStack::unitType() const
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return type;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int32_t CStack::unitBaseAmount() const
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return baseAmount;
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool CStack::unitHasAmmoCart(const battle::Unit * unit) const
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
for(const CStack * st : battle->stacks)
|
|
|
|
{
|
2019-03-22 01:02:32 +02:00
|
|
|
if(battle->battleMatchOwner(st, unit, true) && st->getCreature()->idNumber == CreatureID::AMMO_CART)
|
|
|
|
{
|
2019-03-20 21:58:15 +02:00
|
|
|
return st->alive();
|
2019-03-22 01:02:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//ammo cart works during creature bank battle while not on battlefield
|
2023-03-13 23:26:44 +02:00
|
|
|
const auto * ownerHero = battle->battleGetOwnerHero(unit);
|
2019-03-22 01:02:32 +02:00
|
|
|
if(ownerHero && ownerHero->artifactsWorn.find(ArtifactPosition::MACH2) != ownerHero->artifactsWorn.end())
|
|
|
|
{
|
2023-01-02 15:58:56 +02:00
|
|
|
if(battle->battleGetOwnerHero(unit)->artifactsWorn.at(ArtifactPosition::MACH2).artifact->artType->getId() == ArtifactID::AMMO_CART)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2019-03-22 01:02:32 +02:00
|
|
|
return true;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 01:02:32 +02:00
|
|
|
return false; //will be always false if trying to examine enemy hero in "special battle"
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
PlayerColor CStack::unitEffectiveOwner(const battle::Unit * unit) const
|
2017-03-17 17:48:44 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return battle->battleGetOwner(unit);
|
2017-03-17 17:48:44 +02:00
|
|
|
}
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
uint32_t CStack::unitId() const
|
2017-07-09 18:49:52 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return ID;
|
2017-07-09 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
ui8 CStack::unitSide() const
|
2017-07-09 18:49:52 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return side;
|
2017-07-09 18:49:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
PlayerColor CStack::unitOwner() const
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return owner;
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
SlotID CStack::unitSlot() const
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return slot;
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
std::string CStack::getDescription() const
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return nodeName();
|
2017-07-04 13:24: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
|
|
|
void CStack::spendMana(ServerCallback * server, const int spellCost) const
|
2017-07-04 13:24:46 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(spellCost != 1)
|
|
|
|
logGlobal->warn("Unexpected spell cost %d for creature", spellCost);
|
2017-07-04 13:24:46 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
BattleSetStackProperty ssp;
|
|
|
|
ssp.stackID = unitId();
|
|
|
|
ssp.which = BattleSetStackProperty::CASTS;
|
|
|
|
ssp.val = -spellCost;
|
|
|
|
ssp.absolute = false;
|
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
|
|
|
server->apply(&ssp);
|
2017-07-04 13:24:46 +02:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|