2021-04-01 09:40:58 +00:00
|
|
|
import logging
|
2021-04-10 17:34:30 +00:00
|
|
|
from typing import List, Dict, Set
|
2021-04-01 09:40:58 +00:00
|
|
|
|
|
|
|
from BaseClasses import Region, Entrance, Location, MultiWorld, Item
|
2021-04-10 01:03:46 +00:00
|
|
|
from Options import TechTreeLayout
|
2021-04-09 20:10:04 +00:00
|
|
|
from .Technologies import tech_table, recipe_sources, technology_table, advancement_technologies, required_technologies
|
2021-04-01 09:40:58 +00:00
|
|
|
|
|
|
|
static_nodes = {"automation", "logistics"}
|
|
|
|
|
|
|
|
|
|
|
|
def gen_factorio(world: MultiWorld, player: int):
|
|
|
|
for tech_name, tech_id in tech_table.items():
|
2021-04-09 22:17:55 +00:00
|
|
|
tech_item = Item(tech_name, tech_name in advancement_technologies, tech_id, player)
|
2021-04-01 09:40:58 +00:00
|
|
|
tech_item.game = "Factorio"
|
|
|
|
if tech_name in static_nodes:
|
|
|
|
loc = world.get_location(tech_name, player)
|
|
|
|
loc.item = tech_item
|
2021-04-09 20:10:04 +00:00
|
|
|
loc.locked = True
|
|
|
|
loc.event = tech_item.advancement
|
2021-04-01 09:40:58 +00:00
|
|
|
else:
|
|
|
|
world.itempool.append(tech_item)
|
|
|
|
set_rules(world, player)
|
|
|
|
|
|
|
|
|
|
|
|
def factorio_create_regions(world: MultiWorld, player: int):
|
|
|
|
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
|
|
|
|
for tech_name, tech_id in tech_table.items():
|
|
|
|
tech = Location(player, tech_name, tech_id, nauvis)
|
|
|
|
nauvis.locations.append(tech)
|
|
|
|
tech.game = "Factorio"
|
|
|
|
crash.connect(nauvis)
|
|
|
|
world.regions += [menu, nauvis]
|
|
|
|
|
|
|
|
|
2021-04-10 01:03:46 +00:00
|
|
|
def get_shapes(world: MultiWorld, player: int) -> Dict[str, List[str]]:
|
2021-04-10 17:34:30 +00:00
|
|
|
prerequisites:Dict[str, Set[str]] = {}
|
|
|
|
layout = world.tech_tree_layout[player].value
|
|
|
|
if layout == TechTreeLayout.option_small_diamonds:
|
|
|
|
slice_size = 4
|
2021-04-10 01:03:46 +00:00
|
|
|
tech_names: List[str] = list(set(technology_table)-static_nodes)
|
|
|
|
tech_names.sort()
|
|
|
|
world.random.shuffle(tech_names)
|
2021-04-10 17:34:30 +00:00
|
|
|
while len(tech_names) > slice_size:
|
|
|
|
slice = tech_names[:slice_size]
|
|
|
|
tech_names = tech_names[slice_size:]
|
2021-04-10 16:45:11 +00:00
|
|
|
slice.sort(key=lambda tech_name: len(technology_table[tech_name].ingredients))
|
|
|
|
diamond_0, diamond_1, diamond_2, diamond_3 = slice
|
|
|
|
|
2021-04-10 01:03:46 +00:00
|
|
|
# 0 |
|
|
|
|
# 1 2 |
|
|
|
|
# 3 V
|
2021-04-10 17:34:30 +00:00
|
|
|
prerequisites[diamond_3] = {diamond_1, diamond_2}
|
|
|
|
prerequisites[diamond_2] = prerequisites[diamond_1] = {diamond_0}
|
|
|
|
elif layout == TechTreeLayout.option_medium_diamonds:
|
|
|
|
slice_size = 9
|
|
|
|
tech_names: List[str] = list(set(technology_table)-static_nodes)
|
|
|
|
tech_names.sort()
|
|
|
|
world.random.shuffle(tech_names)
|
|
|
|
while len(tech_names) > slice_size:
|
|
|
|
slice = tech_names[:slice_size]
|
|
|
|
tech_names = tech_names[slice_size:]
|
|
|
|
slice.sort(key=lambda tech_name: len(technology_table[tech_name].ingredients))
|
|
|
|
|
|
|
|
# 0 |
|
|
|
|
# 1 2 |
|
|
|
|
# 3 4 5 |
|
|
|
|
# 6 7 |
|
|
|
|
# 8 V
|
|
|
|
|
|
|
|
prerequisites[slice[1]] = {slice[0]}
|
|
|
|
prerequisites[slice[2]] = {slice[0]}
|
|
|
|
|
|
|
|
prerequisites[slice[3]] = {slice[1]}
|
|
|
|
prerequisites[slice[4]] = {slice[1], slice[2]}
|
|
|
|
prerequisites[slice[5]] = {slice[2]}
|
|
|
|
|
|
|
|
prerequisites[slice[6]] = {slice[3], slice[4]}
|
|
|
|
prerequisites[slice[7]] = {slice[4], slice[5]}
|
|
|
|
|
|
|
|
prerequisites[slice[8]] = {slice[6], slice[7]}
|
|
|
|
|
|
|
|
elif layout == TechTreeLayout.option_pyramid:
|
|
|
|
slice_size = 1
|
|
|
|
tech_names: List[str] = list(set(technology_table)-static_nodes)
|
|
|
|
tech_names.sort()
|
|
|
|
world.random.shuffle(tech_names)
|
|
|
|
tech_names.sort(key=lambda tech_name: len(technology_table[tech_name].ingredients))
|
|
|
|
previous_slice = []
|
|
|
|
while len(tech_names) > slice_size:
|
|
|
|
slice = tech_names[:slice_size]
|
|
|
|
tech_names = tech_names[slice_size:]
|
|
|
|
for i, tech_name in enumerate(previous_slice):
|
|
|
|
prerequisites.setdefault(slice[i], set()).add(tech_name)
|
|
|
|
prerequisites.setdefault(slice[i+1], set()).add(tech_name)
|
|
|
|
previous_slice = slice
|
|
|
|
slice_size += 1
|
|
|
|
|
2021-04-10 01:03:46 +00:00
|
|
|
world.tech_tree_layout_prerequisites[player] = prerequisites
|
|
|
|
return prerequisites
|
|
|
|
|
|
|
|
|
2021-04-01 09:40:58 +00:00
|
|
|
def set_rules(world: MultiWorld, player: int):
|
2021-04-10 01:03:46 +00:00
|
|
|
shapes = get_shapes(world, player)
|
2021-04-01 09:40:58 +00:00
|
|
|
if world.logic[player] != 'nologic':
|
|
|
|
from worlds.generic import Rules
|
2021-04-09 20:16:55 +00:00
|
|
|
allowed_packs = world.max_science_pack[player].get_allowed_packs()
|
2021-04-05 13:37:15 +00:00
|
|
|
for tech_name, technology in technology_table.items():
|
2021-04-01 09:40:58 +00:00
|
|
|
# loose nodes
|
2021-04-09 20:10:04 +00:00
|
|
|
location = world.get_location(tech_name, player)
|
2021-04-09 20:16:55 +00:00
|
|
|
Rules.set_rule(location, technology.build_rule(allowed_packs, player))
|
2021-04-10 01:03:46 +00:00
|
|
|
prequisites = shapes.get(tech_name)
|
|
|
|
if prequisites:
|
2021-04-10 17:34:30 +00:00
|
|
|
locations = {world.get_location(requisite, player) for requisite in prequisites}
|
2021-04-10 01:03:46 +00:00
|
|
|
Rules.add_rule(location, lambda state,
|
|
|
|
locations=locations: all(state.can_reach(loc) for loc in locations))
|
|
|
|
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-04-05 13:37:15 +00:00
|
|
|
# get all technologies
|
|
|
|
world.completion_condition[player] = lambda state: all(state.has(technology, player)
|
2021-04-09 20:10:04 +00:00
|
|
|
for technology in advancement_technologies)
|