1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Skip objects with value too low to be placed in the zone.

This commit is contained in:
Tomasz Zieliński
2023-03-27 17:29:46 +02:00
parent 511a42f9b9
commit b3a457c71a
4 changed files with 23 additions and 7 deletions

View File

@@ -136,6 +136,7 @@ ZoneOptions::ZoneOptions():
id(0), id(0),
type(ETemplateZoneType::PLAYER_START), type(ETemplateZoneType::PLAYER_START),
size(1), size(1),
maxTreasureValue(0),
owner(boost::none), owner(boost::none),
matchTerrainToTown(true), matchTerrainToTown(true),
townsAreSameType(false), townsAreSameType(false),
@@ -242,11 +243,18 @@ std::map<TResource, ui16> ZoneOptions::getMinesInfo() const
void ZoneOptions::setTreasureInfo(const std::vector<CTreasureInfo> & value) void ZoneOptions::setTreasureInfo(const std::vector<CTreasureInfo> & value)
{ {
treasureInfo = value; treasureInfo = value;
maxTreasureValue = 0;
for (const auto& ti : value)
{
vstd::amax(maxTreasureValue, ti.max);
}
} }
void ZoneOptions::addTreasureInfo(const CTreasureInfo & value) void ZoneOptions::addTreasureInfo(const CTreasureInfo & value)
{ {
treasureInfo.push_back(value); treasureInfo.push_back(value);
vstd::amax(maxTreasureValue, value.max);
} }
const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const
@@ -254,6 +262,11 @@ const std::vector<CTreasureInfo> & ZoneOptions::getTreasureInfo() const
return treasureInfo; return treasureInfo;
} }
ui32 ZoneOptions::getMaxTreasureValue() const
{
return maxTreasureValue;
}
TRmgTemplateZoneId ZoneOptions::getMinesLikeZone() const TRmgTemplateZoneId ZoneOptions::getMinesLikeZone() const
{ {
return minesLikeZone; return minesLikeZone;
@@ -386,6 +399,11 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
{ {
auto treasureData = handler.enterArray("treasure"); auto treasureData = handler.enterArray("treasure");
treasureData.serializeStruct(treasureInfo); treasureData.serializeStruct(treasureInfo);
if (!handler.saving)
{
//Just in order to calculate maxTreasureValue
setTreasureInfo(treasureInfo);
}
} }
if((minesLikeZone == NO_ZONE) && (!handler.saving || !mines.empty())) if((minesLikeZone == NO_ZONE) && (!handler.saving || !mines.empty()))

View File

@@ -144,6 +144,7 @@ public:
void setTreasureInfo(const std::vector<CTreasureInfo> & value); void setTreasureInfo(const std::vector<CTreasureInfo> & value);
void addTreasureInfo(const CTreasureInfo & value); void addTreasureInfo(const CTreasureInfo & value);
const std::vector<CTreasureInfo> & getTreasureInfo() const; const std::vector<CTreasureInfo> & getTreasureInfo() const;
ui32 getMaxTreasureValue() const;
TRmgTemplateZoneId getMinesLikeZone() const; TRmgTemplateZoneId getMinesLikeZone() const;
TRmgTemplateZoneId getTerrainTypeLikeZone() const; TRmgTemplateZoneId getTerrainTypeLikeZone() const;
@@ -163,6 +164,7 @@ protected:
TRmgTemplateZoneId id; TRmgTemplateZoneId id;
ETemplateZoneType::ETemplateZoneType type; ETemplateZoneType::ETemplateZoneType type;
int size; int size;
ui32 maxTreasureValue;
boost::optional<int> owner; boost::optional<int> owner;
CTownInfo playerTowns; CTownInfo playerTowns;
CTownInfo neutralTowns; CTownInfo neutralTowns;

View File

@@ -59,21 +59,18 @@ void ObjectDistributor::distributeLimitedObjects()
//Skip objects which don't have global per-map limit here //Skip objects which don't have global per-map limit here
if (rmgInfo.mapLimit) if (rmgInfo.mapLimit)
{ {
//Count all zones where this object can be placed //Count all zones where this object can be placed
std::vector<std::shared_ptr<Zone>> matchingZones; std::vector<std::shared_ptr<Zone>> matchingZones;
//TODO: Are all terrains initialized at this point? Including water?
for (const auto& it : zones) 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); matchingZones.push_back(it.second);
} }
} }
//TODO: Also check if the object value is within zone max value
size_t numZones = matchingZones.size(); size_t numZones = matchingZones.size();
if (!numZones) if (!numZones)
continue; continue;

View File

@@ -65,13 +65,12 @@ void TreasurePlacer::addAllPossibleObjects()
if(!handler->isStaticObject() && handler->getRMGInfo().value) if(!handler->isStaticObject() && handler->getRMGInfo().value)
{ {
auto rmgInfo = handler->getRMGInfo(); auto rmgInfo = handler->getRMGInfo();
if (rmgInfo.mapLimit) if (rmgInfo.mapLimit || rmgInfo.value > zone.getMaxTreasureValue())
{ {
//Skip objects with per-map limit here //Skip objects with per-map limit here
continue; continue;
} }
//TODO: Also check if the object value is within zone max value
for(const auto & temp : handler->getTemplates()) for(const auto & temp : handler->getTemplates())
{ {
if(temp->canBePlacedAt(zone.getTerrainType())) if(temp->canBePlacedAt(zone.getTerrainType()))