diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index a098a267ac..4b6b0331a8 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -522,10 +522,10 @@ public: { this->DrawWidgets(); - DrawShipDepotSprite(this->GetWidget(BDDW_X)->pos_x + 64, this->GetWidget(BDDW_X)->pos_y + 18, 0); - DrawShipDepotSprite(this->GetWidget(BDDW_X)->pos_x + 32, this->GetWidget(BDDW_X)->pos_y + 34, 1); - DrawShipDepotSprite(this->GetWidget(BDDW_Y)->pos_x + 32, this->GetWidget(BDDW_Y)->pos_y + 18, 2); - DrawShipDepotSprite(this->GetWidget(BDDW_Y)->pos_x + 64, this->GetWidget(BDDW_Y)->pos_y + 34, 3); + DrawShipDepotSprite(this->GetWidget(BDDW_X)->pos_x + 64, this->GetWidget(BDDW_X)->pos_y + 18, AXIS_X, DEPOT_PART_NORTH); + DrawShipDepotSprite(this->GetWidget(BDDW_X)->pos_x + 32, this->GetWidget(BDDW_X)->pos_y + 34, AXIS_X, DEPOT_PART_SOUTH); + DrawShipDepotSprite(this->GetWidget(BDDW_Y)->pos_x + 32, this->GetWidget(BDDW_Y)->pos_y + 18, AXIS_Y, DEPOT_PART_NORTH); + DrawShipDepotSprite(this->GetWidget(BDDW_Y)->pos_x + 64, this->GetWidget(BDDW_Y)->pos_y + 34, AXIS_Y, DEPOT_PART_SOUTH); } virtual void OnClick(Point pt, int widget, int click_count) diff --git a/src/newgrf_canal.cpp b/src/newgrf_canal.cpp index b62698a7b5..d516684567 100644 --- a/src/newgrf_canal.cpp +++ b/src/newgrf_canal.cpp @@ -50,7 +50,7 @@ static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte case 0x80: { uint z = GetTileZ(tile) / TILE_HEIGHT; /* Return consistent height within locks */ - if (IsTileType(tile, MP_WATER) && IsLock(tile) && GetSection(tile) >= 8) z--; + if (IsTileType(tile, MP_WATER) && IsLock(tile) && GetLockPart(tile) == LOCK_PART_UPPER) z--; return z; } diff --git a/src/table/water_land.h b/src/table/water_land.h index c099413845..d3cb0a3f98 100644 --- a/src/table/water_land.h +++ b/src/table/water_land.h @@ -53,11 +53,15 @@ static const DrawTileSeqStruct _shipdepot_display_seq_4[] = { TILE_SEQ_END() }; -static const DrawTileSprites _shipdepot_display_data[] = { - TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_1) - TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_2) - TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_3) - TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_4) +static const DrawTileSprites _shipdepot_display_data[][DEPOT_PART_END] = { + { // AXIS_X + TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_1) // DEPOT_PART_NORTH + TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_2) // DEPOT_PART_SOUTH + }, + { // AXIS_Y + TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_3) // DEPOT_PART_NORTH + TILE_SPRITE_LINE(0xFDD, _shipdepot_display_seq_4) // DEPOT_PART_SOUTH + }, }; static const DrawTileSeqStruct _lock_display_seq_0[] = { @@ -132,21 +136,27 @@ static const DrawTileSeqStruct _lock_display_seq_3t[] = { TILE_SEQ_END() }; -static const DrawTileSprites _lock_display_data[] = { - TILE_SPRITE_LINE(1, _lock_display_seq_0) - TILE_SPRITE_LINE(0, _lock_display_seq_1) - TILE_SPRITE_LINE(2, _lock_display_seq_2) - TILE_SPRITE_LINE(3, _lock_display_seq_3) +static const DrawTileSprites _lock_display_data[][DIAGDIR_END] = { + { // LOCK_PART_MIDDLE + TILE_SPRITE_LINE(1, _lock_display_seq_0) // NE + TILE_SPRITE_LINE(0, _lock_display_seq_1) // SE + TILE_SPRITE_LINE(2, _lock_display_seq_2) // SW + TILE_SPRITE_LINE(3, _lock_display_seq_3) // NW + }, - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0b) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1b) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2b) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3b) + { // LOCK_PART_LOWER + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0b) // NE + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1b) // SE + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2b) // SW + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3b) // NW + }, - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0t) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1t) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2t) - TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3t) + { // LOCK_PART_UPPER + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_0t) // NE + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_1t) // SE + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_2t) // SW + TILE_SPRITE_LINE(0xFDD, _lock_display_seq_3t) // NW + }, }; #undef TILE_SEQ_LINE diff --git a/src/water.h b/src/water.h index db52600eeb..a5bb1c6292 100644 --- a/src/water.h +++ b/src/water.h @@ -15,6 +15,7 @@ #include "tile_type.h" #include "company_type.h" #include "slope_type.h" +#include "water_map.h" /** * Describes the behaviour of a tile during flooding. @@ -34,7 +35,7 @@ void DoFloodTile(TileIndex target); void ConvertGroundTilesIntoWaterTiles(); -void DrawShipDepotSprite(int x, int y, int image); +void DrawShipDepotSprite(int x, int y, Axis axis, DepotPart part); void DrawWaterClassGround(const struct TileInfo *ti); void DrawShoreTile(Slope tileh); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index b37636ccb9..5ac09a9b13 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -134,8 +134,8 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui Depot *depot = new Depot(tile); depot->build_date = _date; - MakeShipDepot(tile, _current_company, depot->index, DEPOT_NORTH, axis, wc1); - MakeShipDepot(tile2, _current_company, depot->index, DEPOT_SOUTH, axis, wc2); + MakeShipDepot(tile, _current_company, depot->index, DEPOT_PART_NORTH, axis, wc1); + MakeShipDepot(tile2, _current_company, depot->index, DEPOT_PART_SOUTH, axis, wc2); MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile2); MakeDefaultName(depot); @@ -426,16 +426,17 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) } case WATER_TILE_LOCK: { - static const TileIndexDiffC _lock_tomiddle_offs[] = { - { 0, 0}, {0, 0}, { 0, 0}, {0, 0}, // middle - {-1, 0}, {0, 1}, { 1, 0}, {0, -1}, // lower - { 1, 0}, {0, -1}, {-1, 0}, {0, 1}, // upper + static const TileIndexDiffC _lock_tomiddle_offs[][DIAGDIR_END] = { + /* NE SE SW NW */ + { { 0, 0}, {0, 0}, { 0, 0}, {0, 0} }, // LOCK_PART_MIDDLE + { {-1, 0}, {0, 1}, { 1, 0}, {0, -1} }, // LOCK_PART_LOWER + { { 1, 0}, {0, -1}, {-1, 0}, {0, 1} }, // LOCK_PART_UPPER }; if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); if (_current_company == OWNER_WATER) return CMD_ERROR; /* move to the middle tile.. */ - return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetSection(tile)]), flags); + return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetLockPart(tile)][GetLockDirection(tile)]), flags); } case WATER_TILE_DEPOT: @@ -641,8 +642,8 @@ static void DrawWaterTileStruct(const TileInfo *ti, const DrawTileSeqStruct *dts /** Draw a lock tile. */ static void DrawWaterLock(const TileInfo *ti) { - int section = GetSection(ti->tile); - const DrawTileSprites &dts = _lock_display_data[section]; + int part = GetLockPart(ti->tile); + const DrawTileSprites &dts = _lock_display_data[part][GetLockDirection(ti->tile)]; /* Draw ground sprite. */ SpriteID image = dts.ground.sprite; @@ -670,7 +671,7 @@ static void DrawWaterLock(const TileInfo *ti) if (base == 0) { /* If no custom graphics, use defaults. */ base = SPR_LOCK_BASE; - uint8 z_threshold = section >= 8 ? 8 : 0; + uint8 z_threshold = part == LOCK_PART_UPPER ? 8 : 0; zoffs = ti->z > z_threshold ? 24 : 0; } @@ -681,7 +682,7 @@ static void DrawWaterLock(const TileInfo *ti) static void DrawWaterDepot(const TileInfo *ti) { DrawWaterClassGround(ti); - DrawWaterTileStruct(ti, _shipdepot_display_data[GetSection(ti->tile)].seq, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END); + DrawWaterTileStruct(ti, _shipdepot_display_data[GetShipDepotAxis(ti->tile)][GetShipDepotPart(ti->tile)].seq, 0, 0, COMPANY_SPRITE_COLOUR(GetTileOwner(ti->tile)), CF_END); } static void DrawRiverWater(const TileInfo *ti) @@ -773,9 +774,9 @@ static void DrawTile_Water(TileInfo *ti) } } -void DrawShipDepotSprite(int x, int y, int image) +void DrawShipDepotSprite(int x, int y, Axis axis, DepotPart part) { - const DrawTileSprites &dts = _shipdepot_display_data[image]; + const DrawTileSprites &dts = _shipdepot_display_data[axis][part]; DrawSprite(dts.ground.sprite, dts.ground.pal, x, y); DrawOrigTileSeqInGUI(x, y, &dts, COMPANY_SPRITE_COLOUR(_local_company)); diff --git a/src/water_map.h b/src/water_map.h index 02838a6841..7233a73f85 100644 --- a/src/water_map.h +++ b/src/water_map.h @@ -15,6 +15,28 @@ #include "depot_type.h" #include "tile_map.h" +/** + * Bit field layout of m5 for water tiles. + */ +enum WaterTileTypeBitLayout { + WBL_TYPE_BEGIN = 4, ///< Start of the 'type' bitfield. + WBL_TYPE_COUNT = 4, ///< Length of the 'type' bitfield. + + WBL_TYPE_NORMAL = 0x0, ///< Clear water or coast ('type' bitfield). + WBL_TYPE_LOCK = 0x1, ///< Lock ('type' bitfield). + WBL_TYPE_DEPOT = 0x8, ///< Depot ('type' bitfield). + + WBL_COAST_FLAG = 0, ///< Flag for coast. + + WBL_LOCK_ORIENT_BEGIN = 0, ///< Start of lock orientiation bitfield. + WBL_LOCK_ORIENT_COUNT = 2, ///< Length of lock orientiation bitfield. + WBL_LOCK_PART_BEGIN = 2, ///< Start of lock part bitfield. + WBL_LOCK_PART_COUNT = 2, ///< Length of lock part bitfield. + + WBL_DEPOT_PART = 0, ///< Depot part flag. + WBL_DEPOT_AXIS = 1, ///< Depot axis flag. +}; + /** Available water tile types. */ enum WaterTileType { WATER_TILE_CLEAR, ///< Plain water. @@ -35,17 +57,16 @@ template <> struct EnumPropsT : MakeEnumPropsT