1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Minor changes with BattleHex and BattleHexArray

This commit is contained in:
MichalZr6 2025-01-12 17:15:25 +01:00
parent e26fe815e9
commit 8f63a82d60
8 changed files with 31 additions and 17 deletions

View File

@ -489,7 +489,7 @@ AttackPossibility AttackPossibility::evaluate(
logAi->trace("BattleAI AP: %s -> %s at %d from %d, affects %d units: d:%lld a:%lld c:%lld s:%lld",
attackInfo.attacker->unitType()->getJsonKey(),
attackInfo.defender->unitType()->getJsonKey(),
(int)ap.dest, (int)ap.from, (int)ap.affectedUnits.size(),
ap.dest.toInt(), ap.from.toInt(), (int)ap.affectedUnits.size(),
ap.defenderDamageReduce, ap.attackerDamageReduce, ap.collateralDamageReduce, ap.shootersBlockedDmg);
#endif
@ -504,7 +504,7 @@ AttackPossibility AttackPossibility::evaluate(
logAi->trace("BattleAI best AP: %s -> %s at %d from %d, affects %d units: d:%lld a:%lld c:%lld s:%lld",
attackInfo.attacker->unitType()->getJsonKey(),
attackInfo.defender->unitType()->getJsonKey(),
(int)bestAp.dest, (int)bestAp.from, (int)bestAp.affectedUnits.size(),
bestAp.dest.toInt(), bestAp.from.toInt(), (int)bestAp.affectedUnits.size(),
bestAp.defenderDamageReduce, bestAp.attackerDamageReduce, bestAp.collateralDamageReduce, bestAp.shootersBlockedDmg);
#endif

View File

@ -54,8 +54,8 @@ void logHexNumbers()
#if BATTLE_TRACE_LEVEL >= 1
logVisual->updateWithLock("hexes", [](IVisualLogBuilder & b)
{
for(BattleHex hex = BattleHex(0); hex < GameConstants::BFIELD_SIZE; hex = BattleHex(hex + 1))
b.addText(hex, std::to_string(hex.hex));
for(BattleHex hex = BattleHex(0); hex < GameConstants::BFIELD_SIZE; ++hex)
b.addText(hex, std::to_string(hex.toInt()));
});
#endif
}

View File

@ -687,7 +687,7 @@ bool BattleEvaluator::attemptCastingSpell(const CStack * activeStack)
else
{
auto psFirst = ps.dest.front();
auto strWhere = psFirst.unitValue ? psFirst.unitValue->getDescription() : std::to_string(psFirst.hexValue.hex);
auto strWhere = psFirst.unitValue ? psFirst.unitValue->getDescription() : std::to_string(psFirst.hexValue.toInt());
logAi->trace("Evaluating %s at %s", ps.spell->getNameTranslated(), strWhere);
}
@ -805,7 +805,7 @@ bool BattleEvaluator::attemptCastingSpell(const CStack * activeStack)
logAi->trace(
"Spell %s to %d affects %s (%d), dps: %2f oldHealth: %d newHealth: %d",
ps.spell->getNameTranslated(),
ps.dest.at(0).hexValue.hex, // Safe to access .at(0) now
ps.dest.at(0).hexValue.toInt(), // Safe to access .at(0) now
unit->creatureId().toCreature()->getNameSingularTranslated(),
unit->getCount(),
dpsReduce,

View File

@ -427,7 +427,7 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable(
if(defenderToBypass)
{
#if BATTLE_TRACE_LEVEL >= 1
logAi->trace("Found target to bypass at %d", enemyHex.hex);
logAi->trace("Found target to bypass at %d", enemyHex.toInt());
#endif
auto attackHex = dists.predecessors[enemyHex.toInt()];
@ -639,7 +639,7 @@ BattleScore BattleExchangeEvaluator::calculateExchange(
battle::Units additionalUnits) const
{
#if BATTLE_TRACE_LEVEL>=1
logAi->trace("Battle exchange at %d", ap.attack.shooting ? ap.dest.hex : ap.from.hex);
logAi->trace("Battle exchange at %d", ap.attack.shooting ? ap.dest.toInt() : ap.from.toInt());
#endif
if(cb->battleGetMySide() == BattleSide::LEFT_SIDE
@ -1063,7 +1063,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
}
#if BATTLE_TRACE_LEVEL>=1
logAi->trace("Position %d, blocking score %f", position.hex, blockingScore);
logAi->trace("Position %d, blocking score %f", position.toInt(), blockingScore);
#endif
return blockingScore > BLOCKING_THRESHOLD;

View File

@ -167,7 +167,7 @@ std::string CStack::nodeName() const
oss << owner.toString();
oss << " battle stack [" << ID << "]: " << getCount() << " of ";
if(typeID.hasValue())
oss << typeID.toEntity(VLC)->getNamePluralTextID();
oss << typeID.toCreature()->getNamePluralTranslated();
else
oss << "[UNDEFINED TYPE]";

View File

@ -65,7 +65,7 @@ const BattleHexArray & BattleHex::getNeighbouringTilesDoubleWide(BattleSide side
std::ostream & operator<<(std::ostream & os, const BattleHex & hex)
{
return os << boost::str(boost::format("{BattleHex: x '%d', y '%d', hex '%d'}") % hex.getX() % hex.getY() % hex.toInt());
return os << hex.toInt();
}
VCMI_LIB_NAMESPACE_END

View File

@ -94,6 +94,11 @@ public:
return isValid() && getX() > 0 && getX() < GameConstants::BFIELD_WIDTH - 1;
}
[[nodiscard]] inline bool isTower() const noexcept
{
return hex == BattleHex::CASTLE_CENTRAL_TOWER || hex == BattleHex::CASTLE_UPPER_TOWER || hex == BattleHex::CASTLE_BOTTOM_TOWER;
}
void setX(si16 x)
{
setXY(x, getY());

View File

@ -131,6 +131,20 @@ public:
return std::vector<BattleHex>(internalStorage.begin(), internalStorage.end());
}
[[nodiscard]] std::string toString(std::string delimiter = ", ") const noexcept
{
std::string result = "[";
for(auto it = internalStorage.begin(); it != internalStorage.end(); ++it)
{
if(it != internalStorage.begin())
result += delimiter;
result += std::to_string(it->toInt());
}
result += "]";
return result;
}
template <typename Predicate>
iterator findIf(Predicate predicate) noexcept
{
@ -295,7 +309,7 @@ private:
[[nodiscard]] inline bool isNotValidForInsertion(BattleHex hex) const
{
if(isTower(hex))
if(hex.isTower())
return true;
if(!hex.isValid())
{
@ -306,11 +320,6 @@ private:
return contains(hex) || internalStorage.size() >= totalSize;
}
[[nodiscard]] inline bool isTower(BattleHex hex) const
{
return hex == BattleHex::CASTLE_CENTRAL_TOWER || hex == BattleHex::CASTLE_UPPER_TOWER || hex == BattleHex::CASTLE_BOTTOM_TOWER;
}
static const ArrayOfBattleHexArrays neighbouringTiles;
static const ArrayOfBattleHexArrays allNeighbouringTiles;
static const std::map<BattleSide, ArrayOfBattleHexArrays> neighbouringTilesDoubleWide;