src/industry_cmd.cpp
branchNewGRF_ports
changeset 10991 d8811e327d12
parent 10731 67db0d431d5e
child 10994 cd9968b6f96b
equal deleted inserted replaced
10731:67db0d431d5e 10991:d8811e327d12
    68 	memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs));
    68 	memcpy(&_industry_specs, &_origin_industry_specs, sizeof(_origin_industry_specs));
    69 
    69 
    70 	/* once performed, enable only the current climate industries */
    70 	/* once performed, enable only the current climate industries */
    71 	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
    71 	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
    72 		_industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET &&
    72 		_industry_specs[i].enabled = i < NEW_INDUSTRYOFFSET &&
    73 				HasBit(_origin_industry_specs[i].climate_availability, _settings.game_creation.landscape);
    73 				HasBit(_origin_industry_specs[i].climate_availability, _settings_game.game_creation.landscape);
    74 	}
    74 	}
    75 
    75 
    76 	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
    76 	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
    77 	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
    77 	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
    78 
    78 
    82 }
    82 }
    83 
    83 
    84 void ResetIndustryCreationProbility(IndustryType type)
    84 void ResetIndustryCreationProbility(IndustryType type)
    85 {
    85 {
    86 	assert(type < INVALID_INDUSTRYTYPE);
    86 	assert(type < INVALID_INDUSTRYTYPE);
    87 	_industry_specs[type].appear_creation[_settings.game_creation.landscape] = 0;
    87 	_industry_specs[type].appear_creation[_settings_game.game_creation.landscape] = 0;
    88 }
    88 }
    89 
    89 
    90 DEFINE_OLD_POOL_GENERIC(Industry, Industry)
    90 DEFINE_OLD_POOL_GENERIC(Industry, Industry)
    91 
    91 
    92 /**
    92 /**
   332 	return GetTileMaxZ(tile);
   332 	return GetTileMaxZ(tile);
   333 }
   333 }
   334 
   334 
   335 static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
   335 static Foundation GetFoundation_Industry(TileIndex tile, Slope tileh)
   336 {
   336 {
       
   337 	IndustryGfx gfx = GetIndustryGfx(tile);
       
   338 
       
   339 	/* For NewGRF industry tiles we might not be drawing a foundation. We need to
       
   340 	 * account for this, otherwise we might be applying a FOUNDATION_LEVELED
       
   341 	 * on a steep slope which is not allowed. Furthermore other structures should
       
   342 	 * draw the wall of the foundation in this case.
       
   343 	 */
       
   344 	if (gfx >= NEW_INDUSTRYTILEOFFSET) {
       
   345 		const IndustryTileSpec *indts = GetIndustryTileSpec(gfx);
       
   346 		if (indts->grf_prop.spritegroup != NULL && HasBit(indts->callback_flags, CBM_INDT_DRAW_FOUNDATIONS)) {
       
   347 			uint32 callback_res = GetIndustryTileCallback(CBID_INDUSTRY_DRAW_FOUNDATIONS, 0, 0, gfx, GetIndustryByTile(tile), tile);
       
   348 			if (callback_res == 0) return FOUNDATION_NONE;
       
   349 		}
       
   350 	}
   337 	return FlatteningFoundation(tileh);
   351 	return FlatteningFoundation(tileh);
   338 }
   352 }
   339 
   353 
   340 static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
   354 static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
   341 {
   355 {
   886 	uint count;
   900 	uint count;
   887 	uint counter;
   901 	uint counter;
   888 	uint field_type;
   902 	uint field_type;
   889 	int type;
   903 	int type;
   890 
   904 
   891 	if (_settings.game_creation.landscape == LT_ARCTIC) {
   905 	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
   892 		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
   906 		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
   893 			return;
   907 			return;
   894 	}
   908 	}
   895 
   909 
   896 	/* determine field size */
   910 	/* determine field size */
   897 	r = (Random() & 0x303) + 0x404;
   911 	r = (Random() & 0x303) + 0x404;
   898 	if (_settings.game_creation.landscape == LT_ARCTIC) r += 0x404;
   912 	if (_settings_game.game_creation.landscape == LT_ARCTIC) r += 0x404;
   899 	size_x = GB(r, 0, 8);
   913 	size_x = GB(r, 0, 8);
   900 	size_y = GB(r, 8, 8);
   914 	size_y = GB(r, 8, 8);
   901 
   915 
   902 	/* offset tile to match size */
   916 	/* offset tile to match size */
   903 	tile -= TileDiffXY(size_x / 2, size_y / 2);
   917 	tile -= TileDiffXY(size_x / 2, size_y / 2);
   924 			MarkTileDirtyByTile(cur_tile);
   938 			MarkTileDirtyByTile(cur_tile);
   925 		}
   939 		}
   926 	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
   940 	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
   927 
   941 
   928 	type = 3;
   942 	type = 3;
   929 	if (_settings.game_creation.landscape != LT_ARCTIC && _settings.game_creation.landscape != LT_TROPIC) {
   943 	if (_settings_game.game_creation.landscape != LT_ARCTIC && _settings_game.game_creation.landscape != LT_TROPIC) {
   930 		type = _plantfarmfield_type[Random() & 0xF];
   944 		type = _plantfarmfield_type[Random() & 0xF];
   931 	}
   945 	}
   932 
   946 
   933 	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
   947 	SetupFarmFieldFence(tile - TileDiffXY(1, 0), size_y, type, AXIS_Y);
   934 	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
   948 	SetupFarmFieldFence(tile - TileDiffXY(0, 1), size_x, type, AXIS_X);
   979 {
   993 {
   980 	TileIndex tile = i->xy;
   994 	TileIndex tile = i->xy;
   981 
   995 
   982 	if (!IsIndustryCompleted(tile)) return;  ///< Can't proceed if not completed
   996 	if (!IsIndustryCompleted(tile)) return;  ///< Can't proceed if not completed
   983 
   997 
   984 	if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
   998 	if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
   985 		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
   999 		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
   986 }
  1000 }
   987 
  1001 
   988 static void ProduceIndustryGoods(Industry *i)
  1002 static void ProduceIndustryGoods(Industry *i)
   989 {
  1003 {
  1061 	return true;
  1075 	return true;
  1062 }
  1076 }
  1063 
  1077 
  1064 static bool CheckNewIndustry_Forest(TileIndex tile)
  1078 static bool CheckNewIndustry_Forest(TileIndex tile)
  1065 {
  1079 {
  1066 	if (_settings.game_creation.landscape == LT_ARCTIC) {
  1080 	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
  1067 		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
  1081 		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
  1068 			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
  1082 			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
  1069 			return false;
  1083 			return false;
  1070 		}
  1084 		}
  1071 	}
  1085 	}
  1073 }
  1087 }
  1074 
  1088 
  1075 static bool CheckNewIndustry_OilRefinery(TileIndex tile)
  1089 static bool CheckNewIndustry_OilRefinery(TileIndex tile)
  1076 {
  1090 {
  1077 	if (_game_mode == GM_EDITOR) return true;
  1091 	if (_game_mode == GM_EDITOR) return true;
  1078 	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings.game_creation.oil_refinery_limit) return true;
  1092 	if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return true;
  1079 
  1093 
  1080 	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
  1094 	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
  1081 	return false;
  1095 	return false;
  1082 }
  1096 }
  1083 
  1097 
  1085 
  1099 
  1086 static bool CheckNewIndustry_OilRig(TileIndex tile)
  1100 static bool CheckNewIndustry_OilRig(TileIndex tile)
  1087 {
  1101 {
  1088 	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
  1102 	if (_game_mode == GM_EDITOR && _ignore_restrictions) return true;
  1089 	if (TileHeight(tile) == 0 &&
  1103 	if (TileHeight(tile) == 0 &&
  1090 			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings.game_creation.oil_refinery_limit) return true;
  1104 			DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return true;
  1091 
  1105 
  1092 	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
  1106 	_error_message = STR_483B_CAN_ONLY_BE_POSITIONED;
  1093 	return false;
  1107 	return false;
  1094 }
  1108 }
  1095 
  1109 
  1096 static bool CheckNewIndustry_Farm(TileIndex tile)
  1110 static bool CheckNewIndustry_Farm(TileIndex tile)
  1097 {
  1111 {
  1098 	if (_settings.game_creation.landscape == LT_ARCTIC) {
  1112 	if (_settings_game.game_creation.landscape == LT_ARCTIC) {
  1099 		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
  1113 		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
  1100 			_error_message = STR_0239_SITE_UNSUITABLE;
  1114 			_error_message = STR_0239_SITE_UNSUITABLE;
  1101 			return false;
  1115 			return false;
  1102 		}
  1116 		}
  1103 	}
  1117 	}
  1169 	const Town *t;
  1183 	const Town *t;
  1170 	const Industry *i;
  1184 	const Industry *i;
  1171 
  1185 
  1172 	t = ClosestTownFromTile(tile, (uint)-1);
  1186 	t = ClosestTownFromTile(tile, (uint)-1);
  1173 
  1187 
  1174 	if (_settings.economy.multiple_industry_per_town) return t;
  1188 	if (_settings_game.economy.multiple_industry_per_town) return t;
  1175 
  1189 
  1176 	FOR_ALL_INDUSTRIES(i) {
  1190 	FOR_ALL_INDUSTRIES(i) {
  1177 		if (i->type == (byte)type &&
  1191 		if (i->type == (byte)type &&
  1178 				i->town == t) {
  1192 				i->town == t) {
  1179 			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
  1193 			_error_message = STR_0287_ONLY_ONE_ALLOWED_PER_TOWN;
  1255 	if (custom_shape_check != NULL) *custom_shape_check = custom_shape;
  1269 	if (custom_shape_check != NULL) *custom_shape_check = custom_shape;
  1256 
  1270 
  1257 	/* It is almost impossible to have a fully flat land in TG, so what we
  1271 	/* It is almost impossible to have a fully flat land in TG, so what we
  1258 	 *  do is that we check if we can make the land flat later on. See
  1272 	 *  do is that we check if we can make the land flat later on. See
  1259 	 *  CheckIfCanLevelIndustryPlatform(). */
  1273 	 *  CheckIfCanLevelIndustryPlatform(). */
  1260 	return !refused_slope || (_settings.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions);
  1274 	return !refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions);
  1261 }
  1275 }
  1262 
  1276 
  1263 static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
  1277 static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
  1264 {
  1278 {
  1265 	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
  1279 	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
  1385 static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
  1399 static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
  1386 {
  1400 {
  1387 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1401 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1388 	const Industry *i;
  1402 	const Industry *i;
  1389 
  1403 
  1390 	if (_settings.economy.same_industry_close && indspec->IsRawIndustry())
  1404 	if (_settings_game.economy.same_industry_close && indspec->IsRawIndustry())
  1391 		/* Allow primary industries to be placed close to any other industry */
  1405 		/* Allow primary industries to be placed close to any other industry */
  1392 		return true;
  1406 		return true;
  1393 
  1407 
  1394 	FOR_ALL_INDUSTRIES(i) {
  1408 	FOR_ALL_INDUSTRIES(i) {
  1395 		/* Within 14 tiles from another industry is considered close */
  1409 		/* Within 14 tiles from another industry is considered close */
  1399 		if (in_low_distance &&
  1413 		if (in_low_distance &&
  1400 				!indspec->IsRawIndustry() && // not a primary industry?
  1414 				!indspec->IsRawIndustry() && // not a primary industry?
  1401 				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
  1415 				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
  1402 				/* at least one of those options must be true */
  1416 				/* at least one of those options must be true */
  1403 				_game_mode != GM_EDITOR || // editor must not be stopped
  1417 				_game_mode != GM_EDITOR || // editor must not be stopped
  1404 				!_settings.economy.same_industry_close ||
  1418 				!_settings_game.economy.same_industry_close ||
  1405 				!_settings.economy.multiple_industry_per_town)) {
  1419 				!_settings_game.economy.multiple_industry_per_town)) {
  1406 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1420 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1407 			return false;
  1421 			return false;
  1408 		}
  1422 		}
  1409 
  1423 
  1410 		/* check if there are any conflicting industry types around */
  1424 		/* check if there are any conflicting industry types around */
  1447 	i->accepts_cargo[2] = indspec->accepts_cargo[2];
  1461 	i->accepts_cargo[2] = indspec->accepts_cargo[2];
  1448 	i->production_rate[0] = indspec->production_rate[0];
  1462 	i->production_rate[0] = indspec->production_rate[0];
  1449 	i->production_rate[1] = indspec->production_rate[1];
  1463 	i->production_rate[1] = indspec->production_rate[1];
  1450 
  1464 
  1451 	/* don't use smooth economy for industries using production related callbacks */
  1465 	/* don't use smooth economy for industries using production related callbacks */
  1452 	if (_settings.economy.smooth_economy &&
  1466 	if (_settings_game.economy.smooth_economy &&
  1453 	    !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
  1467 	    !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
  1454 	    !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE))             // production change callbacks
  1468 	    !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE))             // production change callbacks
  1455 	) {
  1469 	) {
  1456 		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
  1470 		i->production_rate[0] = min((RandomRange(256) + 128) * i->production_rate[0] >> 8 , 255);
  1457 		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
  1471 		i->production_rate[1] = min((RandomRange(256) + 128) * i->production_rate[1] >> 8 , 255);
  1575 		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL;
  1589 		if (!CheckIfCallBackAllowsCreation(tile, type, itspec_index, seed)) return NULL;
  1576 	} else {
  1590 	} else {
  1577 		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
  1591 		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
  1578 	}
  1592 	}
  1579 
  1593 
  1580 	if (!custom_shape_check && _settings.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
  1594 	if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
  1581 	if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
  1595 	if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
  1582 
  1596 
  1583 	const Town *t = CheckMultipleIndustryInTown(tile, type);
  1597 	const Town *t = CheckMultipleIndustryInTown(tile, type);
  1584 	if (t == NULL) return NULL;
  1598 	if (t == NULL) return NULL;
  1585 
  1599 
  1619 		return CMD_ERROR;
  1633 		return CMD_ERROR;
  1620 	}
  1634 	}
  1621 
  1635 
  1622 	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
  1636 	/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
  1623 	 * Raw material industries are industries that do not accept cargo (at least for now) */
  1637 	 * Raw material industries are industries that do not accept cargo (at least for now) */
  1624 	if (_game_mode != GM_EDITOR && _settings.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
  1638 	if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
  1625 		return CMD_ERROR;
  1639 		return CMD_ERROR;
  1626 	}
  1640 	}
  1627 
  1641 
  1628 	if (_game_mode != GM_EDITOR && _settings.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
  1642 	if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
  1629 		if (flags & DC_EXEC) {
  1643 		if (flags & DC_EXEC) {
  1630 			/* Prospecting has a chance to fail, however we cannot guarantee that something can
  1644 			/* Prospecting has a chance to fail, however we cannot guarantee that something can
  1631 			 * be built on the map, so the chance gets lower when the map is fuller, but there
  1645 			 * be built on the map, so the chance gets lower when the map is fuller, but there
  1632 			 * is nothing we can really do about that. */
  1646 			 * is nothing we can really do about that. */
  1633 			if (Random() <= indspec->prospecting_chance) {
  1647 			if (Random() <= indspec->prospecting_chance) {
  1698  * @param amount of industries that need to be built */
  1712  * @param amount of industries that need to be built */
  1699 static void PlaceInitialIndustry(IndustryType type, int amount)
  1713 static void PlaceInitialIndustry(IndustryType type, int amount)
  1700 {
  1714 {
  1701 	/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
  1715 	/* We need to bypass the amount given in parameter if it exceeds the maximum dimension of the
  1702 	 * _numof_industry_table.  newgrf can specify a big amount */
  1716 	 * _numof_industry_table.  newgrf can specify a big amount */
  1703 	int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_settings.difficulty.number_industries][amount];
  1717 	int num = (amount > NB_NUMOFINDUSTRY) ? amount : _numof_industry_table[_settings_game.difficulty.number_industries][amount];
  1704 	const IndustrySpec *ind_spc = GetIndustrySpec(type);
  1718 	const IndustrySpec *ind_spc = GetIndustrySpec(type);
  1705 
  1719 
  1706 	/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1720 	/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1707 	num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1721 	num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1708 
  1722 
  1709 	if (_settings.difficulty.number_industries != 0) {
  1723 	if (_settings_game.difficulty.number_industries != 0) {
  1710 		PlayerID old_player = _current_player;
  1724 		PlayerID old_player = _current_player;
  1711 		_current_player = OWNER_NONE;
  1725 		_current_player = OWNER_NONE;
  1712 		assert(num > 0);
  1726 		assert(num > 0);
  1713 
  1727 
  1714 		do {
  1728 		do {
  1733 	uint8 chance;
  1747 	uint8 chance;
  1734 	IndustryType it;
  1748 	IndustryType it;
  1735 	const IndustrySpec *ind_spc;
  1749 	const IndustrySpec *ind_spc;
  1736 
  1750 
  1737 	/* Find the total amount of industries */
  1751 	/* Find the total amount of industries */
  1738 	if (_settings.difficulty.number_industries > 0) {
  1752 	if (_settings_game.difficulty.number_industries > 0) {
  1739 		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
  1753 		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
  1740 
  1754 
  1741 			ind_spc = GetIndustrySpec(it);
  1755 			ind_spc = GetIndustrySpec(it);
  1742 
  1756 
  1743 			if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
  1757 			if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
  1744 				ResetIndustryCreationProbility(it);
  1758 				ResetIndustryCreationProbility(it);
  1745 			}
  1759 			}
  1746 
  1760 
  1747 			chance = ind_spc->appear_creation[_settings.game_creation.landscape];
  1761 			chance = ind_spc->appear_creation[_settings_game.game_creation.landscape];
  1748 			if (ind_spc->enabled && chance > 0) {
  1762 			if (ind_spc->enabled && chance > 0) {
  1749 				/* once the chance of appearance is determind, it have to be scaled by
  1763 				/* once the chance of appearance is determind, it have to be scaled by
  1750 				 * the difficulty level. The "chance" in question is more an index into
  1764 				 * the difficulty level. The "chance" in question is more an index into
  1751 				 * the _numof_industry_table,in fact */
  1765 				 * the _numof_industry_table,in fact */
  1752 				int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_settings.difficulty.number_industries][chance];
  1766 				int num = (chance > NB_NUMOFINDUSTRY) ? chance : _numof_industry_table[_settings_game.difficulty.number_industries][chance];
  1753 
  1767 
  1754 				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1768 				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1755 				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1769 				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1756 				i += num;
  1770 				i += num;
  1757 			}
  1771 			}
  1758 		}
  1772 		}
  1759 	}
  1773 	}
  1760 
  1774 
  1761 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1775 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1762 
  1776 
  1763 	if (_settings.difficulty.number_industries > 0) {
  1777 	if (_settings_game.difficulty.number_industries > 0) {
  1764 		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
  1778 		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
  1765 			/* Once the number of industries has been determined, let's really create them.
  1779 			/* Once the number of industries has been determined, let's really create them.
  1766 			 * The test for chance allows us to try create industries that are available only
  1780 			 * The test for chance allows us to try create industries that are available only
  1767 			 * for this landscape.
  1781 			 * for this landscape.
  1768 			 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1782 			 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1769 			 *          processed that scaling above? No, don't think so.  Will find a way. */
  1783 			 *          processed that scaling above? No, don't think so.  Will find a way. */
  1770 			ind_spc = GetIndustrySpec(it);
  1784 			ind_spc = GetIndustrySpec(it);
  1771 			if (ind_spc->enabled) {
  1785 			if (ind_spc->enabled) {
  1772 				chance = ind_spc->appear_creation[_settings.game_creation.landscape];
  1786 				chance = ind_spc->appear_creation[_settings_game.game_creation.landscape];
  1773 				if (chance > 0) PlaceInitialIndustry(it, chance);
  1787 				if (chance > 0) PlaceInitialIndustry(it, chance);
  1774 			}
  1788 			}
  1775 		}
  1789 		}
  1776 	}
  1790 	}
  1777 }
  1791 }
  1821 	uint16 probability_max = 0;
  1835 	uint16 probability_max = 0;
  1822 
  1836 
  1823 	/* Generate a list of all possible industries that can be built. */
  1837 	/* Generate a list of all possible industries that can be built. */
  1824 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1838 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1825 		ind_spc = GetIndustrySpec(j);
  1839 		ind_spc = GetIndustrySpec(j);
  1826 		byte chance = ind_spc->appear_ingame[_settings.game_creation.landscape];
  1840 		byte chance = ind_spc->appear_ingame[_settings_game.game_creation.landscape];
  1827 
  1841 
  1828 		if (!ind_spc->enabled || chance == 0) continue;
  1842 		if (!ind_spc->enabled || chance == 0) continue;
  1829 
  1843 
  1830 		/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
  1844 		/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
  1831 		 * and if appearing chance for this landscape is above 0, this industry can be chosen */
  1845 		 * and if appearing chance for this landscape is above 0, this industry can be chosen */
  1879 static bool CheckIndustryCloseDownProtection(IndustryType type)
  1893 static bool CheckIndustryCloseDownProtection(IndustryType type)
  1880 {
  1894 {
  1881 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1895 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1882 
  1896 
  1883 	/* oil wells (or the industries with that flag set) are always allowed to closedown */
  1897 	/* oil wells (or the industries with that flag set) are always allowed to closedown */
  1884 	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _settings.game_creation.landscape == LT_TEMPERATE) return false;
  1898 	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _settings_game.game_creation.landscape == LT_TEMPERATE) return false;
  1885 	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1;
  1899 	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1;
  1886 }
  1900 }
  1887 
  1901 
  1888 /**
  1902 /**
  1889 * Can given cargo type be accepted or produced by the industry?
  1903 * Can given cargo type be accepted or produced by the industry?
  2029 	bool closeit = false;
  2043 	bool closeit = false;
  2030 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
  2044 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
  2031 	bool standard = true;
  2045 	bool standard = true;
  2032 	bool suppress_message = false;
  2046 	bool suppress_message = false;
  2033 	/* don't use smooth economy for industries using production related callbacks */
  2047 	/* don't use smooth economy for industries using production related callbacks */
  2034 	bool smooth_economy = _settings.economy.smooth_economy &&
  2048 	bool smooth_economy = _settings_game.economy.smooth_economy &&
  2035 	                      !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
  2049 	                      !(HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_256_TICKS) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
  2036 	                      !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE));            // production change callbacks
  2050 	                      !(HasBit(indspec->callback_flags, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(indspec->callback_flags, CBM_IND_PRODUCTION_CHANGE));            // production change callbacks
  2037 	byte div = 0;
  2051 	byte div = 0;
  2038 	byte mul = 0;
  2052 	byte mul = 0;
  2039 	int8 increment = 0;
  2053 	int8 increment = 0;
  2070 
  2084 
  2071 	if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
  2085 	if (standard && indspec->life_type == INDUSTRYLIFE_BLACK_HOLE) return;
  2072 
  2086 
  2073 	if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
  2087 	if (standard && (indspec->life_type & (INDUSTRYLIFE_ORGANIC | INDUSTRYLIFE_EXTRACTIVE)) != 0) {
  2074 		/* decrease or increase */
  2088 		/* decrease or increase */
  2075 		bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings.game_creation.landscape == LT_TEMPERATE;
  2089 		bool only_decrease = (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings_game.game_creation.landscape == LT_TEMPERATE;
  2076 
  2090 
  2077 		if (smooth_economy) {
  2091 		if (smooth_economy) {
  2078 			closeit = true;
  2092 			closeit = true;
  2079 			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
  2093 			for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
  2080 				if (i->produced_cargo[j] == CT_INVALID) continue;
  2094 				if (i->produced_cargo[j] == CT_INVALID) continue;
  2255 }
  2269 }
  2256 
  2270 
  2257 Money IndustrySpec::GetConstructionCost() const
  2271 Money IndustrySpec::GetConstructionCost() const
  2258 {
  2272 {
  2259 	return (_price.build_industry *
  2273 	return (_price.build_industry *
  2260 			(_settings.construction.raw_industry_construction == 1 && this->IsRawIndustry() ?
  2274 			(_settings_game.construction.raw_industry_construction == 1 && this->IsRawIndustry() ?
  2261 					this->raw_industry_cost_multiplier :
  2275 					this->raw_industry_cost_multiplier :
  2262 					this->cost_multiplier
  2276 					this->cost_multiplier
  2263 			)) >> 8;
  2277 			)) >> 8;
  2264 }
  2278 }
  2265 
  2279