[NoGo] Neighbours are important

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

Post Reply
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

[NoGo] Neighbours are important

Post by Zuu » 27 Dec 2011 20:12

As there were no scripts uploaded yet that set town goals, I came up with the idea of uploading a variant of of the script that TrueBrain wrote for NoGo and was used on the #openttdcoop test server.

The basis is that towns has a requirement of passengers, mail, goods, food etc. When the town size grows, the requirement grows. Thus you have to deliver more and more in order to keep growing the town.

What this variant also adds is a neighbour factor. If a town is smaller than its closest neighbours, it will have a neighbour factor < 1. If the town on the other hand is larger than its neighbours the factor will be > 1. Thus, to grow a large town to become even larger, you might want to consider growing its neighbours too, especially if they are small.

Since the script has to find out the neighbours of all towns, it takes quite some opcodes to initialize. Thankfully OpenTTD gives GameScripts 2500 ticks in the map generation process which is enough for most maps. But if you play 1024x1024 or larger with high town density, you might need to run the game in fast forward before the goals are set up.

Download
Via online content or through the bananas website

Currently no libraries are required.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Splime
Engineer
Engineer
Posts: 1
Joined: 30 Dec 2011 07:49

Re: [NoGo] Neighbours are important

Post by Splime » 30 Dec 2011 07:56

This script is a lot of fun to play with! Though I was wondering, is it possible to make the supply requirements lower, or set some sort of difficulty parameter? I'd like to be able to have my cities grow a little bit faster!

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 30 Dec 2011 12:35

Sure, I was also thinking about adding a parameter to disable the neighbours parameter, which will make it easier and allow playing that style too.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1312
Joined: 31 May 2004 09:21

Re: [NoGo] Neighbours are important

Post by TrueBrain » 30 Dec 2011 14:08

How many ticks do you need in the generation to find out the neighbour graph? (the current value is set as a: this-should-never-be-reached-but-I-have-to-input-some-value)
The only thing necessary for the triumph of evil is for good men to do nothing.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 05 Jan 2012 19:18

With a 2048x2048 map that have high density the setup took 29510 ticks. On a different map of the size 2048x1024 it took 11079 ticks.

These measures were made with about the same amount of setup as in version 1. In version 2 there will be a new feature that will eat a few more ticks but it doesn't have any expansive neighbour lookup but a tile scanner so it is not completely free.

With the new features for version 2 enabled, the setup for a 2048x2048 map took 38863 ticks.


On IRC Eddi mentioned that the amount of towns possible is limited by the town generator. So for the record, I've used the Swedish town names that are included in OpenTTD.


Edit: And for comparison, a 512x512 with the version 2 features enabled took 156 ticks.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 05 Jan 2012 19:46

Update - Version 2

Changes:
  • Towns growth can get reduced/stopped when they get congested
  • When a town gets congested, a news message is sent to all companies with road vehicles in the town area that is tested for congestion. A sign is also placed on the town tile to note that the town is congested.
  • Global goals are created for each congested town to reduce the congestion there. At the moment there is no award, not even a news message for accomplished goals. Only way to tell is that the congestion sign in the town centre is removed.
  • Settings:
    • You can now disable that neighbours town sizes affect growth goals
    • The cargo delivery goals can now be scaled by a factor.
    • What happens with congested towns: [no effect, towns grow slower, towns stop grow]
    • A scale factor to scale the limit of number of vehicles in the town centre at which point the town is considered to be congested. The actual limit depends also on the town population.
    Unnamed, 27th Apr 1950.png
    Unnamed, 27th Apr 1950.png (10.65 KiB) Viewed 28569 times
I would be happy if those of you who play with this GameScript reports back what kind of values on the two scale factors that you find good. That way I can see if I need to adjust the baseline or the recommended easy/medium/hard values.

I've not actually playtested the congestion feature, only by ether manually jamming towns with buses or using the TownCars AI.

The idea is that when you play against the cargo goals it can give some extra challenge on how you distribute your cargo from feeder stations to the towns. Currently it only consider road vehicles so I guess it could make for some interesting decisions if rail, ships and air is a bit expansive compared to road vehicles.
Oskarfors Transport, 12th Apr 1956.png
Oskarfors Transport, 12th Apr 1956.png (120.72 KiB) Viewed 28569 times
goal - neighbors-v2.tar
(20 KiB) Downloaded 391 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

nalyu
Engineer
Engineer
Posts: 4
Joined: 06 Jan 2012 23:08

Re: [NoGo] Neighbours are important

Post by nalyu » 06 Jan 2012 23:16

