2 | * Build/Fund an industry
| 2 | * Are the tiles of the industry free?
|
---|
3 | * @param tile tile where industry is built
| 3 | * @param tile Position to check.
|
---|
4 | * @param flags of operations to conduct
| 4 | * @param it Industry tiles table.
|
---|
5 | * @param p1 various bitstuffed elements
| 5 | * @param itspec_index The index of the itsepc to build/fund
|
---|
6 | * - p1 = (bit 0 - 7) - industry type see build_industry.h and see industry.h
| 6 | * @param type Type of the industry.
|
---|
7 | * - p1 = (bit 8 - 15) - first layout to try
| 7 | * @param initial_random_bits The random bits the industry is going to have after construction.
|
---|
8 | * - p1 = (bit 16 ) - 0 = prospect, 1 = fund (only valid if current company is DEITY)
| 8 | * @param founder Industry founder
|
---|
9 | * @param p2 seed to use for desyncfree randomisations
| 9 | * @param creation_type The circumstances the industry is created under.
|
---|
10 | * @param text unused
| 10 | * @param [out] custom_shape_check Perform custom check for the site.
|
---|
11 | * @return the cost of this operation or an error
| 11 | * @return Failed or succeeded command.
|
---|
41 | Industry *ind = NULL;
| 40 | /* Perform land/water check if not disabled */
|
---|
42 | if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) {
| 41 | if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
|
---|
43 | if (flags & DC_EXEC) {
| 42 |
|
---|
44 | /* Prospected industries not built on water are built as OWNER_TOWN to not e.g. be build on owned land of the founder */
| 43 | if (HasBit(its->callback_mask, CBM_INDT_SHAPE_CHECK)) {
|
---|
45 | Owner prospector = OWNER_TOWN;
| 44 | custom_shape = true;
|
---|
46 | if ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) && _current_company < MAX_COMPANIES) prospector = _current_company;
| 45 | CommandCost ret = PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index, initial_random_bits, founder, creation_type);
|
---|
47 | Backup<CompanyByte> cur_company(_current_company, prospector, FILE_LINE);
| 46 | if (ret.Failed()) return ret;
|
---|
48 | /* Prospecting has a chance to fail, however we cannot guarantee that something can
| 47 | } else {
|
---|
49 | * be built on the map, so the chance gets lower when the map is fuller, but there
| 48 | Slope tileh = GetTileSlope(cur_tile);
|
---|
50 | * is nothing we can really do about that. */
| 49 | refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
|
---|
51 | if (deity_prospect || Random() <= indspec->prospecting_chance) {
| 50 | }
|
---|
52 | for (int i = 0; i < 5000; i++) {
| 51 |
|
---|
53 | /* We should not have more than one Random() in a function call
| 52 | if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house
|
---|
54 | * because parameter evaluation order is not guaranteed in the c++ standard
| 53 | ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house)
|
---|
55 | */
| 54 | if (!IsTileType(cur_tile, MP_HOUSE)) {
|
---|
56 | tile = RandomTile();
| 55 | return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS);
|
---|
57 | /* Start with a random layout */
| 56 | }
|
---|
58 | int layout = RandomRange(num_layouts);
| 57 |
|
---|
59 | /* Check now each layout, starting with the random one */
| 58 | /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
|
---|
60 | for (int j = 0; j < num_layouts; j++) {
| 59 | Backup<CompanyByte> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
|
---|
61 | layout = (layout + 1) % num_layouts;
| 60 | CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
---|
62 | ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, cur_company.GetOriginalValue(), _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_PROSPECTCREATION, &ind);
| 61 | cur_company.Restore();
|
---|
63 | if (ret.Succeeded()) break;
| 62 |
|
---|
64 | }
| 63 | if (ret.Failed()) return ret;
|
---|
65 | if (ret.Succeeded()) break;
| 64 | } else {
|
---|
| | 65 | /* Clear the tiles, but do not affect town ratings */
|
---|
| | 66 | CommandCost ret = DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
|
---|
| | 67 |
|
---|
| | 68 | if (ret.Failed()) {
|
---|
| | 69 | if (!(ind_behav & INDUSTRYBEH_BUILT_ONWATER)) return ret;
|
---|
| | 70 |
|
---|
| | 71 | if (!_settings_game.construction.build_on_competitor_canal) return ret;
|
---|
| | 72 | if (_settings_game.construction.build_on_competitor_canal && (ind_behav & INDUSTRYBEH_BUILT_ONWATER) && (IsTileType(cur_tile, MP_INDUSTRY) || _current_company >= MAX_COMPANIES)) return ret;
|
---|