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

The human-readable name of a cargo type can't be queried by AI/GS. #7869

Open
James103 opened this issue Dec 22, 2019 · 2 comments
Open

The human-readable name of a cargo type can't be queried by AI/GS. #7869

James103 opened this issue Dec 22, 2019 · 2 comments

Comments

@James103
Copy link
Contributor

@James103 James103 commented Dec 22, 2019

Version of OpenTTD

20191207-master-win32

Expected result

You can get the human-readable name of a cargo type by itself, via a method such as ScriptCargo::GetName(cargo_type). For example: ScriptCargo.GetName(0) would return Passengers in vanilla (no NewGRF) games.

Actual result

You are unable to get the human-readable name of a cargo type by itself (there is no way to get it except in the form "X units of Y", and even then it's restricted to output displays only.

Reasoning

The reasoning behind this is so you can make log output and other AI/GS-controllable displays more human-readable and go from something like this: PASS from Town A to Town B to this:
Passengers from Town A to Town B without having to store a mapping of cargo label to cargo name, which has its own sorts of problems including such a mapping quickly becoming outdated.

@ldpl
Copy link
Contributor

@ldpl ldpl commented Jan 6, 2020

There is {CARGO_LIST} and you can use it to show a single cargo type as well.
As for GetName it's unclear what locale should it use and even if you get cargo name it's of no use since you can't show arbitrary strings.

@James103
Copy link
Contributor Author

@James103 James103 commented Jan 7, 2020

  1. Note that {CARGO_LIST} takes a bitmask of which cargoes to display. To show only a single cargo, you should pass it a value of the form 1 << N, where N is the one-based index of the cargo ID to use (different from the zero-based index of other IDs). For cargo IDs higher than 32, this could truncate.
  2. Some output displays (such as log output or setting a name of a group/town/vehicle/etc.) only accept raw strings, which means if you wanted to show a cargo name inside the group name (think SimpleAI), there would still be a reason to use ScriptCargo.GetName(cargo_id).
  3. The locale that should be used for getting the cargo name via ScriptCargo.GetName(cargo_id) should be the same locale as that used to get the engine name (ScriptEngine.GetName(...), or the industry name (ScriptIndustry.GetName(...)), or etc (the locale/language of the host server).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.