* Put an industry on the map. * @param i Just allocated poolitem, mostly empty. * @param tile North tile of the industry. * @param type Type of the industry. * @param layout Industrylayout to build. * @param layout_index Number of the industry layout. * @param t Nearest town. * @param founder F
| 1760 | * @param initial_random_bits Random bits for the industry. |
| 1761 | */ |
| 1762 | static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, const IndustryTileLayout &layout, size_t layout_index, Town *t, Owner founder, uint16_t initial_random_bits) |
| 1763 | { |
| 1764 | const IndustrySpec *indspec = GetIndustrySpec(type); |
| 1765 | |
| 1766 | i->location = TileArea(tile, 1, 1); |
| 1767 | i->type = type; |
| 1768 | |
| 1769 | auto &industries = Industry::industries[type]; |
| 1770 | industries.insert(i->index); |
| 1771 | |
| 1772 | size_t produced_count = 0; |
| 1773 | for (size_t index = 0; index < std::size(indspec->produced_cargo); ++index) { |
| 1774 | if (IsValidCargoType(indspec->produced_cargo[index])) { |
| 1775 | produced_count = index + 1; |
| 1776 | } |
| 1777 | } |
| 1778 | for (size_t index = 0; index < produced_count; ++index) { |
| 1779 | Industry::ProducedCargo &p = i->produced.emplace_back(); |
| 1780 | p.cargo = indspec->produced_cargo[index]; |
| 1781 | p.rate = indspec->production_rate[index]; |
| 1782 | } |
| 1783 | |
| 1784 | size_t accepted_count = 0; |
| 1785 | for (size_t index = 0; index < std::size(indspec->accepts_cargo); ++index) { |
| 1786 | if (IsValidCargoType(indspec->accepts_cargo[index])) { |
| 1787 | accepted_count = index + 1; |
| 1788 | } |
| 1789 | } |
| 1790 | for (size_t index = 0; index < accepted_count; ++index) { |
| 1791 | Industry::AcceptedCargo &a = i->accepted.emplace_back(); |
| 1792 | a.cargo = indspec->accepts_cargo[index]; |
| 1793 | } |
| 1794 | |
| 1795 | /* Randomize initial production if non-original economy is used and there are no production related callbacks. */ |
| 1796 | if (!indspec->UsesOriginalEconomy()) { |
| 1797 | for (auto &p : i->produced) { |
| 1798 | p.rate = ClampTo<uint8_t>((RandomRange(256) + 128) * p.rate >> 8); |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | i->town = t; |
| 1803 | i->owner = OWNER_NONE; |
| 1804 | |
| 1805 | uint16_t r = Random(); |
| 1806 | i->random_colour = static_cast<Colours>(GB(r, 0, 4)); |
| 1807 | i->counter = GB(r, 4, 12); |
| 1808 | i->random = initial_random_bits; |
| 1809 | i->was_cargo_delivered = false; |
| 1810 | i->last_prod_year = TimerGameEconomy::year; |
| 1811 | i->founder = founder; |
| 1812 | i->ctlflags = {}; |
| 1813 | |
| 1814 | i->construction_date = TimerGameCalendar::date; |
| 1815 | i->construction_type = (_game_mode == GM_EDITOR) ? ICT_SCENARIO_EDITOR : |
| 1816 | (_generating_world ? ICT_MAP_GENERATION : ICT_NORMAL_GAMEPLAY); |
| 1817 | |
| 1818 | /* Adding 1 here makes it conform to specs of var44 of varaction2 for industries |
| 1819 | * 0 = created prior of newindustries |
no test coverage detected