mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-30 23:54:35 +01:00
Codechange: Use EnumBitSet for DoCommandFlags
This commit is contained in:
@@ -489,7 +489,7 @@ static void GetTileDesc_Industry(TileIndex tile, TileDesc *td)
|
||||
}
|
||||
}
|
||||
|
||||
static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags)
|
||||
static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlags flags)
|
||||
{
|
||||
Industry *i = Industry::GetByTile(tile);
|
||||
const IndustrySpec *indspec = GetIndustrySpec(i->type);
|
||||
@@ -501,15 +501,15 @@ static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags)
|
||||
*/
|
||||
if ((_current_company != OWNER_WATER && _game_mode != GM_EDITOR &&
|
||||
!_cheats.magic_bulldozer.value) ||
|
||||
((flags & DC_AUTO) != 0) ||
|
||||
flags.Test(DoCommandFlag::Auto) ||
|
||||
(_current_company == OWNER_WATER &&
|
||||
(indspec->behaviour.Test(IndustryBehaviour::BuiltOnWater) ||
|
||||
HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) {
|
||||
SetDParam(1, indspec->name);
|
||||
return CommandCost(flags & DC_AUTO ? STR_ERROR_GENERIC_OBJECT_IN_THE_WAY : INVALID_STRING_ID);
|
||||
return CommandCost(flags.Test(DoCommandFlag::Auto) ? STR_ERROR_GENERIC_OBJECT_IN_THE_WAY : INVALID_STRING_ID);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
AI::BroadcastNewEvent(new ScriptEventIndustryClose(i->index));
|
||||
Game::NewEvent(new ScriptEventIndustryClose(i->index));
|
||||
delete i;
|
||||
@@ -1115,7 +1115,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *)
|
||||
_industry_sound_tile = tile;
|
||||
if (_settings_client.sound.ambient) SndPlayTileFx(SND_38_LUMBER_MILL_1, tile);
|
||||
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC, tile);
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlag::Execute, tile);
|
||||
|
||||
cur_company.Restore();
|
||||
return true;
|
||||
@@ -1506,13 +1506,13 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil
|
||||
|
||||
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN);
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_NONE, cur_tile);
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do({}, cur_tile);
|
||||
cur_company.Restore();
|
||||
|
||||
if (ret.Failed()) return ret;
|
||||
} else {
|
||||
/* Clear the tiles, but do not affect town ratings */
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoTestTownRating, DoCommandFlag::NoModifyTownRating}, cur_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
@@ -1619,7 +1619,7 @@ static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int i
|
||||
* This function tries to flatten out the land below an industry, without
|
||||
* damaging the surroundings too much.
|
||||
*/
|
||||
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, const IndustryTileLayout &layout)
|
||||
static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlags flags, const IndustryTileLayout &layout)
|
||||
{
|
||||
int max_x = 0;
|
||||
int max_y = 0;
|
||||
@@ -1660,14 +1660,14 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
|
||||
}
|
||||
/* This is not 100% correct check, but the best we can do without modifying the map.
|
||||
* What is missing, is if the difference in height is more than 1.. */
|
||||
if (std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags & ~DC_EXEC, tile_walk, SLOPE_N, curh <= h)).Failed()) {
|
||||
if (std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), tile_walk, SLOPE_N, curh <= h)).Failed()) {
|
||||
cur_company.Restore();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* Terraform the land under the industry */
|
||||
for (TileIndex tile_walk : ta) {
|
||||
uint curh = TileHeight(tile_walk);
|
||||
@@ -1941,7 +1941,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
|
||||
WaterClass wc = (IsWaterTile(cur_tile) ? GetWaterClass(cur_tile) : WATER_CLASS_INVALID);
|
||||
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, cur_tile);
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Execute, DoCommandFlag::NoTestTownRating, DoCommandFlag::NoModifyTownRating}, cur_tile);
|
||||
|
||||
MakeIndustry(cur_tile, i->index, it.gfx, Random(), wc);
|
||||
|
||||
@@ -1982,7 +1982,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||
*
|
||||
* @post \c *ip contains the newly created industry if all checks are successful and the \a flags request actual creation, else it contains \c nullptr afterwards.
|
||||
*/
|
||||
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, size_t layout_index, uint32_t random_var8f, uint16_t random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
|
||||
static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCommandFlags flags, const IndustrySpec *indspec, size_t layout_index, uint32_t random_var8f, uint16_t random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
|
||||
{
|
||||
assert(layout_index < indspec->layouts.size());
|
||||
const IndustryTileLayout &layout = indspec->layouts[layout_index];
|
||||
@@ -2021,15 +2021,15 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
|
||||
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)) {
|
||||
!_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DoCommandFlag::NoWater, layout)) {
|
||||
return CommandCost(STR_ERROR_SITE_UNSUITABLE);
|
||||
}
|
||||
|
||||
if (!Industry::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_INDUSTRIES);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
*ip = new Industry(tile);
|
||||
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER | DC_EXEC, layout);
|
||||
if (!custom_shape_check) CheckIfCanLevelIndustryPlatform(tile, {DoCommandFlag::NoWater, DoCommandFlag::Execute}, layout);
|
||||
DoCreateNewIndustry(*ip, tile, type, layout, layout_index, t, founder, random_initial_bits);
|
||||
}
|
||||
|
||||
@@ -2046,7 +2046,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do
|
||||
* @param seed seed to use for desyncfree randomisations
|
||||
* @return the cost of this operation or an error
|
||||
*/
|
||||
CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed)
|
||||
CommandCost CmdBuildIndustry(DoCommandFlags flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed)
|
||||
{
|
||||
if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
|
||||
|
||||
@@ -2075,7 +2075,7 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType i
|
||||
|
||||
Industry *ind = nullptr;
|
||||
if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) {
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
/* 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. */
|
||||
@@ -2124,7 +2124,7 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType i
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
|
||||
if ((flags & DC_EXEC) && ind != nullptr && _game_mode != GM_EDITOR) {
|
||||
if (flags.Test(DoCommandFlag::Execute) && ind != nullptr && _game_mode != GM_EDITOR) {
|
||||
AdvertiseIndustryOpening(ind);
|
||||
}
|
||||
|
||||
@@ -2138,7 +2138,7 @@ CommandCost CmdBuildIndustry(DoCommandFlag flags, TileIndex tile, IndustryType i
|
||||
* @param ctlflags IndustryControlFlags
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, IndustryControlFlags ctlflags)
|
||||
CommandCost CmdIndustrySetFlags(DoCommandFlags flags, IndustryID ind_id, IndustryControlFlags ctlflags)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
@@ -2146,7 +2146,7 @@ CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, Industry
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
if (!ctlflags.IsValid()) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) ind->ctlflags = ctlflags;
|
||||
if (flags.Test(DoCommandFlag::Execute)) ind->ctlflags = ctlflags;
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
@@ -2160,7 +2160,7 @@ CommandCost CmdIndustrySetFlags(DoCommandFlag flags, IndustryID ind_id, Industry
|
||||
* @param custom_news Custom news message text.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const std::string &custom_news)
|
||||
CommandCost CmdIndustrySetProduction(DoCommandFlags flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const std::string &custom_news)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
if (prod_level < PRODLEVEL_MINIMUM || prod_level > PRODLEVEL_MAXIMUM) return CMD_ERROR;
|
||||
@@ -2168,7 +2168,7 @@ CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, uin
|
||||
Industry *ind = Industry::GetIfValid(ind_id);
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
StringID str = STR_NULL;
|
||||
if (prod_level > ind->prod_level) {
|
||||
str = GetIndustrySpec(ind->type)->production_up_text;
|
||||
@@ -2217,7 +2217,7 @@ CommandCost CmdIndustrySetProduction(DoCommandFlag flags, IndustryID ind_id, uin
|
||||
* @param consumer Set exclusive consumer if true, supplier if false.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer)
|
||||
CommandCost CmdIndustrySetExclusivity(DoCommandFlags flags, IndustryID ind_id, Owner company_id, bool consumer)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
@@ -2227,7 +2227,7 @@ CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Ow
|
||||
if (company_id != OWNER_NONE && company_id != INVALID_OWNER && company_id != OWNER_DEITY
|
||||
&& !Company::IsValidID(company_id)) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
if (consumer) {
|
||||
ind->exclusive_consumer = company_id;
|
||||
} else {
|
||||
@@ -2246,14 +2246,14 @@ CommandCost CmdIndustrySetExclusivity(DoCommandFlag flags, IndustryID ind_id, Ow
|
||||
* @param text - Additional industry text.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdIndustrySetText(DoCommandFlag flags, IndustryID ind_id, const std::string &text)
|
||||
CommandCost CmdIndustrySetText(DoCommandFlags flags, IndustryID ind_id, const std::string &text)
|
||||
{
|
||||
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
|
||||
Industry *ind = Industry::GetIfValid(ind_id);
|
||||
if (ind == nullptr) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
ind->text.clear();
|
||||
if (!text.empty()) ind->text = text;
|
||||
InvalidateWindowData(WC_INDUSTRY_VIEW, ind->index);
|
||||
@@ -2277,7 +2277,7 @@ static Industry *CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAv
|
||||
uint32_t seed2 = Random();
|
||||
Industry *i = nullptr;
|
||||
size_t layout_index = RandomRange((uint32_t)indspec->layouts.size());
|
||||
[[maybe_unused]] CommandCost ret = CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, layout_index, seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
|
||||
[[maybe_unused]] CommandCost ret = CreateNewIndustryHelper(tile, type, DoCommandFlag::Execute, indspec, layout_index, seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
|
||||
assert(i != nullptr || ret.Failed());
|
||||
return i;
|
||||
}
|
||||
@@ -3160,7 +3160,7 @@ bool IndustrySpec::UsesOriginalEconomy() const
|
||||
IndustryCallbackMask::ProdChangeBuild}); // production change callbacks
|
||||
}
|
||||
|
||||
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
|
||||
static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
|
||||
{
|
||||
if (AutoslopeEnabled()) {
|
||||
/* We imitate here TTDP's behaviour:
|
||||
|
||||
Reference in New Issue
Block a user