Add field on vehicle window

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Add field on vehicle window

Post by sky81 »

I'm trying to add a filed like: "Type: Steam" inside a vehicle window(were are display Cost , weight etc).
I cannot figure out how to do it. Is it possible to add it for only one vehicle, like the name of the bus
Example: 04 01 7F 01 "NAME" 00 ?
michael blunck
Tycoon
Tycoon
Posts: 5909
Joined: 27 Apr 2005 07:09
Contact:

Re: Add field on vehicle window

Post by michael blunck »

You would do this by callback 23 (additional text in menu).

regards
Michael
Image
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

Do you have an example how to use callback 23, because it's difficult to understand how to do this in nfo?

Thanks
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

I saw some grf's that have set this via Action4. Like this one:
3 * 254 04 00 FF 04 00 D0 98 "Manufactuerer: " 8A "Bombardier "
"Transportation " 0D 98 "Model Name: " 8A "Type-S "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-PT Tram" 00 98 "Manufactuerer: "
8A "Siemens Duewag " 0D 98 "Model Name: " 8A "Type-O "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-K Tram" 00

But I cannot figure out why is not working in mygrf. I think there is something more that I should write somewhere but I don't know what
For each vehicle I have 3 action2 sprites and one actio3
I'm pretty sure that the last action2 refer to what I want to change
246 * 43 02 01 FB 89 10 00 FF 00 00 00 03 FF 00 09 00 00 00 09 00 00 00 FC 00 0F 00 00 00 0F 00 00 00 00
00 23 00 00 00 23 00 00 00 FE 00
247 * 33 02 01 FF 89 10 00 FF 00 00 00 02 FF 00 09 00 00 00 09 00 00 00 FA 00 0F 00 00 00 0F 00 00 00 FE
00
248 * 43 02 01 FB 89 0C 00 FF FF 00 00 03 FC 00 15 00 00 00 15 00 00 00 FD 00 16 00 00 00 16 00 00 00 FB
00 36 00 00 00 36 00 00 00 FE 00
249 * 53 02 01 FE 89 0C 00 FF FF 00 00 04 FA 00 00 00 00 00 00 00 00 00 FD 00 16 00 00 00 16 00 00 00 03
80 23 00 00 00 23 00 00 00 FF 00 36 00 00 00 36 00 00 00 FE 00
250 * 12 03 01 01 FF 5C 00 01 FF FE 00 FB 00

But when I copy sprites 249 and 250 nothing happens .
P.S. I change the ID in action3 from 5C to my vehicle ID.

I try also deleting last to bytes from Action3 (the FB 00). still nothing
Last edited by sky81 on 12 Mar 2021 13:34, edited 1 time in total.
Eddi
Tycoon
Tycoon
Posts: 7627
Joined: 17 Jan 2007 00:14

Re: Add field on vehicle window

Post by Eddi »

here's an excerpt from my (NML) code, not a particularly simple example (using the "text stack"):

Code: Select all

switch(FEAT_TRAINS, SELF, text_switch_default,
  [STORE_TEMP(string(STR_AUTO_10) | string(STR_USAGE_CARGO) << 16, 0x100),
   STORE_TEMP(string(STR_TRACK_TYPES_DEFAULT) | string(STR_TRACK_TYPE_N) << 16, 0x101),
   0])
{
 return string(STR_ENG_DESCRIPTION);
}

item(FEAT_TRAINS, [...]) {
 graphics {
  additional_text: text_switch_default;
}

Code: Select all

STR_ENG_DESCRIPTION     :{BLACK}Axle Scheme: {GOLD}{STRING}{BLACK} Use: {GOLD}{STRING}{BLACK}{}Track Class: {GOLD}{STRING}{BLACK}
STR_AUTO_10             :2'2'
STR_USAGE_CARGO         :Freight
STR_TRACK_TYPES_DEFAULT :{STRING}
STR_TRACK_TYPE_N        :{GREEN}unelectrified{ORANGE}
You might not exactly be interested in Ferion, but if you are, have fun :)
michael blunck
Tycoon
Tycoon
Posts: 5909
Joined: 27 Apr 2005 07:09
Contact:

Re: Add field on vehicle window

Post by michael blunck »

sky81 wrote: 12 Mar 2021 12:22 I saw some grf's that have set this via Action4. Like this one:
3 * 254 04 00 FF 04 00 D0 98 "Manufactuerer: " 8A "Bombardier "
"Transportation " 0D 98 "Model Name: " 8A "Type-S "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-PT Tram" 00 98 "Manufactuerer: "
8A "Siemens Duewag " 0D 98 "Model Name: " 8A "Type-O "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-K Tram" 00

