1
0
forked from mirrors/0ad

Update the passability grid properly when changing the map shape or the water height. Also include a fix for a possible bad memory access.

This was SVN commit r16832.
This commit is contained in:
Itms
2015-07-04 21:25:57 +00:00
parent 7ca2084e89
commit 0e4e3754e9
@@ -170,10 +170,14 @@ void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global))
break;
}
case MT_TerrainChanged:
m_TerrainDirty = true;
MinimalTerrainUpdate();
break;
case MT_WaterChanged:
case MT_ObstructionMapShapeChanged:
m_TerrainDirty = true;
MinimalTerrainUpdate();
UpdateGrid();
m_PreserveUpdateInformations = true;
break;
case MT_TurnStart:
m_SameTurnMovesCount = 0;
@@ -450,8 +454,12 @@ void CCmpPathfinder::UpdateGrid()
else
m_PreserveUpdateInformations = false; // Next time will be a regular update
u16 terrainSize = cmpTerrain->GetTilesPerSide();
if (terrainSize == 0)
return;
// If the terrain was resized then delete the old grid data
if (m_Grid && m_MapSize != cmpTerrain->GetTilesPerSide())
if (m_Grid && m_MapSize != terrainSize)
{
SAFE_DELETE(m_Grid);
SAFE_DELETE(m_TerrainOnlyGrid);
@@ -460,7 +468,7 @@ void CCmpPathfinder::UpdateGrid()
// Initialise the terrain data when first needed
if (!m_Grid)
{
m_MapSize = cmpTerrain->GetTilesPerSide();
m_MapSize = terrainSize;
m_Grid = new Grid<NavcellData>(m_MapSize * Pathfinding::NAVCELLS_PER_TILE, m_MapSize * Pathfinding::NAVCELLS_PER_TILE);
m_TerrainOnlyGrid = new Grid<NavcellData>(m_MapSize * Pathfinding::NAVCELLS_PER_TILE, m_MapSize * Pathfinding::NAVCELLS_PER_TILE);