mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
vcmi: reduce CStack usage a little bit
This commit is contained in:
parent
e946ddcfeb
commit
e0715a76c8
@ -271,7 +271,7 @@ std::vector<const battle::Unit *> BattleExchangeEvaluator::getAdjacentUnits(cons
|
||||
auto hexes = stack->getSurroundingHexes();
|
||||
for(auto hex : hexes)
|
||||
{
|
||||
auto neighbor = cb->battleGetStackByPos(hex);
|
||||
auto neighbor = cb->battleGetUnitByPos(hex);
|
||||
|
||||
if(neighbor && neighbor->unitSide() == stack->unitSide() && !vstd::contains(checkedStacks, neighbor))
|
||||
{
|
||||
|
@ -80,7 +80,7 @@ static bool willSecondHexBlockMoreEnemyShooters(const BattleHex &h1, const Battl
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
for (auto & neighbour : (i ? h2 : h1).neighbouringTiles())
|
||||
if(const CStack * s = cbc->battleGetStackByPos(neighbour))
|
||||
if(const auto * s = cbc->battleGetUnitByPos(neighbour))
|
||||
if(s->isShooter())
|
||||
shooters[i]++;
|
||||
}
|
||||
|
@ -970,13 +970,13 @@ bool EffectAnimation::init()
|
||||
}
|
||||
else
|
||||
{
|
||||
const CStack * destStack = owner.getCurrentPlayerInterface()->cb->battleGetStackByPos(battlehexes[i], false);
|
||||
const auto * destStack = owner.getCurrentPlayerInterface()->cb->battleGetUnitByPos(battlehexes[i], false);
|
||||
Rect tilePos = owner.fieldController->hexPositionLocal(battlehexes[i]);
|
||||
|
||||
be.pos.x = tilePos.x + tilePos.w/2 - first->width()/2;
|
||||
|
||||
if(destStack && destStack->doubleWide()) // Correction for 2-hex creatures.
|
||||
be.pos.x += (destStack->side == BattleSide::ATTACKER ? -1 : 1)*tilePos.w/2;
|
||||
be.pos.x += (destStack->unitSide() == BattleSide::ATTACKER ? -1 : 1)*tilePos.w/2;
|
||||
|
||||
if (alignToBottom())
|
||||
be.pos.y = tilePos.y + tilePos.h - first->height();
|
||||
|
@ -24,7 +24,7 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
///BattleInfo
|
||||
std::pair< std::vector<BattleHex>, int > BattleInfo::getPath(BattleHex start, BattleHex dest, const CStack * stack)
|
||||
std::pair< std::vector<BattleHex>, int > BattleInfo::getPath(BattleHex start, BattleHex dest, const battle::Unit * stack)
|
||||
{
|
||||
auto reachability = getReachability(stack);
|
||||
|
||||
|
@ -130,7 +130,7 @@ public:
|
||||
using CBattleInfoEssentials::battleGetFightingHero;
|
||||
CGHeroInstance * battleGetFightingHero(ui8 side) const;
|
||||
|
||||
std::pair< std::vector<BattleHex>, int > getPath(BattleHex start, BattleHex dest, const CStack * stack); //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
|
||||
std::pair< std::vector<BattleHex>, int > getPath(BattleHex start, BattleHex dest, const battle::Unit * stack); //returned value: pair<path, length>; length may be different than number of elements in path since flying creatures jump between distant hexes
|
||||
|
||||
void calculateCasualties(std::map<ui32,si32> * casualties) const; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)
|
||||
|
||||
|
@ -280,15 +280,15 @@ std::set<BattleHex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* at
|
||||
|
||||
for (BattleHex tile : at.hostileCreaturePositions)
|
||||
{
|
||||
const CStack * st = battleGetStackByPos(tile, true);
|
||||
if(st && st->owner != attacker->owner) //only hostile stacks - does it work well with Berserk?
|
||||
const auto * st = battleGetUnitByPos(tile, true);
|
||||
if(st && st->unitOwner() != attacker->unitOwner()) //only hostile stacks - does it work well with Berserk?
|
||||
{
|
||||
attackedHexes.insert(tile);
|
||||
}
|
||||
}
|
||||
for (BattleHex tile : at.friendlyCreaturePositions)
|
||||
{
|
||||
if(battleGetStackByPos(tile, true)) //friendly stacks can also be damaged by Dragon Breath
|
||||
if(battleGetUnitByPos(tile, true)) //friendly stacks can also be damaged by Dragon Breath
|
||||
{
|
||||
attackedHexes.insert(tile);
|
||||
}
|
||||
|
@ -4815,7 +4815,7 @@ bool CGameHandler::makeBattleAction(BattleAction &ba)
|
||||
if(target.at(0).unitValue)
|
||||
destStack = target.at(0).unitValue;
|
||||
else
|
||||
destStack = gs->curB->battleGetStackByPos(target.at(0).hexValue);
|
||||
destStack = gs->curB->battleGetUnitByPos(target.at(0).hexValue);
|
||||
|
||||
if(healer == nullptr || destStack == nullptr || !healerAbility || healerAbility->subtype < 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user