NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

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 »

Okay, OpenTTD is now returning the same values as TTDPatch/the documentation suggest :)
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

Tell me please, from what point measured offset_x and offset_y in real sprite block

Code: Select all

[left_x, upper_y, width, height, offset_x, offset_y]
?
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:Tell me please, from what point measured offset_x and offset_y in real sprite block

Code: Select all

[left_x, upper_y, width, height, offset_x, offset_y]
?
Read the wiki: http://newgrf-specs.tt-wiki.net/wiki/Pa ... oordinates, http://newgrf-specs.tt-wiki.net/wiki/RealSprites
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

How I can get "Vehicle type ID" of previous vehicle in consist inside of callback "shorten_vehicle"?

E.g., code below is not work and always return 8/8:

Code: Select all

switch (FEAT_TRAINS, SELF, dummy_shorten_vehicle,
[
  STORE_TEMP(-1, 0x10F),
  var[0x61, 0, 0xFFFF, 0xC6]
])
{
  d_m: return SHORTEN_TO_7_8;
  d_c: return SHORTEN_TO_7_8;
  l_e: return SHORTEN_TO_5_8;
  lp_e: return SHORTEN_TO_5_8;
...
  return SHORTEN_TO_8_8;
}
Inside default callback (for sprites) he is work.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

var61/62 is not available in callbacks, except non-altering ones like graphics, sound, etc.
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 »

And before anyone asks: No, this will not be changed.
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

The question is about "how" and "can", not about "var 61/62". This is simply for example. Maybe there another way or variable?
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

i don't know enough about the context you are trying to use this in, but you cannot achieve that by a callback in this case.

if you are trying to build an articulated vehicle, you need to have one separate vehicle-ID for each length.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: NML - a Newgrf Meta Language

Post by PikkaBird »

Eddi wrote:if you are trying to build an articulated vehicle, you need to have one separate vehicle-ID for each length.
No you don't, but I don't think this is what he's trying to do (var 61 would hardly be useful in the context of building an articulate).
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

I trying to make the "large" length trains, from 9 to 16, through emulation conventional trains, consisting of articulated vehicles.
E.g., for my "large" carriage (or engine) with length 15 I use two vehicles with length 8 and 7.
First vehicle in a chain draw his sprite, but second is not draw. But he must set valid length information.

I thought used one dummy vehicle for all shorten values (from SHORTEN_TO_1_8 to SHORTEN_TO_8_8), determining it from the "Vehicle type ID" of previous vehicle in a chain.

We can use PARENT context and get this information about engine. I think, information about the previous and the next vehicle in a chain is no less important.

Tell me, var DA "Next wagon index, FFFF if last wagon" is same as vehicle ID or not?
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

akasoft wrote:First vehicle in a chain draw his sprite, but second is not draw. But he must set valid length information.
I've had the same problem in my double deck carriage and long steam engines.
You can use switch like below. Your articulated vehicle will be 15/8 long:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_veh_length, position_in_vehid_chain % 2) {
    1: return SHORTEN_TO_7_8;
    return SHORTEN_TO_8_8;
}

item(FEAT_TRAINS, item_your_vehicle) {
    ...
    graphics {
    shorten_vehicle:    switch_veh_length;
    }
}
Image
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

This not work, when in consists is articulated vehicles with different ID.
E.g., M-C-M, where
M - motorized head, consists of M-D (M motorized head vehicle SHORTEN_TO_8_8, D - dummy tail vehicle SHORTEN_TO_7_8),
C - carriage vehicle, consists of C-D (C carriage head vehicle SHORTEN_TO_8_8, D - dummy tail vehicle SHORTEN_TO_7_8),

Carriage and motorized vehicle can be variable length from 9 to 16.

In total, chain is: M8-D7-C8-D7-M8-D7. Item D is not draw, but set the length, which depends of previos ID respectively.

Version of the even positions of carriage not work, if chain is e.g. M8-D7-C8-D5-M8-D4.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

in CETS we have several dummy-vehicles for that purpose, one each with a fixed length 3, 4, 5 and 6lu ("length units")

vehicles can be 3 to 16lu by the following scheme:

Code: Select all

   |head|dummy
 3 | 3  |
 4 | 4  |
 5 | 5  |
 6 | 6  |
 7 | 4  | 3
 8 | 4  | 4
 9 | 4  | 5
10 | 4  | 6
11 | 4  | 4 3
12 | 4  | 4 4
13 | 4  | 4 5
14 | 4  | 4 6
15 | 4  | 4 4 3
16 | 4  | 4 4 4
(4 turned out a good length for use with var45/62)
for example this code of a 13lu vehicle:

Code: Select all

