[Patch] Train autoconversion v0.2

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

User avatar
jez
Engineer
Engineer
Posts: 122
Joined: 23 Aug 2003 21:24

[Patch] Train autoconversion v0.2

Post by jez » 19 Mar 2008 01:33

Probably the most stress-free train network upgrading you'll ever experience. :)

When you're upgrading your track network using the track conversion tool, to something like monorail or maglev, you'll usually get a 'train in the way' error if you try to upgrade a depot whilst a train is stopped in there. This patch autoconverts all stopped trains, and their wagons, to the first compatible train/wagon of the new track type. This vastly increases the speed of upgrading your train network - simply build up money, send all your trains to the depots, and convert the depots along with the track and all the trains will also be converted!

Any comments/code improvements/suggestions welcome!
Version history:
v0.1 (for SVN trunk r12347):
- Initial release.

v0.2 (for SVN trunk r12421):
- Now you have to hold CTRL when converting rail to autoconvert depots with trains in.
- Extra options added to the autoreplacement code (thanks Bjarni!), now we only upgrade a depot if we can afford to upgrade ALL trains in depot.
- Significant code overhaul, split up CmdConvertRail into 2 functions as we now need to iterate through all selected tiles twice, to check whether we have the money necessary for the conversion first; we must do this manually because we had to cause this command to trigger 'notest' in DoCommand.
- When querying the cost of converting track, if only depots with trains are selected, gives a cost estimation of upgrading each depot (ie. max possible cost).
- When querying to cost of converting track, if any track or empty depots are selected, gives a cost estimation of just upgrading any selected track (ie. min possible cost).
- When actually doing the replacement, always tries to convert any selected track or empty depots first. If that was successful, goes through each found depot with trains in, and tries to convert it; does so if we can afford the conversion.
- The cost animation near the cursor will reflect the cost of upgrding any empty depots and track tiles (INCLUDING the track tiles of the upgraded depots that had trains in them!). Each upgraded depot will have its own cost animation too, indicating the cost of upgrading the trains and wagons in that depot.



Known bugs:
- Group handling probably isn't very good; currently we just get the EngineReplacement for the group ID of the train (ie. engV->group_id), but set it again using the ALL_GROUP group.
- We might need one or two more custom strings for this patch (although I haven't found the need for any more yet...)
- I'm told there may also be problems with NewGRF, as some GRF sets disallow certain cargo types for certain track types. As my patch basically uses the autoreplace code, I'm hoping that as long as autoreplace is maintained to work with NewGRF, so this patch will work.
- Some code cleanup is needed.
- Currently, if we're estimating the cost of autoreplacing trains in a depot, the command will fail if we don't have enough money. The command needs not to fail, but to return the cost estimation of replacement. This patch currently hacks around this by charging 100 million for replacement if the cost estimation fails, but this should be fixed (Bjarni needs to fix this one in the autoreplace code ;-) )
- Doesn't handle very well replacing wagons for NewGRF sets that might not allow certain cargo types on certain track types (what is the best way to handle this? Hmm.)
- Doesn't handle very well replacing train engines that can hold cargo - maybe (maybe not?) we should try to replace them with train engines that handle the same type of cargo.
- Doesn't have a GUI to specify replacements (do we want this? It would seem very complex, perhaps unnecessarily so.)
Attachments
Autoconvert v0.1.patch
Patch v0.1. Intended to be applied to OpenTTD trunk r12347.
(16.15 KiB) Downloaded 208 times
Autoconvert v0.2.patch
Patch v0.2. Intended to be applied to OpenTTD trunk r12421.
(30.81 KiB) Downloaded 471 times
Autoconvert_screenie2.png
An illustration of a train being converted automatically from railway to maglev. In this case, 'orphaned' wagons in the depot are also upgraded.
(56.75 KiB) Downloaded 424 times
Last edited by jez on 27 Mar 2008 14:28, edited 7 times in total.
=== Jez ===

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: [Patch] Train autoconversion

Post by Bilbo » 19 Mar 2008 12:17

First compatible? What about allowing specifying train replacement orders across railtypes (like SH-40 -> Pegasus, Asiastar -> Chimaera) and then using these for replacement instead of "first available"? This would be more clean solution IMHO
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

TheJosh
Engineer
Engineer
Posts: 75
Joined: 17 Apr 2007 12:19
Contact:

Re: [Patch] Train autoconversion

Post by TheJosh » 19 Mar 2008 12:43

