Digitalfox NML Questions!

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

Moderator: Graphics Moderators

User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Thanks guys, tomorrow I'll give another shot at this :D
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Ok I have a crazy bug! :mrgreen:

My code:

Code: Select all

//---------------------------------------------------------------------------------------//
// Start BUS TRAM Future 6001
//---------------------------------------------------------------------------------------//

//Join the Engine and Wagons
switch (FEAT_ROADVEHS, SELF, switch_cbarticulated_future_6001, extra_callback_info1) {
	0 : return tram_front_engine_future_6001;   
   1 : return tram_wagon_future_6001;
	2 : return tram_wagon_future_6001;
	3 : return tram_wagon_future_6001;
	4 : return tram_wagon_future_6001;
	5 : return tram_rear_engine_future_6001;
		return CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

//Front Engine Sprites
spriteset(spriteset_front_engine_future_6001, "graphics/Duch_Tram_Set/future_6001.png") 
{
    [   0, 20, 10, 28,  -4,  -9 ]
    [  20, 20, 26, 28, -17, -14 ]
    [  50, 20, 36, 28, -26, -20 ]
    [  90, 20, 26, 28,  -9, -15 ]
    [ 120, 20, 10, 28,  -4, -17 ]
    [ 140, 20, 26, 28, -16, -16 ]
    [ 170, 20, 18, 28, -10, -20 ]
    [ 210, 20, 26, 28,  -8, -16 ]
}

//Wagon Sprites
spriteset(spriteset_wagon_future_6001, "graphics/Duch_Tram_Set/future_6001.png") 
{
    [   0, 60, 10, 28,  -4, -11 ]
    [  20, 60, 26, 28, -17, -14 ]
    [  50, 60, 36, 28, -22, -20 ]
    [  90, 60, 26, 28,  -9, -15 ]
    [ 120, 60, 10, 28,  -4, -15 ]
    [ 140, 60, 26, 28, -16, -16 ]
    [ 172, 60, 24, 28,  -8, -20 ]
    [ 210, 60, 26, 28,  -8, -16 ]
}

//Rear Engine Sprites
spriteset(spriteset_rear_engine_future_6001, "graphics/Duch_Tram_Set/future_6001.png") 
{
    [   0, 100, 10, 28,  -4,  -9 ]
    [  20, 100, 26, 28, -17, -14 ]
    [  50, 100, 36, 28, -26, -20 ]
    [  90, 100, 26, 28,  -9, -15 ]
    [ 120, 100, 10, 28,  -4, -17 ]
    [ 140, 100, 26, 28, -16, -16 ]
    [ 172, 100, 17, 28, -8, -20 ]
    [ 210, 100, 26, 28,  -8, -16 ]
}

//Set capacity for all cargoes
switch (FEAT_ROADVEHS, SELF, switch_future_6001_cargo_capacity_engine, cargo_classes) {
    return 50;
}

//Set capacity for all cargoes
switch (FEAT_ROADVEHS, SELF, switch_future_6001_cargo_capacity_wagon, cargo_classes) {
    return 100;
}

item (FEAT_ROADVEHS, tram_front_engine_future_6001) {
	property {
		name						: string(STR_NAME_FUTURE_6001);
		climates_available			        : ALL_CLIMATES;
		sprite_id					        : SPRITE_ID_NEW_ROADVEH;
		visual_effect				        : VISUAL_EFFECT_DISABLE;
		misc_flags					        : bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
		running_cost_base			        : RUNNING_COST_ROADVEH;
		refittable_cargo_classes	                : bitmask(CC_PASSENGERS);
		non_refittable_cargo_classes              : 0; 
		cargo_age_period                              : 300;
		refit_cost					        : 0;
		loading_speed				        : 30;
		tractive_effort_coefficient	                : 0.3;
		air_drag_coefficient		                : 0; 
		reliability_decay			                : 20;
		introduction_date		          	: date(2022,1,1);
		model_life				        	: VEHICLE_NEVER_EXPIRES;
		vehicle_life				        : 25;
		speed						: 160 km/h;
		power						: 2500 hp;
		weight						: 42 ton;
		cargo_capacity				        : 50;
		cost_factor					        : 192;
		running_cost_factor			        : 111;
		length						: 4;
	}
	graphics {
		purchase					: spriteset_front_engine_future_6001;
                articulated_part			        : switch_cbarticulated_future_6001;
		default					: spriteset_front_engine_future_6001;
		cargo_capacity				: switch_future_6001_cargo_capacity_engine;
	}
}

item (FEAT_ROADVEHS, tram_wagon_future_6001) {
	property {
		name						: string(STR_NAME_FUTURE_6001);
		climates_available			: NO_CLIMATE;
		sprite_id					: SPRITE_ID_NEW_ROADVEH;
		visual_effect				: VISUAL_EFFECT_DISABLE;
		misc_flags					: bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
		running_cost_base			: RUNNING_COST_ROADVEH;
		refittable_cargo_classes	: bitmask(CC_PASSENGERS);
		non_refittable_cargo_classes: 0; 
		cargo_age_period            : 300;
		refit_cost					: 0;
		loading_speed				: 30;
		tractive_effort_coefficient	: 0.3;
		air_drag_coefficient		: 0; 
		reliability_decay			: 20;
		speed						: 160 km/h;
		power						: 2500 hp;
		weight						: 42 ton;
		cargo_capacity				: 100;
		length						: 6;
	}
	graphics {
		default						: spriteset_wagon_future_6001;
		cargo_capacity				: switch_future_6001_cargo_capacity_wagon;
	}
}

item (FEAT_ROADVEHS, tram_rear_engine_future_6001) {
	property {
		name						: string(STR_NAME_FUTURE_6001);
		climates_available			: NO_CLIMATE;
		sprite_id					: SPRITE_ID_NEW_ROADVEH;
		visual_effect				: VISUAL_EFFECT_DISABLE;
		misc_flags					: bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
		running_cost_base			: RUNNING_COST_ROADVEH;
		refittable_cargo_classes	: bitmask(CC_PASSENGERS);
		non_refittable_cargo_classes: 0; 
		cargo_age_period            : 300;
		refit_cost					: 0;
		loading_speed				: 30;
		tractive_effort_coefficient	: 0.3;
		air_drag_coefficient		: 0; 
		reliability_decay			: 20;
		speed						: 160 km/h;
		power						: 2500 hp;
		weight						: 42 ton;
		cargo_capacity				: 50;
		length						: 4;
	}
	graphics {
		default						: spriteset_rear_engine_future_6001;
		cargo_capacity				: switch_future_6001_cargo_capacity_engine;
	}
}

//---------------------------------------------------------------------------------------//
// End BUS TRAM Future 6001
//---------------------------------------------------------------------------------------//
My savegame:
Crazy Tram Action, 1st Jan 2030.sav
(24.7 KiB) Downloaded 89 times
My GRF:
Dutch_Tram_r162_lv5.grf
(4.74 KiB) Downloaded 86 times
The problem, just unpause, press fast foward and you'll see the TRAM outside the road station after a few months will just move forward, ignoring the other TRAM in his front!

Is this my code fault or a bug in OpenTTD?

(Sorry about the code indentation, but on notepad++ looks fine, seems the conversion to Firefox didn't work that well... Tabs :\ )
Last edited by Digitalfox on 21 Aug 2014 01:04, edited 1 time in total.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Digitalfox NML Questions!

Post by PikkaBird »

Road vehicles in (Open)TTD will eventually drive through each other if they've been waiting a long time. Whether it's a bug or a feature, who can say? ;)

If NewGRFs can influence this behaviour at all, I'd guess that perhaps it might happen sooner with shortened vehicles. But I don't know that for certain.
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Really? Been playing OTTD for 10 years never noticed it...Wow...

Thanks PikkaBird :)
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Digitalfox NML Questions!

