Problem with cargo_age_period

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

Problem with cargo_age_period

Post by TadeuszD »

Hi, I need some help with cargo_age_period mechanism.
I created in my trainset special kind of passenger cars - restaurant car. According to my idea, this car should increase cargo_age_period for all other passenger cars in the consist. I coded this idea using bitmask_consist_info.
At the first some definitions:

Code: Select all

#define VINFO_PASSENGER_WAGON       0
#define VINFO_LUGGAGE_WAGON         3
#define VINFO_RESTAURANT_WAGON      4

#define VINFO_WAGON_BONUS           bitmask(VINFO_LUGGAGE_WAGON, VINFO_RESTAURANT_WAGON)
Restaurant car sets special flags in bitmask_vehicle_info:

Code: Select all

item(FEAT_TRAINS, item_wrmnouz) {
    property {
    ...
    bitmask_vehicle_info:           bitmask(VINFO_PASSENGER_WAGON, VINFO_RESTAURANT_WAGON);
    }
}
Passenger cars calculate cargo_age_period by using this switch:

Code: Select all

switch(FEAT_TRAINS, SELF, switch_cargo_age_period, bitmask_consist_info & VINFO_WAGON_BONUS) {
    bitmask(VINFO_LUGGAGE_WAGON): return _cargo_age_period_luggage_value_;
    bitmask(VINFO_RESTAURANT_WAGON): return _cargo_age_period_restaurant_value_;
    bitmask(VINFO_LUGGAGE_WAGON, VINFO_RESTAURANT_WAGON): return _cargo_age_period_all_value_;
    return _cargo_age_period_normal_value_;
}
In my opinion described code looks good. I don't see logical problems. But my testers inform me, that cargo_age_period for passenger cars depends on position of the restaurant car in the consist. If the restaurant car is at the begining of the consist, the overall income is lower. If the restaurant car is at the end of the consist, the overall income is higher. It suggest that the cargo_age_period is not recalculated correctly for all vehicles in the consist.
How it is possible? When the switch cargo_age_period is triggered?
I checked expression (bitmask_consist_info & VINFO_WAGON_BONUS) using different sprites for passenger cars and it works - all passenger cars "see" the restaurant car flags wherever he is.

Here is screenshot from tests. All trains are identical except position of the restaurant car. You can see different incomes:

Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Problem with cargo_age_period

Post by frosch »

Code: Select all

switch(FEAT_TRAINS, SELF, switch_cargo_age_period, bitmask_consist_info & VINFO_WAGON_BONUS) {
You need to use "PARENT" scope instead of "SELF" scope here.
With "SELF" scope it will only consider the bitmask of the current vehicle until the end of train, but no vehicles in front.
With "PARENT" it uses the bitmask of all vehicles.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
TadeuszD
Transport Coordinator
Transport Coordinator
Posts: 329
Joined: 07 Nov 2011 19:32
Location: PL

Re: Problem with cargo_age_period

Post by TadeuszD »

frosch wrote:You need to use "PARENT" scope instead of "SELF" scope here..
Thanks, you're right. I found our last discussion from two years ago: viewtopic.php?f=68&t=48891&p=1141951&hi ... o#p1141951
I think, this information is very important and should be described in NML specification.
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 8 guests