1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-10 22:31:40 +02:00

Fix sonar & json

This commit is contained in:
Ivan Savenko
2025-05-19 21:07:28 +03:00
parent cc5f47a085
commit a6cf671a68
4 changed files with 19 additions and 24 deletions

View File

@@ -347,7 +347,7 @@
// So matter what value is used for bias, actual probability for large (1000+) number of rolls is same as stated in description
// However, non-zero bias allows to prevent long streaks of "bad" rolls, and enforce actual probabilities even for small (10-20) number of rolls
// Recommended value is ~10-25. Excessively large values, like 100 can make rolls very predictable, for example rolling 20% ability every 5th roll
"abilityBias" : 25
"abilityBias" : 25,
// defines dice chance and dice size of a morale roll, based on creature's morale.
// Resulting chance is chanceValue / diceSize. If list contains 0 values, option will be disabled
@@ -356,7 +356,7 @@
"moraleDiceSize" : 24,
// Bias for morale rolls. See abilityBias for detailed description
// Recommended value is around moraleDiceSize / 4
"moraleBias" : 8
"moraleBias" : 8,
// defines dice chance and dice size of a luck roll, based on creature's luck
"goodLuckChance" : [ 1, 2, 3 ],
@@ -364,7 +364,7 @@
"luckDiceSize" : 24,
// Bias for luck rolls. See abilityBias for detailed description
// Recommended value is around luckDiceSize / 4
"luckBias" : 8
"luckBias" : 8,
// every 1 attack point damage influence in battle when attack points > defense points during creature attack

View File

