summaryrefslogtreecommitdiff
path: root/src/station_cmd.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/station_cmd.cpp
parent6083d6ffb4b10ffd6e23e27183000cdb190d1ac7 (diff)
downloadopenttd-d30fcd4e354325af0d2b1968cd11c9db36a3e617.tar.xz
(svn r23411) -Add: Company infrastructure counts for rail.
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r--src/station_cmd.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index bb4595381..8f040338c 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -50,6 +50,7 @@
#include "newgrf_airporttiles.h"
#include "order_backup.h"
#include "newgrf_house.h"
+#include "company_gui.h"
#include "table/strings.h"
@@ -1218,6 +1219,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
numtracks_orig = numtracks;
+ Company *c = Company::Get(st->owner);
do {
TileIndex tile = tile_org;
int w = plat_len;
@@ -1235,6 +1237,9 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
}
}
+ /* Railtype can change when overbuilding. */
+ if (IsRailStationTile(tile) && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]--;
+
/* Remove animation if overbuilding */
DeleteAnimatedTile(tile);
byte old_specindex = HasStationTileRail(tile) ? GetCustomStationSpecIndex(tile) : 0;
@@ -1246,6 +1251,8 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
SetStationTileRandomBits(tile, GB(Random(), 0, 4));
SetAnimationFrame(tile, 0);
+ if (!IsStationTileBlocked(tile)) c->infrastructure.rail[rt]++;
+
if (statspec != NULL) {
/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
@@ -1287,6 +1294,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
InvalidateWindowData(WC_SELECT_STATION, 0, 0);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_TRAINS);
+ DirtyCompanyInfrastructureWindows(st->owner);
}
return cost;
@@ -1409,10 +1417,12 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
}
bool build_rail = keep_rail && !IsStationTileBlocked(tile);
+ if (!build_rail && !IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[rt]--;
DoClearSquare(tile);
DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
if (build_rail) MakeRailNormal(tile, owner, TrackToTrackBits(track), rt);
+ DirtyCompanyInfrastructureWindows(owner);
st->rect.AfterRemoveTile(st, tile);
AddTrackToSignalBuffer(tile, track, owner);
@@ -1554,6 +1564,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
v = GetTrainForReservation(tile, track);
if (v != NULL) FreeTrainTrackReservation(v);
}
+ if (!IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)]--;
DoClearSquare(tile);
DeleteNewGRFInspectWindow(GSF_STATIONS, tile);
AddTrackToSignalBuffer(tile, track, owner);
@@ -1574,6 +1585,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
st->speclist = NULL;
st->cached_anim_triggers = 0;
+ DirtyCompanyInfrastructureWindows(st->owner);
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, SVW_TRAINS);
st->UpdateVirtCoord();
DeleteStationIfEmpty(st);
@@ -3500,6 +3512,18 @@ static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_o
if (!IsTileOwner(tile, old_owner)) return;
if (new_owner != INVALID_OWNER) {
+ /* Update company infrastructure counts. Only do it here
+ * if the new owner is valid as otherwise the clear
+ * command will do it for us. No need to dirty windows
+ * here, we'll redraw the whole screen anyway.*/
+ Company *old_company = Company::Get(old_owner);
+ Company *new_company = Company::Get(new_owner);
+
+ if ((IsRailWaypoint(tile) || IsRailStation(tile)) && !IsStationTileBlocked(tile)) {
+ old_company->infrastructure.rail[GetRailType(tile)]--;
+ new_company->infrastructure.rail[GetRailType(tile)]++;
+ }
+
/* for buoys, owner of tile is owner of water, st->owner == OWNER_NONE */
SetTileOwner(tile, new_owner);
InvalidateWindowClassesData(WC_STATION_LIST, 0);