[v2.1.0] Template based train replacement [OpenTTD 1.9.3]

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
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

[v2.1.0] Template based train replacement [OpenTTD 1.9.3]

Post by ffpp »

OpenTTD TBTR

__Intro__

This patch was created to minimize the amount of micromanagement for keeping your trains in order.

I felt that the existing vehicle Autoreplacement meachnism was lacking for trains in some use cases. For
example when the new vehicles you want to use are longer than the ones already used the trains would become
longer than before, possibly not fitting into the same platforms as before anymore.
Similarly, if new vehicles have a larger cargo capacity than the old ones you might want to use less of them
than before to save money but just replacing existing train cars 1:1 would not allow you to do that.

With this patch you can now predefine templates for your trains and let your trains be fitted to match those
templates upon the next depot visit. The template assignment is based on vehicle groups. It works only for
trains since other vehicle types consist of single vehicles only anyways and the Autoreplacement feature is
fully sufficient there.

A short overview of the feature's usage:
* create template
* assign to a group (of trains)
* when any train from that group enters a depot, it will be changed to match the template

__How to use it__

Open the UI
  • from the train groups gui, under "Manage List" and select "Template Replacement".
  • use the key combination [ctrl] + [e].
Organize your trains in groups.
Each group can have one template assigned and if that is the case, this template will be applied to all trains
in the group.

Create a new template
  • Clone from an existing train by using the Clone button and selecting any train from the game window.
  • Create a new custom template: select an engine from the top-right list make sure that no template is
    selected from the bottom list and click "Add Engine". This will create a new template and select it. While a
    template is selected you can append a new engine with "Add Engine" or remove the last engine from it with
    "Delete Engine".
    Adding a new engine can also be done by double clicking on an engine in the upper right list.
Currently there is no option to set the refit for a template manually. But cloning a template from an existing
train will also store the refit for all parts of that train so that this always remains a fallback option.
This means that you could simply create the first train for each group manually and set it as the template for
the rest.

At this moment no additional checks are done whether this template composition is actually valid, this is your
job. BUT, when a template is later applied to an existing train and it turns out that it is not valid after
all, no changes will occur, so no harm should be done to your existing trains if you create an invalid
template ;)

Use the additional options
All three available options are applied on a per-group basis. This makes sense since 2 groups might want to
use the same template but they might want to use a different set of options.
The options can be triggered simply by clicking on one of the strings in the groups list "use depot", "keep
rem" and "use refit". Highlighted in blue means that the option is ON, in gray it means that it is OFF.

Use Depot
When this is ON the template replacement will reuse vehicles from the depot as needed to create the new
chain. But it will only consider vehicles which are stopped and idle in the depot and which don't belong to
any specific group.

Keep Remainders
When this is ON the parts of a train which are not needed anymore after template replacement will be set
to a stopped and idle state in the depot so that they might be used for later replacements. If it is OFF all
remainders from the train will be sold immediately.

Use Refit
When this is ON each train part will use the same refit settings as the one in the template.
This can be useful when 2 groups share the same template but will use it only to shuffle the vehicles around
while the other will use it also to apply the refit.

Toggle Refit Window
This feature is new in 2.1.0. It allows to specify the cargotype to be changed for a template vehicle or the
whole chain. When the refit window is opened, it will affect the currently selected template.

Selecting a single Template Vehicle
Since 2.1.0 it is possible to select a single vehicle from a template. This can be used to:
  • Change the cargotype for only a single part of a template
  • Add a new engine in the middle of an existing template. The new engine will be added after the currently
    selected vehicle
  • Delete a single vehicle from the template
__Wanted Features__
  • Filter by Railtype
__Known Issues__
  • Template Length displayed as 0.0
    This is not the case for templates that were cloned from a train
Screenshot
Image

Patch available at github:
git@github.com:flitzpiepe/OpenTTD.git