But I cannot figure out why is not working in mygrf. I think there is something more that I should write somewhere but I don't know what
The action 4 above sets the text strings for IDs following ID "D0 00". You have to simply address those IDs in your callback 23. C'est ça.

regards
Michael
Image
Eddi
Tycoon
Tycoon
Posts: 7627
Joined: 17 Jan 2007 00:14

Re: Add field on vehicle window

Post by Eddi »

the NFO code resulting from my code looks something like this:

Code: Select all

[imagine some action4 here]

// Name: text_switch_default
3144 * 109 02 00 B7 89 
1A 20 \dx0000D0A2 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000080 
\2r 1A 20 \dx0000D00A 
\2| 7D 80 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000100 
\2r 1A 20 \dx0000D0A0 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000081 
\2r 1A 20 \dx0000D0A1 
\2| 7D 81 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000101 
\2r 1A 00 \dx00000000 
\b1 
\wx8000 \dx00000001 \dx00000000 	// Bogus range to avoid nvar == 0
\wx809E // default: return string(STR_ENG_DESCRIPTION);


// Name: @action3_11
3153 * 43 02 00 B9 89 
0C 00 \dx0000FFFF 
\b3 
\wx00BA \dx00000000 \dx00000000 	// gfx_switch_purchase;
\wx00B7 \dx00000023 \dx00000023 	// text_switch_default;
\wx00BB \dx00000036 \dx00000036 	// @action3_9;
\wx00B9 // gfx_switch;
You might not exactly be interested in Ferion, but if you are, have fun :)
michael blunck
Tycoon
Tycoon
Posts: 5909
Joined: 27 Apr 2005 07:09
Contact:

Re: Add field on vehicle window

Post by michael blunck »

Eddi wrote: 12 Mar 2021 12:52 the NFO code resulting from my code looks something like this:

Code: Select all

[imagine some action4 here]

// Name: text_switch_default
3144 * 109 02 00 B7 89 
1A 20 \dx0000D0A2 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000080 
\2r 1A 20 \dx0000D00A 
\2| 7D 80 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000100 
\2r 1A 20 \dx0000D0A0 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000081 
\2r 1A 20 \dx0000D0A1 
\2| 7D 81 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000101 
\2r 1A 00 \dx00000000 
\b1 
\wx8000 \dx00000001 \dx00000000 	// Bogus range to avoid nvar == 0
\wx809E // default: return string(STR_ENG_DESCRIPTION);


// Name: @action3_11
3153 * 43 02 00 B9 89 
0C 00 \dx0000FFFF 
\b3 
\wx00BA \dx00000000 \dx00000000 	// gfx_switch_purchase;
\wx00B7 \dx00000023 \dx00000023 	// text_switch_default;
\wx00BB \dx00000036 \dx00000036 	// @action3_9;
\wx00B9 // gfx_switch;
Wow! 8)
Image
Eddi
Tycoon
Tycoon
Posts: 7627
Joined: 17 Jan 2007 00:14

Re: Add field on vehicle window

Post by Eddi »

michael blunck wrote: 12 Mar 2021 12:55 Wow! 8)
well, it's not like i did anything there. that's just the output of NMLC...

the "text stack" is awkward anyway, because it's not actually a "stack" (it has no "push" operation. you have to manually store values at the correct locations)
You might not exactly be interested in Ferion, but if you are, have fun :)
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

michael blunck wrote: 12 Mar 2021 12:51
sky81 wrote: 12 Mar 2021 12:22 I saw some grf's that have set this via Action4. Like this one:
3 * 254 04 00 FF 04 00 D0 98 "Manufactuerer: " 8A "Bombardier "
"Transportation " 0D 98 "Model Name: " 8A "Type-S "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-PT Tram" 00 98 "Manufactuerer: "
8A "Siemens Duewag " 0D 98 "Model Name: " 8A "Type-O "
"Tram" 00 98 "Manufactuerer: " 8A "Siemens Duewag "
0D 98 "Model Name: " 8A "Type-K Tram" 00

But I cannot figure out why is not working in mygrf. I think there is something more that I should write somewhere but I don't know what
The action 4 above sets the text strings for IDs following ID "D0 00". You have to simply address those IDs in your callback 23. C'est ça.

