Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DorpsGek opened this issue Sep 19, 2012 · 5 comments
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) enhancement Issue would be a good enhancement; we accept Pull Requests! flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) good first issue Good for newcomers

Comments

@DorpsGek
Copy link
Member

xOR opened the ticket and wrote:

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.

Reported version: 1.2.2
Operating system: All


This issue was imported from FlySpray: https://bugs.openttd.org/task/5304
@DorpsGek
Copy link
Member Author

Yexo wrote:

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.


This comment was imported from FlySpray: https://bugs.openttd.org/task/5304#comment11519

@DorpsGek
Copy link
Member Author

xOR wrote:

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?


This comment was imported from FlySpray: https://bugs.openttd.org/task/5304#comment11520

@DorpsGek
Copy link
Member Author

xOR wrote:


This comment was imported from FlySpray: https://bugs.openttd.org/task/5304#comment11521

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Goal/Game script labels Apr 7, 2018
@TrueBrain
Copy link
Member

I like the solution of a ALL_TOWNS options; that sounds like a really good idea.

I also read a bug here, which deserves his own ticket. #6712

@TrueBrain TrueBrain added good first issue Good for newcomers enhancement Issue would be a good enhancement; we accept Pull Requests! and removed enhancement from FlySpray labels Apr 14, 2018
@frosch123 frosch123 added component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) and removed Goal/Game script labels Apr 14, 2018
@andythenorth
Copy link
Contributor

Thanks for this. There's been no activity on this for some time, and as it stands, it doesn't look likely that it will go any further. I'm closing it as we try to keep the issue count low for OpenTTD, it helps us focus on things that are important and fun. Feel free to discuss in irc or request re-opening if you disagree. Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) enhancement Issue would be a good enhancement; we accept Pull Requests! flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants