summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c10
-rw-r--r--industry_cmd.c8
-rw-r--r--landscape.c4
-rw-r--r--rail_cmd.c2
-rw-r--r--road_cmd.c2
-rw-r--r--terraform_gui.c2
-rw-r--r--tile.c12
-rw-r--r--tile.h31
-rw-r--r--town_cmd.c2
-rw-r--r--tree_cmd.c26
-rw-r--r--tunnelbridge_cmd.c2
11 files changed, 59 insertions, 42 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index e11565b75..aea144127 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -603,13 +603,13 @@ static void TileLoopClearDesert(TileIndex tile)
{
if (IsClearGround(tile, CL_DESERT)) return;
- if (GetMapExtraBits(tile) == 1) {
+ if (GetTropicZone(tile) == TROPICZONE_DESERT) {
SetClearGroundDensity(tile, CL_DESERT, 3);
} else {
- if (GetMapExtraBits(tile + TileDiffXY( 1, 0)) != 1 &&
- GetMapExtraBits(tile + TileDiffXY(-1, 0)) != 1 &&
- GetMapExtraBits(tile + TileDiffXY( 0, 1)) != 1 &&
- GetMapExtraBits(tile + TileDiffXY( 0, -1)) != 1)
+ if (GetTropicZone(tile + TileDiffXY( 1, 0)) != TROPICZONE_DESERT &&
+ GetTropicZone(tile + TileDiffXY(-1, 0)) != TROPICZONE_DESERT &&
+ GetTropicZone(tile + TileDiffXY( 0, 1)) != TROPICZONE_DESERT &&
+ GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT)
return;
SetClearGroundDensity(tile, CL_DESERT, 1);
}
diff --git a/industry_cmd.c b/industry_cmd.c
index d7f3170f9..66b6f2334 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1031,7 +1031,7 @@ static void ChopLumberMillTrees(Industry *i)
SndPlayTileFx(SND_38_CHAINSAW, tile);
DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
- SetMapExtraBits(tile, 0);
+ SetTropicZone(tile, TROPICZONE_INVALID);
i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45);
@@ -1181,7 +1181,7 @@ static bool CheckNewIndustry_Farm(TileIndex tile, int type)
static bool CheckNewIndustry_Plantation(TileIndex tile, int type)
{
- if (GetMapExtraBits(tile) == 1) {
+ if (GetTropicZone(tile) == TROPICZONE_DESERT) {
_error_message = STR_0239_SITE_UNSUITABLE;
return false;
}
@@ -1191,7 +1191,7 @@ static bool CheckNewIndustry_Plantation(TileIndex tile, int type)
static bool CheckNewIndustry_Water(TileIndex tile, int type)
{
- if (GetMapExtraBits(tile) != 1) {
+ if (GetTropicZone(tile) != TROPICZONE_DESERT) {
_error_message = STR_0318_CAN_ONLY_BE_BUILT_IN_DESERT;
return false;
}
@@ -1201,7 +1201,7 @@ static bool CheckNewIndustry_Water(TileIndex tile, int type)
static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type)
{
- if (GetMapExtraBits(tile) != 2) {
+ if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) {
_error_message = STR_0317_CAN_ONLY_BE_BUILT_IN_RAINFOREST;
return false;
}
diff --git a/landscape.c b/landscape.c
index 85aa36665..4ba7f12e4 100644
--- a/landscape.c
+++ b/landscape.c
@@ -590,7 +590,7 @@ static void CreateDesertOrRainForest(void)
if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
}
if (data == endof(_make_desert_or_rainforest_data))
- SetMapExtraBits(tile, 1);
+ SetTropicZone(tile, TROPICZONE_DESERT);
}
for (i = 0; i != 256; i++)
@@ -603,7 +603,7 @@ static void CreateDesertOrRainForest(void)
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CL_DESERT)) break;
}
if (data == endof(_make_desert_or_rainforest_data))
- SetMapExtraBits(tile, 2);
+ SetTropicZone(tile, TROPICZONE_RAINFOREST);
}
}
diff --git a/rail_cmd.c b/rail_cmd.c
index 47831ba7e..1f61b7e6f 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1814,7 +1814,7 @@ static void TileLoop_Track(TileIndex tile)
break;
case LT_DESERT:
- if (GetMapExtraBits(tile) == 1) { /* convert into desert? */
+ if (GetTropicZone(tile) == TROPICZONE_DESERT) { /* convert into desert? */
new_ground = RAIL_GROUND_ICE_DESERT;
goto modify_me;
}
diff --git a/road_cmd.c b/road_cmd.c
index 8d40381c5..7affafbb9 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -920,7 +920,7 @@ static void TileLoop_Road(TileIndex tile)
break;
case LT_DESERT:
- if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+ if (GetTropicZone(tile) == TROPICZONE_DESERT && !(_m[tile].m4 & 0x80)) {
_m[tile].m4 |= 0x80;
MarkTileDirtyByTile(tile);
}
diff --git a/terraform_gui.c b/terraform_gui.c
index b7570c159..9a37bbc10 100644
--- a/terraform_gui.c
+++ b/terraform_gui.c
@@ -55,7 +55,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
_generating_world = true;
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
if (GetTileType(tile) != MP_WATER) {
- SetMapExtraBits(tile, (_ctrl_pressed) ? 0 : 1);
+ SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_INVALID : TROPICZONE_DESERT);
DoCommandP(tile, 0, 0, NULL, CMD_LANDSCAPE_CLEAR);
MarkTileDirtyByTile(tile);
}
diff --git a/tile.c b/tile.c
index f18932c3f..7ab92b664 100644
--- a/tile.c
+++ b/tile.c
@@ -3,18 +3,6 @@
#include "stdafx.h"
#include "tile.h"
-void SetMapExtraBits(TileIndex tile, byte bits)
-{
- assert(tile < MapSize());
- SB(_m[tile].extra, 0, 2, bits & 3);
-}
-
-uint GetMapExtraBits(TileIndex tile)
-{
- assert(tile < MapSize());
- return GB(_m[tile].extra, 0, 2);
-}
-
/** Converts the heights of 4 corners into a tileh, and returns the minimum height of the tile
* @param n,w,e,s the four corners
* @param h uint pointer to write the height to
diff --git a/tile.h b/tile.h
index e3a0d45d6..81bb6d0a0 100644
--- a/tile.h
+++ b/tile.h
@@ -20,9 +20,11 @@ typedef enum TileTypes {
MP_UNMOVABLE,
} TileType;
-
-void SetMapExtraBits(TileIndex tile, byte flags);
-uint GetMapExtraBits(TileIndex tile);
+typedef enum TropicZones {
+ TROPICZONE_INVALID = 0,
+ TROPICZONE_DESERT = 1,
+ TROPICZONE_RAINFOREST = 2,
+} TropicZone;
uint GetTileh(uint n, uint w, uint e, uint s, uint *h);
uint GetTileSlope(TileIndex tile, uint *h);
@@ -106,4 +108,27 @@ static inline bool IsTileOwner(TileIndex tile, Owner owner)
return GetTileOwner(tile) == owner;
}
+/**
+ * Set the tropic zone
+ * @param tile the tile to set the zone of
+ * @param type the new type
+ * @pre assert(tile < MapSize());
+ */
+static inline void SetTropicZone(TileIndex tile, TropicZone type)
+{
+ assert(tile < MapSize());
+ SB(_m[tile].extra, 0, 2, type);
+}
+
+/**
+ * Get the tropic zone
+ * @param tile the tile to get the zone of
+ * @pre assert(tile < MapSize());
+ * @return the zone type
+ */
+static inline TropicZone GetTropicZone(TileIndex tile)
+{
+ assert(tile < MapSize());
+ return (TropicZone)GB(_m[tile].extra, 0, 2);
+}
#endif /* TILE_H */
diff --git a/town_cmd.c b/town_cmd.c
index 8c31c54f2..694d93197 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1762,7 +1762,7 @@ static void UpdateTownGrowRate(Town *t)
if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90)
return;
} else if (_opt.landscape == LT_DESERT) {
- if (GetMapExtraBits(t->xy) == 1 && (t->act_food==0 || t->act_water==0) && t->population > 60)
+ if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60)
return;
}
diff --git a/tree_cmd.c b/tree_cmd.c
index be6b3d5ca..28290c7fe 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -26,10 +26,10 @@ static TreeType GetRandomTreeType(TileIndex tile, uint seed)
return seed * TR_COUNT_SUB_ARCTIC / 256 + TR_SUB_ARCTIC;
case LT_DESERT:
- switch (GetMapExtraBits(tile)) {
- case 0: return seed * TR_COUNT_SUB_TROPICAL / 256 + TR_SUB_TROPICAL;
- case 1: return (seed > 12) ? TR_INVALID : TR_CACTUS;
- default: return seed * TR_COUNT_RAINFOREST / 256 + TR_RAINFOREST;
+ switch (GetTropicZone(tile)) {
+ case TROPICZONE_INVALID: return seed * TR_COUNT_SUB_TROPICAL / 256 + TR_SUB_TROPICAL;
+ case TROPICZONE_DESERT: return (seed > 12) ? TR_INVALID : TR_CACTUS;
+ default: return seed * TR_COUNT_RAINFOREST / 256 + TR_RAINFOREST;
}
default:
@@ -105,7 +105,7 @@ void PlaceTreesRandomly(void)
do {
uint32 r = Random();
TileIndex tile = RandomTileSeed(r);
- if (IsTileType(tile, MP_CLEAR) && GetMapExtraBits(tile) == 2) {
+ if (IsTileType(tile, MP_CLEAR) && GetTropicZone(tile) == TROPICZONE_RAINFOREST) {
PlaceTree(tile, r);
}
} while (--i);
@@ -208,7 +208,7 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
MarkTileDirtyByTile(tile);
if (_game_mode == GM_EDITOR && IS_INT_INSIDE(treetype, TR_RAINFOREST, TR_CACTUS))
- SetMapExtraBits(tile, 2);
+ SetTropicZone(tile, TROPICZONE_RAINFOREST);
}
cost += _price.build_trees;
break;
@@ -376,15 +376,15 @@ static void AnimateTile_Trees(TileIndex tile)
static void TileLoopTreesDesert(TileIndex tile)
{
- switch (GetMapExtraBits(tile)) {
- case 1:
+ switch (GetTropicZone(tile)) {
+ case TROPICZONE_DESERT:
if (GetTreeGround(tile) != TR_SNOW_DESERT) {
SetTreeGroundDensity(tile, TR_SNOW_DESERT, 3);
MarkTileDirtyByTile(tile);
}
break;
- case 2: {
+ case TROPICZONE_RAINFOREST: {
static const SoundFx forest_sounds[] = {
SND_42_LOON_BIRD,
SND_43_LION,
@@ -396,6 +396,8 @@ static void TileLoopTreesDesert(TileIndex tile)
if (CHANCE16I(1, 200, r)) SndPlayTileFx(forest_sounds[GB(r, 16, 2)], tile);
break;
}
+
+ default: break;
}
}
@@ -452,7 +454,9 @@ static void TileLoop_Trees(TileIndex tile)
switch (GetTreeGrowth(tile)) {
case 3: /* regular sized tree */
- if (_opt.landscape == LT_DESERT && GetTreeType(tile) != TR_CACTUS && GetMapExtraBits(tile) == 1) {
+ if (_opt.landscape == LT_DESERT &&
+ GetTreeType(tile) != TR_CACTUS &&
+ GetTropicZone(tile) == TROPICZONE_DESERT) {
AddTreeGrowth(tile, 1);
} else {
switch (GB(Random(), 0, 3)) {
@@ -526,7 +530,7 @@ void OnTick_Trees(void)
/* place a tree at a random rainforest spot */
if (_opt.landscape == LT_DESERT &&
- (r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
+ (r = Random(), tile = RandomTileSeed(r), GetTropicZone(tile) == TROPICZONE_RAINFOREST) &&
IsTileType(tile, MP_CLEAR) &&
(ct = GetClearGround(tile), ct == CL_GRASS || ct == CL_ROUGH) &&
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TR_INVALID) {
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index d218e1596..68cc8246a 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -1225,7 +1225,7 @@ static void TileLoop_TunnelBridge(TileIndex tile)
break;
case LT_DESERT:
- if (GetMapExtraBits(tile) == 1 && !(_m[tile].m4 & 0x80)) {
+ if (GetTropicZone(tile) == TROPICZONE_DESERT && !(_m[tile].m4 & 0x80)) {
_m[tile].m4 |= 0x80;
MarkTileDirtyByTile(tile);
}