[Mod] Advanced Trains [advtrains] [2.5.0]

yw05
Member
Posts: 413
Joined: Tue May 07, 2019 12:59
GitHub: y5nw
Location: Germany

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by yw05 » Post

nazalassa wrote:
Thu Jun 13, 2024 09:05
It seems that both signals have their influence points set correctly; here are screenshots of the influence points:

screenshot_20240613_104642.png
screenshot_20240613_104701.png

And the HUD:

screenshot_20240613_104714.png
Interesting. It seems like for demo signals there is a bug that prevents the proceed_as_main field of the supported aspects table from being passed on into the signal aspect. Can you try using a different set of signals (e.g. Ks signals)?

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

yw05 wrote:
Thu Jun 13, 2024 10:54
Interesting. It seems like for demo signals there is a bug that prevents the proceed_as_main field of the supported aspects table from being passed on into the signal aspect. Can you try using a different set of signals (e.g. Ks signals)?
It was, indeed, the demo signal. Problem solved. Thank you for the help!

P.S: what is the difference between a Ks signal and a normal one?
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
Blockhead
Moderator
Posts: 2387
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Blockhead » Post

nazalassa wrote:
Thu Jun 13, 2024 11:35
P.S: what is the difference between a Ks signal and a normal one?
Ks signals have the ability to introduce speed restrictions and shunt routes, which are not features of the freestanding, wallmounted and semaphore signals.

yw05 and I have written about them previously in these posts:
viewtopic.php?p=434003#p434003 (introduces the signals)
viewtopic.php?p=435054#p435054 (corrects me on what the signal colours and flashing means)

The whole Ks set is also documented in the source code at advtrains/advtrains_signals_ks/doc/advtrains_signals_ks.7advtrains.md (web link).
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Wogster
Member
Posts: 25
Joined: Tue Oct 18, 2022 02:33

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Wogster » Post

Okay, I think I have the interlocking sorted out, now I would like to build my own train.

So our domestic trains here in Canada, are typically the LRC cars, and the EMD F40PH-2 as motive power, there were LRC locomotives, but the trains have been in service since the mid 1980's so the engines all were retired a couple of decades ago, they were well known for leaving black trails where ever they went. Looking at existing .png files for locomotives, looks a little complex, anyone know how the images work?

Can one then "borrow" code from another loco, and modify it to work with different images, looks like licence wise it would work. I would likely skip logos and stuff, to keep out of trademark court..... Funny how the LRC cars actually look a lot like the Japanese cars with a different colour scheme, so maybe I can borrow the code, and just mod the images.

yw05
Member
Posts: 413
Joined: Tue May 07, 2019 12:59
GitHub: y5nw
Location: Germany

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by yw05 » Post

Wogster wrote:
Sun Jun 30, 2024 20:08
Looking at existing .png files for locomotives, looks a little complex, anyone know how the images work?
In short: the model for the wagon (which defines its 3D shape) contains information on which part of the image to use for a particular surface ("face") on the model. This is known as UV mapping. Blockhead likely has further knowledge in this field than I do.

Note: In the context of MT modding, this is not always strictly a single image file. Textures (which are what end up being shown on the surface of the wagons) can be created out of texture modifiers, which can adjust the textures or combine them before being displayed. (By the way, the train HUD is actually just a texture string that combines various images together based on different properties of the train.)

Some models additionally have multiple texture slots (or: materials, texture buffers), where the faces are assigned different materials. For such models you need multiple textures for the wagon to be displayed correctly.

Can one then "borrow" code from another loco, and modify it to work with different images, [...]
In terms of having a single model with different textures? Yes. Since the models only define the shape and the UV map for the wagons, you can make the train appear differently by providing different textures. In fact, mods like Dlxtrains already does this to allow users to customize the livery for the wagons, where the wagon is given a different texture when the livery is changed.

Note that in certain cases you need to pay attention to image dimensions, particularly if the mod uses texture modifiers or includes code that changes the textures of the wagon.
Last edited by yw05 on Mon Jul 01, 2024 12:07, edited 1 time in total.

User avatar
Blockhead
Moderator
Posts: 2387
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Blockhead » Post

Wogster wrote:
Sun Jun 30, 2024 20:08
Okay, I think I have the interlocking sorted out, now I would like to build my own train.