Binaries:
Linux:
openttd_1.9.3_tbtr_2.1.0.tar.xz
(4.45 MiB) Downloaded 305 times
Windows: upcoming
Last edited by ffpp on 08 Oct 2019 16:49, edited 97 times in total.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: [v0.1] Template based train replacement

Post by FooBar »

You sir, made my day. From what I gather from the tin, this is absolutely brilliant! I'll look into the tin later this weekend.
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: [v0.1] Template based train replacement r24031

Post by XeryusTC »

This might win my patch of the year award. It improves auto replacement so much, like how it should be I think. Too bad I don't have a compiler set up so I can't test it :(
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: [v0.1] Template based train replacement r24031

Post by ffpp »

thanks both!

@XeryusTC: what platform are you playing on ?
I did the development on linux but it should be feasable to install some form of visual studio on windows too and upload a binary build. Only Mac-compatible builds I cannot provide.
Also, I would need to find a place where to but those builds. As my PC is not running 24/7 and has no static ip, it's not such a good idea to use it as a web server.
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [v0.1] Template based train replacement r24031

Post by Lord Aro »

ask the nice chaps at #openttdcoop for a nice hg repo ;-)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Supercheese
Tycoon
Tycoon
Posts: 1660
Joined: 16 Dec 2007 22:24
Location: Idaho, USA

Re: [v0.1] Template based train replacement r24031

Post by Supercheese »

Whoah, this looks amazingly useful! If a compiled binary emerges, I will definitely give this a spin. 8)
Eyecandy Road Vehicles | Fake Subways | Supercheese's NewObjects

"Fashions and cultures change, but steam trains shall always be majestic."
-Professor Hershel Layton
User avatar
ColdIce
Transport Coordinator
Transport Coordinator
Posts: 306
Joined: 25 Apr 2006 10:22
Location: Bucharest

Re: [v0.1] Template based train replacement r24031

Post by ColdIce »

failed to compile

here is the build log
http://justpaste.it/t75
The rest is confetti!
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: [v0.1] Template based train replacement r24031

Post by Eddi »

need to run projects/generate.vbs to include the new files from source.list into the vcproject-files

no idea about the strgen warnings, though.
J0anJosep
Traffic Manager
Traffic Manager
Posts: 139
Joined: 06 Aug 2011 15:51
Location: Spain

Re: [v0.1] Template based train replacement r24031

Post by J0anJosep »

Amazing! :bow:
BTW, it also makes easier to control how long trains are. When I wanted to make trains longer after replacing a waggon type for a shorter one (or when making stations longer), I had to do it train by train.

About the problem when an autoreplacement is set. In my opinion, it makes no sense to use the autoreplacement function if a template is defined. So, if you have a group where a template is defined, only apply template (and autorenew if needed), and not autoreplacement. If a vehicle has no template defined, then apply the local/global autoreplacement rules.
Formerly known as Juanjo
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: [v0.1] Template based train replacement r24031

Post by ffpp »

thanks, your suggestion about both replacement functions together sounds definitely reasonable so I included it into the first post.

@Eddi: I'm not sure about those strgen warnings either. I think I got them since porting the patch to r24xxx. I didn't touch the language files other than english.txt.
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: [v0.1] Template based train replacement r24031

Post by Eddi »

i might want to "autoreplace" amongst the templates. i.e. all templates using engine "A" now use enginge "B", i probably wouldn't want to do that on a per-template basis
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: [v0.1] Template based train replacement r24031

Post by ffpp »

I put it in the list.

I'm currently thinking about how to integrate it without putting responsibility on the user to create sane template consists. Because those are very lightweight objects and the usual heavy checks that are done on real train composition are not applicable to them.

The other thing is that along with your idea there should be some kind of safety mechanism so that a player will not accidently mess up half his templates with a single click.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [v0.1] Template based train replacement r24031

Post by Zuu »

Looks promising.

If noone beats me to it, I'll make a windows binary tomorrow given there is no compile errors. If you get to the point that you get a respority set up and builds using the compile farm, I'll gladly add your project to OTTDAU (a program for players on Windows to keep OpenTTD up to date).
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Re: [v0.1] Template based train replacement r24031

