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
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;
}
}