mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Fixed crash at month of double population.
doublingCreatures vector was never properly initialized.
This commit is contained in:
parent
0dc5a13596
commit
57ea1ed1b8
@ -342,6 +342,11 @@ void CCreatureHandler::loadObject(std::string scope, std::string name, const Jso
|
||||
object->idNumber = CreatureID(index);
|
||||
object->iconIndex = object->idNumber + 2;
|
||||
|
||||
if(data["hasDoubleWeek"].Bool()) //
|
||||
{
|
||||
doubledCreatures.insert (object->idNumber); //we need to have id (or identifier) before it is inserted
|
||||
}
|
||||
|
||||
assert(creatures[index] == nullptr); // ensure that this id was not loaded before
|
||||
creatures[index] = object;
|
||||
|
||||
@ -635,9 +640,6 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
|
||||
});
|
||||
}
|
||||
|
||||
if(config["hasDoubleWeek"].Bool())
|
||||
doubledCreatures.insert(creature->idNumber);
|
||||
|
||||
creature->animation.projectileImageName = config["graphics"]["missile"]["projectile"].String();
|
||||
|
||||
creature->special = config["special"].Bool() || config["disabled"].Bool();
|
||||
@ -1037,6 +1039,7 @@ CreatureID CCreatureHandler::pickRandomMonster(const boost::function<int()> &ran
|
||||
|
||||
return vstd::pickRandomElementOf(allowed, randGen);
|
||||
}
|
||||
assert (r >= 0); //should always be, but it crashed
|
||||
return CreatureID(r);
|
||||
}
|
||||
|
||||
|
@ -1127,9 +1127,8 @@ void CGameHandler::newTurn()
|
||||
}
|
||||
else if(VLC->creh->doubledCreatures.size())
|
||||
{
|
||||
auto it = VLC->creh->doubledCreatures.cbegin();
|
||||
std::advance (it, rand() % VLC->creh->doubledCreatures.size()); //picking random element of set is tiring
|
||||
n.creatureid = *it;
|
||||
const std::vector<CreatureID> doubledCreatures (VLC->creh->doubledCreatures.begin(), VLC->creh->doubledCreatures.end());
|
||||
n.creatureid = vstd::pickRandomElementOf (doubledCreatures, boost::ref(rand));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user