switch(FEAT_TRAINS, SELF, VEH_ID(cb_articulate_switch), extra_callback_info1) {
        2: return dummy_zzzd5;
        3: return 0xFF;
        return dummy_zzzd4;
}
here an example for a complicated articulated vehicle:
engine (9lu) - wagon A (11lu) - wagon C (3x11lu) - wagon B (11lu)

Code: Select all

switch(FEAT_TRAINS, SELF, VEH_ID(cb_articulate_custom_switch), extra_callback_info1) {
        1: return dummy_zzzd5;
        2: return DRG_61a;
        14: return DRG_61b;
        5: return DRG_61c;
        8: return DRG_61c;
        11: return DRG_61c;
        4: return dummy_zzzd3;
        7: return dummy_zzzd3;
        10: return dummy_zzzd3;
        13: return dummy_zzzd3;
        16: return dummy_zzzd3;
        17: return 0xFF;
        return dummy_zzzd4;
}
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

A long-open bug was fixed today (if you use "speed: 100km/h;" in your code it'll display 100km/h in game if possible, 101km/h if not instead of 99km/h as it did before) and with that NML was finally ready for the 0.2.0 release. Packages can be found here: http://bundles.openttdcoop.org/nml/releases/
The 0.2 branch will be updated for some time with fixes / small additions, but will receive no major changes. Starting from now the nightlies will no longer consider compatibility with OpenTTD 1.1 and we'll continue to work on it as a tool for OpenTTD 1.2 and later.
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 strange problem with my long carriage in OTTD.
This is articulated vehicle with total length 12/8, combined with normal 8/8 vehicle and 4/8 "dummy" car:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_abdnu_shorten, position_in_vehid_chain % 2) {
    1: return SHORTEN_TO_4_8;
    return SHORTEN_TO_8_8;
}
switch(FEAT_TRAINS, SELF, switch_abdnu_articulated, extra_callback_info1) {
    1: return item_abdnu;   // Add dummy wagon
    return 0xFF;
}
switch(FEAT_TRAINS, SELF, switch_abdnu_graphics, (position_in_vehid_chain%2)*2 + cargo_subtype) {
    0: return sset_bdnu;     // 2 class carriage
    1: return sset_adnu;     // 1 class carriage
    return sset_dummy;
}

item(FEAT_TRAINS, item_abdnu) {
    ...
    graphics {
        ...
        default:                    switch_abdnu_graphics;
        articulated_part:           switch_abdnu_articulated;
        shorten_vehicle:            switch_abdnu_shorten;
    }
}
Everything looks typical, but I obtain strange, visual artefacts:
long-vehicle.png
long-vehicle.png (5.32 KiB) Viewed 2102 times
On the left picture the fence overlaps the roof of carriage. On the right picture carriages overlaps one another.
What is wrong? This is a mistake in my GRF or bug in OTTD? I'm using OTTD 1.1.3.
Image
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

this should behave better/different with trunk. check here: http://www.tt-forums.net/viewtopic.php?f=68&t=57446 (you may get more severe glitches in other places though, like near foundations)
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 for answer.
What do you mean, "trunk"?
Image
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 »

TadeuszD wrote:Thanks for answer.
What do you mean, "trunk"?
http://wiki.openttd.org/FAQ_OpenTTD_versions#Trunk
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: NML - a Newgrf Meta Language

Post by TadeuszD »

Yes, of course... Thanks a lot... I've cheked this word in dictionary, but I forgot this "computer's" denotation... :oops:
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 »

Hello, again...
In my project I use simple recolour sprites for recolouring cargo inside my wagons.
My first version was:

Code: Select all

cargo_palette = reserve_sprites(2);
replace(cargo_palette) { recolour_sprite {
        0xAA: 0x01;
        ...
        } }
replace(cargo_palette + 1) { recolour_sprite {
        0xAA: 0x40;
        ...
        } }
But this version didn't work. I reached internal compiler error:
nmlc: An internal error has occurred:
nmlc-version: 0.2.0 (2c839dc11b3a)
Error: (AssertionError) .
Command: ['nmlc', '-c', '--grf', 'pkp-0.1.grf', 'tmp\\pkp.nml']
Location: File "nml\free_number_list.py", line 33, in pop

This error appears with nml version 0.2.0 and r1702.

I corrected this error in my second version:

Code: Select all

palette_coal = reserve_sprites(1);
replace(palette_coal) { recolour_sprite {
        0xAA: 0x01;
        ...
        } }
palette_grai = reserve_sprites(1);
replace(palette_grai) { recolour_sprite {
        0xAA: 0x40;
        ...
        } }
This works wery well, but I have question: Why the first version of my code didn't work?
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 15 guests