Hi Garry,
I have made some readable comments for my "functions" part of codes for you.
First of all, "Bitmask Sheet" for all these functions:
Code: Select all
/*
BITMASK SHEET
The sheet was defined by John Franklin.
bitmask(0): reserved
bitmask(1): restaurant car
bitmask(2): air conditioner
bitmask(3): conductor car
bitmask(4): brake van
For example,
bitmask_vehicle_info: bitmask(1, 3);
May be used for a restaurant + conductor combined car.
*/
// Electric Engines MUST BE ELECTRIFIED to supply electricity
switch (FEAT_TRAINS, SELF, airconditioner, vehicle_is_powered) {
1: return bitmask(2);
return 0;
}
Next, "Running Cost Factor":
Code: Select all
// Running cost factor depending on speed (NOTICE: NML only recognises m/s in these switch blocks)
// Max Speed < 75 km/h (Slow early trains)
switch (FEAT_TRAINS, SELF, runningcost60, current_speed) {
0: return 1; // Stationary, basis * 1
1..3: return 2; // < 10 km/h, basis * 2
4..6: return 3; // 10-20 km/h, basis * 3
7..10: return 4; // 20-40 km/h, basis * 4
return 5; // > 40 km/h, basis * 5
}
// Max Speed 75-110 km/h (Not so slow, but still not fast)
switch (FEAT_TRAINS, SELF, runningcost80, current_speed) {
0: return 1; // Stationary, basis * 1
1..5: return 2; // < 20 km/h, basis * 2
6..12: return 3; // 20-45 km/h, basis * 3
13..20: return 4; // 45-75 km/h, basis * 4
return 5; // > 75 km/h, basis * 5
}
// Max Speed 110-145 km/h (Regularly fast in Australia)
switch (FEAT_TRAINS, SELF, runningcost120, current_speed) {
0: return 1; // Stationary, basis * 1
1..8: return 2; // < 30 km/h, basis * 2
9..19: return 3; // 30-70 km/h, basis * 3
20..30: return 4; // 70-110 km/h, basis * 4
return 5; // > 110 km/h, basis * 5
}
// Max Speed 145-180 km/h (Very fast in Australia)
switch (FEAT_TRAINS, SELF, runningcost160, current_speed) {
0: return 1; // Stationary, basis * 1
1..12: return 2; // < 45 km/h, basis * 2
13..26: return 3; // 45-95 km/h, basis * 3
27..40: return 4; // 95-145 km/h, basis * 4
return 5; // > 145 km/h, basis * 5
}
// Max Speed 180-220 km/h (Fastest trains in Australia)
switch (FEAT_TRAINS, SELF, runningcost200, current_speed) {
0: return 1; // Stationary, basis * 1
1..15: return 2; // < 55 km/h, basis * 2
16..32: return 3; // 55-115 km/h, basis * 3
33..50: return 4; //115-180 km/h, basis * 4
return 5; // > 180 km/h, basis * 5
}
// Max Speed > 220 km/h (Currently non-existent in Australia)
switch (FEAT_TRAINS, SELF, runningcost250, current_speed) {
0: return 1; // Stationary, basis * 1
1..18: return 2; // < 65 km/h, basis * 2
19..39: return 3; // 65-140 km/h, basis * 3
40..60: return 4; //140-220 km/h, basis * 4
return 5; // > 220 km/h, basis * 5
}
// Now using the composed function to call different functions depending on the maximum speed of a specific train
switch (FEAT_TRAINS, SELF, runningcostfactor, max_speed) {
0..20: runningcost60; // < 75 km/h
21..30: runningcost80; // 75-110 km/h
31..40: runningcost120; // 110-145 km/h
41..50: runningcost160; // 145-180 km/h
51..60: runningcost200; // 180-220 km/h
runningcost250; // > 220 km/h (currently non-existent in Australia)
}
// Another running cost factor depending on the existence of restaurant car, which halves the runing costs of passenger cars.
switch (FEAT_TRAINS, PARENT, cafecostfactor, hasbit(bitmask_consist_info, 1)) {
1: return 1;
return 2;
}
// Running cost factor of AC Generator Cars (and also locomotives able to supply electricity for cars) varies according to the number of cars with need of air condition (including some passenger cars and a few refrigerator wagons)
// The costs are not coded into AC Generator Cars, but into cars with need of AC.
switch (FEAT_TRAINS, PARENT, accostfactor, hasbit(bitmask_consist_info, 2)) {
1: return 2;
return 0;
}
Then, "Cargo Age Period":
Code: Select all
// Cargo age period factor depending on Restaurant Car: attaching restaurant car increases cargo age period of medium and long range passenger cars (i.e. not commuter cars) by 1/4
switch (FEAT_TRAINS, PARENT, cafedecayfactor, hasbit(bitmask_consist_info, 1)) {
1: return 5;
return 4;
}
// Cargo age period factor depending on Air Conditioner: (SUIT THE CONDITION IN AUSTRALIA) using air conditioner increases cargo age period of passenger cars by 1/4
switch (FEAT_TRAINS, PARENT, acdecayfactor, hasbit(bitmask_consist_info, 2)) {
1: return 5;
return 4;
}
And an example for you to understand:
Code: Select all
/*
For example:
graphics {
running_cost_factor: 6 * runningcostfactor() * cafecostfactor() + accostfactor();
^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^
basis current speed restaurant car air condition
purchase_running_cost_factor: 20 * 4;
bitmask_vehicle_info: bitmask(2);
^^^^^^^^^^
air conditioner
cargo_age_period: 10 * cafedecayfactor() * acdecayfactor() << param_cargo_decay;
^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
basis restaurant car air condition parameters, see below
}
Can simulate a 2nd-class passenger coach.
NOTICE: THESE CAN ONLY BE CODED INTO graphics{} BLOCKS SINCE ONLY IN THIS TYPE OF BLOCKS CAN NML HANDLE SWITCH BLOCKS.
IF CODED INTO property{} BLOCKS, NML WILL REPORT ERROR AND FAIL.
For running_cost_factor line, it is advised to add "purchase_running_cost_factor" line and type a value of (basis * 4), since the average running cost factor is estimated to be four times basis.
For electric engines and EMUs, it is better to use the aforementioned "airconditioner" to simulate electric engines MUST BE ELECTRIFIED to supply electricity, unless there is a big battery inside.
For cargo_age_period line, 10 is a good basis for an 2nd coach. 3rd could be 8, 1st could be 12-15, and sleepers could be 20.
"param_cargo_decay" is a new parameter to double or quadruple cargo_age_period to better play on large maps. Default is 0, which just does nothing. 1 means double, and 2 means quadruple.
In fact, given some small positive integers M and N, "M << N" generally means "M times 2 to the power N" (M * 2^N), given that the result is less than 65535.
When the basis is set to 10 (2nd coach), the cargo_age_period would be 160 without air conditioner and restaurant, 200 with either air conditioner or restaurant, and 250 with both.
Comparison: the default cargo_age_period value for all vehicles is 185.
And uncomfortable 3rd coach would be 128, 160, 200, accordingly.
Luxury 1st coach, if basis set to 12, would be 192, 240, 288, accordingly.
Sleepers would be 320, 400, 500, accordingly, which could be rather comfort.
These values could be doubled or quadrupled by the new parameter.
*/