mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
move more Factorio stuff around
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from BaseClasses import MultiWorld
|
||||
|
||||
|
||||
class AutoWorldRegister(type):
|
||||
world_types = {}
|
||||
|
||||
@@ -12,7 +13,7 @@ class AutoWorldRegister(type):
|
||||
|
||||
def call_single(world: MultiWorld, method_name: str, player: int):
|
||||
method = getattr(world.worlds[player], method_name)
|
||||
return method(world, player)
|
||||
return method()
|
||||
|
||||
|
||||
def call_all(world: MultiWorld, method_name: str):
|
||||
@@ -24,14 +25,22 @@ class World(metaclass=AutoWorldRegister):
|
||||
"""A World object encompasses a game's Items, Locations, Rules and additional data or functionality required.
|
||||
A Game should have its own subclass of World in which it defines the required data structures."""
|
||||
|
||||
def __init__(self, player: int):
|
||||
self.player = int
|
||||
world: MultiWorld
|
||||
player: int
|
||||
|
||||
def generate_basic(self, world: MultiWorld, player: int):
|
||||
def __init__(self, world: MultiWorld, player: int):
|
||||
self.world = world
|
||||
self.player = player
|
||||
|
||||
# overwritable methods that get called by Main.py
|
||||
def generate_basic(self):
|
||||
pass
|
||||
|
||||
def generate_output(self, world: MultiWorld, player: int):
|
||||
def set_rules(self):
|
||||
pass
|
||||
|
||||
def create_regions(self, world: MultiWorld, player: int):
|
||||
def create_regions(self):
|
||||
pass
|
||||
|
||||
def generate_output(self):
|
||||
pass
|
||||
|
||||
@@ -69,7 +69,7 @@ def generate_mod(world: MultiWorld, player: int):
|
||||
6: 10}[world.tech_cost[player].value]
|
||||
template_data = {"locations": locations, "player_names": player_names, "tech_table": tech_table,
|
||||
"mod_name": mod_name, "allowed_science_packs": world.max_science_pack[player].get_allowed_packs(),
|
||||
"tech_cost_scale": tech_cost, "custom_data": world.custom_data[player],
|
||||
"tech_cost_scale": tech_cost, "custom_technologies": world.worlds[player].custom_technologies,
|
||||
"tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player],
|
||||
"rocket_recipe": rocket_recipes[world.max_science_pack[player].value],
|
||||
"slot_name": world.player_names[player][0], "seed_name": world.seed_name,
|
||||
|
||||
@@ -11,10 +11,12 @@ funnel_slice_sizes = {TechTreeLayout.option_small_funnels: 6,
|
||||
TechTreeLayout.option_medium_funnels: 10,
|
||||
TechTreeLayout.option_large_funnels: 15}
|
||||
|
||||
def get_shapes(world: MultiWorld, player: int) -> Dict[str, List[str]]:
|
||||
def get_shapes(factorio_world) -> Dict[str, List[str]]:
|
||||
world = factorio_world.world
|
||||
player = factorio_world.player
|
||||
prerequisites: Dict[str, Set[str]] = {}
|
||||
layout = world.tech_tree_layout[player].value
|
||||
custom_technologies = world.custom_data[player]["custom_technologies"]
|
||||
custom_technologies = factorio_world.custom_technologies
|
||||
tech_names: List[str] = list(set(custom_technologies) - world.worlds[player].static_nodes)
|
||||
tech_names.sort()
|
||||
world.random.shuffle(tech_names)
|
||||
|
||||
@@ -11,28 +11,28 @@ class Factorio(World):
|
||||
game: str = "Factorio"
|
||||
static_nodes = {"automation", "logistics"}
|
||||
|
||||
def generate_basic(self, world: MultiWorld, player: int):
|
||||
victory_tech_names = get_rocket_requirements(frozenset(rocket_recipes[world.max_science_pack[player].value]))
|
||||
def generate_basic(self):
|
||||
victory_tech_names = get_rocket_requirements(
|
||||
frozenset(rocket_recipes[self.world.max_science_pack[self.player].value]))
|
||||
for tech_name, tech_id in tech_table.items():
|
||||
tech_item = Item(tech_name, tech_name in advancement_technologies or tech_name in victory_tech_names,
|
||||
tech_id, player)
|
||||
tech_id, self.player)
|
||||
tech_item.game = "Factorio"
|
||||
if tech_name in self.static_nodes:
|
||||
world.get_location(tech_name, player).place_locked_item(tech_item)
|
||||
self.world.get_location(tech_name, self.player).place_locked_item(tech_item)
|
||||
else:
|
||||
world.itempool.append(tech_item)
|
||||
world.custom_data[player]["custom_technologies"] = custom_technologies = set_custom_technologies(world, player)
|
||||
set_rules(world, player, custom_technologies)
|
||||
self.world.itempool.append(tech_item)
|
||||
|
||||
def generate_output(self, world: MultiWorld, player: int):
|
||||
generate_mod(world, player)
|
||||
def generate_output(self):
|
||||
generate_mod(self.world, self.player)
|
||||
|
||||
def create_regions(self, world: MultiWorld, player: int):
|
||||
def create_regions(self):
|
||||
player = self.player
|
||||
menu = Region("Menu", None, "Menu", player)
|
||||
crash = Entrance(player, "Crash Land", menu)
|
||||
menu.exits.append(crash)
|
||||
nauvis = Region("Nauvis", None, "Nauvis", player)
|
||||
nauvis.world = menu.world = world
|
||||
nauvis.world = menu.world = self.world
|
||||
|
||||
for tech_name, tech_id in tech_table.items():
|
||||
tech = Location(player, tech_name, tech_id, nauvis)
|
||||
@@ -41,49 +41,47 @@ class Factorio(World):
|
||||
location = Location(player, "Rocket Launch", None, nauvis)
|
||||
nauvis.locations.append(location)
|
||||
event = Item("Victory", True, None, player)
|
||||
world.push_item(location, event, False)
|
||||
self.world.push_item(location, event, False)
|
||||
location.event = location.locked = True
|
||||
for ingredient in all_ingredient_names:
|
||||
location = Location(player, f"Automate {ingredient}", None, nauvis)
|
||||
nauvis.locations.append(location)
|
||||
event = Item(f"Automated {ingredient}", True, None, player)
|
||||
world.push_item(location, event, False)
|
||||
self.world.push_item(location, event, False)
|
||||
location.event = location.locked = True
|
||||
crash.connect(nauvis)
|
||||
world.regions += [menu, nauvis]
|
||||
self.world.regions += [menu, nauvis]
|
||||
|
||||
def set_rules(self):
|
||||
world = self.world
|
||||
player = self.player
|
||||
self.custom_technologies = set_custom_technologies(self.world, self.player)
|
||||
shapes = get_shapes(self)
|
||||
if world.logic[player] != 'nologic':
|
||||
from worlds.generic import Rules
|
||||
for ingredient in all_ingredient_names:
|
||||
location = world.get_location(f"Automate {ingredient}", player)
|
||||
location.access_rule = lambda state, ingredient=ingredient: \
|
||||
all(state.has(technology.name, player) for technology in required_technologies[ingredient])
|
||||
for tech_name, technology in self.custom_technologies.items():
|
||||
location = world.get_location(tech_name, player)
|
||||
Rules.set_rule(location, technology.build_rule(player))
|
||||
prequisites = shapes.get(tech_name)
|
||||
if prequisites:
|
||||
locations = {world.get_location(requisite, player) for requisite in prequisites}
|
||||
Rules.add_rule(location, lambda state,
|
||||
locations=locations: all(state.can_reach(loc) for loc in locations))
|
||||
# get all science pack technologies (but not the ability to craft them)
|
||||
victory_tech_names = get_rocket_requirements(frozenset(rocket_recipes[world.max_science_pack[player].value]))
|
||||
world.get_location("Rocket Launch", player).access_rule = lambda state: all(state.has(technology, player)
|
||||
for technology in
|
||||
victory_tech_names)
|
||||
|
||||
world.completion_condition[player] = lambda state: state.has('Victory', player)
|
||||
|
||||
def set_custom_technologies(world: MultiWorld, player: int):
|
||||
custom_technologies = {}
|
||||
world_custom = getattr(world, "_custom_technologies", {})
|
||||
world_custom[player] = custom_technologies
|
||||
world._custom_technologies = world_custom
|
||||
allowed_packs = world.max_science_pack[player].get_allowed_packs()
|
||||
for technology_name, technology in technology_table.items():
|
||||
custom_technologies[technology_name] = technology.get_custom(world, allowed_packs, player)
|
||||
return custom_technologies
|
||||
|
||||
|
||||
def set_rules(world: MultiWorld, player: int, custom_technologies):
|
||||
shapes = get_shapes(world, player)
|
||||
if world.logic[player] != 'nologic':
|
||||
from worlds.generic import Rules
|
||||
for ingredient in all_ingredient_names:
|
||||
location = world.get_location(f"Automate {ingredient}", player)
|
||||
location.access_rule = lambda state, ingredient=ingredient: \
|
||||
all(state.has(technology.name, player) for technology in required_technologies[ingredient])
|
||||
for tech_name, technology in custom_technologies.items():
|
||||
location = world.get_location(tech_name, player)
|
||||
Rules.set_rule(location, technology.build_rule(player))
|
||||
prequisites = shapes.get(tech_name)
|
||||
if prequisites:
|
||||
locations = {world.get_location(requisite, player) for requisite in prequisites}
|
||||
Rules.add_rule(location, lambda state,
|
||||
locations=locations: all(state.can_reach(loc) for loc in locations))
|
||||
# get all science pack technologies (but not the ability to craft them)
|
||||
victory_tech_names = get_rocket_requirements(frozenset(rocket_recipes[world.max_science_pack[player].value]))
|
||||
world.get_location("Rocket Launch", player).access_rule = lambda state: all(state.has(technology, player)
|
||||
for technology in
|
||||
victory_tech_names)
|
||||
|
||||
world.completion_condition[player] = lambda state: state.has('Victory', player)
|
||||
|
||||
Reference in New Issue
Block a user