NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

oberhümer
Tycoon
Tycoon
Posts: 1283
Joined: 23 Oct 2009 19:35
Location: Here and there, sometime or another

Re: NML - a Newgrf Meta Language

Post by oberhümer »

--- Licenses: GNU LGPL, version 2 or newer, code and graphics. CC-By-SA, graphics, alternatively. If you're using any, I'd like to hear about it --- Call them "track types" ---
--- Mostly inactive developer for: NuTracks - Central European Train Set --- Running/compiling for: Linux (x86) - Android - Windows (32/64 bit) ---

--- Need a file packer? 7-Zip --- BOINC - use your computing power to benefit science --- Block trackers, not ads --- Unix in dispersible pellets, the formula for the future. ---
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 »

In NML that variable is - iirc - called extra_callback_info1. Not exactly sure right now whether it works outside callbacks for this distinction alone.
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 »

Ah, that feature is so new[0] that I wasn't even aware of it, thanks! :)

[0] Well, relatively. It's still almost a 1000 revisions old...
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: NML - a Newgrf Meta Language

Post by supermop »

..... BEER TRAM?
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!
I have question... When the bitmask_consist_info is calculeted?

I have two types of wagons in my consist. All "normal" wagons have switch to calculate bitmask_vehicle_info (0x08 mean "dangerous" cargo):

Code: Select all

switch(FEAT_TRAINS, SELF, switch_zaes_bitmask, cargo_type_in_veh){
    OIL_: return 0x08;
    PETR: return 0x08;
    RFPR: return 0x08;
    return 0x00;
}

item(FEAT_TRAINS, item_zaes) {
    ...
    graphics {
       bitmask_vehicle_info:       switch_zaes_bitmask;
    }
}
The special "buffer" wagon at the end of the consist use information from bitmask_consist_info (if the train carry dangerous cargo, this wagon must be empty):

Code: Select all

switch(FEAT_TRAINS, SELF, switch_eaos_capacity, (bitmask_consist_info & 0x08)){
    0x08: return 0;
    return 50;
}

item(FEAT_TRAINS, item_eaos) {
    ...
    graphics {
        cargo_capacity:             switch_eaos_capacity;
        purchase_cargo_capacity:    return 50;
    }
}
But this don't work. :cry: I allways have cargo_capacity=50.
What is wrong in my code?
I'm using nmlc 0.2.2
Image
User avatar
stevenh
TTDPatch Developer
TTDPatch Developer
Posts: 759
Joined: 24 Jul 2005 05:07
Location: Canberra, Australia
Contact:

Re: NML - a Newgrf Meta Language

Post by stevenh »

planetmaker wrote:In NML that variable is - iirc - called extra_callback_info1. Not exactly sure right now whether it works outside callbacks for this distinction alone.
i.e. it wont work like:

Code: Select all

graphics {
        purchase:					series_70_purchase_sprite; //Purchase menu sprite
        additional_text:			return string(STR_70_SERIES_ADDITIONAL); //Additional text shown in purchase list
        articulated_part:			switch_series_70_articulated;
        shorten_vehicle:			switch_series_70_length;
        cargo_capacity:				switch_series_70_capacity;
        purchase_cargo_capacity:	series_70_purchase_sprite;
        default:					switch_series_70_sprites;
		extra_callback_info1:		series_70_purchase_sprite;
    }
I'm still trying to work out where the line is as to what NML can do.

supermop wrote:..... BEER TRAM?
Image
http://train.sakura.ne.jp/train/hiroden ... dex01.html
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 »

try linking 'default' to a switch block that queries variable 'extra_callback_info1'.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: NML - a Newgrf Meta Language

Post by PikkaBird »

stevenh wrote:
supermop wrote:..... BEER TRAM?
Image1.jpg
Image1.jpg (152.48 KiB) Viewed 3541 times
User avatar
stevenh
TTDPatch Developer
TTDPatch Developer
Posts: 759
Joined: 24 Jul 2005 05:07
Location: Canberra, Australia
Contact:

Re: NML - a Newgrf Meta Language

Post by stevenh »

FooBar wrote:try linking 'default' to a switch block that queries variable 'extra_callback_info1'.
Right, I chained it all together:

Code: Select all

switch (FEAT_ROADVEHS, SELF, switch_series_70_sprites2, extra_callback_info1 ) {
	0: series_70_part_0;
	series_70_purchase_sprite;
}

switch (FEAT_ROADVEHS, SELF, switch_series_70_sprites, position_in_consist ) {
	1: series_70_part_1;
    2: series_70_part_2;
    switch_series_70_sprites2; //default
}

graphics {
		...
		default:					switch_series_70_sprites;
    }
Excuse the naming, was mainly a test... and now it draws the first sprite correctly, but it continues drawing the rest of the tram!
(See attachment)
Attachments
So close.
So close.
NearlyCorrect.png (4 KiB) Viewed 3537 times
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 »

Now you only make the decision normal sprite / purchase sprite for part 0 of the vehicle.

Try something like this:

Code: Select all


switch (FEAT_ROADVEHS, SELF, switch_series_70_sprites_real, position_in_consist ) {
   1: series_70_part_1;
    2: series_70_part_2;
    series_70_part_0; //default
}

switch (FEAT_ROADVEHS, SELF, switch_series_70_sprites_window, position_in_consist ) {
   0: series_70_purchase_sprite;
    some_1px_transparent_sprite; //all other vehicle parts
}

switch (FEAT_ROADVEHS, SELF, switch_series_70_sprites_choice, extra_callback_info1 ) {
   0: switch_series_70_sprites_real; //for vehicles on the map
   switch_series_70_sprites_window; //for vehicles anywhere else
}

graphics {
      ...
      default:               switch_series_70_sprites_choice;
    }
