Loading

Revision differences

Old revision #pammldfgxNew revision #p68rqetdr
1    /* Make sure there are no adjacent or incompatible ship docking areas */  1/**
2    TileIndex tile_adj;  2 * Is this tile a target for ships to get to a nearby dock?
3    Axis axis_cur = DiagDirToAxis(direction);  3 * @param tile Tile to query
   4 * @param diagdir Optional diagonal direction to look for axis compatibility.
   5 * @return True if the tile is a target for ships to get to a nearby dock.
   6 * @note If the axis of the provided diagdir is parallel to the axis of a nearby
   7 *       dock station, this function returns False. If diagdir is not provided,
   8 *       only tile locations are compared.
   9 */
   10bool IsTileDock(TileIndex tile, DiagDirection diagdir = INVALID_DIAGDIR)
   11{
   12    Axis axis = diagdir == INVALID_DIAGDIR ? INVALID_AXIS : DiagDirToAxis(diagdir);
4  13  
5    if (axis_cur == AXIS_Y) {  14    for (DiagDirection rot = DIAGDIR_BEGIN; rot < DIAGDIR_END; rot++) {
6        tile_adj = tile_cur + TileDiffXY(-2, 0);  15        TileIndex tc = TileAddByDiagDir(tile, rot);
7        if (IsTileType(tile_adj, MP_STATION) && IsOilRig(tile_adj)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);  16        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);  17            Station *dock = Station::GetByTile(tc);
   18            TileIndex docking_location = TILE_ADD(dock->dock_tile, ToTileIndexDiff(GetDockOffset(dock->dock_tile)));
   19            if (axis == INVALID_AXIS) {
   20                return tile == docking_location;
   21            }
   22            else {
   23                if (tile == docking_location) {
   24                    Axis axis_tc = DiagDirToAxis(rot);
   25                    return axis != axis_tc;
   26                }
   27            }
   28        }
   29        if (rot == DIAGDIR_NE && IsTileType(tc + TileDiffXY(-1, 0), MP_INDUSTRY) && GetIndustryGfx(tc + TileDiffXY(-1, 0)) == GFX_OILRIG_1) return true;
9    }  30    }  
10  31  
11    tile_adj = tile_cur + (axis_cur == AXIS_X ? TileDiffXY(0, -1) : TileDiffXY(1, 0));  11    return false;
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    }