From bc1d0ed583587813dcabe980c25c9d342b32d8ff Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 6 Apr 2021 02:20:13 +0200 Subject: [PATCH] Update Factorio mod to give free samples (for now always, probably an option later) --- data/factorio/mod/control.lua | 11 +++-- .../mod_template/data-final-fixes.lua | 43 ++++++++++++++++--- .../mod_template/locale/en/locale.cfg | 2 +- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/data/factorio/mod/control.lua b/data/factorio/mod/control.lua index e43c3bad..f15d0e0f 100644 --- a/data/factorio/mod/control.lua +++ b/data/factorio/mod/control.lua @@ -1,13 +1,12 @@ -- for testing -script.on_event(defines.events.on_tick, function(event) - if event.tick%600 == 0 then - dumpTech() - end -end) +-- script.on_event(defines.events.on_tick, function(event) +-- if event.tick%600 == 0 then +-- dumpTech() +-- end +-- end) -- hook into researches done script.on_event(defines.events.on_research_finished, function(event) - game.print("Research done") dumpTech() end) diff --git a/data/factorio/mod_template/data-final-fixes.lua b/data/factorio/mod_template/data-final-fixes.lua index 8bacb1fb..e97fedd0 100644 --- a/data/factorio/mod_template/data-final-fixes.lua +++ b/data/factorio/mod_template/data-final-fixes.lua @@ -24,17 +24,50 @@ function filter_ingredients(ingredients) return new_ingredient_list 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) + 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 + local recipe = data.raw["recipe"][effect.recipe] + local results + if recipe.normal then + if recipe.normal.result then + results = { {type = "item", amount= recipe.normal.result_count, name=recipe.normal.result} } + else + results = recipe.normal.results + end + elseif recipe.result then + results = { {type = "item", amount= recipe.result_count, name=recipe.result} } + else + results = recipe.results + end + for _, result in pairs(results) do + if result.type == "item" then + local new = {type="give-item", count=result.amount, item=result.name} + table.insert(new_effects, new) + end + end + end + end + end + for _, effect in pairs(new_effects) do + table.insert(old_tech.effects, effect) + end +end + + {# each randomized tech gets set to be invisible, with new nodes added that trigger those #} {%- for original_tech_name, item_name, receiving_player in locations %} original_tech = technologies["{{original_tech_name}}"] {#- the tech researched by the local player #} new_tree_copy = table.deepcopy(template_tech) new_tree_copy.name = "ap-{{ tech_table[original_tech_name] }}-"{# use AP ID #} -{#- hide and disable original tech; which will be shown, unlocked and enabled by AP Client #} -original_tech.enabled = false -{#- copy original tech costs #} -new_tree_copy.unit = table.deepcopy(original_tech.unit) -new_tree_copy.unit.ingredients = filter_ingredients(new_tree_copy.unit.ingredients) +prep_copy(new_tree_copy, original_tech) {% if tech_cost != 1 %} if new_tree_copy.unit.count then new_tree_copy.unit.count = math.max(1, math.floor(new_tree_copy.unit.count * {{ tech_cost }})) diff --git a/data/factorio/mod_template/locale/en/locale.cfg b/data/factorio/mod_template/locale/en/locale.cfg index c0178906..990f34ed 100644 --- a/data/factorio/mod_template/locale/en/locale.cfg +++ b/data/factorio/mod_template/locale/en/locale.cfg @@ -4,5 +4,5 @@ ap-{{ tech_table[original_tech_name] }}-={{ player_names[receiving_player] }}'s {% endfor %} [technology-description] {% for original_tech_name, item_name, receiving_player in locations %} -"ap-{{ tech_table[original_tech_name] }}-=Researching this technology sends {{ item_name }} to {{ player_names[receiving_player] }}. +ap-{{ tech_table[original_tech_name] }}-=Researching this technology sends {{ item_name }} to {{ player_names[receiving_player] }}. {% endfor %} \ No newline at end of file