Skip to content

Commit

Permalink
Codechange: integrate some revised cargo class approaches
Browse files Browse the repository at this point in the history
  • Loading branch information
andythenorth committed Oct 21, 2024
1 parent bf392a6 commit e2c8f10
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/iron_horse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import global_constants
import utils
from polar_fox.cargo_classes import cargo_classes

command_line_args = utils.get_command_line_args()

Expand Down Expand Up @@ -206,6 +207,8 @@ def main():
# globals *within* this module so they can be accessed externally by other modules using iron_horse.foo
globals()['railtype_manager'] = RailTypeManager()
globals()['roster_manager'] = RosterManager()
# we add the polar fox cargo_class_scheme to globals as it requires a TOML load and parse, which we don't want to do frequently
globals()['cargo_class_scheme'] = cargo_classes.CargoClassSchemes().default_scheme

# railtypes
for railtype_module_name in railtype_module_names:
Expand Down
38 changes: 31 additions & 7 deletions src/polar_fox/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,33 +143,42 @@
]

# shared lists of allowed classes, shared across multiple vehicle types
# !! CABBAGE PARTLY UPDATED OCT 2024 UNFINISHED
base_refits_by_class = {
"all_freight": [
"CC_BULK",
"CC_PIECE_GOODS",
"CC_ARMOURED",
"CC_COVERED_BULK",
"CC_EXPRESS",
"CC_FLATBED",
"CC_GAS",
"CC_LIQUID",
"CC_ARMOURED",
"CC_OPEN_BULK",
"CC_PIECE_GOODS",
"CC_POWDERIZED",
"CC_REFRIGERATED",
"CC_COVERED",
"CC_NON_POURABLE",
"CC_WEIRD",
],
"covered_hopper_freight": [], # explicit allowal by label instead
"dump_freight": ["CC_BULK"],
"cryo_gases": ["CC_GAS"],
"dump_freight": ["CC_OPEN_BULK"],
"empty": [],
"express_freight": ["CC_EXPRESS", "CC_ARMOURED"],
"flatbed_freight": ["CC_PIECE_GOODS"],
"flatbed_freight": ["CC_FLATBED"],
"liquids": ["CC_LIQUID"],
"mail": ["CC_MAIL"],
"packaged_freight": ["CC_PIECE_GOODS", "CC_EXPRESS", "CC_ARMOURED", "CC_LIQUID"],
"pax": ["CC_PASSENGERS"],
"refrigerated_freight": ["CC_REFRIGERATED"],
"silo_powders": ["CC_POWDERIZED"],
}

