vehicle_is_reversed ... or not? AND Subtypes

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

Moderator: Graphics Moderators

Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

Hello,

i struggle with the "vehicle_is_reversed"-Variable.

My example:
top: driving to left<br />bottom: reversed to the right
top: driving to left
bottom: reversed to the right
reversed.png (6.01 KiB) Viewed 4478 times
As you can see, the yellow stripe above the door of the first part disappears, because the third part doesn't change livery when the whole train is reversed. First part does change from graphic with yellow stripe to the graphic without the yellow stripe.

But why doesn't it work for the other parts?

Code: Select all

//** -------------------- ID108 ZB ABe 130 -------------------- **//
spriteset(gr_abe_130_a,				"gfx/schmalspur/emus/ABe130.PNG"){tmpl_32_short(0,20)}					// Grafik A
spriteset(gr_abe_130_a_rev,			"gfx/schmalspur/emus/ABe130.PNG"){tmpl_32_short(0,60)}					// Grafik A backwards
spriteset(gr_abe_130_b,				"gfx/schmalspur/emus/ABe130.PNG"){tmpl_32_short(0,100)}				// Grafik B
spriteset(gr_abe_130_c,				"gfx/schmalspur/emus/ABe130.PNG"){tmpl_32_short(0,140)}				// Grafik C
spriteset(gr_abe_130_c_rev,			"gfx/schmalspur/emus/ABe130.PNG"){tmpl_32_short(0,180)}				// Grafik C backwards
spriteset(gr_abe_130_purch,			"gfx/schmalspur/emus/ABe130.PNG"){tmpl_purchase(0)}					// Grafik Purchase

switch(FEAT_TRAINS,SELF,sw_abe_130_articulated,extra_callback_info1){
    1..2: abe_130;
    CB_RESULT_NO_MORE_ARTICULATED_PARTS;
}

switch(FEAT_TRAINS,SELF,sw_gr_abe_130,position_in_consist_from_end % 3){
	0: gr_abe_130_c;
	1: gr_abe_130_b;
	gr_abe_130_a;
	}

switch(FEAT_TRAINS,SELF,sw_gr_abe_130_rev,position_in_consist_from_end % 3){
	0: gr_abe_130_a_rev;
	1: gr_abe_130_b;
	gr_abe_130_c_rev;
	}

switch (FEAT_TRAINS, SELF, sw_abe_130, vehicle_is_reversed ) {
0: sw_gr_abe_130;
sw_gr_abe_130_rev;
}	
		
switch(FEAT_TRAINS,SELF,sw_abe_130_ve,position_in_consist){
	1:visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC,0,ENABLE_WAGON_POWER);
	visual_effect_and_powered(VISUAL_EFFECT_DISABLE,2,DISABLE_WAGON_POWER);
}

item (FEAT_TRAINS,abe_130,108) {
	property {
		sprite_id:			SPRITE_ID_NEW_TRAIN;
		name:               string(STR_NAME_ABE_130);
		climates_available: bitmask(CLIMATE_TEMPERATE,CLIMATE_ARCTIC);
		introduction_date:  date(2004,5,15);
		model_life:			VEHICLE_NEVER_EXPIRES;
		speed:              100 km/h;
		cost_factor:		65;
		running_cost_factor:60;
		bitmask_vehicle_info: bitmask(1);
		running_cost_base:	RUNNING_COST_ELECTRIC;
		engine_class:		ENGINE_CLASS_ELECTRIC;
		visual_effect_and_powered: visual_effect_and_powered(VISUAL_EFFECT_ELECTRIC,-2,DISABLE_WAGON_POWER);
		track_type:			RT_ELNG;
		power:				1541 hp;
		cargo_capacity:		148;
		weight:				69 tons;
		tractive_effort_coefficient: 1;
		refittable_cargo_classes: bitmask(CC_PASSENGERS);
		non_refittable_cargo_classes: bitmask();
        cargo_allow_refit: [];
				}
	graphics{
	default: 			sw_abe_130;
	articulated_part: 	sw_abe_130_articulated;
	purchase: 			gr_abe_130_purch;
	visual_effect_and_powered: sw_abe_130_ve;
	additional_text: return string(STR_ADDITIONAL_TEXT_ABE_130);
	}
}
Last edited by Yoshi on 18 Apr 2014 20:55, edited 1 time in total.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: vehicle_is_reversed ... or not?

