Browse Source

Do not calculate area for invalid positions

Tomasz Zieliński 1 year ago
parent
commit
b9193ecb73
1 changed files with 16 additions and 5 deletions
  1. 16 5
      lib/mapping/ObstacleProxy.cpp

+ 16 - 5
lib/mapping/ObstacleProxy.cpp

@@ -84,16 +84,27 @@ int ObstacleProxy::getWeightedObjects(const int3 & tile, CRandomGenerator & rand
 			rmg::Object * rmgObject = &allObjects.back();
 			for(const auto & offset : obj->getBlockedOffsets())
 			{
-				rmgObject->setPosition(tile - offset);
+				auto newPos = tile - offset;
 
-				if(!isInTheMap(rmgObject->getPosition()))
+				if(!isInTheMap(newPos))
 					continue;
 
-				if(!rmgObject->getArea().getSubarea([this](const int3 & t)
+				rmgObject->setPosition(newPos);
+
+				bool isInTheMapEntirely = true;
+				for (const auto & t : rmgObject->getArea().getTiles())
+				{
+					if (!isInTheMap(t))
+					{
+						isInTheMapEntirely = false;
+						break;
+					}
+
+				}
+				if (!isInTheMapEntirely)
 				{
-					return !isInTheMap(t);
-				}).empty())
 					continue;
+				}
 
 				if(isProhibited(rmgObject->getArea()))
 					continue;