Factorio: implement random recipe times
This commit is contained in:
		
							parent
							
								
									7907838c24
								
							
						
					
					
						commit
						403ddd603f
					
				| 
						 | 
				
			
			@ -329,6 +329,11 @@ class Visibility(Choice):
 | 
			
		|||
    option_sending = 1
 | 
			
		||||
    default = 1
 | 
			
		||||
 | 
			
		||||
class RecipeTime(Choice):
 | 
			
		||||
    option_vanilla = 0
 | 
			
		||||
    option_fast = 1
 | 
			
		||||
    option_normal = 2
 | 
			
		||||
    option_slow = 4
 | 
			
		||||
 | 
			
		||||
class FactorioStartItems(OptionDict):
 | 
			
		||||
    default = {"burner-mining-drill": 19, "stone-furnace": 19}
 | 
			
		||||
| 
						 | 
				
			
			@ -340,7 +345,8 @@ factorio_options: typing.Dict[str, type(Option)] = {"max_science_pack": MaxScien
 | 
			
		|||
                                                    "free_samples": FreeSamples,
 | 
			
		||||
                                                    "visibility": Visibility,
 | 
			
		||||
                                                    "random_tech_ingredients": Toggle,
 | 
			
		||||
                                                    "starting_items": FactorioStartItems}
 | 
			
		||||
                                                    "starting_items": FactorioStartItems,
 | 
			
		||||
                                                    "recipe_time": RecipeTime}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AdvancementGoal(Choice):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,6 +49,14 @@ function copy_factorio_icon(tech, tech_source)
 | 
			
		|||
    tech.icon_size = table.deepcopy(technologies[tech_source].icon_size)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function adjust_energy(recipe_name, factor)
 | 
			
		||||
    local energy = data.raw.recipe[recipe_name].energy_required
 | 
			
		||||
    if (energy == nil) then
 | 
			
		||||
        energy = 1
 | 
			
		||||
    end
 | 
			
		||||
    data.raw.recipe[recipe_name].energy_required = energy * factor
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
table.insert(data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories, "crafting-with-fluid")
 | 
			
		||||
 | 
			
		||||
{# each randomized tech gets set to be invisible, with new nodes added that trigger those #}
 | 
			
		||||
| 
						 | 
				
			
			@ -76,5 +84,9 @@ table.insert(new_tree_copy.prerequisites, "ap-{{ tech_table[prerequesite] }}-")
 | 
			
		|||
{% endif -%}
 | 
			
		||||
{#- add new Technology to game #}
 | 
			
		||||
data:extend{new_tree_copy}
 | 
			
		||||
 | 
			
		||||
{% endfor %}
 | 
			
		||||
{% if recipe_time %}
 | 
			
		||||
{%- for recipe in recipes %}
 | 
			
		||||
adjust_energy("{{ recipe }}", {{ 0.01 * random.randint(recipe_time*25, recipe_time*100) }})
 | 
			
		||||
{%- endfor -%}
 | 
			
		||||
{% endif %}
 | 
			
		||||
| 
						 | 
				
			
			@ -55,6 +55,11 @@ tech_tree_layout:
 | 
			
		|||
  small_funnels: 1
 | 
			
		||||
  medium_funnels: 1
 | 
			
		||||
  large_funnels: 1
 | 
			
		||||
recipe_time:
 | 
			
		||||
  vanilla: 1
 | 
			
		||||
  fast: 0 # 25% to 100% of original time
 | 
			
		||||
  normal: 0 # 50 % to 200% of original time
 | 
			
		||||
  slow: 0 # 100% to 400% of original time
 | 
			
		||||
max_science_pack:
 | 
			
		||||
  automation_science_pack: 0
 | 
			
		||||
  logistic_science_pack: 0
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ import Utils
 | 
			
		|||
import shutil
 | 
			
		||||
import Options
 | 
			
		||||
from BaseClasses import MultiWorld
 | 
			
		||||
from .Technologies import tech_table, rocket_recipes
 | 
			
		||||
from .Technologies import tech_table, rocket_recipes, recipes
 | 
			
		||||
 | 
			
		||||
template_env: Optional[jinja2.Environment] = None
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -62,7 +62,8 @@ def generate_mod(world: MultiWorld, player: int):
 | 
			
		|||
                     "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], "seed_name": world.seed_name,
 | 
			
		||||
                     "starting_items": world.starting_items[player]}
 | 
			
		||||
                     "starting_items": world.starting_items[player], "recipes": recipes,
 | 
			
		||||
                     "recipe_time": world.recipe_time[player], "random": world.random}
 | 
			
		||||
 | 
			
		||||
    for factorio_option in Options.factorio_options:
 | 
			
		||||
        template_data[factorio_option] = getattr(world, factorio_option)[player].value
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -117,13 +117,14 @@ for technology, data in raw.items():
 | 
			
		|||
 | 
			
		||||
del (raw)
 | 
			
		||||
lookup_id_to_name: Dict[int, str] = {item_id: item_name for item_name, item_id in tech_table.items()}
 | 
			
		||||
 | 
			
		||||
recipes = {}
 | 
			
		||||
all_product_sources: Dict[str, Set[Recipe]] = {"character": set()}
 | 
			
		||||
for recipe_name, recipe_data in raw_recipes.items():
 | 
			
		||||
    # example:
 | 
			
		||||
    # "accumulator":{"ingredients":["iron-plate","battery"],"products":["accumulator"],"category":"crafting"}
 | 
			
		||||
 | 
			
		||||
    recipe = Recipe(recipe_name, recipe_data["category"], set(recipe_data["ingredients"]), set(recipe_data["products"]))
 | 
			
		||||
    recipes[recipe_name] = Recipe
 | 
			
		||||
    if recipe.products.isdisjoint(recipe.ingredients) and "empty-barrel" not in recipe.products:  # prevents loop recipes like uranium centrifuging
 | 
			
		||||
        for product_name in recipe.products:
 | 
			
		||||
            all_product_sources.setdefault(product_name, set()).add(recipe)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue