(svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games. NewGRF_ports
authorrichk
Sun, 12 Aug 2007 14:04:32 +0000
branchNewGRF_ports
changeset 6793 1574da7d2297
parent 6792 5dacbc63db85
child 6794 592e0b01dcea
(svn r10865) [NewGRF_ports] -Feature: Added oilrig. Reloads correctly for old games.
-Add: Added SYST class for system (hidden) FSMs (like oilrigs), that should not appear in the build lists.
bin/data/airportsbasic.grf
bin/data/sprites/airportsbasic.nfo
src/aircraft_cmd.cpp
src/newgrf_fsmports.cpp
src/newgrf_fsmports.h
src/openttd.cpp
src/station_cmd.cpp
Binary file bin/data/airportsbasic.grf has changed
--- a/bin/data/sprites/airportsbasic.nfo	Sun Aug 12 12:33:25 2007 +0000
+++ b/bin/data/sprites/airportsbasic.nfo	Sun Aug 12 14:04:32 2007 +0000
@@ -1,7 +1,7 @@
 // Automatically generated by GRFCODEC. Do not modify!
 // (Info version 7)
 // Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel
-    0 * 4	 26 00 00 00
+    0 * 4	 2A 00 00 00
 
 // Length of GRF in sprites
 // if version of TTDPatch higher than X, skip two sprites
@@ -40,7 +40,7 @@
 //        Small Airport
 //----------------------------
 // 11 properties to change, 1 station to change, station id = 0
-   15 * 656	 00 0D 0C 01 00
+   15 * 656	 00 0D 0B 01 00
 
 // Class ID
 	08 "SMLL"
@@ -268,7 +268,7 @@
 // Large Airport
 //------------------------------
 // 11 properties to change, 1 airport to change, airport id = 1
-   16 * 1086	 00 0D 0C 01 01
+   16 * 1086	 00 0D 0B 01 01
 
 // Class ID
 	08 "LRGE"
@@ -809,19 +809,127 @@
    26 * 7	 03 0D 01 02 00 06 00
 
 
+//-------------------------
+// Oilrig
+//-------------------------
+
+// 10 properties to change, 1 station to change, station id = 03
+   27 * 189	 00 0D 09 01 03
+
+// Class ID
+	08 "SYST"
+
+// Prop0B Callbacks
+		0B 01 //Availability
+
+// Define custom layouts
+		0E 01
+			01
+			00 00 00
+
+// Prop19 Vehicle Type
+		19 03 //Air
+
+// Define Finite State Machine
+		1A 09  // positions 00-08
+
+	// Oilrig : Position 00
+	\w32 \w9 \w54 25 \wx0003 25  // HELIPAD1
+		02
+			25 25 00 01
+			51 00 00 01
+
+	// Oilrig : Position 01
+	\w28 \w9 \w80 51 \wx0000 00  // HELITAKEOFF
+		01
+			00 00 25 00
+
+	// Oilrig : Position 02
+	\w28 \w9 \w80 00 \wx0030 00
+		02
+			54 00 00 03
+			51 00 00 01
+
+	// Oilrig : Position 03
+	\w28 \w9 \w80 54 \wx0000 00  // HELILANDING
+		01
+			00 00 00 04
+
+	// Oilrig : Position 04
+	\w28 \w9 \w54 55 \wx0000 00  // HELIENDLANDING
+		03
+			25 25 00 00
+			51 00 00 02
+			00 00 00 04
+
+	// Oilrig : Position 05
+	\wxFFE1 \w69 \w80 00 \wx00B0 00
+		01
+			00 00 00 06
+
+	// Oilrig : Position 06
+	\wxFFE1 \wxFFCF \w80 00 \wx00B0 00
+		01
+			00 00 00 07
+
+	// Oilrig : Position 07
+	\w69 \wxFFCF \w80 00 \wx00B0 00
+		01
+			00 00 00 08
+
+	// Oilrig : Position 08
+	\w69 \w9 \w80 7F \wx00B0 00  // FLYING
+		02
+			7F 00 00 05
+			54 25 00 02
+
+// Prop1C Vehicle Entry Points
+		1C 07 07 07 07
+
+// Prop1F Helipad Groups
+		1F 01 01
+
+// Prop20 Port Subtype
+		20 02
+
+// Prop22 Catchment Area
+		22 03
+
+//availability date varaction2
+//Oilrig available from 1920 (1920+00) to 2175 (1920+255)
+   28 * 14	 02 0D
+		06 // ID
+		81 01 // Variable 01 (current date)
+		00 FF
+		01
+		01 FF 00 FF  //1920-2175
+		00 FF
+
+   29 * 14	 02 0D
+		07 // ID
+		81 0C // Check variable 0C (callback id)
+		00 FF
+		01
+		06 00 13 13 // Jump to action 2 ID 02 if this is callback 13
+		00 00 // Otherwise return the real sprites
+
+	// Use graphics ID (1 station, ID 0, 3 cargo specific graphics, default cargo = 0)
+   30 * 7	 03 0D 01 03 00 07 00
+
+
 // Names
-   27 * 21	 04 0D FF 01 00 CD "Small airports" 00
-   28 * 25	 04 0D 9F 01 00 CD "Kleine vliegvelden" 00
-   29 * 20	 04 0D FF 01 00 CE "Small Airport" 00
-   30 * 22	 04 0D 9F 01 00 CE "Klein vliegveld" 00
-   31 * 21	 04 0D FF 01 01 CD "Large airports" 00
-   32 * 24	 04 0D 9F 01 01 CD "Grote vliegvelden" 00
-   33 * 19	 04 0D FF 01 01 CE "City Airport" 00
-   34 * 21	 04 0D 9F 01 01 CE "Stad vliegveld" 00
-   35 * 16	 04 0D FF 01 02 CD "Heliports" 00
-   36 * 28	 04 0D 9F 01 02 CD "Helikoptervliegvelden" 00
-   37 * 15	 04 0D FF 01 02 CE "Heliport" 00
-   38 * 25	 04 0D 9F 01 02 CE "Helikopter station" 00
+   31 * 21	 04 0D FF 01 00 CD "Small airports" 00
+   32 * 25	 04 0D 9F 01 00 CD "Kleine vliegvelden" 00
+   33 * 20	 04 0D FF 01 00 CE "Small Airport" 00
+   34 * 22	 04 0D 9F 01 00 CE "Klein vliegveld" 00
+   35 * 21	 04 0D FF 01 01 CD "Large airports" 00
+   36 * 24	 04 0D 9F 01 01 CD "Grote vliegvelden" 00
+   37 * 19	 04 0D FF 01 01 CE "City Airport" 00
+   38 * 21	 04 0D 9F 01 01 CE "Stad vliegveld" 00
+   39 * 16	 04 0D FF 01 02 CD "Heliports" 00
+   40 * 28	 04 0D 9F 01 02 CD "Helikoptervliegvelden" 00
+   41 * 15	 04 0D FF 01 02 CE "Heliport" 00
+   42 * 25	 04 0D 9F 01 02 CE "Helikopter station" 00
 
 
 // The Fence Layouts
--- a/src/aircraft_cmd.cpp	Sun Aug 12 12:33:25 2007 +0000
+++ b/src/aircraft_cmd.cpp	Sun Aug 12 14:04:32 2007 +0000
@@ -1080,7 +1080,7 @@
 
 	/* prevent going to 0,0 if airport is deleted. */
 	TileIndex tile = st->airport_tile;
-	if (tile == 0) {
+	if ((tile == 0) || (st->airport_type == AT_OILRIG)) {
 		tile = st->xy;
 
 		/* Jump into our "holding pattern" state machine if possible */
--- a/src/newgrf_fsmports.cpp	Sun Aug 12 12:33:25 2007 +0000
+++ b/src/newgrf_fsmports.cpp	Sun Aug 12 14:04:32 2007 +0000
@@ -103,14 +103,17 @@
 {
 	/* Allow room for all station classes, plus a terminator entry */
 	static StringID names[FSMPORTS_CLASS_MAX + 1];
-	uint i;
+	uint j = 0;
 
 	/* Add each name */
-	for (i = 0; i < FSMPORTS_CLASS_MAX && fsmports_classes[i].id != 0; i++) {
-		names[i] = fsmports_classes[i].name;
+	for (uint i = 0; i < FSMPORTS_CLASS_MAX && fsmports_classes[i].id != 0; i++) {
+		if (fsmports_classes[i].id != SYSTEM_HIDDEN_CLASS) {
+			names[j] = fsmports_classes[i].name;
+			j++;
+		}
 	}
 	/* Terminate the list */
-	names[i] = INVALID_STRING_ID;
+	names[j] = INVALID_STRING_ID;
 
 	return names;
 }
--- a/src/newgrf_fsmports.h	Sun Aug 12 12:33:25 2007 +0000
+++ b/src/newgrf_fsmports.h	Sun Aug 12 14:04:32 2007 +0000
@@ -10,6 +10,10 @@
 #include "helpers.hpp"
 #include "sprite.h"
 
+enum FSMportClass {
+	SYSTEM_HIDDEN_CLASS = 0x53595354  ///< SYST is a hidden class for things like oilrigs that need FSMs, but should not appear in picker lists
+};
+
 enum FSMportsClassID {
 	FSMPORTS_CLASS_BEGIN = 0,    ///< the lowest valid value
 	FSMPORTS_CLASS_DFLT = 0,     ///< Default FSMports class.
--- a/src/openttd.cpp	Sun Aug 12 12:33:25 2007 +0000
+++ b/src/openttd.cpp	Sun Aug 12 14:04:32 2007 +0000
@@ -1245,24 +1245,30 @@
 	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
+	if (grfid != 0x4450414F || localidx != 3) {   //skip oilrigs, but otherwise makeairport
+		/* 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);
+	} else {
+		/* Oilrigs must be set against their root tile, not the tile of the landing pad */
+		/*set top bit of m6 to indicate an fsmportsspec */
+		SetCustomFSMportsSpecIndex(st->xy, fsmportspecindex);
 	}
-
-	/* 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()
@@ -1465,6 +1471,7 @@
 						 * the map
 						 */
 						TileIndex t1 = TILE_ADDXY(t, 1, 0);
+						ResetAirportToNewGRFSpec(t, st, 0x4450414F, 3);
 						if (IsTileType(t1, MP_INDUSTRY) &&
 								GetIndustryGfx(t1) == GFX_OILRIG_3) {
 							/* The internal encoding of oil rigs was changed twice.
--- a/src/station_cmd.cpp	Sun Aug 12 12:33:25 2007 +0000
+++ b/src/station_cmd.cpp	Sun Aug 12 14:04:32 2007 +0000
@@ -2836,6 +2836,12 @@
 	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);
+	SetCustomFSMportsSpecIndex(tile, fsmportspecindex);
+
 	st->xy = tile;
 	st->bus_stops = NULL;
 	st->truck_stops = NULL;