From 50a7cf47700f7d938dd62e408c05f3fb92089ab8 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Sun, 17 Feb 2013 20:58:17 +0000 Subject: [PATCH] cleanup: refactor smoothTerrain() to make it side-effect free git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@538 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/Micropolis.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/micropolisj/engine/Micropolis.java b/src/micropolisj/engine/Micropolis.java index bc9db63..5b432b6 100644 --- a/src/micropolisj/engine/Micropolis.java +++ b/src/micropolisj/engine/Micropolis.java @@ -1155,7 +1155,7 @@ public class Micropolis pollutionAverage = pcount != 0 ? (ptotal / pcount) : 0; - smoothTerrain(qtem); + terrainMem = smoothTerrain(qtem); fireMapOverlayDataChanged(MapState.POLLUTE_OVERLAY); //PLMAP fireMapOverlayDataChanged(MapState.LANDVALUE_OVERLAY); //LVMAP @@ -1347,11 +1347,12 @@ public class Micropolis fireDemandChanged(); } - void smoothTerrain(int [][] qtem) + int [][] smoothTerrain(int [][] qtem) { final int QWX = qtem[0].length; final int QWY = qtem.length; + int [][] mem = new int[QWY][QWX]; for (int y = 0; y < QWY; y++) { for (int x = 0; x < QWX; x++) @@ -1365,9 +1366,10 @@ public class Micropolis z += qtem[y-1][x]; if (y+1 < QWY) z += qtem[y+1][x]; - terrainMem[y][x] = z / 4 + qtem[y][x] / 2; + mem[y][x] = z / 4 + qtem[y][x] / 2; } } + return mem; } // calculate manhatten distance (in 2-units) from center of city