How to check for a specific wagon ID relative to vehicle?

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

Moderator: Graphics Moderators

Post Reply
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

How to check for a specific wagon ID relative to vehicle?

Post by Erato »

Hi!

I want to make a mail car to fit neatly with some passenger cars I made, without having to implement the mail cars as different refits, because of compatibility reasons. Below there's an illustration to help explain what I mean.
So if we take setup a as a basis, where blue indicates a locomotive, green is the mail car and red is the passenger car, then what I want is I want the front-most car that is not a locomotive to have a certain pattern to indicate that it is the front-most one, indicated by the yellow stripes, as shown in b. This should not depend on where the chain starts, as shown in c. I want this to happen regardless of whether it's a mail car or a passenger car, as shown in d.

How I was thinking of implementing it: the cars (both red and green) check what the ID of the entity in front of it is, which would result in a switch like:

Code: Select all

switch(FEAT_TRAINS, SELF, SWITCH_STRIPES_RED, other_vehicle_type_id(-1)) {//Check ID of wagon in front of this one
	ID_GREEN:	SPRITESET_RED;
	ID_RED:		SPRITESET_RED;//If the wagon in front is red or green, use normal sprite
	SPRITESET_RED_STRIPES;//If the wagon in front is not green nor red, use sprite with yellow stripes
}
So here's the problem. I can't find any variable that could do this in the documentation.

Image
a: Setup without this feature (unwanted)
b: Example setup with one locomotive
c: Example setup with two locomotives
d: Example setup with green in the back

This should obviously also work using just the red ones, or just the green ones
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: How to check for a specific wagon ID relative to vehicle?

Post by Transportman »

There is no NML variable you can use, so you need to fall back on the old style variables and some other "magic" to get the ID of the vehicle in front of the actual wagon you want to check.

I did something related to this in the 2cc TrainsInNML, to check if wagons could be added to a train based on the ID of the vehicle in front, see here, with the ID-ranges being defined here. It has been some time since I worked on that part of the code, so I'm not really sure about the "magic" involved, I just know that it works.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: How to check for a specific wagon ID relative to vehicle?

Post by Erato »

Transportman wrote: 22 Nov 2019 18:51 There is no NML variable you can use, so you need to fall back on the old style variables and some other "magic" to get the ID of the vehicle in front of the actual wagon you want to check.

I did something related to this in the 2cc TrainsInNML, to check if wagons could be added to a train based on the ID of the vehicle in front, see here, with the ID-ranges being defined here. It has been some time since I worked on that part of the code, so I'm not really sure about the "magic" involved, I just know that it works.
Ah yes. I remember using that code. Let's just say it helped. And that's nice, because there is no documentation at all as to what the

Code: Select all

var[0x61, 0, 0x0000FFFF, 0xC6]
does. The code used in 2cc only looks at the very last vehicle, had to figure out that 0x61 can be used to get the ID of trains at a position relative to the train the switch is for by saving -1 to 0x10F.

Image

Code: Select all

switch(FEAT_TRAINS,SELF,switch_RED_WAG,[STORE_TEMP(-1, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]){
    RANGE_PASS3: switch_RED_WAG;
    RANGE_MAIL3: switch_RED_WAG;
    SPRITESET_RED_WAG_B;
}
Thanks!
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: How to check for a specific wagon ID relative to vehicle?

Post by Transportman »

True, the code I use is a bit different because it is looking from the wagon being attached, but the train it is being attached to (as the wagon is not attached at the moment my callback is called). In your case, the wagon is attached and can use the SELF scope in the switch to look at the wagon in front of it.
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: audigex, Google Adsense [Bot] and 2 guests