Good idea, although your implementation needs many issues ironed out.
Want to make a real difference? Australia HOPE International - Bringing hope to African orphans and widows.

User avatar
jez
Engineer
Engineer
Posts: 122
Joined: 23 Aug 2003 21:24

Re: [Patch] Train autoconversion

Post by jez » 19 Mar 2008 12:44

Bilbo wrote:First compatible? What about allowing specifying train replacement orders across railtypes (like SH-40 -> Pegasus, Asiastar -> Chimaera) and then using these for replacement instead of "first available"? This would be more clean solution IMHO
Yep, but that would need a relatively involved GUI, which could be done I guess but I don't really need it for my games. You could also do the autoconversion with the first available vehicle, then figure out which vehicle had been used as the replacement, then setup autoreplace to replace that vehicle with the one you wanted.
=== Jez ===

User avatar
NukeBuster
Traffic Manager
Traffic Manager
Posts: 222
Joined: 04 Jan 2006 18:16
Location: Alphen aan den Rijn, The Netherlands
Contact:

Re: [Patch] Train autoconversion

Post by NukeBuster » 19 Mar 2008 18:37

Isn't there already a replace vehicle gui? Couldn't that be used for replacements?

Or let the tool convert just the depo, and use the replace gui to replace the vehicles?
NukeBuster

Transport Empire: The Transport Empire Linux effort
Join the Transport Empire IRC channel: [url]irc://irc.oftc.net/transportempire[/url] !

OpenTTD patch(es): Password at join

User avatar
jez
Engineer
Engineer
Posts: 122
Joined: 23 Aug 2003 21:24

Re: [Patch] Train autoconversion

Post by jez » 19 Mar 2008 18:56

There is an autoreplace GUI, but it can currently only replace vehicles with others of the same track type; it can't convert between track types.
=== Jez ===

User avatar
FooBar
Tycoon
Tycoon
Posts: 6559
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: [Patch] Train autoconversion

Post by FooBar » 19 Mar 2008 21:16

jez wrote:There is an autoreplace GUI...
We know :wink: But one could expand upon the current GUI.

Anyways, I like your feature. Personally, I wouldn't mind upgrading all trains, and then running another replace sequence to get the trains I like. Specifying beforehand would be a more sensible solution though.

User avatar
athanasios
Tycoon
Tycoon
Posts: 3138
Joined: 23 Jun 2005 00:09
Contact:

Re: [Patch] Train autoconversion

Post by athanasios » 20 Mar 2008 00:33

Still better this patch than manually replacing. :)
http://members.fortunecity.com/gamesart
"If no one is a fool I am also a fool." -The TTD maniac.


I prefer to be contacted through PMs. Thanks.

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: [Patch] Train autoconversion

Post by Bilbo » 20 Mar 2008 23:35

Current GUI could be used and it would be expanded to allow entering replace orders across track types. When coverting between track typess, these cross-track orders would then be performed. When the vehicle gets into the depot, only orders for same track type would be done.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)


libik
Engineer
Engineer
Posts: 38
Joined: 18 Nov 2006 11:39

Re: [Patch] Train autoconversion

Post by libik » 22 Mar 2008 21:22

amazing :), thx a lot...

I didn't try it, because I dont have night build yet, but I will buy it as soon as possible...

question > I dont really understand this bug with Groups of trains... It means, that it is not able to convert more trains in one depot or it means, that we shouldnt convert more depots together?
Hi all

User avatar
leno4
Traffic Manager
Traffic Manager
Posts: 247
Joined: 10 Mar 2008 02:45
Location: Australia

Re: [Patch] Train autoconversion

Post by leno4 » 22 Mar 2008 21:38

Could someone please post there openttd.exe with the patch already installed?

Thanks

fabca2
Transport Coordinator
Transport Coordinator
Posts: 312
Joined: 14 Apr 2004 15:18
Location: Fr

Re: [Patch] Train autoconversion

Post by fabca2 » 22 Mar 2008 21:49

This is very good !!!

I like the idea very much.

it's very fast, and if you are not happy you can change train by replacing tools (GUI) as you want.

for thoses who say "you must extend GUI to allow replacing across rail type", I would reply :
- it's longer : you have to select each train type (imagine you have 5 differents train types...)
- you will change every train on your network, you cannot work on a part of it (or you had to manage groups etc...)
so, this is not a good idea.

User avatar
jez
Engineer
Engineer
Posts: 122
Joined: 23 Aug 2003 21:24

