@@ -1264,17 +1264,14 @@ static bool CheckIfIndustryTilesAreFree(
_current_company = OWNER_TOWN;
bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR));
_current_company = old_company;
if (not_clearable) return false;
} else {
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
CompanyID old_company = _current_company;
bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR));
/* Clear the tiles, but do not affect town ratings */
bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR));
}
} while ((++it)->ti.x != -0x80);
@@ -1365,13 +1362,13 @@ static bool CheckIfCanLevelIndustryPlatf
size_y = max_y + 4;
/* Check if we don't leave the map */
if (TileX(cur_tile) + size_x >= MapMaxX() || TileY(cur_tile) + size_y >= MapMaxY()) return false;
/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
* Perform terraforming as OWNER_TOWN to disable autoslope. */
* Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
curh = TileHeight(tile_walk);
if (curh != h) {
@@ -1453,13 +1450,13 @@ enum ProductionLevels {
PRODLEVEL_CLOSURE = 0x00, ///< signal set to actually close the industry
PRODLEVEL_MINIMUM = 0x04, ///< below this level, the industry is set to be closing
PRODLEVEL_DEFAULT = 0x10, ///< default level set when the industry is created
PRODLEVEL_MAXIMUM = 0x80, ///< the industry is running at full speed
};
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner)
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner, Owner founder)
{
const IndustrySpec *indspec = GetIndustrySpec(type);
uint32 r;
uint j;
i->xy = tile;
@@ -1505,13 +1502,13 @@ static void DoCreateNewIndustry(Industry
i->last_month_transported[0] = 0;
i->last_month_transported[1] = 0;
i->was_cargo_delivered = false;
i->last_prod_year = _cur_year;
i->last_month_production[0] = i->production_rate[0] * 8;
i->last_month_production[1] = i->production_rate[1] * 8;
i->founder = _current_company;
i->founder = founder;
if (HasBit(indspec->callback_flags, CBM_IND_DECIDE_COLOUR)) {
uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
if (res != CALLBACK_FAILED) i->random_colour = GB(res, 0, 4);
@@ -1543,15 +1540,12 @@ static void DoCreateNewIndustry(Industry
i->selected_layout = layout + 1;
if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
i->prod_level = PRODLEVEL_DEFAULT;
/* Clear the tiles as OWNER_TOWN, to not affect town rating, and to not clear protected buildings */
do {
TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
byte size;
@@ -1559,13 +1553,13 @@ static void DoCreateNewIndustry(Industry
if (size > i->width) i->width = size;
size = it->ti.y;
if (size > i->height)i->height = size;
WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
DoCommand(cur_tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
DoCommand(cur_tile, 0, 0, DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
MakeIndustry(cur_tile, i->index, it->gfx, Random(), wc);
if (_generating_world) {
SetIndustryConstructionCounter(cur_tile, 3);
SetIndustryConstructionStage(cur_tile, 2);
@@ -1574,13 +1568,12 @@ static void DoCreateNewIndustry(Industry
/* it->gfx is stored in the map. But the translated ID cur_gfx is the interesting one */
IndustryGfx cur_gfx = GetTranslatedIndustryTileID(it->gfx);
const IndustryTileSpec *its = GetIndustryTileSpec(cur_gfx);
if (its->animation_info != 0xFFFF) AddAnimatedTile(cur_tile);
i->width++;
i->height++;
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
for (j = 0; j != 50; j++) PlantRandomFarmField(i);
@@ -1592,15 +1585,16 @@ static void DoCreateNewIndustry(Industry
* @param tile tile where industry is built
* @param type of industry to build
* @param flags of operations to conduct
* @param indspec pointer to industry specifications
* @param itspec_index the index of the itsepc to build/fund
* @param seed random seed (possibly) used by industries
* @param founder Founder of the industry
* @return the pointer of the newly created industry, or NULL if it failed
*/
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed)
static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed, Owner founder)
const IndustryTileTable *it = indspec->table[itspec_index];
bool custom_shape_check = false;
if (!CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, &custom_shape_check)) return NULL;
@@ -1620,13 +1614,13 @@ static Industry *CreateNewIndustryHelper
if (!Industry::CanAllocateItem()) return NULL;
if (flags & DC_EXEC) {
Industry *i = new Industry(tile);
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_EXEC, it, type);
DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE);
DoCreateNewIndustry(i, tile, type, it, itspec_index, t, OWNER_NONE, founder);
return i;
/* We need to return a non-NULL pointer to tell we have created an industry.
* However, we haven't created a real one (no DC_EXEC), so return a fake one. */
@@ -1657,40 +1651,44 @@ CommandCost CmdBuildIndustry(TileIndex t
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 0 && indspec->IsRawIndustry()) {
return CMD_ERROR;
if (_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry()) {
/* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */
CompanyID founder = _current_company;
/* Prospecting has a chance to fail, however we cannot guarantee that something can
* be built on the map, so the chance gets lower when the map is fuller, but there
* is nothing we can really do about that. */
if (Random() <= indspec->prospecting_chance) {
for (int i = 0; i < 5000; i++) {
/* We should not have more than one Random() in a function call
* because parameter evaluation order is not guaranteed in the c++ standard
tile = RandomTile();
ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2);
ind = CreateNewIndustryHelper(tile, p1, flags, indspec, RandomRange(indspec->num_table), p2, founder);
if (ind != NULL) {
break;
_current_company = founder;
int count = indspec->num_table;
const IndustryTileTable * const *itt = indspec->table;
int num = Clamp(GB(p1, 16, 16), 0, count - 1);
_error_message = STR_0239_SITE_UNSUITABLE;
if (--count < 0) return CMD_ERROR;
if (--num < 0) num = indspec->num_table - 1;
} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2);
ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2, _current_company);
if (ind == NULL) return CMD_ERROR;
if (flags & DC_EXEC && _game_mode != GM_EDITOR && ind != NULL) {
SetDParam(0, indspec->name);
if (indspec->new_industry_text > STR_LAST_STRINGID) {
@@ -1709,13 +1707,13 @@ CommandCost CmdBuildIndustry(TileIndex t
Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
uint32 seed = Random();
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed);
return CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, RandomRange(indspec->num_table), seed, OWNER_NONE);
enum {
NB_NUMOFINDUSTRY = 11,
NB_DIFFICULTY_LEVEL = 5,
Status change: