Add: [Script] Basic information about loaded NewGRFs for scripts. #9464
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Currently, scripts use various heuristics to detect loaded NewGRFs that are inherently unreliable and prone to break.
At the same time, the list of loaded NewGRFs is easily accessible to a human player. Thus, giving scripts the same basic information is consistent with the approach to not give scripts any information advantage over a human player.
Description
This PR allows AIs and GS to get the most basic information about loaded NewGRFs. Static NewGRFs are hidden from scripts.
Right now there are no APIs that would allow a script to get more insight into what a NewGRF actually provides and changes (which matches the human experience).
Whether any other information should be exposed to scripts is up for discussion.
Limitations
The implementation is quite inefficient as the active NewGRF config is only kept in a non-indexable linked list.
Also, there is no way for a script to be informed about changes to loaded NewGRFs after game start.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.