From 873caa361b473ba6ea8913ee6b803d5b3568db55 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Tue, 28 May 2013 01:55:58 +0000 Subject: [PATCH] cleanup: move tile value comparisons into TileConstants class git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@688 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/MapScanner.java | 9 ++++--- src/micropolisj/engine/TileConstants.java | 33 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/micropolisj/engine/MapScanner.java b/src/micropolisj/engine/MapScanner.java index 5d6dbc0..4f79153 100644 --- a/src/micropolisj/engine/MapScanner.java +++ b/src/micropolisj/engine/MapScanner.java @@ -428,30 +428,31 @@ class MapScanner city.unpoweredZoneCount++; } - if (cchr9 > PORTBASE) + if (isSpecialZone(cchr)) { doSpecialZone(zonePwrFlag); return; } - if (cchr9 < HOSPITAL) + if (isResidentialZone(cchr)) { doResidential(zonePwrFlag); return; } - if (cchr9 < COMBASE) + if (isHospitalOrChurch(cchr)) { doHospitalChurch(zonePwrFlag); return; } - if (cchr9 < INDBASE) + if (isCommercialZone(cchr)) { doCommercial(zonePwrFlag); return; } + assert isIndustrialZone(cchr); doIndustrial(zonePwrFlag); return; } diff --git a/src/micropolisj/engine/TileConstants.java b/src/micropolisj/engine/TileConstants.java index fa9cd43..b057b98 100644 --- a/src/micropolisj/engine/TileConstants.java +++ b/src/micropolisj/engine/TileConstants.java @@ -428,6 +428,39 @@ public class TileConstants return (tmp >= RAILBASE && tmp < RESBASE); } + public static boolean isCommercialZone(int tile) + { + assert isZoneCenter(tile); + return (tile & LOMASK) >= COMBASE && + (tile & LOMASK) < INDBASE; + } + + public static boolean isHospitalOrChurch(int tile) + { + assert isZoneCenter(tile); + return (tile & LOMASK) >= HOSPITAL && + (tile & LOMASK) < COMBASE; + } + + public static boolean isIndustrialZone(int tile) + { + assert isZoneCenter(tile); + return (tile & LOMASK) >= INDBASE && + (tile & LOMASK) < PORTBASE; + } + + public static boolean isResidentialZone(int tile) + { + assert isZoneCenter(tile); + return (tile & LOMASK) < HOSPITAL; + } + + public static boolean isSpecialZone(int tile) + { + assert isZoneCenter(tile); + return (tile & LOMASK) >= PORTBASE; + } + public static boolean isZoneCenter(int tile) { return tile >= 0 && (tile & ZONEBIT) != 0;