Livery overrides in NML

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
knuckles88
Engineer
Engineer
Posts: 34
Joined: 08 Jan 2012 08:48

Livery overrides in NML

Post by knuckles88 »

Hi NML-ers,

I'm trying to code a locomotive with more than one livery option. I know this can be done without too much difficulty for vehicles that carry cargo, but my locomotive does not. Can anyone point me to a code snippet or example of how this could be done? I'm confused about whether I need a cargotable block to define some kind of custom cargo or whether I can use a predefined dummy, and whether I need to implement this using refittable_cargo_classes or cargo_allow_refit. I tried something like

Code: Select all

switch (FEAT_TRAINS, SELF, SWITCH_U4A_RECOLOUR, cargo_subtype) {
	0: return string(STR_COLOUR_COMPANY);
	1: return string(STR_COLOUR_GREEN);
	2: return string(STR_COLOUR_BLUE);
	return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

item (FEAT_TRAINS, ITEM_TRAIN_U4A) {
	property {
		//normal properties and stuff

		refittable_cargo_classes: bitmask(CC_SPECIAL); 

	//more stuff
	}
	graphics {
		default: SWITCH_U4A_GRAPHICS; 
		purchase: SPRITESET_U4A_PURCHASE;
		articulated_part: SWITCH_U4A_ARTICULATED_PART;
		length: SWITCH_U4A_LENGTH;
		visual_effect_and_powered: SWITCH_U4A_VISUAL;
		cargo_subtype_text: SWITCH_U4A_RECOLOUR;
	}
}
But it doesn't seem to work in OpenTTD 1.2.1. Without the refittable_cargo_classes, my loco appears in the purchase window, but with it the loco does not.

Thanks in advance :)
Last edited by Hyronymus on 14 Jun 2012 21:38, edited 1 time in total.
Reason: Posts split from the original topic by request
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

FooBar wrote:I'll give it a whirl as soon as I can. Thanks!
Does it work correctly now? If it does, I'll make a note to add a warning to the Dutch Track Set to load it before Train Sets in older OpenTTD versions.
knuckles88 wrote:Hi NML-ers,

I'm trying to code a locomotive with more than one livery option. I know this can be done without too much difficulty for vehicles that carry cargo, but my locomotive does not. Can anyone point me to a code snippet or example of how this could be done? I'm confused about whether I need a cargotable block to define some kind of custom cargo or whether I can use a predefined dummy, and whether I need to implement this using refittable_cargo_classes or cargo_allow_refit. I tried something like

But it doesn't seem to work in OpenTTD 1.2.1. Without the refittable_cargo_classes, my loco appears in the purchase window, but with it the loco does not.

Thanks in advance :)
There is no such thing as pure livery refits, so cargo refits are used for that. You can set the cargo capacity very low (1), that should also do the trick. I'm not completely familiar with the code of the Dutch Train Set, but the HS-0 has a capacity of 1 in the code, but in OpenTTD it shows up as having no capacity, so maybe you can try that to have a vehicle with no capacity but with refits.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
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 »

knuckles88 wrote:I'm trying to code a locomotive with more than one livery option. I know this can be done without too much difficulty for vehicles that carry cargo, but my locomotive does not. Can anyone point me to a code snippet or example of how this could be done?
Have a look at the source of the Dutch Trainset for an example. What I do there is give the locomotives a capacity of 1 passenger in the item block, and then override that again via the cargo capacity callback (setting a capacity of 0). That way the locomotive doesn't have a capacity, but is still refittable to passengers which you can attach cargo subtypes to.

I wouldn't bother with a dummy cargo, as that generally breaks compatibility with industry sets.
Transportman wrote:Does it work correctly now?
I actually completely forgot about this, been too busy with my master's thesis lately. I'll have a look now.

EDIT: Yes, this now works as one would like to. Thanks for the fix, frosch! Sorry for not verifying earlier (but you probably already knew that it was working correctly ;) ).
akasoft
Engineer
Engineer
Posts: 120
Joined: 25 Aug 2011 11:48

Re: NML - a Newgrf Meta Language

Post by akasoft »

And use CB_RESULT_NO_TEXT instead of CB_RESULT_NO_MORE_ARTICULATED_PARTS.
knuckles88
Engineer
Engineer
Posts: 34
Joined: 08 Jan 2012 08:48

