[NML] Vehicle callback issues

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

Moderator: Graphics Moderators

Post Reply
User avatar
Valdez
Traffic Manager
Traffic Manager
Posts: 187
Joined: 23 Mar 2011 21:33
Location: Czech Republic

[NML] Vehicle callback issues

Post by Valdez » 02 Sep 2019 07:28

Hello everybody..

I've been trying my luck with GRF coding in NML lately. I have something that I've been working on for the past ~2 weeks
snap.PNG
snap.PNG (14.84 KiB) Viewed 347 times
The first Metro unit is assembled from individual engines, and does not pose a problem.
The rest are doubleheaded with powered center carriages. I can get those working as well, but I have an issue with capacity and TE coefficient callbacks for the center carriage.

Intended behaviour: Center carriage changes its capacity and TE depending on the unit it's coupled to, has capacity and TE set to zero when coupled to anything that isn't a Metro unit.

Actual behaviour: Capacity and TE correctly sets to zero when coupled to engines that aren't Metro units, but for Metro units the callback returns are ignored and the values from property block are used instead.

Code for the center motor carriage (please excuse the odd mishmash of Czech and English in the comments)

Code: Select all

// Spritesety Metro_center_car
spriteset (set_MT_Center_default,       "gfx/ML_8171.png") { tmpl_7x12(0,72) }
spriteset (set_MT_Center_purchase,      "gfx/Purchase.png") { tmpl_purchase(0,80) }

// Switch kapacity
switch (FEAT_TRAINS, PARENT, sw_MT_Center_capacity, vehicle_type_id) {
          ML_8171:            return 165;
          ML_8171M:           return 157;
          ML_M1:              return 174;
          return 0;
          }
          
// Switch TE coeff.
switch (FEAT_TRAINS, PARENT, sw_MT_Center_TEC, vehicle_type_id) {
          ML_8171:            return 30;
          ML_8171M:           return 33;
          ML_M1:              return 33;
          return 0;
          }
          
//Definice traileru
item (FEAT_TRAINS, MT_Center) {
          property {
                    name:                         string(STR_NAME_MT_Center);
                    climates_available:           ALL_CLIMATES;
                    introduction_date:            date(1976,01,01);
                    model_life:                   VEHICLE_NEVER_EXPIRES;
                    cost_factor:                  10;       //temp
                    running_cost_factor:          10;       //temp
                    sprite_id:                    SPRITE_ID_NEW_TRAIN;
                    speed:                        80 km/h;
                    track_type:                   RT_METRO;
                    running_cost_base:            RUNNING_COST_ELECTRIC;
                    weight:                       26 tons;
                    power:                        0 kW;
                    length:                       7;
                    refittable_cargo_classes:     bitmask(CC_PASSENGERS);
                    non_refittable_cargo_classes: bitmask();
                    cargo_capacity:               152;      //callback
                    tractive_effort_coefficient:  0.1176;   //callback
                    loading_speed:                180;
                    cargo_age_period:             165;
          }
          graphics {
                    default:                      set_MT_Center_default;
                    purchase:                     set_MT_Center_purchase;
                    additional_text:              return string(STR_ADTEXT_MT_Center);
                    cargo_capacity:               sw_MT_Center_capacity;
                    tractive_effort_coefficient:  sw_MT_Center_TEC;
          }
}
Oh.. and on a tangentially related note.. is there a way to change display of the purchase sprite so that it shows only for the leading unit in doubleheaded engines? Even when I set the purchase template so that it only shows transparent pixel in the -> direction, the purchase sprite is misaligned (Ečs is assembled from individual engines, 81-71 is double-headed)
Derrrp2.PNG
Derrrp2.PNG (1.92 KiB) Viewed 347 times
My visits on the forums are sporadic only, so PMs may go unanswered for a long time. If you wish to report a bug etc., the best option is via DM or ping on r/Openttd Discord

User avatar
Erato
Route Supervisor
Route Supervisor
Posts: 422
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: [NML] Vehicle callback issues

Post by Erato » 02 Sep 2019 07:37

The reason you're getting 0 for the TE and capacity is because in the switches, you're checking for vehicle_type_id, and if you don't manually set the ID (which you do by having a third argument in item(), i.e. item(feature, name, ID),) you cannot reference these. Try to see if it works if you add this third argument and refer to those instead.

As for the purchase sprite for the dual headed train: they need a different template with a different offset.
No pics no clicks. Seriously. Also stop using Modern Maglev Trains. Use RIMS instead.
ImageImageImageImageImageImage

User avatar
Valdez
Traffic Manager
Traffic Manager
Posts: 187
Joined: 23 Mar 2011 21:33
Location: Czech Republic

Re: [NML] Vehicle callback issues

Post by Valdez » 02 Sep 2019 08:01

As for the first part..

I will try that, but I think (in my next to nonexistent experience, haha) that if this were the issue I'd get 0 capacity even when coupled to the Metro units (which I don't, I get the value from property block instead), not to mention that I used these internal IDs in other vehicle_type_id checks without an issue until now (although those were can_attach_wagon callbacks).

Perhaps the internal IDs are sufficient to tell that this isn't a default return, but to return an actual numerical value I'd have to set the ID number manually..

As for the second, thanks for the tip, will do.


EDIT: Confirmed, vehicle IDs are NOT the reason behind this callback behaviour. No change in vehicle behaviour.
My visits on the forums are sporadic only, so PMs may go unanswered for a long time. If you wish to report a bug etc., the best option is via DM or ping on r/Openttd Discord

User avatar
Valdez
Traffic Manager
Traffic Manager
Posts: 187
Joined: 23 Mar 2011 21:33
Location: Czech Republic

Re: [NML] Vehicle callback issues

Post by Valdez » 02 Sep 2019 20:53

SOLVED

for future reference:
callbacks don't do squat for vehicles with livery override
better set those properties throught the livery override itself
if I need to set a vehicle to have a 0 capacity unless it has a livery override, I should do it via callback

Code: Select all

cargo_capacity: return 0;
thanks Gwyd and Erato
My visits on the forums are sporadic only, so PMs may go unanswered for a long time. If you wish to report a bug etc., the best option is via DM or ping on r/Openttd Discord

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 4 guests