Automatic building in specific tiles

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Automatic building in specific tiles

Post by chester00 »

Hi,

i´ve created a map of germany (8192^2) and i want to recreate the whole german railroad-lines.

I´m using gpx-tracks of the railroad-tracks for calculating the right ingame-tiles, but it´s really annoying to locate them ingame. That´s why i´m searching for a tool or a script that can build rails on the calculated tiles automatically.

My question: Is there any tool/script with this function?
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Automatic building in specific tiles

Post by Zuu »

I don't know of any existing script solution to this. It doesn't mean there are none. For example, I don't follow the threads on external tools for creating heightmaps for OpenTTD. But from your question it looks like you probably have imported a heightmap and might have visited threads on the subject of hightmaps and importing towns.

As you say you calculate tiles from coordinates in your gpx, that hopefully means you have some programming knowledge? If that is the case, or you at least got motivation, you can create a script. From a first glance, a Game Script, using GSCompanyMode, may be able to build railway tracks. You will probably like to use the rail pathfinder library which currently has not been ported from AI-script to GS. A such port is basically s/\bAI/GS/g so it is not very hard to do yourself. But you may run into that some company actions are not allowed to be performed via the GS API. In that case you need to write the script as an AI. Using the game cheats you can later cheat yourself into that AI company if you like to play with the rails as human player.

This said, you will probably get into fiddly problems with connecting rail segments together, doing intersections and when building a segment for some reason fails. Eg. you will have to take a trade of between how complex you like to make the script vs how much time will be needed for manual corrections.

Some useful links:
AI (and GS) documentation on our wiki
AI/GS forum
AI Api
GS API
AI Libraries
GS Libraries


Edit: As for importing the gpx-file, I you would need to transform it into an array assignment in Squirrel 2.0 code and inline that in one of your script source code files.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Automatic building in specific tiles

Post by chester00 »

First of all, thanks for your answer.

Maybe i will try to write a script, but i don´t have much time at the moment. That´s why i´m asking for an available script.

The calculation of the tiles is currently done in an excel file, but for now it doesn´t calculate the whole track, but only a few coordinates. Then i can build the track manually between these given coordinates. I also create the gpx-tracks manually, because that allows me to add waypoint for specific objects like stations, junctions or tunnels. For example the track from Hamburg to Hannover has about 250 calculated tiles, which i have to find and add manually :|

So it would be completely enough, if the script is able to tag these tiles with a railway track or a street or something else.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Automatic building in specific tiles

Post by Zuu »

Tagging tiles with signs from a list of coordinates is a quite simple task for a GS to do.

Export your excel-list like this:

Code: Select all

list = [{x: 10, y: 10}, {x:15, y:10}, ... ];

Code: Select all

local cm = GSCompanyMode(0); // Player company
for (tile in list) {
  GSSign.BuildSign(GSMap.GetTileIndex(tile.x, tile.y), "waypoint");
}

To get a boilerplate GS where you can plug in this code, you could use my Minimal GS. The code should be placed at a location where Player company exist, but is not ran multiple times.

Or if you like to put it unconditionally in the main loop, change the GSSign.BuildSign into SuperLib.Sign.SetSign, and it will take care to not stack multiple signs ontop on the same tile.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Automatic building in specific tiles

Post by chester00 »

That sounds nice.

I just copy your code at the end of the main.nut, but when i load the script, an error occurred.

Code: Select all

1.2 API compatibility in effect.
Error minimal gs\main.nut:227/19:expected ´;´
If i add the semicolon, i´ll get the same error (only 227/20 instead of 227/19)
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Automatic building in specific tiles

Post by Zuu »

You cannot just paste the code at the end of the file. It has to be inside a function. There are callbacks when game is saved/loaded and one called start() when the GS starts. Inside start() the main loop is located as if the GS would return from start() it would not continue to run anymore in that game and as a result OpenTTD make it look like the GS crashed to notify GS authors.

However, it will also not run because I'm a bit rusty in writing Squirrel and made some syntax errors myself. So I have prepared the script for you in the attached zip file. In the bottom of main.nut there is now a function UpdateSigns() which is the only place you need to touch. I did test the attached script and it works. :-)

I didn't rip out all unnecessary code as, if you ever like to expand and do save/load or event processing, the boilerplate parts for that is useful to avoid pitfalls in that.
Attachments
SignsGS.zip
(13.66 KiB) Downloaded 95 times
Fepphamn Transport, 9th Oct 1950.png
Fepphamn Transport, 9th Oct 1950.png (199.23 KiB) Viewed 435 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Automatic building in specific tiles

Post by chester00 »

Thank you, bro. That´s just awesome and exactly what i was looking for. :bow:
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: Automatic building in specific tiles

Post by jimbob »

I'm planning on a similar project for the UK, and have got an AI script to correctly place GIS data as signs on a heightmap.

Have you made any progress in regards to automating road/rail/town/industries etc? If not I will be willing to share the script once I've written it.

Also I would be interested to know what data source you have and where you managed to get a kml of rails from?
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Automatic building in specific tiles

Post by chester00 »

Hey,

in case of your first question my answer is no. I only use the script to place signs and build the rail/road manually.

Second answer: First i´m searching in the web for downloadable kml-files for the tracks. If there isn´t a kml-file for the track i want, i´ll create it by myself in google earth as a normal path.
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: Automatic building in specific tiles

Post by jimbob »

Thanks for the answers. I so far have a game script to place towns and industry and signs. Working on adding roads/rail to it.

Curious as how you have gotten such a large map. Is it a patch? Good luck with your scenario
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
chester00
Engineer
Engineer
Posts: 16
Joined: 21 Jan 2011 11:24

Re: Automatic building in specific tiles

Post by chester00 »

Yes, it´s JGR's Patch Pack.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 10 guests