Request for GS api addition : GSCargo.GetCargoName
Moderator: OpenTTD Developers
Request for GS api addition : GSCargo.GetCargoName
Hello,
If it's possible,
I would like to request an API addition for class GSCargo.
Please add the following Static Public Member Function : static char * GetCargoName(CargoID cargo_type)
That function would returns : The cargo name (I mean, for example "Passangers") like it's defined in newGRF.
also it would be in plain user language (as ottd display to user, including falling back to English if not defined in GRF)
that mean for example getting "passeggeri" (italian) or "passagers" (french) strings according to user language.
note : this function behaves like GSCargo.GetCargoLabel, but gives cargo name for UI purpose.
Thank you,
hpfx.
If it's possible,
I would like to request an API addition for class GSCargo.
Please add the following Static Public Member Function : static char * GetCargoName(CargoID cargo_type)
That function would returns : The cargo name (I mean, for example "Passangers") like it's defined in newGRF.
also it would be in plain user language (as ottd display to user, including falling back to English if not defined in GRF)
that mean for example getting "passeggeri" (italian) or "passagers" (french) strings according to user language.
note : this function behaves like GSCargo.GetCargoLabel, but gives cargo name for UI purpose.
Thank you,
hpfx.
Re: Request for GS api addition : GSCargo.GetCargoName
What if the client in a multiplayer game has a different language than the server? This is possible after all.
Re: Request for GS api addition : GSCargo.GetCargoName
It's not as useful as you think :
- AI doesn't display anything to user : the console is not really part of the game for a player.
So who cares AI API get the function to display real cargo names ? (as API can display there label already).
- GS does already display cargo names, just like openttd : in your english.txt:
-> You need to move 100 Passengers to Paris
and in french.txt
-> Vous devez déplacer 100 passagers vers Paris
With GS code : assuming 0 is the passenger cargo, and 12 "Paris" town.
Check out this link, i use it a lot : http://wiki.openttd.org/OpenTTDDevBlack ... al_strings
edit: oh and btw it's funny you pickup the cargo example as this special string is missing in the doc
But you already know its name now.
So i think what you are asking exist already.
- AI doesn't display anything to user : the console is not really part of the game for a player.
So who cares AI API get the function to display real cargo names ? (as API can display there label already).
- GS does already display cargo names, just like openttd : in your english.txt:
Code: Select all
STR_CARNEED : You need to move {NUM} {CARGO_LIST} to {TOWN}.
and in french.txt
Code: Select all
STR_CARNEED : Vous devez déplacer {NUM} {CARGO_LIST} vers {TOWN}.
With GS code : assuming 0 is the passenger cargo, and 12 "Paris" town.
Code: Select all
GSText(GSText.STR_CARNEED, 100, 0, 12);
edit: oh and btw it's funny you pickup the cargo example as this special string is missing in the doc

