Moderator: OpenTTD Developers
I learned quite a bit about squirrel going through that optimized function krinn, thanks for that. I changed most of my existing script to match (had to avoid some things I don't understand, like the foreach loop - whats with the optional parameter and the "dummy" or "_" sometimes?). Also your idea of encapsulating my town nodes and associated lists in a class, rather than using the 3 public arrays (should be 1 2D array), is intriguing. It could make my other, more accurate, town tile function viable for larger maps as the list won't have to be recreated each loop. Don't know how OpenTTD will handle the large numbers of tiles in memory though, could be up to 6000 per town + large map of 1000+ towns...
And thanks Zuu, that syntax has been elusive for me, no info in the language docs or google. Now I can resume my AI
So thanks to you guys advice, and moving to a town size approximation algorithm, this new version is an order of magnitude faster
A 1024 * 1024 can be created under quota (faster than orig for some reason also) and a 2048 * 2048 in under 5 mins (using normal settings also, thats 3600 industries!)
local thatvar = [a,b,c,d];
if you don't care about the member, to only use the value :
foreach (value in thatvar) -> value = a, balue = b...
because thatvar=a where 0 is the member and a the value
care of both
foreach (item, value in thatvar) -> item= 0 value=a, item=1, value=b...
care of only the member, for this people just use _ or dummy or anything to show you don't really care about it
foreach (item, _ in thatvar) -> item = 0, _ = a...
That's computer deal : using ram or using cpu, you have to use one or the other. I think a guy that want play on huge map have the memory to do that, while his cpu ressource remain tight to one core. So more ram eat to lower cpu usage is better for most people, and ones with too few memory certainly cannot play it with or without the script because of the map size.
Let's take the highest cache hit, so your random town function always pickup the same town: looping 3600 times
- no cache: 3600+3600+3600 calls to functions (get house tile, get border tiles, remove bordertiles)
- cache : 3599 addlist calls (get house tile) + 3599 addlist calls (get border tile) + 2 calls for your functions
i don't think an addlist takes more times than any of those 3 functions...
You can save memory if the cache have no usage after the function, just clear it on exit.
I’m going to take a swing at the proposed method using a class for each node to see how it performs. I think it will be useful on large maps, as my current town size approximation error scales with town size, large maps have many more large towns and therefore larger error. Maybe I give the option as a parameter, to use the slow method, and have a threshhold for townsize, hmm.
One feature request: Could you lower the bank population minimum to 300-400?
- scriptbug.png (34.9 KiB) Viewed 4539 times
Regarding the stuck town building loop; what map size and town count are you using? I guess you realise that if there are not enough valid towns for all the industries (per industry type and up to max ind per town) then the script will understandably get stuck. If this is the case then it is a bug, I will look what happens in some scenarios to test. Thanks for the report.
FYI, I sacrificed reliability for freedom for the settings, so there are probably many setting combos where the script will get stuck. To deal with this I made many settings changeable on the fly, in game. If you are getting some (hopefully comprehensible) errors you can tweak the settings to give more room for the script to build as it is trying
- (123 KiB) Downloaded 142 times
I've changed all to scattered now which creates interesting layouts with good scope.
The town idea is a very intriguing one and I'm looking forward to seeing it - thanks for this update in the meantime.
The reason for the crash is given in the second warning line of text (warnings are in yellow); because you have started (or loaded) a game with the script but also with industries set in map creation. The setting must be "Funding only" on map creation as described in the Readme. The reason for this, as well as the crash, is to allow the gamescript to take over industry creation from the default not run along side. Your setup has 1019 default industries created by the map generator.
Edit: To clarify in case I have not mentioned it anywhere else, this script requires a new game, or a game with no default industries to work.
What are you trying to do? Play an existing game with default industries with this GS which maintains the map industry numbers using the placement algorithms?
If you are just looking to maintain the numbers but don't care about placement then I suggest you use Aphids version of this concept, AFAIK it will work with existing games.
My script was designed to do most of its magic on map creation, the maintenance of numbers is just kind of a feature
I used this script on a new game start today and got these errors with the default settings of the script:
These errors vanish if I set the spawn method for primary industries from cluster to random.
Also while ingame these errors came up:
They vanish after about 4 years, but also do the script messages and there aren't any new industries built after that.
Another possible issue is that with the Clusters method you need "multiple industries per town" enabled in most cases to get it to work, as otherwise same industries cannot be built so close together.
If you run the script with default OpenTTD on default script settings and methods and still get the empty map then there is some serious issue...
I am busy working on a rewrite of this GS which includes building towns, it also has some features to ask the player for help when situations happen that the script gets stuck. There are so many ways this can happen, as you can see from the bugs
So rather than try debug the current version, if you still get errors, I will post the WIP one once it is able to do industries properly like the current one.
This new version is much faster, reliable and handles the many difficulties better. It also can create towns too, using 4 algorithms:
- Random, mimics the standard distribution.
- Scattered, evenly spaced from eachother.
- Clustered, separate groups, customizable.
- Metropolis, similar to "clustered" but has a city in the middle and towns all around, instead of random towns/cities.
Another new feature is messages to the player telling you when things are struggling and hints how to fix (note the Readme is not yet updated to help with this).
Finally a WIP aspect is the ability to generate roads between towns, these will be based on the town algorithm selected so Clusters join eachother, Metropolis joins the city to towns and Scattered/Random joins all on map using a shortest pathfinder (a genetic algorithm written to solve the Travelling Salesman problem here, I might add ). This is not yet finished, but here is the current version with towns and industries generation if anyone wants to check out the towns stuff.
- (180.5 KiB) Downloaded 129 times
Just had a successful test for roads generation, finally got my Travelling Salesman algorithm working nice. After around 600 or so "evolutions" / generations it can solve a 256^2 map, max cities, to satisfaction in a few hundred ticks. Larger maps will be split into 256^2 bits for performance. Road builder takes long as it was designed for accuracy not speed but can build all roads in 3 months give or take.
Users browsing this forum: No registered users and 2 guests