Codechange: Use EnumBitSet for DoCommandFlags

This commit is contained in:
Rubidium
2025-02-13 23:35:52 +01:00
committed by rubidium42
parent f309b90a1d
commit c3d5e6d2a0
95 changed files with 871 additions and 873 deletions
+14 -14
View File
@@ -640,18 +640,18 @@ void ClearSnowLine()
* @param tile tile to clear
* @return the cost of this operation or an error
*/
CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
CommandCost CmdLandscapeClear(DoCommandFlags flags, TileIndex tile)
{
CommandCost cost(EXPENSES_CONSTRUCTION);
bool do_clear = false;
/* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */
if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
if (flags.Test(DoCommandFlag::ForceClearTile) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) {
if (flags.Test(DoCommandFlag::Auto) && GetWaterClass(tile) == WATER_CLASS_CANAL) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST);
do_clear = true;
cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]);
}
Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
Company *c = flags.Any({DoCommandFlag::Auto, DoCommandFlag::Bankrupt}) ? nullptr : Company::GetIfValid(_current_company);
if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) {
return CommandCost(STR_ERROR_CLEARING_LIMIT_REACHED);
}
@@ -666,14 +666,14 @@ CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
* However, we need to check stuff, which is not the same for all object tiles. (e.g. being on water or not) */
/* If a object is removed, it leaves either bare land or water. */
if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
if (flags.Test(DoCommandFlag::NoWater) && HasTileWaterClass(tile) && IsTileOnWater(tile)) {
return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
}
} else {
cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags));
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
if (c != nullptr) c->clear_limit -= 1 << 16;
if (do_clear) {
if (IsWaterTile(tile) && IsCanal(tile)) {
@@ -698,7 +698,7 @@ CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile)
* @param diagonal Whether to use the Orthogonal (false) or Diagonal (true) iterator.
* @return the cost of this operation or an error
*/
std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile, TileIndex start_tile, bool diagonal)
std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, bool diagonal)
{
if (start_tile >= Map::Size()) return { CMD_ERROR, 0 };
@@ -707,15 +707,15 @@ std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile,
CommandCost last_error = CMD_ERROR;
bool had_success = false;
const Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company);
const Company *c = flags.Any({DoCommandFlag::Auto, DoCommandFlag::Bankrupt}) ? nullptr : Company::GetIfValid(_current_company);
int limit = (c == nullptr ? INT32_MAX : GB(c->clear_limit, 16, 16));
if (tile != start_tile) flags |= DC_FORCE_CLEAR_TILE;
if (tile != start_tile) flags.Set(DoCommandFlag::ForceClearTile);
std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
for (; *iter != INVALID_TILE; ++(*iter)) {
TileIndex t = *iter;
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags & ~DC_EXEC, t);
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), t);
if (ret.Failed()) {
last_error = ret;
@@ -725,7 +725,7 @@ std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlag flags, TileIndex tile,
}
had_success = true;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
money -= ret.GetCost();
if (ret.GetCost() > 0 && money < 0) {
return { cost, ret.GetCost() };
@@ -1106,7 +1106,7 @@ static bool RiverMakeWider(TileIndex tile, void *user_data)
TileIndex other_tile = TileAddByDiagDir(tile, d);
if (IsInclinedSlope(GetTileSlope(other_tile)) && IsWaterTile(other_tile)) return false;
}
Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, ComplementSlope(cur_slope), true);
Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto}, tile, ComplementSlope(cur_slope), true);
/* If the river is descending and the adjacent tile has either one or three corners raised, we want to make it match the slope. */
} else if (IsInclinedSlope(desired_slope)) {
@@ -1127,14 +1127,14 @@ static bool RiverMakeWider(TileIndex tile, void *user_data)
/* Lower unwanted corners first. If only one corner is raised, no corners need lowering. */
if (!IsSlopeWithOneCornerRaised(cur_slope)) {
to_change = to_change & ComplementSlope(desired_slope);
Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, false);
Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto}, tile, to_change, false);
}
/* Now check the match and raise any corners needed. */
cur_slope = GetTileSlope(tile);
if (cur_slope != desired_slope && IsSlopeWithOneCornerRaised(cur_slope)) {
to_change = cur_slope ^ desired_slope;
Command<CMD_TERRAFORM_LAND>::Do(DC_EXEC | DC_AUTO, tile, to_change, true);
Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto}, tile, to_change, true);
}
}
/* Update cur_slope after possibly terraforming. */