Skip to content

Commit

Permalink
Change: WIP on updating cargo classes to 2024 scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
andythenorth committed Oct 23, 2024
1 parent f30bca0 commit 7f98df2
Show file tree
Hide file tree
Showing 125 changed files with 195 additions and 158 deletions.
82 changes: 54 additions & 28 deletions src/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,60 @@ def __init__(self, id, **kwargs):

if len(self.economy_variations) == 0:
utils.echo_message(self.id + " is not used in any economy")
# validation
self.validate_cargo_classes()

def validate_cargo_classes(self):
# crude, not intended to solve everything
disallowed_pairs = [("CC_FOOD_GRADE", "CC_NON_FOOD_GRADE")]
for disallowed_pair in disallowed_pairs:
if (disallowed_pair[0] in self.cargo_classes) and (
disallowed_pair[1] in self.cargo_classes
):
raise BaseException(
self.id
+ " sets both "
+ disallowed_pair[0]
+ " and "
+ disallowed_pair[1]
+ " which is not supported"
)
for cargo_class in self.cargo_classes:
# CC_GAS doesn't bother validating for food-grade bits as of 2024, food-grade gases tends to not be relevant
if cargo_class in [
"CC_EXPRESS",
"CC_PIECE_GOODS",
"CC_OPEN_BULK",
"CC_COVERED_BULK",
"CC_LIQUID",
"CC_POWDERIZED",
]:
if ("CC_FOOD_GRADE" not in self.cargo_classes) and (
"CC_NON_FOOD_GRADE" not in self.cargo_classes
):
raise BaseException(
self.id
+ " should set one of CC_FOOD_GRADE or CC_NON_FOOD_GRADE"
)
if cargo_class in ["CC_GAS", "CC_COVERED_BULK", "CC_POWDERIZED", "CC_FLATBED"]:
if (
("CC_PIECE_GOODS" not in self.cargo_classes)
and ("CC_OPEN_BULK" not in self.cargo_classes)
and ("CC_LIQUID" not in self.cargo_classes)
):
raise BaseException(
self.id
+ " should have a fallback set (CC_PIECE_GOODS, CC_OPEN_BULK or CC_LIQUID"
)
if cargo_class in ["CC_FLATBED", "CC_REFRIGERATED"]:
if (
("CC_PIECE_GOODS" not in self.cargo_classes)
and ("CC_EXPRESS" not in self.cargo_classes)
):
raise BaseException(
self.id
+ " should have a fallback set (CC_PIECE_GOODS or CC_EXPRESS"
)

def get_numeric_id(self, economy):
return self.economy_variations[economy].get("numeric_id")
Expand All @@ -78,34 +132,6 @@ def get_property_declaration(self, property_name, economy=None):
value = self.get_property(property_name, economy)
return property_name + ": " + str(value) + ";"

def validate_cargo_classes(self):
# as of October 2024, I concluded that whilst the fundamental classes are useful, the extra 'exclude only' classes are not worth the candle
# (1) there's no clear heuristic for when to set them or not
# - IRL both pipe and farm machines are 'oversized', but STPP was setting CC_OVERSIZED, whilst FMSP was not
# - there's no compelling evidence about how, or even if, these extra classes are useful to vehicle set authors
# (2) setting them is likely to lead to unpredictable effects which are hard to reason about, whereas not setting them is easy to reason about
# https://newgrf-specs.tt-wiki.net/wiki/Action0/Cargos#CargoClasses_.2816.29 and https://newgrf-specs.tt-wiki.net/wiki/NML:Cargos#Cargo_classes

# so we only permit the fundamental classes
allowed_cargo_classes = [
"CC_PASSENGERS",
"CC_MAIL",
"CC_EXPRESS",
"CC_ARMOURED",
"CC_BULK",
"CC_PIECE_GOODS",
"CC_LIQUID",
"NO_CARGO_CLASS",
]
for cargo_class in self.cargo_classes:
if cargo_class not in allowed_cargo_classes:
raise BaseException(
self.id
+ " defines cargo class "
+ cargo_class
+ " which is not permitted."
)