@@ -61,21 +61,21 @@ GameRandomizer::GameRandomizer(const IGameInfoCallback & gameInfo)
GameRandomizer::~GameRandomizer() = default;
bool GameRandomizer::rollMoraleLuck(std::map<ObjectInstanceID, RandomGeneratorWithBias> & seeds, ObjectInstanceID actor, int moraleLuckValue, EGameSettings biasValueSetting, EGameSettings diceSize, EGameSettings diceWeights)
bool GameRandomizer::rollMoraleLuck(std::map<ObjectInstanceID, RandomGeneratorWithBias> & seeds, ObjectInstanceID actor, int moraleLuckValue, EGameSettings biasValueSetting, EGameSettings diceSizeSetting, EGameSettings chanceVectorSetting)
{
assert(moraleLuckValue > 0);
auto goodLuckChanceVector = gameInfo.getSettings().getVector(diceWeights);
int luckDiceSize = gameInfo.getSettings().getInteger(diceSize);
auto chanceVector = gameInfo.getSettings().getVector(chanceVectorSetting);
int diceSize = gameInfo.getSettings().getInteger(diceSizeSetting);
int biasValue = gameInfo.getSettings().getInteger(biasValueSetting);
size_t chanceIndex = std::min<size_t>(goodLuckChanceVector.size(), moraleLuckValue) - 1; // array index, so 0-indexed
size_t chanceIndex = std::min<size_t>(chanceVector.size(), moraleLuckValue) - 1; // array index, so 0-indexed
if(!seeds.count(actor))
seeds.emplace(actor, getDefault().nextInt());
seeds.try_emplace(actor, getDefault().nextInt());
if(goodLuckChanceVector.size() == 0)
if(chanceVector.empty())
return false;
return seeds.at(actor).roll(goodLuckChanceVector[chanceIndex], luckDiceSize, biasValue);
return seeds.at(actor).roll(chanceVector[chanceIndex], diceSize, biasValue);
}
bool GameRandomizer::rollGoodMorale(ObjectInstanceID actor, int moraleValue)
@@ -101,7 +101,7 @@ bool GameRandomizer::rollBadLuck(ObjectInstanceID actor, int luckValue)
bool GameRandomizer::rollCombatAbility(ObjectInstanceID actor, int percentageChance)
{
if(!combatAbilitySeed.count(actor))
combatAbilitySeed.emplace(actor, getDefault().nextInt());
combatAbilitySeed.try_emplace(actor, getDefault().nextInt());
if(percentageChance <= 0)
return false;
@@ -242,7 +242,7 @@ void GameRandomizer::setSeed(int newSeed)
PrimarySkill GameRandomizer::rollPrimarySkillForLevelup(const CGHeroInstance * hero)
{
if(!heroSkillSeed.count(hero->getHeroTypeID()))
heroSkillSeed.emplace(hero->getHeroTypeID(), getDefault().nextInt());
heroSkillSeed.try_emplace(hero->getHeroTypeID(), getDefault().nextInt());
const bool isLowLevelHero = hero->level < GameConstants::HERO_HIGH_LEVEL;
const auto & skillChances = isLowLevelHero ? hero->getHeroClass()->primarySkillLowLevel : hero->getHeroClass()->primarySkillHighLevel;
@@ -260,7 +260,7 @@ PrimarySkill GameRandomizer::rollPrimarySkillForLevelup(const CGHeroInstance * h
SecondarySkill GameRandomizer::rollSecondarySkillForLevelup(const CGHeroInstance * hero, const std::set<SecondarySkill> & options)
{
if(!heroSkillSeed.count(hero->getHeroTypeID()))
heroSkillSeed.emplace(hero->getHeroTypeID(), getDefault().nextInt());
heroSkillSeed.try_emplace(hero->getHeroTypeID(), getDefault().nextInt());
auto & heroRng = heroSkillSeed.at(hero->getHeroTypeID());
@@ -276,9 +276,9 @@ SecondarySkill GameRandomizer::rollSecondarySkillForLevelup(const CGHeroInstance
auto intersect = [](const std::set<SecondarySkill> & left, const std::set<SecondarySkill> & right)
{
std::set<SecondarySkill> intersect;
std::set_intersection(left.begin(), left.end(), right.begin(), right.end(), std::inserter(intersect, intersect.begin()));
return intersect;
std::set<SecondarySkill> intersection;
std::set_intersection(left.begin(), left.end(), right.begin(), right.end(), std::inserter(intersection, intersection.begin()));
return intersection;
};
std::set<SecondarySkill> wisdomList = getObligatorySkills(CSkill::Obligatory::MAJOR);

View File

@@ -1340,7 +1340,6 @@ void BattleActionProcessor::handleAfterAttackCasting(const CBattleInfoCallback &
if(attacker->hasBonusOfType(BonusType::TRANSMUTATION) && defender->isLiving()) //transmutation mechanics, similar to WoG werewolf ability
{
ObjectInstanceID ownerArmy = battle.getBattle()->getSideArmy(attacker->unitSide())->id;
int chanceToTrigger = attacker->valOfBonuses(BonusType::TRANSMUTATION);
if (!gameHandler->randomizer->rollCombatAbility(ownerArmy, chanceToTrigger))
return;
@@ -1404,7 +1403,6 @@ void BattleActionProcessor::handleAfterAttackCasting(const CBattleInfoCallback &
amountToDie = attacker->getBonus(Selector::type()(BonusType::DESTRUCTION).And(Selector::subtype()(BonusCustomSubtype::destructionKillAmount)))->additionalInfo[0];
}
ObjectInstanceID ownerArmy = battle.getBattle()->getSideArmy(attacker->unitSide())->id;
if (!gameHandler->randomizer->rollCombatAbility(ownerArmy, chanceToTrigger))
return;

View File

@@ -748,13 +748,10 @@ void BattleFlowProcessor::stackTurnTrigger(const CBattleInfoCallback & battle, c
break;
}
}
if (fearsomeCreature)
if (fearsomeCreature && gameHandler->randomizer->rollCombatAbility(opponentArmyID, 10)) //fixed 10%
{
if (gameHandler->randomizer->rollCombatAbility(opponentArmyID, 10)) //fixed 10%
{
bte.effect = vstd::to_underlying(BonusType::FEAR);
gameHandler->sendAndApply(bte);
}
bte.effect = vstd::to_underlying(BonusType::FEAR);
gameHandler->sendAndApply(bte);
}
}
BonusList bl = *(st->getBonuses(Selector::type()(BonusType::ENCHANTER)));