|
@@ -1376,25 +1376,29 @@ static bool CheckIfIndustryTilesAreFree(
|
|
|
/* It is almost impossible to have a fully flat land in TG, so what we
|
|
|
* do is that we check if we can make the land flat later on. See
|
|
|
* CheckIfCanLevelIndustryPlatform(). */
|
|
|
return !refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions);
|
|
|
}
|
|
|
|
|
|
static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
|
|
|
/** Is the industry allowed to be built at this place for the town?
|
|
|
* @param tile Tile to construct the industry.
|
|
|
* @param type Type of the industry.
|
|
|
* @param t Town authority that the industry belongs to.
|
|
|
* @return Succeeded or failed command.
|
|
|
*/
|
|
|
static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
|
|
|
{
|
|
|
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
|
|
|
_error_message = STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200;
|
|
|
return false;
|
|
|
return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200);
|
|
|
}
|
|
|
|
|
|
if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
|
|
|
_error_message = STR_ERROR_SITE_UNSUITABLE;
|
|
|
return false;
|
|
|
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
|
|
|
{
|
|
|
int size_x, size_y;
|
|
|
uint curh;
|
|
@@ -1499,20 +1503,25 @@ static bool CheckIfCanLevelIndustryPlatf
|
|
|
|
|
|
_current_company = old_company;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
static bool CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
|
|
|
/** Check that the new industry is far enough from other industries.
|
|
|
* @param tile Tile to construct the industry.
|
|
|
* @param type Type of the new industry.
|
|
|
* @return Succeeded or failed command.
|
|
|
*/
|
|
|
static CommandCost CheckIfFarEnoughFromIndustry(TileIndex tile, int type)
|
|
|
{
|
|
|
const IndustrySpec *indspec = GetIndustrySpec(type);
|
|
|
const Industry *i;
|
|
|
|
|
|
if (_settings_game.economy.same_industry_close && indspec->IsRawIndustry())
|
|
|
/* Allow primary industries to be placed close to any other industry */
|
|
|
return true;
|
|
|
return CommandCost();
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
|
|
/* Within 14 tiles from another industry is considered close */
|
|
|
bool in_low_distance = DistanceMax(tile, i->location.tile) <= 14;
|
|
|
|
|
|
/* check if an industry that accepts the same goods is nearby */
|
|
@@ -1520,26 +1529,24 @@ static bool CheckIfFarEnoughFromIndustry
|
|
|
!indspec->IsRawIndustry() && // not a primary industry?
|
|
|
indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
|
|
|
/* at least one of those options must be true */
|
|
|
_game_mode != GM_EDITOR || // editor must not be stopped
|
|
|
!_settings_game.economy.same_industry_close ||
|
|
|
!_settings_game.economy.multiple_industry_per_town)) {
|
|
|
_error_message = STR_ERROR_INDUSTRY_TOO_CLOSE;
|
|
|
return false;
|
|
|
return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE);
|
|
|
}
|
|
|
|
|
|
/* check if there are any conflicting industry types around */
|
|
|
if ((i->type == indspec->conflicting[0] ||
|
|
|
i->type == indspec->conflicting[1] ||
|
|
|
i->type == indspec->conflicting[2]) &&
|
|
|
in_low_distance) {
|
|
|
_error_message = STR_ERROR_INDUSTRY_TOO_CLOSE;
|
|
|
return false;
|
|
|
return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
/** Production level maximum, minimum and default values.
|
|
|
* It is not a value been really used in order to change, but rather an indicator
|
|
|
* of how the industry is behaving. */
|
|
|
enum ProductionLevels {
|
|
@@ -1694,18 +1701,22 @@ static Industry *CreateNewIndustryHelper
|
|
|
CommandCost ret = _check_new_industry_procs[indspec->check_proc](tile);
|
|
|
ret.SetGlobalErrorMessage();
|
|
|
if (ret.Failed()) return NULL;
|
|
|
}
|
|
|
|
|
|
if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, it, type)) return NULL;
|
|
|
if (!CheckIfFarEnoughFromIndustry(tile, type)) return NULL;
|
|
|
CommandCost ret = CheckIfFarEnoughFromIndustry(tile, type);
|
|
|
ret.SetGlobalErrorMessage();
|
|
|
if (ret.Failed()) return NULL;
|
|
|
|
|
|
const Town *t = FindTownForIndustry(tile, type);
|
|
|
if (t == NULL) return NULL;
|
|
|
|
|
|
if (!CheckIfIndustryIsAllowed(tile, type, t)) return NULL;
|
|
|
ret = CheckIfIndustryIsAllowed(tile, type, t);
|
|
|
ret.SetGlobalErrorMessage();
|
|
|
if (ret.Failed()) return NULL;
|
|
|
|
|
|
if (!Industry::CanAllocateItem()) return NULL;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Industry *i = new Industry(tile);
|
|
|
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER | DC_EXEC, it, type);
|