NML - a Newgrf Meta Language

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

How can I set property 00 before property 2A in NML for trains?

I need the introduction date of the train without randomize it. Can I do this?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

akasoft wrote:How can I set property 00 before property 2A in NML for trains?

I need the introduction date of the train without randomize it. Can I do this?
By design, you can't, neither in nfo nor nml. Randomization always happens, except in the first two years after the game was started.

Using long or short introduction date has no influence there neither. Property 2A (long introduction date) deprecated property 00 (short introduction date). Using the long introduction date in the range between 1920 to 2044 behaves identical to just using the short introduction date. NML thus always uses the long vehicle introduction date.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

The only reason to use the short introduction date would be to support TTDPatch before 2.5 r1210. Since support for TTDPatch is almost completely untested and non-existent in a few other places I'm not going to add support for it unless someone is going to test support for TTDPatch extensively and report what exactly works and what doesn't.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

What about support NewGRF v8 (r23159) in NML?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

akasoft wrote:What about support NewGRF v8 (r23159) in NML?
Certainly. But after 0.2 has been released.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

If I forget to use utf-8 with Cyrillic and use windows-1251 instead of it, I receive error:
nmlc: An internal error has occurred:
nmlc-version: r68M (4453c155361b)
Error: (UnicodeDecodeError) "'utf8' codec can't decode byte 0xee in position 3928: invalid continuation byte".
Command: ['nmlc', '--nfo=xussr.nfo', '--grf=xussr.grf', '--nml=xussr_optimized.nml', '-M', '--MF=xussr_dep.txt', 'xussr.nml']
Location: File "C:\Python27\lib\codecs.py", line 477, in read
(Used wrong encoding, need utf-8 instead of it.)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Can NML support string control code "01 X offset in next byte of string (variable space)"? This is useful for the name of vehicle.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

In source of opengfx+ trains I found this code:

Code: Select all

...
item(FEAT_TRAINS, turbotrain, 20) {
...
	graphics {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_engine_reversal_switch;
	}
	livery_override (passenger_wagon) {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_passenger_reversal_switch;
	}
	livery_override (mail_wagon)      {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_mail_reversal_switch;
	}
...
What is mean? We can change shorten_vehicle in livery_override block separately for selected vehicle ID? Specified value is for passenger_wagon or for turbotrain? And we can change shorten_vehicle in graphics block? Or this bug and so do not?
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

It's not a property, it's a callback. And yes, if you have a livery_override block you should copy all callbacks for the attaching vehicle to there. The first "shorten_vehicle" (in the graphics block) is for the turbotrain, the second oen for the passenger wagon when it's attached to the turbotrain, and the 3rd one for the mail wagon when it's attached to the turbotrain.
akasoft wrote:Can NML support string control code "01 X offset in next byte of string (variable space)"? This is useful for the name of vehicle.
Is this really necesary? Doesn't OpenTTD automatically align the names of vehicles next to the sprites?
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NML - a Newgrf Meta Language

Post by planetmaker »

akasoft wrote:In source of opengfx+ trains I found this code:

Code: Select all

...
item(FEAT_TRAINS, turbotrain, 20) {
...
	graphics {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_engine_reversal_switch;
	}
	livery_override (passenger_wagon) {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_passenger_reversal_switch;
	}
	livery_override (mail_wagon)      {
		shorten_vehicle:        return SHORTEN_TO_7_8;
		turbotrain_mail_reversal_switch;
	}
...
What is mean? We can change shorten_vehicle in livery_override block separately for selected vehicle ID? Specified value is for passenger_wagon or for turbotrain? And we can change shorten_vehicle in graphics block? Or this bug and so do not?
It's the preferred way to use callbacks. See http://newgrf-specs.tt-wiki.net/wiki/NM ... hics_block and http://newgrf-specs.tt-wiki.net/wiki/NM ... _callbacks
Of course callbacks are vehicle-specific, in this case they only apply when the quoted livery-override is active for the wagons.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

Yexo wrote:
akasoft wrote:Can NML support string control code "01 X offset in next byte of string (variable space)"? This is useful for the name of vehicle.
Is this really necesary? Doesn't OpenTTD automatically align the names of vehicles next to the sprites?
last time i looked, nothing of that sort was implemented, buy menu had a fixed offset.

IMHO the GRF should set a "generic" property about the width of the buy menu sprites it would like (per vehicle type?), and the game should take the maximum over all GRFs.

"X offset" is generally a bad thing, especially with automatically scaling GUIs, and i think OpenTTD actually ignores that. we had a very lengthy debate about this previously.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Eddi wrote: last time i looked, nothing of that sort was implemented, buy menu had a fixed offset.
This string control code is used in 2cc trainset and look nice.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

akasoft wrote:
Eddi wrote: last time i looked, nothing of that sort was implemented, buy menu had a fixed offset.
This string control code is used in 2cc trainset and look nice.
the problem here is that the string is used in other places as well, which might not want to use such an offset.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Can I in NML get the current train property 21 (shorten_vehicle) via variable?
(And then use it in selection of spriteset.)
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

according to TTD-locations this is variable 0x80+0x73 (=0xF3), so if nml does not yet have a variable name for this, you should be able to access this by "var[0xF3, 0, 0xFF]"
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Eddi, thanks. I was confused by prefix "[TTDPatch]".
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

if in doubt, doublecheck with src/newgrf_engine.cpp:

Code: Select all

                          case 0x73: return t->gcache.cached_veh_length;
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: NML - a Newgrf Meta Language

Post by Michi_cc »

Eddi wrote:if in doubt, doublecheck with src/newgrf_engine.cpp:

Code: Select all

                          case 0x73: return t->gcache.cached_veh_length;
Hmm, either this line is an OpenTTD bug or it is a documentation bug. I would read "how much shorter the wagon is" as the value passed to prop 21 (i.e. that many lu shorten than normal), while OpenTTD stores the length and not the shorten factor in cached_veh_length.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Re: NML - a Newgrf Meta Language

Post by DaleStan »

TTDPatch source code says

Code: Select all

	.shortened:		// 73h:how much shorter is the wagon (+0x80)
Usage in loadunl.asm seems to match this documentation. It looks to me like the high bit is used for TTDPatch internal record-keeping and is always set in contexts where GRFs could see the information.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 27 guests