1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Merge branch 'vcmi/master' into 'vcmi/develop'

This commit is contained in:
Ivan Savenko
2023-09-15 13:59:02 +03:00
118 changed files with 9641 additions and 492 deletions

View File

@@ -287,7 +287,7 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
//if level set to range
if(auto * info = dynamic_cast<CCreGenLeveledInfo *>(dwl->info))
{
level = getRandomGenerator().nextInt(info->minLevel, info->maxLevel);
level = getRandomGenerator().nextInt(info->minLevel, info->maxLevel) - 1;
}
else // fixed level
{
@@ -298,7 +298,20 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
dwl->info = nullptr;
std::pair<Obj, int> result(Obj::NO_OBJ, -1);
CreatureID cid = (*VLC->townh)[faction]->town->creatures[level][0];
CreatureID cid;
if((*VLC->townh)[faction]->town)
cid = (*VLC->townh)[faction]->town->creatures[level][0];
else
{
//neutral faction
std::vector<CCreature*> possibleCreatures;
std::copy_if(VLC->creh->objects.begin(), VLC->creh->objects.end(), std::back_inserter(possibleCreatures), [faction](const CCreature * c)
{
return c->getFaction().getNum() == faction;
});
assert(!possibleCreatures.empty());
cid = (*RandomGeneratorUtil::nextItem(possibleCreatures, getRandomGenerator()))->getId();
}
//NOTE: this will pick last dwelling with this creature (Mantis #900)
//check for block map equality is better but more complex solution