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

GS - GSTown.SetGrowthRate fails #5786

Closed
DorpsGek opened this issue Oct 11, 2013 · 5 comments
Closed

GS - GSTown.SetGrowthRate fails #5786

DorpsGek opened this issue Oct 11, 2013 · 5 comments
Labels
component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)

Comments

@DorpsGek
Copy link
Member

The_Dude opened the ticket and wrote:

Bug or can be considered a feature request.

When GS controls town growth via GSTown.SetGrowthRate and when GS wants to stop the town growth, currently only done by setting high GR, let's say 1000 days and when GS wants to grow the town again and sets e.g. 10, the town will not grow for at least next 1000 days but will only rebuild houses.

This is cause by the grow_counter (town property), which is not reset when growth is set by GS.

In town_cmd.cpp is the static void UpdateTownGrowRate(Town *t)

prematurely ended with GS
if ((t->growth_rate & TOWN_GROW_RATE_CUSTOM) != 0) {
SetBit(t->flags, TOWN_IS_FUNDED);
SetWindowDirty(WC_TOWN_VIEW, t->index);
return;
}

while skipping the grow_counter new value assignment which goes after
t->grow_counter = m;

In my opinion this bug can be solved either by
if ((t->growth_rate & TOWN_GROW_RATE_CUSTOM) != 0) {
t->grow_counter = t->growth_rate | ~TOWN_GROW_RATE_CUSTOM;
SetBit(t->flags, TOWN_IS_FUNDED);
SetWindowDirty(WC_TOWN_VIEW, t->index);
return;
}
or by implementing new GS function that stops town growth more cleanly then setting very high growth rate (which is obscure)

Reported version: 1.3.2
Operating system: All


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

frosch wrote:

Possible solution attached.
This adds two speical values ScriptTown::TOWN_GROWTH_NONE and TOWN_GROWTH_NORMAL, which can be used with SetGrowthRate.

It also fixes some weird behaviour of current SetGrowthRate and GetGrowthRate:
- GetGrowthRate now returns TOWN_GROWTH_NONE if the town is not growing, instead of some imaginary value.
- SetGrowthRate reset the custom growth rate if zero was passed to it (undocumented). Now, there is a special value TOWN_GROWTH_NORMAL for that.

I am not sure whether the SetGrowthRate(0) thingie is used by scripts. Maybe it needs a API compatibility script, or we can adjust TOWN_GROWTH_NORMAL to use the value "0". Though that value is somewhat treacherous when using a formula to compute a growth rate.

Attachments


This comment was imported from FlySpray: https://bugs.openttd.org/task/5786#comment12702

@DorpsGek
Copy link
Member Author

The_Dude wrote:

Looks very promising. I think such solution really solves the growth zero and fund buildings override. Good work.

Just three remarks I would have

  1. GS could have a function GSTown::GetFundedMonths of simply IsFunded(), so script could extend growth when players spent money for funding (like normal openttd does)

  2. I still miss the grow_counter adjustment when script sets new town growh
    Something like
    if(t->grow_counter >= t->growth) t->grow_counter = t->growth;
    so when you set high growth, and after some time you set lower or much lower, because player did very good, counter could behave the same as in game, where it is reseted like this

  3. Also some script function to set growth back to non-custom might be useful, although I admit I am not sure about that


This comment was imported from FlySpray: https://bugs.openttd.org/task/5786#comment12703

@DorpsGek
Copy link
Member Author

frosch wrote:

  1. Fixed in r25931.
  2. Already included in above diff via TOWN_GROWTH_NORMAL.

This comment was imported from FlySpray: https://bugs.openttd.org/task/5786#comment12705

@DorpsGek
Copy link
Member Author

The_Dude wrote:

Excellent. That would be really very great to see in next branch.

Also if 1) would be included


This comment was imported from FlySpray: https://bugs.openttd.org/task/5786#comment12706

@DorpsGek
Copy link
Member Author

frosch closed the ticket.

Reason for closing: Implemented

in r25931, r25967, r25968, r25969


This comment was imported from FlySpray: https://bugs.openttd.org/task/5786

@DorpsGek DorpsGek added flyspray This issue is imported from FlySpray (https://bugs.openttd.org/) Goal/Game script labels Apr 7, 2018
@frosch123 frosch123 added the component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) label Apr 14, 2018
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) flyspray This issue is imported from FlySpray (https://bugs.openttd.org/)
Projects
None yet
Development

No branches or pull requests

2 participants