Page 1 of 2

vehicle_is_reversed ... or not? AND Subtypes

Posted: 18 Apr 2014 19:08
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 4968 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);
	}
}

Re: vehicle_is_reversed ... or not?

Posted: 18 Apr 2014 19:13
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. :)

Re: vehicle_is_reversed ... or not?

Posted: 18 Apr 2014 19:37
by Yoshi
Thanks :bow:

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 18 Apr 2014 21:00
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...

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 18 Apr 2014 21:11
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.

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 18 Apr 2014 21:13
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 19 Apr 2014 08:03
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 19 Apr 2014 08:26
by Yoshi
What specifically are you attempting to do? There may be other options.
CFL-DoSto.png
CFL-DoSto.png (4.16 KiB) Viewed 4875 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.

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 19 Apr 2014 08:33
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 19 Apr 2014 08:35
by Yoshi
I'm already in the circus since DACH :)

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 19 Apr 2014 09:01
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 22 May 2014 03:45
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 4646 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 4646 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).

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 22 May 2014 06:29
by michael blunck
Snail wrote: [on pushing & pulling]
What we need is a proper implementation of "push-pull" in the game itself.

regards
Michael

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 22 May 2014 12:58
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:

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 15:16
by Yoshi
Thanks for your informations!

Is there a var61 alternative in nml? I didn't found one ;(

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 15:39
by Eddi
there is not (yet), but you can access it direclty: http://newgrf-specs.tt-wiki.net/wiki/NM ... ted_syntax

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 18:34
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 19:45
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

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 21:03
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.

Re: vehicle_is_reversed ... or not? AND Subtypes

Posted: 14 Jun 2014 23:18
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.