regards
Michael
Yes. This is what I have to do. The problem is I don't know how
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

michael blunck wrote: 12 Mar 2021 12:55
Eddi wrote: 12 Mar 2021 12:52 the NFO code resulting from my code looks something like this:

Code: Select all

[imagine some action4 here]

// Name: text_switch_default
3144 * 109 02 00 B7 89 
1A 20 \dx0000D0A2 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000080 
\2r 1A 20 \dx0000D00A 
\2| 7D 80 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000100 
\2r 1A 20 \dx0000D0A0 
\2<< 1A 20 \dx00000010 
\2sto 1A 20 \dx00000081 
\2r 1A 20 \dx0000D0A1 
\2| 7D 81 20 \dxFFFFFFFF 
\2sto 1A 20 \dx00000101 
\2r 1A 00 \dx00000000 
\b1 
\wx8000 \dx00000001 \dx00000000 	// Bogus range to avoid nvar == 0
\wx809E // default: return string(STR_ENG_DESCRIPTION);


// Name: @action3_11
3153 * 43 02 00 B9 89 
0C 00 \dx0000FFFF 
\b3 
\wx00BA \dx00000000 \dx00000000 	// gfx_switch_purchase;
\wx00B7 \dx00000023 \dx00000023 	// text_switch_default;
\wx00BB \dx00000036 \dx00000036 	// @action3_9;
\wx00B9 // gfx_switch;
Wow! 8)
Pff.... Now I'm really lost :)
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

For each vehicle I have 3 action2 sprites and one actio3
I'm pretty sure that the last action2 refer to what I want to change
246 * 43 02 01 FB 89 10 00 FF 00 00 00 03 FF 00 09 00 00 00 09 00 00 00 FC 00 0F 00 00 00 0F 00 00 00 00
00 23 00 00 00 23 00 00 00 FE 00
247 * 33 02 01 FF 89 10 00 FF 00 00 00 02 FF 00 09 00 00 00 09 00 00 00 FA 00 0F 00 00 00 0F 00 00 00 FE
00
248 * 43 02 01 FB 89 0C 00 FF FF 00 00 03 FC 00 15 00 00 00 15 00 00 00 FD 00 16 00 00 00 16 00 00 00 FB
00 36 00 00 00 36 00 00 00 FE 00
249 * 53 02 01 FE 89 0C 00 FF FF 00 00 04 FA 00 00 00 00 00 00 00 00 00 FD 00 16 00 00 00 16 00 00 00 03
80 23 00 00 00 23 00 00 00 FF 00 36 00 00 00 36 00 00 00 FE 00
250 * 12 03 01 01 FF 5C 00 01 FF FE 00 FB 00

But when I copy sprites 249 and 250 nothing happens .
P.S. I change the ID in action3 from 5C to my vehicle ID.

I try also deleting last to bytes from Action3 (the FB 00). still nothing
michael blunck
Tycoon
Tycoon
Posts: 5909
Joined: 27 Apr 2005 07:09
Contact:

Re: Add field on vehicle window

Post by michael blunck »

Small example m4nfo -> nfo:

Code: Select all

define(TAL_HIGH1, 0×200) // O 'Breslau' 1913

defgrftext(TAL_HIGH1, ALL,
T_BLACK _TYPE T_LORANGE "Breslau" CRLF
T_BLACK _WEIGHT T_LORANGE "22t" CRLF
T_BLACK _VOLUME T_LORANGE "28 m" B3 CRLF
T_BLACK _AVAIL T_LORANGE "1913 - 1935" CRLF
T_BLACK _LIFE T_LORANGE "40" _YEARS CRLF
CRLF T_LGREEN _REFIT
CRLF T_BLACK _DBXL09,
...
)

->

25 * 0 04 00 FF 33 00 d2
98 81 70 d4 8A "Breslau" 0d
98 81 71 d4 8A "22 t" 0d
98 81 72 d4 8A "28 m" B3 0d
98 81 73 d4 8A "1913 - 1935" 0d
98 81 74 d4 8A "40" 81 75 d4 0d
0d 91 81 77 d4
0d 98 81 7e d4 00
...

def(4) callback(
    grftext(TAL_HIGH1) if(CB_TEXT)
    ref(3) else
)

->

838 * 0 02 00 04  85 0C 00 FF FF 01
    00 82  23 00 23 00
    00 03
Note that for text IDs you have to give a callback result in callback 23, i.e. for ID "0x200"  0x8200 (00 82).

