(svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type. NewGRF_ports
authorrubidium
Tue, 21 Aug 2007 11:01:13 +0000
branchNewGRF_ports
changeset 6854 92ca286e9466
parent 6853 b3b8bb6c0a48
child 6855 233debbbe961
(svn r10957) [NewGRF_ports] -Codechange: reduce the dependency on AT_XXX enums and airport_type.
src/aircraft_cmd.cpp
src/airport.cpp
src/airport.h
src/fsmport.h
src/newgrf.cpp
src/newgrf_engine.cpp
src/openttd.cpp
src/station.h
src/station_cmd.cpp
--- a/src/aircraft_cmd.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/aircraft_cmd.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -1080,7 +1080,7 @@
 
 	/* prevent going to 0,0 if airport is deleted. */
 	TileIndex tile = st->airport_tile;
-	if ((tile == 0) || (st->airport_type == AT_OILRIG)) {
+	if ((tile == 0) || (st->Airport() == AirportFTAClass::oil_rig)) {
 		tile = st->xy;
 
 		/* Jump into our "holding pattern" state machine if possible */
@@ -1205,7 +1205,7 @@
 					v->y_pos;
 
 			/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
-			gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
+			gp.new_tile = (st->Airport() == AirportFTAClass::oil_rig) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
 
 		} else {
 
--- a/src/airport.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/airport.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -13,6 +13,9 @@
 #include "helpers.hpp"
 #include "newgrf_fsmports.h"
 
+/* static */ AirportFTAClass *AirportFTAClass::oil_rig; ///< "Special" holding pattern used for oil rigs.
+/* static */ AirportFTAClass *AirportFTAClass::dummy;   ///< A dummy holding pattern to be used when an airport has been removed, but the order to go to the airport has not been removed.
+
 /* Uncomment this to print out a full report of the airport-structure
  * You should either use
  * - true: full-report, print out every state and choice with string-names
--- a/src/airport.h	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/airport.h	Tue Aug 21 11:01:13 2007 +0000
@@ -74,6 +74,9 @@
 // Finite sTate mAchine --> FTA
 struct AirportFTAClass : FSMPortClass {
 public:
+	static AirportFTAClass *oil_rig; ///< "Special" holding pattern used for oil rigs.
+	static AirportFTAClass *dummy;   ///< A dummy holding pattern to be used when an airport has been removed, but the order to go to the airport has not been removed.
+
 	enum Flags {
 		AIRPLANES   = 0x1,
 		HELICOPTERS = 0x2,
@@ -82,7 +85,7 @@
 		SEAPLANES   = 0x8
 	};
 
-	AirportFTAClass() : FSMPortClass(), terminals(NULL), helipads(NULL), flags((Flags)0), entry_points(NULL) {}
+	AirportFTAClass(FSMportsSpec *spec) : FSMPortClass(spec), terminals(NULL), helipads(NULL), flags((Flags)0), entry_points(NULL) {}
 
 	~AirportFTAClass();
 
--- a/src/fsmport.h	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/fsmport.h	Tue Aug 21 11:01:13 2007 +0000
@@ -28,11 +28,13 @@
 	byte special;             ///< Used as extra data for special orders 7B, 7C, 7D, 7E
 };
 
+/** Forward declaration, as we need a circular dependancy */
+struct FSMportsSpec;
 
 struct FSMPortClass {
 public:
-	FSMPortClass() : moving_data(NULL), layout(NULL), nof_elements(0), depots(NULL),
-			nof_depots(0), size_x(0), size_y(0), delta_z(0), catchment(0) {}
+	FSMPortClass(FSMportsSpec *spec_) : moving_data(NULL), layout(NULL), nof_elements(0), depots(NULL),
+			nof_depots(0), size_x(0), size_y(0), delta_z(0), catchment(0), spec(spec_) {}
 
 	~FSMPortClass();
 
@@ -53,6 +55,8 @@
 	byte size_y;
 	byte delta_z;                         // Z adjustment for helicopter pads
 	byte catchment;
+
+	FSMportsSpec *spec;
 };
 
 #endif /* FSMPORT_H */
--- a/src/newgrf.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/newgrf.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -2111,7 +2111,7 @@
 				(*fsmportspec)->sclass = AllocateFSMportsClass(BSWAP32(classid));
 
 				/* create new AirportClass for this airport */
-				(*fsmportspec)->portFSM = new AirportFTAClass();
+				(*fsmportspec)->portFSM = new AirportFTAClass(*fsmportspec);
 
 			} break;
 
@@ -5890,6 +5890,10 @@
 
 	/* Update the townname generators list */
 	SortTownGeneratorNames();
+
+	/* Update references for oil rigs and dummy airport */
+	AirportFTAClass::oil_rig = GetCustomFSMportsSpecByGrf(0x4450414F, 3)->portFSM;
+	AirportFTAClass::dummy   = GetCustomFSMportsSpecByGrf(0x4450414F, 4)->portFSM;
 }
 
 void LoadNewGRF(uint load_index, uint file_index)
--- a/src/newgrf_engine.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/newgrf_engine.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -573,7 +573,7 @@
 
 				if (fps->flags & (AirportFTAClass::AIRPLANES | AirportFTAClass::SEAPLANES)) {
 					airporttype = (fps->flags & AirportFTAClass::SHORT_STRIP) ? ATP_TTDP_SMALL : ATP_TTDP_LARGE;
-				} else if (fps == GetCustomFSMportsSpecByGrf(0x4450414F, 3)) {
+				} else if (fps->portFSM == AirportFTAClass::oil_rig) {
 					airporttype = ATP_TTDP_OILRIG;
 				} else {
 					airporttype = ATP_TTDP_HELIPORT;
--- a/src/openttd.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/openttd.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -1336,14 +1336,6 @@
 	/* Update all waypoints */
 	if (CheckSavegameVersion(12)) FixOldWaypoints();
 
-	UpdateAllWaypointSigns();
-
-	UpdateAllStationVirtCoord();
-
-	/* Setup town coords */
-	AfterLoadTown();
-	UpdateAllSignVirtCoords();
-
 	/* make sure there is a town in the game */
 	if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
 		SetSaveLoadError(STR_NO_TOWN_IN_SCENARIO);
@@ -2206,6 +2198,12 @@
 		}
 	}
 
