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 |