implement Factorio option "free_samples"
This commit is contained in:
parent
bc1d0ed583
commit
96a28ed41e
|
@ -262,6 +262,12 @@ class TechCost(Choice):
|
||||||
option_insane = 6
|
option_insane = 6
|
||||||
default = 3
|
default = 3
|
||||||
|
|
||||||
|
class FreeSamples(Choice):
|
||||||
|
option_none = 0
|
||||||
|
option_single_craft = 1
|
||||||
|
option_half_stack = 2
|
||||||
|
option_stack = 3
|
||||||
|
default = 3
|
||||||
|
|
||||||
class TechTreeLayout(Choice):
|
class TechTreeLayout(Choice):
|
||||||
option_single = 0
|
option_single = 0
|
||||||
|
@ -270,7 +276,8 @@ class TechTreeLayout(Choice):
|
||||||
|
|
||||||
factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxSciencePack,
|
factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxSciencePack,
|
||||||
"tech_tree_layout": TechTreeLayout,
|
"tech_tree_layout": TechTreeLayout,
|
||||||
"tech_cost": TechCost}
|
"tech_cost": TechCost,
|
||||||
|
"free_samples": FreeSamples}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
|
|
|
@ -24,12 +24,29 @@ function filter_ingredients(ingredients)
|
||||||
return new_ingredient_list
|
return new_ingredient_list
|
||||||
end
|
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)
|
function prep_copy(new_copy, old_tech)
|
||||||
old_tech.enabled = false
|
old_tech.enabled = false
|
||||||
new_copy.unit = table.deepcopy(old_tech.unit)
|
new_copy.unit = table.deepcopy(old_tech.unit)
|
||||||
new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients)
|
new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients)
|
||||||
|
{% if free_samples %}
|
||||||
local new_effects = {}
|
local new_effects = {}
|
||||||
log(serpent.block(old_tech.effects))
|
|
||||||
if old_tech.effects then
|
if old_tech.effects then
|
||||||
for _, effect in pairs(old_tech.effects) do
|
for _, effect in pairs(old_tech.effects) do
|
||||||
if effect.type == "unlock-recipe" then
|
if effect.type == "unlock-recipe" then
|
||||||
|
@ -48,7 +65,13 @@ function prep_copy(new_copy, old_tech)
|
||||||
end
|
end
|
||||||
for _, result in pairs(results) do
|
for _, result in pairs(results) do
|
||||||
if result.type == "item" then
|
if result.type == "item" then
|
||||||
|
{% if free_samples == 1 %}
|
||||||
local new = {type="give-item", count=result.amount, item=result.name}
|
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)
|
table.insert(new_effects, new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -58,6 +81,7 @@ function prep_copy(new_copy, old_tech)
|
||||||
for _, effect in pairs(new_effects) do
|
for _, effect in pairs(new_effects) do
|
||||||
table.insert(old_tech.effects, effect)
|
table.insert(old_tech.effects, effect)
|
||||||
end
|
end
|
||||||
|
{% endif %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,11 @@ tech_cost:
|
||||||
hard : 0
|
hard : 0
|
||||||
very_hard : 0
|
very_hard : 0
|
||||||
insane : 0
|
insane : 0
|
||||||
|
free_samples:
|
||||||
|
none: 1
|
||||||
|
single_craft: 0
|
||||||
|
half_stack: 0
|
||||||
|
stack: 0
|
||||||
# A Link to the Past options:
|
# A Link to the Past options:
|
||||||
### Logic Section ###
|
### Logic Section ###
|
||||||
# Warning: overworld_glitches is not available and minor_glitches is only partially implemented on the door-rando version
|
# Warning: overworld_glitches is not available and minor_glitches is only partially implemented on the door-rando version
|
||||||
|
|
|
@ -48,7 +48,7 @@ def generate_mod(world: MultiWorld, player: int):
|
||||||
6: 10}[world.tech_cost[player].value]
|
6: 10}[world.tech_cost[player].value]
|
||||||
template_data = {"locations": locations, "player_names" : player_names, "tech_table": tech_table,
|
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(),
|
"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)
|
mod_code = template.render(**template_data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue