Update Factorio mod to give free samples

(for now always, probably an option later)
This commit is contained in:
Fabian Dill 2021-04-06 02:20:13 +02:00
parent 635897574f
commit bc1d0ed583
3 changed files with 44 additions and 12 deletions

View File

@ -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)

View File

@ -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 }}))

View File

@ -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 %}