MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ClearTile_Road

Function ClearTile_Road

src/road_cmd.cpp:1221–1270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219}
1220
1221static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
1222{
1223 switch (GetRoadTileType(tile)) {
1224 case RoadTileType::Normal: {
1225 RoadBits b = GetAllRoadBits(tile);
1226
1227 /* Clear the road if only one piece is on the tile OR we are not using the DoCommandFlag::Auto flag */
1228 if ((HasExactlyOneBit(b) && GetRoadBits(tile, RTT_TRAM) == ROAD_NONE) || !flags.Test(DoCommandFlag::Auto)) {
1229 CommandCost ret(EXPENSES_CONSTRUCTION);
1230 for (RoadTramType rtt : _roadtramtypes) {
1231 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1232
1233 CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true);
1234 if (tmp_ret.Failed()) return tmp_ret;
1235 ret.AddCost(tmp_ret.GetCost());
1236 }
1237 return ret;
1238 }
1239 return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1240 }
1241
1242 case RoadTileType::Crossing: {
1243 CommandCost ret(EXPENSES_CONSTRUCTION);
1244
1245 if (flags.Test(DoCommandFlag::Auto)) return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
1246
1247 /* Must iterate over the roadtypes in a reverse manner because
1248 * tram tracks must be removed before the road bits. */
1249 for (RoadTramType rtt : { RTT_TRAM, RTT_ROAD }) {
1250 if (!MayHaveRoad(tile) || GetRoadType(tile, rtt) == INVALID_ROADTYPE) continue;
1251
1252 CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, true);
1253 if (tmp_ret.Failed()) return tmp_ret;
1254 ret.AddCost(tmp_ret.GetCost());
1255 }
1256
1257 if (flags.Test(DoCommandFlag::Execute)) {
1258 Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
1259 }
1260 return ret;
1261 }
1262
1263 default:
1264 case RoadTileType::Depot:
1265 if (flags.Test(DoCommandFlag::Auto)) {
1266 return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
1267 }
1268 return RemoveRoadDepot(tile, flags);
1269 }
1270}
1271
1272
1273struct DrawRoadTileStruct {

Callers

nothing calls this directly

Calls 14

GetRoadTileTypeFunction · 0.85
GetAllRoadBitsFunction · 0.85
HasExactlyOneBitFunction · 0.85
GetRoadBitsFunction · 0.85
MayHaveRoadFunction · 0.85
GetRoadTypeFunction · 0.85
RemoveRoadFunction · 0.85
CommandCostClass · 0.85
GetCrossingRoadBitsFunction · 0.85
RemoveRoadDepotFunction · 0.85
TestMethod · 0.80
FailedMethod · 0.80

Tested by

no test coverage detected