Track Design Patterns

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • From the screenshots this looks like a really nice piece of work. Thank you for creating this mod.


    I am allowed to ask some questions:


    • How do you calculated the track bezier curve outline to place the walls?
    • Would you accept a small commonapi patch so all track types are possible? (I won't change anything when commonapi wouldn't be loaded)
  • How do you calculated the track bezier curve outline to place the walls?

    I didn't try to fit bezier, since the result from the game fit's well circular arc under approx. 60°, I just let all coordinates go with circular arcs. I make my arc generate two edges each time and it can support up to 90° without much errors.

    Would you accept a small commonapi patch so all track types are possible? (I won't change anything when commonapi wouldn't be loaded)

    Having seen you mod last night on Steam, I am also thinking of it. The selection of track file is done directly in updateFn like following:



    Code
    local trackType = ({"standard.lua", "high_speed.lua"})[params.trackType + 1]



    if you want to patch them, how can you patch a single line in the function?


    However I am interested in working with your api, do I need to expose this single line as a function or a callback to make the patching easier? I have yet looked into your api due to limited time.

    This guy is too lazy to create a signature. 8o

  • The easiest way is with commonapi.uiparameter.modifyTrackCatenary, that does a lot of the stuff under the hood so you don't need to pass any objects around.


    I did post an example here:
    Common API - immer noch macOS Nutzer gesucht! -


    Technical you simple pass the params array and an "array" of trackTypes (exact two entries) to it and it will modify your params and your trackTypes.
    (LUA tables are passed pretty much as references, so this works generally quite well on all constructions).


    So you need somewhere an array local to your data function in the con.
    Then you access this array in your params and updateFn. The fastest way would be to add extra function parameters.
    (Note: I did this without any testing, as you already have a params construction function it should technical pretty simple)


    Code
    local function params(trackTypes)
    local result = {
    ...
    }
    if (commonapi ~= nil and commonapi.uiparameter ~= nil) then
    commonapi.uiparameter.modifyTrackCatenary(result, {selectionlist = trackTypes})
    end
    return result
    end
    Code
    local updateFn = function(models, trackTypes)
    return function(params)
    defaultParams(params)
    local trackType = trackTypes[(params.trackType or 0)+ 1] or "standard.lua"
    ...


    Code
    function data()
    local trackTypes = {"standard.lua", "high_speed.lua"}
    return {
    type = "RAIL_DEPOT",
    ...
    params = params(trackTypes)
    updateFn = updateFn( .... , trackTypes)



    But defaultParams could be a bit tricky to cheat, as it needs the trackTypes as well.
    Technical I would only create the ui-params once and not run the params again when doing the defaultParams call.


    Running modifyTrackCatenary with already patched trackTypes will surely fail, so this is not a final patch.

  • You don't have a direct dependency, the line ensures that the code will run only when commonapi is loaded:


    if (commonapi ~= nil and commonapi.uiparameter ~= nil) then


    end


    CommonAPI works without require or hard dependency, so no worry ;)


    -edit-
    Here a working tunnel_entry.con, again, there is no dependency on CommonAPI, if it's loaded, it will be used, otherwise nothing will be changed:

  • You don't have a direct dependency, the line ensures that the code will run only when commonapi is loaded:

    Thank you for giving working code, yes I know it but reading global variables in lua is not free.


    But I think patching mod follows a good logical separation rule and will be useful if someday maybe you want to make some changes to api, at least I don't need to upgrade my mod immediately if it comes, and the player will have choice, if he has installed 100 tracks and he doesn't want to see a heavy menu. I have been asked for many times if the tracks under the flying junction can be other tracks so I think working with your api will be very constructive.


    I will look into this later, very tired by the mod for the moment, need to take a rest.

    This guy is too lazy to create a signature. 8o

  • Not right now (only when u change code). I think he said that he adds the CommonAPI sometime later.


    For the manual change follow the steps bellow:


    Go in the modfolder ( in steam its steamapps/workshop/content/446800/1168068230 ; else its the Foldername u downloaded)


    go to res/construction and open all of the files (for example with Notepad++ )


    search this line: local trackType = ({"standard.lua", "high_speed.lua"})[params.trackType + 1]
    should be arround the 100 - 150


    and change it to


    local trackType = ({"standard.lua", "high_speed.lua", "extra.lua"})[params.trackType + 1]


    for extra u can add the .lua file of ur track u want to add.



    If you do this for all of your Files yous should have the new track as possible option.

    Warum einfach, wenn es auch schwer geht?


  • Thanks a lot! That is, what I asked for. I will give a try. But you told the actual line is {"standard.lua", "high_speed.lua"}, does it mean, that I can choose between both of them at the moment? Because I can´t.
    Thanks!

  • I can't find this Option too. I think it's a missing Value thing.


    function StationBuilder.trackTypeUiParam(config)
    return {
    key = "tom_trackType",
    name = _("Track type"),
    values = { _("Standard"), _("High-speed") },
    yearFrom = 1925,
    yearTo = 0
    }
    end


    Something like this. I made some changes to Stations where this was in. Added the track Types in Config and added Values in Script Folder. Some Stations don't have this Lines and thats where im completly lost. By the way. I don't recommend this changes for saved Games. I had crazy behaviours.

BlueBrixx