| 1 | /* Make sure there are no adjacent or incompatible ship docking areas */
| 1 | /**
|
|---|
| 2 | TileIndex tile_adj;
| 2 | * Ensure this tile is not a target for ships to get to a nearby dock.
|
|---|
| 3 | Axis axis_cur = DiagDirToAxis(direction);
| 3 | * @note Also takes into account Oil Rigs under construction.
|
|---|
| | | 4 | * @param tile Tile to query
|
|---|
| | | 5 | * @param diagdir Optional diagonal direction to look for axis compatibility.
|
|---|
| | | 6 | * @return Succeeded if the tile is not a ship docking area of a nearby dock,
|
|---|
| | | 7 | * or an error message if the tile is a ship docking area of a nearby
|
|---|
| | | 8 | dock.
|
|---|
| | | 9 | * @note If the axis of a provided diagdir is equal to the axis of a nearby
|
|---|
| | | 10 | * docking area, it returns Succeeded. If diagdir is not provided, only
|
|---|
| | | 11 | * the docking area location is ensured.
|
|---|
| | | 12 | */
|
|---|
| | | 13 | CommandCost EnsureNoDockingTile(TileIndex tile, DiagDirection diagdir = INVALID_DIAGDIR)
|
|---|
| | | 14 | {
|
|---|
| | | 15 | Axis axis = diagdir == INVALID_DIAGDIR ? INVALID_AXIS : DiagDirToAxis(diagdir);
|
|---|
| 5 | if (axis_cur == AXIS_Y) {
| 17 | for (DiagDirection rot = DIAGDIR_BEGIN; rot < DIAGDIR_END; rot++) {
|
|---|
| 6 | tile_adj = tile_cur + TileDiffXY(-2, 0);
| 18 | TileIndex tc = TileAddByDiagDir(tile, rot);
|
|---|
| 7 | if (IsTileType(tile_adj, MP_STATION) && IsOilRig(tile_adj)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
| 19 | if (IsTileType(tc, MP_STATION) && (IsDock(tc) || IsOilRig(tc))) {
|
|---|
| 8 | if (IsTileType(tile_adj, MP_INDUSTRY) && GetIndustryGfx(tile_adj) == GFX_OILRIG_1) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
| 20 | Station *dock = Station::GetByTile(tc);
|
|---|
| | | 21 | TileIndex docking_location = TILE_ADD(dock->dock_tile, ToTileIndexDiff(GetDockOffset(dock->dock_tile)));
|
|---|
| | | 22 | if (axis == INVALID_AXIS) {
|
|---|
| | | 23 | return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
|
|---|
| | | 24 | } else {
|
|---|
| | | 25 | if (tile == docking_location) {
|
|---|
| | | 26 | Axis axis_tc = DiagDirToAxis(rot);
|
|---|
| | | 27 | if (axis != axis_tc) {
|
|---|
| | | 28 | return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
|
|---|
| | | 29 | }
|
|---|
| | | 30 | }
|
|---|
| | | 31 | }
|
|---|
| | | 32 | }
|
|---|
| | | 33 | if (axis != AXIS_X && DiagDirToAxis(rot) == AXIS_X) {
|
|---|
| | | 34 | if (IsTileType(tc + TileDiffXY(-1, 0), MP_INDUSTRY) && GetIndustryGfx(tc + TileDiffXY(-1, 0)) == GFX_OILRIG_1) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
|---|
| | | 35 | }
|
|---|
| 11 | tile_adj = tile_cur + (axis_cur == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));
| 11 | return CommandCost();
|
|---|
| 12 | if (IsDockTile(tile_adj)) {
| 12 | } |
|---|
| 13 | Station *st = Station::GetByTile(tile_adj);
| | |
|---|
| 14 | tile_adj = st->dock_tile;
| | |
|---|
| 15 | Axis axis_adj = DiagDirToAxis(GetDockDirection(tile_adj));
| | |
|---|
| 16 | if (axis_cur != axis_adj) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
| | |
|---|
| 17 | }
| | |
|---|
| 18 |
| | |
|---|
| 19 | tile_adj = tile_cur - (axis_cur == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));
| | |
|---|
| 20 | if (IsDockTile(tile_adj)) {
| | |
|---|
| 21 | Station *st = Station::GetByTile(tile_adj);
| | |
|---|
| 22 | tile_adj = st->dock_tile;
| | |
|---|
| 23 | Axis axis_adj = DiagDirToAxis(GetDockDirection(tile_adj));
| | |
|---|
| 24 | if (axis_cur != axis_adj) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
| | |
|---|
| 25 | } | | |
|---|