mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Fix regressions from battlehex PR (mostly related to towers)
This commit is contained in:
@@ -113,11 +113,11 @@ public:
|
||||
}
|
||||
|
||||
void clear() noexcept;
|
||||
inline void erase(size_type index) noexcept
|
||||
inline void erase(BattleHex target) noexcept
|
||||
{
|
||||
assert(index < totalSize);
|
||||
internalStorage[index] = BattleHex::INVALID;
|
||||
presenceFlags[index] = 0;
|
||||
assert(contains(target));
|
||||
vstd::erase(internalStorage, target);
|
||||
presenceFlags[target.toInt()] = 0;
|
||||
}
|
||||
void erase(iterator first, iterator last) noexcept;
|
||||
inline void pop_back() noexcept
|
||||
@@ -160,17 +160,23 @@ public:
|
||||
/// get (precomputed) all possible surrounding tiles
|
||||
static const BattleHexArray & getAllNeighbouringTiles(BattleHex hex) noexcept
|
||||
{
|
||||
assert(hex.isValid());
|
||||
static const BattleHexArray invalid;
|
||||
|
||||
return allNeighbouringTiles[hex.toInt()];
|
||||
if (hex.isValid())
|
||||
return allNeighbouringTiles[hex.toInt()];
|
||||
else
|
||||
return invalid;
|
||||
}
|
||||
|
||||
/// get (precomputed) only valid and available surrounding tiles
|
||||
static const BattleHexArray & getNeighbouringTiles(BattleHex hex) noexcept
|
||||
{
|
||||
assert(hex.isValid());
|
||||
static const BattleHexArray invalid;
|
||||
|
||||
return neighbouringTiles[hex.toInt()];
|
||||
if (hex.isValid())
|
||||
return neighbouringTiles[hex.toInt()];
|
||||
else
|
||||
return invalid;
|
||||
}
|
||||
|
||||
/// get (precomputed) only valid and available surrounding tiles for double wide creatures
|
||||
|
@@ -1353,14 +1353,9 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(
|
||||
if(attacker->hasBonusOfType(BonusType::WIDE_BREATH))
|
||||
{
|
||||
BattleHexArray hexes = destinationTile.getNeighbouringTiles();
|
||||
for(int i = 0; i < hexes.size(); i++)
|
||||
{
|
||||
if(hexes.at(i) == attackOriginHex)
|
||||
{
|
||||
hexes.erase(i);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (hexes.contains(attackOriginHex))
|
||||
hexes.erase(attackOriginHex);
|
||||
|
||||
for(BattleHex tile : hexes)
|
||||
{
|
||||
//friendly stacks can also be damaged by Dragon Breath
|
||||
|
@@ -134,8 +134,24 @@ const BattleHexArray & Unit::getHexes(BattleHex assumedPos, bool twoHex, BattleS
|
||||
precomputeUnitHexes(BattleSide::DEFENDER, true),
|
||||
};
|
||||
|
||||
int index = side == BattleSide::ATTACKER ? 0 : 2;
|
||||
return precomputed[index + twoHex][assumedPos.toInt()];
|
||||
static const std::array<BattleHexArray, 5> invalidHexes = {
|
||||
BattleHexArray({BattleHex( 0)}),
|
||||
BattleHexArray({BattleHex(-1)}),
|
||||
BattleHexArray({BattleHex(-2)}),
|
||||
BattleHexArray({BattleHex(-3)}),
|
||||
BattleHexArray({BattleHex(-4)})
|
||||
};
|
||||
|
||||
if (assumedPos.isValid())
|
||||
{
|
||||
int index = side == BattleSide::ATTACKER ? 0 : 2;
|
||||
return precomputed[index + twoHex][assumedPos.toInt()];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Towers and such
|
||||
return invalidHexes.at(-assumedPos.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
BattleHex Unit::occupiedHex() const
|
||||
|
@@ -223,7 +223,8 @@ EffectTarget UnitEffect::transformTargetByChain(const Mechanics * m, const Targe
|
||||
effectTarget.emplace_back();
|
||||
|
||||
for(auto hex : battle::Unit::getHexes(unit->getPosition(), unit->doubleWide(), unit->unitSide()))
|
||||
possibleHexes.erase(hex.toInt());
|
||||
if (possibleHexes.contains(hex))
|
||||
possibleHexes.erase(hex);
|
||||
|
||||
if(possibleHexes.empty())
|
||||
break;
|
||||
@@ -278,4 +279,4 @@ void UnitEffect::serializeJsonEffect(JsonSerializeFormat & handler)
|
||||
}
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user