1
0
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:
DjWarmonger 2013-04-23 17:29:16 +00:00
parent 0dc5a13596
commit 57ea1ed1b8
2 changed files with 8 additions and 6 deletions

View File

@ -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);
}

View File

@ -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
{