Cargo_capacity and "N/A" line in the train info window

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

Moderator: Graphics Moderators

Post Reply
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Cargo_capacity and "N/A" line in the train info window

Post by TadeuszD »

A few months (years?) ago I encountered small problem with cargo capacity information displayed in the train information window.
Example #1:
Articulated vehicle, all parts have the same ID, no refit option, only first part of vehicle can transport cargo:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_v1_capacity, position_in_vehid_chain%2) {
    0: return 48;
    return 0;
}
In this example OTTD displays correct capacity in the train window.

Example #2:
Vehicle from example #1, but cargo_subtype refit options are defined:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_v2_capacity, position_in_vehid_chain%2) {
    0: return 48;
    return 0;
}
switch(FEAT_TRAINS, SELF, switch_v2_subtype_text, cargo_subtype) {
    0: return string(STR_SUBTYPE_1);
    1: return string(STR_SUBTYPE_2);
    return CB_RESULT_NO_TEXT;
}
In this example OTTD displays strange additional line in the train info window, such as:

Code: Select all

empty
N/A
I don't understand why OTTD displays "N/A" depending on the refit option is on or off...
Typically, I use workaround to prevent displaying "N/A". You should leave at least 1 cargo unit in second part to do it:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_v2_capacity, position_in_vehid_chain) {
    0: return 48-1;
    return 1;
}
It works, but it looks like a tricky "hack" and has impact on loading speed... :?

But yesterday I tested the new example - articulated vehicle containing a few parts with different IDs and different cargo classes. Additionaly, cargo_subtype refit options are defined for this vehicle.
In this example the information displayed in the train info window looks totally unpredictable... :(
Where can I find the rules of collecting and displaying such information in train window?
Last edited by TadeuszD on 16 Jul 2014 11:36, edited 1 time in total.
Image
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Cargo_capacity and "N/A" line in the train info window

Post by Transportman »

What happens when you try to use the PARENT scope for the subtypes instead of SELF?

Also, on all your code examples, you would get unwanted behavior with multiple sets behind each other as you don't use a modulus (%) in your switch expression. Instead of Engine-Articulated-Engine-Articulated it would behave as Engine-Articulated-Articulated-Articulated for everything you use that switch block for.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: Cargo_capacity and "N/A" line in the train info window

Post by TadeuszD »

Transportman wrote:What happens when you try to use the PARENT scope for the subtypes instead of SELF?.
I think, it is not good idea. I'm working with data of current vehicle, not the leading engine. And my problem is not caused by incorrect behavior of the vehicle or its visual glitches.
Simply put, I don't understand why OTTD displays this unexpected "N/A" line in the list of transported cargo? Maybe this is the simple rule, but I don't see it... :cry:
Transportman wrote:...you don't use a modulus (%) in your switch expression.
Thanks. Of course, I use '%' in my original code. Unfortunately, I have deleted this sign during simplifying the example code... Corrected.
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Cargo_capacity and "N/A" line in the train info window

Post by frosch »

Maybe it's a bug in OpenTTD :p

Can you post the GRF which causes the two lines "empty N/A" to FlySpray?
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 8 guests