mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Do not ban heroes in Prisons, they might be rehired after they are defeated.
Restore hero to pool if Prison fails to be placed.
This commit is contained in:
@@ -509,17 +509,6 @@ void CMapGenerator::banQuestArt(const ArtifactID & id)
|
|||||||
map->getMap(this).allowedArtifact.erase(id);
|
map->getMap(this).allowedArtifact.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMapGenerator::banHero(const HeroTypeID & id)
|
|
||||||
{
|
|
||||||
map->getMap(this).banHero(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMapGenerator::unbanHero(const HeroTypeID & id)
|
|
||||||
{
|
|
||||||
map->getMap(this).unbanHero(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Zone * CMapGenerator::getZoneWater() const
|
Zone * CMapGenerator::getZoneWater() const
|
||||||
{
|
{
|
||||||
for(auto & z : map->getZones())
|
for(auto & z : map->getZones())
|
||||||
|
@@ -65,8 +65,6 @@ public:
|
|||||||
const std::vector<ArtifactID> & getAllPossibleQuestArtifacts() const;
|
const std::vector<ArtifactID> & getAllPossibleQuestArtifacts() const;
|
||||||
const std::vector<HeroTypeID> getAllPossibleHeroes() const;
|
const std::vector<HeroTypeID> getAllPossibleHeroes() const;
|
||||||
void banQuestArt(const ArtifactID & id);
|
void banQuestArt(const ArtifactID & id);
|
||||||
void banHero(const HeroTypeID& id);
|
|
||||||
void unbanHero(const HeroTypeID & id);
|
|
||||||
|
|
||||||
Zone * getZoneWater() const;
|
Zone * getZoneWater() const;
|
||||||
void addWaterTreasuresInfo();
|
void addWaterTreasuresInfo();
|
||||||
|
@@ -56,20 +56,18 @@ HeroTypeID PrisonHeroPlacer::drawRandomHero()
|
|||||||
RandomGeneratorUtil::randomShuffle(allowedHeroes, zone.getRand());
|
RandomGeneratorUtil::randomShuffle(allowedHeroes, zone.getRand());
|
||||||
HeroTypeID ret = allowedHeroes.back();
|
HeroTypeID ret = allowedHeroes.back();
|
||||||
allowedHeroes.pop_back();
|
allowedHeroes.pop_back();
|
||||||
|
|
||||||
generator.banHero(ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw rmgException("No quest heroes left for prisons!");
|
throw rmgException("No unused heroes left for prisons!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrisonHeroPlacer::unbanHero(const HeroTypeID & hid)
|
void PrisonHeroPlacer::restoreDrawnHero(const HeroTypeID & hid)
|
||||||
{
|
{
|
||||||
RecursiveLock lock(externalAccessMutex);
|
RecursiveLock lock(externalAccessMutex);
|
||||||
generator.unbanHero(hid);
|
allowedHeroes.push_back(hid);
|
||||||
}
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
int getPrisonsRemaning() const;
|
int getPrisonsRemaning() const;
|
||||||
HeroTypeID drawRandomHero();
|
HeroTypeID drawRandomHero();
|
||||||
void unbanHero(const HeroTypeID & hid);
|
void restoreDrawnHero(const HeroTypeID & hid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void getAllowedHeroes();
|
void getAllowedHeroes();
|
||||||
|
@@ -130,7 +130,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|||||||
HeroTypeID hid = prisonHeroPlacer->drawRandomHero();
|
HeroTypeID hid = prisonHeroPlacer->drawRandomHero();
|
||||||
oi.destroyObject = [hid, prisonHeroPlacer]()
|
oi.destroyObject = [hid, prisonHeroPlacer]()
|
||||||
{
|
{
|
||||||
prisonHeroPlacer->unbanHero(hid);
|
// Hero can be used again
|
||||||
|
prisonHeroPlacer->restoreDrawnHero(hid);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto factory = VLC->objtypeh->getHandlerFor(Obj::PRISON, 0);
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PRISON, 0);
|
||||||
|
@@ -131,7 +131,12 @@ void MapController::repairMap(CMap * map) const
|
|||||||
//fix hero instance
|
//fix hero instance
|
||||||
if(auto * nih = dynamic_cast<CGHeroInstance*>(obj.get()))
|
if(auto * nih = dynamic_cast<CGHeroInstance*>(obj.get()))
|
||||||
{
|
{
|
||||||
|
// All heroes present on map or in prisons need to be allowed to rehire them after they are defeated
|
||||||
|
|
||||||
|
// FIXME: How about custom scenarios where defeated hero cannot be hired again?
|
||||||
|
|
||||||
map->allowedHeroes.insert(nih->getHeroType());
|
map->allowedHeroes.insert(nih->getHeroType());
|
||||||
|
|
||||||
auto type = VLC->heroh->objects[nih->subID];
|
auto type = VLC->heroh->objects[nih->subID];
|
||||||
assert(type->heroClass);
|
assert(type->heroClass);
|
||||||
//TODO: find a way to get proper type name
|
//TODO: find a way to get proper type name
|
||||||
|
Reference in New Issue
Block a user