Note that I intoduced a dummy sprite that is completely transparent. Note that I did not test this code.
User avatar
supermop
Tycoon
Tycoon
Posts: 1104
Joined: 21 Feb 2010 00:15
Location: Fitzroy North - 96

Re: NML - a Newgrf Meta Language

Post by supermop »

Nice, I once encountered a tram that was a bar in Helsinki, was not aware the concept was universal.
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 »

I just upgraded from nml 1792 to 1846 and now my grf doesn't build any more. I checked the documentation, but that's still the same. What has changed, and more importantly, what do I need to change to get it working again?

The code I get an error on is this:

Code: Select all

recolour_grai = reserve_sprites(1);
replace(recolour_grai) {
    recolour_sprite {
        0xE5: 0x3F;
        0xE8: 0x40;
        0xE9: 0x41;
        0xEA: 0x42;
        0xEB: 0x43;
        0xEC: 0x33;
        0xED: 0x44;
        0xEE: 0x34;
    }
}
The error I get is "Unrecognized identifier 'recolour_grai' encountered", with a reference to the second line of that code snippet. I'm surprized that it's unregcognized, as it's defined one line earlier...

Thanks!
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 »

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 »

Hmmm crap, I should have checked that first. Thanks though! :D

I did some more testing myself, and can confirm that r1834 is working. It spits a huge amount of 'deprecated' warnings, but it works.

There are now some other issues with the grf not showing up ingame...
But let's upgrade OpenTTD first :P
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 »

Yeah, now I'm getting the 'unexpected sprite 123' warning other users were complaining about.
But I'm getting it on my railtype table. Which was working previously.

this is the table:

Code: Select all

railtypetable {
    RAIL,
    ELRL,
    metro: [MTRO, "3RDR"]
}
and that results in this in NFO:

Code: Select all

// param[80] = 1380209203
121 * 9 0D 50 D= FF 00 dx52445233 

122 * 9 09 00 04 0D dx4F52544D 01 

// param[80] = 1330795597
123 * 9 0D 50 D= FF FF dx4F52544D 

124 * 7 06 
50 04 FF wx000E 
FF 

125 * 18 00 08 b1 03 00 
12 "RAIL" "ELRL" "\00\00\00\00" 
Doesn't look too unexpected to me, really...
So I may be in the wrong topic with this problem...

EDIT: I've found that if I replace the railtypetable with the following that then the grf works:

Code: Select all

railtypetable {
    RAIL,
    ELRL,
    metro: ["3RDR"]
}
Hirundo
Transport Coordinator
Transport Coordinator
Posts: 298
Joined: 27 Jan 2008 13:02

Re: NML - a Newgrf Meta Language

Post by Hirundo »

As of today, NML fully supports 32bpp / extra zoom level sprites, including mask files. These are provided via the alternative_sprites block. Documentation can be found on the wiki (mainly here and here)
Create your own NewGRF? Check out this tutorial!
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: NML - a Newgrf Meta Language

Post by Bad_Brett »

I have a question about the industry flags. Right now you can use flags like "build before 1950" and "allow ships and aircrafts", but is there anyway to customize these flags?

My scenario will begin around 1830, so a flag like "build before 1950" doesn't really help me. Is there anyway to create a factory like this with NML:

- Build on water
- Allow ships (but not aircrafts)
- Factory AND station accepts NO cargo
- Factory AND station supplies one type of cargo

The problem is that the flags are based on the Oil Rig... The factory part of Oil Rig doesn't require passengers or mail, but the station still accepts it.

Are there any workarounds or do you think more advanced flags will be available in the future?
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 »

No, the flags are what they are. They're remains of basic TTD essentially.

If you want something different, you can replicate most (if not all) flags via callbacks. This allows you to customize allowing and disallowing construction any way you want. Including dates and building on water.

Allowing ships but not aircraft is not possible. You have to reuse the existing oil rig industry tile with builtin station. If you try to customize anything of that tile it will lose it's station capabilities.

Cargo acceptance and production is controlled via simple property definitions. Unless you want something really fancy, then there are some callbacks that may come in handy.
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 »

Bad_Brett wrote:I have a question about the industry flags. Right now you can use flags like "build before 1950" and "allow ships and aircrafts", but is there anyway to customize these flags?
You cannot customize these build flags (they're for the default industries and mostly for hysterical reasons), but...
- Build on water
- Allow ships (but not aircrafts)
- Factory AND station accepts NO cargo
- Factory AND station supplies one type of cargo
is still perfectly feasible. You need to implement that via the industry callbacks: http://newgrf-specs.tt-wiki.net/wiki/NM ... _callbacks . Namely I'd suggest to use
construction_probability (and return a different probability depending on the year)
location_check

I'm not sure exactly what you mean with the latter two points, though. You can of course define cargo acceptance and production as you want (max 3 input, max 2 output) and even change that via callback (though I'd not recommend to do that as those info are not supported by the GUI).

Check out the FIRS repository and source code for industries which do all this.
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: NML - a Newgrf Meta Language

Post by Bad_Brett »

Thanks for the tips! I guess the best way is to use callbacks instead of the flags then.
planetmaker wrote: I'm not sure exactly what you mean with the latter two points, though. You can of course define cargo acceptance and production as you want (max 3 input, max 2 output) and even change that via callback (though I'd not recommend to do that as those info are not supported by the GUI).

Check out the FIRS repository and source code for industries which do all this.
I've adjusted the output and input of my Oil Rig replacement. So if I click on the factory part of the Oil Rig, it doesn't accept passengers anymore. The problem is that the station part still accepts passengers and mail.

My plan is to include fishing boats and a "fish resource". It would be strange if it was be possible to send mail to the fishes. :)
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 17 guests