Post by PikkaBird »

You've never seen trucks bunch up on top of each other waiting to load? :P
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

PikkaBird wrote:You've never seen trucks bunch up on top of each other waiting to load? :P
Well I use LV4 trucks so the sprites get all messy when they almost merge backs with front's so didn't noticed that behavior :)
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Digitalfox NML Questions!

Post by planetmaker »

PikkaBird wrote:Road vehicles in (Open)TTD will eventually drive through each other if they've been waiting a long time. Whether it's a bug or a feature, who can say? ;)

If NewGRFs can influence this behaviour at all, I'd guess that perhaps it might happen sooner with shortened vehicles. But I don't know that for certain.
These RV "quantum effects" are there on purpose: they help to resolve dead-lock traffic jams which possibly otherwise could not resolve. Unlike for trains you have no spacing by signals, thus the room to free them from a deadlock would be much much smaller.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Digitalfox NML Questions!

Post by Transportman »

I never noticed it for individual parts of trams to do that, only trams as a whole.

Just some notes about your code Digitalfox:
1)Why not do only 1 item and use switch blocks to determine graphics/properties depending on the place in the chain? The Dutch Trainset does it that way for articulated vehicles, it is the same item, but using switch blocks the graphics are set.
2)In switch-blocks, you can use .. to set ranges. So instead of four lines in the articulated switch that all return the wagon, you could also have used 1..4 :.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Transportman wrote:I never noticed it for individual parts of trams to do that, only trams as a whole.

