mirror of https://github.com/OpenTTD/OpenTTD
(svn r4252) -Codechange: Make more use of map accessors. water_cmd is now map access free
parent
b4d9a37acc
commit
89c145b14e
88
water_cmd.c
88
water_cmd.c
|
@ -266,56 +266,58 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
static int32 ClearTile_Water(TileIndex tile, byte flags)
|
static int32 ClearTile_Water(TileIndex tile, byte flags)
|
||||||
{
|
{
|
||||||
byte m5 = _m[tile].m5;
|
switch (GetWaterTileType(tile)) {
|
||||||
|
case WATER_CLEAR:
|
||||||
|
if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
||||||
|
|
||||||
if (m5 <= 1) { // water and shore
|
// Make sure no vehicle is on the tile
|
||||||
// Allow building on water? It's ok to build on shores.
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
if (flags & DC_NO_WATER && m5 != 1)
|
|
||||||
return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
|
|
||||||
|
|
||||||
// Make sure no vehicle is on the tile
|
// Make sure it's not an edge tile.
|
||||||
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
|
||||||
|
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
|
||||||
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure it's not an edge tile.
|
|
||||||
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
|
|
||||||
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
|
|
||||||
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m5 == 0) {
|
|
||||||
if (flags & DC_EXEC) DoClearSquare(tile);
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
||||||
return _price.clear_water;
|
return _price.clear_water;
|
||||||
} else if (m5 == 1) {
|
case WATER_COAST:
|
||||||
uint slope = GetTileSlope(tile,NULL);
|
{
|
||||||
|
uint slope = GetTileSlope(tile, NULL);
|
||||||
|
|
||||||
if (flags & DC_EXEC) DoClearSquare(tile);
|
// Make sure no vehicle is on the tile
|
||||||
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) {
|
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
|
||||||
return _price.clear_water;
|
|
||||||
} else {
|
// Make sure it's not an edge tile.
|
||||||
return _price.purchase_land;
|
if (!IS_INT_INSIDE(TileX(tile), 1, MapMaxX() - 1) ||
|
||||||
|
!IS_INT_INSIDE(TileY(tile), 1, MapMaxY() - 1)) {
|
||||||
|
return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & DC_EXEC) DoClearSquare(tile);
|
||||||
|
if (slope == 8 || slope == 4 || slope == 2 || slope == 1) {
|
||||||
|
return _price.clear_water;
|
||||||
|
} else {
|
||||||
|
return _price.purchase_land;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
case WATER_LOCK:
|
||||||
return CMD_ERROR;
|
{
|
||||||
}
|
static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
|
||||||
} else if ((m5 & 0x10) == 0x10) {
|
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle
|
||||||
// shiplift
|
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower
|
||||||
|
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper
|
||||||
|
};
|
||||||
|
|
||||||
static const TileIndexDiffC _shiplift_tomiddle_offs[] = {
|
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
||||||
{ 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle
|
if (_current_player == OWNER_WATER) return CMD_ERROR;
|
||||||
{-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower
|
// move to the middle tile..
|
||||||
{ 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper
|
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[GetSection(tile)]), flags);
|
||||||
};
|
}
|
||||||
|
case WATER_DEPOT:
|
||||||
|
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
||||||
|
|
||||||
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
return RemoveShipDepot(tile, flags);
|
||||||
// don't allow water to delete it.
|
|
||||||
if (_current_player == OWNER_WATER) return CMD_ERROR;
|
|
||||||
// move to the middle tile..
|
|
||||||
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags);
|
|
||||||
} else {
|
|
||||||
// ship depot
|
|
||||||
if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
|
|
||||||
|
|
||||||
return RemoveShipDepot(tile, flags);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,12 +419,12 @@ static void DrawTile_Water(TileInfo *ti)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WATER_LOCK: {
|
case WATER_LOCK: {
|
||||||
const WaterDrawTileStruct *t = _shiplift_display_seq[ti->map5 & 0xF];
|
const WaterDrawTileStruct *t = _shiplift_display_seq[GetSection(ti->tile)];
|
||||||
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
|
DrawWaterStuff(ti, t, 0, ti->z > t[3].delta_y ? 24 : 0);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case WATER_DEPOT:
|
case WATER_DEPOT:
|
||||||
DrawWaterStuff(ti, _shipdepot_display_seq[ti->map5 & 0x7F], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
|
DrawWaterStuff(ti, _shipdepot_display_seq[GetSection(ti->tile)], PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,12 @@ static inline DiagDirection GetLockDirection(TileIndex t)
|
||||||
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline byte GetSection(TileIndex t)
|
||||||
|
{
|
||||||
|
assert(GetWaterTileType(t) == WATER_LOCK || GetWaterTileType(t) == WATER_DEPOT);
|
||||||
|
return GB(_m[t].m5, 0, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void MakeWater(TileIndex t)
|
static inline void MakeWater(TileIndex t)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue