changeset 18569:42709d5de004 draft

(svn r23414) -Add: Company infrastructure counts for stations/airports.
author michi_cc <michi_cc@openttd.org>
date Sat, 03 Dec 2011 23:40:30 +0000
parents d2563220728e
children bbdb2c13eb92
files src/saveload/company_sl.cpp src/station_cmd.cpp src/waypoint_cmd.cpp
diffstat 3 files changed, 35 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -18,6 +18,7 @@
 #include "../station_map.h"
 #include "../tunnelbridge_map.h"
 #include "../tunnelbridge.h"
+#include "../station_base.h"
 
 #include "saveload.h"
 
@@ -98,6 +99,14 @@
 	Company *c;
 	FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
 
+	/* Collect airport count. */
+	Station *st;
+	FOR_ALL_STATIONS(st) {
+		if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
+			Company::Get(st->owner)->infrastructure.airport++;
+		}
+	}
+
 	for (TileIndex tile = 0; tile < MapSize(); tile++) {
 		switch (GetTileType(tile)) {
 			case MP_RAILWAY:
@@ -133,6 +142,7 @@
 
 			case MP_STATION:
 				c = Company::GetIfValid(GetTileOwner(tile));
+				if (c != NULL && GetStationType(tile) != STATION_AIRPORT) c->infrastructure.station++;
 
 				switch (GetStationType(tile)) {
 					case STATION_RAIL:
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1238,7 +1238,10 @@
 				}
 
 				/* Railtype can change when overbuilding. */
-				if (IsRailStationTile(tile) && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]--;
+				if (IsRailStationTile(tile)) {
+					if (!IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]--;
+					c->infrastructure.station--;
+				}
 
 				/* Remove animation if overbuilding */
 				DeleteAnimatedTile(tile);
@@ -1252,6 +1255,7 @@
 				SetAnimationFrame(tile, 0);
 
 				if (!IsStationTileBlocked(tile)) c->infrastructure.rail[rt]++;
+				c->infrastructure.station++;
 
 				if (statspec != NULL) {
 					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
@@ -1422,6 +1426,7 @@
 			DoClearSquare(tile);
 			DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
 			if (build_rail) MakeRailNormal(tile, owner, TrackToTrackBits(track), rt);
+			Company::Get(owner)->infrastructure.station--;
 			DirtyCompanyInfrastructureWindows(owner);
 
 			st->rect.AfterRemoveTile(st, tile);
@@ -1565,6 +1570,7 @@
 				if (v != NULL) FreeTrainTrackReservation(v);
 			}
 			if (!IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)]--;
+			Company::Get(owner)->infrastructure.station--;
 			DoClearSquare(tile);
 			DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
 			AddTrackToSignalBuffer(tile, track, owner);
@@ -1807,9 +1813,10 @@
 			} else {
 				/* Non-drive-through stop never overbuild and always count as two road bits. */
 				Company::Get(st->owner)->infrastructure.road[FIND_FIRST_BIT(rts)] += 2;
-				DirtyCompanyInfrastructureWindows(st->owner);
 				MakeRoadStop(cur_tile, st->owner, st->index, rs_type, rts, ddir);
 			}
+			Company::Get(st->owner)->infrastructure.station++;
+			DirtyCompanyInfrastructureWindows(st->owner);
 
 			MarkTileDirtyByTile(cur_tile);
 		}
@@ -1906,6 +1913,7 @@
 				DirtyCompanyInfrastructureWindows(c->index);
 			}
 		}
+		Company::Get(st->owner)->infrastructure.station--;
 
 		if (IsDriveThroughStopTile(tile)) {
 			/* Clears the tile for us */
@@ -2258,6 +2266,9 @@
 
 		UpdateAirplanesOnNewStation(st);
 
+		Company::Get(st->owner)->infrastructure.airport++;
+		DirtyCompanyInfrastructureWindows(st->owner);
+
 		st->UpdateVirtCoord();
 		UpdateStationAcceptance(st, false);
 		st->RecomputeIndustriesNear();
@@ -2342,6 +2353,9 @@
 			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 		}
 
+		Company::Get(st->owner)->infrastructure.airport--;
+		DirtyCompanyInfrastructureWindows(st->owner);
+
 		st->UpdateVirtCoord();
 		st->RecomputeIndustriesNear();
 		DeleteStationIfEmpty(st);
@@ -2486,8 +2500,9 @@
 		 * This is needed as we've unconditionally cleared that tile before. */
 		if (wc == WATER_CLASS_CANAL) {
 			Company::Get(st->owner)->infrastructure.water++;
-			DirtyCompanyInfrastructureWindows(st->owner);
 		}
+		Company::Get(st->owner)->infrastructure.station += 2;
+		DirtyCompanyInfrastructureWindows(st->owner);
 
 		MakeDock(tile, st->owner, st->index, direction, wc);
 
@@ -2532,6 +2547,9 @@
 		st->dock_tile = INVALID_TILE;
 		st->facilities &= ~FACIL_DOCK;
 
+		Company::Get(st->owner)->infrastructure.station -= 2;
+		DirtyCompanyInfrastructureWindows(st->owner);
+
 		SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_SHIPS);
 		st->UpdateVirtCoord();
 		st->RecomputeIndustriesNear();
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -28,6 +28,7 @@
 #include "newgrf_station.h"
 #include "company_base.h"
 #include "water.h"
+#include "company_gui.h"
 
 #include "table/strings.h"
 
@@ -252,9 +253,11 @@
 		}
 		byte map_spec_index = AllocateSpecToStation(spec, wp, true);
 
+		Company *c = Company::Get(wp->owner);
 		for (int i = 0; i < count; i++) {
 			TileIndex tile = start_tile + i * offset;
 			byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
+			if (!HasStationTileRail(tile)) c->infrastructure.station++;
 			bool reserved = IsTileType(tile, MP_RAILWAY) ?
 					HasBit(GetRailReservationTrackBits(tile), AxisToTrack(axis)) :
 					HasStationReservation(tile);
@@ -266,6 +269,7 @@
 			DeallocateSpecFromStation(wp, old_specindex);
 			YapfNotifyTrackLayoutChange(tile, AxisToTrack(axis));
 		}
+		DirtyCompanyInfrastructureWindows(wp->owner);
 	}
 
 	return CommandCost(EXPENSES_CONSTRUCTION, count * _price[PR_BUILD_WAYPOINT_RAIL]);