Push-Pull Trains in NML

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

Moderator: Graphics Moderators

Post Reply
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Push-Pull Trains in NML

Post by Leanden »

Hi,

Due to an ever increasing demand to make the trains in BRSet push pull, could someone in the know point me to a technical document or tutorial for NML on how to create DVT/Brake Vans which make a train into a push pull, ideally with sprite replacement rather than masking of the lights.
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Push-Pull Trains in NML

Post by frosch »

I assume you mean swapping the graphics of the front and rear vehicle when a train reverses in a station.

To do that, put a switch into the graphics chain of both the lead and the rear vehicle.

Code: Select all

switch(FEAT_TRAINS, PARENT, sw_front_vehicle, vehicle_is_reversed){
 0: sw_front_graphics;
 default: sw_rear_graphics;
}
switch(FEAT_TRAINS, PARENT, sw_rear_vehicle, vehicle_is_reversed){
 0: sw_rear_graphics;
 default: sw_front_graphics;
}
The switches swap the graphics for front and rear vehicle. Important in the switch is the usage of "PARENT".
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Push-Pull Trains in NML

Post by Leanden »

Perfect, i can adapt this to merely change the order of the consist :D
Image
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: Push-Pull Trains in NML

Post by Eddi »

mind you that this seemingly simple method quickly escalates if you use vehicles of different lengths in the same consist.

and you completely lost if vehicles from different NewGRFs are mixed.
REISCOOL
Traffic Manager
Traffic Manager
Posts: 218
Joined: 08 Apr 2007 11:12
Location: Kentucky

Re: Push-Pull Trains in NML

Post by REISCOOL »

Following the above setup, I've added a pushpull to my set, however I've encountered 2 problems

1. The locomotive I am using can be used with an explicit livery refit, or a random livery choice on purchase. If I use a livery refit, the correct graphics show up on the opposite end when reversed - if I use the random selection, the two ends don't match; that is, the cabcar makes a separate random choice instead of using the lead unit's graphics. I've made a separate random_switch for the cabcar to choose locomotive graphics and made that random_switch dependent on the locomotive's random_switch, but that doesn't seem to fix the problem.

2. The cabcar is defined as a special case of the base coach. I have a livery_override on the locomotive that redirects the coach graphics through a switch to put the cabcar graphics (or a copy of the lead loco when reversed as per question 1) on the last unit of the consist. However, I cannot figure out how to do the same for the locomotive. Is there a way for a locomotive to determine what coaches it is pulling, since I only want the pushpull operation with this specific set of coaches - the locmotive is not a dedicated pushpull, just a general purpose unit with the facilities for pushpull operation.
I've tried running the loco graphics through this switch:

Code: Select all

switch(FEAT_TRAINS, PARENT, switch_cbatelec_ispushpull, vehicle_type_id){
 04: switch_cbatelec_gfx_t7_cabcar;
 switch_ncr_cbatelec_livery_select;
}
I have the graphics line for the loco reference this switch. the coaches are set as vehicle_id 04 [that is, item(FEAT_TRAINS, item_ncr_t7_bilev, 04) in case I've just defined the vehicle id wrong here]. switch_cbatelec_gfx_t7_cabcar is a reverse of the coach graphics selection, switch_ncr_cbatelec_livery_select is the normal livery selection for the loco. In game (OTTD 1.6.1), this doesn't seem to do anything, and the loco never changes its graphics on reverse

EDIT: I've figured out question 2.

Code: Select all

switch(FEAT_TRAINS, PARENT, switch_cbatelec_ispushpull, count_veh_id(04)){
 0: switch_ncr_cbatelec_livery_select;
 switch_cbatelec_gfx_t7_cabcar;
}
works to put the cabcar graphics on the loco only when the correct stock is used.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 19 guests