Factorio: add starting_items
This commit is contained in:
parent
9c3d12dc55
commit
c55983af5f
|
@ -536,7 +536,10 @@ def roll_settings(weights: dict, plando_options: typing.Set[str] = frozenset(("b
|
||||||
elif ret.game == "Factorio":
|
elif ret.game == "Factorio":
|
||||||
for option_name, option in Options.factorio_options.items():
|
for option_name, option in Options.factorio_options.items():
|
||||||
if option_name in weights:
|
if option_name in weights:
|
||||||
setattr(ret, option_name, option.from_any(get_choice(option_name, weights)))
|
if issubclass(option, Options.OptionDict): # get_choice should probably land in the Option class
|
||||||
|
setattr(ret, option_name, option.from_any(weights[option_name]))
|
||||||
|
else:
|
||||||
|
setattr(ret, option_name, option.from_any(get_choice(option_name, weights)))
|
||||||
else:
|
else:
|
||||||
setattr(ret, option_name, option(option.default))
|
setattr(ret, option_name, option(option.default))
|
||||||
elif ret.game == "Minecraft":
|
elif ret.game == "Minecraft":
|
||||||
|
|
47
Options.py
47
Options.py
|
@ -103,12 +103,43 @@ class Choice(Option):
|
||||||
f'known options are {", ".join(f"{option}" for option in cls.name_lookup.values())}')
|
f'known options are {", ".join(f"{option}" for option in cls.name_lookup.values())}')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_any(cls, data: typing.Any):
|
def from_any(cls, data: typing.Any) -> Choice:
|
||||||
if type(data) == int and data in cls.options.values():
|
if type(data) == int and data in cls.options.values():
|
||||||
return cls(data)
|
return cls(data)
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
|
|
||||||
|
class OptionNameSet(Option):
|
||||||
|
default = frozenset()
|
||||||
|
|
||||||
|
def __init__(self, value: typing.Set[str]):
|
||||||
|
self.value: typing.Set[str] = value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_text(cls, text: str) -> OptionNameSet:
|
||||||
|
return cls({option.strip() for option in text.split(",")})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_any(cls, data: typing.Any) -> OptionNameSet:
|
||||||
|
if type(data) == set:
|
||||||
|
return cls(data)
|
||||||
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
|
|
||||||
|
class OptionDict(Option):
|
||||||
|
default = {}
|
||||||
|
|
||||||
|
def __init__(self, value: typing.Dict[str, typing.Any]):
|
||||||
|
self.value: typing.Dict[str, typing.Any] = value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_any(cls, data: typing.Dict[str, typing.Any]) -> OptionDict:
|
||||||
|
if type(data) == dict:
|
||||||
|
return cls(data)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(f"Cannot Convert from non-dictionary, got {type(data)}")
|
||||||
|
|
||||||
|
|
||||||
class Logic(Choice):
|
class Logic(Choice):
|
||||||
option_no_glitches = 0
|
option_no_glitches = 0
|
||||||
option_minor_glitches = 1
|
option_minor_glitches = 1
|
||||||
|
@ -289,12 +320,18 @@ class Visibility(Choice):
|
||||||
default = 1
|
default = 1
|
||||||
|
|
||||||
|
|
||||||
|
class FactorioStartItems(OptionDict):
|
||||||
|
default = {"burner-mining-drill": 19, "stone-furnace": 19}
|
||||||
|
|
||||||
|
|
||||||
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,
|
"free_samples": FreeSamples,
|
||||||
"visibility": Visibility,
|
"visibility": Visibility,
|
||||||
"random_tech_ingredients": Toggle}
|
"random_tech_ingredients": Toggle,
|
||||||
|
"starting_items": FactorioStartItems}
|
||||||
|
|
||||||
|
|
||||||
class AdvancementGoal(Choice):
|
class AdvancementGoal(Choice):
|
||||||
option_few = 0
|
option_few = 0
|
||||||
|
@ -302,14 +339,16 @@ class AdvancementGoal(Choice):
|
||||||
option_many = 2
|
option_many = 2
|
||||||
default = 1
|
default = 1
|
||||||
|
|
||||||
class CombatDifficulty(Choice):
|
|
||||||
|
class CombatDifficulty(Choice):
|
||||||
option_easy = 0
|
option_easy = 0
|
||||||
option_normal = 1
|
option_normal = 1
|
||||||
option_hard = 2
|
option_hard = 2
|
||||||
default = 1
|
default = 1
|
||||||
|
|
||||||
|
|
||||||
minecraft_options: typing.Dict[str, type(Option)] = {
|
minecraft_options: typing.Dict[str, type(Option)] = {
|
||||||
"advancement_goal": AdvancementGoal,
|
"advancement_goal": AdvancementGoal,
|
||||||
"combat_difficulty": CombatDifficulty,
|
"combat_difficulty": CombatDifficulty,
|
||||||
"include_hard_advancements": Toggle,
|
"include_hard_advancements": Toggle,
|
||||||
"include_insane_advancements": Toggle,
|
"include_insane_advancements": Toggle,
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
{% macro dict_to_lua(dict) -%}
|
||||||
|
{
|
||||||
|
{% for key, value in dict.items() %}
|
||||||
|
["{{ key }}"] = {{ value | safe }}{% if not loop.last %},{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{%- endmacro %}
|
||||||
require "lib"
|
require "lib"
|
||||||
require "util"
|
require "util"
|
||||||
|
|
||||||
|
@ -11,10 +18,7 @@ function on_force_created(event)
|
||||||
game.forces[event.force].research_queue_enabled = true
|
game.forces[event.force].research_queue_enabled = true
|
||||||
local data = {}
|
local data = {}
|
||||||
if FREE_SAMPLES ~= 0 then
|
if FREE_SAMPLES ~= 0 then
|
||||||
data['earned_samples'] = {
|
data['earned_samples'] = {{ dict_to_lua(starting_items) }}
|
||||||
["burner-mining-drill"] = 19,
|
|
||||||
["stone-furnace"] = 19
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
data["victory"] = 0
|
data["victory"] = 0
|
||||||
global.forcedata[event.force] = data
|
global.forcedata[event.force] = data
|
||||||
|
|
|
@ -70,6 +70,9 @@ visibility:
|
||||||
random_tech_ingredients:
|
random_tech_ingredients:
|
||||||
on: 1
|
on: 1
|
||||||
off: 0
|
off: 0
|
||||||
|
starting_items:
|
||||||
|
burner-mining-drill: 19
|
||||||
|
stone-furnace: 19
|
||||||
# Minecraft options:
|
# Minecraft options:
|
||||||
advancement_goal: # Number of advancements required (out of 92 total) to spawn the Ender Dragon and complete the game.
|
advancement_goal: # Number of advancements required (out of 92 total) to spawn the Ender Dragon and complete the game.
|
||||||
few: 0 # 30 advancements
|
few: 0 # 30 advancements
|
||||||
|
|
|
@ -71,7 +71,8 @@ def generate_mod(world: MultiWorld, player: int, seedname: str):
|
||||||
"tech_cost_scale": tech_cost, "custom_data": world.custom_data[player],
|
"tech_cost_scale": tech_cost, "custom_data": world.custom_data[player],
|
||||||
"tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player],
|
"tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player],
|
||||||
"rocket_recipe" : rocket_recipes[world.max_science_pack[player].value],
|
"rocket_recipe" : rocket_recipes[world.max_science_pack[player].value],
|
||||||
"slot_name": world.player_names[player][0]}
|
"slot_name": world.player_names[player][0],
|
||||||
|
"starting_items": world.starting_items[player]}
|
||||||
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
|
||||||
control_code = control_template.render(**template_data)
|
control_code = control_template.render(**template_data)
|
||||||
|
|
Loading…
Reference in New Issue