(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
authortron
Sat, 20 May 2006 15:13:27 +0000
changeset 3876 c0d426e78b56
parent 3875 f6c32ef22e50
child 3877 53efa8118448
(svn r4918) Move the information about the size of airports from an global array into the struct which describes an airport
ai/default/default.c
airport.c
airport.h
airport_gui.c
station_cmd.c
variables.h
--- a/ai/default/default.c	Sat May 20 08:12:59 2006 +0000
+++ b/ai/default/default.c	Sat May 20 15:13:27 2006 +0000
@@ -3328,8 +3328,9 @@
 
 	for (; p->mode == 0; p++) {
 		TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
-		uint w = _airport_size_x[p->attr];
-		uint h = _airport_size_y[p->attr];
+		const AirportFTAClass* airport = GetAirport(p->attr);
+		uint w = airport->size_x;
+		uint h = airport->size_y;
 
 		if (cargo & 0x80) {
 			GetProductionAroundTiles(values, tile2, w, h, rad);
--- a/airport.c	Sat May 20 08:12:59 2006 +0000
+++ b/airport.c	Sat May 20 15:13:27 2006 +0000
@@ -20,7 +20,9 @@
 																				const byte *terminals, const byte *helipads,
 																				const byte entry_point,  const byte acc_planes,
 																				const AirportFTAbuildup *FA,
-																				const TileIndexDiffC *depots, const byte nof_depots);
+																				const TileIndexDiffC *depots, const byte nof_depots,
+	uint size_x, uint size_y
+);
 static void AirportFTAClass_Destructor(AirportFTAClass *Airport);
 
 static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
@@ -42,7 +44,8 @@
 		ALL,
 		_airport_fta_country,
 		_airport_depots_country,
-		lengthof(_airport_depots_country)
+		lengthof(_airport_depots_country),
+		4, 3
 	);
 
 	// city airport
@@ -56,7 +59,8 @@
 		ALL,
 		_airport_fta_city,
 		_airport_depots_city,
-		lengthof(_airport_depots_city)
+		lengthof(_airport_depots_city),
+		6, 6
 	);
 
 	// metropolitan airport
@@ -70,7 +74,8 @@
 		ALL,
 		_airport_fta_metropolitan,
 		_airport_depots_metropolitan,
-		lengthof(_airport_depots_metropolitan)
+		lengthof(_airport_depots_metropolitan),
+		6, 6
 	);
 
 	// international airport
@@ -84,7 +89,8 @@
 		ALL,
 		_airport_fta_international,
 		_airport_depots_international,
-		lengthof(_airport_depots_international)
+		lengthof(_airport_depots_international),
+		7, 7
 	);
 
 	// heliport, oilrig
@@ -98,7 +104,8 @@
 		HELICOPTERS_ONLY,
 		_airport_fta_heliport_oilrig,
 		NULL,
-		0
+		0,
+		1, 1
 	);
 
 	Oilrig = Heliport;  // exactly the same structure for heliport/oilrig, so share state machine
@@ -117,7 +124,9 @@
 																				const byte *terminals, const byte *helipads,
 																				const byte entry_point, const byte acc_planes,
 																				const AirportFTAbuildup *FA,
-																				const TileIndexDiffC *depots, const byte nof_depots)
+																				const TileIndexDiffC *depots, const byte nof_depots,
+	uint size_x, uint size_y
+)
 {
 	byte nofterminals, nofhelipads;
 	byte nofterminalgroups = 0;
@@ -126,6 +135,9 @@
 	int i;
 	nofterminals = nofhelipads = 0;
 
+	Airport->size_x = size_x;
+	Airport->size_y = size_y;
+
 	//now we read the number of terminals we have
 	if (terminals != NULL) {
 		i = terminals[0];
--- a/airport.h	Sat May 20 08:12:59 2006 +0000
+++ b/airport.h	Sat May 20 15:13:27 2006 +0000
@@ -105,6 +105,8 @@
 	const TileIndexDiffC *airport_depots; // gives the position of the depots on the airports
 	byte nof_depots;                      // number of depots this airport has
 	struct AirportFTA *layout;            // state machine for airport
+	byte size_x;
+	byte size_y;
 } AirportFTAClass;
 
 // internal structure used in openttd - Finite sTate mAchine --> FTA
--- a/airport_gui.c	Sat May 20 08:12:59 2006 +0000
+++ b/airport_gui.c	Sat May 20 15:13:27 2006 +0000
@@ -147,6 +147,7 @@
 		int sel;
 		int rad = 4; // default catchment radious
 		uint32 avail_airports;
+		const AirportFTAClass* airport;
 
 		if (WP(w,def_d).close) return;
 
@@ -164,7 +165,8 @@
 		_selected_airport_type = sel;
 		// select default the coverage area to 'Off' (8)
 		w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage);