Just some notes about your code Digitalfox:
1)Why not do only 1 item and use switch blocks to determine graphics/properties depending on the place in the chain? The Dutch Trainset does it that way for articulated vehicles, it is the same item, but using switch blocks the graphics are set.
2)In switch-blocks, you can use .. to set ranges. So instead of four lines in the articulated switch that all return the wagon, you could also have used 1..4 :.
Hi Transportman, thank you for you code review, I really apreciate it :)

1) I started with that strategy but then I couldn't figure out how to only have some parts of the tram have visual effects, for example smoke, all parts would show smoke :\
Capacity was also much harder to calculate, not only had I to calculate capacity for each part, but also as total, and so say you have a tram with engines, small, medium and large wagons makes it much harder to get a total capacity number that also can have the same parst with the same amount of capacity!

2) Yes you're right on the rest of the of the code (I have Duch tram set and HEQS coded in NML) I do use ranges, I missed that use, Thanks for point it ou :)

Much appreciated Transportman :)
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Digitalfox NML Questions!

Post by Transportman »

Digitalfox wrote:1) I started with that strategy but then I couldn't figure out how to only have some parts of the tram have visual effects, for example smoke, all parts would show smoke :\
You could do it like this:

Code: Select all

switch (FEAT_ROADVEHS, SELF, switch_tram_engine_future_6001_visual_effect, position_in_consist ) {
    0 : visual_effect( VISUAL_EFFECT_XXX, offset); //First vehicle has effect
    visual_effect( VISUAL_EFFECT_DISABLE, 0); //The rest does not
}

item (FEAT_ROADVEHS, tram_engine_future_6001) {
	property {
	}
	graphics {
		visual_effect			:switch_tram_engine_future_6001_visual_effect;
	}
}
Capacity was also much harder to calculate, not only had I to calculate capacity for each part, but also as total, and so say you have a tram with engines, small, medium and large wagons makes it much harder to get a total capacity number that also can have the same parst with the same amount of capacity!
How do you mean that? You could set the cargo capacities in a similar fashion as I set the visual effect for the different parts.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Ok took your advice, new code using the previous code before multiple items:

Code: Select all

//---------------------------------------------------------------------------------------//
// Start BUS TRAM HTM 821-751
//---------------------------------------------------------------------------------------//

//Engine Sprites
spriteset(spriteset_engine_htm_821_751, "graphics/Duch_Tram_Set/htm_821_751_engine.png") 
{
	[   0, 20, 10, 28,  -4, -11 ]
    [  20, 20, 26, 28, -17, -14 ]
    [  50, 20, 36, 28, -22, -20 ]
    [  90, 20, 26, 28,  -9, -15 ]
    [ 120, 20, 10, 28,  -4, -15 ]
    [ 140, 20, 26, 28, -16, -16 ]
    [ 170, 20, 36, 28, -14, -20 ]
    [ 210, 20, 26, 28,  -8, -16 ]
}

