[Patch] Convert all rail depots and their trains r8 (r26360)

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

Post Reply
MJP
Engineer
Engineer
Posts: 115
Joined: 12 Mar 2011 19:01

[Patch] Convert all rail depots and their trains r8 (r26360)

Post by MJP » 26 Oct 2013 16:42

Hi!

Here is a patch that allows the player to convert a rail depot to another rail type (parts of the code are taken from other files of OpenTTD, especially the autoreplace system). Since it adds a new internal command, it breaks multiplayer compatibility (but if all players applied the patch, it should work).

To fully convert a rail network:
  1. First you send all your trains to depot.
  2. Then you use the classic convert tool (the depot containing trains are not modified).
  3. Here is the new part: you open and upgrade the remaining depots:
    new_button_in_depot_window.png
    new_button_in_depot_window.png (15.29 KiB) Viewed 1904 times
  4. A conversion window appears (see autoreplace? the same). You may choose a specific rail type with the dropdown in the bottom left corner. For each item on the left, you choose a replacement. If there is at least one train still moving in/out of a depot, an error message will appear (in that case, close the window, wait all your trains stop and retry).
    convert_window.png
    convert_window.png (10.04 KiB) Viewed 1683 times
  5. That's all.
Patch:
convert_depot_r8_for_r26360.patch
(43.13 KiB) Downloaded 63 times
[r8]
- fix data transfer in multiplayer (require Packet::Send/Recv_binary() provided with enhanced viewport)

[r7]
- Fix compilation with gcc.
Last edited by MJP on 22 Feb 2014 20:01, edited 7 times in total.

Eddi
Tycoon
Tycoon
Posts: 7368
Joined: 17 Jan 2007 00:14

Re: [Patch] Convert a rail depot and its trains

Post by Eddi » 26 Oct 2013 21:43

and how would repeating the replacement scheme for each of the 500 depots on your 2kx2k map be easier than using the universal railtype?
You might not exactly be interested in Ferion, but if you are, have fun :)

MJP
Engineer
Engineer
Posts: 115
Joined: 12 Mar 2011 19:01

Re: [Patch] Convert a rail depot and its trains

Post by MJP » 26 Oct 2013 22:13

I didn't know about this GRF which seems to be a great solution.
It should be more advertised, maybe integrated to the game and enabled by default.
Anyway, thanks for the tip!

MJP
Engineer
Engineer
Posts: 115
Joined: 12 Mar 2011 19:01

Re: [Patch] Convert all rail depots and their trains r2

Post by MJP » 27 Oct 2013 19:44

I can't add a NewGRF to an already existing savegame so I still need this patch for the time being (and it's fun to do too).
Repeating the process once per depot is clearly unacceptable so I've extended the patch functionality: one ctrl-click, one mapping of replacements and that's all (although the universal rail type is still much easier to use).

The patch r2 is quite functional but I have no clue concerning the 3 known bugs...

Edit: For the bug of the cost, I left a TODO uncoded :( The paid price is certainly right while the estimation is wrong. I need to get some sleep...

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4552
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [Patch] Convert all rail depots and their trains r3

Post by Zuu » 30 Oct 2013 08:59

MJP wrote:upgrade a rail depot to the next rail type
How is this "next" rail type determined? In some rail NewGRFs and/or train NewGRFs there may not be a clear "next" rail. Also if there is a high maintenance cost of some rail type, it may be cases when users want to downgrade even in cases when "next" and "previous" type is possible to determine automatically.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

MJP
Engineer
Engineer
Posts: 115
Joined: 12 Mar 2011 19:01

Re: [Patch] Convert all rail depots and their trains r4

Post by MJP » 31 Oct 2013 00:50

The r3 is indeed an upgrade tool based only on the enum RailType. I took a deeper look at _railtypes and extended the GUI to take into account all 16 possibilities. The next available rail type is now determined according to the sorting_order and a new dropdown let the player change that value. Downgrading is now possible but there are limitations (cargo decrease of wagons). Concerning NewGRF compatibility, I checked very quickly with NuTracks and it seemed OK.

However I don't know how to dynamically rebuild the list of a dropdown, how could I do that? (it's just to remove the selected rail type from the other choices)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4552
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [Patch] Convert all rail depots and their trains r4

Post by Zuu » 31 Oct 2013 08:01

MJP wrote:However I don't know how to dynamically rebuild the list of a dropdown, how could I do that? (it's just to remove the selected rail type from the other choices)
It would be better to mark that option as disabled. That is more transparent for users than hiding the option.

IIRC there is a solution in the GUI framework to always (re-)build the drop down when it is opened. There you can specify these things if you are not able to modify the drop down content without rebuilding.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

MJP
Engineer
Engineer
Posts: 115
Joined: 12 Mar 2011 19:01

Re: [Patch] Convert all rail depots and their trains r4

Post by MJP » 31 Oct 2013 09:59

Zuu wrote:IIRC there is a solution in the GUI framework to always (re-)build the drop down when it is opened. There you can specify these things if you are not able to modify the drop down content without rebuilding.
How embarrassing :oops: I had it working at a time, I thought I was doing it wrong for obviously no good reason and I commented the check. OK, so the dropdown's rebuild function is called from OnClick() and there we can build[+store] a list or provide a previous one (it was my first time using a dropdown in ottd). At least, following your advice, I had to review that part and got it working.

But seeing how it looks, this is not easy to "read". The other dropdown are on the scheme "title that introduces items"+list, that gives "Change type into" and the full rail types list. Looks good to me.

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google Adsense [Bot] and 7 guests