-		SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]);
+		airport = GetAirport(sel);
+		SetTileSelectSize(airport->size_x, airport->size_y);
 
 		if (_patches.modified_catchment) {
 			switch (sel) {
--- a/station_cmd.c	Sat May 20 08:12:59 2006 +0000
+++ b/station_cmd.c	Sat May 20 15:13:27 2006 +0000
@@ -78,11 +78,6 @@
 MemoryPool _roadstop_pool = { "RoadStop", ROADSTOP_POOL_MAX_BLOCKS, ROADSTOP_POOL_BLOCK_SIZE_BITS, sizeof(RoadStop), &RoadStopPoolNewBlock, NULL, 0, 0, NULL };
 
 
-// FIXME -- need to be embedded into Airport variable. Is dynamically
-// deducteable from graphics-tile array, so will not be needed
-const byte _airport_size_x[] = {4, 6, 1, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
-const byte _airport_size_y[] = {3, 6, 1, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
-
 void ShowAircraftDepotWindow(TileIndex tile);
 extern void UpdateAirplanesOnNewStation(Station *st);
 
@@ -689,12 +684,11 @@
 	}
 
 	if (st->airport_tile != 0) {
+		const AirportFTAClass* afc = GetAirport(st->airport_type);
+
 		MergePoint(&rect, st->airport_tile);
 		MergePoint(&rect,
-			st->airport_tile + TileDiffXY(
-				_airport_size_x[st->airport_type] - 1,
-				_airport_size_y[st->airport_type] - 1
-			)
+			st->airport_tile + TileDiffXY(afc->size_x - 1, afc->size_y - 1)
 		);
 	}
 
@@ -1599,6 +1593,7 @@
 	int32 ret;
 	int w, h;
 	bool airport_upgrade = true;
+	const AirportFTAClass* afc;
 
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
@@ -1623,8 +1618,9 @@
 		}
 	}
 
-	w = _airport_size_x[p1];
-	h = _airport_size_y[p1];
+	afc = GetAirport(p1);
+	w = afc->size_x;
+	h = afc->size_y;
 
 	ret = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
 	if (CmdFailed(ret)) return ret;
@@ -1672,8 +1668,6 @@
 	cost += _price.build_airport * w * h;
 
 	if (flags & DC_EXEC) {
-		const AirportFTAClass *afc = GetAirport(p1);
-
 		st->owner = _current_player;
 		if (IsLocalPlayer() && afc->nof_depots != 0)
 			_last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]);
@@ -1717,14 +1711,16 @@
 	TileIndex tile;
 	int w,h;
 	int32 cost;
+	const AirportFTAClass* afc;
 
 	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 		return CMD_ERROR;
 
 	tile = st->airport_tile;
 
-	w = _airport_size_x[st->airport_type];
-	h = _airport_size_y[st->airport_type];
+	afc = GetAirport(st->airport_type);
+	w = afc->size_x;
+	h = afc->size_y;
 
 	cost = w * h * _price.remove_airport;
 
@@ -1738,7 +1734,6 @@
 	} END_TILE_LOOP(tile_cur, w,h,tile)
 
 	if (flags & DC_EXEC) {
-		const AirportFTAClass *afc = GetAirport(st->airport_type);
 		uint i;
 
 		for (i = 0; i < afc->nof_depots; ++i) {
--- a/variables.h	Sat May 20 08:12:59 2006 +0000
+++ b/variables.h	Sat May 20 15:13:27 2006 +0000
@@ -403,12 +403,6 @@
 
 extern const TileTypeProcs * const _tile_type_procs[16];
 
-/* station_cmd.c */
-// there are 5 types of airport (Country (3x4) , City(6x6), Metropolitan(6x6), International(7x7), Heliport(1x1)
-// will become obsolete once airports are loaded from seperate file
-extern const byte _airport_size_x[];
-extern const byte _airport_size_y[];
-
 /* misc */
 VARDEF char _screenshot_name[128];
 VARDEF byte _vehicle_design_names;