I am now playing this but after a while my town asks for water. The only problem is that the town has not build a watertower. and i can't fund one myself because when i try it says "can't construct this industry type here... ...can only be built in towns."

My parameters are set as followed:
Cargo req. depends on : Size of current town size
Cargo goal factor (in%): 150
Congested towns: disabled

2nd thing: Cargo goal is @ hard however my town has now a population of 3.626 Goal for cargo = 5 passengers, 1.000 liters of water and 2 tonnes of food i think those values are a bit low for the size of the town.

Edit 1: Now started at a town close to it that already had a watertower.

User avatar
AndersI
Tycoon
Tycoon
Posts: 1732
Joined: 19 Apr 2004 20:09
Location: Sweden
Contact:

Re: [NoGo] Neighbours are important

Post by AndersI » 07 Jan 2012 12:54

nalyu wrote:I am now playing this but after a while my town asks for water. The only problem is that the town has not build a watertower. and i can't fund one myself because when i try it says "can't construct this industry type here... ...can only be built in towns."
I believe the water towers must be built on top of a town house. Did you try that?

nalyu
Engineer
Engineer
Posts: 4
Joined: 06 Jan 2012 23:08

Re: [NoGo] Neighbours are important

Post by nalyu » 07 Jan 2012 14:39

AndersI wrote:
nalyu wrote:I am now playing this but after a while my town asks for water. The only problem is that the town has not build a watertower. and i can't fund one myself because when i try it says "can't construct this industry type here... ...can only be built in towns."
I believe the water towers must be built on top of a town house. Did you try that?
That worked but it was not needed because started with a town close to it that had a watertower and that one is now much bigger.
Thanks anyway.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 07 Jan 2012 16:20

nalyu wrote:My parameters are set as followed:
Cargo req. depends on : Size of current town size
Cargo goal factor (in%): 150
Congested towns: disabled

2nd thing: Cargo goal is @ hard however my town has now a population of 3.626 Goal for cargo = 5 passengers, 1.000 liters of water and 2 tonnes of food i think those values are a bit low for the size of the town.
Those low numbers are clearly a bug. I've confirmed that when you set cargo requirement to depend only on town size, you get the goals 1/100 compared to what they should be. Soon there will be a new version that fixes this issue.

Unfortunately the only way to fix your current game is to hack your version 2 of this game script so that it contains the fix that will be in version 3. For that purpose I've attached both a patch that can be applied to town.nut and a new town.nut that you can replace the old one with. To do so, find the tar file with this GameScript. Probably located in OpenTTD/content_download/game. Move that one up to OpenTTD/game. untar and preferable remove the tar file to not have two different version 2 in the search path. Then either replace town.nut or apply the attached patch.
Attachments
town.nut
Replacement town.nut for version 2. Only required if you need to apply the fix in a running game with version 2 of Neighbours are important. For all others, there will shortly be a version 3 that contains this fix.
(8.94 KiB) Downloaded 313 times
factor-fix.patch
Patch to fix bug in town.nut for version 2. Only required if you need to apply the fix in a running game with version 2 of Neighbours are important. For all others, there will shortly be a version 3 that contains this fix.
(3.58 KiB) Downloaded 329 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 07 Jan 2012 16:56

Update - Version 3

Changes:
  • Fixed bug that caused the goals to be 1/100 of the intended values when the neighbours factor was turned off.
  • Reduced the maximum neighbour factor from 800% to 500%. That is large towns with small neighbours can now at maximum get their goals raised by 500% compared to 800% before. Perhaps this will still give a high penalty if you don't also grow the neighbours, but not as extremely high
  • Added a readme.txt
Attachments
goal - neighbors-v3.tar
(22 KiB) Downloaded 419 times
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

nalyu
Engineer
Engineer
Posts: 4
Joined: 06 Jan 2012 23:08

Re: [NoGo] Neighbours are important

Post by nalyu » 08 Jan 2012 05:07

Zuu wrote:
nalyu wrote:My parameters are set as followed:
Cargo req. depends on : Size of current town size
Cargo goal factor (in%): 150
Congested towns: disabled

2nd thing: Cargo goal is @ hard however my town has now a population of 3.626 Goal for cargo = 5 passengers, 1.000 liters of water and 2 tonnes of food i think those values are a bit low for the size of the town.
Those low numbers are clearly a bug. I've confirmed that when you set cargo requirement to depend only on town size, you get the goals 1/100 compared to what they should be. Soon there will be a new version that fixes this issue.

