34 static GRFFile *_cur_grffile; |
34 static GRFFile *_cur_grffile; |
35 GRFFile *_first_grffile; |
35 GRFFile *_first_grffile; |
36 int _grffile_count; |
36 int _grffile_count; |
37 static int _cur_spriteid; |
37 static int _cur_spriteid; |
38 static int _cur_stage; |
38 static int _cur_stage; |
39 |
|
40 static int32 _paramlist[0x7f]; |
|
41 static int _param_max; |
|
42 |
39 |
43 /* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */ |
40 /* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */ |
44 static uint32 _ttdpatch_flags[8]; |
41 static uint32 _ttdpatch_flags[8]; |
45 |
42 |
46 |
43 |
1764 param_val = _traininfo_vehicle_pitch; |
1761 param_val = _traininfo_vehicle_pitch; |
1765 break; |
1762 break; |
1766 /* TODO */ |
1763 /* TODO */ |
1767 case 0x8F: /* Track type cost multipliers */ |
1764 case 0x8F: /* Track type cost multipliers */ |
1768 default: |
1765 default: |
1769 if (param >= 0x80) { |
1766 if (param < 0x80) { |
|
1767 /* Parameter. */ |
|
1768 param_val = _cur_grffile->param[param]; |
|
1769 } else { |
1770 /* In-game variable. */ |
1770 /* In-game variable. */ |
1771 grfmsg(GMS_WARN, "Unsupported in-game variable %x. Ignoring test.", param); |
1771 grfmsg(GMS_WARN, "Unsupported in-game variable 0x%02X. Ignoring test.", param); |
1772 } else { |
1772 return; |
1773 /* Parameter. */ |
1773 } |
1774 param_val = _paramlist[param]; |
|
1775 } |
|
1776 return; |
|
1777 } |
1774 } |
1778 |
1775 |
1779 DEBUG(grf, 7) ("Test condtype %d, param %x, condval %x", condtype, param_val, cond_val); |
1776 DEBUG(grf, 7) ("Test condtype %d, param %x, condval %x", condtype, param_val, cond_val); |
1780 switch (condtype) { |
1777 switch (condtype) { |
1781 case 0: result = !!(param_val & (1 << cond_val)); |
1778 case 0: result = !!(param_val & (1 << cond_val)); |
1950 * (source2 like in 05, and source1 as well) |
1947 * (source2 like in 05, and source1 as well) |
1951 */ |
1948 */ |
1952 |
1949 |
1953 byte target; |
1950 byte target; |
1954 byte oper; |
1951 byte oper; |
1955 uint16 src1; |
1952 uint32 src1; |
1956 uint16 src2; |
1953 uint32 src2; |
1957 uint16 data = 0; |
1954 uint32 data = 0; |
1958 int32 *dest; |
1955 uint32 res; |
1959 |
1956 |
1960 check_length(len, 5, "ParamSet"); |
1957 check_length(len, 5, "ParamSet"); |
1961 buf++; |
1958 buf++; |
1962 target = grf_load_byte(&buf); |
1959 target = grf_load_byte(&buf); |
1963 oper = grf_load_byte(&buf); |
1960 oper = grf_load_byte(&buf); |
1964 src1 = grf_load_byte(&buf); |
1961 src1 = grf_load_byte(&buf); |
1965 src2 = grf_load_byte(&buf); |
1962 src2 = grf_load_byte(&buf); |
1966 |
1963 |
1967 if (len >= 8) |
1964 if (len >= 8) data = grf_load_dword(&buf); |
1968 data = grf_load_dword(&buf); |
|
1969 |
1965 |
1970 /* You can add 80 to the operation to make it apply only if the target |
1966 /* You can add 80 to the operation to make it apply only if the target |
1971 * is not defined yet. In this respect, a parameter is taken to be |
1967 * is not defined yet. In this respect, a parameter is taken to be |
1972 * defined if any of the following applies: |
1968 * defined if any of the following applies: |
1973 * - it has been set to any value in the newgrf(w).cfg parameter list |
1969 * - it has been set to any value in the newgrf(w).cfg parameter list |
1974 * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by |
1970 * - it OR A PARAMETER WITH HIGHER NUMBER has been set to any value by |
1975 * an earlier action D */ |
1971 * an earlier action D */ |
1976 if (oper & 0x80) { |
1972 if (oper & 0x80) { |
1977 if (_param_max < target) |
1973 if (_cur_grffile->param_end < target) |
1978 oper &= 0x7F; |
1974 oper &= 0x7F; |
1979 else |
1975 else |
1980 return; |
1976 return; |
1981 } |
1977 } |
1982 |
1978 |
1986 * of <data>. If referring to parameters that are undefined, a value |
1982 * of <data>. If referring to parameters that are undefined, a value |
1987 * of 0 is used instead. */ |
1983 * of 0 is used instead. */ |
1988 if (src1 == 0xFF) { |
1984 if (src1 == 0xFF) { |
1989 src1 = data; |
1985 src1 = data; |
1990 } else { |
1986 } else { |
1991 src1 = _param_max >= src1 ? _paramlist[src1] : 0; |
1987 src1 = _cur_grffile->param_end >= src1 ? _cur_grffile->param[src1] : 0; |
1992 } |
1988 } |
1993 |
1989 |
1994 if (src2 == 0xFF) { |
1990 if (src2 == 0xFF) { |
1995 src2 = data; |
1991 src2 = data; |
1996 } else { |
1992 } else { |
1997 src2 = _param_max >= src2 ? _paramlist[src2] : 0; |
1993 src2 = _cur_grffile->param_end >= src2 ? _cur_grffile->param[src2] : 0; |
1998 } |
1994 } |
1999 |
1995 |
2000 /* TODO: You can access the parameters of another GRF file by using |
1996 /* TODO: You can access the parameters of another GRF file by using |
2001 * source2=FE, source1=the other GRF's parameter number and data=GRF |
1997 * source2=FE, source1=the other GRF's parameter number and data=GRF |
2002 * ID. This is only valid with operation 00 (set). If the GRF ID |
1998 * ID. This is only valid with operation 00 (set). If the GRF ID |
2003 * cannot be found, a value of 0 is used for the parameter value |
1999 * cannot be found, a value of 0 is used for the parameter value |
2004 * instead. */ |
2000 * instead. */ |
2005 |
2001 |
2006 /* TODO: The target operand can also refer to the special variables |
|
2007 * from action 7, but at the moment the only variable that is valid to |
|
2008 * write is 8E. */ |
|
2009 |
|
2010 if (target == 0x8E) { |
|
2011 dest = &_traininfo_vehicle_pitch; |
|
2012 } else { |
|
2013 if (_param_max < target) |
|
2014 _param_max = target; |
|
2015 dest = &_paramlist[target]; |
|
2016 } |
|
2017 |
|
2018 /* FIXME: No checking for overflows. */ |
|
2019 switch (oper) { |
2002 switch (oper) { |
2020 case 0x00: |
2003 case 0x00: |
2021 *dest = src1; |
2004 res = src1; |
2022 break; |
2005 break; |
|
2006 |
2023 case 0x01: |
2007 case 0x01: |
2024 *dest = src1 + src2; |
2008 res = src1 + src2; |
2025 break; |
2009 break; |
|
2010 |
2026 case 0x02: |
2011 case 0x02: |
2027 *dest = src1 - src2; |
2012 res = src1 - src2; |
2028 break; |
2013 break; |
|
2014 |
2029 case 0x03: |
2015 case 0x03: |
2030 *dest = ((uint32) src1) * ((uint32) src2); |
2016 res = src1 * src2; |
2031 break; |
2017 break; |
|
2018 |
2032 case 0x04: |
2019 case 0x04: |
2033 *dest = ((int32) src1) * ((int32) src2); |
2020 res = (int32)src1 * (int32)src2; |
2034 break; |
2021 break; |
|
2022 |
2035 case 0x05: |
2023 case 0x05: |
2036 if (src2 & 0x8000) /* src2 is "negative" */ |
2024 if ((int32)src2 < 0) |
2037 *dest = src1 >> -((int16) src2); |
2025 res = src1 >> -(int32)src2; |
2038 else |
2026 else |
2039 *dest = src1 << src2; |
2027 res = src1 << src2; |
2040 break; |
2028 break; |
|
2029 |
2041 case 0x06: |
2030 case 0x06: |
2042 if (src2 & 0x8000) /* src2 is "negative" */ |
2031 if ((int32)src2 < 0) |
2043 *dest = ((int16) src1) >> -((int16) src2); |
2032 res = (int32)src1 >> -(int32)src2; |
2044 else |
2033 else |
2045 *dest = ((int16) src1) << src2; |
2034 res = (int32)src1 << src2; |
2046 break; |
2035 break; |
|
2036 |
2047 default: |
2037 default: |
2048 grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper); |
2038 grfmsg(GMS_ERROR, "ParamSet: Unknown operation %d, skipping.", oper); |
|
2039 return; |
|
2040 } |
|
2041 |
|
2042 switch (target) { |
|
2043 case 0x8E: // Y-Offset for train sprites |
|
2044 _traininfo_vehicle_pitch = res; |
|
2045 break; |
|
2046 |
|
2047 // TODO implement |
|
2048 case 0x8F: // Rail track type cost factors |
|
2049 case 0x93: // Tile refresh offset to left |
|
2050 case 0x94: // Tile refresh offset to right |
|
2051 case 0x95: // Tile refresh offset upwards |
|
2052 case 0x96: // Tile refresh offset downwards |
|
2053 case 0x97: // Snow line height |
|
2054 case 0x99: // Global ID offset |
|
2055 DEBUG(grf, 7) ("ParamSet: Skipping unimplemented target 0x%02X", target); |
|
2056 break; |
|
2057 |
|
2058 default: |
|
2059 if (target < 0x80) { |
|
2060 _cur_grffile->param[target] = res; |
|
2061 if (target + 1U > _cur_grffile->param_end) _cur_grffile->param_end = target + 1; |
|
2062 } else { |
|
2063 DEBUG(grf, 7) ("ParamSet: Skipping unknown target 0x%02X", target); |
|
2064 } |
|
2065 break; |
2049 } |
2066 } |
2050 } |
2067 } |
2051 |
2068 |
2052 static void GRFInhibit(byte *buf, int len) |
2069 static void GRFInhibit(byte *buf, int len) |
2053 { |
2070 { |