Post by XeryusTC »

ffpp wrote:thanks both!

@XeryusTC: what platform are you playing on ?
I did the development on linux but it should be feasable to install some form of visual studio on windows too and upload a binary build. Only Mac-compatible builds I cannot provide.
Also, I would need to find a place where to but those builds. As my PC is not running 24/7 and has no static ip, it's not such a good idea to use it as a web server.
I am on Windows. Setting up a compiler should be trivial but I just haven't done so yet as I have not really done any programming lately.
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [v0.1] Template based train replacement r24031

Post by Zuu »

In order to make project generation work in Windows the following fixes to source.list are required:
sources_fix.patch
(638 Bytes) Downloaded 511 times
Note that you need a space after the '#' in a comment or the generate.vbs script will fail. Also you were missing some .h files of your patch.


When compiling (using Visual Studio 2008), I got these errors (plus the ones related to translations):

Code: Select all

5>..srcsaveloadaaa_template_veh_sl.cpp(92) : error C2015: too many characters in constant
5>..srcsaveloadaaa_template_replacement_sl.cpp(34) : error C2015: too many characters in constant
5>error_gui.cpp
5>..srcaaa_template_gui_main.cpp(168) : error C2229: class 'TemplateReplaceWindow' has an illegal zero-sized array
There are a few warnings too. Attached you find the complete build log.
build_log.txt
(88.34 KiB) Downloaded 487 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: [v0.1.b] Template based train replacement r24031

Post by ffpp »

Thanks Zuu!
I didn't get around to test the build on windows, yet.

I was about to upload a newer version of the patch myself when I saw your post, so I incorporated your fixes to the sources.list.

Regarding the warnings: there are actually a lot of them, and most - hopefully all - just due to unused old code.
I will clean this up next, but probably not before next week so there is some time to throw some more suggestions or complaints my way :)

The next two important things to add would then be to make the default behaviour about auto-selling old vehicles and reusing idle vehicles optional. It's not so much work in principal but I'm still thinking about the nicest way to integrate these things into the gui. Then one will be able to define the replacement behaviour on a per-template basis.
User avatar
ffpp
Engineer
Engineer
Posts: 125
Joined: 29 Jan 2010 12:56

Re: [v0.1.b] Template based train replacement r24031

Post by ffpp »

Funny.
I just found a quite old suggestion thread that was dealing with exactly the same idea as my patch.
The first photoshopped screenshot even looks like very similar to my implementation.
I swear, it didn't steal any ideas ! ^^
Here is the link:
http://www.tt-forums.net/viewtopic.php? ... t=template

Does anyone remember this thread ? At least FooBar has been posting in it ;)
Last edited by ffpp on 22 Mar 2012 18:25, edited 1 time in total.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: [v0.1.b] Template based train replacement r24031

Post by FooBar »

Yes, I remember that thread. That's why you made my day previously :P
Your implementation is even more than I would expect from a patch like this, so well done.

Unfortunately I haven't been able to compile yet. MSVC10 is giving me weird errors on a file that you haven't even modified. I didn't find the time yet to build a clean version of the same revision to see if that works. Will have to try again later to see what's up with that. If the clean build works and the patched doesn't I'll make sure to post the details.
broodje
Director
Director
Posts: 615
Joined: 13 Jul 2003 12:47
Location: Alphen aan den Rijn
Contact:

Re: [v0.1.b] Template based train replacement r24031

Post by broodje »

Yep, of course I remember that threat, I can't wait till your patch is included in the main branch.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: [v0.1.b] Template based train replacement r24031

Post by FooBar »