Looking at existing .png files for locomotives, looks a little complex, anyone know how the images work?
The images on their own won't make much/any sense until you open the image file in Blender so you can see what faces match up to what pixels. This is, as yw05 notes, called UV mapping. It's the process where x and y coordinates for a 2D texture get mapped into u and v coordinates which are their actual positions on the faces of the 3D geometry. Thankfully if you're just doing an edit of an existing train, the UV map is already in place and you can just reference it from within Blender.
Wogster wrote:
Sun Jun 30, 2024 20:08
Can one then "borrow" code from another loco, and modify it to work with different images, looks like licence wise it would work. I would likely skip logos and stuff, to keep out of trademark court..... Funny how the LRC cars actually look a lot like the Japanese cars with a different colour scheme, so maybe I can borrow the code, and just mod the images.
If you wanted to use the Japanese cars, then you could easily make a copy and edit of that mod from the Basic Trains pack.

First copy out the directory advtrains_train_japan into your mods directory and rename it to a new mod name, like advtrains_train_lrc

You then edit the names of things so it's no longer actually a duplicate: rename all of the texture and model files, rename the mod in mod.conf, and change the code in init.lua to register a wagon with a new original name.

Then you get to editing the actual texture file. It's either guess-and-check or you import the b3d files (advtrains_engine_japan.b3d, advtrains_wagon_japan.b3d, but you already renamed those right?) into Blender and go to the UV Editing tab to see what faces match what pixels.

Edit: Anyone interested should also check out "Post your livery repaints here!".
Last edited by Blockhead on Mon Jul 01, 2024 01:35, edited 1 time in total.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

Wogster
Member
Posts: 25
Joined: Tue Oct 18, 2022 02:33

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Wogster » Post

Blockhead wrote:
Sun Jun 30, 2024 22:35
Wogster wrote:
Sun Jun 30, 2024 20:08
Okay, I think I have the interlocking sorted out, now I would like to build my own train.

Looking at existing .png files for locomotives, looks a little complex, anyone know how the images work?
The images on their own won't make much/any sense until you open the image file in Blender so you can see what faces match up to what pixels. This is, as yw05 notes, called UV mapping. It's the process where x and y coordinates for a 2D texture get mapped into u and v coordinates which are their actual positions on the faces of the 3D geometry. Thankfully if you're just doing an edit of an existing train, the UV map is already in place and you can just reference it from within Blender.
Wogster wrote:
Sun Jun 30, 2024 20:08
Can one then "borrow" code from another loco, and modify it to work with different images, looks like licence wise it would work. I would likely skip logos and stuff, to keep out of trademark court..... Funny how the LRC cars actually look a lot like the Japanese cars with a different colour scheme, so maybe I can borrow the code, and just mod the images.
If you wanted to use the Japanese cars, then you could easily make a copy and edit of that mod from the Basic Trains pack.

First copy out the directory advtrains_train_japan into your mods directory and rename it to a new mod name, like advtrains_train_lrc

You then edit the names of things so it's no longer actually a duplicate: rename all of the texture and model files, rename the mod in mod.conf, and change the code in init.lua to register a wagon with a new original name.

Then you get to editing the actual texture file. It's either guess-and-check or you import the b3d files (advtrains_engine_japan.b3d, advtrains_wagon_japan.b3d, but you already renamed those right?) into Blender and go to the UV Editing tab to see what faces match what pixels.
This looks harder then I thought, so I think I will skip it.

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

yw05 wrote:
Sun Jun 30, 2024 21:42
Some models additionally have multiple texture slots (or: materials, texture buffers), where the faces are assigned different materials.
Due to Blender uncooperativeness, I would be extremely interested in knowing how to add several slots to a model in Blender.
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
Blockhead
Moderator
Posts: 2387
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Blockhead » Post

nazalassa wrote:
Mon Jul 01, 2024 12:40
Due to Blender uncooperativeness, I would be extremely interested in knowing how to add several slots to a model in Blender.
For you, I recommend Nathan Salapat's (Minetest Videos) tutorial series on asset creation with Blender link. As you can see in the playlist link, the 4th episode covers multiple materials.

The idea is applied there to nodes but the Blender workflow is identical; for Advtrains, the only difference is in the fields used in Lua. Instead of mesh and tiles, you use mesh and textures.

