src/industry_cmd.cpp
changeset 8234 ce9107c79628
parent 8230 64f28fe2d5c8
child 8264 b1e85998c7d3
equal deleted inserted replaced
8233:560ddd54f068 8234:ce9107c79628
  1375 	_current_player = old_player;
  1375 	_current_player = old_player;
  1376 	return true;
  1376 	return true;
  1377 }
  1377 }
  1378 
  1378 
  1379 
  1379 
  1380 static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
  1380 static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
  1381 {
  1381 {
  1382 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1382 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1383 	const Industry *i;
  1383 	const Industry *i;
  1384 
  1384 
  1385 	/* accepting industries won't be close, not even with patch */
       
  1386 	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
  1385 	if (_patches.same_industry_close && indspec->accepts_cargo[0] == CT_INVALID)
       
  1386 		/* Allow primary industries to be placed close to any other industry */
  1387 		return true;
  1387 		return true;
  1388 
  1388 
  1389 	FOR_ALL_INDUSTRIES(i) {
  1389 	FOR_ALL_INDUSTRIES(i) {
       
  1390 		/* Within 14 tiles from another industry is considered close */
       
  1391 		bool in_low_distance = DistanceMax(tile, i->xy) <= 14;
       
  1392 
  1390 		/* check if an industry that accepts the same goods is nearby */
  1393 		/* check if an industry that accepts the same goods is nearby */
  1391 		if (DistanceMax(tile, i->xy) <= 14 &&
  1394 		if (in_low_distance &&
  1392 				indspec->accepts_cargo[0] != CT_INVALID &&
  1395 				indspec->accepts_cargo[0] != CT_INVALID && // not a primary industry?
  1393 				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
  1396 				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
  1394 					_game_mode != GM_EDITOR ||
  1397 				/* at least one of those options must be true */
  1395 					!_patches.same_industry_close ||
  1398 				_game_mode != GM_EDITOR || // editor must not be stopped
  1396 					!_patches.multiple_industry_per_town
  1399 				!_patches.same_industry_close ||
  1397 				)) {
  1400 				!_patches.multiple_industry_per_town)) {
  1398 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1401 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1399 			return false;
  1402 			return false;
  1400 		}
  1403 		}
  1401 
  1404 
  1402 		/* check "not close to" field. */
  1405 		/* check if there are any conflicting industry types around */
  1403 		if ((i->type == indspec->conflicting[0] || i->type == indspec->conflicting[1] || i->type == indspec->conflicting[2]) &&
  1406 		if ((i->type == indspec->conflicting[0] ||
  1404 				DistanceMax(tile, i->xy) <= 14) {
  1407 				i->type == indspec->conflicting[1] ||
       
  1408 				i->type == indspec->conflicting[2]) &&
       
  1409 				in_low_distance) {
  1405 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1410 			_error_message = STR_INDUSTRY_TOO_CLOSE;
  1406 			return false;
  1411 			return false;
  1407 		}
  1412 		}
  1408 	}
  1413 	}
  1409 	return true;
  1414 	return true;
  1556 	} else {
  1561 	} else {
  1557 		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
  1562 		if (!_check_new_industry_procs[indspec->check_proc](tile)) return NULL;
  1558 	}
  1563 	}
  1559 
  1564 
  1560 	if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
  1565 	if (!custom_shape_check && _patches.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, 0, it, type)) return NULL;
  1561 	if (!CheckIfTooCloseToIndustry(tile, type)) return NULL;
  1566 	if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
  1562 
  1567 
  1563 	const Town *t = CheckMultipleIndustryInTown(tile, type);
  1568 	const Town *t = CheckMultipleIndustryInTown(tile, type);
  1564 	if (t == NULL) return NULL;
  1569 	if (t == NULL) return NULL;
  1565 
  1570 
  1566 	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
  1571 	if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;