summaryrefslogtreecommitdiff
path: root/src/saveload/company_sl.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-12-03 23:40:13 +0000
committermichi_cc <michi_cc@openttd.org>2011-12-03 23:40:13 +0000
commitd30fcd4e354325af0d2b1968cd11c9db36a3e617 (patch)
treeb69954355d81dd316ec4fcbeddcd117fecb1edee /src/saveload/company_sl.cpp
parent6083d6ffb4b10ffd6e23e27183000cdb190d1ac7 (diff)
downloadopenttd-d30fcd4e354325af0d2b1968cd11c9db36a3e617.tar.xz
(svn r23411) -Add: Company infrastructure counts for rail.
Diffstat (limited to 'src/saveload/company_sl.cpp')
-rw-r--r--src/saveload/company_sl.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
index 894611d6e..358600948 100644
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -13,6 +13,11 @@
#include "../company_func.h"
#include "../company_manager_face.h"
#include "../fios.h"
+#include "../rail_map.h"
+#include "../road_map.h"
+#include "../station_map.h"
+#include "../tunnelbridge_map.h"
+#include "../tunnelbridge.h"
#include "saveload.h"
@@ -86,6 +91,78 @@ CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
return cmf;
}
+/** Rebuilding of company statistics after loading a savegame. */
+void AfterLoadCompanyStats()
+{
+ /* Reset infrastructure statistics to zero. */
+ Company *c;
+ FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
+
+ for (TileIndex tile = 0; tile < MapSize(); tile++) {
+ switch (GetTileType(tile)) {
+ case MP_RAILWAY:
+ c = Company::GetIfValid(GetTileOwner(tile));
+ if (c != NULL) {
+ uint pieces = 1;
+ if (IsPlainRail(tile)) {
+ TrackBits bits = GetTrackBits(tile);
+ pieces = CountBits(bits);
+ if (TracksOverlap(bits)) pieces *= pieces;
+ }
+ c->infrastructure.rail[GetRailType(tile)] += pieces;
+
+ if (HasSignals(tile)) c->infrastructure.signal += CountBits(GetPresentSignals(tile));
+ }
+ break;
+
+ case MP_ROAD:
+ if (IsLevelCrossing(tile)) {
+ c = Company::GetIfValid(GetTileOwner(tile));
+ if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
+ }
+ break;
+
+ case MP_STATION:
+ c = Company::GetIfValid(GetTileOwner(tile));
+
+ switch (GetStationType(tile)) {
+ case STATION_RAIL:
+ case STATION_WAYPOINT:
+ if (c != NULL && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case MP_TUNNELBRIDGE: {
+ /* Only count the tunnel/bridge if we're on the northern end tile. */
+ TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
+ if (tile < other_end) {
+ /* Count each tunnel/bridge TUNNELBRIDGE_TRACKBIT_FACTOR times to simulate
+ * the higher structural maintenance needs, and don't forget the end tiles. */
+ uint len = (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
+
+ switch (GetTunnelBridgeTransportType(tile)) {
+ case TRANSPORT_RAIL:
+ c = Company::GetIfValid(GetTileOwner(tile));
+ if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += len;
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+}
+
/* Save/load of companies */