mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-11 11:31:52 +02:00
Skip objects with value too low to be placed in the zone.
This commit is contained in:
parent
511a42f9b9
commit
b3a457c71a
@ -136,6 +136,7 @@ ZoneOptions::ZoneOptions():
|
||||
id(0),
|
||||
type(ETemplateZoneType::PLAYER_START),
|
||||
size(1),
|
||||
maxTreasureValue(0),
|
||||
owner(boost::none),
|
||||
matchTerrainToTown(true),
|
||||
townsAreSameType(false),
|
||||
@ -242,11 +243,18 @@ std::map<TResource, ui16> ZoneOptions::getMinesInfo() const
|
||||
void ZoneOptions::setTreasureInfo(const std::vector<CTreasureInfo> & value)
|
||||
{
|
||||
treasureInfo = value;
|
||||
|
||||
maxTreasureValue = 0;
|
||||
for (const auto& ti : value)
|
||||
{
|
||||
vstd::amax(maxTreasureValue, ti.max);
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneOptions::addTreasureInfo(const CTreasureInfo & value)
|
||||
{
|
||||
treasureInfo.push_back(value);
|
||||
vstd::amax(maxTreasureValue, value.max);
|
||||
}
|
||||
|
||||
const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const
|
||||
@ -254,6 +262,11 @@ const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const
|
||||
return treasureInfo;
|
||||
}
|
||||
|
||||
ui32 ZoneOptions::getMaxTreasureValue() const
|
||||
{
|
||||
return maxTreasureValue;
|
||||
}
|
||||
|
||||
TRmgTemplateZoneId ZoneOptions::getMinesLikeZone() const
|
||||
{
|
||||
return minesLikeZone;
|
||||
@ -386,6 +399,11 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
auto treasureData = handler.enterArray("treasure");
|
||||
treasureData.serializeStruct(treasureInfo);
|
||||
if (!handler.saving)
|
||||
{
|
||||
//Just in order to calculate maxTreasureValue
|
||||
setTreasureInfo(treasureInfo);
|
||||
}
|
||||
}
|
||||
|
||||
if((minesLikeZone == NO_ZONE) && (!handler.saving || !mines.empty()))
|
||||
|
@ -144,6 +144,7 @@ public:
|
||||
void setTreasureInfo(const std::vector<CTreasureInfo> & value);
|
||||
void addTreasureInfo(const CTreasureInfo & value);
|
||||
const std::vector<CTreasureInfo> & getTreasureInfo() const;
|
||||
ui32 getMaxTreasureValue() const;
|
||||
|
||||
TRmgTemplateZoneId getMinesLikeZone() const;
|
||||
TRmgTemplateZoneId getTerrainTypeLikeZone() const;
|
||||
@ -163,6 +164,7 @@ protected:
|
||||
TRmgTemplateZoneId id;
|
||||
ETemplateZoneType::ETemplateZoneType type;
|
||||
int size;
|
||||
ui32 maxTreasureValue;
|
||||
boost::optional<int> owner;
|
||||
CTownInfo playerTowns;
|
||||
CTownInfo neutralTowns;
|
||||
|
@ -59,21 +59,18 @@ void ObjectDistributor::distributeLimitedObjects()
|
||||
//Skip objects which don't have global per-map limit here
|
||||
if (rmgInfo.mapLimit)
|
||||
{
|
||||
|
||||
//Count all zones where this object can be placed
|
||||
std::vector<std::shared_ptr<Zone>> matchingZones;
|
||||
|
||||
//TODO: Are all terrains initialized at this point? Including water?
|
||||
for (const auto& it : zones)
|
||||
{
|
||||
if (!handler->getTemplates(it.second->getTerrainType()).empty())
|
||||
if (!handler->getTemplates(it.second->getTerrainType()).empty() &&
|
||||
rmgInfo.value <= it.second->getMaxTreasureValue())
|
||||
{
|
||||
matchingZones.push_back(it.second);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Also check if the object value is within zone max value
|
||||
|
||||
size_t numZones = matchingZones.size();
|
||||
if (!numZones)
|
||||
continue;
|
||||
|
@ -65,13 +65,12 @@ void TreasurePlacer::addAllPossibleObjects()
|
||||
if(!handler->isStaticObject() && handler->getRMGInfo().value)
|
||||
{
|
||||
auto rmgInfo = handler->getRMGInfo();
|
||||
if (rmgInfo.mapLimit)
|
||||
if (rmgInfo.mapLimit || rmgInfo.value > zone.getMaxTreasureValue())
|
||||
{
|
||||
//Skip objects with per-map limit here
|
||||
continue;
|
||||
}
|
||||
|
||||
//TODO: Also check if the object value is within zone max value
|
||||
for(const auto & temp : handler->getTemplates())
|
||||
{
|
||||
if(temp->canBePlacedAt(zone.getTerrainType()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user