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: 8258
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

TadeuszD wrote:Why the first version of my code didn't work?
that's a very good question that needs investigation, however, try this code:

Code: Select all

cargo_palette = reserve_sprites(2);
replace(cargo_palette) {
        recolour_sprite {
        0xAA: 0x01;
        ...
        }
        recolour_sprite {
        0xAA: 0x40;
        ...
        }
}
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Separate from that your code doesn't work, I'm getting the idea that it's better to reserve sprites one at a time.

According to the NewGRF specs, your grf will be deactivated if the system can't reserve a contiguous block of sprites. From what I understand, when reserving one at a time you can reserve sprites from multiple non-contiguous blocks. In some cases you may be required to use a contiguous block, but in this case of translation tables you don't.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

TadeuszD wrote:This works wery well, but I have question: Why the first version of my code didn't work?
The first version doesn't work because there is a bug in NML. Thanks for the report, I'll fix it as soon as possible.
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

Thanks to all.
Eddi's code works. But according to FooBar suggestions, I will reserve sprites one at a time. I don't require contiguous block in my project.
And I'm waiting for updated NML compliler... ;)
Image
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

FooBar wrote:Separate from that your code doesn't work, I'm getting the idea that it's better to reserve sprites one at a time.

According to the NewGRF specs, your grf will be deactivated if the system can't reserve a contiguous block of sprites. From what I understand, when reserving one at a time you can reserve sprites from multiple non-contiguous blocks. In some cases you may be required to use a contiguous block, but in this case of translation tables you don't.
At least in OpenTTD, it makes absolutely no difference AFAIK
Create your own NewGRF? Check out this tutorial!
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Why can't I use this:

Code: Select all

//if nutracks, we're going to use the MTRO railtype label.
if (railtype_available("MTRO")) {
    railtypetable {
        RAIL,
        ELRL,
        MTRO
    }
}
//in any other case we'll be using the default 3RDR label.
else {
    railtypetable {
        RAIL,
        ELRL,
        MTRO: ["3RDR"]
    }
}
I believe something like that is possible (and legal) in NFO directly, but nmlc throws a "nmlc: "src/railtypetable.pnml", line 13: A grf may contain only one rail type table."
Is it because the second railtypetable is on line 13 perhaps? :P

Using nmlc r1711. Indeed slightly older, but I went through the commit log and this doesn't appear to be addressed since.

EDIT: Oh, and I do have a workaround, so that's not the issue. Would just be nice if I could do the above :)

EDIT2: nevermind, I just remembered this: http://newgrf-specs.tt-wiki.net/wiki/NML:Railtypetable

So the solution is this:

Code: Select all

railtypetable {
    RAIL,
    ELRL,
    MTRO: ["3RDR", MTRO]
}
Cleaner as well. Don't know if the double MTRO is going to bite me, but that's an easy fix. Thanks though :)
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 »

The point of the railtypetable as implemented in NML is to not need the case distinction as you tried to implement it but to include that directly into the railtype table (and checking for available railtypes is what you really want to do, not a particular newgrf, right)?
http://newgrf-specs.tt-wiki.net/wiki/NML:Railtypetable

Code: Select all

    railtypetable {
        RAIL,
        ELRL,
        metrotracks: [MTRO, "3RDR"]
    }
And henceforth you use "metrotracks" in that newgrf where you want to refer to the appropriate railtype (whatever it now may be, depending on railtype newgrfs). "metrotracks" will preferentially be assigned to the label "MTRO", but if that is not available it will be assigned to the label "3RDR".
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Thanks, I came to that conclusion myself in the meantime as well (and was about to report on that) :)

Thing is though, I seem to have fallen in a vicious circle with that:
- The railtype is only available if there are vehicles of that type available;
- The vehicles are only available on said railtype if the railtype is available.

Expanding on your example: if I set NuTracks to use metro tracks, I don't get any metro tracks and my metro vehicles are unavailable. If I set it to use third rail tracks the rails are available as well as the vehicles.
In the first case I end up in that circle. In the second case the vehicles are unconditionally assigned to 3RDR and therefore the tracks are made available as well.

I suspect if I set metrotracks: [MTRO, "3RDR", RAIL] that I then well end up with my metro vehicles on rail, no matter what tracks set loaded.

So it's a nice idea on paper, but I don't appear to get it to work...
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

FooBar wrote: - The railtype is only available if there are vehicles of that type available;
'Available only if there are vehicles' applies to players, not to NewGRFs. The railtype_available() function only tests if there's a railtype defined with that label.
So there's no circular dependency here.

FooBar wrote:So it's a nice idea on paper, but I don't appear to get it to work...
Did you try in-game?
Create your own NewGRF? Check out this tutorial!
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

Yes, I did try ingame.

To summarize:
metrotracks: [MTRO, "3RDR"]: I only get the metros if I set NuTracks to third rail track usage or if I use the metro track set (which defines 3RDR).
metrotracks: ["3RDR", MTRO]: Works only with NuTracks set to Metro usage, no metros with metro track set.
metrotracks: [MTRO, "3RDR", RAIL]: With this and the metro track set loaded I get the metro's on electrified rail and no metro tracks available.
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 »

FooBar wrote:Yes, I did try ingame.
I don't think NuTracks is a good test candidate, as AFAIR it provides different railtypes depending on the grf parameters and other loaded GRFs.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: NML - a Newgrf Meta Language

Post by FooBar »

It does, but as it doesn't recognise the Dutch Trainset, you have to use the manual settings. So I don't think it matters.

Still, the last test case was without NuTracks. Metro Track Set provides only 3RDR (and 3RDC) track types and does no fancy detection of stuff. Even with that and the "metrotracks: [MTRO, "3RDR", RAIL]" entry in the railtype table I don't get my metros on 3RDR as one would expect/hope, but on elektrified rail instead.

