Fix pmap usage in Simulation::flood_water

flood_water would occasionally corrupt pmap by moving the pmap entry at i's location even if the entry itself didn't refer to i. pmap updates are tricky, they are best handled by Simulation::move.
This commit is contained in:
Tamás Bálint Misius
2023-04-16 11:05:37 +02:00
parent 54d08f3496
commit 5fc8770ee2

View File

@@ -736,7 +736,7 @@ int Simulation::FloodINST(int x, int y)
bool Simulation::flood_water(int x, int y, int i)
{
int x1, x2, originalY = y;
int x1, x2, originalX = x, originalY = y;
int r = pmap[y][x];
if (!r)
return false;
@@ -780,12 +780,7 @@ bool Simulation::flood_water(int x, int y, int i)
else if (!eval_move(parts[i].type, x, y - 1, nullptr))
continue;
int oldx = (int)(parts[i].x + 0.5f);
int oldy = (int)(parts[i].y + 0.5f);
pmap[y - 1][x] = pmap[oldy][oldx];
pmap[oldy][oldx] = 0;
parts[i].x = float(x);
parts[i].y = float(y - 1);
move(i, originalX, originalY, x, y - 1);
return true;
}