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

Merge pull request #5722 from IvanSavenko/wandering_month_fix

Fix crash on spawning wandering monsters on new month
This commit is contained in:
Ivan Savenko
2025-05-19 14:44:58 +03:00
committed by GitHub
2 changed files with 6 additions and 12 deletions

View File

@@ -4054,15 +4054,8 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID)
{
tile = tiles.begin();
logGlobal->trace("\tSpawning monster at %s", tile->toString());
{
auto count = cre->getRandomAmount(getRandomGenerator());
createWanderingMonster(*tile, creatureID);
auto monsterId = getTopObj(*tile)->id;
setObjPropertyValue(monsterId, ObjProperty::MONSTER_COUNT, count);
setObjPropertyValue(monsterId, ObjProperty::MONSTER_POWER, (si64)1000*count);
}
auto count = cre->getRandomAmount(getRandomGenerator());
createWanderingMonster(*tile, creatureID, count);
tiles.erase(tile); //not use it again
}
}
@@ -4291,7 +4284,7 @@ std::shared_ptr<CGObjectInstance> CGameHandler::createNewObject(const int3 & vis
return o;
}
void CGameHandler::createWanderingMonster(const int3 & visitablePosition, CreatureID creature)
void CGameHandler::createWanderingMonster(const int3 & visitablePosition, CreatureID creature, int unitSize)
{
auto createdObject = createNewObject(visitablePosition, Obj::MONSTER, creature);
@@ -4301,7 +4294,8 @@ void CGameHandler::createWanderingMonster(const int3 & visitablePosition, Creatu
cre->character = 2;
cre->gainedArtifact = ArtifactID::NONE;
cre->identifier = -1;
cre->addToSlot(SlotID(0), std::make_unique<CStackInstance>(gameState().cb, creature, -1)); //add placeholder stack
cre->temppower = static_cast<int64_t>(unitSize) * 1000;
cre->addToSlot(SlotID(0), std::make_unique<CStackInstance>(gameState().cb, creature, unitSize));
newObject(createdObject, PlayerColor::NEUTRAL);
}