The Advtrains example I can give is the linetrack boat; I never actually published the Blend file for that, so I'm attaching it. Sorry the textures aren't included, and I can't attach more than 1 MB of attachments whereas my project files are like 10 MB, but you can re-link the ones from a copy of linetrack (first line how to apply materials in Blender and then you should be able to work that out).
Attachments
BetterFerry.zip
(161.11 KiB) Downloaded 91 times
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Blockhead wrote:
Mon Jul 01, 2024 15:18
nazalassa wrote:
Mon Jul 01, 2024 12:40
Due to Blender uncooperativeness, I would be extremely interested in knowing how to add several slots to a model in Blender.
For you, I recommend Nathan Salapat's (Minetest Videos) tutorial series on asset creation with Blender link. As you can see in the playlist link, the 4th episode covers multiple materials.
Thanks! Hopefully there will be some new trains soon :)
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Blockhead wrote:
Mon Jul 01, 2024 15:18
The idea is applied there to nodes but the Blender workflow is identical; for Advtrains, the only difference is in the fields used in Lua. Instead of mesh and tiles, you use mesh and textures.

The Advtrains example I can give is the linetrack boat; I never actually published the Blend file for that, so I'm attaching it. Sorry the textures aren't included, and I can't attach more than 1 MB of attachments whereas my project files are like 10 MB, but you can re-link the ones from a copy of linetrack (first line how to apply materials in Blender and then you should be able to work that out).
Is there a way to specify an order for the texture slots?
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
Blockhead
Moderator
Posts: 2387
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Blockhead » Post

nazalassa wrote:
Tue Jul 02, 2024 16:58
Is there a way to specify an order for the texture slots?
The order has to match how it came out of Blender. One Blender material slot = one textures slot. I'm not sure if there's a rhyme or reason to how it goes - it may be alphabetical, according to internal IDs from Blender, or any other weird thing that the exporter chooses (or leaves as undefined behaviour). I could try to work it out probably but I've always just edited and reloaded until it's right.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Introducing Red Comet! It lacks an interior and the inside faces of three on four doors look like they are shaded weirdly though. I can not understand why.
screenshot_20240704_163057.png
screenshot_20240704_163057.png (142.97 KiB) Viewed 4870 times
screenshot_20240704_163127.png
screenshot_20240704_163127.png (111.85 KiB) Viewed 4870 times
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
Blockhead
Moderator
Posts: 2387
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Blockhead » Post

nazalassa wrote:
Thu Jul 04, 2024 14:32
Introducing Red Comet!

screenshot_20240704_163057.png
screenshot_20240704_163127.png
Nice, I like the profile, it fits well into Advtrains and looks good while still looking like a kind-of realistic profile. Wagons for Advtrains can end up looking kind of "miniature"
nazalassa wrote:
Thu Jul 04, 2024 14:32
the inside faces of three on four doors look like they are shaded weirdly though. I can not understand why.
I think that they are smooth shaded when the rest of the train is flat shaded - help article. Typically trains look better in flat shading but a lot of MBB's older stuff uses smooth shading. Also, you should learn how to view face normals so you can tell which way a face is.. facing. Blender draws both sides of a face but Minetest will only draw one, the side that in Blender the normal is pointing outward from.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Blockhead wrote:
Thu Jul 04, 2024 15:11
I think that they are smooth shaded when the rest of the train is flat shaded.
[...]
Unfortunately, setting these faces to flat shading did not solve the problem. They are displayed correctly in Blender though.
Blockhead wrote:
Thu Jul 04, 2024 15:11
Blender draws both sides of a face but Minetest will only draw one, the side that in Blender the normal is pointing outward from.
Unless the 'Backface culling' box has been ticked in the material properties.
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Blockhead wrote:
Thu Jul 04, 2024 15:11
nazalassa wrote:
Thu Jul 04, 2024 14:32
the inside faces of three on four doors look like they are shaded weirdly though. I can not understand why.
I think that they are smooth shaded when the rest of the train is flat shaded - help article. Typically trains look better in flat shading but a lot of MBB's older stuff uses smooth shading. Also, you should learn how to view face normals so you can tell which way a face is.. facing. Blender draws both sides of a face but Minetest will only draw one, the side that in Blender the normal is pointing outward from.
It's getting even worse: the roof and some other faces are now also incorrectly shaded. As previously stated, changing the shading in Blender does not change anything, neither in the viewport nor in the game. In Blender all faces are displayed correctly though.

Upd.: I previously used one mesh for both the exterior and the interior. After separating it into two independent meshes, the faces that were displayed weirdly are now displayed correctly. Perhaps the mis-displaying is due to having too much polygons on a mesh? Or maybe because several materials are used on it? Further research is needed.

Upd. 2: That also solved the problem for the doors.
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

