1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

vcmi: split bonus to enumerator and HeroBonus.h

This commit is contained in:
Konstantin
2023-05-01 01:20:01 +03:00
committed by Konstantin P
parent 9f5ee885b4
commit 05eccbc2bb
123 changed files with 1321 additions and 1350 deletions

View File

@@ -126,7 +126,7 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastSpell(con
if(!hero)
return ESpellCastProblem::NO_HERO_TO_CAST_SPELL;
if(hero->hasBonusOfType(Bonus::BLOCK_ALL_MAGIC))
if(hero->hasBonusOfType(BonusType::BLOCK_ALL_MAGIC))
return ESpellCastProblem::MAGIC_IS_BLOCKED;
}
break;
@@ -204,7 +204,7 @@ bool CBattleInfoCallback::battleHasWallPenalty(const IBonusBearer * shooter, Bat
return false;
const std::string cachingStrNoWallPenalty = "type_NO_WALL_PENALTY";
static const auto selectorNoWallPenalty = Selector::type()(Bonus::NO_WALL_PENALTY);
static const auto selectorNoWallPenalty = Selector::type()(BonusType::NO_WALL_PENALTY);
if(shooter->hasBonus(selectorNoWallPenalty, cachingStrNoWallPenalty))
return false;
@@ -227,7 +227,7 @@ std::vector<PossiblePlayerBattleAction> CBattleInfoCallback::getClientActionsFor
{
if(stack->canCast()) //TODO: check for battlefield effects that prevent casting?
{
if(stack->hasBonusOfType(Bonus::SPELLCASTER))
if(stack->hasBonusOfType(BonusType::SPELLCASTER))
{
for(const auto & spellID : data.creatureSpellsToCast)
{
@@ -236,12 +236,12 @@ std::vector<PossiblePlayerBattleAction> CBattleInfoCallback::getClientActionsFor
allowedActionList.push_back(act);
}
}
if(stack->hasBonusOfType(Bonus::RANDOM_SPELLCASTER))
if(stack->hasBonusOfType(BonusType::RANDOM_SPELLCASTER))
allowedActionList.push_back(PossiblePlayerBattleAction::RANDOM_GENIE_SPELL);
}
if(stack->canShoot())
allowedActionList.push_back(PossiblePlayerBattleAction::SHOOT);
if(stack->hasBonusOfType(Bonus::RETURN_AFTER_STRIKE))
if(stack->hasBonusOfType(BonusType::RETURN_AFTER_STRIKE))
allowedActionList.push_back(PossiblePlayerBattleAction::ATTACK_AND_RETURN);
allowedActionList.push_back(PossiblePlayerBattleAction::ATTACK); //all active stacks can attack
@@ -251,9 +251,9 @@ std::vector<PossiblePlayerBattleAction> CBattleInfoCallback::getClientActionsFor
allowedActionList.push_back(PossiblePlayerBattleAction::MOVE_STACK);
const auto * siegedTown = battleGetDefendedTown();
if(siegedTown && siegedTown->hasFort() && stack->hasBonusOfType(Bonus::CATAPULT)) //TODO: check shots
if(siegedTown && siegedTown->hasFort() && stack->hasBonusOfType(BonusType::CATAPULT)) //TODO: check shots
allowedActionList.push_back(PossiblePlayerBattleAction::CATAPULT);
if(stack->hasBonusOfType(Bonus::HEALER))
if(stack->hasBonusOfType(BonusType::HEALER))
allowedActionList.push_back(PossiblePlayerBattleAction::HEAL);
}
@@ -686,10 +686,10 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
return false;
//forgetfulness
TConstBonusListPtr forgetfulList = attacker->getBonuses(Selector::type()(Bonus::FORGETFULL));
TConstBonusListPtr forgetfulList = attacker->getBonuses(Selector::type()(BonusType::FORGETFULL));
if(!forgetfulList->empty())
{
int forgetful = forgetfulList->valOfBonuses(Selector::type()(Bonus::FORGETFULL));
int forgetful = forgetfulList->valOfBonuses(Selector::type()(BonusType::FORGETFULL));
//advanced+ level
if(forgetful > 1)
@@ -697,7 +697,7 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker) const
}
return attacker->canShoot() && (!battleIsUnitBlocked(attacker)
|| attacker->hasBonusOfType(Bonus::FREE_SHOOTING));
|| attacker->hasBonusOfType(BonusType::FREE_SHOOTING));
}
bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker, BattleHex dest) const
@@ -712,7 +712,7 @@ bool CBattleInfoCallback::battleCanShoot(const battle::Unit * attacker, BattleHe
{
if(battleCanShoot(attacker))
{
auto limitedRangeBonus = attacker->getBonus(Selector::type()(Bonus::LIMITED_SHOOTING_RANGE));
auto limitedRangeBonus = attacker->getBonus(Selector::type()(BonusType::LIMITED_SHOOTING_RANGE));
if(limitedRangeBonus == nullptr)
{
return true;
@@ -1239,11 +1239,11 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(const battle:
{
attackOriginHex = attacker->occupiedHex(attackOriginHex); //the other hex stack stands on
}
if(attacker->hasBonusOfType(Bonus::ATTACKS_ALL_ADJACENT))
if(attacker->hasBonusOfType(BonusType::ATTACKS_ALL_ADJACENT))
{
boost::copy(attacker->getSurroundingHexes(attackerPos), vstd::set_inserter(at.hostileCreaturePositions));
}
if(attacker->hasBonusOfType(Bonus::THREE_HEADED_ATTACK))
if(attacker->hasBonusOfType(BonusType::THREE_HEADED_ATTACK))
{
std::vector<BattleHex> hexes = attacker->getSurroundingHexes(attackerPos);
for(BattleHex tile : hexes)
@@ -1256,7 +1256,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(const battle:
}
}
}
if(attacker->hasBonusOfType(Bonus::WIDE_BREATH))
if(attacker->hasBonusOfType(BonusType::WIDE_BREATH))
{
std::vector<BattleHex> hexes = destinationTile.neighbouringTiles();
for(int i = 0; i<hexes.size(); i++)
@@ -1275,7 +1275,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyAttackableHexes(const battle:
at.friendlyCreaturePositions.insert(tile);
}
}
else if(attacker->hasBonusOfType(Bonus::TWO_HEX_ATTACK_BREATH))
else if(attacker->hasBonusOfType(BonusType::TWO_HEX_ATTACK_BREATH))
{
auto direction = BattleHex::mutualPosition(attackOriginHex, destinationTile);
if(direction != BattleHex::NONE) //only adjacent hexes are subject of dragon breath calculation
@@ -1312,7 +1312,7 @@ AttackableTiles CBattleInfoCallback::getPotentiallyShootableHexes(const battle::
AttackableTiles at;
RETURN_IF_NOT_BATTLE(at);
if(attacker->hasBonusOfType(Bonus::SHOOTS_ALL_ADJACENT) && !vstd::contains(attackerPos.neighbouringTiles(), destinationTile))
if(attacker->hasBonusOfType(BonusType::SHOOTS_ALL_ADJACENT) && !vstd::contains(attackerPos.neighbouringTiles(), destinationTile))
{
std::vector<BattleHex> targetHexes = destinationTile.neighbouringTiles();
targetHexes.push_back(destinationTile);
@@ -1448,7 +1448,7 @@ bool CBattleInfoCallback::battleHasDistancePenalty(const IBonusBearer * shooter,
RETURN_IF_NOT_BATTLE(false);
const std::string cachingStrNoDistancePenalty = "type_NO_DISTANCE_PENALTY";
static const auto selectorNoDistancePenalty = Selector::type()(Bonus::NO_DISTANCE_PENALTY);
static const auto selectorNoDistancePenalty = Selector::type()(BonusType::NO_DISTANCE_PENALTY);
if(shooter->hasBonus(selectorNoDistancePenalty, cachingStrNoDistancePenalty))
return false;
@@ -1458,7 +1458,7 @@ bool CBattleInfoCallback::battleHasDistancePenalty(const IBonusBearer * shooter,
//If any hex of target creature is within range, there is no penalty
int range = GameConstants::BATTLE_PENALTY_DISTANCE;
auto bonus = shooter->getBonus(Selector::type()(Bonus::LIMITED_SHOOTING_RANGE));
auto bonus = shooter->getBonus(Selector::type()(BonusType::LIMITED_SHOOTING_RANGE));
if(bonus != nullptr && bonus->additionalInfo != CAddInfo::NONE)
range = bonus->additionalInfo[0];
@@ -1542,13 +1542,13 @@ int32_t CBattleInfoCallback::battleGetSpellCost(const spells::Spell * sp, const
for(const auto * unit : battleAliveUnits())
{
if(unit->unitOwner() == caster->tempOwner && unit->hasBonusOfType(Bonus::CHANGES_SPELL_COST_FOR_ALLY))
if(unit->unitOwner() == caster->tempOwner && unit->hasBonusOfType(BonusType::CHANGES_SPELL_COST_FOR_ALLY))
{
vstd::amax(manaReduction, unit->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ALLY));
vstd::amax(manaReduction, unit->valOfBonuses(BonusType::CHANGES_SPELL_COST_FOR_ALLY));
}
if(unit->unitOwner() != caster->tempOwner && unit->hasBonusOfType(Bonus::CHANGES_SPELL_COST_FOR_ENEMY))
if(unit->unitOwner() != caster->tempOwner && unit->hasBonusOfType(BonusType::CHANGES_SPELL_COST_FOR_ENEMY))
{
vstd::amax(manaIncrease, unit->valOfBonuses(Bonus::CHANGES_SPELL_COST_FOR_ENEMY));
vstd::amax(manaIncrease, unit->valOfBonuses(BonusType::CHANGES_SPELL_COST_FOR_ENEMY));
}
}
@@ -1564,7 +1564,7 @@ bool CBattleInfoCallback::battleIsUnitBlocked(const battle::Unit * unit) const
{
RETURN_IF_NOT_BATTLE(false);
if(unit->hasBonusOfType(Bonus::SIEGE_WEAPON)) //siege weapons cannot be blocked
if(unit->hasBonusOfType(BonusType::SIEGE_WEAPON)) //siege weapons cannot be blocked
return false;
for(const auto * adjacent : battleAdjacentUnits(unit))
@@ -1635,9 +1635,9 @@ SpellID CBattleInfoCallback::getRandomBeneficialSpell(CRandomGenerator & rand, c
for(const SpellID& spellID : allPossibleSpells)
{
std::stringstream cachingStr;
cachingStr << "source_" << Bonus::SPELL_EFFECT << "id_" << spellID.num;
cachingStr << "source_" << vstd::to_underlying(BonusSource::SPELL_EFFECT) << "id_" << spellID.num;
if(subject->hasBonus(Selector::source(Bonus::SPELL_EFFECT, spellID), Selector::all, cachingStr.str())
if(subject->hasBonus(Selector::source(BonusSource::SPELL_EFFECT, spellID), Selector::all, cachingStr.str())
//TODO: this ability has special limitations
|| !(spellID.toSpell()->canBeCast(this, spells::Mode::CREATURE_ACTIVE, subject)))
continue;
@@ -1702,7 +1702,7 @@ SpellID CBattleInfoCallback::getRandomBeneficialSpell(CRandomGenerator & rand, c
{
const auto * kingMonster = getAliveEnemy([&](const CStack * stack) -> bool //look for enemy, non-shooting stack
{
const auto isKing = Selector::type()(Bonus::KING);
const auto isKing = Selector::type()(BonusType::KING);
return stack->hasBonus(isKing);
});
@@ -1729,7 +1729,7 @@ SpellID CBattleInfoCallback::getRandomCastedSpell(CRandomGenerator & rand,const
{
RETURN_IF_NOT_BATTLE(SpellID::NONE);
TConstBonusListPtr bl = caster->getBonuses(Selector::type()(Bonus::SPELLCASTER));
TConstBonusListPtr bl = caster->getBonuses(Selector::type()(BonusType::SPELLCASTER));
if (!bl->size())
return SpellID::NONE;
int totalWeight = 0;
@@ -1772,7 +1772,7 @@ int CBattleInfoCallback::battleGetSurrenderCost(const PlayerColor & Player) cons
ret += unit->getRawSurrenderCost();
if(const CGHeroInstance * h = battleGetFightingHero(side))
discount += h->valOfBonuses(Bonus::SURRENDER_DISCOUNT);
discount += h->valOfBonuses(BonusType::SURRENDER_DISCOUNT);
ret = static_cast<int>(ret * (100.0 - discount) / 100.0);
vstd::amax(ret, 0); //no negative costs for >100% discounts (impossible in original H3 mechanics, but some day...)
@@ -1790,7 +1790,7 @@ si8 CBattleInfoCallback::battleMinSpellLevel(ui8 side) const
if(!node)
return 0;
auto b = node->getBonuses(Selector::type()(Bonus::BLOCK_MAGIC_BELOW));
auto b = node->getBonuses(Selector::type()(BonusType::BLOCK_MAGIC_BELOW));
if(b->size())
return b->totalValue();
@@ -1809,7 +1809,7 @@ si8 CBattleInfoCallback::battleMaxSpellLevel(ui8 side) const
return GameConstants::SPELL_LEVELS;
//We can't "just get value" - it'd be 0 if there are bonuses (and all would be blocked)
auto b = node->getBonuses(Selector::type()(Bonus::BLOCK_MAGIC_ABOVE));
auto b = node->getBonuses(Selector::type()(BonusType::BLOCK_MAGIC_ABOVE));
if(b->size())
return b->totalValue();
@@ -1820,7 +1820,7 @@ std::optional<int> CBattleInfoCallback::battleIsFinished() const
{
auto units = battleGetUnitsIf([=](const battle::Unit * unit)
{
return unit->alive() && !unit->isTurret() && !unit->hasBonusOfType(Bonus::SIEGE_WEAPON);
return unit->alive() && !unit->isTurret() && !unit->hasBonusOfType(BonusType::SIEGE_WEAPON);
});
std::array<bool, 2> hasUnit = {false, false}; //index is BattleSide