src/newgrf.cpp
changeset 6576 3a7cc737dec8
parent 6570 0db336a1b931
child 6579 3b1c0599dace
equal deleted inserted replaced
6575:f1a0ca44f8ca 6576:3a7cc737dec8
  1789 		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
  1789 		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
  1790 	};
  1790 	};
  1791 
  1791 
  1792 	EngineInfo *ei = NULL;
  1792 	EngineInfo *ei = NULL;
  1793 
  1793 
  1794 	if (len == 1) {
       
  1795 		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
       
  1796 		return;
       
  1797 	}
       
  1798 
       
  1799 	if (!check_length(len, 6, "FeatureChangeInfo")) return;
  1794 	if (!check_length(len, 6, "FeatureChangeInfo")) return;
  1800 	buf++;
  1795 	buf++;
  1801 	uint8 feature  = grf_load_byte(&buf);
  1796 	uint8 feature  = grf_load_byte(&buf);
  1802 	uint8 numprops = grf_load_byte(&buf);
  1797 	uint8 numprops = grf_load_byte(&buf);
  1803 	uint numinfo  = grf_load_byte(&buf);
  1798 	uint numinfo  = grf_load_byte(&buf);
  1877 }
  1872 }
  1878 
  1873 
  1879 /* Action 0x00 (GLS_SAFETYSCAN) */
  1874 /* Action 0x00 (GLS_SAFETYSCAN) */
  1880 static void SafeChangeInfo(byte *buf, int len)
  1875 static void SafeChangeInfo(byte *buf, int len)
  1881 {
  1876 {
  1882 	if (len == 1) {
       
  1883 		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
       
  1884 		return;
       
  1885 	}
       
  1886 
       
  1887 	if (!check_length(len, 6, "SafeChangeInfo")) return;
  1877 	if (!check_length(len, 6, "SafeChangeInfo")) return;
  1888 	buf++;
  1878 	buf++;
  1889 	uint8 feature  = grf_load_byte(&buf);
  1879 	uint8 feature  = grf_load_byte(&buf);
  1890 	uint8 numprops = grf_load_byte(&buf);
  1880 	uint8 numprops = grf_load_byte(&buf);
  1891 	grf_load_byte(&buf);
  1881 	grf_load_byte(&buf);
  1906 
  1896 
  1907 /* Action 0x00 (GLS_INIT) */
  1897 /* Action 0x00 (GLS_INIT) */
  1908 static void InitChangeInfo(byte *buf, int len)
  1898 static void InitChangeInfo(byte *buf, int len)
  1909 {
  1899 {
  1910 	byte *bufend = buf + len;
  1900 	byte *bufend = buf + len;
  1911 
       
  1912 	if (len == 1) {
       
  1913 		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
       
  1914 		return;
       
  1915 	}
       
  1916 
  1901 
  1917 	if (!check_length(len, 6, "InitChangeInfo")) return;
  1902 	if (!check_length(len, 6, "InitChangeInfo")) return;
  1918 	buf++;
  1903 	buf++;
  1919 	uint8 feature  = grf_load_byte(&buf);
  1904 	uint8 feature  = grf_load_byte(&buf);
  1920 	uint8 numprops = grf_load_byte(&buf);
  1905 	uint8 numprops = grf_load_byte(&buf);
  1951 
  1936 
  1952 /* Action 0x00 (GLS_RESERVE) */
  1937 /* Action 0x00 (GLS_RESERVE) */
  1953 static void ReserveChangeInfo(byte *buf, int len)
  1938 static void ReserveChangeInfo(byte *buf, int len)
  1954 {
  1939 {
  1955 	byte *bufend = buf + len;
  1940 	byte *bufend = buf + len;
  1956 
       
  1957 	if (len == 1) {
       
  1958 		grfmsg(8, "Silently ignoring one-byte special sprite 0x00");
       
  1959 		return;
       
  1960 	}
       
  1961 
  1941 
  1962 	if (!check_length(len, 6, "InitChangeInfo")) return;
  1942 	if (!check_length(len, 6, "InitChangeInfo")) return;
  1963 	buf++;
  1943 	buf++;
  1964 	uint8 feature  = grf_load_byte(&buf);
  1944 	uint8 feature  = grf_load_byte(&buf);
  1965 
  1945 
  2051 
  2031 
  2052 	for (uint16 i = 0; i < num_sets * num_ents; i++) {
  2032 	for (uint16 i = 0; i < num_sets * num_ents; i++) {
  2053 		LoadNextSprite(_cur_spriteid++, _file_index);
  2033 		LoadNextSprite(_cur_spriteid++, _file_index);
  2054 		_nfo_line++;
  2034 		_nfo_line++;
  2055 	}
  2035 	}
       
  2036 }
       
  2037 
       
  2038 /* Action 0x01 (SKIP) */
       
  2039 static void SkipAct1(byte *buf, int len)
       
  2040 {
       
  2041 	if (!check_length(len, 4, "SkipAct1")) return;
       
  2042 	buf++;
       
  2043 	grf_load_byte(&buf);
       
  2044 	uint8 num_sets  = grf_load_byte(&buf);
       
  2045 	uint16 num_ents = grf_load_extended(&buf);
       
  2046 
       
  2047 	_skip_sprites = num_sets * num_ents;
       
  2048 
       
  2049 	grfmsg(3, "SkipAct1: Skipping %d sprites", _skip_sprites);
  2056 }
  2050 }
  2057 
  2051 
  2058 /* Helper function to either create a callback or link to a previously
  2052 /* Helper function to either create a callback or link to a previously
  2059  * defined spritegroup. */
  2053  * defined spritegroup. */
  2060 static const SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
  2054 static const SpriteGroup* GetGroupFromGroupID(byte setid, byte type, uint16 groupid)
  4612 	/* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf
  4606 	/* We need a pre-stage to set up GOTO labels of Action 0x10 because the grf
  4613 	 * is not in memory and scanning the file every time would be too expensive.
  4607 	 * is not in memory and scanning the file every time would be too expensive.
  4614 	 * In other stages we skip action 0x10 since it's already dealt with. */
  4608 	 * In other stages we skip action 0x10 since it's already dealt with. */
  4615 	static const SpecialSpriteHandler handlers[][GLS_END] = {
  4609 	static const SpecialSpriteHandler handlers[][GLS_END] = {
  4616 		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       InitChangeInfo, ReserveChangeInfo, FeatureChangeInfo, },
  4610 		/* 0x00 */ { NULL,     SafeChangeInfo, NULL,       InitChangeInfo, ReserveChangeInfo, FeatureChangeInfo, },
  4617 		/* 0x01 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              NewSpriteSet, },
  4611 		/* 0x01 */ { SkipAct1, SkipAct1,  SkipAct1,        SkipAct1,       SkipAct1,          NewSpriteSet, },
  4618 		/* 0x02 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              NewSpriteGroup, },
  4612 		/* 0x02 */ { NULL,     NULL,      NULL,            NULL,           NULL,              NewSpriteGroup, },
  4619 		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
  4613 		/* 0x03 */ { NULL,     GRFUnsafe, NULL,            NULL,           NULL,              FeatureMapSpriteGroup, },
  4620 		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
  4614 		/* 0x04 */ { NULL,     NULL,      NULL,            NULL,           NULL,              FeatureNewName, },
  4621 		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
  4615 		/* 0x05 */ { SkipAct5, SkipAct5,  SkipAct5,        SkipAct5,       SkipAct5,          GraphicsNew, },
  4622 		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
  4616 		/* 0x06 */ { NULL,     NULL,      NULL,            CfgApply,       CfgApply,          CfgApply, },
  4623 		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },
  4617 		/* 0x07 */ { NULL,     NULL,      NULL,            NULL,           SkipIf,            SkipIf, },