Bladeren bron

Apply suggestions from code review

Co-authored-by: Andrey Filipenkov <[email protected]>
Nordsoft91 3 jaren geleden
bovenliggende
commit
60264aae29
3 gewijzigde bestanden met toevoegingen van 12 en 16 verwijderingen
  1. 3 2
      lib/CModHandler.cpp
  2. 4 2
      lib/CModHandler.h
  3. 5 12
      lib/rmg/ObstaclePlacer.cpp

+ 3 - 2
lib/CModHandler.cpp

@@ -655,8 +655,9 @@ void CModInfo::loadLocalData(const JsonNode & data)
 	
 	//check compatibility
 	bool wasEnabled = enabled;
-	enabled &= vcmiCompatibleMin.isNull() || Version::GameVersion().compatible(vcmiCompatibleMin);
-	enabled &= vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(Version::GameVersion());
+	enabled = enabled && (vcmiCompatibleMin.isNull() || Version::GameVersion().compatible(vcmiCompatibleMin));
+	enabled = enabled && (vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(Version::GameVersion()));
+
 	if(wasEnabled && !enabled)
 		logGlobal->warn("Mod %s is incompatible with current version of VCMI and cannot be enabled", name);
 

+ 4 - 2
lib/CModHandler.h

@@ -212,7 +212,8 @@ public:
 	/// version of the mod
 	Version version;
 	
-	///The  vcmi versions compatible with the mod
+	/// vcmi versions compatible with the mod
+
 	Version vcmiCompatibleMin, vcmiCompatibleMax;
 
 	/// list of mods that should be loaded before this one
@@ -364,7 +365,8 @@ public:
 		if(h.saving)
 		{
 			h & activeMods;
-			for(auto & m : activeMods)
+			for(const auto & m : activeMods)
+
 				h & allMods[m].version;
 		}
 		else

+ 5 - 12
lib/rmg/ObstaclePlacer.cpp

@@ -171,10 +171,7 @@ void ObstacleProxy::finalInsertion(CMapEditManager * manager, std::set<CGObjectI
 
 std::pair<bool, bool> ObstacleProxy::verifyCoverage(const int3 & t) const
 {
-	std::pair<bool, bool> result(false, false);
-	if(blockedArea.contains(t))
-		result.first = true;
-	return result;
+	return {blockedArea.contains(t), false};
 }
 
 void ObstacleProxy::placeObject(rmg::Object & object, std::set<CGObjectInstance*> & instances)
@@ -230,12 +227,7 @@ void ObstaclePlacer::init()
 
 std::pair<bool, bool> ObstaclePlacer::verifyCoverage(const int3 & t) const
 {
-	std::pair<bool, bool> result(false, false);
-	if(map.shouldBeBlocked(t))
-		result.first = true;
-	if(zone.areaPossible().contains(t))
-		result.second = true;
-	return result;
+	return {map.shouldBeBlocked(t), zone.areaPossible().contains(t)};
 }
 
 void ObstaclePlacer::placeObject(rmg::Object & object, std::set<CGObjectInstance*> &)
@@ -248,9 +240,10 @@ void ObstaclePlacer::postProcess(const rmg::Object & object)
 	//river processing
 	if(riverManager)
 	{
-		if(object.instances().front()->object().typeName == "mountain")
+		const auto objTypeName = object.instances().front()->object().typeName;
+		if(objTypeName == "mountain")
 			riverManager->riverSource().unite(object.getArea());
-		if(object.instances().front()->object().typeName == "lake")
+		else if(objTypeName == "lake")
 			riverManager->riverSink().unite(object.getArea());
 	}
 }