But you already know its name now.
So i think what you are asking exist already.
Re: Request for GS api addition : GSCargo.GetCargoName
Indeed !krinn wrote:It's not as useful as you think :
- GS does already display cargo names, just like openttd : in your english.txt:With GS code : assuming 0 is the passenger cargo, and 12 "Paris" town.Code: Select all
STR_CARNEED : You need to move {NUM} {CARGO_LIST} to {TOWN}.
Code: Select all
GSText(GSText.STR_CARNEED, 100, 0, 12);
Yes, that's exactely what I was looking for,
I didn't think it was existing, by looking stuff from existing GS around here, some of them use cargo name hardcoded in language file, like this :
Code: Select all
STR_PASS : you must deliver {NUM} Passengers...
by seeing that (and after I did check API), I believed it was not build in... yet, I was wrong.
That feature is just great !
Thank you.
Re: Request for GS api addition : GSCargo.GetCargoName
Sorry,
it's not so easy...
{CARGO_LIST} does not give the name of the cargo, it gives something I don't understand :
for example : english.txt
with code :
you will get: id 7 = Passenger, Mail, Coal
while you can expect "Goods" for cargoid 7 (in temperate/sub-tropical/sub-arctic climate)
I don't know what this list does mean, but that can explain why it's called "cargo_list".
I took a look at documentation, {CARGO} need two parameters because it display cargo and unit ("950 tonnes of Coal " while I just need "Coal")
it's not so easy...
{CARGO_LIST} does not give the name of the cargo, it gives something I don't understand :
for example : english.txt
Code: Select all
STR_INFO : id {NUM} = {CARGO_LIST}
Code: Select all
GSText(GSText.STR_INFO,7,7);
while you can expect "Goods" for cargoid 7 (in temperate/sub-tropical/sub-arctic climate)
I don't know what this list does mean, but that can explain why it's called "cargo_list".
I took a look at documentation, {CARGO} need two parameters because it display cargo and unit ("950 tonnes of Coal " while I just need "Coal")
Re: Request for GS api addition : GSCargo.GetCargoName
Try {CARGO_TINY}, {CARGO_SHORT} or {CARGO_LONG} instead of {CARGO_LIST} (at least in OpenTTD's language files these are used, not sure whether they are all available for GS). Or give it 1 << 7 (a one left-shifted by 7, which is 1*(2^7) = 128) as a parameter instead of just the 7.
For {CARGO_LIST} the parameter apparently is a bitfield, so convert the number to binary to see which cargoes will be displayed. 7 is 111 in binary, so bits #0, #1 and #2 are 1 (they are counted from the right), which makes the game display the names of the cargoes with IDs 0, 1 and 2.
For {CARGO_LIST} the parameter apparently is a bitfield, so convert the number to binary to see which cargoes will be displayed. 7 is 111 in binary, so bits #0, #1 and #2 are 1 (they are counted from the right), which makes the game display the names of the cargoes with IDs 0, 1 and 2.
Re: Request for GS api addition : GSCargo.GetCargoName
No, these are all related to display quantity figures.3298 wrote:Try {CARGO_TINY}, {CARGO_SHORT} or {CARGO_LONG}
Only this worked (Thank to your remark):
Code: Select all
GSText(GSText.STR_STRANGETHING, cargoid, 1<<cargoid);
Also I have an issue with this implementation : I would like to convert this GSText into string (ok to loose colors or other formating feature)
That's just it's impossible to perform correct debugging without sending this text to "AI/GameScript debug" window.
Thank you.
Re: Request for GS api addition : GSCargo.GetCargoName
Well, you have the cargoid and the GetCargoLabel, it won't really kill you to log PASS instead of passengers 

Re: Request for GS api addition : GSCargo.GetCargoName
Well,krinn wrote:Well, you have the cargoid and the GetCargoLabel, it won't really kill you to log PASS instead of passengers
I like to check exactly,
if I had to rely on that
Code: Select all
GSText(GSText.STR_CARNEED, 100, 0, 12);
Instead of that you just log cargoid or cargolabel, you will have "100 PASS"... and you never see the bug in your code until you can display it in a proper way

But Ok, it's not possible, I have to live with it.
Re: Request for GS api addition : GSCargo.GetCargoName
The {CARGO_LIST} command is the right one you are looking for.
If you want to display a single cargo, you set the parameter to 1 << (cargo index).
An example can be found in Sillicon Valley:
https://dev.openttdcoop.org/projects/si ... n.nut#L322
https://dev.openttdcoop.org/projects/si ... ish.txt#L6
Oh, and don't hard code "7" for a specific cargo. The cargo indices are arbitrary numbers which change.
If you want to display a single cargo, you set the parameter to 1 << (cargo index).
An example can be found in Sillicon Valley:
https://dev.openttdcoop.org/projects/si ... n.nut#L322
https://dev.openttdcoop.org/projects/si ... ish.txt#L6
Oh, and don't hard code "7" for a specific cargo. The cargo indices are arbitrary numbers which change.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Re: Request for GS api addition : GSCargo.GetCargoName
Hi,
don't fear, I'm not going hardcode cargoid, I've seen that ECS, FIRS and base cargo each use their own id (for example WATR and FRUT have different id). that's good to remind to anyone, you right.
I understand now why last cargoid is 31 (1<<31).
Regards,
hpfx
Thank you.frosch wrote:The {CARGO_LIST} command is the right one you are looking for.
If you want to display a single cargo, you set the parameter to 1 << (cargo index).
An example can be found in Sillicon Valley:
https://dev.openttdcoop.org/projects/si ... n.nut#L322
https://dev.openttdcoop.org/projects/si ... ish.txt#L6
Oh, and don't hard code "7" for a specific cargo. The cargo indices are arbitrary numbers which change.
don't fear, I'm not going hardcode cargoid, I've seen that ECS, FIRS and base cargo each use their own id (for example WATR and FRUT have different id). that's good to remind to anyone, you right.
I understand now why last cargoid is 31 (1<<31).
Regards,
hpfx
Who is online
Users browsing this forum: No registered users and 15 guests