mirror of
https://github.com/vcmi/vcmi.git
synced 2025-12-01 23:12:49 +02:00
Reworked and fixed selection of secondary skills:
- Fixed off-by-one error when checking for obligatory skills - If both wisdom and magic school must be offered in the same slot, magic school will be correctly offered on next levelup - Obligatory skill can now be proposed for upgrade - Obligatory skills are now offered using hero class weight instead of simple random - If hero has multiple skills not available to his class game will select random skill instead of first one - Moved storage of random seed to server instead of mutable member
This commit is contained in:
@@ -123,26 +123,30 @@ void CHero::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
SecondarySkill CHeroClass::chooseSecSkill(const std::set<SecondarySkill> & possibles, CRandomGenerator & rand) const //picks secondary skill out from given possibilities
|
||||
{
|
||||
assert(!possibles.empty());
|
||||
|
||||
if (possibles.size() == 1)
|
||||
return *possibles.begin();
|
||||
|
||||
int totalProb = 0;
|
||||
for(const auto & possible : possibles)
|
||||
if (secSkillProbability.count(possible) != 0)
|
||||
totalProb += secSkillProbability.at(possible);
|
||||
|
||||
if (totalProb != 0) // may trigger if set contains only banned skills (0 probability)
|
||||
{
|
||||
auto ran = rand.nextInt(totalProb - 1);
|
||||
for(const auto & possible : possibles)
|
||||
{
|
||||
if (secSkillProbability.count(possible) != 0)
|
||||
ran -= secSkillProbability.at(possible);
|
||||
if (totalProb == 0) // may trigger if set contains only banned skills (0 probability)
|
||||
return *RandomGeneratorUtil::nextItem(possibles, rand);
|
||||
|
||||
if(ran < 0)
|
||||
{
|
||||
return possible;
|
||||
}
|
||||
}
|
||||
auto ran = rand.nextInt(totalProb - 1);
|
||||
for(const auto & possible : possibles)
|
||||
{
|
||||
if (secSkillProbability.count(possible) != 0)
|
||||
ran -= secSkillProbability.at(possible);
|
||||
|
||||
if(ran < 0)
|
||||
return possible;
|
||||
}
|
||||
// FIXME: select randomly? How H3 handles such rare situation?
|
||||
|
||||
assert(0); // should not be possible
|
||||
return *possibles.begin();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user