summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clear_cmd.c13
-rw-r--r--main_gui.c7
-rw-r--r--town_cmd.c6
-rw-r--r--unmovable_cmd.c41
-rw-r--r--unmovable_map.h65
5 files changed, 95 insertions, 37 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index 364e7733b..e11565b75 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -13,6 +13,7 @@
#include "tunnel_map.h"
#include "variables.h"
#include "table/sprites.h"
+#include "unmovable_map.h"
typedef struct TerraformerHeightMod {
TileIndex tile;
@@ -379,18 +380,16 @@ int32 CmdPurchaseLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
- if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 3 &&
- IsTileOwner(tile, _current_player))
+ if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
+ }
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
if (flags & DC_EXEC) {
- ModifyTile(tile,
- MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
- 3 /* map5 */
- );
+ MakeOwnedLand(tile, _current_player);
+ MarkTileDirtyByTile(tile);
}
return cost + _price.purchase_land * 10;
@@ -435,7 +434,7 @@ int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile = TileVirtXY(x, y);
- if (!IsTileType(tile, MP_UNMOVABLE) || _m[tile].m5 != 3) return CMD_ERROR;
+ if (!IsOwnedLandTile(tile)) return CMD_ERROR;
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
diff --git a/main_gui.c b/main_gui.c
index 6c6614e02..afdbbff7d 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -27,6 +27,7 @@
#include "waypoint.h"
#include "variables.h"
#include "train.h"
+#include "unmovable_map.h"
#include "network_data.h"
#include "network_client.h"
@@ -1207,7 +1208,8 @@ static void PlaceProc_LightHouse(TileIndex tile)
return;
}
- ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 1);
+ MakeLighthouse(tile);
+ MarkTileDirtyByTile(tile);
SndPlayTileFx(SND_1F_SPLAT, tile);
}
@@ -1217,7 +1219,8 @@ static void PlaceProc_Transmitter(TileIndex tile)
return;
}
- ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAP5, 0);
+ MakeTransmitter(tile);
+ MarkTileDirtyByTile(tile);
SndPlayTileFx(SND_1F_SPLAT, tile);
}
diff --git a/town_cmd.c b/town_cmd.c
index c9eede7c8..34af05731 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -21,6 +21,7 @@
#include "saveload.h"
#include "economy.h"
#include "gui.h"
+#include "unmovable_map.h"
#include "variables.h"
enum {
@@ -1577,9 +1578,8 @@ static bool DoBuildStatueOfCompany(TileIndex tile)
if (CmdFailed(r)) return false;
- ModifyTile(tile, MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5,
- 2 /* map5 */
- );
+ MakeStatue(tile, _current_player);
+ MarkTileDirtyByTile(tile);
return true;
}
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index 23e11ab50..9a9643a75 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -15,6 +15,7 @@
#include "economy.h"
#include "town.h"
#include "sprite.h"
+#include "unmovable_map.h"
#include "variables.h"
/** Destroy a HQ.
@@ -184,7 +185,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
static uint GetSlopeZ_Unmovable(const TileInfo* ti)
{
- if (_m[ti->tile].m5 == 3) {
+ if (IsOwnedLand(ti->tile)) {
return ti->z + GetPartialZ(ti->x & 0xF, ti->y & 0xF, ti->tileh);
} else {
return ti->z + (ti->tileh == 0 ? 0 : 8);
@@ -193,20 +194,19 @@ static uint GetSlopeZ_Unmovable(const TileInfo* ti)
static uint GetSlopeTileh_Unmovable(const TileInfo *ti)
{
- return _m[ti->tile].m5 == 3 ? ti->tileh : 0;
+ return IsOwnedLand(ti->tile) ? ti->tileh : 0;
}
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
{
- byte m5 = _m[tile].m5;
-
- if (m5 & 0x80) {
+ if (_m[tile].m5 & 0x80) {
if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
}
- if (m5 == 3) // company owned land
+ if (IsOwnedLand(tile)) {
return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
+ }
// checks if you're allowed to remove unmovable things
if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
@@ -245,19 +245,16 @@ static void GetAcceptedCargo_Unmovable(TileIndex tile, AcceptedCargo ac)
ac[CT_MAIL] = max(1, level / 2);
}
-static const StringID _unmovable_tile_str[] = {
- STR_5803_COMPANY_HEADQUARTERS,
- STR_5801_TRANSMITTER,
- STR_5802_LIGHTHOUSE,
- STR_2016_STATUE,
- STR_5805_COMPANY_OWNED_LAND,
-};
static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td)
{
- int i = _m[tile].m5;
- if (i & 0x80) i = -1;
- td->str = _unmovable_tile_str[i + 1];
+ switch (GetUnmovableType(tile)) {
+ case UNMOVABLE_TRANSMITTER: td->str = STR_5801_TRANSMITTER; break;
+ case UNMOVABLE_LIGHTHOUSE: td->str = STR_5802_LIGHTHOUSE; break;
+ case UNMOVABLE_STATUE: td->str = STR_2016_STATUE; break;
+ case UNMOVABLE_OWNED_LAND: td->str = STR_5805_COMPANY_OWNED_LAND; break;
+ default: td->str = STR_5803_COMPANY_HEADQUARTERS; break;
+ }
td->owner = GetTileOwner(tile);
}
@@ -321,9 +318,7 @@ static bool checkRadioTowerNearby(TileIndex tile)
TileIndex tile_s = tile - TileDiffXY(4, 4);
BEGIN_TILE_LOOP(tile, 9, 9, tile_s)
- // already a radio tower here?
- if (IsTileType(tile, MP_UNMOVABLE) && _m[tile].m5 == 0)
- return false;
+ if (IsTransmitterTile(tile)) return false;
END_TILE_LOOP(tile, 9, 9, tile_s)
return true;
}
@@ -345,9 +340,7 @@ void GenerateUnmovables(void)
tile = RandomTile();
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == 0 && h >= 32) {
if (!checkRadioTowerNearby(tile)) continue;
- SetTileType(tile, MP_UNMOVABLE);
- SetTileOwner(tile, OWNER_NONE);
- _m[tile].m5 = 0;
+ MakeTransmitter(tile);
if (--j == 0) break;
}
} while (--i);
@@ -380,9 +373,7 @@ restart:
assert(tile == TILE_MASK(tile));
- SetTileType(tile, MP_UNMOVABLE);
- SetTileOwner(tile, OWNER_NONE);
- _m[tile].m5 = 1;
+ MakeLighthouse(tile);
} while (--i);
}
diff --git a/unmovable_map.h b/unmovable_map.h
new file mode 100644
index 000000000..32375c2cd
--- /dev/null
+++ b/unmovable_map.h
@@ -0,0 +1,65 @@
+/* $Id$ */
+
+typedef enum UnmovableType {
+ UNMOVABLE_TRANSMITTER = 0,
+ UNMOVABLE_LIGHTHOUSE = 1,
+ UNMOVABLE_STATUE = 2,
+ UNMOVABLE_OWNED_LAND = 3
+} UnmovableType;
+
+
+static inline UnmovableType GetUnmovableType(TileIndex t)
+{
+ return _m[t].m5;
+}
+
+
+static inline bool IsTransmitterTile(TileIndex t)
+{
+ return
+ IsTileType(t, MP_UNMOVABLE) &&
+ GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
+}
+
+
+static inline bool IsOwnedLand(TileIndex t)
+{
+ return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
+}
+
+static inline bool IsOwnedLandTile(TileIndex t)
+{
+ return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
+}
+
+
+static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
+{
+ SetTileType(t, MP_UNMOVABLE);
+ SetTileOwner(t, o);
+ _m[t].m2 = 0;
+ _m[t].m3 = 0;
+ _m[t].m4 = 0;
+ _m[t].m5 = u;
+}
+
+
+static inline void MakeTransmitter(TileIndex t)
+{
+ MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
+}
+
+static inline void MakeLighthouse(TileIndex t)
+{
+ MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
+}
+
+static inline void MakeStatue(TileIndex t, Owner o)
+{
+ MakeUnmovable(t, UNMOVABLE_STATUE, o);
+}
+
+static inline void MakeOwnedLand(TileIndex t, Owner o)
+{
+ MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
+}