# generally we want to allow refit on classes, and disallow on labels (see disallowed_refits_by_label)
# BUT for _some_ specialist vehicle types, it's simpler to just allow refit by label
# !! CABBAGE NEEDS UPDATED OCT 2024 NOT CLEAR THESE ALL NEEDED !!
allowed_refits_by_label = {
# box cars get some extended cargos
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"box_freight": [
"BEAN",
"CMNT",
Expand All @@ -181,6 +190,8 @@
"WHEA",
],
# seems to be used by intermodal, otherwise chemicals tankers are deprecated in favour of product tankers
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"chemicals": [
"ACID",
"CHLO",
Expand All @@ -206,6 +217,8 @@
"ZINC",
],
# 'dirty' mine/quarry covered hopper cargos
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"covered_hoppers_mineral": [
"ALO_",
"BDMT",
Expand All @@ -225,12 +238,16 @@
],
# non-food cargos that need 'clean' covered hopper
# preference is not to overlap with mineral covered hoppers and farm hoppers (as they will be combined where needed)
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"covered_hoppers_pellet_powder": [
"CBLK",
"NHNO",
"PLAS",
"RUBR",
],
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"cryo_gases": [
"CHLO",
"H2__",
Expand All @@ -239,13 +256,17 @@
"O2__",
"WELD",
],
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"edible_liquids": [
"BEER",
"EOIL",
"FOOD",
"MILK",
"WATR",
],
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# !! some of these might be able to drop back to classes with FIRS 4 or 5
"farm_food_products": [
"BAKE",
"BEAN",
Expand All @@ -266,6 +287,7 @@
"TATO",
"WHEA",
],
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# for bolster wagon
"long_products": [
"ALUM",
Expand All @@ -288,6 +310,7 @@
"WOOD",
"ZINC",
],
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
# hax for intermodal container sprite selection - reefer car refits work just fine using CC_REFRIGERATED
"reefer": [
"FISH",
Expand All @@ -297,6 +320,7 @@
}

# rather than using disallowed classes (can cause breakage), specific labels are disallowed
# !! CABBAGE NEEDS UPDATED OCT 2024 - STILL NEEDED?
disallowed_refits_by_label = {
"non_dump_bulk": [
"WOOD",
Expand Down
43 changes: 32 additions & 11 deletions src/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import iron_horse
import spritelayer_cargos


class Consist(object):
"""
'Vehicles' (appearing in buy menu) are composed as articulated consists.
Expand Down Expand Up @@ -5306,7 +5305,8 @@ def __init__(self, **kwargs):
# tank cars are unrealistically autorefittable, and at no cost
# Pikka: if people complain that it's unrealistic, tell them "don't do it then"
super().__init__(**kwargs)
self.class_refit_groups = [] # no classes, use explicit labels
self.class_refit_groups = ["cryo_gases"]
# labels are for legacy support, prior to CC_GAS class; this left in place as of Oct 2024
self.label_refits_allowed = polar_fox.constants.allowed_refits_by_label[
"cryo_gases"
]
Expand Down Expand Up @@ -7983,7 +7983,8 @@ class SiloCarConsistBase(CarConsist):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.class_refit_groups = [] # no classes, use explicit labels
self.class_refit_groups = ["silo_powders"]
# labels are for legacy support, prior to CC_GAS class; this left in place as of Oct 2024
self.label_refits_allowed = [
"SUGR",
"FMSP",
Expand Down Expand Up @@ -8429,7 +8430,7 @@ def __init__(self, **kwargs):
# Pikka: if people complain that it's unrealistic, tell them "don't do it then"
# they may also change livery at stations if refitted between certain cargo types <shrug>
super().__init__(**kwargs)
self.class_refit_groups = ["liquids"]
self.class_refit_groups = ["liquids_non_food_grade"]
self.label_refits_allowed = []
self.label_refits_disallowed = polar_fox.constants.disallowed_refits_by_label[
"non_generic_liquids"
Expand Down Expand Up @@ -9623,20 +9624,40 @@ def get_extra_flags(self, unit_variant):

@property
def refittable_classes(self):
cargo_classes = []
result = []
# maps lists of allowed classes. No equivalent for disallowed classes, that's overly restrictive and damages the viability of class-based refitting
if hasattr(self, "articulated_unit_different_class_refit_groups"):
# in *rare* cases an articulated unit might need different refit classes to its parent consist
class_refit_groups = self.articulated_unit_different_class_refit_groups
else:
# by default get the refit classes from the consist
class_refit_groups = self.consist.class_refit_groups
for i in class_refit_groups:
[
cargo_classes.append(cargo_class)
for cargo_class in global_constants.base_refits_by_class[i]
]
return ",".join(set(cargo_classes)) # use set() here to dedupe
for class_refit_group in class_refit_groups:
for cargo_class in global_constants.base_refits_by_class[class_refit_group]:
if cargo_class in iron_horse.cargo_class_scheme.cargo_classes_taxonomy.keys():
result.append(
str(
iron_horse.cargo_class_scheme.cargo_classes_taxonomy[cargo_class]["bit_number"]
)
)
if cargo_class not in iron_horse.cargo_class_scheme.cargo_classes_taxonomy.keys():
print("CABBAGE", cargo_class)
# TEMP TO MAKE COMPILE WORK
result.append(cargo_class)
"""
classes_mapped_to_bit_numbers = []
for cargo_class in self.cargo_classes:
classes_mapped_to_bit_numbers.append(
str(
cargo_class_scheme.cargo_classes_taxonomy[cargo_class]["bit_number"]
)
)
return "bitmask(" + ",".join(classes_mapped_to_bit_numbers) + ")"
"""
# use set() here to dedupe
result = list(set(result))
print(self.id, result)
return ",".join(result)

@property
def loading_speed(self):
Expand Down

0 comments on commit e2c8f10

Please sign in to comment.