If I should provide some testing grfs please let me know. It's also possible to check out the dutchtrains source and build yourself. The railtypetable is conveniently located in a separate file in the /src dir.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

If I couple a carriage (made with GRF7) up to a engine (made with nmlc GRF8, r1772), then I receive a error:
grf7to8.png
grf7to8.png (2.97 KiB) Viewed 2207 times
Vehicles with GRF7 to GRF7 and with GRF8 to GRF8 - has no error.

What is wrong or this is bug in openttd?

In NML source I use:

Code: Select all

switch (FEAT_TRAINS, SELF, chs7_can_attach_wagon,
  0)
{
  return CB_RESULT_ATTACH_ALLOW;
}
and in NML r 1772 the named const is
# Callback results
'CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES' : 0x400,
'CB_RESULT_ATTACH_ALLOW' : 0x401,
'CB_RESULT_ATTACH_DISALLOW' : 0x402,
For reference, in NML r1720 (GRF7)
# Callback results
'CB_RESULT_ATTACH_DISALLOW' : 0xFD,
'CB_RESULT_ATTACH_ALLOW' : 0xFE,
'CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES' : 0xFF,
I want to couple up vehicles in GRF7 and GRF8 in various combinations.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

Thanks for your report. That's actually a bug in OpenTTD, see my report on the bug tracker: http://bugs.openttd.org/task/4923
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Receive a exception:
nmlc: An internal error has occurred:
nmlc-version: r233M (973e12ba5192)
Error: (AssertionError) .
Command: ['nmlc', '--nfo=xussr.nfo', '--grf=xussr.grf', '--nml=xussr_optimize
d.nml', '-M', '--MF=xussr_dep.txt', 'xussr.nml']
Location: File "nml\output_base.py", line 108, in prepare_byte
What is it? I just add more train vehicle. If I comment it or another before - has no error.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Add.
If I comment string with cargo_subtype_text in graphics block -- has no error. Strings with code I do not comment.

Code: Select all

item (FEAT_TRAINS, chs8) 
{
...
  graphics {
...
//    cargo_subtype_text: chs8_cargo_subtype_text;
...
  }
}
Code is

Code: Select all

switch (FEAT_TRAINS, SELF, chs8_cargo_subtype_text3,
  current_year >= 1995)
{
  1: string(STR_CHS8_REFIT_V4);
  return CB_RESULT_NO_TEXT;
}

switch (FEAT_TRAINS, SELF, chs8_cargo_subtype_text2,
  current_year >= 1990)
{
  1: string(STR_CHS8_REFIT_V3);
  return CB_RESULT_NO_TEXT;
}

switch (FEAT_TRAINS, SELF, chs8_cargo_subtype_text,
  cargo_subtype)
{
  0: string(STR_CHS8_REFIT_V1);
  1: string(STR_CHS8_REFIT_V2);
  2: chs8_cargo_subtype_text2;
  3: chs8_cargo_subtype_text3;
  4: string(STR_CHS8_REFIT_V5);
  5: string(STR_CHS8_REFIT_V6);
  6: string(STR_CHS8_REFIT_V7);
  7: string(STR_CHS8_REFIT_V8);
  8: string(STR_CHS8_REFIT_V9);
  9: string(STR_CHS8_REFIT_V10);
  return CB_RESULT_NO_TEXT;
}
If I comment another vehicle or callback cargo_subtype_text in it - has no error, otherwise - has error.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

Could you send me your complete nml file to reproduce those problems? I haven't found a way to reproduce those last two problems yet.

Edit: fixed in r1784
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

If I made articulated vehicle consists of 10 elements by it:

Code: Select all

switch (FEAT_TRAINS, SELF, rs5q_articulated_part,
  extra_callback_info1)
{
  1..9: return rs5;
  return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}


item (FEAT_TRAINS, rs5) 
{
  property
  {
    cargo_capacity: 188;
..
  }
  graphics
  {
    articulated_part: rs5q_articulated_part;
  }
}
and want to the first element to contain 188 units of cargo and others element contain no cargo, I use callback cargo_capacity:

Code: Select all

switch (FEAT_TRAINS, SELF, rs5_cargo_capacity,
  position_in_vehid_chain)
{
  0: return 188;
  return 0;
}
It work when vehicle is purchased. But in purchase menu I see 10 * 188 == 1880 unis of cargo. I want see 188. I define separate purchase_cargo_capacity:

Code: Select all

switch (FEAT_TRAINS, SELF, rs5_purchase_cargo_capacity,
  0)
{
  return 188;
}
but I see 1880 units of cargo again.

Why it is multiply by count of elements, if I want to return single value in purchase_cargo_capacity callback? It is possible? What am I does wrong?

I can do this:

Code: Select all

switch (FEAT_TRAINS, SELF, rs5q_articulated_part,
  extra_callback_info1)
{
  1..9: return rs5int;
  return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}
and define another item

Code: Select all

item (FEAT_TRAINS, rs5int) 
{
  property
  {
    cargo_capacity: 0;
..
  }
}
to it work, but I want to save the identifiers and use one it instead of two.
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

The simpliest method is to divide cargo capacity by number of vehicle parts:

Code: Select all

item (FEAT_TRAINS, rs5) 
{
  property
  {
    cargo_capacity: 188/10;
..
  }
But, keep in mind, you will see 180 (or 190 depending on NML version) in purchase menu because of integer conversion.
Image
Eddi
Tycoon
Tycoon
Posts: 8258
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

the cleanest solution (imho) is to use different IDs for front and following vehicles, so you have:

Code: Select all

item(rs5_front) {
  capacity: 188;
  articulated: 9x rs5_back;
}

item(rs5_back) {
  capacity: 0;
}
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 6 guests