Import infrastructure sharing patch

Strip trailing whitespace
Remove a leftover line form settings.ini

http://www.tt-forums.net/viewtopic.php?p=1008843#p1008843
This commit is contained in:
patch-import
2015-08-06 22:24:24 +01:00
committed by Jonathan G Rennison
parent 856896c36e
commit ee791055f9
32 changed files with 794 additions and 66 deletions

View File

@@ -32,6 +32,7 @@
#include "core/random_func.hpp"
#include "company_base.h"
#include "newgrf.h"
#include "infrastructure_func.h"
#include "order_backup.h"
#include "zoom_func.h"
@@ -1932,7 +1933,7 @@ CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1,
Train *t = Train::GetIfValid(p1);
if (t == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(t->owner);
CommandCost ret = CheckVehicleControlAllowed(t);
if (ret.Failed()) return ret;
@@ -2802,7 +2803,7 @@ static void TrainEnterStation(Train *v, StationID station)
/* Check if the vehicle is compatible with the specified tile */
static inline bool CheckCompatibleRail(const Train *v, TileIndex tile)
{
return IsTileOwner(tile, v->owner) &&
return IsInfraTileUsageAllowed(VEH_TRAIN, v->owner, tile) &&
(!v->IsFrontEngine() || HasBit(v->compatible_railtypes, GetRailType(tile)));
}
@@ -3963,6 +3964,9 @@ void Train::OnNewDay()
/* running costs */
CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
/* sharing fee */
PayDailyTrackSharingFee(this);
this->profit_this_year -= cost.GetCost();
this->running_ticks = 0;
@@ -3994,3 +3998,49 @@ Trackdir Train::GetVehicleTrackdir() const
return TrackDirectionToTrackdir(FindFirstTrack(this->track), this->direction);
}
/**
* Delete a train while it is visible.
* This happens when a company bankrupts when infrastructure sharing is enabled.
* @param v The train to delete.
*/
void DeleteVisibleTrain(Train *v)
{
FreeTrainTrackReservation(v);
TileIndex crossing = TrainApproachingCrossingTile(v);
/* delete train from back to front */
Train *u;
Train *prev = v->Last();
do {
u = prev;
prev = u->Previous();
if (prev != NULL) prev->SetNext(NULL);
/* 'u' shouldn't be accessed after it has been deleted */
TileIndex tile = u->tile;
TrackBits trackbits = u->track;
delete u;
if (trackbits == TRACK_BIT_WORMHOLE) {
/* Vehicle is inside a wormhole, u->track contains no useful value then. */
trackbits = DiagDirToDiagTrackBits(GetTunnelBridgeDirection(tile));
}
Track track = TrackBitsToTrack(trackbits);
if (HasReservedTracks(tile, trackbits)) UnreserveRailTrack(tile, track);
if (IsLevelCrossingTile(tile)) UpdateLevelCrossing(tile);
/* Update signals */
if (IsTileType(tile, MP_TUNNELBRIDGE) || IsRailDepotTile(tile)) {
AddSideToSignalBuffer(tile, INVALID_DIAGDIR, GetTileOwner(tile));
} else {
AddTrackToSignalBuffer(tile, track, GetTileOwner(tile));
}
} while (prev != NULL);
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
UpdateSignalsInBuffer();
}