NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

BarthVader wrote:I looked into the documentation but I can't find anything about how to make articulated vehicles. Is it possible?
Yes, it is possible, but the documentation for NML is still by far not as extensive as the documentation for the underlying NFO language. Therefore it is often useful to also read the nfo documentation at http://wiki.ttdpatch.net/tiki-index.php ... phicsSpecs The documentation for callback 16 (not 19) which is used to created articulated vehicles can be found here: http://wiki.ttdpatch.net/tiki-index.php ... allback_16_
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: NML - a Newgrf Meta Language

Post by DJ Nekkid »

sorry, my mistake.
Member of the
ImageImage
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

oberhümer wrote:2. Less important: NML can't handle numbers in railtype names. This makes it hard, if not impossible, to make third rail (3RDR) vehicles.
This is supported since NML r1080. In your railtype table you can now instead of just an identifier (like 3RDR) also use a literal string (like "3RDR"). Identifiers are not allowed to start with a number, but strings are. To reference the railtype later in your code use the builtin function railtype (like: railtype("3RDR")).
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 »

Thank you very much for that.
--- 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. ---
BarthVader
Engineer
Engineer
Posts: 10
Joined: 02 Oct 2010 18:47

Re: NML - a Newgrf Meta Language

Post by BarthVader »

Could I ask for some example?
edit: Example of articulated vehicle coded in NML. I've already checked those projects and couldn't find one.
Last edited by BarthVader on 10 Dec 2010 14:15, edited 1 time in total.
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 »

BarthVader wrote:Could I ask for some example?
Of what?

If you mean NML projects in general, check out OpenGFX+RV, +Airports, +Trains, +Industries, SwedishRails and a number of TownName NewGRFs as found on the DevZone.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

A simple tram with 4 parts coded in NML (tram foster expression from ogfx+rv, made into an articulated vehicle by attaching the engine to itself 3 times).

Code: Select all

template tmpl_tram(x, y) {
	[  x,     y,  8, 18,   -3, -10]
	[ 16 + x, y, 20, 18,  -14,  -5]
	[ 48 + x, y, 28, 15,  -14,  -8]
	[ 96 + x, y, 20, 18,   -6,  -7]
	[128 + x, y,  8, 18,   -3, -10]
	[144 + x, y, 20, 18,  -14,  -9]
	[176 + x, y, 28, 15,  -14,  -8]
	[224 + x, y, 20, 18,   -6,  -7]
}
spriteset(foster_express_set, "tram_foster_express.png") {
	tmpl_tram(48,1)
}
spritegroup foster_express_group {
	loading: foster_express_set;
	loaded: foster_express_set;
}
switch(FEAT_ROADVEHS, SELF, foster_express_articulated_parts, extra_callback_info1) {
	1..3: return 88;
	CB_FAILED;
}

switch(FEAT_ROADVEHS, SELF, foster_express_callbacks, current_callback) {
	VEH_CB_ARTICULATED_PARTS: foster_express_articulated_parts;
	foster_express_group;
}

item(FEAT_ROADVEHS, foster_express_tram, 88) {
	property {
		name:                         string(STR_NAME_FOSTER_EXPRESS);
		climates_available:           ALL_CLIMATES;
		model_life:                   40;                         // years
		vehicle_life:                 30;                         // years
		introduction_date:            date(1965,1,1);
		reliability_decay:            1; 
		running_cost_base:            RUNNING_COST_ROADVEH;       // Default road vehicle running cost base
		running_cost_factor:          135;
		cost_factor:                  143;
		speed:                        75 km/h;
		power:                        220 hp;
		weight:                       22 ton;
		sprite_id:                    SPRITE_ID_NEW_ROADVEH;      // We have our own sprites
		loading_speed:                16;                         // loading speed
		tractive_effort_coefficient:  0.3;
		air_drag_coefficient:         0.5;
		cargo_capacity:               45;                         // passengers
		refittable_cargo_classes:     bitmask(CC_PASSENGERS); // Allow passengers (and tourists)
		non_refittable_cargo_classes: NO_CARGO_CLASS;         // Disallow other cargos
		refittable_cargo_types:       0;
		misc_flags:                   bitmask(ROADVEH_FLAG_TRAM); // This is a tram
		callback_flags:               bitmask(VEH_CBF_ARTICULATED_PARTS);
	}
	graphics {
		foster_express_callbacks;
	}
}
Attachments
tram_foster_express.png
tram_foster_express.png (2.39 KiB) Viewed 5078 times
BarthVader
Engineer
Engineer
Posts: 10
Joined: 02 Oct 2010 18:47

Re: NML - a Newgrf Meta Language

Post by BarthVader »

Well, thanks a lot.
BarthVader
Engineer
Engineer
Posts: 10
Joined: 02 Oct 2010 18:47

Re: NML - a Newgrf Meta Language

Post by BarthVader »

How to code wagons that can be used to make articulated vehicles but can't be used separately (e. g. tenders)?
Already checked TTDPatch Wiki, nothing there.
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 »

