src/newgrf.cpp
branchnoai
changeset 9641 855e32c08c9b
parent 9631 8a2d1c2ceb88
child 9686 d3c195c226f9
equal deleted inserted replaced
9640:494df85104a3 9641:855e32c08c9b
    39 #include "helpers.hpp"
    39 #include "helpers.hpp"
    40 #include "table/town_land.h"
    40 #include "table/town_land.h"
    41 #include "cargotype.h"
    41 #include "cargotype.h"
    42 #include "industry.h"
    42 #include "industry.h"
    43 #include "newgrf_canal.h"
    43 #include "newgrf_canal.h"
       
    44 #include "table/build_industry.h"
    44 #include "newgrf_commons.h"
    45 #include "newgrf_commons.h"
    45 #include "newgrf_townname.h"
    46 #include "newgrf_townname.h"
       
    47 #include "newgrf_industries.h"
    46 
    48 
    47 /* TTDPatch extended GRF format codec
    49 /* TTDPatch extended GRF format codec
    48  * (c) Petr Baudis 2004 (GPL'd)
    50  * (c) Petr Baudis 2004 (GPL'd)
    49  * Changes by Florian octo Forster are (c) by the OpenTTD development team.
    51  * Changes by Florian octo Forster are (c) by the OpenTTD development team.
    50  *
    52  *
  1675 
  1677 
  1676 	*bufp = buf;
  1678 	*bufp = buf;
  1677 	return ret;
  1679 	return ret;
  1678 }
  1680 }
  1679 
  1681 
       
  1682 static bool IndustrytilesChangeInfo(uint indtid, int numinfo, int prop, byte **bufp, int len)
       
  1683 {
       
  1684 	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return true;
       
  1685 
       
  1686 	byte *buf = *bufp;
       
  1687 	bool ret = false;
       
  1688 
       
  1689 	if (indtid + numinfo > NUM_INDUSTRYTILES) {
       
  1690 		grfmsg(1, "IndustryTilesChangeInfo: Too many industry tiles loaded (%u), max (%u). Ignoring.", indtid + numinfo, NUM_INDUSTRYTILES);
       
  1691 		return false;
       
  1692 	}
       
  1693 
       
  1694 	/* Allocate industry tile specs if they haven't been allocated already. */
       
  1695 	if (_cur_grffile->indtspec == NULL) {
       
  1696 		_cur_grffile->indtspec = CallocT<IndustryTileSpec*>(NUM_INDUSTRYTILES);
       
  1697 
       
  1698 		/* Reset any overrides that have been set. */
       
  1699 		_industile_mngr.ResetOverride();
       
  1700 	}
       
  1701 
       
  1702 	for (int i = 0; i < numinfo; i++) {
       
  1703 		IndustryTileSpec *tsp = _cur_grffile->indtspec[indtid + i];
       
  1704 
       
  1705 		if (prop != 0x08 && tsp == NULL) {
       
  1706 			grfmsg(2, "IndustryTilesChangeInfo: Attempt to modify undefined industry tile %u. Ignoring.", indtid + i);
       
  1707 			continue;
       
  1708 		}
       
  1709 
       
  1710 		switch (prop) {
       
  1711 			case 0x08: { // Substitute industry tile type
       
  1712 				IndustryTileSpec **tilespec = &_cur_grffile->indtspec[indtid + i];
       
  1713 				byte subs_id = grf_load_byte(&buf);
       
  1714 
       
  1715 				if (subs_id == 0xFF) {
       
  1716 					/* Instead of defining a new industry, a substitute industry id
       
  1717 					 * of 0xFF disables the old industry with the current id. */
       
  1718 					tsp->enabled = false;
       
  1719 					continue;
       
  1720 				} else if (subs_id >= NEW_INDUSTRYTILEOFFSET) {
       
  1721 					/* The substitute id must be one of the original industry tile. */
       
  1722 					grfmsg(2, "IndustryTilesChangeInfo: Attempt to use new industry tile %u as substitute industry tile for %u. Ignoring.", subs_id, indtid + i);
       
  1723 					return false;
       
  1724 				}
       
  1725 
       
  1726 				/* Allocate space for this industry. */
       
  1727 				if (*tilespec == NULL) {
       
  1728 					int tempid;
       
  1729 					*tilespec = CallocT<IndustryTileSpec>(1);
       
  1730 					tsp = *tilespec;
       
  1731 
       
  1732 					memcpy(tsp, &_industry_tile_specs[subs_id], sizeof(_industry_tile_specs[subs_id]));
       
  1733 					tsp->enabled = true;
       
  1734 					tsp->grf_prop.local_id = indtid + i;
       
  1735 					tsp->grf_prop.subst_id = subs_id;
       
  1736 					tsp->grf_prop.grffile = _cur_grffile;
       
  1737 					tempid = _industile_mngr.AddEntityID(indtid + i, _cur_grffile->grfid, subs_id); // pre-reserve the tile slot
       
  1738 				}
       
  1739 			} break;
       
  1740 
       
  1741 			case 0x09: { // Industry tile override
       
  1742 				byte ovrid = grf_load_byte(&buf);
       
  1743 
       
  1744 				/* The industry being overridden must be an original industry. */
       
  1745 				if (ovrid >= NEW_INDUSTRYTILEOFFSET) {
       
  1746 					grfmsg(2, "IndustryTilesChangeInfo: Attempt to override new industry tile %u with industry tile id %u. Ignoring.", ovrid, indtid + i);
       
  1747 					return false;
       
  1748 				}
       
  1749 
       
  1750 				tsp->grf_prop.override = ovrid;
       
  1751 				_industile_mngr.Add(indtid + i, ovrid);
       
  1752 			} break;
       
  1753 
       
  1754 			case 0x0A: // Tile acceptance
       
  1755 			case 0x0B:
       
  1756 			case 0x0C: {
       
  1757 				uint16 acctp = grf_load_word(&buf);
       
  1758 				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
       
  1759 				tsp->acceptance[prop - 0x0A] = GetCargoTranslation(GB(acctp, 8, 8), _cur_grffile);
       
  1760 			} break;
       
  1761 
       
  1762 			case 0x0D: // Land shape flags
       
  1763 				tsp->slopes_refused = (Slope)grf_load_byte(&buf);
       
  1764 				break;
       
  1765 
       
  1766 			case 0x0E: // Callback flags
       
  1767 				tsp->callback_flags = grf_load_byte(&buf);
       
  1768 				break;
       
  1769 
       
  1770 			case 0x0F: // Animation information
       
  1771 				tsp->animation_info = grf_load_word(&buf);
       
  1772 				break;
       
  1773 
       
  1774 			case 0x10: // Animation speed
       
  1775 				tsp->animation_speed = grf_load_byte(&buf);
       
  1776 				break;
       
  1777 
       
  1778 			case 0x11: // Triggers for callback 25
       
  1779 				tsp->animation_triggers = grf_load_byte(&buf);
       
  1780 				break;
       
  1781 
       
  1782 			case 0x12: // Special flags
       
  1783 				tsp->animation_special_flags = grf_load_byte(&buf);
       
  1784 				break;
       
  1785 
       
  1786 			default:
       
  1787 				ret = true;
       
  1788 				break;
       
  1789 		}
       
  1790 	}
       
  1791 
       
  1792 	*bufp = buf;
       
  1793 	return ret;
       
  1794 }
       
  1795 
       
  1796 static bool IndustriesChangeInfo(uint indid, int numinfo, int prop, byte **bufp, int len)
       
  1797 {
       
  1798 	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return true;
       
  1799 
       
  1800 	byte *buf = *bufp;
       
  1801 	bool ret = false;
       
  1802 
       
  1803 	if (indid + numinfo > NUM_INDUSTRYTYPES) {
       
  1804 		grfmsg(1, "IndustriesChangeInfo: Too many industries loaded (%u), max (%u). Ignoring.", indid + numinfo, NUM_INDUSTRYTYPES);
       
  1805 		return false;
       
  1806 	}
       
  1807 
       
  1808 	grfmsg(1, "IndustriesChangeInfo: newid %u", indid);
       
  1809 
       
  1810 	/* Allocate industry specs if they haven't been allocated already. */
       
  1811 	if (_cur_grffile->industryspec == NULL) {
       
  1812 		_cur_grffile->industryspec = CallocT<IndustrySpec*>(NUM_INDUSTRYTYPES);
       
  1813 
       
  1814 		/* Reset any overrides that have been set. */
       
  1815 		_industry_mngr.ResetOverride();
       
  1816 	}
       
  1817 
       
  1818 	for (int i = 0; i < numinfo; i++) {
       
  1819 		IndustrySpec *indsp = _cur_grffile->industryspec[indid + i];
       
  1820 
       
  1821 		if (prop != 0x08 && indsp == NULL) {
       
  1822 			grfmsg(2, "IndustriesChangeInfo: Attempt to modify undefined industry %u. Ignoring.", indid + i);
       
  1823 			continue;
       
  1824 		}
       
  1825 
       
  1826 		switch (prop) {
       
  1827 			case 0x08: { // Substitute industry type
       
  1828 				IndustrySpec **indspec = &_cur_grffile->industryspec[indid + i];
       
  1829 				byte subs_id = grf_load_byte(&buf);
       
  1830 
       
  1831 				if (subs_id == 0xFF) {
       
  1832 					/* Instead of defining a new industry, a substitute industry id
       
  1833 					 * of 0xFF disables the old industry with the current id. */
       
  1834 					_industry_specs[indid + i].enabled = false;
       
  1835 					continue;
       
  1836 				} else if (subs_id >= NEW_INDUSTRYOFFSET) {
       
  1837 					/* The substitute id must be one of the original industry. */
       
  1838 					grfmsg(2, "_industry_specs: Attempt to use new industry %u as substitute industry for %u. Ignoring.", subs_id, indid + i);
       
  1839 					return false;
       
  1840 				}
       
  1841 
       
  1842 				/* Allocate space for this industry.
       
  1843 				 * Only need to do it once. If ever it is called again, it should not
       
  1844 				 * do anything */
       
  1845 				if (*indspec == NULL) {
       
  1846 					*indspec = CallocT<IndustrySpec>(1);
       
  1847 					indsp = *indspec;
       
  1848 
       
  1849 					memcpy(indsp, &_origin_industry_specs[subs_id], sizeof(_industry_specs[subs_id]));
       
  1850 					indsp->enabled = true;
       
  1851 					indsp->grf_prop.local_id = indid + i;
       
  1852 					indsp->grf_prop.subst_id = subs_id;
       
  1853 					indsp->grf_prop.grffile = _cur_grffile;
       
  1854 				}
       
  1855 			} break;
       
  1856 
       
  1857 			case 0x09: { // Industry type override
       
  1858 				byte ovrid = grf_load_byte(&buf);
       
  1859 
       
  1860 				/* The industry being overridden must be an original industry. */
       
  1861 				if (ovrid >= NEW_INDUSTRYOFFSET) {
       
  1862 					grfmsg(2, "IndustriesChangeInfo: Attempt to override new industry %u with industry id %u. Ignoring.", ovrid, indid + i);
       
  1863 					return false;
       
  1864 				}
       
  1865 				indsp->grf_prop.override = ovrid;
       
  1866 				_industry_mngr.Add(indid + i, ovrid);
       
  1867 			} break;
       
  1868 
       
  1869 			case 0x0A: { // Set industry layout(s)
       
  1870 				indsp->num_table = grf_load_byte(&buf); // Number of layaouts
       
  1871 				uint32 defsize = grf_load_dword(&buf);  // Total size of the definition
       
  1872 				IndustryTileTable **tile_table = CallocT<IndustryTileTable*>(indsp->num_table); // Table with tiles to compose an industry
       
  1873 				IndustryTileTable *itt = CallocT<IndustryTileTable>(defsize); // Temporary array to read the tile layouts from the GRF
       
  1874 				int size;
       
  1875 				IndustryTileTable *copy_from;
       
  1876 
       
  1877 				for (byte j = 0; j < indsp->num_table; j++) {
       
  1878 					for (int k = 0;; k++) {
       
  1879 						itt[k].ti.x = grf_load_byte(&buf); // Offsets from northermost tile
       
  1880 
       
  1881 						if (itt[k].ti.x == 0xFE && k == 0) {
       
  1882 							/* This means we have to borrow the layout from an old industry */
       
  1883 							IndustryType type = grf_load_byte(&buf);  //industry holding required layout
       
  1884 							byte laynbr = grf_load_byte(&buf);        //layout number to borrow
       
  1885 
       
  1886 							copy_from = (IndustryTileTable*)_origin_industry_specs[type].table[laynbr];
       
  1887 							for (size = 1;; size++) {
       
  1888 								if (_origin_industry_specs[type].table[laynbr + (size - 1)]->ti.x == -0x80 &&
       
  1889 										_origin_industry_specs[type].table[laynbr + (size - 1)]->ti.y == 0) break;
       
  1890 							}
       
  1891 							break;
       
  1892 						}
       
  1893 
       
  1894 						itt[k].ti.y = grf_load_byte(&buf); // Or table definition finalisation
       
  1895 
       
  1896 						if (itt[k].ti.x == 0 && itt[k].ti.y == 0x80) {
       
  1897 							/*  Not the same terminator.  The one we are using is rather
       
  1898 							 x= -80, y = x .  So, adjust it. */
       
  1899 							itt[k].ti.x = -0x80;
       
  1900 							itt[k].ti.y =  0;
       
  1901 							itt[k].gfx  =  0;
       
  1902 
       
  1903 							size = k + 1;
       
  1904 							copy_from = itt;
       
  1905 							break;
       
  1906 						}
       
  1907 
       
  1908 						itt[k].gfx = grf_load_byte(&buf);
       
  1909 
       
  1910 						if (itt[k].gfx == 0xFE) {
       
  1911 							/* Use a new tile from this GRF */
       
  1912 							int local_tile_id = grf_load_word(&buf);
       
  1913 
       
  1914 							/* Read the ID from the _industile_mngr. */
       
  1915 							int tempid = _industile_mngr.GetID(local_tile_id, _cur_grffile->grfid);
       
  1916 
       
  1917 							if (tempid == INVALID_INDUSTRYTILE) {
       
  1918 								grfmsg(2, "IndustriesChangeInfo: Attempt to use industry tile %u with industry id %u, not yet defined. Ignoring.", local_tile_id, indid);
       
  1919 							} else {
       
  1920 								/* Declared as been valid, can be used */
       
  1921 								itt[k].gfx = tempid;
       
  1922 								size = k + 1;
       
  1923 								copy_from = itt;
       
  1924 							}
       
  1925 						}
       
  1926 					}
       
  1927 					tile_table[j] = CallocT<IndustryTileTable>(size);
       
  1928 					memcpy(tile_table[j], copy_from, sizeof(*copy_from) * size);
       
  1929 				}
       
  1930 				/* Install final layout construction in the industry spec */
       
  1931 				indsp->table = tile_table;
       
  1932 				SETBIT(indsp->cleanup_flag, 1);
       
  1933 				free(itt);
       
  1934 			} break;
       
  1935 
       
  1936 			case 0x0B: // Industry production flags
       
  1937 				indsp->life_type = (IndustryLifeType)grf_load_byte(&buf);
       
  1938 				break;
       
  1939 
       
  1940 			case 0x0C: // Industry closure message
       
  1941 				indsp->closure_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
       
  1942 				break;
       
  1943 
       
  1944 			case 0x0D: // Production increase message
       
  1945 				indsp->production_up_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
       
  1946 				break;
       
  1947 
       
  1948 			case 0x0E: // Production decrease message
       
  1949 				indsp->production_down_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
       
  1950 				break;
       
  1951 
       
  1952 			case 0x0F: // Fund cost multiplier
       
  1953 				indsp->cost_multiplier = grf_load_byte(&buf);
       
  1954 				break;
       
  1955 
       
  1956 			case 0x10: // Production cargo types
       
  1957 				for (byte j = 0; j < 2; j++) {
       
  1958 					indsp->produced_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
       
  1959 				}
       
  1960 				break;
       
  1961 
       
  1962 			case 0x11: // Acceptance cargo types
       
  1963 				for (byte j = 0; j < 3; j++) {
       
  1964 					indsp->accepts_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
       
  1965 				}
       
  1966 				grf_load_byte(&buf); // Unnused, eat it up
       
  1967 				break;
       
  1968 
       
  1969 			case 0x12: // Production multipliers
       
  1970 			case 0x13:
       
  1971 				indsp->production_rate[prop - 0x12] = grf_load_byte(&buf);
       
  1972 				break;
       
  1973 
       
  1974 			case 0x14: // Minimal amount of cargo distributed
       
  1975 				indsp->minimal_cargo = grf_load_byte(&buf);
       
  1976 				break;
       
  1977 
       
  1978 			case 0x15: { // Random sound effects
       
  1979 				indsp->number_of_sounds = grf_load_byte(&buf);
       
  1980 				uint8 *sounds = MallocT<uint8>(indsp->number_of_sounds);
       
  1981 
       
  1982 				for (uint8 j = 0; j < indsp->number_of_sounds; j++) sounds[j] = grf_load_byte(&buf);
       
  1983 				indsp->random_sounds = sounds;
       
  1984 				SETBIT(indsp->cleanup_flag, 0);
       
  1985 			} break;
       
  1986 
       
  1987 			case 0x16: // Conflicting industry types
       
  1988 				for (byte j = 0; j < 3; j++) indsp->conflicting[j] = grf_load_byte(&buf);
       
  1989 				break;
       
  1990 
       
  1991 			case 0x17: // Probability in random game
       
  1992 				indsp->appear_ingame[_opt.landscape] = grf_load_byte(&buf);
       
  1993 				break;
       
  1994 
       
  1995 			case 0x18: // Probability during gameplay
       
  1996 				indsp->appear_creation[_opt.landscape] = grf_load_byte(&buf);
       
  1997 				break;
       
  1998 
       
  1999 			case 0x19: // Map color
       
  2000 				indsp->map_colour = MapDOSColour(grf_load_byte(&buf));
       
  2001 				break;
       
  2002 
       
  2003 			case 0x1A: // Special industry flags to define special behavior
       
  2004 				indsp->behaviour = (IndustyBehaviour)grf_load_dword(&buf);
       
  2005 				break;
       
  2006 
       
  2007 			case 0x1B: // New industry text ID
       
  2008 				indsp->new_industry_text = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
       
  2009 				break;
       
  2010 
       
  2011 			case 0x1C: // Input cargo multipliers for the three input cargo types
       
  2012 			case 0x1D:
       
  2013 			case 0x1E: {
       
  2014 					uint32 multiples = grf_load_dword(&buf);
       
  2015 					indsp->input_cargo_multiplier[prop - 0x1C][0] = GB(multiples, 0,15);
       
  2016 					indsp->input_cargo_multiplier[prop - 0x1C][1] = GB(multiples, 15,15);
       
  2017 				} break;
       
  2018 
       
  2019 			case 0x1F: // Industry name
       
  2020 				indsp->name = MapGRFStringID(_cur_grffile->grfid, grf_load_word(&buf));
       
  2021 				break;
       
  2022 
       
  2023 			case 0x20: // Prospecting success chance
       
  2024 				indsp->prospecting_chance = grf_load_dword(&buf);
       
  2025 				break;
       
  2026 
       
  2027 			case 0x21:   // Callback flags
       
  2028 			case 0x22: { // Callback additional flags
       
  2029 				byte aflag = grf_load_byte(&buf);
       
  2030 				SB(indsp->callback_flags, (prop - 0x21) * 8, 8, aflag);
       
  2031 			} break;
       
  2032 
       
  2033 			default:
       
  2034 				ret = true;
       
  2035 				break;
       
  2036 		}
       
  2037 	}
       
  2038 
       
  2039 	*bufp = buf;
       
  2040 	return ret;
       
  2041 }
       
  2042 
  1680 /* Action 0x00 */
  2043 /* Action 0x00 */
  1681 static void FeatureChangeInfo(byte *buf, int len)
  2044 static void FeatureChangeInfo(byte *buf, int len)
  1682 {
  2045 {
  1683 	byte *bufend = buf + len;
  2046 	byte *bufend = buf + len;
  1684 
  2047 
  1703 		/* GSF_STATION */      StationChangeInfo,
  2066 		/* GSF_STATION */      StationChangeInfo,
  1704 		/* GSF_CANAL */        NULL,
  2067 		/* GSF_CANAL */        NULL,
  1705 		/* GSF_BRIDGE */       BridgeChangeInfo,
  2068 		/* GSF_BRIDGE */       BridgeChangeInfo,
  1706 		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
  2069 		/* GSF_TOWNHOUSE */    TownHouseChangeInfo,
  1707 		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
  2070 		/* GSF_GLOBALVAR */    GlobalVarChangeInfo,
  1708 		/* GSF_INDUSTRYTILES */NULL,
  2071 		/* GSF_INDUSTRYTILES */IndustrytilesChangeInfo,
  1709 		/* GSF_INDUSTRIES */   NULL,
  2072 		/* GSF_INDUSTRIES */   IndustriesChangeInfo,
  1710 		/* GSF_CARGOS */       NULL, /* Cargo is handled during reservation */
  2073 		/* GSF_CARGOS */       NULL, /* Cargo is handled during reservation */
  1711 		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
  2074 		/* GSF_SOUNDFX */      SoundEffectChangeInfo,
  1712 	};
  2075 	};
  1713 
  2076 
  1714 	if (!check_length(len, 6, "FeatureChangeInfo")) return;
  2077 	if (!check_length(len, 6, "FeatureChangeInfo")) return;
  2560 
  2923 
  2561 		hs->spritegroup = _cur_grffile->spritegroups[groupid];
  2924 		hs->spritegroup = _cur_grffile->spritegroups[groupid];
  2562 	}
  2925 	}
  2563 }
  2926 }
  2564 
  2927 
       
  2928 static void IndustryMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
       
  2929 {
       
  2930 	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return;
       
  2931 
       
  2932 	byte *bp = &buf[4 + idcount + cidcount * 3];
       
  2933 	uint16 groupid = grf_load_word(&bp);
       
  2934 
       
  2935 	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
       
  2936 		grfmsg(1, "IndustryMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
       
  2937 		       groupid, _cur_grffile->spritegroups_count);
       
  2938 		return;
       
  2939 	}
       
  2940 
       
  2941 	for (uint i = 0; i < idcount; i++) {
       
  2942 		uint8 id = buf[3 + i];
       
  2943 		IndustrySpec *indsp = _cur_grffile->industryspec[id];
       
  2944 
       
  2945 		if (indsp == NULL) {
       
  2946 			grfmsg(1, "IndustryMapSpriteGroup: Too many industries defined, skipping");
       
  2947 			return;
       
  2948 		}
       
  2949 
       
  2950 		indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
       
  2951 	}
       
  2952 }
       
  2953 
       
  2954 static void IndustrytileMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
       
  2955 {
       
  2956 	if (!HASBIT(_ttdpatch_flags[3], 0x07)) return;
       
  2957 
       
  2958 	byte *bp = &buf[4 + idcount + cidcount * 3];
       
  2959 	uint16 groupid = grf_load_word(&bp);
       
  2960 
       
  2961 	if (groupid >= _cur_grffile->spritegroups_count || _cur_grffile->spritegroups[groupid] == NULL) {
       
  2962 		grfmsg(1, "IndustrytileMapSpriteGroup: Spriteset 0x%04X out of range 0x%X or empty, skipping.",
       
  2963 		       groupid, _cur_grffile->spritegroups_count);
       
  2964 		return;
       
  2965 	}
       
  2966 
       
  2967 	for (uint i = 0; i < idcount; i++) {
       
  2968 		uint8 id = buf[3 + i];
       
  2969 		IndustryTileSpec *indtsp = _cur_grffile->indtspec[id];
       
  2970 
       
  2971 		if (indtsp == NULL) {
       
  2972 			grfmsg(1, "IndustrytileMapSpriteGroup: Too many industry tiles defined, skipping");
       
  2973 			return;
       
  2974 		}
       
  2975 
       
  2976 		indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
       
  2977 	}
       
  2978 }
  2565 
  2979 
  2566 static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
  2980 static void CargoMapSpriteGroup(byte *buf, uint8 idcount, uint8 cidcount)
  2567 {
  2981 {
  2568 	byte *bp = &buf[4 + idcount + cidcount * 3];
  2982 	byte *bp = &buf[4 + idcount + cidcount * 3];
  2569 	uint16 groupid = grf_load_word(&bp);
  2983 	uint16 groupid = grf_load_word(&bp);
  2647 			StationMapSpriteGroup(buf, idcount, cidcount);
  3061 			StationMapSpriteGroup(buf, idcount, cidcount);
  2648 			return;
  3062 			return;
  2649 
  3063 
  2650 		case GSF_TOWNHOUSE:
  3064 		case GSF_TOWNHOUSE:
  2651 			TownHouseMapSpriteGroup(buf, idcount, cidcount);
  3065 			TownHouseMapSpriteGroup(buf, idcount, cidcount);
       
  3066 			return;
       
  3067 
       
  3068 		case GSF_INDUSTRIES:
       
  3069 			IndustryMapSpriteGroup(buf, idcount, cidcount);
       
  3070 			return;
       
  3071 
       
  3072 		case GSF_INDUSTRYTILES:
       
  3073 			IndustrytileMapSpriteGroup(buf, idcount, cidcount);
  2652 			return;
  3074 			return;
  2653 
  3075 
  2654 		case GSF_CARGOS:
  3076 		case GSF_CARGOS:
  2655 			CargoMapSpriteGroup(buf, idcount, cidcount);
  3077 			CargoMapSpriteGroup(buf, idcount, cidcount);
  2656 			return;
  3078 			return;
  4778 	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
  5200 	for (GRFFile *file = _first_grffile; file != NULL; file = file->next) {
  4779 		if (file->industryspec != NULL) {
  5201 		if (file->industryspec != NULL) {
  4780 			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
  5202 			for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
  4781 				IndustrySpec *indsp = file->industryspec[i];
  5203 				IndustrySpec *indsp = file->industryspec[i];
  4782 
  5204 
  4783 				if (indsp != NULL  && indsp->enabled) {
  5205 				if (indsp != NULL && indsp->enabled) {
       
  5206 					StringID strid;
       
  5207 					/* process the conversion of text at the end, so to be sure everything will be fine
       
  5208 					 * and available.  Check if it does not return undefind marker, which is a very good sign of a
       
  5209 					 * substitute industry who has not changed the string been examined, thus using it as such */
       
  5210 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->name);
       
  5211 					if (strid != STR_UNDEFINED) indsp->name = strid;
       
  5212 
       
  5213 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->closure_text);
       
  5214 					if (strid != STR_UNDEFINED) indsp->closure_text = strid;
       
  5215 
       
  5216 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_up_text);
       
  5217 					if (strid != STR_UNDEFINED) indsp->production_up_text = strid;
       
  5218 
       
  5219 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->production_down_text);
       
  5220 					if (strid != STR_UNDEFINED) indsp->production_down_text = strid;
       
  5221 
       
  5222 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
       
  5223 					if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
       
  5224 
  4784 					_industry_mngr.SetEntitySpec(indsp);
  5225 					_industry_mngr.SetEntitySpec(indsp);
  4785 					_loaded_newgrf_features.has_newindustries = true;
  5226 					_loaded_newgrf_features.has_newindustries = true;
  4786 				}
  5227 				}
  4787 			}
  5228 			}
  4788 		}
  5229 		}
  4791 			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
  5232 			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
  4792 				IndustryTileSpec *indtsp = file->indtspec[i];
  5233 				IndustryTileSpec *indtsp = file->indtspec[i];
  4793 				if (indtsp != NULL) {
  5234 				if (indtsp != NULL) {
  4794 					_industile_mngr.SetEntitySpec(indtsp);
  5235 					_industile_mngr.SetEntitySpec(indtsp);
  4795 				}
  5236 				}
       
  5237 			}
       
  5238 		}
       
  5239 	}
       
  5240 
       
  5241 	for (uint j = 0; j < NUM_INDUSTRYTYPES; j++) {
       
  5242 		IndustrySpec *indsp = &_industry_specs[j];
       
  5243 		if (indsp->enabled && indsp->grf_prop.grffile != NULL) {
       
  5244 			for (uint i = 0; i < 3; i++) {
       
  5245 				indsp->conflicting[i] = MapNewGRFIndustryType(indsp->conflicting[i], indsp->grf_prop.grffile->grfid);
  4796 			}
  5246 			}
  4797 		}
  5247 		}
  4798 	}
  5248 	}
  4799 }
  5249 }
  4800 
  5250