FS#1182 - [PATCH] convert railtype Rail <-> ElRail

Attached to Project: OpenTTD
Opened by Zdeněk Sojka (SmatZ) - Saturday, 01 September 2007, 12:05 GMT
Type Bug
Category Core
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No



In current version, there are some problems with Rail <-> ElRail conversions.
Only depot tile can be converted, but then there may be a train outside the depot.
Then, there are problems when the rail is converted back to elrail (it has to be reversed so the cached_power is updated).

On non-depot rail, the message TrainInTheWay is shown.

Similiar behaviour can be seen in 0.5 branch, but there cached_power is updated without reversing the train.

This patch allows Rail <-> ElRail conversion for all tiles, even when a train is on. Its power is upgraded using faster method, with VehicleFromPos instead of FOR_ALL_VEHICLES.
Also, some parts were unified into CmdConvertRail().

known "problems"
- when downgraded to rail, el.train will slow down slowly when on a bringe/tunnel, because it stays on the same "tile". On normal track, it stops when it should enter new tile
- train doesn't restart, when it enters electrified tile

This can be changed if this patch gets accepted. I don't want to make big patches as smaller will be accepted more likely.
This task depends upon

Closed by  Remko Bijker (Rubidium)
Saturday, 08 September 2007, 09:52 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r11059.
Comment by Zdeněk Sojka (SmatZ) - Tuesday, 04 September 2007, 12:05 GMT
No comments yet :-(

So I attach actual diff and two savegames.

The 9th Jan - from 0.5.2, the same way behaves actual trunk.
The 10th Jan - modified trunk. Train is stopped when rail is converted.

(note: when loaded "9th Jan" in patched version, it will behave the same as in older versions - the status of the train is incorrect)
(actually, the diff does more work - it allows conversion of all rail tiles, not just depots)

Any comment appreciated
Comment by Zdeněk Sojka (SmatZ) - Tuesday, 04 September 2007, 12:06 GMT
One more change for 11039... (causing only warnings)
Comment by Zdeněk Sojka (SmatZ) - Friday, 07 September 2007, 22:31 GMT
Updated to newer svn, fixed one bug:
if tunnel was busy, endtile was returned and INVALID_TILE, and so, INVALID_TILE was used as endtile when converting compatible rail.