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

Open
wants to merge 9 commits into
base: master
from

Conversation

@nielsmh
Copy link
Contributor

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

James103 commented Jan 14, 2020

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.

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 force-pushed the nielsmh:gs-indcontrol branch from f15c37a to 9c08d3f Feb 7, 2020
@nielsmh nielsmh marked this pull request as ready for review Feb 8, 2020
@frosch123
Copy link
Member

frosch123 commented Feb 8, 2020

Please also update game_changelog.hpp

@SamuXarick
Copy link
Contributor

SamuXarick commented Feb 28, 2020

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

SamuXarick commented Feb 29, 2020

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

…ecrease but are not allowed to
@nielsmh nielsmh force-pushed the nielsmh:gs-indcontrol branch from 5bbcbb8 to 6977ea0 Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.