mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r4172) -Codechange: Added a few accessors to work with ShipDepots and Locks
This commit is contained in:
parent
24f23babd1
commit
8a91805c05
25
water_cmd.c
25
water_cmd.c
|
@ -41,14 +41,6 @@ const SpriteID _water_shore_sprites[15] = {
|
|||
|
||||
static void FloodVehicle(Vehicle *v);
|
||||
|
||||
static bool IsClearWaterTile(TileIndex tile)
|
||||
{
|
||||
return
|
||||
IsTileType(tile, MP_WATER) &&
|
||||
_m[tile].m5 == 0 &&
|
||||
GetTileSlope(tile, NULL) == 0;
|
||||
}
|
||||
|
||||
/** Build a ship depot.
|
||||
* @param x,y tile coordinates where ship depot is built
|
||||
* @param p1 depot direction (0 == X or 1 == Y)
|
||||
|
@ -103,16 +95,17 @@ static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
|
|||
{
|
||||
TileIndex tile2;
|
||||
|
||||
if (!IsShipDepot(tile)) return CMD_ERROR;
|
||||
if (!CheckTileOwnership(tile)) return CMD_ERROR;
|
||||
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||
|
||||
tile2 = tile + ((_m[tile].m5 & 2) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
||||
tile2 = GetOtherShipDepotTile(tile);
|
||||
|
||||
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Kill the depot */
|
||||
DoDeleteDepot(tile);
|
||||
/* Kill the depot, which is registered at the northernmost tile. Use that one */
|
||||
DoDeleteDepot(tile2 < tile ? tile2 : tile);
|
||||
|
||||
MakeWater(tile);
|
||||
MakeWater(tile2);
|
||||
|
@ -156,7 +149,7 @@ static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
|
|||
|
||||
static int32 RemoveShiplift(TileIndex tile, uint32 flags)
|
||||
{
|
||||
TileIndexDiff delta = TileOffsByDir(GB(_m[tile].m5, 0, 2));
|
||||
TileIndexDiff delta = TileOffsByDir(GetLockDirection(tile));
|
||||
|
||||
// make sure no vehicle is on the tile.
|
||||
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
|
||||
|
@ -322,14 +315,6 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
|
|||
// ship depot
|
||||
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
||||
|
||||
switch (m5) {
|
||||
case 0x80: break;
|
||||
case 0x81: tile -= TileDiffXY(1, 0); break;
|
||||
case 0x82: break;
|
||||
case 0x83: tile -= TileDiffXY(0, 1); break;
|
||||
default: return CMD_ERROR;
|
||||
}
|
||||
|
||||
return RemoveShipDepot(tile, flags);
|
||||
}
|
||||
}
|
||||
|
|
28
water_map.h
28
water_map.h
|
@ -5,7 +5,8 @@
|
|||
|
||||
typedef enum DepotPart {
|
||||
DEPOT_NORTH = 0x80,
|
||||
DEPOT_SOUTH = 0x81
|
||||
DEPOT_SOUTH = 0x81,
|
||||
DEPOT_END = 0x84,
|
||||
} DepotPart;
|
||||
|
||||
typedef enum LockPart {
|
||||
|
@ -14,6 +15,30 @@ typedef enum LockPart {
|
|||
LOCK_UPPER = 0x18
|
||||
} LockPart;
|
||||
|
||||
static inline bool IsClearWaterTile(TileIndex tile)
|
||||
{
|
||||
return
|
||||
IsTileType(tile, MP_WATER) &&
|
||||
_m[tile].m5 == 0 &&
|
||||
GetTileSlope(tile, NULL) == 0;
|
||||
}
|
||||
|
||||
static inline TileIndex GetOtherShipDepotTile(TileIndex t)
|
||||
{
|
||||
return t + (HASBIT(_m[t].m5, 0) ? -1 : 1) * (HASBIT(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
||||
}
|
||||
|
||||
static inline TileIndex IsShipDepot(TileIndex t)
|
||||
{
|
||||
return IS_INT_INSIDE(_m[t].m5, DEPOT_NORTH, DEPOT_END);
|
||||
}
|
||||
|
||||
static inline DiagDirection GetLockDirection(TileIndex t)
|
||||
{
|
||||
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
||||
}
|
||||
|
||||
|
||||
static inline void MakeWater(TileIndex t)
|
||||
{
|
||||
SetTileType(t, MP_WATER);
|
||||
|
@ -24,7 +49,6 @@ static inline void MakeWater(TileIndex t)
|
|||
_m[t].m5 = 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void MakeShore(TileIndex t)
|
||||
{
|
||||
SetTileType(t, MP_WATER);
|
||||
|
|
Loading…
Reference in New Issue