2021-06-11 12:22:44 +00:00
|
|
|
from ..AutoWorld import World
|
2021-05-12 23:34:59 +00:00
|
|
|
|
2021-04-01 09:40:58 +00:00
|
|
|
from BaseClasses import Region, Entrance, Location, MultiWorld, Item
|
2021-05-22 08:06:21 +00:00
|
|
|
from .Technologies import tech_table, recipe_sources, technology_table, advancement_technologies, \
|
|
|
|
all_ingredient_names, required_technologies, get_rocket_requirements, rocket_recipes
|
2021-04-11 16:19:47 +00:00
|
|
|
from .Shapes import get_shapes
|
2021-06-11 12:22:44 +00:00
|
|
|
from .Mod import generate_mod
|
|
|
|
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-05-12 23:34:59 +00:00
|
|
|
class Factorio(World):
|
2021-06-11 12:22:44 +00:00
|
|
|
game: str = "Factorio"
|
|
|
|
static_nodes = {"automation", "logistics"}
|
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
def generate_basic(self):
|
|
|
|
victory_tech_names = get_rocket_requirements(
|
|
|
|
frozenset(rocket_recipes[self.world.max_science_pack[self.player].value]))
|
2021-05-12 23:34:59 +00:00
|
|
|
for tech_name, tech_id in tech_table.items():
|
2021-06-11 12:22:44 +00:00
|
|
|
tech_item = Item(tech_name, tech_name in advancement_technologies or tech_name in victory_tech_names,
|
2021-06-11 16:02:48 +00:00
|
|
|
tech_id, self.player)
|
2021-05-12 23:34:59 +00:00
|
|
|
tech_item.game = "Factorio"
|
2021-06-11 12:22:44 +00:00
|
|
|
if tech_name in self.static_nodes:
|
2021-06-11 16:02:48 +00:00
|
|
|
self.world.get_location(tech_name, self.player).place_locked_item(tech_item)
|
2021-05-12 23:34:59 +00:00
|
|
|
else:
|
2021-06-11 16:02:48 +00:00
|
|
|
self.world.itempool.append(tech_item)
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
def generate_output(self):
|
|
|
|
generate_mod(self.world, self.player)
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
def create_regions(self):
|
|
|
|
player = self.player
|
2021-06-11 12:22:44 +00:00
|
|
|
menu = Region("Menu", None, "Menu", player)
|
|
|
|
crash = Entrance(player, "Crash Land", menu)
|
|
|
|
menu.exits.append(crash)
|
|
|
|
nauvis = Region("Nauvis", None, "Nauvis", player)
|
2021-06-11 16:02:48 +00:00
|
|
|
nauvis.world = menu.world = self.world
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-06-11 12:22:44 +00:00
|
|
|
for tech_name, tech_id in tech_table.items():
|
|
|
|
tech = Location(player, tech_name, tech_id, nauvis)
|
|
|
|
nauvis.locations.append(tech)
|
|
|
|
tech.game = "Factorio"
|
|
|
|
location = Location(player, "Rocket Launch", None, nauvis)
|
2021-05-22 08:06:21 +00:00
|
|
|
nauvis.locations.append(location)
|
2021-06-11 12:22:44 +00:00
|
|
|
event = Item("Victory", True, None, player)
|
2021-06-11 16:02:48 +00:00
|
|
|
self.world.push_item(location, event, False)
|
2021-05-22 08:06:21 +00:00
|
|
|
location.event = location.locked = True
|
2021-06-11 12:22:44 +00:00
|
|
|
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)
|
2021-06-11 16:02:48 +00:00
|
|
|
self.world.push_item(location, event, False)
|
2021-06-11 12:22:44 +00:00
|
|
|
location.event = location.locked = True
|
|
|
|
crash.connect(nauvis)
|
2021-06-11 16:02:48 +00:00
|
|
|
self.world.regions += [menu, nauvis]
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
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)
|
2021-05-22 08:06:21 +00:00
|
|
|
|
2021-04-23 23:16:49 +00:00
|
|
|
def set_custom_technologies(world: MultiWorld, player: int):
|
|
|
|
custom_technologies = {}
|
|
|
|
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
|