regards
Michael
Image
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

michael blunck wrote: 12 Mar 2021 13:49 Small example m4nfo -> nfo:

Code: Select all

define(TAL_HIGH1, 0×200) // O 'Breslau' 1913

defgrftext(TAL_HIGH1, ALL,
T_BLACK _TYPE T_LORANGE "Breslau" CRLF
T_BLACK _WEIGHT T_LORANGE "22t" CRLF
T_BLACK _VOLUME T_LORANGE "28 m" B3 CRLF
T_BLACK _AVAIL T_LORANGE "1913 - 1935" CRLF
T_BLACK _LIFE T_LORANGE "40" _YEARS CRLF
CRLF T_LGREEN _REFIT
CRLF T_BLACK _DBXL09,
...
)

->

25 * 0 04 00 FF 33 00 d2
98 81 70 d4 8A "Breslau" 0d
98 81 71 d4 8A "22 t" 0d
98 81 72 d4 8A "28 m" B3 0d
98 81 73 d4 8A "1913 - 1935" 0d
98 81 74 d4 8A "40" 81 75 d4 0d
0d 91 81 77 d4
0d 98 81 7e d4 00
...

def(4) callback(
    grftext(TAL_HIGH1) if(CB_TEXT)
    ref(3) else
)

->

838 * 0 02 00 04  85 0C 00 FF FF 01
    00 82  23 00 23 00
    00 03
Note that for text IDs you have to give a callback result in callback 23, i.e. for ID "0x200"  0x8200 (00 82).

regards
Michael
Thank you for your time and support. I try your code, also found some other code but still not appear. After I chaange something in Action3 like added ID of this action2, only then it worked, but not like I was expected. It changed also my picture of the trolley. It is something that I'm missing but I don't know what.
If I use action04 and action2 like you suggested (without action3) should work? As far as I read about action3 is just mapping action0 vehicle id with some cargo define at action2 and also some graphics define at action 2, but I cannot figure out what to do.
Here is a pat of the code:
76 * 1 00
77 * 9 02 01 AA 01 01 00 00 00 00
78 * 9 02 01 DD 01 01 01 00 01 00
79 * 14 02 01 01 81 10 00 FF 01 49 80 01 01 AA 00
80 * 14 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
82 * 10 03 01 01 44 01 FF DD 00 03 00
So after Sprite 8 I added somethink like this:
81 * 53 02 01 FC 89 0C 00 FF FF 00 00 04 FA 00 00 00 00 00 00 00 00 00 FD 00 16 00 00 00 16 00 00 00 00
80 23 00 00 00 23 00 00 00 FE 00 36 00 00 00 36 00 00 00 FC 00
When I reffer in action I replace DD with FC (id of the action 2 that I added). then it worked but my trolley changed it's picture
michael blunck
Tycoon
Tycoon
Posts: 5909
Joined: 27 Apr 2005 07:09
Contact:

Re: Add field on vehicle window

Post by michael blunck »

Ah, you didn't mention that you're on cargo culting.

In fact, Eddi and me only showed code snippets illustrating use of callback 23 for extra text in purchase menu.

We didn't provide a complete grf, in no way. I.e., o/c you need proper action 0 and action 3 as well.

regards
Michael
Image
Eddi
Tycoon
Tycoon
Posts: 7627
Joined: 17 Jan 2007 00:14

Re: Add field on vehicle window

Post by Eddi »

no, you should not change your action 3. you need to look for the line that checks the "callback" variable, it should be this one in your code snippet:
sky81 wrote: 14 Mar 2021 19:12 80 * 14 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
there you need to add another case, checking for callback 23.
You might not exactly be interested in Ferion, but if you are, have fun :)
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

Eddi wrote: 14 Mar 2021 20:01 no, you should not change your action 3. you need to look for the line that checks the "callback" variable, it should be this one in your code snippet:
sky81 wrote: 14 Mar 2021 19:12 80 * 14 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
there you need to add another case, checking for callback 23.
OK. I'm not very familiar with case. Shold it be something like this:
* 20 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00 00 80 23 00 02 00 ?
I try also like this with no luck:
* 22 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00 00 80 23 00 23 00 02 00 ?
I undestant the 00 80 means first item inside action4 block that I define earlier. 02 00 don't know what it means.
Anyway, does not show any additional text with the combination above. Any ideeas?

