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

Feature: Disallow industry production changes from GS #7912

Merged
merged 1 commit into from Dec 22, 2020

Conversation

nielsmh
Copy link
Contributor

@nielsmh nielsmh commented Jan 6, 2020

This is (so far) completely untested!

Flags to disallow production changes in industries, so GS can "freeze" industries.
Two additional functions for GS to query when an industry last had activity. (Not available to AI since this information is not available to players either.)

This may have strange interactions with NewGRF industries and probably needs some thorough analysis/testing.

@James103
Copy link
Contributor

James103 commented Jan 6, 2020

If you want a Game Script to be able to disallow in-game industry production changes, it comes naturally that you would also want a Game Script to be able to set the production level of an industry. The combination of those two would allow the GS to gain full control over industry production levels.

@nielsmh
Copy link
Contributor Author

nielsmh commented Jan 7, 2020

I do wish for GS to control industry production levels, but it turns out to be a difficult problem, since industries' production levels can be controlled in several ways.
Standard rules industries are affected by the game setting for smooth economy, depending on that setting only one or another kind of production change is allowed.
NewGRF industries are worse, they can have the production change callback, production callback, and have internal state. It's very easy to create a NewGRF industry that can have varying production levels depending on all kinds of things, but not react to any attempts at changing production level.

@James103
Copy link
Contributor

James103 commented Jan 7, 2020

I have the following ideas that would go with the idea of Game Scripts controlling cargo:

On the producer level:

  • Allow Game Scripts to lock in industry production (this PR currently does this).
  • Allow Game Scripts to change the production level of an industry (may be difficult as per @nielsmh)
  • Allow Game Scripts to freeze all natural production from an industry or town (this voids any cargo coming from the industry/town unless the GS ordered the industry/town to produce)
  • Allow Game Scripts to force industries to produce cargo (including unnatural cargo types).
    Example: Coal Mine produces 100 Passengers and promptly shuts down (workers leaving the area).
  • Allow Game Scripts to force industries to transport cargo (this ignores station ratings).
  • Allow Game Scripts to force an industry to announce imminent closure.

On the station level:

  • Allow Game Scripts to set and/or lock the station rating for a station/cargo pair.
  • Allow Game Scripts to change the amount of waiting cargo at a station.
  • Allow Game Scripts to protect waiting cargo from disappearing due to bad service/overcrowding.

@planetmaker
Copy link
Contributor

planetmaker commented Jan 7, 2020

There's 3 kinds of industries (or maybe 4: BLACK_HOLE | EXTRACTIVE | ORGANIC | PROCESSING ):

a) Primary industries (EXTRACTIVE / ORGANIC) which have a definable production level. They produce things out of thin air.
b) Secondary industries (PROCESSING). They take input and convert it some way into output. The level is controlled mostly by input amount. How exactly is in NewGRF control. There is technically at least 2 ways NewGRF may implement this: Like (a) but with additional variable checks. Or (usually) by consuming input (in required ratios) and producing output accordingly
c) Tertiary (BLACK HOLE) industries which just consume, but don't produce (like power plants).

A sensible production level is only available for (a) which means for mines and farms mostly. For (b) and (c) it's probably only an option to trigger the production call-backs outside the monthly loop or not. NewGRFs can basically disregard the production_level in the the production callback which is triggered periodically (all 256 ticks) and/or upon delivery of goods.

That said: I totally like the idea and approach. It just needs a word of caution for players that it might not work always as expected when using industry newgrfs (e.g. with FIRS /ECS I expect partially funky results)

@James103
Copy link
Contributor

I also think that a Game Script should allow an industry to force announce imminent closure (regardless of if the industry can naturally close). This would allow Game Scripts to notify players/AI that an industry will close before demolishing the industry itself (or having the game demolish the industry at the end of the month).

@ldpl
Copy link
Contributor

ldpl commented Jan 14, 2020

IMO it's not a big issue that this thing doesn't quite work with all newgrfs as it only affects GS authors, not players directly.

Also, I think found another good use for IndustryControlFlags - add flags to allow exclusive access to the industry for a specific company. One flag for supply and one for production, all GS-controlled. Would solve a lot of industry sharing issues in mp. I'll make a PR one this gets merged.

@nielsmh
Copy link
Contributor Author

nielsmh commented Jan 14, 2020

Should the industry GUI show any indication of whether the industry is under GS control or working normally? I don't think it's necessary.

@ldpl
Copy link
Contributor

ldpl commented Jan 14, 2020

@nielsmh, well, it kinda should IMO but OpenTTD generally doesn't show such things. For example, for towns a lot of GS stuff is hidden so if something goes wrong you need CityMania client that actually shows it albeit in a very ugly way.

@nielsmh nielsmh added component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) savegame upgrade labels Jan 15, 2020
src/industry_cmd.cpp Outdated Show resolved Hide resolved
src/industry_cmd.cpp Show resolved Hide resolved
src/industry_cmd.cpp Outdated Show resolved Hide resolved
@nielsmh nielsmh marked this pull request as ready for review February 8, 2020 08:15
@frosch123
Copy link
Member

Please also update game_changelog.hpp

@SamuXarick
Copy link
Contributor

I'm testing this PR, and will report issues as I find them.
GetLastProductionYear on a Power Station retrieves the year the industry started construction. Shouldn't it report an error for industries that can't produce any cargo?

src/industry_cmd.cpp Show resolved Hide resolved
@SamuXarick
Copy link
Contributor

PR 7912 GS test.zip
Tests some API functions at the end of every month and some others at the end of every year.

@nielsmh nielsmh requested a review from frosch123 April 11, 2020 15:29
@TrueBrain TrueBrain added candidate: needs considering This Pull Request needs more opinions size: large This Pull Request is large in size; review will take a while labels Dec 14, 2020
@TrueBrain TrueBrain added candidate: yes This Pull Request is a candidate for being merged and removed candidate: needs considering This Pull Request needs more opinions labels Dec 22, 2020
src/saveload/afterload.cpp Outdated Show resolved Hide resolved
@TrueBrain
Copy link
Member

I changed your patch slightly, so it integrated better with #8115 (as in, less diff). Names of functions, commands, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
candidate: yes This Pull Request is a candidate for being merged component: AI/Game script (squirrel) This issue is related to Squirrel (Scripting language) size: large This Pull Request is large in size; review will take a while
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants