(svn r10844) [NewGRF_ports] -Feature: Airports loaded from old savegames (prior to vsn74). Only applies currently to Small, Large, and Commuter.
Note: this just loads the airports. It does not correct any aircraft.
--- a/src/newgrf_config.cpp Thu Aug 09 03:14:06 2007 +0000
+++ b/src/newgrf_config.cpp Fri Aug 10 18:31:08 2007 +0000
@@ -480,6 +480,21 @@
}
}
+/* Adds a GRF from the global _all_grfs list to the list for the current game.
+ * Useful for adding compulsory grfs to older games.
+ */
+void AddGRFTToGameListByGRFid(uint32 grfid)
+{
+ /* Copy GRF details from scanned list */
+ GRFConfig *c = CallocT<GRFConfig>(1);
+ const GRFConfig *src = FindGRFConfig(grfid, NULL); // OAPD - airportsbasic.grf
+ *c = *src;
+ c->filename = strdup(src->filename);
+ if (src->name != NULL) c->name = strdup(src->name);
+ if (src->info != NULL) c->info = strdup(src->info);
+ c->next = NULL;
+ AppendToGRFConfigList(&_grfconfig, c);
+}
static void Load_NGRF()
{
@@ -490,6 +505,12 @@
AppendToGRFConfigList(&_grfconfig, c);
}
+ if (CheckSavegameVersion(74)) {
+ /* before doing tile tests, ensure mandatory newgrfs loaded */
+ AddGRFTToGameListByGRFid(0x4450414F); // OAPD - airportsbasic.grf
+ AddGRFTToGameListByGRFid(0x5850414F); // OAPX - airportsextended.grf
+ }
+
/* Append static NewGRF configuration */
AppendStaticGRFConfigs(&_grfconfig);
}
--- a/src/openttd.cpp Thu Aug 09 03:14:06 2007 +0000
+++ b/src/openttd.cpp Fri Aug 10 18:31:08 2007 +0000
@@ -67,6 +67,7 @@
#include "sound/sound_driver.hpp"
#include "music/music_driver.hpp"
#include "video/video_driver.hpp"
+#include "newgrf_fsmports.h"
#include "bridge_map.h"
#include "clear_map.h"
@@ -89,6 +90,8 @@
extern void ShowOSErrorBox(const char *buf);
extern void SetDefaultRailGui();
+extern void GetFSMportsLayout(byte *layout, int width, int length, const FSMportsSpec *fsmportspec, byte set);
+
const char *_default_blitter = "8bpp-optimized";
/* TODO: usrerror() for errors which are not of an internal nature but
@@ -1237,6 +1240,31 @@
return rt >= min ? (RailType)(rt + 1): rt;
}
+void ResetAirportToNewGRFSpec(TileIndex tile, Station *st, uint32 grfid, uint8 localidx)
+{
+ const FSMportsSpec *fsmportspec = GetCustomFSMportsSpecByGrf(grfid, localidx);
+ int fsmportspecindex = AllocateFSMportsSpecToStation(fsmportspec, st, true);
+
+ /* find layout tiletype corresponding to location on airport */
+ TileIndexDiffC tile_offset = TileIndexToTileIndexDiffC(tile, st->airport_tile);
+ int w = fsmportspec->size_x[0]; //old airports are always 0th graphics set orientation... ie NE
+ int h = fsmportspec->size_y[0];
+ byte *layout_ptr = (byte*)alloca((w * h) + 2);
+ GetFSMportsLayout(layout_ptr, w, h, fsmportspec, 0);
+ st->FSMport_orientation = *layout_ptr++; //orientation
+ layout_ptr++; //skip minipic ID
+ for (byte skip = 0; skip < (tile_offset.y * w + tile_offset.x); skip++)
+ {
+ layout_ptr++; //skip to the correct layout tiletype
+ }
+
+ /* replace the savegame layout tiletype with the newgrf one */
+ MakeAirport(tile, st->owner, st->index, *layout_ptr);
+
+ /*set top bit of m6 to indicate an fsmportsspec */
+ SetCustomFSMportsSpecIndex(tile, fsmportspecindex);
+}
+
bool AfterLoadGame()
{
TileIndex map_size = MapSize();
@@ -1453,6 +1481,38 @@
break;
}
+ case STATION_AIRPORT: {
+ /* if savegame is prior to introduction of fsmportspecs, and it is an airport, convert to fsmport */
+ if (CheckSavegameVersion(74)) {
+ /* things to sort out:
+ * a) assign appropriate default fsmportspec to airport
+ * b) mark each tile as part of an fsmportspec
+ * c) maybe replace tile graphics with newgrf ones, to hook all airports into new definitions
+ * d) when aircraft are loaded, they will need updating
+ */
+ switch (st->airport_type) {
+ case AT_SMALL:
+ {
+ ResetAirportToNewGRFSpec(t, st, 0x4450414F, 0);
+ }
+ break;
+ case AT_LARGE:
+ {
+ ResetAirportToNewGRFSpec(t, st, 0x4450414F, 1);
+ }
+ break;
+ case AT_COMMUTER:
+ {
+ ResetAirportToNewGRFSpec(t, st, 0x5850414F, 0);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ }
+
default: break;
}
break;
--- a/src/station_cmd.cpp Thu Aug 09 03:14:06 2007 +0000
+++ b/src/station_cmd.cpp Fri Aug 10 18:31:08 2007 +0000
@@ -1528,7 +1528,7 @@
return ret;
}
-static void GetFSMportsLayout(byte *layout, int width, int length, const FSMportsSpec *fsmportspec, byte set)
+void GetFSMportsLayout(byte *layout, int width, int length, const FSMportsSpec *fsmportspec, byte set)
{
if (fsmportspec != NULL) {
/* Custom layout defined, follow it. */