changeset 18745:c2cfd98f0c98 draft

(svn r23593) -Fix (r23411): Infrastructure counts for rail were not properly updated when converting rail or building level crossings.
author michi_cc <michi_cc@openttd.org>
date Mon, 19 Dec 2011 14:24:12 +0000
parents 328311cde7a0
children 6f51fce90722
files src/rail_cmd.cpp src/road_cmd.cpp
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -1532,7 +1532,7 @@
 				}
 
 				/* Update the company infrastructure counters. */
-				if (IsRailStationTile(tile) && !IsStationTileBlocked(tile)) {
+				if (!IsRailStationTile(tile) || !IsStationTileBlocked(tile)) {
 					Company *c = Company::Get(GetTileOwner(tile));
 					uint num_pieces = IsLevelCrossingTile(tile) ? LEVELCROSSING_TRACKBIT_FACTOR : 1;
 					if (IsPlainRailTile(tile)) {
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -377,6 +377,11 @@
 					bool reserved = HasCrossingReservation(tile);
 					MakeRailNormal(tile, GetTileOwner(tile), tracks, GetRailType(tile));
 					if (reserved) SetTrackReservation(tile, tracks);
+
+					/* Update rail count for level crossings. The plain track should still be accounted
+					 * for, so only subtract the difference to the level crossing cost. */
+					c = Company::GetIfValid(GetTileOwner(tile));
+					if (c != NULL) c->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR - 1;
 				} else {
 					SetRoadTypes(tile, rts);
 					/* If we ever get HWAY and it is possible without road then we will need to promote ownership and invalidate town index here, too */
@@ -609,6 +614,11 @@
 					if (rt != ROADTYPE_ROAD) c->infrastructure.road[ROADTYPE_ROAD] += 2;
 					DirtyCompanyInfrastructureWindows(_current_company);
 				}
+				/* Update rail count for level crossings. The plain track is already
+				 * counted, so only add the difference to the level crossing cost. */
+				c = Company::GetIfValid(GetTileOwner(tile));
+				if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR - 1;
+
 				/* Always add road to the roadtypes (can't draw without it) */
 				bool reserved = HasBit(GetRailReservationTrackBits(tile), railtrack);
 				MakeRoadCrossing(tile, _current_company, _current_company, GetTileOwner(tile), roaddir, GetRailType(tile), RoadTypeToRoadTypes(rt) | ROADTYPES_ROAD, p2);