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

View File

@@ -259,7 +259,7 @@ static Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
* @param town_check Shall the town rating checked/affected
* @return A succeeded command when it is allowed to remove the road bits, a failed command otherwise.
*/
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlag flags, bool town_check)
CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlags flags, bool town_check)
{
if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return CommandCost();
@@ -322,7 +322,7 @@ CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, R
* @param rt roadtype to remove
* @param town_check should we check if the town allows removal?
*/
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadTramType rtt, bool town_check)
static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pieces, RoadTramType rtt, bool town_check)
{
assert(pieces != ROAD_NONE);
@@ -372,7 +372,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
/* Pay for *every* tile of the bridge or tunnel */
uint len = GetTunnelBridgeLength(other_end, tile) + 2;
cost.AddCost(len * 2 * RoadClearCost(existing_rt));
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
/* A full diagonal road tile has two road bits. */
UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
@@ -398,7 +398,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
} else {
assert(IsDriveThroughStopTile(tile));
cost.AddCost(RoadClearCost(existing_rt) * 2);
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
/* A full diagonal road tile has two road bits. */
UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
SetRoadType(tile, rtt, INVALID_ROADTYPE);
@@ -444,7 +444,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
return CMD_ERROR;
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
if (HasRoadWorks(tile)) {
/* flooding tile with road works, don't forget to remove the effect vehicle too */
assert(_current_company == OWNER_WATER);
@@ -495,7 +495,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
return CMD_ERROR;
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(tile, GetCrossingRoadAxis(tile));
/* A full diagonal road tile has two road bits. */
@@ -607,7 +607,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi
* @param town_id the town that is building the road (INVALID_TOWN if not applicable)
* @return the cost of this operation or an error
*/
CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
{
CompanyID company = _current_company;
CommandCost cost(EXPENSES_CONSTRUCTION);
@@ -679,7 +679,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
}
/* Ignore half built tiles */
if ((flags & DC_EXEC) && IsStraightRoad(existing)) {
if (flags.Test(DoCommandFlag::Execute) && IsStraightRoad(existing)) {
SetDisallowedRoadDirections(tile, dis_new);
MarkTileDirtyByTile(tile);
}
@@ -762,7 +762,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
Track railtrack = AxisToTrack(OtherAxis(roaddir));
YapfNotifyTrackLayoutChange(tile, railtrack);
/* Update company infrastructure counts. A level crossing has two road bits. */
@@ -882,7 +882,7 @@ do_clear:;
cost.AddCost(num_pieces * RoadBuildCost(rt));
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
switch (GetTileType(tile)) {
case MP_ROAD: {
RoadTileType rttype = GetRoadTileType(tile);
@@ -976,7 +976,7 @@ static bool CanConnectToRoad(TileIndex tile, RoadType rt, DiagDirection dir)
* - true = Fail if an obstacle is found. Always take into account start_half and end_half. This behavior is used for scripts
* @return the cost of this operation or an error
*/
CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
{
if (start_tile >= Map::Size()) return CMD_ERROR;
@@ -1072,7 +1072,7 @@ CommandCost CmdBuildLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex
* @param end_half end tile starts in the 2nd half of tile (p2 & 2)
* @return the cost of this operation or an error
*/
std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
{
CommandCost cost(EXPENSES_CONSTRUCTION);
@@ -1104,12 +1104,12 @@ std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlag flags, TileIndex
/* try to remove the halves. */
if (bits != 0) {
RoadTramType rtt = GetRoadTramType(rt);
CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rtt, true);
CommandCost ret = RemoveRoad(tile, DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), bits, rtt, true);
if (ret.Succeeded()) {
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
money_spent += ret.GetCost();
if (money_spent > 0 && money_spent > money_available) {
return { cost, std::get<0>(Command<CMD_REMOVE_LONG_ROAD>::Do(flags & ~DC_EXEC, end_tile, start_tile, rt, axis, start_half, end_half)).GetCost() };
return { cost, std::get<0>(Command<CMD_REMOVE_LONG_ROAD>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), end_tile, start_tile, rt, axis, start_half, end_half)).GetCost() };
}
RemoveRoad(tile, flags, bits, rtt, false);
}
@@ -1146,7 +1146,7 @@ std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlag flags, TileIndex
* @todo When checking for the tile slope,
* distinguish between "Flat land required" and "land sloped in wrong direction"
*/
CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, DiagDirection dir)
{
if (!ValParamRoadType(rt) || !IsValidDiagDirection(dir)) return CMD_ERROR;
@@ -1184,7 +1184,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt,
if (!Depot::CanAllocateItem()) return CMD_ERROR;
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
if (rotate_existing_depot) {
SetRoadDepotExitDirection(tile, dir);
} else {
@@ -1204,7 +1204,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt,
return cost;
}
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlags flags)
{
if (_current_company != OWNER_WATER) {
CommandCost ret = CheckTileOwnership(tile);
@@ -1214,7 +1214,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
Company *c = Company::GetIfValid(GetTileOwner(tile));
if (c != nullptr) {
/* A road depot has two road bits. */
@@ -1231,14 +1231,14 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
}
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
{
switch (GetRoadTileType(tile)) {
case ROAD_TILE_NORMAL: {
RoadBits b = GetAllRoadBits(tile);
/* Clear the road if only one piece is on the tile OR we are not using the DC_AUTO flag */
if ((HasExactlyOneBit(b) && GetRoadBits(tile, RTT_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) {
/* Clear the road if only one piece is on the tile OR we are not using the DoCommandFlag::Auto flag */
if ((HasExactlyOneBit(b) && GetRoadBits(tile, RTT_TRAM) == ROAD_NONE) || !flags.Test(DoCommandFlag::Auto)) {
CommandCost ret(EXPENSES_CONSTRUCTION);
for (RoadTramType rtt : _roadtramtypes) {
if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
@@ -1255,7 +1255,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
case ROAD_TILE_CROSSING: {
CommandCost ret(EXPENSES_CONSTRUCTION);
if (flags & DC_AUTO) return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
/* Must iterate over the roadtypes in a reverse manner because
* tram tracks must be removed before the road bits. */
@@ -1267,7 +1267,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
ret.AddCost(tmp_ret);
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
}
return ret;
@@ -1275,7 +1275,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
default:
case ROAD_TILE_DEPOT:
if (flags & DC_AUTO) {
if (flags.Test(DoCommandFlag::Auto)) {
return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
}
return RemoveRoadDepot(tile, flags);
@@ -2058,7 +2058,7 @@ static void TileLoop_Road(TileIndex tile)
const RoadBits new_rb = CleanUpRoadBits(tile, old_rb);
if (old_rb != new_rb) {
RemoveRoad(tile, DC_EXEC | DC_AUTO | DC_NO_WATER, (old_rb ^ new_rb), RTT_ROAD, true);
RemoveRoad(tile, {DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, (old_rb ^ new_rb), RTT_ROAD, true);
/* If new_rb is 0, there are now no road pieces left and the tile is no longer a road tile */
if (new_rb == 0) {
@@ -2289,7 +2289,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne
if (IsRoadDepot(tile)) {
if (GetTileOwner(tile) == old_owner) {
if (new_owner == INVALID_OWNER) {
Command<CMD_LANDSCAPE_CLEAR>::Do(DC_EXEC | DC_BANKRUPT, tile);
Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile);
} else {
/* A road depot has two road bits. No need to dirty windows here, we'll redraw the whole screen anyway. */
RoadType rt = GetRoadTypeRoad(tile);
@@ -2326,7 +2326,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne
if (IsLevelCrossing(tile)) {
if (GetTileOwner(tile) == old_owner) {
if (new_owner == INVALID_OWNER) {
Command<CMD_REMOVE_SINGLE_RAIL>::Do(DC_EXEC | DC_BANKRUPT, tile, GetCrossingRailTrack(tile));
Command<CMD_REMOVE_SINGLE_RAIL>::Do({DoCommandFlag::Execute, DoCommandFlag::Bankrupt}, tile, GetCrossingRailTrack(tile));
} else {
/* Update infrastructure counts. No need to dirty windows here, we'll redraw the whole screen anyway. */
Company::Get(old_owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR;
@@ -2338,7 +2338,7 @@ static void ChangeTileOwner_Road(TileIndex tile, Owner old_owner, Owner new_owne
}
}
static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
{
if (_settings_game.construction.build_on_slopes && AutoslopeEnabled()) {
switch (GetRoadTileType(tile)) {
@@ -2442,7 +2442,7 @@ static void ConvertRoadTypeOwner(TileIndex tile, uint num_pieces, Owner owner, R
* @param to_type new roadtype to convert to.
* @return the cost of this operation or an error
*/
CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_start, RoadType to_type)
CommandCost CmdConvertRoad(DoCommandFlags flags, TileIndex tile, TileIndex area_start, RoadType to_type)
{
TileIndex area_end = tile;
@@ -2497,7 +2497,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
* acceptance of destructive actions. */
if (owner == OWNER_TOWN) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
CommandCost ret = CheckforTownRating(DC_NONE, t, tt == MP_TUNNELBRIDGE ? TUNNELBRIDGE_REMOVE : ROAD_REMOVE);
CommandCost ret = CheckforTownRating({}, t, tt == MP_TUNNELBRIDGE ? TUNNELBRIDGE_REMOVE : ROAD_REMOVE);
if (ret.Failed()) {
error = ret;
continue;
@@ -2531,7 +2531,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
found_convertible_road = true;
cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
if (flags & DC_EXEC) { // we can safely convert, too
if (flags.Test(DoCommandFlag::Execute)) { // we can safely convert, too
/* Call ConvertRoadTypeOwner() to update the company infrastructure counters. */
if (owner == _current_company) {
ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
@@ -2579,7 +2579,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
found_convertible_road = true;
cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
/* Update the company infrastructure counters. */
if (owner == _current_company) {
/* Each piece should be counted TUNNELBRIDGE_TRACKBIT_FACTOR times
@@ -2605,7 +2605,7 @@ CommandCost CmdConvertRoad(DoCommandFlag flags, TileIndex tile, TileIndex area_s
}
}
if (flags & DC_EXEC) {
if (flags.Test(DoCommandFlag::Execute)) {
/* Roadtype changed, update roadvehicles as when entering different track */
for (RoadVehicle *v : affected_rvs) {
v->CargoChanged();