OpenTTD

Tasklist

FS#5304 - Game Script: GSTown.SetCargoGoal() and GSTown.SetGrowthRate() affecting all towns in one step

Attached to Project: OpenTTD
Opened by xOR (xOR) - Wednesday, 19 September 2012, 21:48 GMT
Last edited by andythenorth (andythenorth) - Monday, 04 September 2017, 07:02 GMT
Type Feature Request
Category Script → Goal/Game script
Status New
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version 1.2.2
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 5
Private No

Details

To initialize a map with cargo goals for all towns/cities right now my GameScript is iterating through all of the towns and calls GSTown.SetCargoGoal() and GSTown.SetGrowthRate() for each of them. However, on a 512x512 map with 200 towns when I want to set 4 cargo goals and set the growth rate this is causing 5 DoCommands per town to be sent. As each DoCommand causes a waiting time of at least 1 tick this makes at least 1000 ticks only for waiting. On top comes the actual work and other initialization code (in a test initialization took 1295 ticks in total).
With a 1024x1024 map (which is quite common when checking the current multiplayer server list) and number_towns = 3 I just got 768 towns and initialization took 6575 ticks. That's more than 3 minutes only to initialize goals to 0 to create certain starting conditions for players in CityBuilder.

I understand there is no way around the DoCommand handling and the delay involved, so I got the idea that these two functions could be changed so they can also work with INVALID_TOWN as Town ID, meaning that the change should be applied to all towns and cities on the map. The DoCommands for that would be changed accordingly, so to set 4 cargo goals on all towns I would only need 4 calls to GSTown.SetCargoGoal().

I can't think of a situation where it would make sense to be used mid-game but for initialization purposes it would be useful to have that.
This task depends upon

Comment by Thijs Marinussen (Yexo) - Thursday, 20 September 2012, 19:45 GMT
When generating a new game a GameScript should have 2500 ticks to initialize everything it wants as long as it doesn't call Sleep(). However this is currently broken since not only a sleep but also any DoCommand will stop the initialization and start the game. These 2500 ticks could be increased easily, it then doesn't take any time at all to call SetCargoGoal on all towns. I've discussed this with frosch and we both think this is a better solution than introducing a function that works on all towns since such a function would be pretty limited.
Comment by xOR (xOR) - Thursday, 20 September 2012, 19:51 GMT
I agree, this solution would be better, as it's only about initialization anyway. What do you mean by "2500 ticks could be increased easily", you plan to implement a configuration option for it?
Comment by xOR (xOR) - Thursday, 20 September 2012, 20:23 GMT

Loading...