1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

vcmi: camelCase methods of new classes

Also use EGameSettings for clamping morale and luck
This commit is contained in:
Konstantin 2023-05-02 01:05:59 +03:00 committed by Konstantin P
parent a6de9097be
commit fbc05c70ac
14 changed files with 46 additions and 39 deletions

View File

@ -214,7 +214,7 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
bestAttack.attackerState->unitType()->getJsonKey(),
bestAttack.affectedUnits[0]->unitType()->getJsonKey(),
(int)bestAttack.affectedUnits[0]->getCount(), action, (int)bestAttack.from, (int)bestAttack.attack.attacker->getPosition().hex,
bestAttack.attack.chargeDistance, bestAttack.attack.attacker->Speed(0, true),
bestAttack.attack.chargeDistance, bestAttack.attack.attacker->speed(0, true),
bestAttack.defenderDamageReduce, bestAttack.attackerDamageReduce, bestAttack.attackValue()
);
}

View File

@ -205,7 +205,7 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable(const battle::Uni
if(targets.unreachableEnemies.empty())
return result;
auto speed = activeStack->Speed();
auto speed = activeStack->speed();
if(speed == 0)
return result;
@ -607,7 +607,7 @@ void BattleExchangeEvaluator::updateReachabilityMap(HypotheticBattle & hb)
for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1)
{
bool reachable = unitReachability.distances[hex] <= unit->Speed(turn);
bool reachable = unitReachability.distances[hex] <= unit->speed(turn);
if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK)
{
@ -617,7 +617,7 @@ void BattleExchangeEvaluator::updateReachabilityMap(HypotheticBattle & hb)
{
for(BattleHex neighbor : hex.neighbouringTiles())
{
reachable = unitReachability.distances[neighbor] <= unit->Speed(turn);
reachable = unitReachability.distances[neighbor] <= unit->speed(turn);
if(reachable) break;
}
@ -665,7 +665,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1)
{
bool enemyUnit = false;
bool reachable = unitReachability.distances[hex] <= unit->Speed(turn);
bool reachable = unitReachability.distances[hex] <= unit->speed(turn);
if(!reachable && unitReachability.accessibility[hex] == EAccessibility::ALIVE_STACK)
{
@ -677,7 +677,7 @@ bool BattleExchangeEvaluator::checkPositionBlocksOurStacks(HypotheticBattle & hb
for(BattleHex neighbor : hex.neighbouringTiles())
{
reachable = unitReachability.distances[neighbor] <= unit->Speed(turn);
reachable = unitReachability.distances[neighbor] <= unit->speed(turn);
if(reachable) break;
}

View File

@ -77,7 +77,7 @@ std::vector<SlotInfo>::iterator ArmyManager::getWeakestCreature(std::vector<Slot
if(left.creature->getLevel() != right.creature->getLevel())
return left.creature->getLevel() < right.creature->getLevel();
return left.creature->Speed() > right.creature->Speed();
return left.creature->speed() > right.creature->speed();
});
return weakest;
@ -150,7 +150,7 @@ std::vector<SlotInfo> ArmyManager::getBestArmy(const IBonusBearer * armyCarrier,
for(auto & slot : newArmyInstance.Slots())
{
auto morale = slot.second->MoraleVal();
auto morale = slot.second->moraleVal();
auto multiplier = 1.0f;
const float BadMoraleChance = 0.083f;

View File

@ -63,7 +63,7 @@ std::vector<SlotInfo>::iterator ArmyManager::getWeakestCreature(std::vector<Slot
if(left.creature->getLevel() != right.creature->getLevel())
return left.creature->getLevel() < right.creature->getLevel();
return left.creature->Speed() > right.creature->Speed();
return left.creature->speed() > right.creature->speed();
});
return weakest;

View File

@ -529,7 +529,7 @@ bool BattleActionsController::actionIsLegal(PossiblePlayerBattleAction action, B
switch (action.get())
{
case PossiblePlayerBattleAction::CHOOSE_TACTICS_STACK:
return (targetStack && targetStackOwned && targetStack->Speed() > 0);
return (targetStack && targetStackOwned && targetStack->speed() > 0);
case PossiblePlayerBattleAction::CREATURE_INFO:
return (targetStack && targetStackOwned && targetStack->alive());

View File

@ -636,7 +636,7 @@ void BattleInterface::tacticPhaseEnd()
static bool immobile(const CStack *s)
{
return !s->Speed(0, true); //should bound stacks be immobile?
return !s->speed(0, true); //should bound stacks be immobile?
}
void BattleInterface::tacticNextStack(const CStack * current)

View File

@ -385,7 +385,7 @@ void MoraleLuckBox::set(const AFactionMember * node)
bonusValue = 0;
if(node)
bonusValue = morale ? node->MoraleValAndBonusList(modifierList) : node->LuckValAndBonusList(modifierList);
bonusValue = morale ? node->moraleValAndBonusList(modifierList) : node->luckValAndBonusList(modifierList);
int mrlt = (bonusValue>0)-(bonusValue<0); //signum: -1 - bad luck / morale, 0 - neutral, 1 - good
hoverText = CGI->generaltexth->heroscrn[hoverTextBase[morale] - mrlt];

View File

@ -526,7 +526,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(battleStack->isShooter()), battleStack->getDefense(battleStack->isShooter()));
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(battleStack->isShooter()) * dmgMultiply, battleStack->getMaxDamage(battleStack->isShooter()) * dmgMultiply);
addStatLabel(EStat::HEALTH, parent->info->creature->getMaxHealth(), battleStack->getMaxHealth());
addStatLabel(EStat::SPEED, parent->info->creature->Speed(), battleStack->Speed());
addStatLabel(EStat::SPEED, parent->info->creature->speed(), battleStack->speed());
if(battleStack->isShooter())
addStatLabel(EStat::SHOTS, battleStack->shots.total(), battleStack->shots.available());
@ -546,7 +546,7 @@ CStackWindow::MainSection::MainSection(CStackWindow * owner, int yOffset, bool s
addStatLabel(EStat::DEFENCE, parent->info->creature->getDefense(shooter), parent->info->stackNode->getDefense(shooter));
addStatLabel(EStat::DAMAGE, parent->info->stackNode->getMinDamage(shooter) * dmgMultiply, parent->info->stackNode->getMaxDamage(shooter) * dmgMultiply);
addStatLabel(EStat::HEALTH, parent->info->creature->getMaxHealth(), parent->info->stackNode->getMaxHealth());
addStatLabel(EStat::SPEED, parent->info->creature->Speed(), parent->info->stackNode->Speed());
addStatLabel(EStat::SPEED, parent->info->creature->speed(), parent->info->stackNode->speed());
if(shooter)
addStatLabel(EStat::SHOTS, parent->info->stackNode->valOfBonuses(Bonus::SHOTS));

View File

@ -23,7 +23,7 @@ class DLL_LINKAGE ACreature: public AFactionMember
{
public:
bool isLiving() const; //non-undead, non-non living or alive
ui32 Speed(int turn = 0, bool useBind = false) const; //get speed (in moving tiles) of creature with all modificators
ui32 speed(int turn = 0, bool useBind = false) const; //get speed (in moving tiles) of creature with all modificators
virtual ui32 getMaxHealth() const; //get max HP of stack with all modifiers
};

View File

@ -54,21 +54,21 @@ public:
int getPrimSkillLevel(PrimarySkill::PrimarySkill id) const;
/**
Returns morale of creature or hero. Taking absolute bonuses into account.
For now, uses range [-3, +3]
For now, uses range from EGameSettings
*/
int MoraleVal() const;
int moraleVal() const;
/**
Returns luck of creature or hero. Taking absolute bonuses into account.
For now, uses range [-3, +3]
For now, uses range from EGameSettings
*/
int LuckVal() const;
int luckVal() const;
/**
Returns total value of all morale bonuses and sets bonusList as a pointer to the list of selected bonuses.
@param bonusList is the out param it's list of all selected bonuses
@return total value of all morale in the range [-3, +3] and 0 otherwise
@return total value of all morale in the range from EGameSettings and 0 otherwise
*/
int MoraleValAndBonusList(std::shared_ptr<const BonusList> & bonusList) const;
int LuckValAndBonusList(std::shared_ptr<const BonusList> & bonusList) const;
int moraleValAndBonusList(std::shared_ptr<const BonusList> & bonusList) const;
int luckValAndBonusList(std::shared_ptr<const BonusList> & bonusList) const;
};
VCMI_LIB_NAMESPACE_END

View File

@ -12,6 +12,7 @@
#include "VCMI_Lib.h"
#include "GameConstants.h"
#include "GameSettings.h"
#include "bonuses/BonusList.h"
#include "bonuses/Bonus.h"
#include "bonuses/IBonusBearer.h"
@ -90,7 +91,7 @@ int AFactionMember::getPrimSkillLevel(PrimarySkill::PrimarySkill id) const
return std::max(ret, minSkillValue); //otherwise, some artifacts may cause negative skill value effect, sp=0 works in old saves
}
int AFactionMember::MoraleValAndBonusList(TConstBonusListPtr & bonusList) const
int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const
{
static const auto unaffectedByMoraleSelector = Selector::type()(Bonus::NON_LIVING).Or(Selector::type()(Bonus::UNDEAD))
.Or(Selector::type()(Bonus::SIEGE_WEAPON)).Or(Selector::type()(Bonus::NO_MORALE));
@ -108,10 +109,13 @@ int AFactionMember::MoraleValAndBonusList(TConstBonusListPtr & bonusList) const
static const std::string cachingStrMor = "type_MORALE";
bonusList = getBonusBearer()->getBonuses(moraleSelector, cachingStrMor);
return std::clamp(bonusList->totalValue(), -3, +3);
int32_t maxGoodMorale = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE).size();
int32_t maxBadMorale = -VLC->settings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE).size();
return std::clamp(bonusList->totalValue(), maxBadMorale, maxGoodMorale);
}
int AFactionMember::LuckValAndBonusList(TConstBonusListPtr & bonusList) const
int AFactionMember::luckValAndBonusList(TConstBonusListPtr & bonusList) const
{
if(getBonusBearer()->hasBonusOfType(Bonus::NO_LUCK))
{
@ -124,19 +128,22 @@ int AFactionMember::LuckValAndBonusList(TConstBonusListPtr & bonusList) const
static const std::string cachingStrLuck = "type_LUCK";
bonusList = getBonusBearer()->getBonuses(luckSelector, cachingStrLuck);
return std::clamp(bonusList->totalValue(), -3, +3);
int32_t maxGoodLuck = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE).size();
int32_t maxBadLuck = -VLC->settings()->getVector(EGameSettings::COMBAT_BAD_LUCK_DICE).size();
return std::clamp(bonusList->totalValue(), maxBadLuck, maxGoodLuck);
}
int AFactionMember::MoraleVal() const
int AFactionMember::moraleVal() const
{
TConstBonusListPtr tmp = nullptr;
return MoraleValAndBonusList(tmp);
return moraleValAndBonusList(tmp);
}
int AFactionMember::LuckVal() const
int AFactionMember::luckVal() const
{
TConstBonusListPtr tmp = nullptr;
return LuckValAndBonusList(tmp);
return luckValAndBonusList(tmp);
}
ui32 ACreature::getMaxHealth() const
@ -147,7 +154,7 @@ ui32 ACreature::getMaxHealth() const
return std::max(1, value); //never 0
}
ui32 ACreature::Speed(int turn, bool useBind) const
ui32 ACreature::speed(int turn, bool useBind) const
{
//war machines cannot move
if(getBonusBearer()->hasBonus(Selector::type()(Bonus::SIEGE_WEAPON).And(Selector::turns(turn))))

View File

@ -3089,8 +3089,8 @@ void InfoAboutHero::initFromHero(const CGHeroInstance *h, InfoAboutHero::EInfoLe
{
//include details about hero
details = new Details();
details->luck = h->LuckVal();
details->morale = h->MoraleVal();
details->luck = h->luckVal();
details->morale = h->moraleVal();
details->mana = h->mana;
details->primskills.resize(GameConstants::PRIMARY_SKILLS);

View File

@ -247,7 +247,7 @@ std::vector<PossiblePlayerBattleAction> CBattleInfoCallback::getClientActionsFor
allowedActionList.push_back(PossiblePlayerBattleAction::ATTACK); //all active stacks can attack
allowedActionList.push_back(PossiblePlayerBattleAction::WALK_AND_ATTACK); //not all stacks can always walk, but we will check this elsewhere
if(stack->canMove() && stack->Speed(0, true)) //probably no reason to try move war machines or bound stacks
if(stack->canMove() && stack->speed(0, true)) //probably no reason to try move war machines or bound stacks
allowedActionList.push_back(PossiblePlayerBattleAction::MOVE_STACK);
const auto * siegedTown = battleGetDefendedTown();
@ -566,7 +566,7 @@ std::vector<BattleHex> CBattleInfoCallback::battleGetAvailableHexes(const Reacha
if(!unit->getPosition().isValid()) //turrets
return ret;
auto unitSpeed = unit->Speed(0, true);
auto unitSpeed = unit->speed(0, true);
const bool tacticsPhase = battleTacticDist() && battleGetTacticsSide() == unit->unitSide();

View File

@ -926,7 +926,7 @@ void CGameHandler::makeAttack(const CStack * attacker, const CStack * defender,
if(counter)
bat.flags |= BattleAttack::COUNTER;
const int attackerLuck = attacker->LuckVal();
const int attackerLuck = attacker->luckVal();
if(attackerLuck > 0)
{
@ -1334,7 +1334,7 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
ret = path.second;
int creSpeed = curStack->Speed(0, true);
int creSpeed = curStack->speed(0, true);
if (gs->curB->tacticDistance > 0 && creSpeed > 0)
creSpeed = GameConstants::BFIELD_SIZE;
@ -6518,7 +6518,7 @@ void CGameHandler::runBattle()
sendAndApply(&removeGhosts);
// check for bad morale => freeze
int nextStackMorale = next->MoraleVal();
int nextStackMorale = next->moraleVal();
if(!next->hadMorale && !next->waited() && nextStackMorale < 0)
{
auto diceSize = VLC->settings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE);
@ -6704,7 +6704,7 @@ void CGameHandler::runBattle()
if(next != nullptr)
{
//check for good morale
nextStackMorale = next->MoraleVal();
nextStackMorale = next->moraleVal();
if( !battleResult.get()
&& !next->hadMorale
&& !next->defending