2021-08-03 17:03:41 +00:00
|
|
|
import collections
|
2021-11-20 03:47:19 +00:00
|
|
|
import typing
|
2021-08-03 17:03:41 +00:00
|
|
|
|
2022-05-11 18:05:53 +00:00
|
|
|
from ..AutoWorld import World, WebWorld
|
2021-05-12 23:34:59 +00:00
|
|
|
|
2022-06-17 01:23:27 +00:00
|
|
|
from BaseClasses import Region, Entrance, Location, Item, RegionType, Tutorial, ItemClassification
|
2021-11-20 03:47:19 +00:00
|
|
|
from .Technologies import base_tech_table, recipe_sources, base_technology_table, \
|
2022-06-19 16:06:27 +00:00
|
|
|
all_ingredient_names, all_product_sources, required_technologies, get_rocket_requirements, \
|
2021-07-07 08:14:58 +00:00
|
|
|
progressive_technology_table, common_tech_table, tech_to_progressive_lookup, progressive_tech_table, \
|
2021-11-25 17:44:01 +00:00
|
|
|
get_science_pack_pools, Recipe, recipes, technology_table, tech_table, factorio_base_id, useless_technologies, \
|
2022-07-08 13:35:33 +00:00
|
|
|
fluids, stacking_items, valid_ingredients
|
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-12-01 07:18:17 +00:00
|
|
|
from .Options import factorio_options, MaxSciencePack, Silo, Satellite, TechTreeInformation, Goal
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-07-23 23:41:41 +00:00
|
|
|
import logging
|
|
|
|
|
2021-07-12 11:54:47 +00:00
|
|
|
|
2022-05-11 18:05:53 +00:00
|
|
|
class FactorioWeb(WebWorld):
|
|
|
|
tutorials = [Tutorial(
|
|
|
|
"Multiworld Setup Tutorial",
|
|
|
|
"A guide to setting up the Archipelago Factorio software on your computer.",
|
|
|
|
"English",
|
|
|
|
"setup_en.md",
|
|
|
|
"setup/en",
|
|
|
|
["Berserker, Farrak Kilhn"]
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
2021-07-12 11:54:47 +00:00
|
|
|
class FactorioItem(Item):
|
|
|
|
game = "Factorio"
|
|
|
|
|
|
|
|
|
2021-08-04 03:40:51 +00:00
|
|
|
all_items = tech_table.copy()
|
|
|
|
all_items["Attack Trap"] = factorio_base_id - 1
|
|
|
|
all_items["Evolution Trap"] = factorio_base_id - 2
|
|
|
|
|
|
|
|
|
2021-05-12 23:34:59 +00:00
|
|
|
class Factorio(World):
|
2021-08-31 21:28:46 +00:00
|
|
|
"""
|
|
|
|
Factorio is a game about automation. You play as an engineer who has crash landed on the planet
|
|
|
|
Nauvis, an inhospitable world filled with dangerous creatures called biters. Build a factory,
|
|
|
|
research new technologies, and become more efficient in your quest to build a rocket and return home.
|
|
|
|
"""
|
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"}
|
2022-03-14 18:40:35 +00:00
|
|
|
custom_recipes: typing.Dict[str, Recipe]
|
2021-11-20 03:47:19 +00:00
|
|
|
advancement_technologies: typing.Set[str]
|
2021-06-11 12:22:44 +00:00
|
|
|
|
2022-05-11 18:05:53 +00:00
|
|
|
web = FactorioWeb()
|
|
|
|
|
2021-08-04 03:40:51 +00:00
|
|
|
item_name_to_id = all_items
|
2021-07-12 16:05:46 +00:00
|
|
|
location_name_to_id = base_tech_table
|
2022-02-05 14:49:19 +00:00
|
|
|
item_name_groups = {
|
2022-06-01 15:25:40 +00:00
|
|
|
"Progressive": set(progressive_tech_table.keys()),
|
2022-02-05 14:49:19 +00:00
|
|
|
}
|
2021-08-06 06:14:16 +00:00
|
|
|
data_version = 5
|
2022-04-08 09:16:36 +00:00
|
|
|
required_client_version = (0, 3, 0)
|
2021-08-01 04:15:50 +00:00
|
|
|
|
2021-11-19 18:44:34 +00:00
|
|
|
def __init__(self, world, player: int):
|
|
|
|
super(Factorio, self).__init__(world, player)
|
2021-11-20 03:47:19 +00:00
|
|
|
self.advancement_technologies = set()
|
2022-03-14 18:40:35 +00:00
|
|
|
self.custom_recipes = {}
|
2021-11-19 18:44:34 +00:00
|
|
|
|
2021-07-22 16:21:31 +00:00
|
|
|
def generate_basic(self):
|
2021-08-04 03:40:51 +00:00
|
|
|
player = self.player
|
|
|
|
want_progressives = collections.defaultdict(lambda: self.world.progressive[player].
|
2021-08-03 17:03:41 +00:00
|
|
|
want_progressives(self.world.random))
|
2021-08-04 03:40:51 +00:00
|
|
|
skip_silo = self.world.silo[player].value == Silo.option_spawn
|
|
|
|
evolution_traps_wanted = self.world.evolution_traps[player].value
|
|
|
|
attack_traps_wanted = self.world.attack_traps[player].value
|
|
|
|
traps_wanted = ["Evolution Trap"] * evolution_traps_wanted + ["Attack Trap"] * attack_traps_wanted
|
|
|
|
self.world.random.shuffle(traps_wanted)
|
2022-03-24 16:15:52 +00:00
|
|
|
|
2021-07-12 11:54:47 +00:00
|
|
|
for tech_name in base_tech_table:
|
2021-08-04 03:40:51 +00:00
|
|
|
if traps_wanted and tech_name in useless_technologies:
|
|
|
|
self.world.itempool.append(self.create_item(traps_wanted.pop()))
|
|
|
|
elif skip_silo and tech_name == "rocket-silo":
|
|
|
|
pass
|
2021-05-12 23:34:59 +00:00
|
|
|
else:
|
2021-08-04 03:40:51 +00:00
|
|
|
progressive_item_name = tech_to_progressive_lookup.get(tech_name, tech_name)
|
|
|
|
want_progressive = want_progressives[progressive_item_name]
|
|
|
|
item_name = progressive_item_name if want_progressive else tech_name
|
|
|
|
tech_item = self.create_item(item_name)
|
|
|
|
if tech_name in self.static_nodes:
|
|
|
|
self.world.get_location(tech_name, player).place_locked_item(tech_item)
|
|
|
|
else:
|
|
|
|
self.world.itempool.append(tech_item)
|
2022-03-24 16:15:52 +00:00
|
|
|
|
2021-08-04 03:40:51 +00:00
|
|
|
map_basic_settings = self.world.world_gen[player].value["basic"]
|
2021-07-18 23:02:23 +00:00
|
|
|
if map_basic_settings.get("seed", None) is None: # allow seed 0
|
2021-08-04 03:40:51 +00:00
|
|
|
map_basic_settings["seed"] = self.world.slot_seeds[player].randint(0, 2 ** 32 - 1) # 32 bit uint
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2022-03-24 16:15:52 +00:00
|
|
|
# used to be called "sending_visible"
|
|
|
|
if self.world.tech_tree_information[player] == TechTreeInformation.option_full:
|
|
|
|
# mark all locations as pre-hinted
|
|
|
|
self.world.start_location_hints[self.player].value.update(base_tech_table)
|
2021-10-10 03:38:53 +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
|
2022-03-14 18:40:35 +00:00
|
|
|
menu = Region("Menu", RegionType.Generic, "Menu", player, self.world)
|
2021-06-11 12:22:44 +00:00
|
|
|
crash = Entrance(player, "Crash Land", menu)
|
|
|
|
menu.exits.append(crash)
|
2022-03-14 18:40:35 +00:00
|
|
|
nauvis = Region("Nauvis", RegionType.Generic, "Nauvis", player, self.world)
|
2021-04-01 09:40:58 +00:00
|
|
|
|
2021-07-25 20:12:03 +00:00
|
|
|
skip_silo = self.world.silo[self.player].value == Silo.option_spawn
|
2021-07-04 20:21:53 +00:00
|
|
|
for tech_name, tech_id in base_tech_table.items():
|
2021-07-25 20:12:03 +00:00
|
|
|
if skip_silo and tech_name == "rocket-silo":
|
|
|
|
continue
|
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"
|
2022-06-17 01:23:27 +00:00
|
|
|
event = FactorioItem("Victory", ItemClassification.progression, 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)
|
2022-06-17 01:23:27 +00:00
|
|
|
event = FactorioItem(f"Automated {ingredient}", ItemClassification.progression, 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]
|
|
|
|
|
2021-09-22 06:08:29 +00:00
|
|
|
location.access_rule = lambda state, ingredient=ingredient, custom_recipe=custom_recipe: \
|
2021-07-07 08:14:58 +00:00
|
|
|
(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-07-25 20:12:03 +00:00
|
|
|
skip_silo = self.world.silo[self.player].value == Silo.option_spawn
|
2021-06-11 16:02:48 +00:00
|
|
|
for tech_name, technology in self.custom_technologies.items():
|
2021-07-25 20:12:03 +00:00
|
|
|
if skip_silo and tech_name == "rocket-silo":
|
|
|
|
continue
|
2021-06-11 16:02:48 +00:00
|
|
|
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
|
|
|
|
2021-12-04 09:54:11 +00:00
|
|
|
silo_recipe = None
|
|
|
|
if self.world.silo[self.player] == Silo.option_spawn:
|
|
|
|
silo_recipe = self.custom_recipes["rocket-silo"] if "rocket-silo" in self.custom_recipes \
|
2022-02-02 15:29:29 +00:00
|
|
|
else next(iter(all_product_sources.get("rocket-silo")))
|
2021-07-23 23:41:41 +00:00
|
|
|
part_recipe = self.custom_recipes["rocket-part"]
|
2021-12-04 09:54:11 +00:00
|
|
|
satellite_recipe = None
|
|
|
|
if self.world.goal[self.player] == Goal.option_satellite:
|
|
|
|
satellite_recipe = self.custom_recipes["satellite"] if "satellite" in self.custom_recipes \
|
2022-02-02 15:29:29 +00:00
|
|
|
else next(iter(all_product_sources.get("satellite")))
|
2021-11-20 20:35:51 +00:00
|
|
|
victory_tech_names = get_rocket_requirements(silo_recipe, part_recipe, satellite_recipe)
|
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-08-21 04:55:08 +00:00
|
|
|
def collect_item(self, state, item, remove=False):
|
2021-07-04 20:21:53 +00:00
|
|
|
if item.advancement and item.name in progressive_technology_table:
|
|
|
|
prog_table = progressive_technology_table[item.name].progressive
|
2021-08-21 04:55:08 +00:00
|
|
|
if remove:
|
|
|
|
for item_name in reversed(prog_table):
|
|
|
|
if state.has(item_name, item.player):
|
|
|
|
return item_name
|
|
|
|
else:
|
|
|
|
for item_name in prog_table:
|
|
|
|
if not state.has(item_name, item.player):
|
|
|
|
return item_name
|
2021-08-10 07:47:28 +00:00
|
|
|
|
2021-08-21 04:55:08 +00:00
|
|
|
return super(Factorio, self).collect_item(state, item, remove)
|
2021-07-04 20:21:53 +00:00
|
|
|
|
2021-06-25 21:32:13 +00:00
|
|
|
options = factorio_options
|
|
|
|
|
2021-11-02 11:29:29 +00:00
|
|
|
@classmethod
|
|
|
|
def stage_write_spoiler(cls, world, spoiler_handle):
|
|
|
|
factorio_players = world.get_game_players(cls.game)
|
|
|
|
spoiler_handle.write('\n\nFactorio Recipes:\n')
|
|
|
|
for player in factorio_players:
|
|
|
|
name = world.get_player_name(player)
|
|
|
|
for recipe in world.worlds[player].custom_recipes.values():
|
|
|
|
spoiler_handle.write(f"\n{recipe.name} ({name}): {recipe.ingredients} -> {recipe.products}")
|
|
|
|
|
2021-11-26 02:27:16 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_category(category: str, liquids: int) -> str:
|
|
|
|
categories = {1: "crafting-with-fluid",
|
|
|
|
2: "chemistry"}
|
|
|
|
return categories.get(liquids, category)
|
|
|
|
|
|
|
|
def make_quick_recipe(self, original: Recipe, pool: list, allow_liquids: int = 2) -> Recipe:
|
|
|
|
new_ingredients = {}
|
|
|
|
liquids_used = 0
|
|
|
|
for _ in original.ingredients:
|
|
|
|
new_ingredient = pool.pop()
|
2022-06-18 11:40:02 +00:00
|
|
|
if new_ingredient in fluids:
|
|
|
|
while liquids_used == allow_liquids and new_ingredient in fluids:
|
2022-03-15 13:02:05 +00:00
|
|
|
# liquids already at max for current recipe.
|
|
|
|
# Return the liquid to the pool and get a new ingredient.
|
2021-11-26 02:27:16 +00:00
|
|
|
pool.append(new_ingredient)
|
2022-03-15 13:02:05 +00:00
|
|
|
new_ingredient = pool.pop(0)
|
2022-07-31 21:01:39 +00:00
|
|
|
liquids_used += 1 if new_ingredient in fluids else 0
|
2021-11-26 02:27:16 +00:00
|
|
|
new_ingredients[new_ingredient] = 1
|
2022-02-02 15:29:29 +00:00
|
|
|
return Recipe(original.name, self.get_category(original.category, liquids_used), new_ingredients,
|
|
|
|
original.products, original.energy)
|
2021-11-26 02:27:16 +00:00
|
|
|
|
2022-06-18 07:15:14 +00:00
|
|
|
def make_balanced_recipe(self, original: Recipe, pool: typing.Set[str], factor: float = 1,
|
|
|
|
allow_liquids: int = 2) -> Recipe:
|
2021-07-23 23:41:41 +00:00
|
|
|
"""Generate a recipe from pool with time and cost similar to original * factor"""
|
|
|
|
new_ingredients = {}
|
2022-06-18 07:15:14 +00:00
|
|
|
# have to first sort for determinism, while filtering out non-stacking items
|
2022-07-08 13:35:33 +00:00
|
|
|
pool: typing.List[str] = sorted(pool & valid_ingredients)
|
2022-06-18 07:15:14 +00:00
|
|
|
# then sort with random data to shuffle
|
|
|
|
self.world.random.shuffle(pool)
|
2021-07-23 23:41:41 +00:00
|
|
|
target_raw = int(sum((count for ingredient, count in original.base_cost.items())) * factor)
|
|
|
|
target_energy = original.total_energy * factor
|
|
|
|
target_num_ingredients = len(original.ingredients)
|
|
|
|
remaining_raw = target_raw
|
|
|
|
remaining_energy = target_energy
|
|
|
|
remaining_num_ingredients = target_num_ingredients
|
|
|
|
fallback_pool = []
|
2021-11-25 17:44:01 +00:00
|
|
|
liquids_used = 0
|
2021-07-23 23:41:41 +00:00
|
|
|
|
|
|
|
# fill all but one slot with random ingredients, last with a good match
|
2021-11-19 18:44:34 +00:00
|
|
|
while remaining_num_ingredients > 0 and pool:
|
2021-11-26 01:37:15 +00:00
|
|
|
ingredient = pool.pop()
|
2022-06-18 11:40:02 +00:00
|
|
|
if liquids_used == allow_liquids and ingredient in fluids:
|
2022-02-02 15:29:29 +00:00
|
|
|
continue # can't use this ingredient as we already have maximum liquid in our recipe.
|
2022-05-21 18:57:26 +00:00
|
|
|
ingredient_raw = 0
|
2021-11-26 01:37:15 +00:00
|
|
|
if ingredient in all_product_sources:
|
|
|
|
ingredient_recipe = min(all_product_sources[ingredient], key=lambda recipe: recipe.rel_cost)
|
|
|
|
ingredient_raw = sum((count for ingredient, count in ingredient_recipe.base_cost.items()))
|
|
|
|
ingredient_energy = ingredient_recipe.total_energy
|
|
|
|
else:
|
|
|
|
# assume simple ore TODO: remove if tree when mining data is harvested from Factorio
|
|
|
|
ingredient_energy = 2
|
2022-05-21 18:57:26 +00:00
|
|
|
if not ingredient_raw:
|
|
|
|
ingredient_raw = 1
|
2021-07-23 23:41:41 +00:00
|
|
|
if remaining_num_ingredients == 1:
|
|
|
|
max_raw = 1.1 * remaining_raw
|
|
|
|
min_raw = 0.9 * remaining_raw
|
|
|
|
max_energy = 1.1 * remaining_energy
|
2021-11-22 02:24:25 +00:00
|
|
|
min_energy = 0.9 * remaining_energy
|
2021-07-23 23:41:41 +00:00
|
|
|
else:
|
|
|
|
max_raw = remaining_raw * 0.75
|
|
|
|
min_raw = (remaining_raw - max_raw) / remaining_num_ingredients
|
|
|
|
max_energy = remaining_energy * 0.75
|
|
|
|
min_energy = (remaining_energy - max_energy) / remaining_num_ingredients
|
2021-09-22 06:08:29 +00:00
|
|
|
min_num_raw = min_raw / ingredient_raw
|
|
|
|
max_num_raw = max_raw / ingredient_raw
|
|
|
|
min_num_energy = min_energy / ingredient_energy
|
|
|
|
max_num_energy = max_energy / ingredient_energy
|
2021-07-23 23:41:41 +00:00
|
|
|
min_num = int(max(1, min_num_raw, min_num_energy))
|
|
|
|
max_num = int(min(1000, max_num_raw, max_num_energy))
|
|
|
|
if min_num > max_num:
|
|
|
|
fallback_pool.append(ingredient)
|
2021-09-22 06:08:29 +00:00
|
|
|
continue # can't use that ingredient
|
|
|
|
num = self.world.random.randint(min_num, max_num)
|
2021-07-23 23:41:41 +00:00
|
|
|
new_ingredients[ingredient] = num
|
|
|
|
remaining_raw -= num * ingredient_raw
|
|
|
|
remaining_energy -= num * ingredient_energy
|
|
|
|
remaining_num_ingredients -= 1
|
2022-06-18 11:40:02 +00:00
|
|
|
if ingredient in fluids:
|
2021-11-25 17:44:01 +00:00
|
|
|
liquids_used += 1
|
2021-07-23 23:41:41 +00:00
|
|
|
|
|
|
|
# fill failed slots with whatever we got
|
|
|
|
pool = fallback_pool
|
2021-11-19 18:44:34 +00:00
|
|
|
while remaining_num_ingredients > 0 and pool:
|
2021-07-23 23:41:41 +00:00
|
|
|
ingredient = pool.pop()
|
2022-06-18 11:40:02 +00:00
|
|
|
if liquids_used == allow_liquids and ingredient in fluids:
|
2021-11-26 01:37:15 +00:00
|
|
|
continue # can't use this ingredient as we already have maximum liquid in our recipe.
|
|
|
|
|
2021-11-26 00:38:33 +00:00
|
|
|
ingredient_recipe = recipes.get(ingredient, None)
|
|
|
|
if not ingredient_recipe and ingredient.endswith("-barrel"):
|
|
|
|
ingredient_recipe = recipes.get(f"fill-{ingredient}", None)
|
|
|
|
if not ingredient_recipe:
|
2021-07-23 23:41:41 +00:00
|
|
|
logging.warning(f"missing recipe for {ingredient}")
|
|
|
|
continue
|
|
|
|
ingredient_raw = sum((count for ingredient, count in ingredient_recipe.base_cost.items()))
|
|
|
|
ingredient_energy = ingredient_recipe.total_energy
|
2021-09-22 06:08:29 +00:00
|
|
|
num_raw = remaining_raw / ingredient_raw / remaining_num_ingredients
|
|
|
|
num_energy = remaining_energy / ingredient_energy / remaining_num_ingredients
|
2021-07-23 23:41:41 +00:00
|
|
|
num = int(min(num_raw, num_energy))
|
2021-11-26 01:37:15 +00:00
|
|
|
if num < 1:
|
|
|
|
continue
|
|
|
|
|
2021-07-23 23:41:41 +00:00
|
|
|
new_ingredients[ingredient] = num
|
|
|
|
remaining_raw -= num * ingredient_raw
|
|
|
|
remaining_energy -= num * ingredient_energy
|
|
|
|
remaining_num_ingredients -= 1
|
2022-06-18 11:40:02 +00:00
|
|
|
if ingredient in fluids:
|
2021-11-25 17:44:01 +00:00
|
|
|
liquids_used += 1
|
2021-07-23 23:41:41 +00:00
|
|
|
|
|
|
|
if remaining_num_ingredients > 1:
|
|
|
|
logging.warning("could not randomize recipe")
|
|
|
|
|
2022-02-02 15:29:29 +00:00
|
|
|
return Recipe(original.name, self.get_category(original.category, liquids_used), new_ingredients,
|
|
|
|
original.products, original.energy)
|
2021-07-23 23:41:41 +00:00
|
|
|
|
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()
|
2022-07-09 10:35:38 +00:00
|
|
|
valid_pool = sorted(science_pack_pools[self.world.max_science_pack[self.player].get_max_pack()] & valid_ingredients)
|
2021-07-07 08:14:58 +00:00
|
|
|
self.world.random.shuffle(valid_pool)
|
|
|
|
self.custom_recipes = {"rocket-part": Recipe("rocket-part", original_rocket_part.category,
|
2021-09-22 06:08:29 +00:00
|
|
|
{valid_pool[x]: 10 for x in range(3)},
|
2021-07-23 23:41:41 +00:00
|
|
|
original_rocket_part.products,
|
|
|
|
original_rocket_part.energy)}
|
2021-07-07 08:14:58 +00:00
|
|
|
|
|
|
|
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)
|
2021-09-22 06:08:29 +00:00
|
|
|
if pack in recipes: # skips over space science pack
|
2021-11-26 02:27:16 +00:00
|
|
|
new_recipe = self.make_quick_recipe(recipes[pack], valid_pool)
|
2021-07-07 08:14:58 +00:00
|
|
|
self.custom_recipes[pack] = new_recipe
|
|
|
|
|
2021-11-21 00:27:17 +00:00
|
|
|
if self.world.silo[self.player].value == Silo.option_randomize_recipe \
|
|
|
|
or self.world.satellite[self.player].value == Satellite.option_randomize_recipe:
|
2022-06-18 07:15:14 +00:00
|
|
|
valid_pool = set()
|
2021-09-26 21:02:19 +00:00
|
|
|
for pack in sorted(self.world.max_science_pack[self.player].get_allowed_packs()):
|
2022-06-18 07:15:14 +00:00
|
|
|
valid_pool |= science_pack_pools[pack]
|
2021-07-23 23:41:41 +00:00
|
|
|
|
2021-11-21 00:27:17 +00:00
|
|
|
if self.world.silo[self.player].value == Silo.option_randomize_recipe:
|
2022-03-14 18:40:35 +00:00
|
|
|
new_recipe = self.make_balanced_recipe(recipes["rocket-silo"], valid_pool,
|
2021-11-21 00:27:17 +00:00
|
|
|
factor=(self.world.max_science_pack[self.player].value + 1) / 7)
|
|
|
|
self.custom_recipes["rocket-silo"] = new_recipe
|
|
|
|
|
|
|
|
if self.world.satellite[self.player].value == Satellite.option_randomize_recipe:
|
|
|
|
new_recipe = self.make_balanced_recipe(recipes["satellite"], valid_pool,
|
|
|
|
factor=(self.world.max_science_pack[self.player].value + 1) / 7)
|
|
|
|
self.custom_recipes["satellite"] = new_recipe
|
2022-03-14 18:40:35 +00:00
|
|
|
bridge = "ap-energy-bridge"
|
|
|
|
new_recipe = self.make_quick_recipe(
|
|
|
|
Recipe(bridge, "crafting", {"replace_1": 1, "replace_2": 1, "replace_3": 1},
|
|
|
|
{bridge: 1}, 10),
|
|
|
|
sorted(science_pack_pools[self.world.max_science_pack[self.player].get_ordered_science_packs()[0]]))
|
|
|
|
for ingredient_name in new_recipe.ingredients:
|
2022-03-15 13:01:15 +00:00
|
|
|
new_recipe.ingredients[ingredient_name] = self.world.random.randint(10, 100)
|
2022-03-14 18:40:35 +00:00
|
|
|
self.custom_recipes[bridge] = new_recipe
|
2021-11-21 00:27:17 +00:00
|
|
|
|
|
|
|
needed_recipes = self.world.max_science_pack[self.player].get_allowed_packs() | {"rocket-part"}
|
|
|
|
if self.world.silo[self.player] != Silo.option_spawn:
|
|
|
|
needed_recipes |= {"rocket-silo"}
|
2021-12-04 14:20:16 +00:00
|
|
|
if self.world.goal[self.player].value == Goal.option_satellite:
|
2021-11-20 20:35:51 +00:00
|
|
|
needed_recipes |= {"satellite"}
|
2021-11-20 03:47:19 +00:00
|
|
|
|
|
|
|
for recipe in needed_recipes:
|
|
|
|
recipe = self.custom_recipes.get(recipe, recipes[recipe])
|
|
|
|
self.advancement_technologies |= {tech.name for tech in recipe.recursive_unlocking_technologies}
|
|
|
|
|
2021-07-07 08:14:58 +00:00
|
|
|
# handle marking progressive techs as advancement
|
|
|
|
prog_add = set()
|
2021-11-20 03:47:19 +00:00
|
|
|
for tech in self.advancement_technologies:
|
2021-07-07 08:14:58 +00:00
|
|
|
if tech in tech_to_progressive_lookup:
|
|
|
|
prog_add.add(tech_to_progressive_lookup[tech])
|
2021-11-20 03:47:19 +00:00
|
|
|
self.advancement_technologies |= prog_add
|
2021-07-12 11:54:47 +00:00
|
|
|
|
2022-06-17 01:23:27 +00:00
|
|
|
def create_item(self, name: str) -> FactorioItem:
|
|
|
|
if name in tech_table: # is a Technology
|
|
|
|
if name in self.advancement_technologies:
|
|
|
|
classification = ItemClassification.progression
|
|
|
|
else:
|
|
|
|
classification = ItemClassification.filler
|
|
|
|
return FactorioItem(name,
|
|
|
|
classification,
|
2021-08-04 03:40:51 +00:00
|
|
|
tech_table[name], self.player)
|
2021-09-29 03:21:33 +00:00
|
|
|
|
2022-06-17 01:23:27 +00:00
|
|
|
item = FactorioItem(name,
|
|
|
|
ItemClassification.trap if "Trap" in name else ItemClassification.filler,
|
|
|
|
all_items[name], self.player)
|
2021-09-29 03:21:33 +00:00
|
|
|
return item
|