mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r27246) -Codechange: Deduplicate code between removing part of a rail station and removing the whole rail station. (adf88)
This commit is contained in:
parent
272c386fa8
commit
6bdae2f64a
|
@ -1645,49 +1645,14 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
|
||||||
/* clear all areas of the station */
|
/* clear all areas of the station */
|
||||||
TILE_AREA_LOOP(tile, ta) {
|
TILE_AREA_LOOP(tile, ta) {
|
||||||
/* only remove tiles that are actually train station tiles */
|
/* only remove tiles that are actually train station tiles */
|
||||||
if (!st->TileBelongsToRailStation(tile)) continue;
|
if (st->TileBelongsToRailStation(tile)) {
|
||||||
|
SmallVector<T*, 4> affected_stations; // dummy
|
||||||
CommandCost ret = EnsureNoVehicleOnGround(tile);
|
CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
|
||||||
if (ret.Failed()) return ret;
|
if (ret.Failed()) return ret;
|
||||||
|
cost.AddCost(ret);
|
||||||
cost.AddCost(removal_cost);
|
|
||||||
if (flags & DC_EXEC) {
|
|
||||||
/* read variables before the station tile is removed */
|
|
||||||
Track track = GetRailStationTrack(tile);
|
|
||||||
Owner owner = GetTileOwner(tile); // _current_company can be OWNER_WATER
|
|
||||||
Train *v = NULL;
|
|
||||||
if (HasStationReservation(tile)) {
|
|
||||||
v = GetTrainForReservation(tile, track);
|
|
||||||
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);
|
|
||||||
YapfNotifyTrackLayoutChange(tile, track);
|
|
||||||
if (v != NULL) TryPathReserve(v, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
|
||||||
st->rect.AfterRemoveRect(st, st->train_station);
|
|
||||||
|
|
||||||
st->train_station.Clear();
|
|
||||||
|
|
||||||
st->facilities &= ~FACIL_TRAIN;
|
|
||||||
|
|
||||||
free(st->speclist);
|
|
||||||
st->num_specs = 0;
|
|
||||||
st->speclist = NULL;
|
|
||||||
st->cached_anim_triggers = 0;
|
|
||||||
|
|
||||||
DirtyCompanyInfrastructureWindows(st->owner);
|
|
||||||
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_TRAINS);
|
|
||||||
st->UpdateVirtCoord();
|
|
||||||
DeleteStationIfEmpty(st);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue