Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: add vehicle 'refit' callback (cb 0x163) and cargo class filter prop (0x28 for trains etc) #344

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -604,7 +627,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)],
"refittable_cargo_classes": refittable_cargo_classes(0x18, 0x25, 0x11),
"non_refittable_cargo_classes": [{"size": 2, "num": 0x19}, zero_refit_mask(0x11)],
"introduction_date": {"size": 4, "num": 0x1A},
# 1B (sort purchase list) is implemented elsewhere
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
1 change: 1 addition & 0 deletions nml/actions/action3_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'sound_effect' : {'type': 'cb', 'num': 0x33, 'flag_bit': 7},
'refit_cost' : {'type': 'cb', 'num': 0x15E, 'purchase': 1},
'name' : {'type': 'cb', 'num': 0x161, 'flag_bit': 8, 'purchase': 2},
'refit' : {'type': 'cb', 'num': 0x163, "purchase": 2},
}

# Function to convert vehicle length to the actual property value, which is (8 - length)
Expand Down
Loading