Red Comet is now finished!
screenshot_20240722_122605.png
screenshot_20240722_122605.png (94.57 KiB) Viewed 4554 times
It features lights that go on (when going forwards) and off (on reversing), seats, and information displays. These displays are implemented in a separate mod (advtrains_info_displays) so they can be used by any train pack.

In the following screenshot, you can see several different displays, well, displaying:
screenshot_20240718_141404.png
screenshot_20240718_141404.png (144.7 KiB) Viewed 4554 times
Each wagon may, in its definition, define one or more display slots, which are named ("front", "side", "line", ...). This name allows for slot contents to be defined train-wide (the "front" display is set to xyz across the whole train, etc.). Each slot may define a text color, a background color, and a size, and may display still text, scrolling text, or images. Moreover, a display slot may cycle through several things to display, and the duration of each of them can be specified individually.

Which brings some problems:
  • Advtrains only saves some fields from a train's table, and the info display system uses its own fields; thus the displays are not saved across server restarts. The culprit seems to be this table, defined in the function advtrains.avt_save, at line 468 of advtrains/advtrains/init.lua:

    Code: Select all

    local v=advtrains.save_keys(train, {
       -- Various fields
    })
    
    I think that could be solved by defining the table outside of the function, and adding a function that adds a field to the table (advtrains.register_train_field_to_save()?); that would allow external mods to expand train behaviour without needing to save the data themselves.
  • There is no way to add luaatc functions, which may hinder mods that add new functionnalities to advtrains (or not). Thus I would suggest a function that adds entries (functions or tables) to the static environment (in advtrains/advtrains_luaautomation/environment.lua) (that would prevent overwriting previous entries, etc.) (atlatc.register_luaatc_functions(table_to_merge)?).
  • On a completely unrelated subject, there is no way to set train fields such as in/outside text, line and rc, outside a "train" event. Bah, there are workarounds, so anyway.
The two mods are attached to this post:
redcom.tgz
(39.55 KiB) Downloaded 120 times
(contentdb will follow soon, hopefully)


NB: There is a tool named "TEMP" which allows players to modify the display slots of trains, by punching them. It is defined at the bottom of advtrains_info_displays/init.lua. If you use this mod on a server you will probably want to remove it. I will remove it in the next release because I still need it :)
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

yw05
Member
Posts: 413
Joined: Tue May 07, 2019 12:59
GitHub: y5nw
Location: Germany

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by yw05 » Post

nazalassa wrote:
Mon Jul 22, 2024 15:32
Advtrains only saves some fields from a train's table, and the info display system uses its own fields; thus the displays are not saved across server restarts. The culprit seems to be this table, defined in the function advtrains.avt_save, at line 468 of advtrains/advtrains/init.lua:

Code: Select all

local v=advtrains.save_keys(train, {
   -- Various fields
})
I think that could be solved by defining the table outside of the function, and adding a function that adds a field to the table (advtrains.register_train_field_to_save()?); that would allow external mods to expand train behaviour without needing to save the data themselves.
I think that is related with the fact that Advtrains keep some "temporary" data that does not need to be saved across restarts. IMO there are multiple approaches to this:
  • An API to add additional fields to preserve in serialization.
  • Another possibility would be to require fields provided by other mods to be prefixed with e.g. _ and then having advtrains always save such keys. The downside of this approach is that this is more computationally expensive (although I am not sure to what extent).
  • Add a (e.g.) userdata field that is always kept and dedicated for other mods.
There is no way to add luaatc functions, which may hinder mods that add new functionnalities to advtrains (or not).

Thus I would suggest a function that adds entries (functions or tables) to the static environment (in advtrains/advtrains_luaautomation/environment.lua) (that would prevent overwriting previous entries, etc.) (atlatc.register_luaatc_functions(table_to_merge)?).
gpcf added a atlatc.register_function to the departureboards branch for his departure boards. I hope that gets merged into master.

For tables/constants I would suggest registering a table getter that returns the actual value when the LuaATC code is run (or, more lazily, when the value is actually needed as a global). This would allow passing different tables based on e.g. the event type and also avoid certain pitfalls related to copying tables.

(The same approach could be said for function as well, but IMO the registered functions can handle that themselves.)
On a completely unrelated subject, there is no way to set train fields such as in/outside text, line and rc, outside a "train" event. Bah, there are workarounds, so anyway.
I'm quite sure the train display can also be set in the interrupt or schedule events.

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