+	UpdateAllWaypointSigns();
+	UpdateAllStationVirtCoord();
+
+	/* Setup town coords */
+	AfterLoadTown();
+	UpdateAllSignVirtCoords();
 
 	return true;
 }
--- a/src/station.h	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/station.h	Tue Aug 21 11:01:13 2007 +0000
@@ -117,7 +117,7 @@
 
 		const AirportFTAClass *Airport() const
 		{
-			return (IsCustomFSMportsSpecIndex(airport_tile) ? fsmportsspeclist[1].spec : GetCustomFSMportsSpecByGrf(0x4450414F, 4))->portFSM;
+			return IsCustomFSMportsSpecIndex(airport_tile) ? fsmportsspeclist[1].spec->portFSM : AirportFTAClass::dummy;
 		}
 
 	TileIndex xy;
--- a/src/station_cmd.cpp	Tue Aug 21 09:02:06 2007 +0000
+++ b/src/station_cmd.cpp	Tue Aug 21 11:01:13 2007 +0000
@@ -371,7 +371,7 @@
 	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
 
 	pt.y -= 32;
-	if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16;
+	if (st->facilities & FACIL_AIRPORT && st->Airport() == AirportFTAClass::oil_rig) pt.y -= 16;
 
 	SetDParam(0, st->index);
 	SetDParam(1, st->facilities);
@@ -1559,7 +1559,7 @@
 		uint num = 0;
 		const Station *st;
 		FOR_ALL_STATIONS(st) {
-			if (st->town == t && st->facilities&FACIL_AIRPORT && st->airport_type != AT_OILRIG)
+			if (st->town == t && st->facilities & FACIL_AIRPORT && st->Airport() == AirportFTAClass::oil_rig)
 				num++;
 		}
 		if (num >= 2) {
@@ -2773,11 +2773,9 @@
 
 	st->owner = OWNER_NONE;
 	st->airport_flags.ResetAll();
-	st->airport_type = AT_OILRIG;
 
 	//add assignment of fsmportspec, and paint tile of North corner as fsmport
-	const FSMportsSpec *fsmportspec = GetCustomFSMportsSpecByGrf(0x4450414F, 3);
-	int fsmportspecindex = AllocateFSMportsSpecToStation(fsmportspec, st, true);
+	int fsmportspecindex = AllocateFSMportsSpecToStation(AirportFTAClass::oil_rig->spec, st, true);
 	SetCustomFSMportsSpecIndex(tile, fsmportspecindex);
 
 	st->xy = tile;