//Wagon Sprites
spriteset(spriteset_wagon_htm_821_751, "graphics/Duch_Tram_Set/htm_821_751_trailer.png") 
{
	[   0, 20, 10, 28,  -4, -11 ]
    [  20, 20, 26, 28, -17, -14 ]
    [  50, 20, 36, 28, -20, -20 ]
    [  90, 20, 26, 28,  -9, -15 ]
    [ 120, 20, 10, 28,  -4, -13 ]
    [ 140, 20, 26, 28, -16, -16 ]
    [ 170, 20, 36, 28, -16, -20 ]
    [ 210, 20, 26, 28,  -8, -16 ] 
}

//Join the Engine and Wagons sprites
switch (FEAT_ROADVEHS, SELF, switch_spritegroup_htm_821_751, position_in_consist ) {
	1: spriteset_wagon_htm_821_751;
    spriteset_engine_htm_821_751;
}

//Set number of articulated parts
switch (FEAT_ROADVEHS, SELF, switch_cbarticulated_htm_821_751, extra_callback_info1) {
	0..1: return tram_htm_821_751;
	CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

//Set visual effect of each part
switch (FEAT_ROADVEHS, SELF, switch_tram_htm_821_751_visual_effect, position_in_consist ) {
	0 : visual_effect( VISUAL_EFFECT_ELECTRIC, 0);
	visual_effect( VISUAL_EFFECT_DISABLE, 0);
}

//Set capacity of each part
switch (FEAT_ROADVEHS, SELF, switch_capacity_htm_821_751, position_in_consist ) {
	0: return 40;
	return 50;
}

//Set length of each part
switch (FEAT_ROADVEHS, SELF, switch_length_htm_821_751, position_in_consist ) {
	0: return 7;
	return 7;
}

item (FEAT_ROADVEHS, tram_htm_821_751) {
	property {
		name						: string(STR_NAME_HTM_821_751);
		climates_available			: ALL_CLIMATES;
		sprite_id					: SPRITE_ID_NEW_ROADVEH;
		misc_flags					: bitmask(ROADVEH_FLAG_TRAM, ROADVEH_FLAG_2CC);
		running_cost_base			: RUNNING_COST_ROADVEH;
		refittable_cargo_classes	: bitmask(CC_PASSENGERS);
		non_refittable_cargo_classes: 0; 
		cargo_age_period            : 300;
		refit_cost					: 0;
		loading_speed				: 30;
		tractive_effort_coefficient	: 0.3;
		air_drag_coefficient		: 0; 
		reliability_decay			: 20;
		introduction_date			: date(1929,1,1);
		model_life					: 15;
		vehicle_life				: 25;
		speed						: 60 km/h;
		power						: 315 hp;
		weight						: 26 ton;
		cargo_capacity				: 90;
		cost_factor					: 104;
		running_cost_factor			: 63;
	}
	graphics {
		purchase					: spriteset_engine_htm_821_751;       
        articulated_part			: switch_cbarticulated_htm_821_751;
		default						: switch_spritegroup_htm_821_751;
		cargo_capacity				: switch_capacity_htm_821_751;
		visual_effect         		: switch_tram_htm_821_751_visual_effect;
		length						: switch_length_htm_821_751;
	}
}

//---------------------------------------------------------------------------------------//
// End BUS TRAM HTM 821-751
//---------------------------------------------------------------------------------------//
With this code on purchase windows it shows capacity -> 80 when it should be 90.

Ok I then add purchase_cargo_capacity: 90; to graphics {} it works on changing the value on purchase menu but it gives 180.

You have to divide that number by the number of parts! So 90/2 = 45. purchase_cargo_capacity: 45;

But when you have multiple parts with multiple capacity's, when you have to divide say 100 by 6 parts it gives a decimal number instead of a integer number and doesn't work properly!

Any way of working this out?
Last edited by Digitalfox on 21 Aug 2014 16:32, edited 1 time in total.
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Digitalfox NML Questions!

Post by FooBar »

Digitalfox wrote:So 90/2 = 35.
You may want do do that math again ;)
Digitalfox wrote:But when you have multiple parts with multiple capacity's, when you have to divide say 100 by 6 parts it gives a decimal number instead of a integer number and doesn't work properly!
You can only use capacities that are a multiple of the amount of vehicle parts.
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

