From 67948880263b63e87397949639947606ac87a01f Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Tue, 28 May 2013 01:52:27 +0000 Subject: [PATCH] tiles: helper functions- isFire, isRadioactive, isFlood git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@679 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/MapScanner.java | 45 +++++++++++------------ src/micropolisj/engine/TileConstants.java | 18 +++++++++ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/micropolisj/engine/MapScanner.java b/src/micropolisj/engine/MapScanner.java index 8cc58e4..aed4b23 100644 --- a/src/micropolisj/engine/MapScanner.java +++ b/src/micropolisj/engine/MapScanner.java @@ -39,34 +39,31 @@ class MapScanner */ public void scanTile() { + if (isFire(cchr)) + { + city.firePop++; + if (PRNG.nextInt(4) == 0) + { + // one in four times + doFire(); + } + return; + } + else if (isFlood(cchr)) + { + doFlood(); + return; + } + else if (isRadioactive(cchr)) + { + doRadioactiveTile(); + return; + } + cchr9 = (char) (cchr & LOMASK); if (cchr9 >= FLOOD) { - if (cchr9 < ROADBASE) - { - if (cchr9 >= FIREBASE) - { - city.firePop++; - if (PRNG.nextInt(4) == 0) - { - // one in four times - doFire(); - } - return; - } - - if (cchr9 < RADTILE) - { - doFlood(); - } - else - { - doRadioactiveTile(); - } - return; - } - if (city.newPower && ((cchr & CONDBIT) != 0)) { setZonePower(); diff --git a/src/micropolisj/engine/TileConstants.java b/src/micropolisj/engine/TileConstants.java index e5c5c01..63706ee 100644 --- a/src/micropolisj/engine/TileConstants.java +++ b/src/micropolisj/engine/TileConstants.java @@ -297,6 +297,18 @@ public class TileConstants && ((tile & BURNBIT) == 0)); } + public static boolean isFire(int tile) + { + int tmp = tile & LOMASK; + return (tmp >= FIREBASE && tmp < ROADBASE); + } + + public static boolean isRadioactive(int tile) + { + int tmp = tile & LOMASK; + return (tmp >= RADTILE && tmp < FIREBASE); + } + public static boolean isOverWater(char cell) { switch (cell & LOMASK) @@ -384,6 +396,12 @@ public class TileConstants return tile >= 0 && (tile & BULLBIT) != 0; } + public static boolean isFlood(int tile) + { + int tmp = tile & LOMASK; + return (tmp >= FLOOD && tmp < RADTILE); + } + static boolean isFloodable(int tile) { return (tile == DIRT || ((tile & BULLBIT) != 0 && (tile & BURNBIT) != 0));