grfspecial.c
changeset 359 5232542d89bc
parent 357 5a92ba8a59e6
child 360 aeeee342efe0
equal deleted inserted replaced
358:da81e0ef68cf 359:5232542d89bc
   721 }
   721 }
   722 
   722 
   723 /* Action 0x03 */
   723 /* Action 0x03 */
   724 static void VehicleMapSpriteSuperset(byte *buf, int len)
   724 static void VehicleMapSpriteSuperset(byte *buf, int len)
   725 {
   725 {
   726 	byte *bufend = buf + len;
       
   727 	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
   726 	/* <03> <feature> <n-id> <ids>... <num-cid> [<cargo-type> <cid>]... <def-cid>
   728 	 * id-list	:= [<id>] [id-list]
   727 	 * id-list	:= [<id>] [id-list]
   729 	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
   728 	 * cargo-list	:= <cargo-type> <cid> [cargo-list]
   730 	 *
   729 	 *
   731 	 * B feature       see action 0
   730 	 * B feature       see action 0
   925 	/* TODO: More params. More condition types. */
   924 	/* TODO: More params. More condition types. */
   926 	uint8 param;
   925 	uint8 param;
   927 	uint8 paramsize;
   926 	uint8 paramsize;
   928 	uint8 condtype;
   927 	uint8 condtype;
   929 	uint8 numsprites;
   928 	uint8 numsprites;
   930 	int val, result;
   929 	int param_val = 0, cond_val = 0, result;
   931 
   930 
   932 	check_length(len, 6, "SkipIf");
   931 	check_length(len, 6, "SkipIf");
   933 	param = buf[1];
   932 	param = buf[1];
   934 	paramsize = buf[2];
   933 	paramsize = buf[2];
   935 	condtype = buf[3];
   934 	condtype = buf[3];
   936 	numsprites = buf[4 + paramsize];
   935 
   937 
   936 	if (condtype < 2) {
   938 	if (param == 0x83) {
   937 		/* Always 1 for bit tests, the given value should
   939 		val = _opt.landscape;
   938 		 * be ignored. */
   940 	} else {
   939 		paramsize = 1;
   941 		grfmsg(GMS_WARN, "Unsupported param %x. Ignoring test.", param);
   940 	}
   942 		return;
   941 
       
   942 	buf += 4;
       
   943 	if (paramsize == 4)
       
   944 		cond_val = grf_load_dword(&buf);
       
   945 	else if (paramsize == 2)
       
   946 		cond_val = grf_load_word(&buf);
       
   947 	else if (paramsize == 1)
       
   948 		cond_val = grf_load_byte(&buf);
       
   949 
       
   950 	switch (param) {
       
   951 		case 0x83:
       
   952 			param_val = _opt.landscape;
       
   953 			break;
       
   954 		case 0x84:
       
   955 			/* XXX: This should be always true (at least until we get multiple loading stages?). */
       
   956 			param_val = 1;
       
   957 			break;
       
   958 		case 0x86:
       
   959 			param_val = _opt.road_side << 4;
       
   960 			break;
       
   961 		default:
       
   962 			grfmsg(GMS_WARN, "Unsupported param %x. Ignoring test.", param);
       
   963 			return;
   943 	}
   964 	}
   944 
   965 
   945 	switch (condtype) {
   966 	switch (condtype) {
   946 		case 2: result = (buf[4] == val);
   967 		case 0: result = (param_val & (1 << cond_val));
   947 			break;
   968 			break;
   948 		case 3: result = (buf[4] != val);
   969 		case 1: result = !(param_val & (1 << cond_val));
       
   970 			break;
       
   971 		/* TODO: For the following, make it to work with paramsize>1. */
       
   972 		case 2: result = (param_val == cond_val);
       
   973 			break;
       
   974 		case 3: result = (param_val != cond_val);
       
   975 			break;
       
   976 		case 4: result = (param_val < cond_val);
       
   977 			break;
       
   978 		case 5: result = (param_val > cond_val);
   949 			break;
   979 			break;
   950 		default:
   980 		default:
   951 			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
   981 			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
   952 			return;
   982 			return;
   953 	}
   983 	}
   954 
   984 
   955 	if (!result)
   985 	if (result == 0) {
       
   986 		grfmsg(GMS_NOTICE, "Not skipping sprites, test was false.");
   956 		return;
   987 		return;
       
   988 	}
       
   989 
       
   990 	numsprites = grf_load_byte(&buf);
       
   991 	grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites);
   957 
   992 
   958 	_skip_sprites = numsprites;
   993 	_skip_sprites = numsprites;
   959 	if (_skip_sprites == 0) {
   994 	if (_skip_sprites == 0) {
   960 		/* Zero means there are no sprites to skip, so
   995 		/* Zero means there are no sprites to skip, so
   961 		 * we use -1 to indicate that all further
   996 		 * we use -1 to indicate that all further