https://newgrf-specs.tt-wiki.net/wiki/N ... _variables
The only variables with "power" in them are "vehicle_is_powered", "vehicle_is_not_powered" and "vehicle_is_potentially_powered".
I ran into this issue as well when making variable running costs for 2cc in NML. You have to provide those values hardcoded for the vehicle in question.
I.E:
Code: Select all
// Dynamic running cost for locomotive.
switch(FEAT_TRAINS, PARENT, switch_dmu_Germany_DB_VT_040_Flying_Hamburger_locomotive_running_cost_factor, [STORE_TEMP(25, 0)]) {
switch_locomotive_running_cost_factor;
}
I am storing the value '25' in temporary storage zero.
Code: Select all
// Dynamic running cost for locomotive.
switch(FEAT_TRAINS, PARENT, switch_locomotive_running_cost_factor,
[STORE_TEMP(param_locomotive_running_cost == 0 ? 0 : LOAD_TEMP(0) * 10000 / (10000 / param_locomotive_running_cost) / 100, 1),
STORE_TEMP(param_running_cost_dynamic_idle_percentage == 0 ? 0 : LOAD_TEMP(1) * 10000 / (10000 / param_running_cost_dynamic_idle_percentage) / 100, 2),
STORE_TEMP(
param_locomotive_running_cost_dynamic == 2 ? 200 :
param_locomotive_running_cost_dynamic == 3 ? 50 :
param_locomotive_running_cost_dynamic == 4 ? 10 :
param_locomotive_running_cost_dynamic == 5 ? 2 : 1
, 3),
param_locomotive_running_cost_dynamic]) {
0: max(0, LOAD_TEMP(1));
1: max(0, max(LOAD_TEMP(2), current_speed * 100 / max_speed * LOAD_TEMP(1) / 100));
2..5: switch_running_costs_dynamic_curve;
6: max(0, current_speed < 1 ? LOAD_TEMP(2) : current_speed < current_max_speed ? LOAD_TEMP(1) * 150 / 100 : LOAD_TEMP(1));
}
And i am loading that value in that switch and doing a "diminishing returns" (basically the same as 1 / n where 'n' is a setting in the grf as a running cost percentage) on it and store that calculation in temp register 1.
Then i figure out what the idle running cost will be, using temp 1's value, and store that in temp 2.
The actual "diminishing returns" formula is using temp 3's value for 'linearity factor' and is in another switch:
Code: Select all
switch(FEAT_TRAINS, PARENT, switch_running_costs_dynamic_curve, 0) {
return max(0,
max(LOAD_TEMP(2),
min(LOAD_TEMP(1),
(LOAD_TEMP(1) + 1) *
((1000000 - LOAD_TEMP(3) * 1000000 / (current_speed + LOAD_TEMP(3))) /
(1000 - LOAD_TEMP(3) * 1000 / (max_speed + LOAD_TEMP(3)))) / 1000
)));
}
Which produces a nice curve where running costs go up rapidly at low speeds and level off towards the vehicles designed max speed.
Either way, you have to provide those hardcoded values as they don't exist in variables unfortunately. You can ofc abuse the CCompiler for this using define statements. Or, you could do what i did and simply write a piece of software that fetches whatever value there currently is and writes the appropriate switches for each vehicle as in the first code block above.
You can find my application here:
https://github.com/TheCadde/OTTD-2cc-in ... eplacement
Though obviously it's aimed at 2CC trainset in NML. But the general idea is there.