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!)