Post by PikkaBird »

The vehicle_is_reversed flag (var fe bit 8) is only accurate for the first vehicle in the consist, so the switch which tests it needs to be PARENT rather than SELF. :)
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not?

Post by Yoshi »

Thanks :bow:
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

Is it possible to get the vehicle ID and the subytpe from a vehicle at a specific position in the consist? ...something other_vehicle_type_id and other_vehicle_subtype...
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by PikkaBird »

It is possible in nfo, using var 61. It may not [yet] be possible in NML.

What specifically are you attempting to do? There may be other options.
Eddi
Tycoon
Tycoon
Posts: 8273
Joined: 17 Jan 2007 00:14

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Eddi »

it's not natively supported in nml yet, but you can use the var[0x61,...] way to access the info. also, if you're not in a fixed consist, make sure you check GRF-ID of the vehicle first
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by michael blunck »

Yoshi wrote: Is it possible to get the vehicle ID and the subytpe from a vehicle at a specific position in the consist?
What means "subtype of a vehicle"? Do you per chance mean "number of refits to the same cargo type"?

regards
Michael
Image
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

What specifically are you attempting to do? There may be other options.
CFL-DoSto.png
CFL-DoSto.png (4.16 KiB) Viewed 4385 times
I'm trying to add push/pull operation to that train. Engine and Cab car aren't the problem!
The coaches in the middle of the train have cargosubtypes/liveries with 1st and 2nd class.

When the train is reversed, the coaches have to look, which subtype the coach on the other side has:
So coach at third position_in_consist "asks" coach at third position_in_consist_from_end, what his subtype is.
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by michael blunck »

Yoshi wrote: I'm trying to add push/pull operation to that train. Engine and Cab car aren't the problem!
The coaches in the middle of the train have cargosubtypes/liveries with 1st and 2nd class.

When the train is reversed, the coaches have to look, which subtype the coach on the other side has:
So coach at third position_in_consist "asks" coach at third position_in_consist_from_end, what his subtype is.
Hehe, welcome in the push-pull circus! You should ask Snail about a general solution for this kind of "magic". :cool:

regards
Michael
Image
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

I'm already in the circus since DACH :)
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by michael blunck »

Yoshi wrote: I'm already in the circus since DACH :)
Not really, your questions about enhanced consist re-ordering are revealing it. :cool:

regards
Michael
Image
User avatar
Snail
Tycoon
Tycoon
Posts: 1283
Joined: 28 Apr 2003 18:52
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Snail »

Yoshi wrote:I'm trying to add push/pull operation to that train. Engine and Cab car aren't the problem!
The coaches in the middle of the train have cargosubtypes/liveries with 1st and 2nd class.

When the train is reversed, the coaches have to look, which subtype the coach on the other side has:
So coach at third position_in_consist "asks" coach at third position_in_consist_from_end, what his subtype is.
That's pretty easily achieved with var61, as suggested. Push-pull trains are not hard to code, just tedious :p

In the French set, this is already implemented both for regular trains and MUs:
Train pulled by a BB600 diesel. The coaches keep their visual appearance upon reversing
Train pulled by a BB600 diesel. The coaches keep their visual appearance upon reversing
ss pp 3.png (16.32 KiB) Viewed 4156 times
Two MUs of different types, attached, doing push-pull
Two MUs of different types, attached, doing push-pull
ss pp 1+2.png (12.28 KiB) Viewed 4156 times
It's very easy to code with m4nfo, and it works quite well. Unluckily, it only works if the consist is perfectly symmetric with respect to the wagons' lengths, since we can't change a vehicle's size outside of the depot.

What I find annoying, is that var61 only works with graphics and recoloring: it doesn't work, for example, with the power effects (I'm not referring to the fact that a vehicle "is powered" or not; I'm only referring to the diesel smoke, the steam puffs, and the electric bolts). So, if you have, say, a DMU in which some vehicles show diesel smoke and others don't, you can't "exchange" this visual effect upon reversing using var61. You need a workaround for that (I'm using userbits).
The French Narrow Gauge Train Set is now released! Get it here
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by michael blunck »

Snail wrote: [on pushing & pulling]
What we need is a proper implementation of "push-pull" in the game itself.

regards
Michael
Image
User avatar
Snail
Tycoon
Tycoon
Posts: 1283
Joined: 28 Apr 2003 18:52
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Snail »

michael blunck wrote: What we need is a proper implementation of "push-pull" in the game itself.
I agree. But how many years have we been repeating that for? :roll:
The French Narrow Gauge Train Set is now released! Get it here
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

Thanks for your informations!

Is there a var61 alternative in nml? I didn't found one ;(
Eddi
Tycoon
Tycoon
Posts: 8273
Joined: 17 Jan 2007 00:14

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Eddi »

there is not (yet), but you can access it direclty: http://newgrf-specs.tt-wiki.net/wiki/NM ... ted_syntax
Yoshi
Transport Coordinator
Transport Coordinator
Posts: 278
Joined: 21 Dec 2010 17:24

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Yoshi »

Thanks...
how is the correct usage of that?

I want to check the first vehicle in consist.

Code: Select all

switch (FEAT_TRAINS, SELF, sw_graphic, var[<num>, <shift>, <mask>, <param>] ) {
...
}
  • <num> = 61
  • <shift> = ?
  • <mask> = ?
  • <param> = 200 = C8 "Sprite type; FD for trains forward, FE or FF when reversed"
So the results are
FD,FE or FF? :D
michael blunck
Tycoon
Tycoon
Posts: 5948
Joined: 27 Apr 2005 07:09
Contact:

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by michael blunck »

No, <param> must be var "FE" (modflags), and you have to check bit 8.

[edit]
typo fixed. Note: var "FE" bit 8 is the same as var "FF" bit 0 ("FF" is simply the high 8 bits of var "FE").

And what Eddi said: you need to set temp register 0x10f, which is interpreted as offset (+ / -) from the current vehicle.
[/edit]

regards
Michael
Last edited by michael blunck on 15 Jun 2014 04:48, edited 1 time in total.
Image
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by planetmaker »

Yoshi wrote:Thanks...
how is the correct usage of that?

I want to check the first vehicle in consist.

Code: Select all

switch (FEAT_TRAINS, SELF, sw_graphic, var[<num>, <shift>, <mask>, <param>] ) {
...
}
  • <num> = 61
  • <shift> = ?
  • <mask> = ?
  • <param> = 200 = C8 "Sprite type; FD for trains forward, FE or FF when reversed"
So the results are
FD,FE or FF? :D
You find an example e.g. in NUTS: https://rhodecode.openttdcoop.org/nuts/ ... 0/nuts.nml (search for 0x61 - the 2nd occurance). You'll want to replace the variable 0x47 (random bits) by the one you need (0xFF). And iirc you want to use a mask of 0x01 with shift 0.
Eddi
Tycoon
Tycoon
Posts: 8273
Joined: 17 Jan 2007 00:14

Re: vehicle_is_reversed ... or not? AND Subtypes

Post by Eddi »

you also need to "STORE_TEMP(offset, 0x10F)" before accessing var61

if you want to figure out what to put as param/shift/mask, you can refer to the file nml/actions/action2var_variables.py of your nml installation (or the repository), and search for the variable's name. there you find something like

Code: Select all

    'vehicle_is_reversed'              : {'var': 0xFE, 'start':  8, 'size':  1}
you can now put in "var" into "param", "start" into "shift" and "2^size-1" into "mask".

note that reading var 0xFE and shifting by 8 is the same as reading var 0xFF and shifting by 0.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 5 guests