@property
def properties_for_gs(self):
result = {}
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/acid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.5", # extra realism, per forum suggestion Nov 2017
is_freight="1",
cargo_classes = ["CC_LIQUID"],
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="ACID",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_ACID)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="GRVL",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_AGGREGATES)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/alcohol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.1", # such realism - I looked up the weight of 1L of beer, heavier than water :P
is_freight="1",
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_LIQUID"],
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_LIQUID", "CC_FOOD_GRADE"],
cargo_label="BEER",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_ALCOHOL)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/aluminia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="ALO_", # Aluminium Oxide
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_ALUMINIA)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/aluminium.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="ALUM",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_ALUMINIUM)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/ammonia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="0.60", # extra realism per forum suggestion
is_freight="1",
cargo_classes = ["CC_LIQUID"],
cargo_classes = ["CC_GAS", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="NH3_",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_AMMONIA)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/ammonium_nitrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="0.60", # extra realism per forum suggestion
is_freight="1",
cargo_classes = ["CC_BULK", "CC_PIECE_GOODS"],
cargo_classes = ["CC_COVERED_BULK", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="NHNO",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_AMMONIUM_NITRATE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/bauxite.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_COVERED_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="AORE",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_BAUXITE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/beans.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_COVERED_BULK", "CC_PIECE_GOODS", "CC_FOOD_GRADE"],
cargo_label="BEAN",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_BEANS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/building_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS", "CC_BULK"],
cargo_classes = ["CC_PIECE_GOODS", "CC_COVERED_BULK", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="BDMT",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_BUILDING_MATERIALS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/carbon_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS", "CC_BULK"],
cargo_classes = ["CC_PIECE_GOODS", "CC_COVERED_BULK", "CC_POWDERIZED", "CC_NON_FOOD_GRADE"],
cargo_label="CBLK",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CARBON_BLACK)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/cassava.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_COVERED_BULK", "CC_FOOD_GRADE"],
cargo_label="CASS",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CASSAVA)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/cast_iron.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="CSTI",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CAST_IRON)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/cement.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_COVERED_BULK", "CC_POWDERIZED", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="CMNT",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CEMENT)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/chemicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.2", # extra realism, per forum suggestion Nov 2017
is_freight="1",
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS"],
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS", "CC_GAS", "CC_NON_FOOD_GRADE"],
cargo_label="RFPR",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_CHEMICALS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/chlorine.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="2.0",
is_freight="1",
cargo_classes = ["CC_LIQUID"],
cargo_classes = ["CC_GAS", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="CHLO",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_CHLORINE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/chromite_ore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="CHRO",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CHROMITE_ORE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/clay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_COVERED_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="CLAY",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CLAY)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/cleaning_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS"],
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="SOAP",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_CLEANING_AGENTS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/coal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="COAL",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="TTD_STR_QUANTITY_COAL",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/coal_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_LIQUID"],
cargo_classes = ["CC_LIQUID", "CC_NON_FOOD_GRADE"],
cargo_label="CTAR",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_COAL_TAR)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="0.25", # IRL coffee is lighter even than this, but eh
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS", "CC_EXPRESS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_EXPRESS", "CC_FOOD_GRADE"],
cargo_label="JAVA",
units_of_cargo="TTD_STR_BAGS",
items_of_cargo="string(STR_CARGO_UNIT_COFFEE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/coke.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="COKE",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_COKE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/concrete_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="CCPR",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_CONCRETE_PRODUCTS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/copper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="COPR",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_COPPER)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/copper_concentrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_COVERED_BULK", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="COCO",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_COPPER_CONCENTRATE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/copper_ore.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_BULK"],
cargo_classes = ["CC_OPEN_BULK", "CC_NON_FOOD_GRADE"],
cargo_label="CORE",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="TTD_STR_QUANTITY_COPPER_ORE",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/edible_oil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS", "CC_LIQUID"],
cargo_classes = ["CC_PIECE_GOODS", "CC_LIQUID", "CC_FOOD_GRADE"],
cargo_label="EOIL",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_EDIBLE_OIL)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/electrical_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="1.0",
is_freight="1",
cargo_classes = ["CC_PIECE_GOODS"],
cargo_classes = ["CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="POWR",
units_of_cargo="TTD_STR_TONS",
items_of_cargo="string(STR_CARGO_UNIT_ELECTRICAL_PARTS)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/engineering_supplies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="0.65",
is_freight="1",
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS"],
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="ENSP",
units_of_cargo="TTD_STR_CRATES",
items_of_cargo="string(STR_CARGO_UNIT_ENGINEERING_SUPPLIES)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/ethylene.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="2.0",
is_freight="1",
cargo_classes = ["CC_LIQUID"],
cargo_classes = ["CC_LIQUID", "CC_PIECE_GOODS", "CC_NON_FOOD_GRADE"],
cargo_label="C2H4",
units_of_cargo="TTD_STR_LITERS",
items_of_cargo="string(STR_CARGO_UNIT_ETHYLENE)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/explosives.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
weight="0.25",
is_freight="1",
# armoured is a deliberate choice for explosives, tested with 10 of the major vehicle grfs in 2024, worked well
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_ARMOURED"],
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_ARMOURED", "CC_NON_FOOD_GRADE"],
cargo_label="BOOM",
units_of_cargo="TTD_STR_CRATES",
items_of_cargo="string(STR_CARGO_UNIT_EXPLOSIVES)",
Expand Down
2 changes: 1 addition & 1 deletion src/cargos/farm_supplies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sprite="NEW_CARGO_SPRITE",
weight="0.65",
is_freight="1",
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS"],
cargo_classes = ["CC_EXPRESS", "CC_PIECE_GOODS", "CC_FLATBED", "CC_NON_FOOD_GRADE"],
cargo_label="FMSP",
units_of_cargo="TTD_STR_CRATES",
items_of_cargo="string(STR_CARGO_UNIT_FMSP)",
Expand Down
Loading

0 comments on commit 7f98df2

Please sign in to comment.