Factorio: exclude science packs and rocket-part from free samples
This commit is contained in:
parent
9f2f343f76
commit
91655a855d
|
@ -59,7 +59,7 @@ class FactorioManager(App):
|
||||||
super(FactorioManager, self).__init__()
|
super(FactorioManager, self).__init__()
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.commandprocessor = ctx.command_processor(ctx)
|
self.commandprocessor = ctx.command_processor(ctx)
|
||||||
self.icon = "data/icon.png"
|
self.icon = r"data/icon.png"
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self.grid = GridLayout()
|
self.grid = GridLayout()
|
||||||
|
|
|
@ -6,6 +6,7 @@ require "util"
|
||||||
FREE_SAMPLES = {{ free_samples }}
|
FREE_SAMPLES = {{ free_samples }}
|
||||||
SLOT_NAME = "{{ slot_name }}"
|
SLOT_NAME = "{{ slot_name }}"
|
||||||
SEED_NAME = "{{ seed_name }}"
|
SEED_NAME = "{{ seed_name }}"
|
||||||
|
FREE_SAMPLE_BLACKLIST = {{ dict_to_lua(free_sample_blacklist) }}
|
||||||
|
|
||||||
{% if not imported_blueprints -%}
|
{% if not imported_blueprints -%}
|
||||||
function set_permissions()
|
function set_permissions()
|
||||||
|
@ -152,29 +153,32 @@ script.on_event(defines.events.on_research_finished, function(event)
|
||||||
local technology = event.research
|
local technology = event.research
|
||||||
if technology.researched and string.find(technology.name, "ap%-") == 1 then
|
if technology.researched and string.find(technology.name, "ap%-") == 1 then
|
||||||
dumpInfo(technology.force) --is sendable
|
dumpInfo(technology.force) --is sendable
|
||||||
end
|
else
|
||||||
if FREE_SAMPLES == 0 then
|
if FREE_SAMPLES == 0 then
|
||||||
return -- Nothing else to do
|
return -- Nothing else to do
|
||||||
end
|
end
|
||||||
if not technology.effects then
|
if not technology.effects then
|
||||||
return -- No technology effects, so nothing to do.
|
return -- No technology effects, so nothing to do.
|
||||||
end
|
end
|
||||||
for _, effect in pairs(technology.effects) do
|
for _, effect in pairs(technology.effects) do
|
||||||
if effect.type == "unlock-recipe" then
|
if effect.type == "unlock-recipe" then
|
||||||
local recipe = game.recipe_prototypes[effect.recipe]
|
local recipe = game.recipe_prototypes[effect.recipe]
|
||||||
for _, result in pairs(recipe.products) do
|
for _, result in pairs(recipe.products) do
|
||||||
if result.type == "item" and result.amount then
|
if result.type == "item" and result.amount then
|
||||||
local name = result.name
|
local name = result.name
|
||||||
local count
|
if FREE_SAMPLE_BLACKLIST[name] ~= 1 then
|
||||||
if FREE_SAMPLES == 1 then
|
local count
|
||||||
count = result.amount
|
if FREE_SAMPLES == 1 then
|
||||||
else
|
count = result.amount
|
||||||
count = get_any_stack_size(result.name)
|
else
|
||||||
if FREE_SAMPLES == 2 then
|
count = get_any_stack_size(result.name)
|
||||||
count = math.ceil(count / 2)
|
if FREE_SAMPLES == 2 then
|
||||||
|
count = math.ceil(count / 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
add_samples(technology.force, name, count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
add_samples(technology.force, name, count)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Utils
|
||||||
import shutil
|
import shutil
|
||||||
import Options
|
import Options
|
||||||
from BaseClasses import MultiWorld
|
from BaseClasses import MultiWorld
|
||||||
from .Technologies import tech_table, rocket_recipes, recipes
|
from .Technologies import tech_table, rocket_recipes, recipes, free_sample_blacklist
|
||||||
|
|
||||||
template_env: Optional[jinja2.Environment] = None
|
template_env: Optional[jinja2.Environment] = None
|
||||||
|
|
||||||
|
@ -76,7 +76,8 @@ def generate_mod(world: MultiWorld, player: int):
|
||||||
"slot_name": world.player_names[player][0], "seed_name": world.seed_name,
|
"slot_name": world.player_names[player][0], "seed_name": world.seed_name,
|
||||||
"starting_items": world.starting_items[player], "recipes": recipes,
|
"starting_items": world.starting_items[player], "recipes": recipes,
|
||||||
"random": world.slot_seeds[player], "static_nodes": world.worlds[player].static_nodes,
|
"random": world.slot_seeds[player], "static_nodes": world.worlds[player].static_nodes,
|
||||||
"recipe_time_scale": recipe_time_scales[world.recipe_time[player].value]}
|
"recipe_time_scale": recipe_time_scales[world.recipe_time[player].value],
|
||||||
|
"free_sample_blacklist": {item : 1 for item in free_sample_blacklist}}
|
||||||
|
|
||||||
for factorio_option in Options.factorio_options:
|
for factorio_option in Options.factorio_options:
|
||||||
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
||||||
|
|
|
@ -99,6 +99,7 @@ class Machine(FactorioElement):
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
self.categories: set = categories
|
self.categories: set = categories
|
||||||
|
|
||||||
|
|
||||||
# recipes and technologies can share names in Factorio
|
# recipes and technologies can share names in Factorio
|
||||||
for technology_name in sorted(raw):
|
for technology_name in sorted(raw):
|
||||||
data = raw[technology_name]
|
data = raw[technology_name]
|
||||||
|
@ -125,7 +126,8 @@ for recipe_name, recipe_data in raw_recipes.items():
|
||||||
|
|
||||||
recipe = Recipe(recipe_name, recipe_data["category"], set(recipe_data["ingredients"]), set(recipe_data["products"]))
|
recipe = Recipe(recipe_name, recipe_data["category"], set(recipe_data["ingredients"]), set(recipe_data["products"]))
|
||||||
recipes[recipe_name] = Recipe
|
recipes[recipe_name] = Recipe
|
||||||
if recipe.products.isdisjoint(recipe.ingredients) and "empty-barrel" not in recipe.products: # prevents loop recipes like uranium centrifuging
|
if recipe.products.isdisjoint(
|
||||||
|
recipe.ingredients) and "empty-barrel" not in recipe.products: # prevents loop recipes like uranium centrifuging
|
||||||
for product_name in recipe.products:
|
for product_name in recipe.products:
|
||||||
all_product_sources.setdefault(product_name, set()).add(recipe)
|
all_product_sources.setdefault(product_name, set()).add(recipe)
|
||||||
|
|
||||||
|
@ -153,6 +155,7 @@ def unlock_just_tech(recipe: Recipe, _done) -> Set[Technology]:
|
||||||
current_technologies |= recursively_get_unlocking_technologies(ingredient_name, _done)
|
current_technologies |= recursively_get_unlocking_technologies(ingredient_name, _done)
|
||||||
return current_technologies
|
return current_technologies
|
||||||
|
|
||||||
|
|
||||||
def unlock(recipe: Recipe, _done) -> Set[Technology]:
|
def unlock(recipe: Recipe, _done) -> Set[Technology]:
|
||||||
current_technologies = set()
|
current_technologies = set()
|
||||||
current_technologies |= recipe.unlocking_technologies
|
current_technologies |= recipe.unlocking_technologies
|
||||||
|
@ -162,7 +165,9 @@ def unlock(recipe: Recipe, _done) -> Set[Technology]:
|
||||||
|
|
||||||
return current_technologies
|
return current_technologies
|
||||||
|
|
||||||
def recursively_get_unlocking_technologies(ingredient_name, _done=None, unlock_func=unlock_just_tech) -> Set[Technology]:
|
|
||||||
|
def recursively_get_unlocking_technologies(ingredient_name, _done=None, unlock_func=unlock_just_tech) -> Set[
|
||||||
|
Technology]:
|
||||||
if _done:
|
if _done:
|
||||||
if ingredient_name in _done:
|
if ingredient_name in _done:
|
||||||
return set()
|
return set()
|
||||||
|
@ -180,7 +185,6 @@ def recursively_get_unlocking_technologies(ingredient_name, _done=None, unlock_f
|
||||||
return current_technologies
|
return current_technologies
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
required_machine_technologies: Dict[str, FrozenSet[Technology]] = {}
|
required_machine_technologies: Dict[str, FrozenSet[Technology]] = {}
|
||||||
for ingredient_name in machines:
|
for ingredient_name in machines:
|
||||||
required_machine_technologies[ingredient_name] = frozenset(recursively_get_unlocking_technologies(ingredient_name))
|
required_machine_technologies[ingredient_name] = frozenset(recursively_get_unlocking_technologies(ingredient_name))
|
||||||
|
@ -192,14 +196,14 @@ for machine in machines.values():
|
||||||
if machine != pot_source_machine \
|
if machine != pot_source_machine \
|
||||||
and machine.categories.issuperset(pot_source_machine.categories) \
|
and machine.categories.issuperset(pot_source_machine.categories) \
|
||||||
and required_machine_technologies[machine.name].issuperset(
|
and required_machine_technologies[machine.name].issuperset(
|
||||||
required_machine_technologies[pot_source_machine.name]):
|
required_machine_technologies[pot_source_machine.name]):
|
||||||
logically_useful = False
|
logically_useful = False
|
||||||
break
|
break
|
||||||
|
|
||||||
if logically_useful:
|
if logically_useful:
|
||||||
logical_machines[machine.name] = machine
|
logical_machines[machine.name] = machine
|
||||||
|
|
||||||
del(required_machine_technologies)
|
del (required_machine_technologies)
|
||||||
|
|
||||||
machines_per_category: Dict[str: Set[Machine]] = {}
|
machines_per_category: Dict[str: Set[Machine]] = {}
|
||||||
for machine in logical_machines.values():
|
for machine in logical_machines.values():
|
||||||
|
@ -219,11 +223,11 @@ for ingredient_name in all_ingredient_names:
|
||||||
required_technologies[ingredient_name] = frozenset(
|
required_technologies[ingredient_name] = frozenset(
|
||||||
recursively_get_unlocking_technologies(ingredient_name, unlock_func=unlock))
|
recursively_get_unlocking_technologies(ingredient_name, unlock_func=unlock))
|
||||||
|
|
||||||
|
|
||||||
advancement_technologies: Set[str] = set()
|
advancement_technologies: Set[str] = set()
|
||||||
for technologies in required_technologies.values():
|
for technologies in required_technologies.values():
|
||||||
advancement_technologies |= {technology.name for technology in technologies}
|
advancement_technologies |= {technology.name for technology in technologies}
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(10)
|
@functools.lru_cache(10)
|
||||||
def get_rocket_requirements(ingredients: Set[str]) -> Set[str]:
|
def get_rocket_requirements(ingredients: Set[str]) -> Set[str]:
|
||||||
techs = recursively_get_unlocking_technologies("rocket-silo")
|
techs = recursively_get_unlocking_technologies("rocket-silo")
|
||||||
|
@ -232,6 +236,8 @@ def get_rocket_requirements(ingredients: Set[str]) -> Set[str]:
|
||||||
return {tech.name for tech in techs}
|
return {tech.name for tech in techs}
|
||||||
|
|
||||||
|
|
||||||
|
free_sample_blacklist = all_ingredient_names | {"rocket-part"}
|
||||||
|
|
||||||
rocket_recipes = {
|
rocket_recipes = {
|
||||||
Options.MaxSciencePack.option_space_science_pack:
|
Options.MaxSciencePack.option_space_science_pack:
|
||||||
{"rocket-control-unit": 10, "low-density-structure": 10, "rocket-fuel": 10},
|
{"rocket-control-unit": 10, "low-density-structure": 10, "rocket-fuel": 10},
|
||||||
|
@ -247,4 +253,4 @@ rocket_recipes = {
|
||||||
{"electronic-circuit": 10, "stone-brick": 10, "coal": 10},
|
{"electronic-circuit": 10, "stone-brick": 10, "coal": 10},
|
||||||
Options.MaxSciencePack.option_automation_science_pack:
|
Options.MaxSciencePack.option_automation_science_pack:
|
||||||
{"copper-cable": 10, "iron-plate": 10, "wood": 10}
|
{"copper-cable": 10, "iron-plate": 10, "wood": 10}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue