News:

Want to praise Simutrans?
Your feedback is important for us ;D.

[idea] Shift railroad track switches by script

Started by Emil Sawicki, December 27, 2023, 09:19:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Emil Sawicki

I have always been finding default railway ,,triangle" switches ugly. Currently I play pak192, which does not contain ,,done" switches (like addons for 128), so they shift when a train approaches. Some of them shift rarely, so ,,triangles" are often visible on screenshots. And I am geek so I want my screenshots perfect.
I got an idea to write script shifting all switches at once to given position by setting portion of track as occupied for just a tick. Then track returns back to unoccupied, so it can be used by actual trains.
Portions of track to set occupied would be given once, manually, by player selecting tiles with proper tool. If player rearranges track layout, one have to update script with new coordinates same way.
There would be two methods to run that squirrel: automatically right after game loaded and at any moment by defined key.
Script would be written by geek for geeks, but first I have to ask if squirrel have tools:
1. to get coords by clicking in game world, and store them;
2. to set track occupied?
Simutrans 123, Windows 10

Yona-TYT

You can trying to create a script tool, these have support for obtaining coordinates dynamically (something that does not work in scenarios), I am not sure about "set track occupied", but if it is not I can try to implement it myself.  ;)

Andarix

#2
Quote from: Emil Sawicki on December 27, 2023, 09:19:56 PM...
Script would be written by geek for geeks, but first I have to ask if squirrel have tools:
1. to get coords by clicking in game world, and store them;
...

simple 2 click tool

function is_valid_pos(pl, pos, start)
{
    print("is_valid_pos() called. " + pl.get_name() + "," + pos + ", " + start)
    return 2
}

/**
 * return error message
 */
function do_work(pl, start, end)
{

    local l = abs(start.x - end.x) + abs(start.y - end.y)

  local output_message = format(translate("Shortest distance from %s to %s -> %d tiles."),coord_to_string(start)  ,coord_to_string(end)  ,l )

    return gui.add_message_at(player_x(1), output_message, world.get_time())
}

Quote...
2. to set track occupied?

currently not possible

EDIT

It should be easier to customize the source files if available. And then simply let a locomotive drive past with its own timetable.

https://simutrans-germany.com/wiki/wiki/en_WayDef#Switches_for_tracks

Leartin

The switches change graphics in two occasions: First, when the train plans the route and reserves the tile; Second when the train actually moves over the tile.
Being reserved/occupied and having changed graphics is not directly related. On the one hand, they don't change after a train left, staying as they are until the next change event. On the other hand, the switch status is not part of a save, while reserved tracks are. So a switch that changed due to reservation is no longer changed after a load, but still reserved (and changes when the train arrives).

Therefore:
A tool should have no need to occupy track. It would change the graphic used by the switch. I think this would be very similar to the "rotate building" - tool, just that instead of rotations, it cycles through switch positions. Not a script though.

If such a tool existed, you could automatically use it with a script. Begs the question if switch status couldn't be (optional) part of a savefile, rather than needing such a workaround.

Yona-TYT

Do you want to change the status of the passage signs?

Are you looking for something like this?
local list = sign_list_x()
foreach(sign in list) {
    sign.set_state("green")
}


Emil Sawicki

Quote from: Yona-TYT on December 27, 2023, 10:16:17 PMI can try to implement it myself.  ;)
What exactly do you mean?

Quote from: Andarix on December 28, 2023, 08:21:04 AMcurrently not possible

It should be easier to customize the source files if available. And then simply let a locomotive drive past with its own timetable.

https://simutrans-germany.com/wiki/wiki/en_WayDef#Switches_for_tracks
Whyn't? Isn't track status ,,reserved"/,,unreserved" simple boolean? Also, actually we do have an in-game general tool to force unreserve track.
Do you mean to draw each switch position? Yes, I could do that, but it'll be very big tool menu, if it contains switches for all track types, especially in pak 192. Maybe I could put those in sub-menu, like signals, or wide-ballast tracks are.

Quote from: Leartin on December 28, 2023, 02:18:30 PMA tool should have no need to occupy track. It would change the graphic used by the switch. I think this would be very similar to the "rotate building" - tool, just that instead of rotations, it cycles through switch positions. Not a script though.

If such a tool existed, you could automatically use it with a script. Begs the question if switch status couldn't be (optional) part of a savefile, rather than needing such a workaround.
Very interesting. Do you have any clue such tool (to shift/rotate switches) could be created?
Simutrans 123, Windows 10

Andarix

To be honest, I don't really understand your request.

Apparently you want to change the switches manually like on a model railway. For this you should then look for a model railway program.

Emil Sawicki

I don't mean switching it for train to pass, but switching all of them at once, just to get rid of those triangles. Just for eyecandy.
Simutrans 123, Windows 10

Leartin

Quote from: Emil Sawicki on December 29, 2023, 10:43:32 AMVery interesting. Do you have any clue such tool (to shift/rotate switches) could be created?
No idea if that works with scripts. But in the game itself, certainly.
I reckon it would be a one-click-tool which checks if the clicked location has a way (or even if it has a 'schiene'), if that way has three ribis (= is a switch), get the desc of the way and check if switch images exist ("has_switch_image()"). If all that is true, it would need to gather the ribis, snowy and switch direction, and use them to call set_images() with the same parameters, except a different switch direction. [if the switch direction is ne, set to sw, else to ne] - hence changing which switch is displayed.

Since it's somewhat niche, I think it would be best to add that behaviour to the existing rotate building tool, as they won't interfere with each other, are somewhat similar, and I doubt any pakset would add a dedicated "change switch graphic"-tool.


prissi

The preservation of switch images is in r11021. The rotate house tool will switch now also the rail switches, if they are switchable in r11025.