(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method. NewGRF_ports
authorrichk
Mon, 16 Jul 2007 21:11:29 +0000
branchNewGRF_ports
changeset 6724 cfa62b4744d4
parent 6723 5b28f7109fb6
child 6725 23339968083f
(svn r10594) [NewGRF_ports] -Fix: restored original airport placement functionality. You can now place an airport using newgrf, or using original method.
src/airport_gui.cpp
src/station_cmd.cpp
--- a/src/airport_gui.cpp	Mon Jul 16 13:37:33 2007 +0000
+++ b/src/airport_gui.cpp	Mon Jul 16 21:11:29 2007 +0000
@@ -56,7 +56,7 @@
 	//DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
 		DoCommandP(tile,
 				_railstation.orientation | (_railstation.numtracks << 8) | (_railstation.platlength << 16) | (_ctrl_pressed << 24),
-				_selected_airport_type | (_railstation.fsmports_class << 8) | (_railstation.station_type << 16), CcBuildAirport,
+				_selected_airport_type | ((_railstation.newstation_selected)? 0x80 : 0x00) | (_railstation.fsmports_class << 8) | (_railstation.station_type << 16), CcBuildAirport,
 				CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
 }
 
@@ -258,6 +258,7 @@
 		case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
 			RaiseWindowWidget(w, _selected_airport_type + 7);
 			_selected_airport_type = e->we.click.widget - 7;
+			_railstation.newstation_selected = false;
 			LowerWindowWidget(w, _selected_airport_type + 7);
 			SndPlayFx(SND_15_BEEP);
 			SetWindowDirty(w);
--- a/src/station_cmd.cpp	Mon Jul 16 13:37:33 2007 +0000
+++ b/src/station_cmd.cpp	Mon Jul 16 21:11:29 2007 +0000
@@ -1496,6 +1496,7 @@
  * - p1 = (bit 24)    - allow stations directly adjacent to other stations.
  * @param p2 various bitstuffed elements
  * - p2 = (bit  0- 3) - airport type
+ * - p2 = (bit  7)    - newstation (1) or original (0)
  * - p2 = (bit  8-15) - custom fsmport class
  * - p2 = (bit 16-23) - custom fsmport id
  */
@@ -1503,6 +1504,8 @@
 {
 	bool airport_upgrade = true;
 	const uint airport_type_for_flat_check = 0x80 | (GB(p2, 0, 4) << 3);
+	bool newfsmairport = (HASBIT(p2, 7));
+	byte original_airport_type = GB(p2, 0, 4);
 
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -1528,7 +1531,7 @@
 		}
 	}
 
-	const AirportFTAClass *afc = GetAirport(GB(p2, 0, 4));
+	const AirportFTAClass *afc = GetAirport(original_airport_type);
 	int w = afc->size_x;
 	int h = afc->size_y;
 
@@ -1540,7 +1543,7 @@
 	/* Check if we can allocate a custom stationspec to this station */
 	const FSMportsSpec *fsmportsspec = GetCustomFSMportsSpec((FSMportsClassID)GB(p2, 8, 8), GB(p2, 16, 8));
 
-	if (fsmportsspec != NULL) {
+	if (newfsmairport) {
 		/* Perform NewStation checks */
 		w = fsmportsspec->width;
 		h = fsmportsspec->lengths;
@@ -1610,10 +1613,12 @@
 
 	if (flags & DC_EXEC) {
 		byte *layout_ptr;
+		byte layout;
+		int fsmportspecindex;
 
 		st->airport_tile = tile;
 		st->AddFacility(FACIL_AIRPORT, tile);
-		st->airport_type = (byte)p1;
+		st->airport_type = (byte)original_airport_type;
 		st->airport_flags = 0;
 
 		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
@@ -1627,17 +1632,23 @@
 		 */
 		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
 
-		int fsmportspecindex = AllocateFSMportsSpecToStation(fsmportsspec, st, flags & DC_EXEC);
-		if (fsmportspecindex == -1) return CMD_ERROR;
-
-		layout_ptr = (byte*)alloca(w * h);
-		GetFSMportsLayout(layout_ptr, w, h, fsmportsspec);
+		if (newfsmairport) {
+			fsmportspecindex = AllocateFSMportsSpecToStation(fsmportsspec, st, flags & DC_EXEC);
+			if (fsmportspecindex == -1) return CMD_ERROR;
+
+			layout_ptr = (byte*)alloca(w * h);
+			GetFSMportsLayout(layout_ptr, w, h, fsmportsspec);
+		} else {
+			layout_ptr = (byte*)_airport_sections[original_airport_type];
+		}
 
 		{
 			BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
-				byte layout = *layout_ptr++;
+				layout = *layout_ptr++;
 				MakeAirport(tile_cur, st->owner, st->index, layout);
-				SetCustomFSMportsSpecIndex(tile_cur, fsmportspecindex);  //set top bit of m6 to indicate an fsmportsspec
+				if (newfsmairport) {
+					SetCustomFSMportsSpecIndex(tile_cur, fsmportspecindex);  //set top bit of m6 to indicate an fsmportsspec
+				}
 			} END_TILE_LOOP(tile_cur, w, h, tile)
 		}