BarthVader wrote:How to code wagons that can be used to make articulated vehicles but can't be used separately (e. g. tenders)?
Already checked TTDPatch Wiki, nothing there.
You need add to each engine the VEH_CB_CAN_ATTACH_WAGON callback and check for the vehicleID of the wagon to be attached - and fail for those engines where it must not be attached to. You can - afaik - not prevent the wagon being attached to engines from another set which allow other wagons. Or use VEH_CB_ARTICULATED_PARTS for articulated vehicles, but that still doesn't prevent the wagon to be attached to other engines.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

Planetmaker: while everything you write is true, it's not an answer to the question asked. The question was about articulated vehicles.
BarthVader wrote:How to code wagons that can be used to make articulated vehicles but can't be used separately (e. g. tenders)?
Already checked TTDPatch Wiki, nothing there.
Just set "climates_available" to "NO_CLIMATE".
BarthVader
Engineer
Engineer
Posts: 10
Joined: 02 Oct 2010 18:47

Re: NML - a Newgrf Meta Language

Post by BarthVader »

Wow... it was so easy... Thanks again.
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 »

So... new bug, new report (note that I'm still using the version I reported the other bugs in). What it boils down to is that I can't make sprite groups which use more than one sprite set per line (loading/unloading, on road vehicles). I've written them exactly as written in the documentation, and it didn't mention anything about them being specific to trains. Like this:

Code: Select all

spritegroup some_sprite_group {
     loaded: [empty_set, half_set, full_set];
     loading: [empty_set, half_set, full_set];
}
When compiling code that uses this, there is the error "Invalid amount of arguments for real sprite." I'm sure the actual sprites in the sprite sets all are correct.
--- 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. ---
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

oberhümer wrote:When compiling code that uses this, there is the error "Invalid amount of arguments for real sprite." I'm sure the actual sprites in the sprite sets all are correct.
That error message is related to a real sprite, not to the spritegroup block. Since r1109 NML will print the a line number with that error so it should be easier to find the cause. However since the openttdcoop server is currently down I can't push that revision yet, so you'll have to wait a bit. If you post the complete nml file I'll take a look at it to see if I can find the problem.
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 »

This is the problematic file. You'll find there is nothing wrong with the sprite defnitions.
Attachments
f9000_graphics.pnml.txt
(3.8 KiB) Downloaded 150 times
--- 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 »

That snippet you post is unproblematic and doesn't create an error here (using NML r1118). Please post the complete (pre-processed) NML file. Maybe it's related to something triggered in another part of the code. You can also send it via pm, if you don't want to publish it here.

Btw, you use the same sprite set definitions (sizes, offsets) for a lot of vehicles. You'd save a lot of code and make alignment easier, if you use something like

Code: Select all

template tmpl_f9000(x,y) {
	[x, y, 8, 18, -4, -9]
	[x+16, y, 20, 16, -10, -8]
	[x+48, y, 28, 12, -14, -6]
	[x+96, y, 20, 16, -10, -8]
	[x+128, y, 8, 18, -4, -9]
	[x+144, y, 20, 16, -10, -8]
	[x+176, y, 28, 12, -14, -6]
	[x+224, y, 20, 16, -10, -8]
}
spriteset(f9000_coil_set, "tile_template.png") { tmpl_f9000(18,136) }
spritegroup f9000_coil_grp {
	loaded: f9000_coil_set;
	loading: f9000_coil_set;
}

spriteset(f9000_coil_set, "tile_template.png") { tmpl_f9000(96,8) }
spritegroup f9000_good_grp {
	loaded: f9000_good_set;
	loading: f9000_good_set;
}
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 »

Thank you for the tip. I'll try with the newest version of NML - perhaps that fixed it. The problem definitely is/was with that file, since I have no problems when removing it.
--- 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
Ammler
President
President
Posts: 953
Joined: 18 Jun 2006 18:18
Location: Switzerland
Contact:

Re: NML - a Newgrf Meta Language

Post by Ammler »

As NML has no release yet, it can change from commit to commit, so it is highly recommend to update quite often. You are welcome on the DevZone, where your project could be automatically built (and rebuild with probably updated NML nightlies)
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 »

Well, now I'm there, and have already encountered the next problem: the 2cc flag for trucks seems to turn them into trams instead (however, the reverse is not true). Download this file to test.

(Actually, I should have filed a report on the Devzone... maybe next time.)
--- 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. ---
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

oberhümer wrote:Well, now I'm there, and have already encountered the next problem: the 2cc flag for trucks seems to turn them into trams instead (however, the reverse is not true). Download this file to test.

(Actually, I should have filed a report on the Devzone... maybe next time.)
I've just compiled narvs to test (with the f9000 enabled) but it worked like it should, no tram. However if you'd use

Code: Select all

misc_flags: ROADVEH_FLAG_2CC;
Instead of the correct code

Code: Select all

misc_flags: bitmask(ROADVEH_FLAG_2CC);
this is exactly what would happen.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest