News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

"Automated" object placing when building a map

Started by PLinden, January 10, 2025, 05:08:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PLinden

Hi

I'm currently building a map based on a real metropolitan area to simulate and hopefully improve traffic flows. Trying to be as accurate as possible, I take the coordinates of the object (town, station, stop...) from a real world map image with the same dimensions as the in-game map and then place the object manually in game as public player.

Since the map is quite large (3000x2500) and I already manually placed 100 towns, I wonder if there is a smarter way to place objects. Especially manually moving to the right location is very time-consuming.

I was thinking of manually editing the save game and inserting a list of text markers with labels and coordinates from my excel file. However, since the map is so big, I think the xml file would crash my computer.

Then I was thinking of a script that processes a list of entries and places a text marker with a label at the given coordinate.

Given my lack of experience with Simutrans, I'd appreciate any advise on how to do this properly.

Thanks a lot

prissi

#1
There is a script interface in the newest version in some pak sets. Which are you playing?

Switch to public player and then mark a area with the new tool. the second to last in the special toolbar in pak64 and pak128. Mark a reagion. It will generate a script in your simutrans folder under addons/pakset/tool and then a folder with the tool you just wrote. If you open the folder, you will find a file tool.nut
// automated rebuild scrip with size (6,3)

include("hm_toolkit_v3")

function hm_build() {
if(this.player.nr != 1) {
return "Must be run as public player!"
}

hm_ground_tl(0,[0,0,0])
...
hm_ground_tl(0,[0,1,0])
hm_city_tl(0,"01_CITYrmax",[1,1,0],0)
hm_way_tl("Road_040",[5,0,0],[0,0,0],1,0)
hm_way_tl("Road_040",[4,2,0],[0,2,0],1,0)
hm_way_tl("Road_040",[3,2,0],[3,0,0],1,0)
hm_way_tl("Road_040",[0,2,0],[0,0,0],1,0)
hm_house_tl("RES_15_14",[2,1,0],0)
hm_house_tl("RES_15_14",[4,1,0],0)
hm_set_owner_tl(15,[5,0,0])
}
The coordinates are relative to the mouse click when calling the macro and building it.
hm_ground_tl flattens the ground. You will not need this for your scripts
hm_city_tl builds a townhall (and gives the population in the first parameter. Using 0 avoids building any houses automatically; otherwise the town will grow to that population. However, if you have laid down roads first, then the chances are very good that the new streets will be along those predefined roads.
hm_house_tl build a house and obviously must be called after the creation of the townhall or else the house will belong to whatever townhall is next.
hm_way_tl builds a road
hm_set_owner_tl sets this road as unowned (15)

There is one strong limitation right now: The ground needs to be in the right height. So currently, you need to have either the height at each position or have a flat world. However, changing the build skript to take only coordinates in x,y is quite straight fordward. I will change them for the next nightly that these also accepts coord with only two paramter.

PLinden

Thanks for your reply! This seems like a good solution. I would just select the entire map and have it place text markers at the defined coordinates.

I play pak128.german v2.3 beta. Do I have problems finding it or is this not included in this pak set?


prissi

As far as I know, it is not included in the pakset. But you can edit the config/menuconf.tab file in the pakset. In general tools section you need to add

general_tool[42]=,,,F2
general_tool[47]=,,,F3

So that would put the recording at F3 and the script execution at F2. You can choose any other key too.

PLinden

Using your steps, I could use the tool in the pakset and tried a few things.
However, I've run into a problem:
my initial idea was to create text signs with the name of the station, so I'd know what station goes where. However, the tool does not seem to record text signs. Is there a way to modify the script so it also detects these text labels? I'm not good with code, but if you could point me in the right direction, I'm happy to try.

Thanks a lot!

prissi

ONe could record text signs but that defies the purpose of the tool as stations are ment to have unique names when placed automatically. Copying the station's name is not a goo thing.

You can add it to the script later, labels are easy to create:
label_x.create(coord(1,2), player_x(1), "This is a label")
Only that 1 and 2 will be absolute coordinate of the map, not relative to the tool.

PLinden

Thanks so much, the label_x.create command is exactly what I needed, especially with the absolute coordinates! It enabled me to place thousands of labels for all stations according to data from openstreetmap.

Is there a similar function for cities? It would be much faster to directly place cities with a script instead of labels which I then replace manually with a city.

prissi

There is, as written further up in the second post. If the script is run as administrator, you can call "hm_city_tl(population,"01_CITY",[x,y],rotation)" which just calls a function executed as
local tile = square_x(x,y).get_ground_tile()
command_x(tool_add_city).work(player, tile, format("%d,%s,%d", population, desc_name, rotation))
You can also use this function directly in your code. These towns will have random roads, when you give a population number for their growth.

And I hope your posts no longer require moderation. Not sure what went wrong with your accout.

prissi

#8
You can build all the roads yourself. The roads in city follow the cityrules but are random to some degree. But if there is already a grid, then cities usually follow that before building a new road.

edit by Isaac: The person to whom this is a reply was a spammer, so their comment as removed. —ieh