src/industry_cmd.cpp
changeset 7676 926233c6e06a
parent 7666 69cabc700c4d
child 7733 bc007653ce57
equal deleted inserted replaced
7675:93f4f0f33c9a 7676:926233c6e06a
  1439 	i->accepts_cargo[1] = indspec->accepts_cargo[1];
  1439 	i->accepts_cargo[1] = indspec->accepts_cargo[1];
  1440 	i->accepts_cargo[2] = indspec->accepts_cargo[2];
  1440 	i->accepts_cargo[2] = indspec->accepts_cargo[2];
  1441 	i->production_rate[0] = indspec->production_rate[0];
  1441 	i->production_rate[0] = indspec->production_rate[0];
  1442 	i->production_rate[1] = indspec->production_rate[1];
  1442 	i->production_rate[1] = indspec->production_rate[1];
  1443 
  1443 
  1444 	if (_patches.smooth_economy) {
  1444 	/* don't use smooth economy for industries using production callbacks */
       
  1445 	if (_patches.smooth_economy  && !(HASBIT(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HASBIT(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL))) {
  1445 		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
  1446 		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
  1446 		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
  1447 		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
  1447 	}
  1448 	}
  1448 
  1449 
  1449 	i->town = t;
  1450 	i->town = t;
  1860 	StringID str = STR_NULL;
  1861 	StringID str = STR_NULL;
  1861 	bool closeit = false;
  1862 	bool closeit = false;
  1862 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
  1863 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
  1863 	bool standard = true;
  1864 	bool standard = true;
  1864 	bool suppress_message = false;
  1865 	bool suppress_message = false;
       
  1866 	/* don't use smooth economy for industries using production callbacks */
       
  1867 	bool smooth_economy = _patches.smooth_economy && !(HASBIT(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HASBIT(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL));
  1865 	byte div = 0;
  1868 	byte div = 0;
  1866 	byte mul = 0;
  1869 	byte mul = 0;
  1867 
  1870 
  1868 	if (HASBIT(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE)) {
  1871 	if (HASBIT(indspec->callback_flags, monthly ? CBM_IND_MONTHLYPROD_CHANGE : CBM_IND_PRODUCTION_CHANGE)) {
  1869 		uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy);
  1872 		uint16 res = GetIndustryCallback(monthly ? CBID_INDUSTRY_MONTHLYPROD_CHANGE : CBID_INDUSTRY_PRODUCTION_CHANGE, 0, Random(), i, i->type, i->xy);
  1886 				case 0xC: mul = res - 0x9; break; // Multiply production by 32
  1889 				case 0xC: mul = res - 0x9; break; // Multiply production by 32
  1887 			}
  1890 			}
  1888 		}
  1891 		}
  1889 	}
  1892 	}
  1890 
  1893 
  1891 	if (standard && monthly != _patches.smooth_economy) return;
  1894 	if (standard && monthly != smooth_economy) return;
  1892 
  1895 
  1893 	if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
  1896 	if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
  1894 
  1897 
  1895 	if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
  1898 	if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
  1896 		/* decrease or increase */
  1899 		/* decrease or increase */
  1897 		bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE;
  1900 		bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE;
  1898 
  1901 
  1899 		if (_patches.smooth_economy) {
  1902 		if (smooth_economy) {
  1900 			closeit = true;
  1903 			closeit = true;
  1901 			for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
  1904 			for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
  1902 				uint32 r = Random();
  1905 				uint32 r = Random();
  1903 				int old_prod, new_prod, percent;
  1906 				int old_prod, new_prod, percent;
  1904 				int mag;
  1907 				int mag;
  1947 			}
  1950 			}
  1948 		}
  1951 		}
  1949 	}
  1952 	}
  1950 
  1953 
  1951 	if (standard && indspec->life_type & INDUSTRYLIFE_PROCESSING) {
  1954 	if (standard && indspec->life_type & INDUSTRYLIFE_PROCESSING) {
  1952 		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, _patches.smooth_economy ? 180 : 2)) {
  1955 		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, smooth_economy ? 180 : 2)) {
  1953 			closeit = true;
  1956 			closeit = true;
  1954 		}
  1957 		}
  1955 	}
  1958 	}
  1956 
  1959 
  1957 	/* Increase if needed */
  1960 	/* Increase if needed */