Unfortunately the only way to fix your current game is to hack your version 2 of this game script so that it contains the fix that will be in version 3. For that purpose I've attached both a patch that can be applied to town.nut and a new town.nut that you can replace the old one with. To do so, find the tar file with this GameScript. Probably located in OpenTTD/content_download/game. Move that one up to OpenTTD/game. untar and preferable remove the tar file to not have two different version 2 in the search path. Then either replace town.nut or apply the attached patch.
As that town had only a population of about 4k it was easier for me to start over but thanks anyway.

mstanescu
Engineer
Engineer
Posts: 8
Joined: 02 Mar 2007 20:45

Re: [NoGo] Neighbours are important

Post by mstanescu » 08 Jan 2012 22:42

Hello,

I am trying to run this script on a dedicated linux server with a certain scenario but i am having problems figuring out how to start.

My config has

Code: Select all

[game_scripts]
"Neighbours are important" = enable_neighbours=0
I see it is running on my local windows machine when i generate a game but script is not running when i am loading this scenario.

Is there a trick for running the script with scenarios?

Thanks
Mihai

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 09 Jan 2012 19:11

You will have the same problem trying to bind a save game to a Game Script after the game has been created. A scenario is basically a savegame with a different extension. To solve your problem without modifications to OpenTTD, you need create a new scenario where you set in your main menu to use this Game Script before clicking on the scenario editor button to create a new scenario.

If you find this too constraining, then that is a feature request for the NoGo framework and OpenTTD itself. For the development of the Tutorial I hope there will be a solution to be able to bind a scenario to a Game Script after the scenario has been created. But that is unfortunately not the case at the moment.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Fanatik
Engineer
Engineer
Posts: 7
Joined: 17 Apr 2012 09:18

Re: [NoGo] Neighbours are important

Post by Fanatik » 19 Apr 2012 10:33

Aloha Zuu :)

As proclaimed in http://www.tt-forums.net/viewtopic.php?f=33&t=57431 i've extended your script a little bit and wanted to ask you if your interested in the changes. Some of your code still remains within so ofc i won't release it to the public without your review and permission. Anyway these are the changes i've implemented so far...

List o' changes

- Cities now show who their neighbouring cities are within the town GUI.

- Congestion now actually happens (rebalanced values to the point where "Hard" means hard and Easy means easy)

- Added lots of new Settings (and updated others with appropriate descriptions)

- Lots of Balancing for CargoGoals

- Implementing a CacheClass (Tables are great!) for reoccuring calculations all over the place

- Added Periodic Expansion of Cities even while their CargoGoals are not reached (very slow growth, but still ;P)

- Added Option to adjust the TimeSpan between each Periodic Expansion

- Added Option to have Cities benefit from Periodic Expansion more then Towns.

- Replaced integer (percentage) values for difficulties with named Settings. There are always quite a lot, but people wont tell the difference between 50 and 52 ingame anyway, so i think this is more intuitive.

- Added Option to switch between simple (Passengers/Mail) and complex cargoGoals.

- CargoGoals (except for Passengers) now have an offset within their calculation so they form a nice curve instead of a line ;P

- Added a small CargoGoal handicap for Cities without a neighbour if neighbours are enabled.

- Added a Compatiblity Mode for FIRS newGRF (as i love it!). Up to 5 different Goals in the normal Landscape (Passengers->Mail->CratesOfWarez->Food->Fuel)

- Added Translation for German

- Added an Option for changing the maximum amount of neighbours a town may have

- In lack of a better alternative introduced an ugly and primitive way to sort GSSettings into Categories


NextUp:

- Quality of Service: Have a town get a Expand()-boost if the Towns PercentageTransported Values stay above a certain value for at least X months.... for the perfectionist ;)

- Properly Save important values when the Game issues a save.

- Evolving Neighbourhood: Towns pick new neighbours as they grow in size.

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 19 Apr 2012 19:11

Looks good to me. I haven't been playing with the game script much since I created it. The reason why I had percetange settings and not a few labled values was that I didn't want to spend my time playing it through several times to figure out what settings to pick. Instead I opened it up for players to test and hopefully report back what they found as good settings.
Zuu wrote:I would be happy if those of you who play with this GameScript reports back what kind of values on the two scale factors that you find good. That way I can see if I need to adjust the baseline or the recommended easy/medium/hard values.
So, I very much welcome that you have taken your time and refine the script based on your experience with it. If you look around, you'll see that I've created more AI/GS projects than that I can possible improve all of them to higher standard very quickly.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

e4e5nf3
Engineer
Engineer
Posts: 18
Joined: 23 Feb 2012 22:13

