|
@@ -1227,26 +1227,27 @@ CommandCost CmdBuildRailStation(TileInde
|
|
|
st->cached_anim_triggers |= statspec->animation.triggers;
|
|
|
}
|
|
|
|
|
|
tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
|
|
|
track = AxisToTrack(axis);
|
|
|
|
|
|
layout_ptr = AllocaM(byte, numtracks * plat_len);
|
|
|
GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
|
|
|
|
|
|
numtracks_orig = numtracks;
|
|
|
|
|
|
Company *c = Company::Get(st->owner);
|
|
|
TileIndex tile_track = tile_org;
|
|
|
do {
|
|
|
TileIndex tile = tile_org;
|
|
|
TileIndex tile = tile_track;
|
|
|
int w = plat_len;
|
|
|
do {
|
|
|
byte layout = *layout_ptr++;
|
|
|
if (IsRailStationTile(tile) && HasStationReservation(tile)) {
|
|
|
/* Check for trains having a reservation for this tile. */
|
|
|
Train *v = GetTrainForReservation(tile, AxisToTrack(GetRailStationAxis(tile)));
|
|
|
if (v != NULL) {
|
|
|
FreeTrainTrackReservation(v);
|
|
|
*affected_vehicles.Append() = v;
|
|
|
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), false);
|
|
|
for (; v->Next() != NULL; v = v->Next()) { }
|
|
|
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), false);
|
|
@@ -1284,38 +1285,63 @@ CommandCost CmdBuildRailStation(TileInde
|
|
|
SetStationGfx(tile, (callback & ~1) + axis);
|
|
|
} else {
|
|
|
ErrorUnknownCallbackResult(statspec->grf_prop.grffile->grfid, CBID_STATION_TILE_LAYOUT, callback);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Trigger station animation -- after building? */
|
|
|
TriggerStationAnimation(st, tile, SAT_BUILT);
|
|
|
}
|
|
|
|
|
|
tile += tile_delta;
|
|
|
} while (--w);
|
|
|
AddTrackToSignalBuffer(tile_org, track, _current_company);
|
|
|
YapfNotifyTrackLayoutChange(tile_org, track);
|
|
|
tile_org += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
|
|
|
AddTrackToSignalBuffer(tile_track, track, _current_company);
|
|
|
YapfNotifyTrackLayoutChange(tile_track, track);
|
|
|
tile_track += tile_delta ^ TileDiffXY(1, 1); // perpendicular to tile_delta
|
|
|
} while (--numtracks);
|
|
|
|
|
|
for (uint i = 0; i < affected_vehicles.Length(); ++i) {
|
|
|
/* Restore reservations of trains. */
|
|
|
Train *v = affected_vehicles[i];
|
|
|
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
|
|
|
TryPathReserve(v, true, true);
|
|
|
for (; v->Next() != NULL; v = v->Next()) { }
|
|
|
if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
|
|
|
}
|
|
|
|
|
|
/* Check whether we need to expand the reservation of trains already on the station. */
|
|
|
TileArea update_reservation_area;
|
|
|
if (axis == AXIS_X) {
|
|
|
update_reservation_area = TileArea(tile_org, 1, numtracks_orig);
|
|
|
} else {
|
|
|
update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
|
|
|
}
|
|
|
|
|
|
TILE_AREA_LOOP(tile, update_reservation_area) {
|
|
|
DiagDirection dir = AxisToDiagDir(axis);
|
|
|
TileIndexDiff tile_offset = TileOffsByDiagDir(dir);
|
|
|
TileIndex platform_begin = tile - tile_offset * (st->GetPlatformLength(tile, ReverseDiagDir(dir)) - 1);
|
|
|
TileIndex platform_end = tile + tile_offset * (st->GetPlatformLength(tile, dir) - 1);
|
|
|
|
|
|
/* If there is at least on reservation on the platform, we reserve the whole platform. */
|
|
|
bool reservation = false;
|
|
|
for (TileIndex t = platform_begin; !reservation && t <= platform_end; t += tile_offset) {
|
|
|
reservation = HasStationReservation(t);
|
|
|
}
|
|
|
|
|
|
if (reservation) {
|
|
|
SetRailStationPlatformReservation(platform_begin, dir, true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
st->MarkTilesDirty(false);
|
|
|
st->UpdateVirtCoord();
|
|
|
UpdateStationAcceptance(st, false);
|
|
|
st->RecomputeIndustriesNear();
|
|
|
InvalidateWindowData(WC_SELECT_STATION, 0, 0);
|
|
|
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
|
|
|
SetWindowWidgetDirty(WC_STATION_VIEW, st->index, WID_SV_TRAINS);
|
|
|
DirtyCompanyInfrastructureWindows(st->owner);
|
|
|
}
|
|
|
|
|
|
return cost;
|
|
|
}
|