* Build a road depot. * @param tile tile where to build the depot * @param flags operation to perform * @param rt road type * @param dir entrance direction * @return the cost of this operation or an error * * @todo When checking for the tile slope, * distinguish between "Flat land required" and "land sloped in wrong direction" */
| 1135 | * distinguish between "Flat land required" and "land sloped in wrong direction" |
| 1136 | */ |
| 1137 | CommandCost CmdBuildRoadDepot(DoCommandFlags flags, TileIndex tile, RoadType rt, DiagDirection dir) |
| 1138 | { |
| 1139 | if (!ValParamRoadType(rt) || !IsValidDiagDirection(dir)) return CMD_ERROR; |
| 1140 | |
| 1141 | CommandCost cost(EXPENSES_CONSTRUCTION); |
| 1142 | |
| 1143 | Slope tileh = GetTileSlope(tile); |
| 1144 | if (tileh != SLOPE_FLAT) { |
| 1145 | if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) { |
| 1146 | return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); |
| 1147 | } |
| 1148 | cost.AddCost(_price[PR_BUILD_FOUNDATION]); |
| 1149 | } |
| 1150 | |
| 1151 | /* Allow the user to rotate the depot instead of having to destroy it and build it again */ |
| 1152 | bool rotate_existing_depot = false; |
| 1153 | if (IsRoadDepotTile(tile) && (HasRoadTypeTram(tile) ? rt == GetRoadTypeTram(tile) : rt == GetRoadTypeRoad(tile))) |
| 1154 | { |
| 1155 | CommandCost ret = CheckTileOwnership(tile); |
| 1156 | if (ret.Failed()) return ret; |
| 1157 | |
| 1158 | if (dir == GetRoadDepotDirection(tile)) return CommandCost(); |
| 1159 | |
| 1160 | ret = EnsureNoVehicleOnGround(tile); |
| 1161 | if (ret.Failed()) return ret; |
| 1162 | |
| 1163 | rotate_existing_depot = true; |
| 1164 | } |
| 1165 | |
| 1166 | if (!rotate_existing_depot) { |
| 1167 | cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile)); |
| 1168 | if (cost.Failed()) return cost; |
| 1169 | |
| 1170 | if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); |
| 1171 | |
| 1172 | if (!Depot::CanAllocateItem()) return CMD_ERROR; |
| 1173 | } |
| 1174 | |
| 1175 | if (flags.Test(DoCommandFlag::Execute)) { |
| 1176 | if (rotate_existing_depot) { |
| 1177 | SetRoadDepotExitDirection(tile, dir); |
| 1178 | } else { |
| 1179 | Depot *dep = new Depot(tile); |
| 1180 | MakeRoadDepot(tile, _current_company, dep->index, dir, rt); |
| 1181 | MakeDefaultName(dep); |
| 1182 | |
| 1183 | /* A road depot has two road bits. */ |
| 1184 | UpdateCompanyRoadInfrastructure(rt, _current_company, ROAD_DEPOT_TRACKBIT_FACTOR); |
| 1185 | } |
| 1186 | |
| 1187 | MarkTileDirtyByTile(tile); |
| 1188 | } |
| 1189 | |
| 1190 | cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]); |
| 1191 | return cost; |
| 1192 | } |
| 1193 | |
| 1194 | static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlags flags) |
nothing calls this directly
no test coverage detected