Tried building again, after trowing out my local source copy and checking out a new one. Clean OpenTTD worked. After applying the 0.1b patch I get this warning:
7>d:ttdopenttdtrunk.hgsrcvehicle.cpp(814): warning C4800: 'OrderDepotActionFlags' : forcing value to bool 'true' or 'false' (performance warning)
And more worryingly these errors:
7>Link:
7> Creating library D:TTDOpenTTDtrunk.hgprojects..objsWin32Debugopenttd.lib and object D:TTDOpenTTDtrunk.hgprojects..objsWin32Debugopenttd.exp
7>vehicle.obj : error LNK2019: unresolved external symbol "struct TemplateReplacement * __fastcall GetTemplateReplacementByGroupID(unsigned short)" (?GetTemplateReplacementByGroupID@@YIPAUTemplateReplacement@@G@Z) referenced in function "void __fastcall VehicleEnteredDepotThisTick(struct Vehicle *)" (?VehicleEnteredDepotThisTick@@YIXPAUVehicle@@@Z)
7>vehicle.obj : error LNK2019: unresolved external symbol "class CommandCost __fastcall CmdTemplateReplaceVehicle(struct Train *,bool,enum DoCommandFlag)" (?CmdTemplateReplaceVehicle@@YI?AVCommandCost@@PAUTrain@@_NW4DoCommandFlag@@@Z) referenced in function "void __fastcall CallVehicleTicks(void)" (?CallVehicleTicks@@YIXXZ)
7>vehicle.obj : error LNK2019: unresolved external symbol "class CommandCost __fastcall TestBuyAllTemplateVehiclesInChain(struct Train *)" (?TestBuyAllTemplateVehiclesInChain@@YI?AVCommandCost@@PAUTrain@@@Z) referenced in function "void __fastcall CallVehicleTicks(void)" (?CallVehicleTicks@@YIXXZ)
7>group_gui.obj : error LNK2019: unresolved external symbol "void __fastcall ShowTemplateReplaceWindow(unsigned short,unsigned int,struct VehicleListIdentifier,class GUIList<struct Vehicle const *,char const *> *,unsigned char,int)" (?ShowTemplateReplaceWindow@@YIXGIUVehicleListIdentifier@@PAV?$GUIList@PBUVehicle@@PBD@@EH@Z) referenced in function "public: virtual void __thiscall VehicleGroupWindow::OnDropdownSelect(int,int)" (?OnDropdownSelect@VehicleGroupWindow@@UAEXHH@Z)
7>group_cmd.obj : error LNK2019: unresolved external symbol "short __fastcall deleteIllegalTemplateReplacements(unsigned short)" (?deleteIllegalTemplateReplacements@@YIFG@Z) referenced in function "class CommandCost __fastcall CmdDeleteGroup(unsigned int,enum DoCommandFlag,unsigned int,unsigned int,char const *)" (?CmdDeleteGroup@@YI?AVCommandCost@@IW4DoCommandFlag@@IIPBD@Z)
7>afterload.obj : error LNK2019: unresolved external symbol "void __fastcall AfterLoadTemplateVehicles(void)" (?AfterLoadTemplateVehicles@@YIXXZ) referenced in function "bool __fastcall AfterLoadGame(void)" (?AfterLoadGame@@YI_NXZ)
7>saveload.obj : error LNK2001: unresolved external symbol "struct ChunkHandler const * const _template_vehicle_chunk_handlers" (?_template_vehicle_chunk_handlers@@3QBUChunkHandler@@B)
7>saveload.obj : error LNK2001: unresolved external symbol "struct ChunkHandler const * const _template_replacement_chunk_handlers" (?_template_replacement_chunk_handlers@@3QBUChunkHandler@@B)
7>saveload.obj : error LNK2001: unresolved external symbol "struct Pool<struct TemplateVehicle,unsigned short,512,65536,1,0,1> _template_pool" (?_template_pool@@3U?$Pool@UTemplateVehicle@@G$0CAA@$0BAAAA@$00$0A@$00@@A)
7>D:TTDOpenTTDtrunk.hgprojects..objsWin32Debugopenttd.exe : fatal error LNK1120: 9 unresolved externals
7>
7>Build FAILED.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 9 guests