diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index b718dbaa42..53dff6091d 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2076,7 +2076,7 @@ CommandCost CmdBuildIndustry(DoCommandFlags flags, TileIndex tile, IndustryType return CMD_ERROR; } - if (_game_mode != GM_EDITOR && GetIndustryProbabilityCallback(it, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) { + if (_game_mode != GM_EDITOR && GetIndustryProbabilityCallback(it, _current_company == OWNER_DEITY ? IndustryAvailabilityCallType::RandomCreation : IndustryAvailabilityCallType::UserCreation, 1) == 0) { return CMD_ERROR; } @@ -2097,7 +2097,7 @@ CommandCost CmdBuildIndustry(DoCommandFlags flags, TileIndex tile, IndustryType bool prospect_success = deity_prospect || Random() <= indspec->prospecting_chance; if (prospect_success) { /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ - IndustryAvailabilityCallType calltype = _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_PROSPECTCREATION; + IndustryAvailabilityCallType calltype = _current_company == OWNER_DEITY ? IndustryAvailabilityCallType::RandomCreation : IndustryAvailabilityCallType::ProspectCreation; AutoRestoreBackup cur_company(_current_company, OWNER_TOWN); for (int i = 0; i < 5000; i++) { /* We should not have more than one Random() in a function call @@ -2130,7 +2130,7 @@ CommandCost CmdBuildIndustry(DoCommandFlags flags, TileIndex tile, IndustryType /* Check subsequently each layout, starting with the given layout in p1 */ for (size_t i = 0; i < num_layouts; i++) { layout = (layout + 1) % num_layouts; - ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, _current_company == OWNER_DEITY ? IACT_RANDOMCREATION : IACT_USERCREATION, &ind); + ret = CreateNewIndustryHelper(tile, it, flags, indspec, layout, random_var8f, random_initial_bits, _current_company, _current_company == OWNER_DEITY ? IndustryAvailabilityCallType::RandomCreation : IndustryAvailabilityCallType::UserCreation, &ind); if (ret.Succeeded()) break; } @@ -2309,7 +2309,7 @@ static uint32_t GetScaledIndustryGenerationProbability(IndustryType it, std::opt uint32_t chance = ind_spc->appear_creation[to_underlying(_settings_game.game_creation.landscape)]; if (!ind_spc->enabled || ind_spc->layouts.empty() || (_game_mode != GM_EDITOR && _settings_game.difficulty.industry_density == IndustryDensity::FundedOnly) || - (chance = GetIndustryProbabilityCallback(it, IACT_MAPGENERATION, chance)) == 0) { + (chance = GetIndustryProbabilityCallback(it, IndustryAvailabilityCallType::MapGeneration, chance)) == 0) { *force_at_least_one = false; return 0; } else { @@ -2341,7 +2341,7 @@ static uint16_t GetIndustryGamePlayProbability(IndustryType it, uint8_t *min_num if (!ind_spc->enabled || ind_spc->layouts.empty() || (ind_spc->behaviour.Test(IndustryBehaviour::Before1950) && TimerGameCalendar::year > 1950) || (ind_spc->behaviour.Test(IndustryBehaviour::After1960) && TimerGameCalendar::year < 1960) || - (chance = GetIndustryProbabilityCallback(it, IACT_RANDOMCREATION, chance)) == 0) { + (chance = GetIndustryProbabilityCallback(it, IndustryAvailabilityCallType::RandomCreation, chance)) == 0) { *min_number = 0; return 0; } @@ -2404,7 +2404,7 @@ static void PlaceInitialIndustry(IndustryType type, bool water, bool try_hard) AutoRestoreBackup cur_company(_current_company, OWNER_NONE); IncreaseGeneratingWorldProgress(water ? GWP_WATER_INDUSTRY : GWP_LAND_INDUSTRY); - PlaceIndustry(type, IACT_MAPGENERATION, try_hard); + PlaceIndustry(type, IndustryAvailabilityCallType::MapGeneration, try_hard); } /** @@ -2722,7 +2722,7 @@ void IndustryBuildData::TryBuildNewIndustry() } /* Try to create the industry. */ - const Industry *ind = PlaceIndustry(it, IACT_RANDOMCREATION, false); + const Industry *ind = PlaceIndustry(it, IndustryAvailabilityCallType::RandomCreation, false); if (ind == nullptr) { this->builddata[it].wait_count = this->builddata[it].max_wait + 1; // Compensate for decrementing below. this->builddata[it].max_wait = std::min(1000, this->builddata[it].max_wait + 2); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 1f10cf1496..5860b22e06 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -311,7 +311,7 @@ class BuildIndustryWindow : public Window { void UpdateAvailability() { - this->enabled = this->selected_type != IT_INVALID && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0); + this->enabled = this->selected_type != IT_INVALID && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IndustryAvailabilityCallType::UserCreation, 1) > 0); } void SetupArrays() diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index fcda0dc1a8..2b2cffadce 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -556,7 +556,7 @@ CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, siz ind.founder = founder; ind.psa = nullptr; - IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, creation_type); + IndustriesResolverObject object(tile, &ind, type, seed, CBID_INDUSTRY_LOCATION, 0, to_underlying(creation_type)); std::array regs100; uint16_t result = object.ResolveCallback(regs100); @@ -579,7 +579,7 @@ uint32_t GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityC const IndustrySpec *indspec = GetIndustrySpec(type); if (indspec->callback_mask.Test(IndustryCallbackMask::Probability)) { - uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, nullptr, type, INVALID_TILE); + uint16_t res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, to_underlying(creation_type), nullptr, type, INVALID_TILE); if (res != CALLBACK_FAILED) { if (indspec->grf_prop.grffile->grf_version < 8) { /* Disallow if result != 0 */ diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h index 201d2439c3..b94aa41ffe 100644 --- a/src/newgrf_industries.h +++ b/src/newgrf_industries.h @@ -68,11 +68,11 @@ struct IndustriesResolverObject : public ResolverObject { }; /** From where has callback #CBID_INDUSTRY_PROBABILITY been called */ -enum IndustryAvailabilityCallType : uint8_t { - IACT_MAPGENERATION, ///< during random map generation - IACT_RANDOMCREATION, ///< during creation of random ingame industry - IACT_USERCREATION, ///< from the Fund/build window - IACT_PROSPECTCREATION, ///< from the Fund/build using prospecting +enum class IndustryAvailabilityCallType : uint8_t { + MapGeneration, ///< during random map generation + RandomCreation, ///< during creation of random ingame industry + UserCreation, ///< from the Fund/build window + ProspectCreation, ///< from the Fund/build using prospecting }; /* in newgrf_industry.cpp */ diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index 45f6080571..77d5350a96 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -240,7 +240,7 @@ CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind ind.founder = founder; std::array regs100; - uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | static_cast(layout_index), gfx, &ind, ind_tile, regs100); + uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, to_underlying(creation_type) << 8 | static_cast(layout_index), gfx, &ind, ind_tile, regs100); if (callback_res == CALLBACK_FAILED) { if (!IsSlopeRefused(GetTileSlope(ind_tile), its->slopes_refused)) return CommandCost(); return CommandCost(STR_ERROR_SITE_UNSUITABLE); diff --git a/src/script/api/script_industrytype.cpp b/src/script/api/script_industrytype.cpp index ffc1bc8b74..49881e7796 100644 --- a/src/script/api/script_industrytype.cpp +++ b/src/script/api/script_industrytype.cpp @@ -96,7 +96,7 @@ if (!IsValidIndustryType(industry_type)) return false; const bool deity = ScriptCompanyMode::IsDeity(); - if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false; + if (::GetIndustryProbabilityCallback(industry_type, deity ? IndustryAvailabilityCallType::RandomCreation : IndustryAvailabilityCallType::UserCreation, 1) == 0) return false; if (deity) return true; if (!::GetIndustrySpec(industry_type)->IsRawIndustry()) return true; @@ -110,7 +110,7 @@ const bool deity = ScriptCompanyMode::IsDeity(); if (!deity && !::GetIndustrySpec(industry_type)->IsRawIndustry()) return false; - if (::GetIndustryProbabilityCallback(industry_type, deity ? IACT_RANDOMCREATION : IACT_USERCREATION, 1) == 0) return false; + if (::GetIndustryProbabilityCallback(industry_type, deity ? IndustryAvailabilityCallType::RandomCreation : IndustryAvailabilityCallType::UserCreation, 1) == 0) return false; /* raw_industry_construction == 2 means "prospect" */ return deity || _settings_game.construction.raw_industry_construction == 2;