Factorio: add starting_items
This commit is contained in:
		
							parent
							
								
									9c3d12dc55
								
							
						
					
					
						commit
						c55983af5f
					
				|  | @ -536,6 +536,9 @@ def roll_settings(weights: dict, plando_options: typing.Set[str] = frozenset(("b | |||
|     elif ret.game == "Factorio": | ||||
|         for option_name, option in Options.factorio_options.items(): | ||||
|             if option_name in 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: | ||||
|                 setattr(ret, option_name, option(option.default)) | ||||
|  |  | |||
							
								
								
									
										43
									
								
								Options.py
								
								
								
								
							
							
						
						
									
										43
									
								
								Options.py
								
								
								
								
							|  | @ -103,12 +103,43 @@ class Choice(Option): | |||
|             f'known options are {", ".join(f"{option}" for option in cls.name_lookup.values())}') | ||||
| 
 | ||||
|     @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(): | ||||
|             return cls(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): | ||||
|     option_no_glitches = 0 | ||||
|     option_minor_glitches = 1 | ||||
|  | @ -289,12 +320,18 @@ class Visibility(Choice): | |||
|     default = 1 | ||||
| 
 | ||||
| 
 | ||||
| class FactorioStartItems(OptionDict): | ||||
|     default = {"burner-mining-drill": 19, "stone-furnace": 19} | ||||
| 
 | ||||
| 
 | ||||
| factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxSciencePack, | ||||
|                                                     "tech_tree_layout": TechTreeLayout, | ||||
|                                                     "tech_cost": TechCost, | ||||
|                                                     "free_samples": FreeSamples, | ||||
|                                                     "visibility": Visibility, | ||||
|                                                     "random_tech_ingredients": Toggle} | ||||
|                                                     "random_tech_ingredients": Toggle, | ||||
|                                                     "starting_items": FactorioStartItems} | ||||
| 
 | ||||
| 
 | ||||
| class AdvancementGoal(Choice): | ||||
|     option_few = 0 | ||||
|  | @ -302,12 +339,14 @@ class AdvancementGoal(Choice): | |||
|     option_many = 2 | ||||
|     default = 1 | ||||
| 
 | ||||
| 
 | ||||
| class CombatDifficulty(Choice): | ||||
|     option_easy = 0 | ||||
|     option_normal = 1 | ||||
|     option_hard = 2 | ||||
|     default = 1 | ||||
| 
 | ||||
| 
 | ||||
| minecraft_options: typing.Dict[str, type(Option)] = { | ||||
|     "advancement_goal": AdvancementGoal, | ||||
|     "combat_difficulty": CombatDifficulty, | ||||
|  |  | |||
|  | @ -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 "util" | ||||
| 
 | ||||
|  | @ -11,10 +18,7 @@ function on_force_created(event) | |||
|     game.forces[event.force].research_queue_enabled = true | ||||
|     local data = {} | ||||
|     if FREE_SAMPLES ~= 0 then | ||||
|         data['earned_samples'] = { | ||||
|             ["burner-mining-drill"] = 19, | ||||
|             ["stone-furnace"] = 19 | ||||
|         } | ||||
|         data['earned_samples'] = {{ dict_to_lua(starting_items) }} | ||||
|     end | ||||
|     data["victory"] = 0 | ||||
|     global.forcedata[event.force] = data | ||||
|  |  | |||
|  | @ -70,6 +70,9 @@ visibility: | |||
| random_tech_ingredients: | ||||
|   on: 1 | ||||
|   off: 0 | ||||
| starting_items: | ||||
|   burner-mining-drill: 19 | ||||
|   stone-furnace: 19 | ||||
| # Minecraft options:  | ||||
| advancement_goal: # Number of advancements required (out of 92 total) to spawn the Ender Dragon and complete the game.  | ||||
|   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_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player], | ||||
|                      "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: | ||||
|         template_data[factorio_option] = getattr(world, factorio_option)[player].value | ||||
|     control_code = control_template.render(**template_data) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue