[GS] Released Scenario Builder

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

[GS] Released Scenario Builder

Post by jimbob »

Please find following my scenario builder GS, I have used for my UK scenario. Feel free to modify it for your own purposes. I'd recommend building the lists in your favourite spreadsheet program (attached is my very messy excel file I used to build my lists), also note your heightmap will have to be build using a Cartesian Northing, Easting coordinate system or you will have to make a far more complex convertor to OTTD grids.

My scenario used data and a heightmap in OSGB which are effectively X and Y coordinates which only need to be scaled and offset to become grid coordinates. Easiest way to do this is sample two costal points in both the scenario editor and your mapping software. I used free open source QGIS (http://qgis.org/en/site/) for my mapping software and OS open data (https://www.ordnancesurvey.co.uk/busine ... ducts.html the same data which was used to build the UK minecraft map)

The GS is currently able to:
  • Place towns with set location, size and city status, accounting for barriers, hills, and coast
  • industry with one of three methods: at Determined located (with nearest valid search), within determined area (rectangles), or random (prospecting)
  • rectangles of trees
  • signs
I used the following process:
1. Load heightmap in scenario editor
2. add temporary town away from anything which will be added so that the scenario will be "playable"
3. set the GS in the AI settings
4. save it and play the scenario
5. watch while the GS places towns, industry, signs and trees (note trees will take a while on big maps, ~10mins to place 10,000 rectangles for my UK map)
6. save the game, go to your saves folder, move the *.sav file to scenarios and rename it to *.scn
7. load it back into the editor, delete the temporary town, and make other manual adjustments
8. save it and done!

Please post any suggestions, improvements you've made, question, comments, or complaints about my poorly styled code.
Attachments
main.nut
Scenario Generator script
(589.4 KiB) Downloaded 320 times
OTTDConversion.xlsx
List Generators
(10.75 MiB) Downloaded 363 times
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Hi

Nice work there... was looking to try and build the uk using your bits but cannot find where to put the script using ottd 1.5.3 on window s 10. I was going to try and use it with full ecs, uk renewal, pipes, fish and a few other newgrfs and the uk v3 heightmap and those old houses from around 1830 onwards...

Trying to rework existing scenarios always causes reload problems in my experience (very limited :/)
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

Hi,

I will post more details for how to get the script working along with finding the ids for industries this evening.
I have also a height map for the uk in osgb coordinates, you can use any heigh map but but converting the coordinates could become very maths heavy and you will need to know the system your height map used.
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

Okay, So the script main.nut is needed with info.nut to explain what it is to OTTD. These two in a folder need to be placed in your ...\OpenTTD\game\ folder either where you installed the OTTD or there is another folder in your documents.

also attached is the heightmap I used for my scenario which will work with the script as it is. For other heightmaps you will have to generate new sets of x and y coordinates for the lists such as local industries = [{....
_
_
}];

to get the industry IDs for your GRFs, modify the code to iterate through the industry type list printing the names and IDs of each
something like this:

Code: Select all

for(i=1;i<255;i++){
	GSLog.Info(GSIndustryType.GetName(i)
}
}
untested

if your heightmap is from grid coordinates it will be similar to how I did it, if it is in lat/long that you will have a very very nasty time dealing with conversions, easiest way would be to get some GIS software which can handle the conversion to grid, but I would just avoid it to start with. In an unknown system it will be hellish, so if you have downloaded someones heightmap ask for the coordinate system from the author.

any questions please ask :D
Attachments
ScenarioGenerator.zip
place in "...\game" folder
(236.44 KiB) Downloaded 253 times
Blend.png
heightmap in "...\scenario\heightmap"
(1.05 MiB) Not downloaded yet
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Many thanks, hopefully I will give it a try at the weekend :)
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Hmm, not quite lining up on the heightmap, I seem to have cities in the sea... thinking I need to use 4096 x4096 since you don't seem to be able to use it as is is...

Was using old main, substituting...

Looks like time to get the API :/
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

hi,

the GS is currently very dumb, it doesn't look at the size of the map or make any kind of checks before trying to run, if you want a smaller scenario it should work if you factor down the x and y grid coordinates in the lists.

if a town or industry is placed on the sea, it will look for nearby land (forget if it was 5 or 10 tiles)

for the API docs, there is a link to NOGO on the wiki... for the most part it is the same as the AI API, with GS substituted for AI.
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [GS] Released Scenario Builder

Post by Zuu »

As for api:

GS: http://nogo.openttd.org/
AI: http://noai.openttd.org/

But yes, you can also go via the wiki which was mostly written in the past when there was only AI and not GS, but has after that had some patch work to include GS details. You can still probably see the AI origin in the wiki. I do recommend reading the AI/GS stuff on the wiki as it contains some useful facts on how AI/GS scripts interact with OpenTTD and some squirrel 2.0 pitfalls.
Last edited by Zuu on 09 Jan 2016 11:30, edited 1 time in total.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

No problem, I sorted it (weekend was best ;))

I used the original main file with the second scenario package and replaced the towns with those from the new one. Then I rotated the heightmap 90 degrees, went through your procedure and voilà!

I'm just generating a full sized screenshot (whole map so you can see the results) and then I'm going to try and play, save and reload the map. If all goes well, I'll post the finished scenario here.

Then I'm going to try and cut out the motorways and rail so I can simulate undeveloped Britain for an 1870 map to see what we might have come up with without landowners' rights, nimbys, etc ;). Idea being steelworks don't appear before 1875 so how will ppl cope with the transition..
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Zuu wrote:As for api:

GS: http://nogo.openttd.org/
AI: http://noai.openttd.org/

But yes, you can also go via the wiki which was mostly written in the past when there was only AI and not GS, but has after that had some patch work to include GS details. You can still probably see the AI origin in the wiki. I do recommend reading the AI/GS stuff on the wiki as it contains some useful facts on how AI/GS scripts interact with OpenTTD and some squirrel 2.0 pitfalls.
Thanks Zuu :)

I am thinking of seeing if I can get the placement script working with some of the other gamescripts here like neighbours, balanced growth, etc so I know I'm going to have to do some serious reading to catch up with U guys :/

20yr years ago I introduced my little bro to this game and he broke it (passed was it 4bn back then?) in a few weeks or less I think and now its my cousin's kids (11 and downwards). They only know the uk and get easily confused by random town names and positioning especially when you're trying to help their gameplay :)
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

Teaching national geography is not a bad thing either, the map is helping my girlfriend actually get an idea of where places are located.

Your scenario sounds exciting, one adaption to the game script I would like to make but haven't managed yet, is to add construction/destruction dates to industries so the power plants and mills exist during the correct years. I've also not found any historic population data for scaling back the sizes of towns/cities.

for combining the scripts, should hopefully be a case of wrapping each of the scripts into a function/co-routine wrapper, which should give scoping that avoids nasty namespace issues.

Most important thing is that the generator script should run once and once only, currently it only flags to the save function when it is done completely, but it would be safer to keep track of progress encase the script is still running during a save.

Will be excited to see what you can manage with the early start dates. When I can find the time/effort to add more I am hoping to add canals to my 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
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

I think dates are set in the newgrfs but if you want to apply a disaster like Margaret Thatcher to the coal industry for example, I suppose you can either use an array of known coal mines created from start or randomly select from a list of coal mines generated from the game at a year or few during the 80s to reduce by 80% in your script. I know that the newgrf topics are still quite active from my background reading so I reckon that anyone there should be able to quickly help with that. ;)

I know some might argue not just the coal industry was her effect but I don't think this thread is the place for that...

I had started discussing the combi script idea http://www.tt-forums.net/viewtopic.php?f=65&t=71555 and what you're suggesting might be a little ambitious from the noises I've been getting so far but you have more downloads here recently so I guess there are a few more guys on this now.

Will the guy under the bed please make himself known? ;)

Oops, full map 700MB and nothing will open it so I can shrink it :/
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

Putting a wrapper around the build industry method: http://nogo.openttd.org/docs/trunk/clas ... d215cb34a7
you could use an if statement and the gameTime class to set dates to build them.


sadly I don't see a method on the industry object to close them. This along with placing rivers, and terraforming and canals without company scope. I am planning to suggest the GS be extended to allow.

Impressive, I gave up waiting for a full map screenshot.
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Sorry about that issue.

I've done a save but it keeps crashing when DictatorialAI starts reloading and trying to find its property. Windows shuts it down so no crash logs.

I've included script, heightmap too for anyone aware of the issue while I search for clues...

Also found a potential source for historical population stats but not yet sure as to whether they actually have the info yet
Last edited by madprof on 10 Jan 2016 13:15, edited 1 time in total.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [GS] Released Scenario Builder

Post by Zuu »

On the matter of closing industries:

I have a started, but not completed patch that allow GS to speak with industry NewGRFs. I made a fork of Busy Bee where raw industry production is increased by completing goals using the patch and a special NewGRF which listen to the GS and change production on the command of the GS. It should also be possible for the GS using this patch to close industries although I'm not sure if I ever tried it.

Patch thread in NewGRF dev forum
Bee Productive - the Busy Bee fork

Eg. you may be interested to look at it. But it is not in trunk as of now and there is no ETA.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
madprof
Engineer
Engineer
Posts: 13
Joined: 02 Jan 2016 22:00

Re: [GS] Released Scenario Builder

Post by madprof »

Thanks Zuu :)

Interesting addition. One question though.. was the patch incorporated into 1.5.3? At the moment I can see why things are so locked down, i.e., to protect game integrity and security, in relation to blowing everything apart to add new functionality it seems and rightly too I suppose...

1.5.3 question cos patch was July? it might affect take up until 1.6 is released at least.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [GS] Released Scenario Builder

Post by Zuu »

Zuu wrote:But it is not in trunk as of now and there is no ETA.
Not in trunk means it is not sure if/when it get released. It needs more work for that. But knowing what use cases there might be is motivating.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

Being unfamiliar with grf coding I'm not entirely sure what they can do other than what I've seen with pikkas industry or firs or even if you mean industry or more grfs more generally.
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
User avatar
le_harv
Engineer
Engineer
Posts: 83
Joined: 27 Sep 2014 05:16

Re: [GS] Released Scenario Builder

Post by le_harv »

I'm a bit late to the party for scripts but I stumbled across this when looking for a way to batch process city placement for a scenario I am tinkering with. I understand the logic of this I think but I am struggling a bit.

Firstly, I can't seem to select the script from the AI/GS settings menu in the scenario editor even though the two files are placed in their own folder in the OpenTTD/Game folder. . I am working through the steps in this thread with your heightmap and files.

Secondly, how would I go about creating a list of X/Y coordinates and getting them to work with this script? For example, I have a heightmap in mind, and can develop a list of X/Y coordinates from it. EDIT - Opening one of the .nut files in notepad I can sort of see where to paste the lists in the same format.

Thanks in advance for any help you can provide me. Currently using JGR Patch Pack 26.

Cheers

Le_Harv
User avatar
jimbob
Engineer
Engineer
Posts: 87
Joined: 24 Nov 2014 21:13
Location: At a desk
Contact:

Re: [GS] Released Scenario Builder

Post by jimbob »

le_harv wrote:I'm a bit late to the party for scripts but I stumbled across this when looking for a way to batch process city placement for a scenario I am tinkering with. I understand the logic of this I think but I am struggling a bit.

Firstly, I can't seem to select the script from the AI/GS settings menu in the scenario editor even though the two files are placed in their own folder in the OpenTTD/Game folder. . I am working through the steps in this thread with your heightmap and files.

Secondly, how would I go about creating a list of X/Y coordinates and getting them to work with this script? For example, I have a heightmap in mind, and can develop a list of X/Y coordinates from it. EDIT - Opening one of the .nut files in notepad I can sort of see where to paste the lists in the same format.

Thanks in advance for any help you can provide me. Currently using JGR Patch Pack 26.

Cheers

Le_Harv

Hey, I'm affraid I can't really remember much about this script, but I believe I ran it through the debug console. Because parts of the script were ran through a company (roads) and rail and canals were planned it was converted to an AI which only run in a game. Having let the script run in the new game, you can rename the extension to open the "game save" as a scenario again.

The UK heightmap I used was a geospatial TIFF which was in OSGB coordinates, I had to sample coordinates at the two ends of the UK to get scaling factor to convert between OSGB and pixels. All my points for towns/rivers/roads were loaded from a number of Ordance Survey layers also in OSGB. QGIS is very good at handling all the coordinates and heightmap information as well as all the different strange coordinates systems maps use. I would do everything in QGIS before converting your layers to any projection which uses Eastings and Northings in meters, then manually do the conversion between meters and pixels.

Of course if your heightmap is not a geospatial image (the good news is you don't have to worry about GIS, but the bad news is you can't just auto generate your towns from map data), I would start off with pixels coordinates, any decent image editor should be able to get your pixel coordinates, and just move your cursor to the point and copy the numbers into that section of the nut file. This would also need ripping out all of the code which converts OSGB to pixels

I don't know anything about patch packs but if the pack can load vanillia scenarios I'd run it all in vanillia before loading it with JGR.
Image
Real life transport planner
My projects:Link to my UK Scenario|Scenario Builder GS
Do check out my 3D unity transport game: transporter
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 8 guests