Re: NML - a Newgrf Meta Language

Post by knuckles88 »

Thanks guys - it's working now :)

Here's a screenshot of the result: the left and right locos have custom liveries applied, while the middle one follows the company colour scheme (red). Another train is sitting in a depot somewhere to show the refit options.
1.png
1.png (46.12 KiB) Viewed 361 times
Out of curiosity, is it possible to code the loco so that it forces cars attached to it to follow its colour scheme? I've been looking at the livery_override block, but that seems to work in the opposite way (cars attached influence loco).

Edit: I just realized that if I only display vehicles with cargo type "None" in the purchase menu, my loco won't appear (only in the Passengers list). Is there a way to override the cargo type for the purchase menu so it displays correctly?
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 »

knuckles88 wrote:Is there a way to override the cargo type for the purchase menu so it displays correctly?
Not that I know of. One could even consider it a bug in OpenTTD.

As for your other question, you can query both the vehicle ID and chosen cargo subtype of the leading vehicle in the switch-chain of a wagon (use the PARENT variable scope). I wouldn't bother with livery override personally.
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 »

knuckles88 wrote:Out of curiosity, is it possible to code the loco so that it forces cars attached to it to follow its colour scheme? I've been looking at the livery_override block, but that seems to work in the opposite way (cars attached influence loco).
Assuming a livery_override block is the same thing as an Action3LiveryOverride, then it doesn't work in the opposite way. It specifies graphics (including callbacks) to use for the wagon when behind that locomotive.
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: NML - a Newgrf Meta Language

Post by Yexo »

PikkaBird wrote:
knuckles88 wrote:Out of curiosity, is it possible to code the loco so that it forces cars attached to it to follow its colour scheme? I've been looking at the livery_override block, but that seems to work in the opposite way (cars attached influence loco).
Assuming a livery_override block is the same thing as an Action3LiveryOverride, then it doesn't work in the opposite way. It specifies graphics (including callbacks) to use for the wagon when behind that locomotive.
It is, so that explanation is correct :)
knuckles88
Engineer
Engineer
Posts: 34
Joined: 08 Jan 2012 08:48

Re: NML - a Newgrf Meta Language

Post by knuckles88 »

Thanks for the info about livery overrides :) To expand on that... I've coded myself a locomotive and I'm interested in building some related passenger cars. The loco has custom livery options (Company Colours, Green, or Blue - the latter two because those are the actual colours CNR used while it was in service), and while I'm fine with the default coaches following the company colour scheme, I would want my custom passenger cars to follow the livery of my loco.

If I'm interested in releasing my work so far as a .grf and possibly expanding to my custom passenger car later, is there a preferred way of doing things? The options I can think of are:

1) Release what I have as one .grf, and expand it to include the custom passenger car in a future version. Would this cause compatibility issues?

2) Release what I have as a .grf, and later release a separate .grf for the passenger car. Would it be difficult to connect the livery of the custom passenger car to the livery (coded as a cargo subtype) of a custom loco in a different .grf?
Supercheese
Tycoon
Tycoon
Posts: 1660
Joined: 16 Dec 2007 22:24
Location: Idaho, USA

Re: NML - a Newgrf Meta Language

Post by Supercheese »

knuckles88 wrote:1) Release what I have as one .grf, and expand it to include the custom passenger car in a future version. Would this cause compatibility issues?

2) Release what I have as a .grf, and later release a separate .grf for the passenger car. Would it be difficult to connect the livery of the custom passenger car to the livery (coded as a cargo subtype) of a custom loco in a different .grf?
I wouldn't recomment releasing two .GRFs, as the total number of GRFs that can be loaded into a game is limited. Best to save on GRF space!
Eyecandy Road Vehicles | Fake Subways | Supercheese's NewObjects

"Fashions and cultures change, but steam trains shall always be majestic."
-Professor Hershel Layton
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 »

knuckles88 wrote: 1) Release what I have as one .grf, and expand it to include the custom passenger car in a future version. Would this cause compatibility issues?
That's definitely the way: just release a new version of your NewGRF (mind to update the version number you supply via the grf block (action14)). Releasing separate NewGRFs for an engine and its wagons is not helpful for players either. Besidest hat it's easier to code it in a single NewGRF.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Amazon [Bot] and 35 guests