|
@@ -59,7 +59,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
|
|
|
if(!handler->isStaticObject() && handler->getRMGInfo().value)
|
|
|
{
|
|
|
- for(auto temp : handler->getTemplates())
|
|
|
+ for(const auto & temp : handler->getTemplates())
|
|
|
{
|
|
|
if(temp->canBePlacedAt(zone.getTerrainType()))
|
|
|
{
|
|
@@ -99,9 +99,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
|
|
|
auto hid = *RandomGeneratorUtil::nextItem(possibleHeroes, generator.rand);
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PRISON, 0);
|
|
|
- auto obj = (CGHeroInstance *) factory->create();
|
|
|
-
|
|
|
-
|
|
|
+ auto * obj = dynamic_cast<CGHeroInstance *>(factory->create());
|
|
|
+
|
|
|
obj->subID = hid; //will be initialized later
|
|
|
obj->exp = generator.getConfig().prisonExperience[i];
|
|
|
obj->setOwner(PlayerColor::NEUTRAL);
|
|
@@ -119,8 +118,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
}
|
|
|
|
|
|
//all following objects are unlimited
|
|
|
- oi.maxPerZone = std::numeric_limits<ui32>().max();
|
|
|
-
|
|
|
+ oi.maxPerZone = std::numeric_limits<ui32>::max();
|
|
|
+
|
|
|
std::vector<CCreature *> creatures; //native creatures for this zone
|
|
|
for(auto cre : VLC->creh->objects)
|
|
|
{
|
|
@@ -141,35 +140,35 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
{
|
|
|
//don't spawn original "neutral" dwellings that got replaced by Conflux dwellings in AB
|
|
|
static int elementalConfluxROE[] = {7, 13, 16, 47};
|
|
|
- for(int i = 0; i < 4; i++)
|
|
|
- vstd::erase_if_present(subObjects, elementalConfluxROE[i]);
|
|
|
+ for(int & i : elementalConfluxROE)
|
|
|
+ vstd::erase_if_present(subObjects, i);
|
|
|
}
|
|
|
|
|
|
for(auto secondaryID : subObjects)
|
|
|
{
|
|
|
- auto dwellingHandler = dynamic_cast<const CDwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(dwellingType, secondaryID).get());
|
|
|
+ const auto * dwellingHandler = dynamic_cast<const CDwellingInstanceConstructor *>(VLC->objtypeh->getHandlerFor(dwellingType, secondaryID).get());
|
|
|
auto creatures = dwellingHandler->getProducedCreatures();
|
|
|
if(creatures.empty())
|
|
|
continue;
|
|
|
-
|
|
|
- auto cre = creatures.front();
|
|
|
+
|
|
|
+ const auto * cre = creatures.front();
|
|
|
if(cre->faction == zone.getTownType())
|
|
|
{
|
|
|
- float nativeZonesCount = static_cast<float>(map.getZoneCount(cre->faction));
|
|
|
+ auto nativeZonesCount = static_cast<float>(map.getZoneCount(cre->faction));
|
|
|
oi.value = static_cast<ui32>(cre->AIValue * cre->growth * (1 + (nativeZonesCount / map.getTotalZoneCount()) + (nativeZonesCount / 2)));
|
|
|
oi.probability = 40;
|
|
|
-
|
|
|
- for(auto tmplate : dwellingHandler->getTemplates())
|
|
|
+
|
|
|
+ for(const auto & tmplate : dwellingHandler->getTemplates())
|
|
|
{
|
|
|
if(tmplate->canBePlacedAt(zone.getTerrainType()))
|
|
|
{
|
|
|
oi.generateObject = [tmplate, secondaryID, dwellingType]() -> CGObjectInstance *
|
|
|
{
|
|
|
- auto obj = VLC->objtypeh->getHandlerFor(dwellingType, secondaryID)->create(tmplate);
|
|
|
+ auto * obj = VLC->objtypeh->getHandlerFor(dwellingType, secondaryID)->create(tmplate);
|
|
|
obj->tempOwner = PlayerColor::NEUTRAL;
|
|
|
return obj;
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
oi.templ = tmplate;
|
|
|
possibleObjects.push_back(oi);
|
|
|
}
|
|
@@ -183,7 +182,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i, this]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SPELL_SCROLL, 0);
|
|
|
- auto obj = (CGArtifact *) factory->create();
|
|
|
+ auto * obj = dynamic_cast<CGArtifact *>(factory->create());
|
|
|
std::vector<SpellID> out;
|
|
|
|
|
|
for(auto spell : VLC->spellh->objects) //spellh size appears to be greater (?)
|
|
@@ -193,7 +192,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
out.push_back(spell->id);
|
|
|
}
|
|
|
}
|
|
|
- auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, generator.rand));
|
|
|
+ auto * a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, generator.rand));
|
|
|
obj->storedArtifact = a;
|
|
|
return obj;
|
|
|
};
|
|
@@ -209,7 +208,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
obj->resources[Res::GOLD] = i * 5000;
|
|
|
return obj;
|
|
|
};
|
|
@@ -225,7 +224,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
obj->gainedExp = i * 5000;
|
|
|
return obj;
|
|
|
};
|
|
@@ -246,7 +245,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
int actualTier = creature->level > tierValues.size() ?
|
|
|
tierValues.size() - 1 :
|
|
|
creature->level - 1;
|
|
|
- float creaturesAmount = ((float)tierValues[actualTier]) / creature->AIValue;
|
|
|
+ float creaturesAmount = (static_cast<float>(tierValues[actualTier])) / creature->AIValue;
|
|
|
if(creaturesAmount <= 5)
|
|
|
{
|
|
|
creaturesAmount = boost::math::round(creaturesAmount); //allow single monsters
|
|
@@ -267,8 +266,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
}
|
|
|
return static_cast<int>(creaturesAmount);
|
|
|
};
|
|
|
-
|
|
|
- for(auto creature : creatures)
|
|
|
+
|
|
|
+ for(auto * creature : creatures)
|
|
|
{
|
|
|
int creaturesAmount = creatureToCount(creature);
|
|
|
if(!creaturesAmount)
|
|
@@ -277,13 +276,13 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [creature, creaturesAmount]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
- auto stack = new CStackInstance(creature, creaturesAmount);
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
+ auto * stack = new CStackInstance(creature, creaturesAmount);
|
|
|
obj->creatures.putStack(SlotID(0), stack);
|
|
|
return obj;
|
|
|
};
|
|
|
oi.setTemplate(Obj::PANDORAS_BOX, 0, zone.getTerrainType());
|
|
|
- oi.value = static_cast<ui32>((2 * (creature->AIValue) * creaturesAmount * (1 + (float)(map.getZoneCount(creature->faction)) / map.getTotalZoneCount())) / 3);
|
|
|
+ oi.value = static_cast<ui32>((2 * (creature->AIValue) * creaturesAmount * (1 + static_cast<float>(map.getZoneCount(creature->faction)) / map.getTotalZoneCount())) / 3);
|
|
|
oi.probability = 3;
|
|
|
possibleObjects.push_back(oi);
|
|
|
}
|
|
@@ -294,8 +293,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i, this]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
-
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
+
|
|
|
std::vector <CSpell *> spells;
|
|
|
for(auto spell : VLC->spellh->objects)
|
|
|
{
|
|
@@ -304,7 +303,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
}
|
|
|
|
|
|
RandomGeneratorUtil::randomShuffle(spells, generator.rand);
|
|
|
- for(int j = 0; j < std::min(12, (int)spells.size()); j++)
|
|
|
+ for(int j = 0; j < std::min(12, static_cast<int>(spells.size())); j++)
|
|
|
{
|
|
|
obj->spells.push_back(spells[j]->id);
|
|
|
}
|
|
@@ -323,17 +322,17 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i, this]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
-
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
+
|
|
|
std::vector <CSpell *> spells;
|
|
|
for(auto spell : VLC->spellh->objects)
|
|
|
{
|
|
|
- if(map.isAllowedSpell(spell->id) && spell->school[(ESpellSchool)i])
|
|
|
+ if(map.isAllowedSpell(spell->id) && spell->school[static_cast<ESpellSchool>(i)])
|
|
|
spells.push_back(spell);
|
|
|
}
|
|
|
|
|
|
RandomGeneratorUtil::randomShuffle(spells, generator.rand);
|
|
|
- for(int j = 0; j < std::min(15, (int)spells.size()); j++)
|
|
|
+ for(int j = 0; j < std::min(15, static_cast<int>(spells.size())); j++)
|
|
|
{
|
|
|
obj->spells.push_back(spells[j]->id);
|
|
|
}
|
|
@@ -351,8 +350,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [this]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::PANDORAS_BOX, 0);
|
|
|
- auto obj = (CGPandoraBox *) factory->create();
|
|
|
-
|
|
|
+ auto * obj = dynamic_cast<CGPandoraBox *>(factory->create());
|
|
|
+
|
|
|
std::vector <CSpell *> spells;
|
|
|
for(auto spell : VLC->spellh->objects)
|
|
|
{
|
|
@@ -361,7 +360,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
}
|
|
|
|
|
|
RandomGeneratorUtil::randomShuffle(spells, generator.rand);
|
|
|
- for(int j = 0; j < std::min(60, (int)spells.size()); j++)
|
|
|
+ for(int j = 0; j < std::min(60, static_cast<int>(spells.size())); j++)
|
|
|
{
|
|
|
obj->spells.push_back(spells[j]->id);
|
|
|
}
|
|
@@ -382,10 +381,10 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
const int questArtsRemaining = static_cast<int>(generator.getQuestArtsRemaning().size());
|
|
|
|
|
|
//general issue is that not many artifact types are available for quests
|
|
|
-
|
|
|
- if(questArtsRemaining >= genericSeerHuts + (int)creatures.size())
|
|
|
+
|
|
|
+ if(questArtsRemaining >= genericSeerHuts + static_cast<int>(creatures.size()))
|
|
|
{
|
|
|
- seerHutsPerType = questArtsRemaining / (genericSeerHuts + (int)creatures.size());
|
|
|
+ seerHutsPerType = questArtsRemaining / (genericSeerHuts + static_cast<int>(creatures.size()));
|
|
|
}
|
|
|
else if(questArtsRemaining >= genericSeerHuts)
|
|
|
{
|
|
@@ -394,8 +393,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.maxPerZone = seerHutsPerType;
|
|
|
|
|
|
RandomGeneratorUtil::randomShuffle(creatures, generator.rand);
|
|
|
-
|
|
|
- auto generateArtInfo = [this](ArtifactID id) -> ObjectInfo
|
|
|
+
|
|
|
+ auto generateArtInfo = [this](const ArtifactID & id) -> ObjectInfo
|
|
|
{
|
|
|
ObjectInfo artInfo;
|
|
|
artInfo.probability = std::numeric_limits<ui16>::max(); //99,9% to spawn that art in first treasure pile
|
|
@@ -409,10 +408,10 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
};
|
|
|
return artInfo;
|
|
|
};
|
|
|
-
|
|
|
- for(int i = 0; i < std::min((int)creatures.size(), questArtsRemaining - genericSeerHuts); i++)
|
|
|
+
|
|
|
+ for(int i = 0; i < std::min(static_cast<int>(creatures.size()), questArtsRemaining - genericSeerHuts); i++)
|
|
|
{
|
|
|
- auto creature = creatures[i];
|
|
|
+ auto * creature = creatures[i];
|
|
|
int creaturesAmount = creatureToCount(creature);
|
|
|
|
|
|
if(!creaturesAmount)
|
|
@@ -423,7 +422,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [creature, creaturesAmount, randomAppearance, this, generateArtInfo]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
|
|
- auto obj = (CGSeerHut *) factory->create();
|
|
|
+ auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
|
|
obj->rewardType = CGSeerHut::CREATURE;
|
|
|
obj->rID = creature->idNumber;
|
|
|
obj->rVal = creaturesAmount;
|
|
@@ -442,7 +441,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
return obj;
|
|
|
};
|
|
|
oi.setTemplate(Obj::SEER_HUT, randomAppearance, zone.getTerrainType());
|
|
|
- oi.value = static_cast<ui32>(((2 * (creature->AIValue) * creaturesAmount * (1 + (float)(map.getZoneCount(creature->faction)) / map.getTotalZoneCount())) - 4000) / 3);
|
|
|
+ oi.value = static_cast<ui32>(((2 * (creature->AIValue) * creaturesAmount * (1 + static_cast<float>(map.getZoneCount(creature->faction)) / map.getTotalZoneCount())) - 4000) / 3);
|
|
|
oi.probability = 3;
|
|
|
possibleObjects.push_back(oi);
|
|
|
}
|
|
@@ -459,8 +458,8 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i, randomAppearance, this, generateArtInfo]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
|
|
- auto obj = (CGSeerHut *) factory->create();
|
|
|
-
|
|
|
+ auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
|
|
+
|
|
|
obj->rewardType = CGSeerHut::EXPERIENCE;
|
|
|
obj->rID = 0; //unitialized?
|
|
|
obj->rVal = generator.getConfig().questRewardValues[i];
|
|
@@ -483,7 +482,7 @@ void TreasurePlacer::addAllPossibleObjects()
|
|
|
oi.generateObject = [i, randomAppearance, this, generateArtInfo]() -> CGObjectInstance *
|
|
|
{
|
|
|
auto factory = VLC->objtypeh->getHandlerFor(Obj::SEER_HUT, randomAppearance);
|
|
|
- auto obj = (CGSeerHut *) factory->create();
|
|
|
+ auto * obj = dynamic_cast<CGSeerHut *>(factory->create());
|
|
|
obj->rewardType = CGSeerHut::RESOURCES;
|
|
|
obj->rID = Res::GOLD;
|
|
|
obj->rVal = generator.getConfig().questRewardValues[i];
|
|
@@ -521,7 +520,7 @@ std::vector<ObjectInfo*> TreasurePlacer::prepareTreasurePile(const CTreasureInfo
|
|
|
|
|
|
int currentValue = 0;
|
|
|
bool hasLargeObject = false;
|
|
|
- while(currentValue <= (int)desiredValue - 100) //no objects with value below 100 are available
|
|
|
+ while(currentValue <= static_cast<int>(desiredValue) - 100) //no objects with value below 100 are available
|
|
|
{
|
|
|
auto * oi = getRandomObject(desiredValue, currentValue, maxValue, !hasLargeObject);
|
|
|
if(!oi) //fail
|
|
@@ -550,7 +549,7 @@ std::vector<ObjectInfo*> TreasurePlacer::prepareTreasurePile(const CTreasureInfo
|
|
|
rmg::Object TreasurePlacer::constructTreasurePile(const std::vector<ObjectInfo*> & treasureInfos, bool densePlacement)
|
|
|
{
|
|
|
rmg::Object rmgObject;
|
|
|
- for(auto & oi : treasureInfos)
|
|
|
+ for(const auto & oi : treasureInfos)
|
|
|
{
|
|
|
auto blockedArea = rmgObject.getArea();
|
|
|
auto accessibleArea = rmgObject.getAccessibleArea();
|
|
@@ -574,7 +573,7 @@ rmg::Object TreasurePlacer::constructTreasurePile(const std::vector<ObjectInfo*>
|
|
|
if(densePlacement)
|
|
|
{
|
|
|
int bestPositionsWeight = std::numeric_limits<int>::max();
|
|
|
- for(auto & t : accessibleArea.getTilesVector())
|
|
|
+ for(const auto & t : accessibleArea.getTilesVector())
|
|
|
{
|
|
|
instance.setPosition(t);
|
|
|
int w = rmgObject.getAccessibleArea().getTilesVector().size();
|
|
@@ -640,7 +639,7 @@ ObjectInfo * TreasurePlacer::getRandomObject(ui32 desiredValue, ui32 currentValu
|
|
|
if(oi.value >= minValue && oi.maxPerZone > 0)
|
|
|
{
|
|
|
total += oi.probability;
|
|
|
- thresholds.push_back(std::make_pair(total, &oi));
|
|
|
+ thresholds.emplace_back(total, &oi);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -651,13 +650,13 @@ ObjectInfo * TreasurePlacer::getRandomObject(ui32 desiredValue, ui32 currentValu
|
|
|
else
|
|
|
{
|
|
|
int r = generator.rand.nextInt(1, total);
|
|
|
-
|
|
|
+ auto sorter = [](const std::pair<ui32, ObjectInfo *> & rhs, const ui32 lhs) -> bool
|
|
|
+ {
|
|
|
+ return static_cast<int>(rhs.first) < lhs;
|
|
|
+ };
|
|
|
+
|
|
|
//binary search = fastest
|
|
|
- auto it = std::lower_bound(thresholds.begin(), thresholds.end(), r,
|
|
|
- [](const std::pair<ui32, ObjectInfo*> &rhs, const int lhs)->bool
|
|
|
- {
|
|
|
- return (int)rhs.first < lhs;
|
|
|
- });
|
|
|
+ auto it = std::lower_bound(thresholds.begin(), thresholds.end(), r, sorter);
|
|
|
return it->second;
|
|
|
}
|
|
|
}
|
|
@@ -746,8 +745,8 @@ void TreasurePlacer::createTreasures(ObjectManager & manager)
|
|
|
auto ti = map.getTile(tile);
|
|
|
if(ti.getNearestObjectDistance() < minDistance)
|
|
|
return -1.f;
|
|
|
-
|
|
|
- for(auto & t : rmgObject.getArea().getTilesVector())
|
|
|
+
|
|
|
+ for(const auto & t : rmgObject.getArea().getTilesVector())
|
|
|
{
|
|
|
if(map.getTile(t).getNearestObjectDistance() < minDistance)
|
|
|
return -1.f;
|
|
@@ -805,13 +804,6 @@ char TreasurePlacer::dump(const int3 & t)
|
|
|
return Modificator::dump(t);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-ObjectInfo::ObjectInfo()
|
|
|
-: templ(), value(0), probability(0), maxPerZone(1)
|
|
|
-{
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
void ObjectInfo::setTemplate(si32 type, si32 subtype, TerrainId terrainType)
|
|
|
{
|
|
|
auto templHandler = VLC->objtypeh->getHandlerFor(type, subtype);
|