newgrf.c
changeset 3806 dbbfd0c2331b
parent 3803 1bd124196372
child 3807 927ac7827a28
equal deleted inserted replaced
3805:a50035a117bd 3806:dbbfd0c2331b
  1929 	 *                 to place where parameter is to be stored. */
  1929 	 *                 to place where parameter is to be stored. */
  1930 	/* TODO */
  1930 	/* TODO */
  1931 	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
  1931 	grfmsg(GMS_NOTICE, "CfgApply: Ignoring (not implemented).\n");
  1932 }
  1932 }
  1933 
  1933 
       
  1934 static uint32 GetParamVal(byte param, uint32 *cond_val)
       
  1935 {
       
  1936 	switch (param) {
       
  1937 		case 0x83: /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
       
  1938 			return _opt.landscape;
       
  1939 
       
  1940 		case 0x84: /* .grf loading stage, 0=initialization, 1=activation */
       
  1941 			return _cur_stage;
       
  1942 
       
  1943 		case 0x85: { /* TTDPatch flags, only for bit tests */
       
  1944 			uint32 param_val = _ttdpatch_flags[*cond_val / 0x20];
       
  1945 			*cond_val %= 0x20;
       
  1946 			return param_val;
       
  1947 		}
       
  1948 
       
  1949 		case 0x86: /* road traffic side, bit 4 clear=left, set=right */
       
  1950 			return _opt.road_side << 4;
       
  1951 
       
  1952 		case 0x88: /* GRF ID check */
       
  1953 			return 0;
       
  1954 
       
  1955 		case 0x8B: { /* TTDPatch version */
       
  1956 			uint major    = 2;
       
  1957 			uint minor    = 0;
       
  1958 			uint revision = 10; // special case: 2.0.1 is 2.0.10
       
  1959 			uint build    = 73;
       
  1960 			return (major << 24) | (minor << 20) | (revision << 16) | (build * 10);
       
  1961 		}
       
  1962 
       
  1963 		case 0x8D: /* TTD Version, 00=DOS, 01=Windows */
       
  1964 			return !_use_dos_palette;
       
  1965 
       
  1966 		case 0x8E: /* Y-offset for train sprites */
       
  1967 			return _traininfo_vehicle_pitch;
       
  1968 
       
  1969 		case 0x92: /* Game mode */
       
  1970 			return _game_mode;
       
  1971 
       
  1972 		case 0x9D: /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
       
  1973 			return 1;
       
  1974 
       
  1975 		default:
       
  1976 			/* GRF Parameter */
       
  1977 			if (param < 0x80) return _cur_grffile->param[param];
       
  1978 
       
  1979 			/* In-game variable. */
       
  1980 			grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X.", param);
       
  1981 			return -1;
       
  1982 	}
       
  1983 
       
  1984 }
       
  1985 
  1934 /* Action 0x07 */
  1986 /* Action 0x07 */
  1935 /* Action 0x09 */
  1987 /* Action 0x09 */
  1936 static void SkipIf(byte *buf, int len)
  1988 static void SkipIf(byte *buf, int len)
  1937 {
  1989 {
  1938 	/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
  1990 	/* <07/09> <param-num> <param-size> <condition-type> <value> <num-sprites>
  1947 	uint8 paramsize;
  1999 	uint8 paramsize;
  1948 	uint8 condtype;
  2000 	uint8 condtype;
  1949 	uint8 numsprites;
  2001 	uint8 numsprites;
  1950 	uint32 param_val = 0;
  2002 	uint32 param_val = 0;
  1951 	uint32 cond_val = 0;
  2003 	uint32 cond_val = 0;
       
  2004 	uint32 mask = 0;
  1952 	bool result;
  2005 	bool result;
  1953 	GRFLabel *label;
  2006 	GRFLabel *label;
  1954 	GRFLabel *choice = NULL;
  2007 	GRFLabel *choice = NULL;
  1955 
  2008 
  1956 	check_length(len, 6, "SkipIf");
  2009 	check_length(len, 6, "SkipIf");
  1963 		/* Always 1 for bit tests, the given value should be ignored. */
  2016 		/* Always 1 for bit tests, the given value should be ignored. */
  1964 		paramsize = 1;
  2017 		paramsize = 1;
  1965 	}
  2018 	}
  1966 
  2019 
  1967 	switch (paramsize) {
  2020 	switch (paramsize) {
  1968 		case 4: cond_val = grf_load_dword(&buf); break;
  2021 		case 4: cond_val = grf_load_dword(&buf); mask = 0xFFFFFFFF; break;
  1969 		case 2: cond_val = grf_load_word(&buf);  break;
  2022 		case 2: cond_val = grf_load_word(&buf);  mask = 0x0000FFFF; break;
  1970 		case 1: cond_val = grf_load_byte(&buf);  break;
  2023 		case 1: cond_val = grf_load_byte(&buf);  mask = 0x000000FF; break;
  1971 		default: break;
  2024 		default: break;
  1972 	}
  2025 	}
  1973 
  2026 
  1974 	switch (param) {
  2027 	if (param < 0x80 && _cur_grffile->param_end <= param) {
  1975 		case 0x83:    /* current climate, 0=temp, 1=arctic, 2=trop, 3=toyland */
  2028 		DEBUG(grf, 7) ("Param %d undefined, skipping test", param);
  1976 			param_val = _opt.landscape;
  2029 		return;
  1977 			break;
  2030 	}
  1978 		case 0x84:    /* .grf loading stage, 0=initialization, 1=activation */
  2031 
  1979 			param_val = _cur_stage;
  2032 	if (param == 0x88 && GetFileByGRFID(cond_val) == NULL) {
  1980 			break;
  2033 		DEBUG(grf, 7) ("GRFID 0x%08X unknown, skipping test", BSWAP32(cond_val));
  1981 		case 0x85:    /* TTDPatch flags, only for bit tests */
  2034 		return;
  1982 			param_val = _ttdpatch_flags[cond_val / 0x20];
  2035 	}
  1983 			cond_val %= 0x20;
  2036 
  1984 			break;
  2037 	param_val = GetParamVal(param, &cond_val);
  1985 		case 0x86:    /* road traffic side, bit 4 clear=left, set=right */
  2038 
  1986 			param_val = _opt.road_side << 4;
  2039 	/* Apply parameter mask, only for GRF parameters. */
  1987 			break;
  2040 	if (param < 0x80) param_val &= mask;
  1988 		case 0x88: {  /* see if specified GRFID is active */
       
  1989 			param_val = (GetFileByGRFID(cond_val) != NULL);
       
  1990 		}	break;
       
  1991 
       
  1992 		case 0x8B: { /* TTDPatch version */
       
  1993 			uint major    = 2;
       
  1994 			uint minor    = 0;
       
  1995 			uint revision = 10; // special case: 2.0.1 is 2.0.10
       
  1996 			uint build    = 73;
       
  1997 			param_val = (major << 24) | (minor << 20) | (revision << 16) | (build * 10);
       
  1998 			break;
       
  1999 		}
       
  2000 
       
  2001 		case 0x8D:    /* TTD Version, 00=DOS, 01=Windows */
       
  2002 			param_val = !_use_dos_palette;
       
  2003 			break;
       
  2004 		case 0x8E:
       
  2005 			param_val = _traininfo_vehicle_pitch;
       
  2006 			break;
       
  2007 		case 0x9D:    /* TTD Platform, 00=TTDPatch, 01=OpenTTD */
       
  2008 			param_val = 1;
       
  2009 			break;
       
  2010 		/* TODO */
       
  2011 		case 0x8F:    /* Track type cost multipliers */
       
  2012 		default:
       
  2013 			if (param < 0x80) {
       
  2014 				/* Parameter. */
       
  2015 				param_val = _cur_grffile->param[param];
       
  2016 			} else {
       
  2017 				/* In-game variable. */
       
  2018 				grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X. Ignoring test.", param);
       
  2019 				return;
       
  2020 			}
       
  2021 	}
       
  2022 
  2041 
  2023 	DEBUG(grf, 7) ("Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
  2042 	DEBUG(grf, 7) ("Test condtype %d, param 0x%08X, condval 0x%08X", condtype, param_val, cond_val);
  2024 	switch (condtype) {
  2043 	switch (condtype) {
  2025 		case 0: result = !!(param_val & (1 << cond_val));
  2044 		case 0: result = !!(param_val & (1 << cond_val));
  2026 			break;
  2045 			break;
  2033 			break;
  2052 			break;
  2034 		case 4: result = (param_val < cond_val);
  2053 		case 4: result = (param_val < cond_val);
  2035 			break;
  2054 			break;
  2036 		case 5: result = (param_val > cond_val);
  2055 		case 5: result = (param_val > cond_val);
  2037 			break;
  2056 			break;
  2038 		case 6: result = !!param_val; /* GRFID is active (only for param-num=88) */
  2057 		/* Tests 6 to 10 are only for param 0x88, GRFID checks */
  2039 			break;
  2058 		case 6: /* Is GRFID active? */
  2040 		case 7: result = !param_val; /* GRFID is not active (only for param-num=88) */
  2059 		case 9: /* GRFID is or will be active? */
       
  2060 			result = (GetFileByGRFID(cond_val)->flags & 1) == 1;
       
  2061 			break;
       
  2062 		case 7: /* Is GRFID non-active? */
       
  2063 		case 10: /* GRFID is not nor will be active */
       
  2064 			result = (GetFileByGRFID(cond_val)->flags & 1) == 0;
       
  2065 			break;
       
  2066 		case 8: /* GRFID is not but will be active? */
       
  2067 			result = 0;
       
  2068 			if ((GetFileByGRFID(cond_val)->flags & 1) == 1) {
       
  2069 				const GRFFile *file;
       
  2070 				for (file = _first_grffile; file != NULL; file = file->next) {
       
  2071 					if (file->grfid == cond_val) break;
       
  2072 					if (file == _cur_grffile) {
       
  2073 						result = 1;
       
  2074 						break;
       
  2075 					}
       
  2076 				}
       
  2077 			}
  2041 			break;
  2078 			break;
  2042 		default:
  2079 		default:
  2043 			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
  2080 			grfmsg(GMS_WARN, "Unsupported test %d. Ignoring.", condtype);
  2044 			return;
  2081 			return;
  2045 	}
  2082 	}