scanTile: use annotations in tiles.rc to determine behavior of tiles

git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@832 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
jason@long.name 2013-09-01 21:34:06 +00:00
parent 070cd90727
commit bef75adc90
3 changed files with 194 additions and 193 deletions

View file

@ -33,51 +33,70 @@ class MapScanner
this.PRNG = city.PRNG;
}
static enum TileBehavior
{
FIRE,
FLOOD,
RADIOACTIVE,
ROAD,
RAIL,
EXPLOSION,
RESIDENTIAL,
HOSPITAL_CHURCH,
COMMERCIAL,
INDUSTRIAL,
SPECIAL;
}
/**
* Activate the tile identified by xpos and ypos properties.
*/
public void scanTile()
{
if (isFire(cchr))
{
doFire();
return;
}
else if (isFlood(cchr))
{
doFlood();
return;
}
else if (isRadioactive(cchr))
{
doRadioactiveTile();
return;
}
cchr9 = (char) (cchr & LOMASK);
if (isRoad(cchr))
{
String behaviorStr = getTileBehavior(cchr);
if (behaviorStr == null) {
return;
}
switch (TileBehavior.valueOf(behaviorStr)) {
case FIRE:
doFire();
return;
case FLOOD:
doFlood();
return;
case RADIOACTIVE:
doRadioactiveTile();
return;
case ROAD:
doRoad();
return;
}
if (isZoneCenter(cchr))
{
doZone();
return;
}
if (isRail(cchr))
{
case RAIL:
doRail();
return;
}
if (isTinyExplosion(cchr))
{
case EXPLOSION:
// clear AniRubble
city.setTile(xpos, ypos, (char)(RUBBLE + PRNG.nextInt(4) + BULLBIT));
return;
case RESIDENTIAL:
doResidential();
return;
case HOSPITAL_CHURCH:
doHospitalChurch();
return;
case COMMERCIAL:
doCommercial();
return;
case INDUSTRIAL:
doIndustrial();
return;
case SPECIAL:
doSpecialZone();
return;
default:
throw new Error("Unknown behavior: "+behaviorStr);
}
}
@ -409,34 +428,6 @@ class MapScanner
}
}
/**
* Called when the current tile is the key tile of any zone.
*/
void doZone()
{
if (isSpecialZone(cchr))
{
doSpecialZone();
}
else if (isResidentialZone(cchr))
{
doResidential();
}
else if (isHospitalOrChurch(cchr))
{
doHospitalChurch();
}
else if (isCommercialZone(cchr))
{
doCommercial();
}
else
{
assert isIndustrialZone(cchr);
doIndustrial();
}
}
boolean checkZonePower()
{
boolean zonePwrFlag = setZonePower();

View file

@ -242,6 +242,14 @@ public class TileConstants
}
}
//used by scanTile
public static String getTileBehavior(int tile)
{
tile &= LOMASK;
TileSpec ts = Tiles.get(tile);
return ts != null ? ts.getAttribute("behavior") : null;
}
//used by queryZoneStatus
public static int getDescriptionNumber(int tile)
{