NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

TadeuszD wrote:and next merging it using another tools...
it's not that difficult... :p

anyway, you could try this: (untested)
[Edit: possibly cleaner version]
Attachments
nml_wagonspeedlimits2.diff
(462 Bytes) Downloaded 91 times
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

I have next questions:
When the callback bitmask_vehicle_info is called? Is it called every time when property bitmask_consist_info is used?
Can I use bitmask_consist_info to determine wagon's parameter? Or this property can be called only from leading engine? Is there any protection against recursive calls?

What I want to do... I have defined the wagon with three cargo subtypes available. I want to decrease wagon's max speed if combination of wagons in the train and their cargo subtype settings fulfills special conditions. It should be independent of other wagon speed limits.
Image
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

I found partial answer myself. ;)
TadeuszD wrote:Can I use bitmask_consist_info to determine wagon's parameter?
Yes, you can. But if you want to calculate bitmask_consist_info for whole train you should use PARENT scope in switch definition. See the example:

Code: Select all

switch(FEAT_TRAINS, PARENT, switch_wagon_speed, hasbit(bitmask_consist_info, VINFO_EXT_PASSENGER_WAGON) ) {
    1: return 160;
    return 125;
}
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch »

bitmask_vehicle_info is not called everytime the variable is accessed.

All vehicle callbacks which affect vehicle properties are called when the consist changes and serveral other triggers. The results are then cached, and not updated when the vehicle moves normally.

bitmask_vehicle_info is the first callback which is called. So after a consist is created/changed, the bitmask is computed for all vehicles in the consist. Any properties afterwards can thus refer to bitmask_consist_info. bitmask_vehicle_info otoh cannot refer to any properties that change via callbacks.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

NMLC r2095 and 5029. Unexpected chars at the begin and end of warning message:

Code: Select all

←[33m nmlc warning: "src\\constr-stages.pnml", line 101: Block 'switch_constr_anim_speed' is not referenced, ignoring.←[0m
Image
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

looks like escape sequences (colour changes?) to me. use a terminal that understands those :)
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 »

Yes, looks like the way we added colour to the warnings is not fool-proof. On terminals which don't understand it, they show up as these weired characters.
http://dev.openttdcoop.org/issues/5411
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

I'm using Windows command line shell... :lol:


And I have next problem. I'm not sure is this the real bug, but the result doesn't match to NML documentation... :roll:
In my house I defined:

Code: Select all

building_flags:             bitmask(HOUSE_FLAG_ANIMATE, HOUSE_FLAG_RANDOM_ANIMATION);
According to NML documentation the extra_callback_info1 argument in anim_next_frame callback should contains 32 random bits. In my opinion it doesn't work. I've checked many combination and extra_callback_info1 is always 0.
For example, this piece of code always returns 4:

Code: Select all

switch(FEAT_HOUSES, SELF, switch_anim_next_frame, STORE_TEMP(4, 1)) {
    return LOAD_TEMP(1);
}
and this piece of code always return 0...:

Code: Select all

switch(FEAT_HOUSES, SELF, switch_anim_next_frame, STORE_TEMP(extra_callback_info1, 1)) {
    return LOAD_TEMP(1);
}
Does this problem corresponds to http://dev.openttdcoop.org/issues/5294 ?
Image
User avatar
MinchinWeb
Traffic Manager
Traffic Manager
Posts: 225
Joined: 01 Feb 2011 12:41
Contact:

Re: NML - a Newgrf Meta Language

Post by MinchinWeb »

Yes, Windows command prompt doesn't like ANSI escape characters like the colours. You can use a library like Colorama to get coloured console output on Windows. And I think the only code you need to add at the start of your Python program is:

Code: Select all

from colorama import init
init()
and coloured output should work fine.
Alberta Town Names - 1500+ real names from 'Acme' to 'Zama City'
MinchinWeb's Random Town Name Generator - providing 2 million plus names...
WmDOT v13 - An AI that doubles as your highway department
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

be aware that due to an oddity in nfo, switches with only a "return" without any other decision targets are a special case, which returns the last accessed variable instead of whatever comes after "return". maybe that spoils your output.

so

Code: Select all

switch(1) {
  return 2;
}
actually returns "1", not "2"

use

Code: Select all

switch(1) {
  0: return 2;
  return 2;
}
instead
TadeuszD wrote: Does this problem corresponds to http://dev.openttdcoop.org/issues/5294 ?
unlikely
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

Eddi wrote:be aware that due to an oddity in nfo, switches with only a "return" without any other decision targets are a special case, which returns the last accessed variable instead of whatever comes after "return".
Thanks. Good to know...
But I tested many combination. For example, I expect that code below returns frame #0 with probability 75% (two random bits are tested, random bits should be refreshed every ~7.5 seconds (256 ticks)) but it always returns frame #1:

Code: Select all

property {
building_flags:         bitmask(HOUSE_FLAG_ANIMATE, HOUSE_FLAG_RANDOM_ANIMATION);
refresh_multiplier:     0;
...
}

switch(FEAT_HOUSES, SELF, switch_anim_next_frame, extra_callback_info1 & 0x03 != 0) {
    1: return 0;
    return 1;
}
Image
User avatar
WWTBAM
Moderator
Moderator
Posts: 3689
Joined: 02 Apr 2005 07:01
Location: Sydney NSW Antipodea
Contact:

Re: NML - a Newgrf Meta Language

Post by WWTBAM »

So I was going to look into resurrecting the NSW Bus Set. I tried using the attached files as a start using NML 2.3.x so as to have TTDP compatibility. The vehicle gets introduced in OpenTTD but not in TTDP. I was told NML 2.x was kept for TTDPatch compatibility. Ignore the errors regarding the sprites not showing up in game as that is not my primary concern unless they are causing TTDP to bork.
Attachments
NSWGBS.zip
(6.02 KiB) Downloaded 83 times
Formerly known as r0b0t_b0y2003, robotboy, roboboy and beclawat. The best place to get the most recent nightly builds of TTDPatch is: http://roboboy.users.tt-forums.net/TTDPatch/nightlies/
User avatar
WWTBAM
Moderator
Moderator
Posts: 3689
Joined: 02 Apr 2005 07:01
Location: Sydney NSW Antipodea
Contact:

Re: NML - a Newgrf Meta Language

Post by WWTBAM »

Here is the NFO equivalent of the NML in the zip in my last post except using a byte-size ID instead of word-size. It also has issues in both OpenTTD and TTDPatch - no vehicle appears in either game with no grfcodec errors or errors from the game.
Attachments
main.nfo
(1012 Bytes) Downloaded 79 times
Formerly known as r0b0t_b0y2003, robotboy, roboboy and beclawat. The best place to get the most recent nightly builds of TTDPatch is: http://roboboy.users.tt-forums.net/TTDPatch/nightlies/
Rodney7790
Engineer
Engineer
Posts: 26
Joined: 28 Dec 2012 19:56
Location: CZ

Re: NML - a Newgrf Meta Language

Post by Rodney7790 »

Hello, while finishing my second set, strange problem has appeared. In my first set, adding sounds was easy by this part of code:

Code: Select all

switch(FEAT_TRAINS, SELF, sound_169 , extra_callback_info1) {
    SOUND_EVENT_START: return sound("snds/start.wav");
	SOUND_EVENT_TUNNEL: return sound("snds/houkacka.wav");
    return CB_RESULT_NO_SOUND;
}
.
.
.
graphics {
.....
		sound_effect:			sound_169;
    }
Now I have copied the same to my second set and it doesn't make any sound. I have used the same sounds. Can anyone help me? Thank you.
Trond
Tycoon
Tycoon
Posts: 973
Joined: 25 Jan 2008 07:32
Location: Gamle Ørnenuten

Re: NML - a Newgrf Meta Language

Post by Trond »

Is it in a new folder? If it is, did you remember to copy the soundfiles to the new folder?
..: Trond :.. because you deserve it! Image

The whole problem with the world is that fools and fanatics are always so certain of themselves,
and wiser people so full of doubts.
Bertrand Russell

MyGRFs: Norwegian Funny Town Names 4 | LOTR & WoW Town Names 2 | Islandic Town Names 1 | Random Norwegian Town Names
Favorites: GRFCrawler | ISR | WIKI | Now Playing: OpenTTD 1.3.2 w/YAPP 3.0-RC3.9ish
Rodney7790
Engineer
Engineer
Posts: 26
Joined: 28 Dec 2012 19:56
Location: CZ

Re: NML - a Newgrf Meta Language

Post by Rodney7790 »

Yes, I have copied files to folder of new set. The GRF file is much bigger than before. But it doesn't do any sound in game.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

two things:

are you sure you modified the vehicle id in the "item" statement after copying)

