From 96a28ed41ef4312e2bebb752196900bb8d736566 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 6 Apr 2021 21:16:25 +0200 Subject: [PATCH] implement Factorio option "free_samples" --- Options.py | 9 ++++++- .../mod_template/data-final-fixes.lua | 26 ++++++++++++++++++- playerSettings.yaml | 5 ++++ worlds/factorio/Mod.py | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/Options.py b/Options.py index 826fff6c..ea32ca51 100644 --- a/Options.py +++ b/Options.py @@ -262,6 +262,12 @@ class TechCost(Choice): option_insane = 6 default = 3 +class FreeSamples(Choice): + option_none = 0 + option_single_craft = 1 + option_half_stack = 2 + option_stack = 3 + default = 3 class TechTreeLayout(Choice): option_single = 0 @@ -270,7 +276,8 @@ class TechTreeLayout(Choice): factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxSciencePack, "tech_tree_layout": TechTreeLayout, - "tech_cost": TechCost} + "tech_cost": TechCost, + "free_samples": FreeSamples} if __name__ == "__main__": import argparse diff --git a/data/factorio/mod_template/data-final-fixes.lua b/data/factorio/mod_template/data-final-fixes.lua index e97fedd0..8c0f18bd 100644 --- a/data/factorio/mod_template/data-final-fixes.lua +++ b/data/factorio/mod_template/data-final-fixes.lua @@ -24,12 +24,29 @@ function filter_ingredients(ingredients) return new_ingredient_list end +function get_any_stack_size(name) + local item = data.raw["item"][name] + if item ~= nil then + return item.stack_size + end + {#- need to search #} + for _, group in pairs(data.raw) do + for _, testitem in pairs(group) do + if testitem.name == name then + return testitem.stack_size + end + end + end + {#- failsafe #} + return 1 +end + function prep_copy(new_copy, old_tech) old_tech.enabled = false new_copy.unit = table.deepcopy(old_tech.unit) new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients) + {% if free_samples %} local new_effects = {} - log(serpent.block(old_tech.effects)) if old_tech.effects then for _, effect in pairs(old_tech.effects) do if effect.type == "unlock-recipe" then @@ -48,7 +65,13 @@ function prep_copy(new_copy, old_tech) end for _, result in pairs(results) do if result.type == "item" then + {% if free_samples == 1 %} local new = {type="give-item", count=result.amount, item=result.name} + {% elif free_samples == 2 %} + local new = {type="give-item", count=get_any_stack_size(result.name) * 0.5, item=result.name} + {% else %} + local new = {type="give-item", count=get_any_stack_size(result.name), item=result.name} + {% endif %} table.insert(new_effects, new) end end @@ -58,6 +81,7 @@ function prep_copy(new_copy, old_tech) for _, effect in pairs(new_effects) do table.insert(old_tech.effects, effect) end + {% endif %} end diff --git a/playerSettings.yaml b/playerSettings.yaml index 01399eb0..3e470690 100644 --- a/playerSettings.yaml +++ b/playerSettings.yaml @@ -54,6 +54,11 @@ tech_cost: hard : 0 very_hard : 0 insane : 0 +free_samples: + none: 1 + single_craft: 0 + half_stack: 0 + stack: 0 # A Link to the Past options: ### Logic Section ### # Warning: overworld_glitches is not available and minor_glitches is only partially implemented on the door-rando version diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index ac396cdd..4bf3eae4 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -48,7 +48,7 @@ def generate_mod(world: MultiWorld, player: int): 6: 10}[world.tech_cost[player].value] template_data = {"locations": locations, "player_names" : player_names, "tech_table": tech_table, "mod_name": mod_name, "allowed_science_packs": world.max_science_pack[player].get_allowed_packs(), - "tech_cost": tech_cost} + "tech_cost": tech_cost, "free_samples": world.free_samples[player].value} mod_code = template.render(**template_data)