yw05 wrote:
Mon Jul 22, 2024 16:08
I'm quite sure the train display can also be set in the interrupt or schedule events.
atc_set_text_*() only works when train_id is defined. As far as I can understand, this value is gotten from the event data or, if there is no train id in the event data (as in the case of an interrupt), the train that is on the luaatc rail, if any. So it may work for luaatc rails. However there is no such function for operation panels, where my departure code runs. (I could use interrupt_pos() though, and let the rail do its job, but it may not work if the train has left the rail.)
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

yw05
Member
Posts: 413
Joined: Tue May 07, 2019 12:59
GitHub: y5nw
Location: Germany

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by yw05 » Post

nazalassa wrote:
Tue Jul 23, 2024 13:01
yw05 wrote:
Mon Jul 22, 2024 16:08
I'm quite sure the train display can also be set in the interrupt or schedule events.
atc_set_text_*() only works when train_id is defined. As far as I can understand, this value is gotten from the event data or, if there is no train id in the event data (as in the case of an interrupt), the train that is on the luaatc rail, if any. So it may work for luaatc rails. However there is no such function for operation panels, where my departure code runs. (I could use interrupt_pos() though, and let the rail do its job, but it may not work if the train has left the rail.)
Out of curiosity, what is your use case for setting the outside display from OP panels?

Aside from that, this can be solved by adding a atc_set_text_*(id, text) command to Advtrains, which I don't think is particularly complex.

It might be worth mentioning that Emojigit has a fork of Advtrains that introduces an OOP-based API for trains. IMO that would make more sense here than extending the existing atc_set_text_*(id, text). That said, if we choose to use that, I would personally prefer at least keeping the existing API (1) for compatibility and (2) with the consideration that there are contexts (e.g. ATC tracks) where a train is implicitly defined and a OOP-based API is not necessary.

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

yw05 wrote:
Tue Jul 23, 2024 19:10
Out of curiosity, what is your use case for setting the outside display from OP panels?
I have a terminal station in which trains arrive at the station and stay there until they are asked to leave. There is an operation panel for each line that ends at the station, which fires schedule events on itself; when receiving such an event, it looks in a list of trains currently at the station, which train would be more suitable for the next departure, and sets its info displays accordingly. Then it interrupts itself to make the train leave in 15 seconds or so. I could actually interrupt_pos() the ATC rail to let it do the job so I am setting the inside text from the operation panel only because I'm lazy ;)

[hr]

Having taken a look at the advtrains wiki's "proposals" page (https://advtrains.de/wiki/doku.php?id=d ... argetracks), I have an idea for "long sections", as explained on said page. This is all about implementation, so there are no proposals for any long section shape or whatever. It's just implementation.

In the connection system, which looks like:

Code: Select all

conns = {
   {c = side_1, y = y_1},
   {c = side_2, y = y_2},
   ...
}
an offset can be specified for any connection, like:

Code: Select all

conns = {
   {c = 0, y = 0},
   {c = 9, y = 0, o = {x = 5, z = -2}},
   ...
}
To find out the rail that is connected to such a connection, advtrains may simply add this offset to the rail's position, and then look for rails as usual.

An example: consider the following situation. There is a long section at the red position, a rail at the blue one; the green position is the long section's position, plus the offset defined for the first connection (in this example it is {x = 5, z = -2}). The purple lines represent external rails, and the orange line is the long section (well, sort of).
long-section-diagram.gif
long-section-diagram.gif (4.74 KiB) Viewed 4449 times
To find out the rail connected to the long section's second connection, we add the connection's offset to the long section's position, which gives the green position. Then, we proceed as usual: from the rotation of the rail and the 'c' field of the connection definition, and the green position, we obtain that the next rail is at the blue position (offsetted from the green position by the offset given by the c field, which is 9). We can then apply the usual logic to that rail.

Then there is to solve the problem for the other direction: from the blue position, going towards the long section, we need to find it. Until now there has been nothing at the green position, so using the usual logic for connections we will find out that the tracks stop here, and we will not find the long section. Thus, in order to make as little changes as possible in the current advtrains code, I would suggest that looking at the green position returns something that points to the red position, where the long section is. That may be done with either dummy nodes, or "virtual" ndb entries, or a new table (in the ndb?) which contains these entries. These nodes/entries would then redirect to the long section itself.

An example of how it may go:
We want to follow the connection of the rail at the blue position that goes towards the long section. As such we do as usual: we take the rail's position (blue position) and we add the offset given by the connection's direction. We end up at the green position, and look in the ndb (or at the node placed there, depending on how advtrains does). We find out that it is a "redirect node/entry", which tells us that a rail does end (or start) at the green position, but that it is actually located at the red position. Then we apply the usual logic, but on the rail at the red position. Done!
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
nazalassa
Member
Posts: 49
Joined: Sun May 26, 2024 14:50
In-game: Nazalassa
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by nazalassa » Post

