Tomasz Zieliński 2 lat temu
rodzic
commit
49c029ea6c
2 zmienionych plików z 7 dodań i 3 usunięć
  1. 6 3
      lib/rmg/CRmgTemplate.cpp
  2. 1 0
      lib/rmg/CRmgTemplate.h

+ 6 - 3
lib/rmg/CRmgTemplate.cpp

@@ -243,9 +243,13 @@ std::map<TResource, ui16> ZoneOptions::getMinesInfo() const
 void ZoneOptions::setTreasureInfo(const std::vector<CTreasureInfo> & value)
 {
 	treasureInfo = value;
+	recalculateMaxTreasureValue();
+}
 
+void ZoneOptions::recalculateMaxTreasureValue()
+{
 	maxTreasureValue = 0;
-	for (const auto& ti : value)
+	for (const auto& ti : treasureInfo)
 	{
 		vstd::amax(maxTreasureValue, ti.max);
 	}
@@ -401,8 +405,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
 		treasureData.serializeStruct(treasureInfo);
 		if (!handler.saving)
 		{
-			//Just in order to calculate maxTreasureValue
-			setTreasureInfo(treasureInfo);
+			recalculateMaxTreasureValue();
 		}
 	}
 

+ 1 - 0
lib/rmg/CRmgTemplate.h

@@ -145,6 +145,7 @@ public:
 	void addTreasureInfo(const CTreasureInfo & value);
 	const std::vector<CTreasureInfo> & getTreasureInfo() const;
 	ui32 getMaxTreasureValue() const;
+	void recalculateMaxTreasureValue();
 
 	TRmgTemplateZoneId getMinesLikeZone() const;
 	TRmgTemplateZoneId getTerrainTypeLikeZone() const;