2021-06-11 12:22:44 +00:00
|
|
|
from ..AutoWorld import World
|
2021-05-12 23:34:59 +00:00
|
|
|
|
2021-07-07 08:14:58 +00:00
|
|
|
from BaseClasses import Region, Entrance, Location, Item
|
2021-07-04 20:21:53 +00:00
|
|
|
from .Technologies import base_tech_table, recipe_sources, base_technology_table, advancement_technologies, \
|
|
|
|
all_ingredient_names, required_technologies, get_rocket_requirements, rocket_recipes, \
|
2021-07-07 08:14:58 +00:00
|
|
|
progressive_technology_table, common_tech_table, tech_to_progressive_lookup, progressive_tech_table, \
|
2021-07-12 11:54:47 +00:00
|
|
|
get_science_pack_pools, Recipe, recipes, technology_table, tech_table
|
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-06-25 21:32:13 +00:00
|
|
|
from .Options import factorio_options
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-07-12 11:54:47 +00:00
|
|
|
|
|
|
|
class FactorioItem(Item):
|
|
|
|
game = "Factorio"
|
|
|
|
|
|
|
|
|
2021-05-12 23:34:59 +00:00
|
|
|
class Factorio(World):
|
2021-06-11 12:22:44 +00:00
|
|
|
game: str = "Factorio"
|
2021-06-15 13:32:40 +00:00
|
|
|
static_nodes = {"automation", "logistics", "rocket-silo"}
|
2021-07-07 08:14:58 +00:00
|
|
|
custom_recipes = {}
|
|
|
|
additional_advancement_technologies = set()
|
2021-07-12 11:54:47 +00:00
|
|
|
item_names = frozenset(tech_table)
|
2021-07-12 13:11:48 +00:00
|
|
|
location_names = frozenset(base_tech_table)
|
2021-06-11 12:22:44 +00:00
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
def generate_basic(self):
|
2021-07-12 11:54:47 +00:00
|
|
|
for tech_name in base_tech_table:
|
|
|
|
if self.world.progressive:
|
|
|
|
item_name = tech_to_progressive_lookup.get(tech_name, tech_name)
|
2021-07-04 20:21:53 +00:00
|
|
|
else:
|
2021-07-12 11:54:47 +00:00
|
|
|
item_name = item_name
|
|
|
|
tech_item = self.create_item(item_name)
|
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-07-01 23:29:49 +00:00
|
|
|
world_gen = self.world.world_gen[self.player].value
|
2021-07-07 08:14:58 +00:00
|
|
|
if world_gen.get("seed", None) is None: # allow seed 0
|
2021-07-04 20:21:53 +00:00
|
|
|
world_gen["seed"] = self.world.slot_seeds[self.player].randint(0, 2**32-1) # 32 bit uint
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-07-07 08:14:58 +00:00
|
|
|
generate_output = generate_mod
|
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-07-04 20:21:53 +00:00
|
|
|
for tech_name, tech_id in base_tech_table.items():
|
2021-06-11 12:22:44 +00:00
|
|
|
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-07-07 08:14:58 +00:00
|
|
|
location.game = "Factorio"
|
2021-06-11 12:22:44 +00:00
|
|
|
event = Item("Victory", True, None, player)
|
2021-07-07 08:14:58 +00:00
|
|
|
event.game = "Factorio"
|
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-26 04:05:38 +00:00
|
|
|
for ingredient in self.world.max_science_pack[self.player].get_allowed_packs():
|
2021-06-11 12:22:44 +00:00
|
|
|
location = Location(player, f"Automate {ingredient}", None, nauvis)
|
2021-07-07 08:14:58 +00:00
|
|
|
location.game = "Factorio"
|
2021-06-11 12:22:44 +00:00
|
|
|
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
|
2021-07-07 08:14:58 +00:00
|
|
|
self.custom_technologies = self.set_custom_technologies()
|
|
|
|
self.set_custom_recipes()
|
2021-06-11 16:02:48 +00:00
|
|
|
shapes = get_shapes(self)
|
|
|
|
if world.logic[player] != 'nologic':
|
|
|
|
from worlds.generic import Rules
|
2021-06-26 04:05:38 +00:00
|
|
|
for ingredient in self.world.max_science_pack[self.player].get_allowed_packs():
|
2021-06-11 16:02:48 +00:00
|
|
|
location = world.get_location(f"Automate {ingredient}", player)
|
2021-07-07 08:14:58 +00:00
|
|
|
|
|
|
|
if self.world.recipe_ingredients[self.player]:
|
|
|
|
custom_recipe = self.custom_recipes[ingredient]
|
|
|
|
|
|
|
|
location.access_rule = lambda state, ingredient=ingredient, custom_recipe = custom_recipe: \
|
|
|
|
(ingredient not in technology_table or state.has(ingredient, player)) and \
|
|
|
|
all(state.has(technology.name, player) for sub_ingredient in custom_recipe.ingredients
|
|
|
|
for technology in required_technologies[sub_ingredient])
|
|
|
|
else:
|
|
|
|
location.access_rule = lambda state, ingredient=ingredient: \
|
|
|
|
all(state.has(technology.name, player) for technology in required_technologies[ingredient])
|
|
|
|
|
2021-06-11 16:02:48 +00:00
|
|
|
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))
|
2021-07-07 08:14:58 +00:00
|
|
|
|
|
|
|
victory_tech_names = get_rocket_requirements(self.custom_recipes["rocket-part"])
|
2021-06-11 16:02:48 +00:00
|
|
|
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-07-04 20:21:53 +00:00
|
|
|
def collect(self, state, item) -> bool:
|
|
|
|
if item.advancement and item.name in progressive_technology_table:
|
|
|
|
prog_table = progressive_technology_table[item.name].progressive
|
|
|
|
for item_name in prog_table:
|
|
|
|
if not state.has(item_name, item.player):
|
|
|
|
state.prog_items[item_name, item.player] += 1
|
|
|
|
return True
|
|
|
|
return super(Factorio, self).collect(state, item)
|
|
|
|
|
2021-06-26 22:23:42 +00:00
|
|
|
def get_required_client_version(self) -> tuple:
|
2021-07-01 23:58:03 +00:00
|
|
|
return max((0, 1, 4), super(Factorio, self).get_required_client_version())
|
2021-06-26 22:23:42 +00:00
|
|
|
|
2021-06-25 21:32:13 +00:00
|
|
|
options = factorio_options
|
|
|
|
|
2021-07-07 08:14:58 +00:00
|
|
|
def set_custom_technologies(self):
|
|
|
|
custom_technologies = {}
|
|
|
|
allowed_packs = self.world.max_science_pack[self.player].get_allowed_packs()
|
|
|
|
for technology_name, technology in base_technology_table.items():
|
|
|
|
custom_technologies[technology_name] = technology.get_custom(self.world, allowed_packs, self.player)
|
|
|
|
return custom_technologies
|
|
|
|
|
|
|
|
def set_custom_recipes(self):
|
|
|
|
original_rocket_part = recipes["rocket-part"]
|
2021-07-09 15:44:24 +00:00
|
|
|
science_pack_pools = get_science_pack_pools()
|
2021-07-07 08:14:58 +00:00
|
|
|
valid_pool = sorted(science_pack_pools[self.world.max_science_pack[self.player].get_max_pack()])
|
|
|
|
self.world.random.shuffle(valid_pool)
|
|
|
|
self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category,
|
|
|
|
{valid_pool[x] : 10 for x in range(3)},
|
|
|
|
original_rocket_part.products)}
|
|
|
|
self.additional_advancement_technologies = {tech.name for tech in
|
|
|
|
self.custom_recipes["rocket-part"].recursive_unlocking_technologies}
|
|
|
|
|
|
|
|
if self.world.recipe_ingredients[self.player]:
|
|
|
|
valid_pool = []
|
|
|
|
for pack in self.world.max_science_pack[self.player].get_ordered_science_packs():
|
|
|
|
valid_pool += sorted(science_pack_pools[pack])
|
|
|
|
self.world.random.shuffle(valid_pool)
|
|
|
|
if pack in recipes: # skips over space science pack
|
|
|
|
original = recipes[pack]
|
|
|
|
new_ingredients = {}
|
|
|
|
for _ in original.ingredients:
|
|
|
|
new_ingredients[valid_pool.pop()] = 1
|
|
|
|
new_recipe = Recipe(pack, original.category, new_ingredients, original.products)
|
|
|
|
self.additional_advancement_technologies |= {tech.name for tech in
|
|
|
|
new_recipe.recursive_unlocking_technologies}
|
|
|
|
self.custom_recipes[pack] = new_recipe
|
|
|
|
|
|
|
|
# handle marking progressive techs as advancement
|
|
|
|
prog_add = set()
|
|
|
|
for tech in self.additional_advancement_technologies:
|
|
|
|
if tech in tech_to_progressive_lookup:
|
|
|
|
prog_add.add(tech_to_progressive_lookup[tech])
|
|
|
|
self.additional_advancement_technologies |= prog_add
|
2021-07-12 11:54:47 +00:00
|
|
|
|
|
|
|
def create_item(self, name: str) -> Item:
|
|
|
|
assert name in tech_table
|
|
|
|
return FactorioItem(name, name in advancement_technologies or
|
|
|
|
name in self.additional_advancement_technologies,
|
|
|
|
tech_table[name], self.player)
|