mirror of https://github.com/OpenTTD/OpenTTD
(svn r27350) [1.5] -Backport from trunk:
- Fix: Incorrect owner assignment when adding/removing road/tram to/from bridges [FS#6317] (r27313, r27312) - Fix: Mark infrastructure window dirty in more cases (r27311) - Change: Auto-complete partial roads when building level-crossings [FS#6283] (r27309)release/1.5
parent
495f18a890
commit
5e34e09891
|
@ -485,37 +485,38 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
RoadTypes roadtypes = GetRoadTypes(tile);
|
RoadTypes roadtypes = GetRoadTypes(tile);
|
||||||
RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
|
RoadBits road = GetRoadBits(tile, ROADTYPE_ROAD);
|
||||||
RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
|
RoadBits tram = GetRoadBits(tile, ROADTYPE_TRAM);
|
||||||
if ((track == TRACK_X && (road | tram) == ROAD_Y) ||
|
if ((track == TRACK_X && ((road | tram) & ROAD_X) == 0) ||
|
||||||
(track == TRACK_Y && (road | tram) == ROAD_X)) {
|
(track == TRACK_Y && ((road | tram) & ROAD_Y) == 0)) {
|
||||||
switch (roadtypes) {
|
Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
||||||
default: break;
|
Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
||||||
case ROADTYPES_TRAM:
|
/* Disallow breaking end-of-line of someone else
|
||||||
/* Tram crossings must always have road. */
|
* so trams can still reverse on this tile. */
|
||||||
if (flags & DC_EXEC) {
|
if (Company::IsValidID(tram_owner) && HasExactlyOneBit(tram)) {
|
||||||
SetRoadOwner(tile, ROADTYPE_ROAD, _current_company);
|
CommandCost ret = CheckOwnership(tram_owner);
|
||||||
Company *c = Company::GetIfValid(_current_company);
|
if (ret.Failed()) return ret;
|
||||||
if (c != NULL) {
|
|
||||||
/* A full diagonal tile has two road bits. */
|
|
||||||
c->infrastructure.road[ROADTYPE_ROAD] += 2;
|
|
||||||
DirtyCompanyInfrastructureWindows(c->index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
roadtypes |= ROADTYPES_ROAD;
|
|
||||||
cost.AddCost(2 * _price[PR_BUILD_ROAD]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ROADTYPES_ALL:
|
|
||||||
if (road != tram) return CMD_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
/* Crossings must always have a road... */
|
||||||
|
uint num_new_road_pieces = 2 - CountBits(road);
|
||||||
|
if (road == ROAD_NONE) road_owner = _current_company;
|
||||||
|
roadtypes |= ROADTYPES_ROAD;
|
||||||
|
/* ...but tram is not required. */
|
||||||
|
uint num_new_tram_pieces = (tram != ROAD_NONE) ? 2 - CountBits(tram) : 0;
|
||||||
|
|
||||||
road |= tram;
|
cost.AddCost((num_new_road_pieces + num_new_tram_pieces) * _price[PR_BUILD_ROAD]);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
MakeRoadCrossing(tile, GetRoadOwner(tile, ROADTYPE_ROAD), GetRoadOwner(tile, ROADTYPE_TRAM), _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
|
MakeRoadCrossing(tile, road_owner, tram_owner, _current_company, (track == TRACK_X ? AXIS_Y : AXIS_X), railtype, roadtypes, GetTownIndex(tile));
|
||||||
UpdateLevelCrossing(tile, false);
|
UpdateLevelCrossing(tile, false);
|
||||||
Company::Get(_current_company)->infrastructure.rail[railtype] += LEVELCROSSING_TRACKBIT_FACTOR;
|
Company::Get(_current_company)->infrastructure.rail[railtype] += LEVELCROSSING_TRACKBIT_FACTOR;
|
||||||
DirtyCompanyInfrastructureWindows(_current_company);
|
DirtyCompanyInfrastructureWindows(_current_company);
|
||||||
|
if (num_new_road_pieces > 0 && Company::IsValidID(road_owner)) {
|
||||||
|
Company::Get(road_owner)->infrastructure.road[ROADTYPE_ROAD] += num_new_road_pieces;
|
||||||
|
DirtyCompanyInfrastructureWindows(road_owner);
|
||||||
|
}
|
||||||
|
if (num_new_tram_pieces > 0 && Company::IsValidID(tram_owner)) {
|
||||||
|
Company::Get(tram_owner)->infrastructure.road[ROADTYPE_TRAM] += num_new_tram_pieces;
|
||||||
|
DirtyCompanyInfrastructureWindows(tram_owner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,10 +237,10 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
|
||||||
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
|
||||||
|
|
||||||
/* If the owner of the bridge sells all its road, also move the ownership
|
/* If the owner of the bridge sells all its road, also move the ownership
|
||||||
* to the owner of the other roadtype. */
|
* to the owner of the other roadtype, unless the bridge owner is a town. */
|
||||||
RoadType other_rt = (rt == ROADTYPE_ROAD) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
|
RoadType other_rt = (rt == ROADTYPE_ROAD) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
|
||||||
Owner other_owner = GetRoadOwner(tile, other_rt);
|
Owner other_owner = GetRoadOwner(tile, other_rt);
|
||||||
if (other_owner != GetTileOwner(tile)) {
|
if (!IsTileOwner(tile, other_owner) && !IsTileOwner(tile, OWNER_TOWN)) {
|
||||||
SetTileOwner(tile, other_owner);
|
SetTileOwner(tile, other_owner);
|
||||||
SetTileOwner(other_end, other_owner);
|
SetTileOwner(other_end, other_owner);
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,10 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
|
||||||
/* Update rail count for level crossings. The plain track should still be accounted
|
/* Update rail count for level crossings. The plain track should still be accounted
|
||||||
* for, so only subtract the difference to the level crossing cost. */
|
* for, so only subtract the difference to the level crossing cost. */
|
||||||
c = Company::GetIfValid(GetTileOwner(tile));
|
c = Company::GetIfValid(GetTileOwner(tile));
|
||||||
if (c != NULL) c->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR - 1;
|
if (c != NULL) {
|
||||||
|
c->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR - 1;
|
||||||
|
DirtyCompanyInfrastructureWindows(c->index);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SetRoadTypes(tile, rts);
|
SetRoadTypes(tile, rts);
|
||||||
}
|
}
|
||||||
|
@ -638,7 +641,10 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
/* Update rail count for level crossings. The plain track is already
|
/* Update rail count for level crossings. The plain track is already
|
||||||
* counted, so only add the difference to the level crossing cost. */
|
* counted, so only add the difference to the level crossing cost. */
|
||||||
c = Company::GetIfValid(GetTileOwner(tile));
|
c = Company::GetIfValid(GetTileOwner(tile));
|
||||||
if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR - 1;
|
if (c != NULL) {
|
||||||
|
c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR - 1;
|
||||||
|
DirtyCompanyInfrastructureWindows(c->index);
|
||||||
|
}
|
||||||
|
|
||||||
/* Always add road to the roadtypes (can't draw without it) */
|
/* Always add road to the roadtypes (can't draw without it) */
|
||||||
bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
|
bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
|
||||||
|
|
|
@ -1992,6 +1992,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Company::Get(st->owner)->infrastructure.station--;
|
Company::Get(st->owner)->infrastructure.station--;
|
||||||
|
DirtyCompanyInfrastructureWindows(st->owner);
|
||||||
|
|
||||||
if (IsDriveThroughStopTile(tile)) {
|
if (IsDriveThroughStopTile(tile)) {
|
||||||
/* Clears the tile for us */
|
/* Clears the tile for us */
|
||||||
|
|
|
@ -487,7 +487,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
DiagDirection dir = AxisToDiagDir(direction);
|
DiagDirection dir = AxisToDiagDir(direction);
|
||||||
|
|
||||||
Company *c = Company::GetIfValid(owner);
|
Company *c = Company::GetIfValid(company);
|
||||||
switch (transport_type) {
|
switch (transport_type) {
|
||||||
case TRANSPORT_RAIL:
|
case TRANSPORT_RAIL:
|
||||||
/* Add to company infrastructure count if required. */
|
/* Add to company infrastructure count if required. */
|
||||||
|
@ -510,13 +510,11 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
RoadType new_rt;
|
RoadType new_rt;
|
||||||
FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ prev_roadtypes) {
|
FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ prev_roadtypes) {
|
||||||
/* A full diagonal road tile has two road bits. */
|
/* A full diagonal road tile has two road bits. */
|
||||||
Company::Get(owner)->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
c->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Owner owner_road = owner;
|
Owner owner_road = HasBit(prev_roadtypes, ROADTYPE_ROAD) ? GetRoadOwner(tile_start, ROADTYPE_ROAD) : company;
|
||||||
Owner owner_tram = owner;
|
Owner owner_tram = HasBit(prev_roadtypes, ROADTYPE_TRAM) ? GetRoadOwner(tile_start, ROADTYPE_TRAM) : company;
|
||||||
if (HasBit(prev_roadtypes, ROADTYPE_ROAD)) owner_road = GetRoadOwner(tile_start, ROADTYPE_ROAD);
|
|
||||||
if (HasBit(prev_roadtypes, ROADTYPE_TRAM)) owner_tram = GetRoadOwner(tile_start, ROADTYPE_TRAM);
|
|
||||||
MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes);
|
MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes);
|
||||||
MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes);
|
MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes);
|
||||||
break;
|
break;
|
||||||
|
@ -534,7 +532,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
|
|
||||||
/* Mark all tiles dirty */
|
/* Mark all tiles dirty */
|
||||||
MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
|
MarkBridgeDirty(tile_start, tile_end, AxisToDiagDir(direction), z_start);
|
||||||
DirtyCompanyInfrastructureWindows(owner);
|
DirtyCompanyInfrastructureWindows(company);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
|
if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
|
||||||
|
|
Loading…
Reference in New Issue