and if you reuse the same sounds, just put the same switch id there, no need to duplicate the sounds.
Trond
Tycoon
Tycoon
Posts: 973
Joined: 25 Jan 2008 07:32
Location: Gamle Ørnenuten

Re: NML - a Newgrf Meta Language

Post by Trond »

So, there is no support for norwegian letters with NML? I get an error when trying to encode with a languagefile containing the norwegian letter 'å'... When I remove the 'å', it encodes fine...
..: Trond :.. because you deserve it! Image

The whole problem with the world is that fools and fanatics are always so certain of themselves,
and wiser people so full of doubts.
Bertrand Russell

MyGRFs: Norwegian Funny Town Names 4 | LOTR & WoW Town Names 2 | Islandic Town Names 1 | Random Norwegian Town Names
Favorites: GRFCrawler | ISR | WIKI | Now Playing: OpenTTD 1.3.2 w/YAPP 3.0-RC3.9ish
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 »

Trond wrote:So, there is no support for norwegian letters with NML? I get an error when trying to encode with a languagefile containing the norwegian letter 'å'... When I remove the 'å', it encodes fine...
There is support for virtually every letter. Required encoding for all text files is UTF-8, you likely use something else; check with your editor settings.
Trond
Tycoon
Tycoon
Posts: 973
Joined: 25 Jan 2008 07:32
Location: Gamle Ørnenuten

Re: NML - a Newgrf Meta Language

Post by Trond »

Seems the file I downloaded was "UTF-8 without BOM" or something like that. When I changed it in Notepad++ to UTF-8 it worked fine...
..: Trond :.. because you deserve it! Image

The whole problem with the world is that fools and fanatics are always so certain of themselves,
and wiser people so full of doubts.
Bertrand Russell

MyGRFs: Norwegian Funny Town Names 4 | LOTR & WoW Town Names 2 | Islandic Town Names 1 | Random Norwegian Town Names
Favorites: GRFCrawler | ISR | WIKI | Now Playing: OpenTTD 1.3.2 w/YAPP 3.0-RC3.9ish
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 23 guests