Re: [NoGo] Neighbours are important

Post by e4e5nf3 » 21 Apr 2012 21:52

Very fun script, it certainly adds a certain sense of realism and challenge to the game.

Growing a town starts to become a challenge once it reaches a certain size. In my current game I have practically every large city on the map "feeding" my target city (it started as a size 75 and has grown into a size 10000+). The problem I have now is that I can't send anymore passengers and goods to my target city because the feeder cities are already at maximum production, thus the target city has stopped growing. And even if I managed to grow these feeder cities, I am already producing the maximum amount of goods possible on the map, so I have no extra goods to spare to send to extra cities.

Have I reached the "end game"?

User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [NoGo] Neighbours are important

Post by Zuu » 23 Apr 2012 15:00

If your advanced setting allows, you can fund new industries and also fund new towns.

You could possible also re-direct your passengers and cargo to another town B to grow that. Then when town B has grown you can go back to growing your original town and now have more passengers and mail from B to send.

Also, unless you have disabled the neighbours part of "neighbours are important", then it is beneficial to grow the 5 or so closest towns in relation to the town you try to grow. That will reduce the cargo requirements of your town.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)

Malaras
Engineer
Engineer
Posts: 1
Joined: 09 Jun 2012 22:49

Re: [NoGo] Neighbours are important

Post by Malaras » 09 Jun 2012 22:53

Fanatik wrote:Aloha Zuu :)

As proclaimed in http://www.tt-forums.net/viewtopic.php?f=33&t=57431 i've extended your script a little bit and wanted to ask you if your interested in the changes. Some of your code still remains within so ofc i won't release it to the public without your review and permission. Anyway these are the changes i've implemented so far...

List o' changes

- Cities now show who their neighbouring cities are within the town GUI.

- Congestion now actually happens (rebalanced values to the point where "Hard" means hard and Easy means easy)

- Added lots of new Settings (and updated others with appropriate descriptions)

- Lots of Balancing for CargoGoals

- Implementing a CacheClass (Tables are great!) for reoccuring calculations all over the place

- Added Periodic Expansion of Cities even while their CargoGoals are not reached (very slow growth, but still ;P)

- Added Option to adjust the TimeSpan between each Periodic Expansion

- Added Option to have Cities benefit from Periodic Expansion more then Towns.

- Replaced integer (percentage) values for difficulties with named Settings. There are always quite a lot, but people wont tell the difference between 50 and 52 ingame anyway, so i think this is more intuitive.

- Added Option to switch between simple (Passengers/Mail) and complex cargoGoals.

- CargoGoals (except for Passengers) now have an offset within their calculation so they form a nice curve instead of a line ;P

- Added a small CargoGoal handicap for Cities without a neighbour if neighbours are enabled.

- Added a Compatiblity Mode for FIRS newGRF (as i love it!). Up to 5 different Goals in the normal Landscape (Passengers->Mail->CratesOfWarez->Food->Fuel)

- Added Translation for German

- Added an Option for changing the maximum amount of neighbours a town may have

- In lack of a better alternative introduced an ugly and primitive way to sort GSSettings into Categories


NextUp:

- Quality of Service: Have a town get a Expand()-boost if the Towns PercentageTransported Values stay above a certain value for at least X months.... for the perfectionist ;)

- Properly Save important values when the Game issues a save.

- Evolving Neighbourhood: Towns pick new neighbours as they grow in size.
Zuu wrote:Looks good to me. I haven't been playing with the game script much since I created it. The reason why I had percetange settings and not a few labled values was that I didn't want to spend my time playing it through several times to figure out what settings to pick. Instead I opened it up for players to test and hopefully report back what they found as good settings.
Zuu wrote:I would be happy if those of you who play with this GameScript reports back what kind of values on the two scale factors that you find good. That way I can see if I need to adjust the baseline or the recommended easy/medium/hard values.
So, I very much welcome that you have taken your time and refine the script based on your experience with it. If you look around, you'll see that I've created more AI/GS projects than that I can possible improve all of them to higher standard very quickly.

Did you ever share this? ;)

User avatar
V453000 :)
President
President
Posts: 947
Joined: 01 Feb 2011 11:22
Location: Beer

Re: [NoGo] Neighbours are important

Post by V453000 :) » 12 Aug 2012 13:32

The towns funded in game seem not influenced by this script. :)
[15:30] <Zuu_> V453000, IIRC it should handle that event but it might not be working. You could try to save + load. Also report it in the thread and I'll tke a look at he code when possible (at a train at the moment)
Here you go.
ImageImageImage

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests