(svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
authordarkvater
Fri, 12 Nov 2004 19:03:37 +0000
changeset 363 cf3cee5f33b4
parent 362 bd9bc9c072ba
child 364 9e93d102fd4a
(svn r551) -newgrf: Preliminary support for TTDPatch flags checking (we just pretend that a bunch of things are on and the rest is off and that's it). Patch by octo, small cleanup by pasky.
grfspecial.c
--- a/grfspecial.c	Fri Nov 12 18:57:46 2004 +0000
+++ b/grfspecial.c	Fri Nov 12 19:03:37 2004 +0000
@@ -26,6 +26,10 @@
 static int32 _paramlist[0x7f];
 static int _param_max;
 
+/* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
+static uint32 _ttdpatch_flags[8];
+
+
 typedef void (*SpecialSpriteHandler)(byte *buf, int len);
 
 static const int _vehshifts[4] = {
@@ -898,6 +902,10 @@
 			/* XXX: This should be always true (at least until we get multiple loading stages?). */
 			param_val = 1;
 			break;
+		case 0x85:
+			param_val = _ttdpatch_flags[cond_val / 0x20];
+			cond_val %= 0x20;
+			break;
 		case 0x86:
 			param_val = _opt.road_side << 4;
 			break;
@@ -1176,6 +1184,26 @@
 	/* TODO */
 }
 
+
+static void InitializeGRFSpecial(void)
+{
+	/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
+
+	_ttdpatch_flags[1] = (1 << 0x08)	/* mammothtrains */
+		| (1 << 0x0B)			/* subsidiaries */
+		| (1 << 0x14)			/* bridgespeedlimits */
+		| (1 << 0x16)			/* eternalgame */
+		| (1 << 0x17)			/* newtrains */
+		| (1 << 0x18)			/* newrvs */
+		| (1 << 0x19)			/* newships */
+		| (1 << 0x1A);		/* newplanes */
+
+	_ttdpatch_flags[2] = (1 << 0x0D)	/* signalsontrafficside */
+		| (1 << 0x16)			/* canals */
+		| (1 << 0x17);		/* newstartyear */
+}
+
+
 /* Here we perform initial decoding of some special sprites (as are they
  * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
  * partial implementation yet; also, we ignore the stages stuff). */
@@ -1203,12 +1231,18 @@
 		/* 0xd */ ParamSet,
 		/* 0xe */ GRFInhibit,
 	};
+	static int initialized;
 	byte action;
 	byte *buf = malloc(num);
 	int i;
 
 	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
 
+	if (!initialized) {
+		InitializeGRFSpecial();
+		initialized = 1;
+	}
+
 	_cur_grffile = filename;
 	_cur_spriteid = spriteid;