mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: enum-class-ify Commands
This commit is contained in:
+26
-26
@@ -1087,8 +1087,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
|
||||
* If that fails clear the land, and if that fails exit.
|
||||
* This is to make sure that we can build a road here later. */
|
||||
RoadType rt = GetTownRoadType();
|
||||
if (Command<CMD_BUILD_ROAD>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, t->index).Failed() &&
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Failed()) {
|
||||
if (Command<Commands::BuildRoad>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, (dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X, rt, DRD_NONE, t->index).Failed() &&
|
||||
Command<Commands::LandscapeClear>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Failed()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1105,7 +1105,7 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
|
||||
CommandCost res = CMD_ERROR;
|
||||
if (!_generating_world && Chance16(1, 10)) {
|
||||
/* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */
|
||||
res = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater},
|
||||
res = std::get<0>(Command<Commands::TerraformLand>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater},
|
||||
tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, false));
|
||||
}
|
||||
if (res.Failed() && Chance16(1, 3)) {
|
||||
@@ -1122,9 +1122,9 @@ static bool TerraformTownTile(TileIndex tile, Slope edges, bool dir)
|
||||
{
|
||||
assert(tile < Map::Size());
|
||||
|
||||
CommandCost r = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, edges, dir));
|
||||
CommandCost r = std::get<0>(Command<Commands::TerraformLand>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, edges, dir));
|
||||
if (r.Failed() || r.GetCost() >= (_price[Price::Terraform] + 2) * 8) return false;
|
||||
Command<CMD_TERRAFORM_LAND>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater, DoCommandFlag::Execute}, tile, edges, dir);
|
||||
Command<Commands::TerraformLand>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater, DoCommandFlag::Execute}, tile, edges, dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1251,7 +1251,7 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile, TownExpandModes mode
|
||||
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
|
||||
{
|
||||
RoadType rt = GetTownRoadType();
|
||||
return Command<CMD_BUILD_ROAD>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, rcmd, rt, DRD_NONE, t->index).Succeeded();
|
||||
return Command<Commands::BuildRoad>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile, rcmd, rt, DRD_NONE, t->index).Succeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1296,7 +1296,7 @@ static bool CanRoadContinueIntoNextTile(const Town *t, const TileIndex tile, con
|
||||
if (IsTileType(next_tile, TileType::Railway) && !_settings_game.economy.allow_town_level_crossings) return false;
|
||||
|
||||
/* If a road tile can be built, the construction is allowed. */
|
||||
return Command<CMD_BUILD_ROAD>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, next_tile, rcmd, rt, DRD_NONE, t->index).Succeeded();
|
||||
return Command<Commands::BuildRoad>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, next_tile, rcmd, rt, DRD_NONE, t->index).Succeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1379,8 +1379,8 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
|
||||
|
||||
/* Can we actually build the bridge? */
|
||||
RoadType rt = GetTownRoadType();
|
||||
if (Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()), tile, bridge_tile, TRANSPORT_ROAD, bridge_type, rt).Succeeded()) {
|
||||
Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()).Set(DoCommandFlag::Execute), tile, bridge_tile, TRANSPORT_ROAD, bridge_type, rt);
|
||||
if (Command<Commands::BuildBridge>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildBridge>()), tile, bridge_tile, TRANSPORT_ROAD, bridge_type, rt).Succeeded()) {
|
||||
Command<Commands::BuildBridge>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildBridge>()).Set(DoCommandFlag::Execute), tile, bridge_tile, TRANSPORT_ROAD, bridge_type, rt);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1449,8 +1449,8 @@ static bool GrowTownWithTunnel(const Town *t, const TileIndex tile, const DiagDi
|
||||
|
||||
/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
|
||||
RoadType rt = GetTownRoadType();
|
||||
if (Command<CMD_BUILD_TUNNEL>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_TUNNEL>()), tile, TRANSPORT_ROAD, rt).Succeeded()) {
|
||||
Command<CMD_BUILD_TUNNEL>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_TUNNEL>()).Set(DoCommandFlag::Execute), tile, TRANSPORT_ROAD, rt);
|
||||
if (Command<Commands::BuildTunnel>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildTunnel>()), tile, TRANSPORT_ROAD, rt).Succeeded()) {
|
||||
Command<Commands::BuildTunnel>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildTunnel>()).Set(DoCommandFlag::Execute), tile, TRANSPORT_ROAD, rt);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1934,9 +1934,9 @@ static bool GrowTown(Town *t, TownExpandModes modes)
|
||||
for (const auto &ptr : _town_coord_mod) {
|
||||
/* Only work with plain land that not already has a house */
|
||||
if (!IsTileType(tile, TileType::House) && IsTileFlat(tile)) {
|
||||
if (Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Succeeded()) {
|
||||
if (Command<Commands::LandscapeClear>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Succeeded()) {
|
||||
RoadType rt = GetTownRoadType();
|
||||
Command<CMD_BUILD_ROAD>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto}, tile, GenRandomRoadBits(), rt, DRD_NONE, t->index);
|
||||
Command<Commands::BuildRoad>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto}, tile, GenRandomRoadBits(), rt, DRD_NONE, t->index);
|
||||
cur_company.Restore();
|
||||
return true;
|
||||
}
|
||||
@@ -2385,7 +2385,7 @@ HouseZones GetClimateMaskForLandscape()
|
||||
*/
|
||||
static Town *CreateRandomTown(uint attempts, uint32_t townnameparts, TownSize size, bool city, TownLayout layout)
|
||||
{
|
||||
assert(_game_mode == GM_EDITOR || _generating_world); // These are the preconditions for CMD_DELETE_TOWN
|
||||
assert(_game_mode == GM_EDITOR || _generating_world); // These are the preconditions for Commands::DeleteTown
|
||||
|
||||
if (!Town::CanAllocateItem()) return nullptr;
|
||||
|
||||
@@ -2410,7 +2410,7 @@ static Town *CreateRandomTown(uint attempts, uint32_t townnameparts, TownSize si
|
||||
if (t->cache.population > 0) return t;
|
||||
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN);
|
||||
[[maybe_unused]] CommandCost rc = Command<CMD_DELETE_TOWN>::Do(DoCommandFlag::Execute, t->index);
|
||||
[[maybe_unused]] CommandCost rc = Command<Commands::DeleteTown>::Do(DoCommandFlag::Execute, t->index);
|
||||
cur_company.Restore();
|
||||
assert(rc.Succeeded());
|
||||
|
||||
@@ -2540,7 +2540,7 @@ HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
|
||||
*/
|
||||
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, uint8_t counter, uint8_t stage, HouseID type, uint8_t random_bits, bool is_protected)
|
||||
{
|
||||
[[maybe_unused]] CommandCost cc = Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile);
|
||||
[[maybe_unused]] CommandCost cc = Command<Commands::LandscapeClear>::Do({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile);
|
||||
assert(cc.Succeeded());
|
||||
|
||||
IncreaseBuildingCount(t, type);
|
||||
@@ -2597,7 +2597,7 @@ static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
|
||||
if (IsBridgeAbove(tile)) return false;
|
||||
|
||||
/* can we clear the land? */
|
||||
return Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Succeeded();
|
||||
return Command<Commands::LandscapeClear>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, tile).Succeeded();
|
||||
}
|
||||
|
||||
|
||||
@@ -2979,7 +2979,7 @@ CommandCost CmdPlaceHouse(DoCommandFlags flags, TileIndex tile, HouseID house, b
|
||||
|
||||
/* We might be replacing an existing house, otherwise check if we can clear land. */
|
||||
if (!(replace && GetTileType(subtile) == TileType::House)) {
|
||||
CommandCost cost = Command<CMD_LANDSCAPE_CLEAR>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, subtile);
|
||||
CommandCost cost = Command<Commands::LandscapeClear>::Do({DoCommandFlag::Auto, DoCommandFlag::NoWater}, subtile);
|
||||
if (!cost.Succeeded()) return cost;
|
||||
}
|
||||
}
|
||||
@@ -3036,7 +3036,7 @@ CommandCost CmdPlaceHouseArea(DoCommandFlags flags, TileIndex tile, TileIndex st
|
||||
std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
|
||||
for (; *iter != INVALID_TILE; ++(*iter)) {
|
||||
TileIndex t = *iter;
|
||||
CommandCost ret = Command<CMD_PLACE_HOUSE>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), t, house, is_protected, replace);
|
||||
CommandCost ret = Command<Commands::PlaceHouse>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), t, house, is_protected, replace);
|
||||
|
||||
/* If we've reached the limit, stop building (or testing). */
|
||||
if (c != nullptr && limit-- <= 0) break;
|
||||
@@ -3046,7 +3046,7 @@ CommandCost CmdPlaceHouseArea(DoCommandFlags flags, TileIndex tile, TileIndex st
|
||||
continue;
|
||||
}
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) Command<CMD_PLACE_HOUSE>::Do(flags, t, house, is_protected, replace);
|
||||
if (flags.Test(DoCommandFlag::Execute)) Command<Commands::PlaceHouse>::Do(flags, t, house, is_protected, replace);
|
||||
had_success = true;
|
||||
}
|
||||
|
||||
@@ -3357,7 +3357,7 @@ CommandCost CmdDeleteTown(DoCommandFlags flags, TownID town_id)
|
||||
/* Non-oil rig stations are always a problem. */
|
||||
if (!st->facilities.Test(StationFacility::Airport) || st->airport.type != AT_OILRIG) return CMD_ERROR;
|
||||
/* We can only automatically delete oil rigs *if* there's no vehicle on them. */
|
||||
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, st->airport.tile);
|
||||
CommandCost ret = Command<Commands::LandscapeClear>::Do(flags, st->airport.tile);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
@@ -3378,7 +3378,7 @@ CommandCost CmdDeleteTown(DoCommandFlags flags, TownID town_id)
|
||||
* tile was already deleted earlier in the loop. */
|
||||
for (const auto current_tile : Map::Iterate()) {
|
||||
if (IsTileType(current_tile, TileType::TunnelBridge) && TestTownOwnsBridge(current_tile, t)) {
|
||||
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
|
||||
CommandCost ret = Command<Commands::LandscapeClear>::Do(flags, current_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
@@ -3421,7 +3421,7 @@ CommandCost CmdDeleteTown(DoCommandFlags flags, TownID town_id)
|
||||
break;
|
||||
}
|
||||
if (try_clear) {
|
||||
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
|
||||
CommandCost ret = Command<Commands::LandscapeClear>::Do(flags, current_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
}
|
||||
}
|
||||
@@ -3531,7 +3531,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlags flags)
|
||||
static bool CheckClearTile(TileIndex tile)
|
||||
{
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_NONE);
|
||||
CommandCost r = Command<CMD_LANDSCAPE_CLEAR>::Do({}, tile);
|
||||
CommandCost r = Command<Commands::LandscapeClear>::Do({}, tile);
|
||||
cur_company.Restore();
|
||||
return r.Succeeded();
|
||||
}
|
||||
@@ -3587,7 +3587,7 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlags flags)
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_NONE);
|
||||
Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlag::Execute, best_position);
|
||||
Command<Commands::LandscapeClear>::Do(DoCommandFlag::Execute, best_position);
|
||||
cur_company.Restore();
|
||||
BuildObject(OBJECT_STATUE, best_position, _current_company, t);
|
||||
t->statues.Set(_current_company); // Once found and built, "inform" the Town.
|
||||
@@ -4229,7 +4229,7 @@ static CommandCost TerraformTile_Town(TileIndex tile, DoCommandFlags flags, int
|
||||
}
|
||||
}
|
||||
|
||||
return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
|
||||
return Command<Commands::LandscapeClear>::Do(flags, tile);
|
||||
}
|
||||
|
||||
/** Tile callback functions for a town */
|
||||
|
||||
Reference in New Issue
Block a user