P/S. I let action3 like it was before:
82 * 10 03 01 01 44 01 FF DD 00 03 00

Thanks for your help
Eddi
Tycoon
Tycoon
Posts: 7627
Joined: 17 Jan 2007 00:14

Re: Add field on vehicle window

Post by Eddi »

sky81 wrote: 14 Mar 2021 20:10 OK. I'm not very familiar with case.
ok. step backwards for a minute. excercise for you:

take this line

Code: Select all

80 * 14	 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
and comment each byte with it's meaning like this:

Code: Select all

80 * 14 // number and length
02 // action 2
01 // feature 1
...
use this page for reference:
https://newgrf-specs.tt-wiki.net/wiki/V ... on2#Format
You might not exactly be interested in Ferion, but if you are, have fun :)
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

Eddi wrote: 14 Mar 2021 22:52
sky81 wrote: 14 Mar 2021 20:10 OK. I'm not very familiar with case.
ok. step backwards for a minute. excercise for you:

take this line

Code: Select all

80 * 14	 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
and comment each byte with it's meaning like this:

Code: Select all

80 * 14 // number and length
02 // action 2
01 // feature 1
...
use this page for reference:
https://newgrf-specs.tt-wiki.net/wiki/V ... on2#Format
I looked on the wiki bt I do not understant all the data there. Here is what in uderstood:
80 * 14 // number and length
02 // action 2
01 // feature 1
03 - ID of Action2, to be used in action 03 if neccesarry
81 - I guess it's refering what to access from the callback parameter (example for callback 33 , has a param of 01 00 access 00)
0C - callback
00 FF 01-I'm lost
01 00 - the call back parater or return (I saw that if I set for example 01 80 in callback 23, it will write the 2nd data from action04 string - because of that 01)
33 33 - I guess this is the call back (although I was expected 33 00)
0A 00 - I'm lost

Any help will be appreciated.
Thanks
sky81
Engineer
Engineer
Posts: 32
Joined: 29 Oct 2019 05:49

Re: Add field on vehicle window

Post by sky81 »

sky81 wrote: 15 Mar 2021 06:09
Eddi wrote: 14 Mar 2021 22:52
sky81 wrote: 14 Mar 2021 20:10 OK. I'm not very familiar with case.
ok. step backwards for a minute. excercise for you:

take this line

Code: Select all

80 * 14	 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
and comment each byte with it's meaning like this:

Code: Select all

80 * 14 // number and length
02 // action 2
01 // feature 1
...
use this page for reference:
https://newgrf-specs.tt-wiki.net/wiki/V ... on2#Format
I looked on the wiki bt I do not understant all the data there. Here is what in uderstood:
80 * 14 // number and length
02 // action 2
01 // feature 1
03 - ID of Action2, to be used in action 03 if neccesarry
81 - I guess it's refering what to access from the callback parameter (example for callback 33 , has a param of 01 00 access 00)
0C - callback
00 FF 01-I'm lost
01 00 - the call back parater or return (I saw that if I set for example 01 80 in callback 23, it will write the 2nd data from action04 string - because of that 01)
33 33 - I guess this is the call back (although I was expected 33 00)
0A 00 - I'm lost

Any help will be appreciated.
Thanks
I figure out the action2 command but I cannot integrated in Action3.
If I append the command like this:
02 01 03 81 0C 00 FF 01 02 00 33 33 AA 00
00 80 23 23 FE 00
then the text will not appear.
The text appear if I set in Action3 the ID of this text after the action0 ID, like this:
* 10 03 01 01 44 01 FF 03 00 03 00
But I cannot do that because this alterates the graphic picture of the bus.

So the solution is to make another Action2 variaation with same ID like the grapfics: DD
something like this:
188 * 1 00
189 * 9 02 01 AA 01 01 00 00 00 00
190 * 9 02 01 DD 01 01 01 00 01 00
191 * 14 02 01 01 81 10 00 FF 01 49 80 01 01 AA 00
192 * 14 02 01 03 81 0C 00 FF 01 01 00 33 33 AA 00
193 * 14 02 01 DD 81 0C 00 FF 01 00 80 23 23 FE 00
194 * 10 03 01 01 44 01 FF DD 00 03 00
But the picture that appear in the buying window is not the one from Sprit 190 or sprit 189.
Like is ignoring Sprit 189,190.
This happens only if I inserted line 193.

Any ideeas?
Last edited by sky81 on 15 Mar 2021 09:17, edited 1 time in total.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 6 guests