changeset 15877:82c114e71a7d draft

(svn r20559) -Fix [FS#4045]: make sure that all vehicles are build in the most northern depot/hangar tile
author yexo <yexo@openttd.org>
date Thu, 19 Aug 2010 13:44:41 +0000
parents 625f70985d01
children 4904a2bf3864
files src/aircraft_cmd.cpp src/ship_cmd.cpp src/vehicle_cmd.cpp src/water_cmd.cpp src/water_map.h
diffstat 5 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -225,9 +225,13 @@
 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
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -613,6 +613,7 @@
  */
 CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
 {
+	tile = GetShipDepotNorthTile(tile);
 	if (flags & DC_EXEC) {
 		int x;
 		int y;
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -137,7 +137,7 @@
 		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()) {
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -172,7 +172,6 @@
 	}
 
 	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 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;
--- a/src/water_map.h
+++ b/src/water_map.h
@@ -198,6 +198,19 @@
 }
 
 /**
+ * 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.
  * @return \c true if it is a water lock tile.