grfspecial.c
changeset 363 2a01c271fe2d
parent 362 4bb825210268
child 366 05c09e262c8e
equal deleted inserted replaced
362:4bb825210268 363:2a01c271fe2d
    23 static const char *_cur_grffile;
    23 static const char *_cur_grffile;
    24 static int _cur_spriteid;
    24 static int _cur_spriteid;
    25 
    25 
    26 static int32 _paramlist[0x7f];
    26 static int32 _paramlist[0x7f];
    27 static int _param_max;
    27 static int _param_max;
       
    28 
       
    29 /* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */
       
    30 static uint32 _ttdpatch_flags[8];
       
    31 
    28 
    32 
    29 typedef void (*SpecialSpriteHandler)(byte *buf, int len);
    33 typedef void (*SpecialSpriteHandler)(byte *buf, int len);
    30 
    34 
    31 static const int _vehshifts[4] = {
    35 static const int _vehshifts[4] = {
    32 	0,
    36 	0,
   896 			break;
   900 			break;
   897 		case 0x84:
   901 		case 0x84:
   898 			/* XXX: This should be always true (at least until we get multiple loading stages?). */
   902 			/* XXX: This should be always true (at least until we get multiple loading stages?). */
   899 			param_val = 1;
   903 			param_val = 1;
   900 			break;
   904 			break;
       
   905 		case 0x85:
       
   906 			param_val = _ttdpatch_flags[cond_val / 0x20];
       
   907 			cond_val %= 0x20;
       
   908 			break;
   901 		case 0x86:
   909 		case 0x86:
   902 			param_val = _opt.road_side << 4;
   910 			param_val = _opt.road_side << 4;
   903 			break;
   911 			break;
   904 		default:
   912 		default:
   905 			if (param >= 0x80) {
   913 			if (param >= 0x80) {
  1173 	 *
  1181 	 *
  1174 	 * B num           Number of GRFIDs that follow
  1182 	 * B num           Number of GRFIDs that follow
  1175 	 * D grfids        GRFIDs of the files to deactivate */
  1183 	 * D grfids        GRFIDs of the files to deactivate */
  1176 	/* TODO */
  1184 	/* TODO */
  1177 }
  1185 }
       
  1186 
       
  1187 
       
  1188 static void InitializeGRFSpecial(void)
       
  1189 {
       
  1190 	/* FIXME: We should rather reflect reality in _ttdpatch_flags[]. */
       
  1191 
       
  1192 	_ttdpatch_flags[1] = (1 << 0x08)	/* mammothtrains */
       
  1193 		| (1 << 0x0B)			/* subsidiaries */
       
  1194 		| (1 << 0x14)			/* bridgespeedlimits */
       
  1195 		| (1 << 0x16)			/* eternalgame */
       
  1196 		| (1 << 0x17)			/* newtrains */
       
  1197 		| (1 << 0x18)			/* newrvs */
       
  1198 		| (1 << 0x19)			/* newships */
       
  1199 		| (1 << 0x1A);		/* newplanes */
       
  1200 
       
  1201 	_ttdpatch_flags[2] = (1 << 0x0D)	/* signalsontrafficside */
       
  1202 		| (1 << 0x16)			/* canals */
       
  1203 		| (1 << 0x17);		/* newstartyear */
       
  1204 }
       
  1205 
  1178 
  1206 
  1179 /* Here we perform initial decoding of some special sprites (as are they
  1207 /* Here we perform initial decoding of some special sprites (as are they
  1180  * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
  1208  * described at http://www.ttdpatch.net/src/newgrf.txt, but this is only a very
  1181  * partial implementation yet; also, we ignore the stages stuff). */
  1209  * partial implementation yet; also, we ignore the stages stuff). */
  1182 /* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
  1210 /* XXX: We consider GRF files trusted. It would be trivial to exploit OTTD by
  1201 		/* 0xb */ GRFError,
  1229 		/* 0xb */ GRFError,
  1202 		/* 0xc */ GRFComment,
  1230 		/* 0xc */ GRFComment,
  1203 		/* 0xd */ ParamSet,
  1231 		/* 0xd */ ParamSet,
  1204 		/* 0xe */ GRFInhibit,
  1232 		/* 0xe */ GRFInhibit,
  1205 	};
  1233 	};
       
  1234 	static int initialized;
  1206 	byte action;
  1235 	byte action;
  1207 	byte *buf = malloc(num);
  1236 	byte *buf = malloc(num);
  1208 	int i;
  1237 	int i;
  1209 
  1238 
  1210 	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
  1239 	if (buf == NULL) error("DecodeSpecialSprite: Could not allocate memory");
       
  1240 
       
  1241 	if (!initialized) {
       
  1242 		InitializeGRFSpecial();
       
  1243 		initialized = 1;
       
  1244 	}
  1211 
  1245 
  1212 	_cur_grffile = filename;
  1246 	_cur_grffile = filename;
  1213 	_cur_spriteid = spriteid;
  1247 	_cur_spriteid = spriteid;
  1214 
  1248 
  1215 	for (i = 0; i != num; i++)
  1249 	for (i = 0; i != num; i++)