summaryrefslogtreecommitdiff
path: root/src/road_cmd.cpp
diff options
context:
space:
mode:
authorgooball <67861995+UnsuspiciousGooball@users.noreply.github.com>2020-12-28 22:54:28 +0100
committerGitHub <noreply@github.com>2020-12-28 22:54:28 +0100
commit0125892f041026d049dd9ce7e6d1a63ed5fd67eb (patch)
tree8d494094fc78b2a75acae550272ac1f3f36d2c69 /src/road_cmd.cpp
parentb30c3f64981bdd0593ec9e028561fa06c9b611b5 (diff)
downloadopenttd-0125892f041026d049dd9ce7e6d1a63ed5fd67eb.tar.xz
Fix #8297: Infrastructure counters for road tunnels, bridges, depots … (#8454)
The previous fix 887e9481ff0e70df6bf93ce15a3899a03f124c50 only worked for roads and failed to consider a multiplier used for the infrastructure totals for tunnels/bridges. Also, depots and bus/truck stops are counted as 2 road pieces on creation but were only counted as 1 road piece on conversion because the function DiagDirToRoadBits() was used, which only ever returns single-piece road segments. Co-authored-by: A. S <admin-git@sotai.tk>
Diffstat (limited to 'src/road_cmd.cpp')
-rw-r--r--src/road_cmd.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index bac6f8e1f..d0104cb99 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -1191,7 +1191,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
dep->build_date = _date;
/* A road depot has two road bits. */
- UpdateCompanyRoadInfrastructure(rt, _current_company, 2);
+ UpdateCompanyRoadInfrastructure(rt, _current_company, ROAD_DEPOT_TRACKBIT_FACTOR);
MakeRoadDepot(tile, _current_company, dep->index, dir, rt);
MarkTileDirtyByTile(tile);
@@ -1217,7 +1217,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
/* A road depot has two road bits. */
RoadType rt = GetRoadTypeRoad(tile);
if (rt == INVALID_ROADTYPE) rt = GetRoadTypeTram(tile);
- c->infrastructure.road[rt] -= 2;
+ c->infrastructure.road[rt] -= ROAD_DEPOT_TRACKBIT_FACTOR;
DirtyCompanyInfrastructureWindows(c->index);
}
@@ -2405,14 +2405,22 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
}
- uint num_pieces = CountBits(GetAnyRoadBits(tile, rtt));;
+ uint num_pieces = CountBits(GetAnyRoadBits(tile, rtt));
+ if (tt == MP_STATION && IsStandardRoadStopTile(tile)) {
+ num_pieces *= ROAD_STOP_TRACKBIT_FACTOR;
+ } else if (tt == MP_ROAD && IsRoadDepot(tile)) {
+ num_pieces *= ROAD_DEPOT_TRACKBIT_FACTOR;
+ }
+
found_convertible_road = true;
cost.AddCost(num_pieces * RoadConvertCost(from_type, to_type));
if (flags & DC_EXEC) { // we can safely convert, too
/* Update the company infrastructure counters. */
- if (!IsRoadStopTile(tile) && owner == _current_company) {
- ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
+ if (owner == _current_company) {
+ Company * c = Company::Get(_current_company);
+ c->infrastructure.road[from_type] -= num_pieces;
+ c->infrastructure.road[to_type] += num_pieces;
}
/* Perform the conversion */
@@ -2460,8 +2468,9 @@ CommandCost CmdConvertRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (flags & DC_EXEC) {
/* Update the company infrastructure counters. */
if (owner == _current_company) {
- ConvertRoadTypeOwner(tile, num_pieces, owner, from_type, to_type);
- ConvertRoadTypeOwner(endtile, num_pieces, owner, from_type, to_type);
+ /* Each piece should be counted TUNNELBRIDGE_TRACKBIT_FACTOR times
+ * for the infrastructure counters (cause of #8297). */
+ ConvertRoadTypeOwner(tile, num_pieces * TUNNELBRIDGE_TRACKBIT_FACTOR, owner, from_type, to_type);
SetTunnelBridgeOwner(tile, endtile, _current_company);
}