diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index ecba1df29a..511df3aebb 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -225,9 +225,13 @@ void GetAircraftSpriteSize(EngineID engine, uint &width, uint &height) CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) { const AircraftVehicleInfo *avi = &e->u.air; + const Station *st = Station::GetByTile(tile); /* Prevent building aircraft types at places which can't handle them */ - if (!CanVehicleUseStation(e->index, Station::GetByTile(tile))) return CMD_ERROR; + if (!CanVehicleUseStation(e->index, st)) return CMD_ERROR; + + /* Make sure all aircraft end up in the first tile of the hanger. */ + tile = st->airport.GetHangarTile(st->airport.GetHangarNum(tile)); if (flags & DC_EXEC) { Aircraft *v = new Aircraft(); // aircraft diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index f2becb60f1..4475a8e055 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -613,6 +613,7 @@ bool Ship::Tick() */ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret) { + tile = GetShipDepotNorthTile(tile); if (flags & DC_EXEC) { int x; int y; diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 45b6e36749..e5b5df6cd4 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -137,7 +137,7 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint v->unitnumber = unit_num; v->value = value.GetCost(); - InvalidateWindowData(WC_VEHICLE_DEPOT, tile); + InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0); SetWindowDirty(WC_COMPANY, _current_company); if (IsLocalCompany()) { diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 3c0e6ee2ff..78d190d692 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -172,7 +172,6 @@ static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags) } if (flags & DC_EXEC) { - /* Kill the depot, which is registered at the northernmost tile. Use that one */ delete Depot::GetByTile(tile); MakeWaterKeepingClass(tile, GetTileOwner(tile)); @@ -1180,9 +1179,7 @@ static TrackStatus GetTileTrackStatus_Water(TileIndex tile, TransportType mode, static bool ClickTile_Water(TileIndex tile) { if (GetWaterTileType(tile) == WATER_TILE_DEPOT) { - TileIndex tile2 = GetOtherShipDepotTile(tile); - - ShowDepotWindow(tile < tile2 ? tile : tile2, VEH_SHIP); + ShowDepotWindow(GetShipDepotNorthTile(tile), VEH_SHIP); return true; } return false; diff --git a/src/water_map.h b/src/water_map.h index 55e2730a5c..83c3a055f4 100644 --- a/src/water_map.h +++ b/src/water_map.h @@ -197,6 +197,19 @@ static inline DiagDirection GetShipDepotDirection(TileIndex t) return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1)); } +/** + * Get the most northern tile of a ship depot. + * @param tile One of the tiles of the ship depot. + * @return The northern tile of the depot. + */ +static TileIndex GetShipDepotNorthTile(TileIndex t) +{ + assert(IsShipDepot(t)); + TileIndex tile2 = GetOtherShipDepotTile(t); + + return t < tile2 ? t : tile2; +} + /** * Is it a water lock tile? * @param t Water tile to query.