Skip to content

Commit fbb46aa

Browse files
committed
Let's count in that we can't step from an incomplete building to a complete one.
1 parent 4c65a9b commit fbb46aa

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/Savegame/Base.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,13 +1310,18 @@ std::list<std::vector<BaseFacility*>::iterator> Base::getDisconnectedFacilities(
13101310
{
13111311
int x = stack.top().first, y = stack.top().second;
13121312
stack.pop();
1313-
if (grid[x][y] != 0)
1313+
if (x >= 0 && x < BASE_SIZE && y >= 0 && y < BASE_SIZE && grid[x][y] != 0 && !grid[x][y]->second)
13141314
{
13151315
grid[x][y]->second = true;
1316-
if (x-1 >= 0 && grid[x-1][y] != 0 && !grid[x-1][y]->second) stack.push(std::make_pair(x-1,y));
1317-
if (x+1 < BASE_SIZE && grid[x+1][y] != 0 && !grid[x+1][y]->second) stack.push(std::make_pair(x+1,y));
1318-
if (y-1 >= 0 && grid[x][y-1] != 0 && !grid[x][y-1]->second) stack.push(std::make_pair(x,y-1));
1319-
if (y+1 < BASE_SIZE && grid[x][y+1] != 0 && !grid[x][y+1]->second) stack.push(std::make_pair(x,y+1));
1316+
BaseFacility *fac = *(grid[x][y]->first);
1317+
BaseFacility *neighborLeft = (x-1 >= 0 && grid[x-1][y] != 0) ? *(grid[x-1][y]->first) : 0;
1318+
BaseFacility *neighborRight = (x+1 < BASE_SIZE && grid[x+1][y] != 0) ? *(grid[x+1][y]->first) : 0;
1319+
BaseFacility *neighborTop = (y-1 >= 0 && grid[x][y-1] != 0) ? *(grid[x][y-1]->first) : 0;
1320+
BaseFacility *neighborBottom= (y+1 < BASE_SIZE && grid[x][y+1] != 0) ? *(grid[x][y+1]->first) : 0;
1321+
if ((fac->getBuildTime() == 0) || (neighborLeft != 0 && (neighborLeft == fac || neighborLeft->getBuildTime() > neighborLeft->getRules()->getBuildTime()))) stack.push(std::make_pair(x-1,y));
1322+
if ((fac->getBuildTime() == 0) || (neighborRight != 0 && (neighborRight == fac || neighborRight->getBuildTime() > neighborRight->getRules()->getBuildTime()))) stack.push(std::make_pair(x+1,y));
1323+
if ((fac->getBuildTime() == 0) || (neighborTop != 0 && (neighborTop == fac || neighborTop->getBuildTime() > neighborTop->getRules()->getBuildTime()))) stack.push(std::make_pair(x,y-1));
1324+
if ((fac->getBuildTime() == 0) || (neighborBottom != 0 && (neighborBottom == fac || neighborBottom->getBuildTime() > neighborBottom->getRules()->getBuildTime()))) stack.push(std::make_pair(x,y+1));
13201325
}
13211326
}
13221327

0 commit comments

Comments
 (0)