FooBar wrote:
Digitalfox wrote:So 90/2 = 35.
You may want do do that math again ;)
Oh yeah sorry long night :oops: , I'll edit the initial post, thank you ;)
FooBar wrote:
Digitalfox wrote:But when you have multiple parts with multiple capacity's, when you have to divide say 100 by 6 parts it gives a decimal number instead of a integer number and doesn't work properly!
You can only use capacities that are a multiple of the amount of vehicle parts.
That's a bugger ;(

But why is the capacity buy menu showing 80, when no purchase_cargo is defined? It seems it's doing 40 + 40 = 80, but why doesn't it load 50 + 40 = 90?
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: Digitalfox NML Questions!

Post by michael blunck »

Digitalfox wrote: But why is the capacity buy menu showing 80, when no purchase_cargo is defined? It seems it's doing 40 + 40 = 80, but why doesn't it load 50 + 40 = 90?
Because you´re setting capacities by use of a callback, hence you need to run the very same callback for the purchase menu to get the very same capacities.

BTW, you don´t need to set vehicle lengths to the very same value ("7") by using a callback, but this could be done inside the vehicle´s definition (the "item") once and for all.

regards
Michael
Image
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

michael blunck wrote:
Digitalfox wrote: But why is the capacity buy menu showing 80, when no purchase_cargo is defined? It seems it's doing 40 + 40 = 80, but why doesn't it load 50 + 40 = 90?
Because you´re setting capacities by use of a callback, hence you need to run the very same callback for the purchase menu to get the very same capacities.

BTW, you don´t need to set vehicle lengths to the very same value ("7") by using a callback, but this could be done inside the vehicle´s definition (the "item") once and for all.

regards
Michael
Hi, on your first point I did tried: purchase_cargo_capacity : switch_capacity_htm_821_751; and Still got 80 on buy menu!

On lengths, I know but this is like a template, so first all working properly then optimize for each tram ;)
User avatar
FooBar
Tycoon
Tycoon
Posts: 6553
Joined: 21 May 2007 11:47
Location: The Netherlands
Contact:

Re: Digitalfox NML Questions!

Post by FooBar »

In the purchase menu the vehicle isn't actually built, so only the first vehicle part is evaluated. This is also stated in the NML documentation: the position_in_consist variable is not available in the purchase menu.
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: Digitalfox NML Questions!

Post by Digitalfox »

Ok got it...

Thank you all guys, really appreciate the help :bow:
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Digitalfox NML Questions!

Post by Eddi »

instead of all these switches on position in consist you might want to consider just using a different vehicle ID for the articulated part. when you create a GRFv8 (any modern nml will do this), you have more vehicle IDs than you ever need. then you can do many things as properties instead of callbacks, which will both clean up the code and fix some purchase list things.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Digitalfox NML Questions!

Post by PikkaBird »

Eddi wrote:instead of all these switches on position in consist you might want to consider just using a different vehicle ID for the articulated part.
Welcome to tonight's edition of "didn't read the thread"... :roll:
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Digitalfox NML Questions!

Post by Transportman »

Eddi wrote:instead of all these switches on position in consist you might want to consider just using a different vehicle ID for the articulated part. when you create a GRFv8 (any modern nml will do this), you have more vehicle IDs than you ever need. then you can do many things as properties instead of callbacks, which will both clean up the code and fix some purchase list things.
It doesn't really matter, it is a personal preference. Personally I prefer the 1 ID approach, especially when more advanced things are done in the set, as then it has the potential to clean up some switches that might come up.

But that is more of a train thing as consists can be made from different train parts, which can make for some complicated switch blocks to correctly detect the end of a certain part. I do not want to know how the Dutch Trainset code would need to look like if it would work with different IDs for the articulated parts. For other vehicle types it is less of an issue.

@DigitalFox: Another suggestion, you might want to look at templates for your spritesets. Now you copy over the locations of sprites for every spriteset, but if your set would grow, it is cleaner to use templates and easier to fix if something is wrong afterwards.

For more information on templates, see the specs and tutorial
Last edited by planetmaker on 23 Aug 2014 07:09, edited 1 time in total.
Reason: fixed broken link
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 31 guests