Skip to content

Commit

Permalink
Codechange: WIP on optional support for a roster reusing wagons from …
Browse files Browse the repository at this point in the history
…another roster
  • Loading branch information
andythenorth committed Feb 18, 2024
1 parent 4aac945 commit a92326b
Show file tree
Hide file tree
Showing 516 changed files with 1,280 additions and 531 deletions.
6 changes: 3 additions & 3 deletions src/id_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def find_vacant_id_runs(numeric_id_defender, lower_bound, upper_bound):
unused_ids = []
for i in range(int(lower_bound / 10), int(upper_bound / 10)):
id = i * 10
if id not in iron_horse.roster_manager.numeric_id_defender:
if id not in iron_horse.roster_manager.numeric_id_defender.keys():
unused_ids.append(id)
id_runs = []
run = []
Expand Down Expand Up @@ -41,12 +41,12 @@ def main():
# tidy-mind problem, but do we have any vacant numeric ID slots in the currently used range?

id_gaps_articulated = find_vacant_id_runs(
iron_horse.roster_manager.numeric_id_defender,
iron_horse.roster_manager.numeric_id_defender.keys(),
0,
global_constants.max_articulated_id - 10,
)
id_gaps_non_articulated = find_vacant_id_runs(
iron_horse.roster_manager.numeric_id_defender,
iron_horse.roster_manager.numeric_id_defender.keys(),
global_constants.max_articulated_id + 10,
# yolo 65k why not
65000,
Expand Down
2 changes: 1 addition & 1 deletion src/iron_horse.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def validate_vehicles(self):
# has to be explicitly called after all rosters are active, and all vehicles and vehicle units are registered to each roster
# validation will also populate numeric_id_defender which can be re-used for ID reporting
# actual validation is delegated to the roster
self.numeric_id_defender = []
self.numeric_id_defender = {}
for roster in self:
roster.validate_vehicles(self.numeric_id_defender)

Expand Down
18 changes: 12 additions & 6 deletions src/roster.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,21 @@ def validate_vehicles(self, numeric_id_defender):
)
for numeric_id in consist.unique_numeric_ids:
if numeric_id in numeric_id_defender:
colliding_consist = numeric_id_defender[numeric_id]
# there is a specific case of reused vehicles that are allowed to overlap IDs (they will be grf-independent, and the compile doesn't actually care)
# it should be enough to just check the base_id, as both consists should then have been instantiated from the same source module
if colliding_consist.base_id == consist.base_id:
continue
raise BaseException(
"Error: consist "
+ consist.id
+ " has a unit variant with numeric_id that collides ("
+ " has a unit variant with a numeric_id that collides ("
+ str(numeric_id)
+ ") with a numeric_id of a unit variant in another consist"
+ ") with a numeric_id of a unit variant in consist "
+ colliding_consist.id
)
else:
numeric_id_defender.append(numeric_id)
numeric_id_defender[numeric_id] = consist
# no return value needed

def register_wagon_consist(self, wagon_consist):
Expand All @@ -365,8 +371,8 @@ def post_init_actions(self):
# this is not intended to be a common case, it's for things like torpedo cars where redrawing and redefining them for all rosters is pointless
# this may cause compile failures when refactoring stuff due to cross-roster dependencies being broken, if so comment the calls out
for roster_id_providing_modules, wagon_module_names in self.wagon_modules_provided_by_other_rosters.items():
#self.init_wagon_modules(roster_id_providing_modules, wagon_module_names)
pass
self.init_wagon_modules(roster_id_providing_modules, wagon_module_names)
#pass

def init_wagon_modules(self, roster_id_of_module, wagon_module_names):
package_name = "vehicles." + roster_id_of_module
Expand All @@ -375,7 +381,7 @@ def init_wagon_modules(self, roster_id_of_module, wagon_module_names):
wagon_module = importlib.import_module(
"." + wagon_module_name + "_" + roster_id_of_module, package_name
)
wagon_module.main(self.id)
wagon_module.main(self.id, roster_id_providing_module=roster_id_of_module)
except ModuleNotFoundError:
# we want to warn, not fail, if a module is missing
# to suppress this warning, add an empty module file with main() and pass
Expand Down
1 change: 1 addition & 0 deletions src/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,7 @@ def __init__(self, speedy=False, **kwargs):
id = self.get_wagon_id(self.base_id, **kwargs)
kwargs["id"] = id
super().__init__(**kwargs)
self.roster_id_providing_module = kwargs["roster_id_providing_module"]
self.roster.register_wagon_consist(self)

self._joker = False # override this in subclass as needed
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/acid_tank_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/ae_3_5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="ae_3_5",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/ae_3_6_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="ae_3_6_1",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/ae_4_7.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="ae_4_7",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/aggregate_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/aggregate_hopper_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/alignment_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/automobile_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_22200.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_22200",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_22200_upgraded.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_22200_upgraded",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_25200.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_25200",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_26000.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_26000",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_26000_upgraded.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_26000_upgraded",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_27000.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_27000",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_7200.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_7200",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_8100_duo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_8100_duo",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bb_8500_duo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bb_8500_duo",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bls_ae_4_4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bls_ae_4_4",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bls_ae_6_8.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bls_ae_6_8",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bls_ae_8_8.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bls_ae_8_8",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bls_re_475.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# multi-system !!


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bls_re_475",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bls_re_4_4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="bls_re_4_4",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bolster_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/box_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/bulkhead_flat_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/caboose_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/carbon_black_hopper_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/cc_6500.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="cc_6500",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/cc_7100.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="cc_7100",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/cement_silo_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/cement_silo_cars_v_barrel_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/chemical_covered_hopper_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/coil_buggy_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/coil_cars_covered_asymmetric_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/coil_cars_covered_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/coil_cars_uncovered_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/covered_hopper_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/cryo_tank_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/curtain_side_box_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
2 changes: 1 addition & 1 deletion src/vehicles/ibex/de_6_6.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from train import EngineConsist, ElectricEngineUnit


def main(roster_id):
def main(roster_id, **kwargs):
consist = EngineConsist(
roster_id=roster_id,
id="de_6_6",
Expand Down
2 changes: 1 addition & 1 deletion src/vehicles/ibex/double_deck_automobile_cars_ibex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# placeholder to avoid module import failures (this is by design the cleanest solution as of Feb 2024)

def main(roster_id):
def main(roster_id, **kwargs):
pass
Loading

0 comments on commit a92326b

Please sign in to comment.