mirror of https://github.com/OpenTTD/OpenTTD
Feature: Road depots may have a road and tram type at the same time.
parent
cf955bc24b
commit
408732d25b
|
@ -524,9 +524,20 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
|
|||
return CommandCost(EXPENSES_CONSTRUCTION, RoadClearCost(existing_rt) * 2);
|
||||
}
|
||||
|
||||
default:
|
||||
case ROAD_TILE_DEPOT:
|
||||
return CMD_ERROR;
|
||||
case ROAD_TILE_DEPOT: {
|
||||
if (!HasRoadTypeRoad(tile) || !HasRoadTypeTram(tile)) return CMD_ERROR;
|
||||
if (flags & DC_EXEC) {
|
||||
Company *c = Company::GetIfValid(GetTileOwner(tile));
|
||||
c->infrastructure.road[GetRoadType(tile, rtt)] -= ROAD_DEPOT_TRACKBIT_FACTOR;
|
||||
DirtyCompanyInfrastructureWindows(c->index);
|
||||
SetRoadType(tile, rtt, INVALID_ROADTYPE);
|
||||
Depot::GetByTile(tile)->AfterAddRemove(TileArea(tile), false);
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
|
||||
}
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,7 +723,16 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
|
|||
break;
|
||||
|
||||
case ROAD_TILE_DEPOT:
|
||||
if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
if (DiagDirToRoadBits(GetRoadDepotDirection(tile)) == pieces) {
|
||||
/* Check if we can add a new road/tram type if none present. */
|
||||
if (HasTileRoadType(tile, rtt)) {
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
/* We may add a new road type. */
|
||||
cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
|
||||
break;
|
||||
}
|
||||
|
||||
goto do_clear;
|
||||
|
||||
default: NOT_REACHED();
|
||||
|
@ -886,7 +906,12 @@ do_clear:;
|
|||
switch (GetTileType(tile)) {
|
||||
case MP_ROAD: {
|
||||
RoadTileType rttype = GetRoadTileType(tile);
|
||||
if (existing == ROAD_NONE || rttype == ROAD_TILE_CROSSING) {
|
||||
if (rttype == ROAD_TILE_DEPOT) {
|
||||
SetRoadType(tile, rtt, rt);
|
||||
UpdateCompanyRoadInfrastructure(rt, _current_company, ROAD_DEPOT_TRACKBIT_FACTOR);
|
||||
Depot::GetByTile(tile)->AfterAddRemove(TileArea(tile), true);
|
||||
break;
|
||||
} else if (existing == ROAD_NONE || rttype == ROAD_TILE_CROSSING) {
|
||||
SetRoadType(tile, rtt, rt);
|
||||
SetRoadOwner(tile, rtt, company);
|
||||
if (rtt == RTT_ROAD) SetTownIndex(tile, town_id);
|
||||
|
@ -1227,14 +1252,19 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
|
|||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
|
||||
RoadType rt = GetRoadTypeRoad(tile);
|
||||
RoadType tt = GetRoadTypeTram(tile);
|
||||
if (rt != INVALID_ROADTYPE && tt != INVALID_ROADTYPE) cost.AddCost(_price[PR_CLEAR_DEPOT_ROAD]);
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
Depot *depot = Depot::GetByTile(tile);
|
||||
Company *c = Company::GetIfValid(depot->owner);
|
||||
if (c != nullptr) {
|
||||
/* A road depot has two road bits. */
|
||||
RoadType rt = GetRoadTypeRoad(tile);
|
||||
if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
|
||||
c->infrastructure.road[rt] -= ROAD_DEPOT_TRACKBIT_FACTOR;
|
||||
if (rt != INVALID_ROADTYPE) c->infrastructure.road[rt] -= ROAD_DEPOT_TRACKBIT_FACTOR;
|
||||
if (tt != INVALID_ROADTYPE) c->infrastructure.road[tt] -= ROAD_DEPOT_TRACKBIT_FACTOR;
|
||||
DirtyCompanyInfrastructureWindows(c->index);
|
||||
}
|
||||
|
||||
|
@ -1242,7 +1272,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
|
|||
depot->AfterAddRemove(TileArea(tile), false);
|
||||
}
|
||||
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);
|
||||
return cost;
|
||||
}
|
||||
|
||||
static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
|
||||
|
|
Loading…
Reference in New Issue