diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f235ab23fb..3893670b6d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -380,8 +380,8 @@ jobs: bundle_name: "focal" compiler: "g++" c_compiler: "gcc" - - container_image: "ubuntu:21.10" - bundle_name: "impish" + - container_image: "ubuntu:22.04" + bundle_name: "jammy" compiler: "g++" c_compiler: "gcc" - container_image: "debian:buster" diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 6a2a645a8e..f1f3082abd 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1493,18 +1493,12 @@ bool IsSlopeRefused(Slope current, Slope refused) * Are the tiles of the industry free? * @param tile Position to check. * @param layout Industry tiles table. - * @param layout_index The index of the layout to build/fund * @param type Type of the industry. - * @param initial_random_bits The random bits the industry is going to have after construction. - * @param founder Industry founder - * @param creation_type The circumstances the industry is created under. - * @param[out] custom_shape_check Perform custom check for the site. * @return Failed or succeeded command. */ -static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = nullptr) +static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileLayout &layout, IndustryType type) { - bool refused_slope = false; - bool custom_shape = false; + IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; for (const IndustryTileLayoutTile &it : layout) { IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx); @@ -1526,20 +1520,9 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil const IndustryTileSpec *its = GetIndustryTileSpec(gfx); - IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour; - /* Perform land/water check if not disabled */ if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); - if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { - custom_shape = true; - CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type); - if (ret.Failed()) return ret; - } else { - Slope tileh = GetTileSlope(cur_tile); - refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); - } - if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house) if (!IsTileType(cur_tile, MP_HOUSE)) { @@ -1557,12 +1540,50 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil DoCommandFlag flags = DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING; if ((ind_behav & INDUSTRYBEH_BUILT_ONWATER) && IsWaterTile(cur_tile)) flags |= DC_ALLOW_REMOVE_WATER; CommandCost ret = DoCommand(cur_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); - if (ret.Failed()) return ret; } } } + return CommandCost(); +} + +/** + * Check slope requirements for industry tiles. + * @param tile Position to check. + * @param layout Industry tiles table. + * @param layout_index The index of the layout to build/fund + * @param type Type of the industry. + * @param initial_random_bits The random bits the industry is going to have after construction. + * @param founder Industry founder + * @param creation_type The circumstances the industry is created under. + * @param[out] custom_shape_check Perform custom check for the site. + * @return Failed or succeeded command. + */ +static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check = nullptr) +{ + bool refused_slope = false; + bool custom_shape = false; + + for (const IndustryTileLayoutTile &it : layout) { + IndustryGfx gfx = GetTranslatedIndustryTileID(it.gfx); + TileIndex cur_tile = TileAddWrap(tile, it.ti.x, it.ti.y); + assert(IsValidTile(cur_tile)); // checked before in CheckIfIndustryTilesAreFree + + if (gfx != GFX_WATERTILE_SPECIALCHECK) { + const IndustryTileSpec *its = GetIndustryTileSpec(gfx); + + if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) { + custom_shape = true; + CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, layout_index, initial_random_bits, founder, creation_type); + if (ret.Failed()) return ret; + } else { + Slope tileh = GetTileSlope(cur_tile); + refused_slope |= IsSlopeRefused(tileh, its->slopes_refused); + } + } + } + if (custom_shape_check != nullptr) *custom_shape_check = custom_shape; /* It is almost impossible to have a fully flat land in TG, so what we @@ -2008,28 +2029,11 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do { assert(layout_index < indspec->layouts.size()); const IndustryTileLayout &layout = indspec->layouts[layout_index]; - bool custom_shape_check = false; *ip = nullptr; - std::vector object_areas(_cleared_object_areas); - CommandCost ret = CheckIfIndustryTilesAreFree(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check); - _cleared_object_areas = object_areas; - if (ret.Failed()) return ret; - - if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) { - ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type); - } else { - ret = _check_new_industry_procs[indspec->check_proc](tile); - } - if (ret.Failed()) return ret; - - if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && - !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout, type)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); - } - - ret = CheckIfFarEnoughFromConflictingIndustry(tile, type); + /* 1. Cheap: Built-in checks on industry level. */ + CommandCost ret = CheckIfFarEnoughFromConflictingIndustry(tile, type); if (ret.Failed()) return ret; Town *t = nullptr; @@ -2040,6 +2044,30 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do ret = CheckIfIndustryIsAllowed(tile, type, t); if (ret.Failed()) return ret; + /* 2. Built-in checks on industry tiles. */ + std::vector object_areas(_cleared_object_areas); + ret = CheckIfIndustryTilesAreFree(tile, layout, type); + _cleared_object_areas = object_areas; + if (ret.Failed()) return ret; + + /* 3. NewGRF-defined checks on industry level. */ + if (HasBit(GetIndustrySpec(type)->callback_mask, CBM_IND_LOCATION)) { + ret = CheckIfCallBackAllowsCreation(tile, type, layout_index, random_var8f, random_initial_bits, founder, creation_type); + } else { + ret = _check_new_industry_procs[indspec->check_proc](tile); + } + if (ret.Failed()) return ret; + + /* 4. Expensive: NewGRF-defined checks on industry tiles. */ + bool custom_shape_check = false; + ret = CheckIfIndustryTileSlopes(tile, layout, layout_index, type, random_initial_bits, founder, creation_type, &custom_shape_check); + if (ret.Failed()) return ret; + + if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && + !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout, type)) { + return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + } + if (!Industry::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_INDUSTRIES); if (flags & DC_EXEC) { diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 444097a83a..50bf644118 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1798,9 +1798,12 @@ again: Direction new_dir = RoadVehGetSlidingDirection(v, x, y); if (v->IsFrontEngine()) { - Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); + const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); if (u != nullptr) { v->cur_speed = u->First()->cur_speed; + /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ + v->path.tile.push_front(tile); + v->path.td.push_front(dir); return false; } } @@ -1911,15 +1914,15 @@ again: int y = TileY(v->tile) * TILE_SIZE + rdp[turn_around_start_frame].y; Direction new_dir = RoadVehGetSlidingDirection(v, x, y); - if (v->IsFrontEngine() && RoadVehFindCloseTo(v, x, y, new_dir) != nullptr) { - /* We are blocked. */ - v->cur_speed = 0; - if (!v->path.empty()) { - /* Prevent pathfinding rerun as we already know where we are heading to. */ + if (v->IsFrontEngine()) { + const Vehicle *u = RoadVehFindCloseTo(v, x, y, new_dir); + if (u != nullptr) { + v->cur_speed = u->First()->cur_speed; + /* We might be blocked, prevent pathfinding rerun as we already know where we are heading to. */ v->path.tile.push_front(v->tile); v->path.td.push_front(dir); + return false; } - return false; } uint32 r = VehicleEnterTile(v, v->tile, x, y);