Re: [Patch] Train autoconversion

Post by jez » 22 Mar 2008 22:21

libik wrote:question > I dont really understand this bug with Groups of trains... It means, that it is not able to convert more trains in one depot or it means, that we shouldnt convert more depots together?
I'm going to investigate this one a bit more. There are groups of trains, and I need to find out more but I think it's possible to group them and treat different groups differently when it comes to autoconversion. We need to handle that properly with this patch.
leno4 wrote:Could someone please post there openttd.exe with the patch already installed?
Thanks
When I have a newer version that's more robust with fewer bugs I will post such an exe. :-)
=== Jez ===

User avatar
leno4
Traffic Manager
Traffic Manager
Posts: 247
Joined: 10 Mar 2008 02:45
Location: Australia

Re: [Patch] Train autoconversion

Post by leno4 » 22 Mar 2008 22:29

jez wrote:
libik wrote:question > I dont really understand this bug with Groups of trains... It means, that it is not able to convert more trains in one depot or it means, that we shouldnt convert more depots together?
I'm going to investigate this one a bit more. There are groups of trains, and I need to find out more but I think it's possible to group them and treat different groups differently when it comes to autoconversion. We need to handle that properly with this patch.
leno4 wrote:Could someone please post there openttd.exe with the patch already installed?
Thanks
When I have a newer version that's more robust with fewer bugs I will post such an exe. :-)
Thanks a lot

User avatar
Bilbo
Tycoon
Tycoon
Posts: 1710
Joined: 06 Jun 2007 21:07
Location: Czech Republic

Re: [Patch] Train autoconversion

Post by Bilbo » 23 Mar 2008 00:06

fabca2 wrote:for thoses who say "you must extend GUI to allow replacing across rail type", I would reply :
- it's longer : you have to select each train type (imagine you have 5 differents train types...)
You specify 5 replacements, then you can proceed in converting entire network. Much easier than deleting 100 trains by hand and then creating 100 new one.
If you use some newGRF's, you may want to specify which replacements you want, instead of relying on some automatic selection (which may or may not be good).
fabca2 wrote: - you will change every train on your network, you cannot work on a part of it (or you had to manage groups etc...)
No. Only trains in depots that are hit by the "convert track" tool gets changed, so you have very precise selection of what parts get converted. Cross-type replace orders would be ignored when train just enters the depot. These would be only for the autoconverter.
If you need something, do it yourself or it will be never done.

My patches: Extra large maps (1048576 high, 1048576 wide) (FS#1059), Vehicle + Town + Industry console commands (FS#1060), few minor patches (FS#2820, FS#1521, FS#2837, FS#2843), AI debugging facility

Other: Very large ships NewGRF, Bilbo's multiplayer patch pack v5 (for OpenTTD 0.7.3)

libik
Engineer
Engineer
Posts: 38
Joined: 18 Nov 2006 11:39

Re: [Patch] Train autoconversion

Post by libik » 23 Mar 2008 17:32

how to install this patch?
Hi all

Yexo
Tycoon
Tycoon
Posts: 3653
Joined: 20 Dec 2007 12:49

Re: [Patch] Train autoconversion

Post by Yexo » 23 Mar 2008 18:33

libik wrote:how to install this patch?
Read http://www.tt-forums.net/viewtopic.php?f=33&t=21678

User avatar
jez
Engineer
Engineer
Posts: 122
Joined: 23 Aug 2003 21:24

Re: [Patch] Train autoconversion

Post by jez » 27 Mar 2008 00:07

I'm releasing my new version of this patch. :-) As you can see from the v0.2 version history, I've made quite a few changes and things are a bit nicer now, especially thanks to Bjarni's hard work in improving the train autoreplace code. Still one or two bugs to contend with, though.

Note that you now need to hold CTRL when you convert track for this autoreplacement to happen; otherwise you still get the old behaviour.

This new version isn't very well tested, so suggestions and bug reports are welcome.

OpenTTD devs, I'd appreciate starting to get some code reviews from you if you feel like it, too. :-)
=== Jez ===

User avatar
brupje
Transport Coordinator
Transport Coordinator
Posts: 288
Joined: 03 Oct 2006 07:17
Location: The hague, Netherlands

Re: [Patch] Train autoconversion v0.2

Post by brupje » 04 Apr 2008 16:14

I get

About to do DepotCost... tileindex: 161454
Illegal instruction (core dumped)

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 5 guests