Factorio: implement custom filler items (#4945)

This commit is contained in:
Fabian Dill
2025-05-02 23:39:14 +02:00
committed by GitHub
parent 2455f1158f
commit da0207f5cb
2 changed files with 11 additions and 5 deletions

View File

@@ -485,7 +485,7 @@ class World(metaclass=AutoWorldRegister):
def get_filler_item_name(self) -> str: def get_filler_item_name(self) -> str:
"""Called when the item pool needs to be filled with additional items to match location count.""" """Called when the item pool needs to be filled with additional items to match location count."""
logging.warning(f"World {self} is generating a filler item without custom filler pool.") logging.warning(f"World {self} is generating a filler item without custom filler pool.")
return self.multiworld.random.choice(tuple(self.item_name_to_id.keys())) return self.random.choice(tuple(self.item_name_to_id.keys()))
@classmethod @classmethod
def create_group(cls, multiworld: "MultiWorld", new_player_id: int, players: Set[int]) -> World: def create_group(cls, multiworld: "MultiWorld", new_player_id: int, players: Set[int]) -> World:

View File

@@ -115,6 +115,7 @@ class Factorio(World):
settings: typing.ClassVar[FactorioSettings] settings: typing.ClassVar[FactorioSettings]
trap_names: tuple[str] = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", trap_names: tuple[str] = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery",
"Atomic Rocket", "Atomic Cliff Remover", "Inventory Spill") "Atomic Rocket", "Atomic Cliff Remover", "Inventory Spill")
want_progressives: dict[str, bool] = collections.defaultdict(lambda: False)
def __init__(self, world, player: int): def __init__(self, world, player: int):
super(Factorio, self).__init__(world, player) super(Factorio, self).__init__(world, player)
@@ -133,6 +134,8 @@ class Factorio(World):
self.options.max_tech_cost.value, self.options.min_tech_cost.value self.options.max_tech_cost.value, self.options.min_tech_cost.value
self.tech_mix = self.options.tech_cost_mix.value self.tech_mix = self.options.tech_cost_mix.value
self.skip_silo = self.options.silo.value == Silo.option_spawn self.skip_silo = self.options.silo.value == Silo.option_spawn
self.want_progressives = collections.defaultdict(
lambda: self.options.progressive.want_progressives(self.random))
def create_regions(self): def create_regions(self):
player = self.player player = self.player
@@ -201,9 +204,6 @@ class Factorio(World):
range(getattr(self.options, range(getattr(self.options,
f"{trap_name.lower().replace(' ', '_')}_traps"))) f"{trap_name.lower().replace(' ', '_')}_traps")))
want_progressives = collections.defaultdict(lambda: self.options.progressive.
want_progressives(self.random))
cost_sorted_locations = sorted(self.science_locations, key=lambda location: location.name) cost_sorted_locations = sorted(self.science_locations, key=lambda location: location.name)
special_index = {"automation": 0, special_index = {"automation": 0,
"logistics": 1, "logistics": 1,
@@ -218,7 +218,7 @@ class Factorio(World):
for tech_name in base_tech_table: for tech_name in base_tech_table:
if tech_name not in self.removed_technologies: if tech_name not in self.removed_technologies:
progressive_item_name = tech_to_progressive_lookup.get(tech_name, tech_name) progressive_item_name = tech_to_progressive_lookup.get(tech_name, tech_name)
want_progressive = want_progressives[progressive_item_name] want_progressive = self.want_progressives[progressive_item_name]
item_name = progressive_item_name if want_progressive else tech_name item_name = progressive_item_name if want_progressive else tech_name
tech_item = self.create_item(item_name) tech_item = self.create_item(item_name)
index = special_index.get(tech_name, None) index = special_index.get(tech_name, None)
@@ -233,6 +233,12 @@ class Factorio(World):
loc.place_locked_item(tech_item) loc.place_locked_item(tech_item)
loc.revealed = True loc.revealed = True
def get_filler_item_name(self) -> str:
tech_name: str = self.random.choice(tuple(tech_table))
progressive_item_name: str = tech_to_progressive_lookup.get(tech_name, tech_name)
want_progressive: bool = self.want_progressives[progressive_item_name]
return progressive_item_name if want_progressive else tech_name
def set_rules(self): def set_rules(self):
player = self.player player = self.player
shapes = get_shapes(self) shapes = get_shapes(self)