I realized I forgot to add a .zip for Red Comet alongside the .tgz, so here is it. Sorry.
redcom.zip
(46.55 KiB) Downloaded 90 times

-- Upd. --
I noticed the .zip provided triggers errors. I have updated it, removing the faulty code. (it was the part that was supposed to cooperate with advtrains)
Life is like a multitasking OS: you know you'll eventually get back to anything, but you don't know when. s/luanti/minetest/gi

User avatar
apercy
Member
Posts: 671
Joined: Wed Mar 25, 2020 16:31
GitHub: APercy
In-game: APercy
Location: Pinheiral - RJ - Brazil

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by apercy » Post

What's happening here?

Code: Select all

<ACTION> 2024-08-12 01:30:33: [Main] Server: Shutting down
<WARNING> 2024-08-12 01:30:33: [Main] [advtrains]Crash during advtrains main step - skipping the shutdown save operation to not save inconsistent data!
<ACTION> 2024-08-12 01:30:33: [Main] [fishing] Server shuts down. saving trophies table
End log output over terminal (no stdout/stderr backlog during that)
========================
2024-08-12 01:30:34: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'advtrains' in callback environment_Step(): /home/ubuntu/minetest/bin/../builtin/game/item.lua:753: attempt to call upvalue 'get_node_raw' (a nil value)
2024-08-12 01:30:34: ERROR[Main]: stack traceback:
2024-08-12 01:30:34: ERROR[Main]:       /home/ubuntu/minetest/bin/../builtin/game/item.lua:753: in function 'get_node_or_nil'
2024-08-12 01:30:34: ERROR[Main]:       ...untu/minetest/bin/../mods/advtrains/advtrains/nodedb.lua:274: in function 'get_rail_info_at'
2024-08-12 01:30:34: ERROR[Main]:       ...ntu/minetest/bin/../mods/advtrains/advtrains/helpers.lua:320: in function 'get_adjacent_rail'
2024-08-12 01:30:34: ERROR[Main]:       ...ubuntu/minetest/bin/../mods/advtrains/advtrains/path.lua:253: in function 'advtrains_path_get'
2024-08-12 01:30:34: ERROR[Main]:       ...ubuntu/minetest/bin/../mods/advtrains/advtrains/path.lua:338: in function 'path_get_index_by_offset'
2024-08-12 01:30:34: ERROR[Main]:       .../minetest/bin/../mods/advtrains/advtrains/trainlogic.lua:230: in function 'recalc_end_index'
2024-08-12 01:30:34: ERROR[Main]:       .../minetest/bin/../mods/advtrains/advtrains/trainlogic.lua:333: in function 'train_ensure_init'
2024-08-12 01:30:34: ERROR[Main]:       .../minetest/bin/../mods/advtrains/advtrains/trainlogic.lua:102: in function 'mainloop_trainlogic'
2024-08-12 01:30:34: ERROR[Main]:       ...ubuntu/minetest/bin/../mods/advtrains/advtrains/init.lua:616: in function <...ubuntu/minetest/bin/../mods/advtrains/advtrains/init.lua:578>
2024-08-12 01:30:34: ERROR[Main]:       /home/ubuntu/minetest/bin/../builtin/common/register.lua:26: in function </home/ubuntu/minetest/bin/../builtin/common/register.lua:12>
using the last version of contentDb

User avatar
apercy
Member
Posts: 671
Joined: Wed Mar 25, 2020 16:31
GitHub: APercy
In-game: APercy
Location: Pinheiral - RJ - Brazil

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by apercy » Post

apercy wrote:
Mon Aug 12, 2024 01:32
What's happening here?

Code: Select all

...
using the last version of contentDb
nevermind, it was an accidental minetest repo update

User avatar
Athozus
New member
Posts: 5
Joined: Tue Dec 15, 2020 13:26
GitHub: Athozus
IRC: Athozus
In-game: Athozus
Location: Toulouse, France
Contact:

Re: [Mod] Advanced Trains [advtrains] [2.4.3]

by Athozus » Post

@nazalassa Hi, your train looks really good !

Would it be possible for you to publish both `advtrains_info_displays` and Red Comet on ContentDB, so that's easier (I prefer using cdb or git tbh) ?

Thanks anyway, this train reminds me the MP 89 :)
-- Athozus

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests