Skip to content

Commit

Permalink
Add: support for extended refit properties
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 authored and andythenorth committed Nov 23, 2024
1 parent b8b7da5 commit 3c66104
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions nml/actions/action0properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,29 @@ def zero_refit_mask(prop_num):
return {"size": 4, "num": prop_num, "value_function": lambda value: ConstantNumeric(0)}


def refittable_cargo_classes(prop_or_num, prop_and_num, refit_mask_num):
def prop_value(value, index):
if isinstance(value, ConstantNumeric):
return value if index == 0 else None
if isinstance(value, Array) and len(value.values) == 2 and isinstance(value.values[index], ConstantNumeric):
return value.values[index]
raise generic.ScriptError("refittable_cargo_classes must be a constant or an array of 2 constants")

def prop_test(value):
return value is not None

return [
{"size": 2, "num": prop_or_num, "value_function": lambda value: prop_value(value, 0)},
{
"size": 2,
"num": prop_and_num,
"value_function": lambda value: prop_value(value, 1),
"test_function": prop_test,
},
zero_refit_mask(refit_mask_num),
]


#
# Feature 0x00 (Trains)
#
Expand Down Expand Up @@ -440,7 +463,7 @@ def zero_refit_mask(prop_num):
"bitmask_vehicle_info": {"size": 1, "num": 0x25},
"retire_early": {"size": 1, "num": 0x26},
"misc_flags": {"size": 1, "num": 0x27},
"refittable_cargo_classes": [{"size": 2, "num": 0x28}, zero_refit_mask(0x1D)],
"refittable_cargo_classes": refittable_cargo_classes(0x28, 0x32, 0x1D),
"non_refittable_cargo_classes": [{"size": 2, "num": 0x29}, zero_refit_mask(0x1D)],
"introduction_date": {"size": 4, "num": 0x2A},
"cargo_age_period": {"size": 2, "num": 0x2B},
Expand Down Expand Up @@ -514,7 +537,7 @@ def prop15_test(value):
"refit_cost": {"size": 1, "num": 0x1A},
"retire_early": {"size": 1, "num": 0x1B},
"misc_flags": {"size": 1, "num": 0x1C},
"refittable_cargo_classes": [{"size": 2, "num": 0x1D}, zero_refit_mask(0x16)],
"refittable_cargo_classes": refittable_cargo_classes(0x1D, 0x29, 0x16),
"non_refittable_cargo_classes": [{"size": 2, "num": 0x1E}, zero_refit_mask(0x16)],
"introduction_date": {"size": 4, "num": 0x1F},
# 20 (sort purchase list) is implemented elsewhere
Expand Down Expand Up @@ -605,7 +628,7 @@ def prop23_test(value):
"retire_early": {"size": 1, "num": 0x16},
"misc_flags": {"size": 1, "num": 0x17},
"refittable_cargo_classes": [{"size": 2, "num": 0x18}, zero_refit_mask(0x11)],
"non_refittable_cargo_classes": [{"size": 2, "num": 0x19}, zero_refit_mask(0x11)],
"non_refittable_cargo_classes": refittable_cargo_classes(0x19, 0x25, 0x11),
"introduction_date": {"size": 4, "num": 0x1A},
# 1B (sort purchase list) is implemented elsewhere
# 1C has two names, to simplify docs
Expand Down Expand Up @@ -668,7 +691,7 @@ def aircraft_is_large(value):
"refit_cost": {"size": 1, "num": 0x15},
"retire_early": {"size": 1, "num": 0x16},
"misc_flags": {"size": 1, "num": 0x17},
"refittable_cargo_classes": [{"size": 2, "num": 0x18}, zero_refit_mask(0x13)],
"refittable_cargo_classes": refittable_cargo_classes(0x18, 0x23, 0x13),
"non_refittable_cargo_classes": [{"size": 2, "num": 0x19}, zero_refit_mask(0x13)],
"introduction_date": {"size": 4, "num": 0x1A},
# 1B (sort purchase list) is implemented elsewhere
Expand Down

0 comments on commit 3c66104

Please sign in to comment.