mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: make IndustryAvailabilityCallType a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
89174e891a
commit
77be3fc12d
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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<int32_t, 16> 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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -240,7 +240,7 @@ CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind
|
||||
ind.founder = founder;
|
||||
|
||||
std::array<int32_t, 16> regs100;
|
||||
uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | static_cast<uint32_t>(layout_index), gfx, &ind, ind_tile, regs100);
|
||||
uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, to_underlying(creation_type) << 8 | static_cast<uint32_t>(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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user