mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix regressions from battlehex PR (mostly related to towers)
This commit is contained in:
@@ -113,11 +113,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clear() noexcept;
|
void clear() noexcept;
|
||||||
inline void erase(size_type index) noexcept
|
inline void erase(BattleHex target) noexcept
|
||||||
{
|
{
|
||||||
assert(index < totalSize);
|
assert(contains(target));
|
||||||
internalStorage[index] = BattleHex::INVALID;
|
vstd::erase(internalStorage, target);
|
||||||
presenceFlags[index] = 0;
|
presenceFlags[target.toInt()] = 0;
|
||||||
}
|
}
|
||||||
void erase(iterator first, iterator last) noexcept;
|
void erase(iterator first, iterator last) noexcept;
|
||||||
inline void pop_back() noexcept
|
inline void pop_back() noexcept
|
||||||
@@ -160,17 +160,23 @@ public:
|
|||||||
/// get (precomputed) all possible surrounding tiles
|
/// get (precomputed) all possible surrounding tiles
|
||||||
static const BattleHexArray & getAllNeighbouringTiles(BattleHex hex) noexcept
|
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
|
/// get (precomputed) only valid and available surrounding tiles
|
||||||
static const BattleHexArray & getNeighbouringTiles(BattleHex hex) noexcept
|
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
|
/// 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))
|
if(attacker->hasBonusOfType(BonusType::WIDE_BREATH))
|
||||||
{
|
{
|
||||||
BattleHexArray hexes = destinationTile.getNeighbouringTiles();
|
BattleHexArray hexes = destinationTile.getNeighbouringTiles();
|
||||||
for(int i = 0; i < hexes.size(); i++)
|
if (hexes.contains(attackOriginHex))
|
||||||
{
|
hexes.erase(attackOriginHex);
|
||||||
if(hexes.at(i) == attackOriginHex)
|
|
||||||
{
|
|
||||||
hexes.erase(i);
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(BattleHex tile : hexes)
|
for(BattleHex tile : hexes)
|
||||||
{
|
{
|
||||||
//friendly stacks can also be damaged by Dragon Breath
|
//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),
|
precomputeUnitHexes(BattleSide::DEFENDER, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
int index = side == BattleSide::ATTACKER ? 0 : 2;
|
static const std::array<BattleHexArray, 5> invalidHexes = {
|
||||||
return precomputed[index + twoHex][assumedPos.toInt()];
|
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
|
BattleHex Unit::occupiedHex() const
|
||||||
|
|||||||
@@ -223,7 +223,8 @@ EffectTarget UnitEffect::transformTargetByChain(const Mechanics * m, const Targe
|
|||||||
effectTarget.emplace_back();
|
effectTarget.emplace_back();
|
||||||
|
|
||||||
for(auto hex : battle::Unit::getHexes(unit->getPosition(), unit->doubleWide(), unit->unitSide()))
|
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())
|
if(possibleHexes.empty())
|
||||||
break;
|
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