(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements. NewGRF_ports
authorrichk
Mon, 16 Jul 2007 22:51:14 +0000
branchNewGRF_ports
changeset 6729 76133dcea48b
parent 6728 c0279f992578
child 6730 f09255ea0123
(svn r10599) [NewGRF_ports] -Change: Updated RemoveAirport function to work with either old or new style airport placements.
WARNING: this has highlighted bug where IsRailwayStation returns true for any graphic with id 0..7. So custom layouts trigger the wrong delete routine. To test; delete click on tower to trigger bug. Normal airport delete works OK clicking on helipad.
src/station_cmd.cpp
--- a/src/station_cmd.cpp	Mon Jul 16 22:47:52 2007 +0000
+++ b/src/station_cmd.cpp	Mon Jul 16 22:51:14 2007 +0000
@@ -1665,14 +1665,25 @@
 
 static CommandCost RemoveAirport(Station *st, uint32 flags)
 {
+	int w, h;
+	const FSMportsSpec *fsmportsspec;
+	const AirportFTAClass *afc;
+
 	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 		return CMD_ERROR;
 
 	TileIndex tile = st->airport_tile;
-
-	const AirportFTAClass *afc = st->Airport();
-	int w = afc->size_x;
-	int h = afc->size_y;
+	bool newfsmairport = IsCustomFSMportsSpecIndex(tile);
+
+	if (newfsmairport) {
+		fsmportsspec = st->fsmportsspeclist[GetCustomStationSpecIndex(tile)].spec;
+		w = fsmportsspec->width;
+		h = fsmportsspec->lengths;
+	} else {
+		afc = st->Airport();
+		w = afc->size_x;
+		h = afc->size_y;
+	}
 
 	CommandCost cost(w * h * _price.remove_airport);
 
@@ -1683,11 +1694,20 @@
 		if (v->u.air.targetairport == st->index && v->u.air.state != FLYING) return CMD_ERROR;
 	}
 
+	byte *layout_ptr;
+	byte layout;
+
+	if (newfsmairport) {
+		layout_ptr = (byte*)alloca(w * h);
+		GetFSMportsLayout(layout_ptr, w, h, fsmportsspec);
+	} else {
+		layout_ptr = (byte*)_airport_sections[st->airport_type];
+	}
+
 	{
-		const byte *b = _airport_sections[st->airport_type];
 		BEGIN_TILE_LOOP(tile_cur, w, h, tile)
-
-			if ((byte)*b++ != (byte)255) {
+			layout = *layout_ptr++;
+			if ((byte)layout != (byte)255) {
 				if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR;
 
 				if (flags & DC_EXEC) {
@@ -1699,10 +1719,12 @@
 	}
 
 	if (flags & DC_EXEC) {
-		for (uint i = 0; i < afc->nof_depots; ++i) {
-			DeleteWindowById(
-				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
-			);
+		if (!newfsmairport) {
+			for (uint i = 0; i < afc->nof_depots; ++i) {
+				DeleteWindowById(
+					WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
+				);
+			}
 		}
 
 		st->rect.AfterRemoveRect(st, tile, w, h);