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

Fix game startup

This commit is contained in:
Ivan Savenko
2023-10-26 16:50:29 +03:00
parent cc30bdda04
commit 461c481ef3
6 changed files with 20 additions and 14 deletions

View File

@@ -529,7 +529,7 @@ void CGameState::randomizeMapObjects()
auto * hero = dynamic_cast<CGHeroInstance *>(object); auto * hero = dynamic_cast<CGHeroInstance *>(object);
auto * town = dynamic_cast<CGTownInstance *>(object); auto * town = dynamic_cast<CGTownInstance *>(object);
if (hero) if (hero && hero->ID != Obj::PRISON)
map->heroesOnMap.emplace_back(hero); map->heroesOnMap.emplace_back(hero);
if (town) if (town)
@@ -579,7 +579,7 @@ void CGameState::placeStartingHero(const PlayerColor & playerColor, const HeroTy
CGObjectInstance * hero = handler->create(handler->getTemplates().front()); CGObjectInstance * hero = handler->create(handler->getTemplates().front());
hero->ID = Obj::HERO; hero->ID = Obj::HERO;
hero->subID = VLC->heroh->objects[heroTypeId]->heroClass->getIndex(); hero->subID = heroTypeId;
hero->tempOwner = playerColor; hero->tempOwner = playerColor;
hero->pos = townPos; hero->pos = townPos;
@@ -1826,10 +1826,10 @@ void CGameState::buildBonusSystemTree()
buildGlobalTeamPlayerTree(); buildGlobalTeamPlayerTree();
attachArmedObjects(); attachArmedObjects();
for(CGTownInstance *t : map->towns) // for(CGTownInstance *t : map->towns)
{ // {
t->deserializationFix(); // t->deserializationFix();
} // }
// CStackInstance <-> CCreature, CStackInstance <-> CArmedInstance, CArtifactInstance <-> CArtifact // CStackInstance <-> CCreature, CStackInstance <-> CArmedInstance, CArtifactInstance <-> CArtifact
// are provided on initializing / deserializing // are provided on initializing / deserializing

View File

@@ -189,6 +189,7 @@ void CGCreature::pickRandomObject(CRandomGenerator & rand)
break; break;
} }
ID = MapObjectID::MONSTER; ID = MapObjectID::MONSTER;
setType(ID, subID);
} }
void CGCreature::initObj(CRandomGenerator & rand) void CGCreature::initObj(CRandomGenerator & rand)

View File

@@ -569,15 +569,17 @@ void CGHeroInstance::pickRandomObject(CRandomGenerator & rand)
{ {
ID = Obj::HERO; ID = Obj::HERO;
subID = cb->gameState()->pickNextHeroType(getOwner()); subID = cb->gameState()->pickNextHeroType(getOwner());
}
type = VLC->heroh->objects[subID]; type = VLC->heroh->objects[subID];
randomizeArmy(type->heroClass->faction);
}
if (ID != Obj::PRISON)
{
// to find object handler we must use heroClass->id // to find object handler we must use heroClass->id
// after setType subID used to store unique hero identify id. Check issue 2277 for details // after setType subID used to store unique hero identify id. Check issue 2277 for details
setType(ID, type->heroClass->getIndex()); setType(ID, type->heroClass->getIndex());
}
this->subID = subID; this->subID = subID;
randomizeArmy(type->heroClass->faction);
} }
void CGHeroInstance::initObj(CRandomGenerator & rand) void CGHeroInstance::initObj(CRandomGenerator & rand)

View File

@@ -122,7 +122,7 @@ std::set<int3> CGObjectInstance::getBlockedOffsets() const
return appearance->getBlockedOffsets(); return appearance->getBlockedOffsets();
} }
void CGObjectInstance::setType(si32 newID, si32 newSubID) void CGObjectInstance::setType(MapObjectID newID, MapObjectSubID newSubID)
{ {
auto position = visitablePos(); auto position = visitablePos();
auto oldOffset = getVisitableOffset(); auto oldOffset = getVisitableOffset();

View File

@@ -157,7 +157,7 @@ protected:
virtual void setPropertyDer(ui8 what, ui32 val); virtual void setPropertyDer(ui8 what, ui32 val);
/// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman") /// Called mostly during map randomization to turn random object into a regular one (e.g. "Random Monster" into "Pikeman")
void setType(si32 ID, si32 subID); void setType(MapObjectID ID, MapObjectSubID subID);
/// Gives dummy bonus from this object to hero. Can be used to track visited state /// Gives dummy bonus from this object to hero. Can be used to track visited state
void giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration = BonusDuration::ONE_DAY) const; void giveDummyBonus(const ObjectInstanceID & heroID, BonusDuration::Type duration = BonusDuration::ONE_DAY) const;

View File

@@ -255,6 +255,7 @@ void CGResource::pickRandomObject(CRandomGenerator & rand)
{ {
ID = Obj::RESOURCE; ID = Obj::RESOURCE;
subID = rand.nextInt(EGameResID::WOOD, EGameResID::GOLD); subID = rand.nextInt(EGameResID::WOOD, EGameResID::GOLD);
setType(ID, subID);
} }
} }
@@ -735,6 +736,8 @@ void CGArtifact::pickRandomObject(CRandomGenerator & rand)
if (ID != Obj::SPELL_SCROLL) if (ID != Obj::SPELL_SCROLL)
ID = MapObjectID::ARTIFACT; ID = MapObjectID::ARTIFACT;
setType(ID, subID);
} }
void CGArtifact::initObj(CRandomGenerator & rand) void CGArtifact::initObj(CRandomGenerator & rand)