| 
									
										
										
										
											2021-05-22 10:06:21 +02:00
										 |  |  | {% from "macros.lua" import dict_to_recipe %} | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | -- this file gets written automatically by the Archipelago Randomizer and is in its raw form a Jinja2 Template | 
					
						
							| 
									
										
										
										
											2021-04-07 01:55:53 +02:00
										 |  |  | require('lib') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  | {%- for recipe_name, recipe in custom_recipes.items() %} | 
					
						
							| 
									
										
										
										
											2021-11-25 09:44:01 -08:00
										 |  |  | data.raw["recipe"]["{{recipe_name}}"].category = "{{recipe.category}}" | 
					
						
							|  |  |  | data.raw["recipe"]["{{recipe_name}}"].ingredients = {{ dict_to_recipe(recipe.ingredients, liquids) }} | 
					
						
							| 
									
										
										
										
											2021-07-07 10:14:58 +02:00
										 |  |  | {%- endfor %} | 
					
						
							| 
									
										
										
										
											2021-05-07 21:58:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | local technologies = data.raw["technology"] | 
					
						
							|  |  |  | local original_tech | 
					
						
							|  |  |  | local new_tree_copy | 
					
						
							| 
									
										
										
										
											2021-04-03 14:47:49 +02:00
										 |  |  | allowed_ingredients = {} | 
					
						
							| 
									
										
										
										
											2021-06-11 18:02:48 +02:00
										 |  |  | {%- for tech_name, technology in custom_technologies.items() %} | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  | allowed_ingredients["{{ tech_name }}"] = { | 
					
						
							|  |  |  | {%- for ingredient in technology.ingredients %} | 
					
						
							|  |  |  | ["{{ingredient}}"] = 1, | 
					
						
							|  |  |  | {%- endfor %} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-04-03 14:47:49 +02:00
										 |  |  | {% endfor %} | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | local template_tech = table.deepcopy(technologies["automation"]) | 
					
						
							|  |  |  | {#-  ensure the copy unlocks nothing #} | 
					
						
							|  |  |  | template_tech.unlocks = {} | 
					
						
							|  |  |  | template_tech.upgrade = false | 
					
						
							|  |  |  | template_tech.effects = {} | 
					
						
							| 
									
										
										
										
											2021-04-03 14:47:49 +02:00
										 |  |  | template_tech.prerequisites = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-30 23:18:17 -08:00
										 |  |  | {%- if max_science_pack < 6 %} | 
					
						
							|  |  |  |     technologies["space-science-pack"].effects = {} | 
					
						
							|  |  |  |     {%- if max_science_pack == 0 %} | 
					
						
							|  |  |  |         table.insert (technologies["automation"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {%- elif max_science_pack == 1 %} | 
					
						
							|  |  |  |         table.insert (technologies["logistic-science-pack"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {%- elif max_science_pack == 2 %} | 
					
						
							|  |  |  |         table.insert (technologies["military-science-pack"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {%- elif max_science_pack == 3 %} | 
					
						
							|  |  |  |         table.insert (technologies["chemical-science-pack"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {%- elif max_science_pack == 4 %} | 
					
						
							|  |  |  |         table.insert (technologies["production-science-pack"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {%- elif max_science_pack == 5 %} | 
					
						
							|  |  |  |         table.insert (technologies["utility-science-pack"].effects, {type = "unlock-recipe", recipe = "satellite"}) | 
					
						
							|  |  |  |     {% endif %} | 
					
						
							|  |  |  | {% endif %} | 
					
						
							|  |  |  | {%- if silo == 2 %} | 
					
						
							|  |  |  |     data.raw["recipe"]["rocket-silo"].enabled = true | 
					
						
							|  |  |  | {% endif %} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-06 02:20:13 +02:00
										 |  |  | function prep_copy(new_copy, old_tech) | 
					
						
							| 
									
										
										
										
											2021-06-21 22:25:49 +02:00
										 |  |  |     old_tech.hidden = true | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  |     local ingredient_filter = allowed_ingredients[old_tech.name] | 
					
						
							|  |  |  |     if ingredient_filter ~= nil then | 
					
						
							| 
									
										
										
										
											2021-11-08 10:00:00 -08:00
										 |  |  | 	    if mods["science-not-invited"] then | 
					
						
							|  |  |  | 			local weights = { | 
					
						
							|  |  |  | 				["automation-science-pack"] =   0, -- Red science | 
					
						
							|  |  |  | 				["logistic-science-pack"]   =   0, -- Green science | 
					
						
							|  |  |  | 				["military-science-pack"]   =   0, -- Black science | 
					
						
							|  |  |  | 				["chemical-science-pack"]   =   0, -- Blue science | 
					
						
							|  |  |  | 				["production-science-pack"] =   0, -- Purple science | 
					
						
							|  |  |  | 				["utility-science-pack"]    =   0, -- Yellow science | 
					
						
							|  |  |  | 				["space-science-pack"]      =   0  -- Space science | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for key, value in pairs(ingredient_filter) do | 
					
						
							|  |  |  | 				weights[key] = value | 
					
						
							|  |  |  | 			end | 
					
						
							|  |  |  | 			SNI.setWeights(weights) | 
					
						
							| 
									
										
										
										
											2021-11-26 09:16:42 -08:00
										 |  |  |             -- Just in case an ingredient is being added to an existing tech. Found the root cause of the 9.223e+18 problem. | 
					
						
							|  |  |  |             -- Turns out science-not-invited was ultimately dividing by zero, due to it being unaware of there being added ingredients. | 
					
						
							|  |  |  |             old_tech.unit.ingredients = add_ingredients(old_tech.unit.ingredients, ingredient_filter) | 
					
						
							| 
									
										
										
										
											2021-11-08 10:00:00 -08:00
										 |  |  | 			SNI.sendInvite(old_tech) | 
					
						
							|  |  |  | 			-- SCIENCE-not-invited could potentially make tech cost 9.223e+18. | 
					
						
							| 
									
										
										
										
											2021-11-26 09:16:42 -08:00
										 |  |  | 			old_tech.unit.count = math.min(100000, old_tech.unit.count) | 
					
						
							| 
									
										
										
										
											2021-11-08 10:00:00 -08:00
										 |  |  | 		end | 
					
						
							|  |  |  | 		new_copy.unit = table.deepcopy(old_tech.unit) | 
					
						
							|  |  |  | 		new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients, ingredient_filter) | 
					
						
							|  |  |  | 		new_copy.unit.ingredients = add_ingredients(new_copy.unit.ingredients, ingredient_filter) | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         new_copy.unit = table.deepcopy(old_tech.unit) | 
					
						
							| 
									
										
										
										
											2021-04-24 01:16:49 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-04-06 02:20:13 +02:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | function set_ap_icon(tech) | 
					
						
							|  |  |  |     tech.icon = "__{{ mod_name }}__/graphics/icons/ap.png" | 
					
						
							|  |  |  |     tech.icons = nil | 
					
						
							|  |  |  |     tech.icon_size = 128 | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 10:46:27 +02:00
										 |  |  | function set_ap_unimportant_icon(tech) | 
					
						
							|  |  |  |     tech.icon = "__{{ mod_name }}__/graphics/icons/ap_unimportant.png" | 
					
						
							|  |  |  |     tech.icons = nil | 
					
						
							|  |  |  |     tech.icon_size = 128 | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | function copy_factorio_icon(tech, tech_source) | 
					
						
							|  |  |  |     tech.icon = table.deepcopy(technologies[tech_source].icon) | 
					
						
							|  |  |  |     tech.icons = table.deepcopy(technologies[tech_source].icons) | 
					
						
							|  |  |  |     tech.icon_size = table.deepcopy(technologies[tech_source].icon_size) | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-31 20:19:05 +02:00
										 |  |  | {# This got complex, but seems to be required to hit all corner cases #} | 
					
						
							| 
									
										
										
										
											2021-06-06 21:11:58 +02:00
										 |  |  | function adjust_energy(recipe_name, factor) | 
					
						
							| 
									
										
										
										
											2021-07-10 08:01:39 +02:00
										 |  |  |     local recipe = data.raw.recipe[recipe_name] | 
					
						
							|  |  |  |     local energy = recipe.energy_required | 
					
						
							| 
									
										
										
										
											2021-07-31 20:19:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (recipe.normal ~= nil) then | 
					
						
							|  |  |  |         if (recipe.normal.energy_required == nil) then | 
					
						
							|  |  |  |             energy = 0.5 | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             energy = recipe.normal.energy_required | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-07-10 08:01:39 +02:00
										 |  |  |         recipe.normal.energy_required = energy * factor | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-07-31 20:19:05 +02:00
										 |  |  |     if (recipe.expensive ~= nil) then | 
					
						
							|  |  |  |         if (recipe.expensive.energy_required == nil) then | 
					
						
							|  |  |  |             energy = 0.5 | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             energy = recipe.expensive.energy_required | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-07-10 08:01:39 +02:00
										 |  |  |         recipe.expensive.energy_required = energy * factor | 
					
						
							| 
									
										
										
										
											2021-06-06 21:11:58 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-07-31 20:19:05 +02:00
										 |  |  |     if (energy ~= nil) then | 
					
						
							|  |  |  |         data.raw.recipe[recipe_name].energy_required = energy * factor | 
					
						
							|  |  |  |     elseif (recipe.expensive == nil and recipe.normal == nil) then | 
					
						
							|  |  |  |         data.raw.recipe[recipe_name].energy_required = 0.5 * factor | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2021-06-06 21:11:58 +02:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 19:10:26 +01:00
										 |  |  | function set_energy(recipe_name, energy) | 
					
						
							|  |  |  |     local recipe = data.raw.recipe[recipe_name] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (recipe.normal ~= nil) then | 
					
						
							|  |  |  |         recipe.normal.energy_required = energy | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     if (recipe.expensive ~= nil) then | 
					
						
							|  |  |  |         recipe.expensive.energy_required = energy | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     if (recipe.expensive == nil and recipe.normal == nil) then | 
					
						
							|  |  |  |         recipe.energy_required = energy | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 22:09:09 +02:00
										 |  |  | data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"].crafting_categories) | 
					
						
							|  |  |  | data.raw["assembling-machine"]["assembling-machine-2"].crafting_categories = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"].crafting_categories) | 
					
						
							|  |  |  | data.raw["assembling-machine"]["assembling-machine-1"].fluid_boxes = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-2"].fluid_boxes) | 
					
						
							| 
									
										
										
										
											2021-07-13 05:13:38 +02:00
										 |  |  | data.raw["ammo"]["artillery-shell"].stack_size = 10 | 
					
						
							| 
									
										
										
										
											2021-04-06 02:20:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | {# each randomized tech gets set to be invisible, with new nodes added that trigger those #} | 
					
						
							| 
									
										
										
										
											2021-05-22 10:46:27 +02:00
										 |  |  | {%- for original_tech_name, item_name, receiving_player, advancement in locations %} | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 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 #} | 
					
						
							| 
									
										
										
										
											2021-04-06 02:20:13 +02:00
										 |  |  | prep_copy(new_tree_copy, original_tech) | 
					
						
							| 
									
										
										
										
											2021-06-15 15:32:40 +02:00
										 |  |  | {% if tech_cost_scale != 1 %} | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | new_tree_copy.unit.count = math.max(1, math.floor(new_tree_copy.unit.count * {{ tech_cost_scale }})) | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | {% endif %} | 
					
						
							| 
									
										
										
										
											2021-07-04 22:21:53 +02:00
										 |  |  | {%- if (tech_tree_information == 2 or original_tech_name in static_nodes) and item_name in base_tech_table -%} | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | {#- copy Factorio Technology Icon -#} | 
					
						
							|  |  |  | copy_factorio_icon(new_tree_copy, "{{ item_name }}") | 
					
						
							| 
									
										
										
										
											2021-07-31 19:45:17 +02:00
										 |  |  | {%- if original_tech_name == "rocket-silo" and original_tech_name in static_nodes %} | 
					
						
							|  |  |  | {%- for ingredient in custom_recipes["rocket-part"].ingredients %} | 
					
						
							|  |  |  | table.insert(new_tree_copy.effects, {type = "nothing", effect_description = "Ingredient {{ loop.index }}: {{ ingredient }}"}) | 
					
						
							|  |  |  | {% endfor -%} | 
					
						
							|  |  |  | {% endif -%} | 
					
						
							| 
									
										
										
										
											2021-07-04 22:21:53 +02:00
										 |  |  | {%- elif (tech_tree_information == 2 or original_tech_name in static_nodes) and item_name in progressive_technology_table -%} | 
					
						
							|  |  |  | copy_factorio_icon(new_tree_copy, "{{ progressive_technology_table[item_name][0] }}") | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | {%- else -%} | 
					
						
							|  |  |  | {#- use default AP icon if no Factorio graphics exist -#} | 
					
						
							| 
									
										
										
										
											2021-06-21 22:25:49 +02:00
										 |  |  | {% if advancement or not tech_tree_information %}set_ap_icon(new_tree_copy){% else %}set_ap_unimportant_icon(new_tree_copy){% endif %} | 
					
						
							| 
									
										
										
										
											2021-05-22 08:08:37 +02:00
										 |  |  | {%- endif -%} | 
					
						
							| 
									
										
										
										
											2021-04-10 03:03:46 +02:00
										 |  |  | {#- connect Technology  #} | 
					
						
							|  |  |  | {%- if original_tech_name in tech_tree_layout_prerequisites %} | 
					
						
							|  |  |  | {%- for prerequesite in tech_tree_layout_prerequisites[original_tech_name] %} | 
					
						
							|  |  |  | table.insert(new_tree_copy.prerequisites, "ap-{{ tech_table[prerequesite] }}-") | 
					
						
							|  |  |  | {% endfor %} | 
					
						
							|  |  |  | {% endif -%} | 
					
						
							|  |  |  | {#- add new Technology to game #} | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | data:extend{new_tree_copy} | 
					
						
							| 
									
										
										
										
											2021-06-06 21:11:58 +02:00
										 |  |  | {% endfor %} | 
					
						
							| 
									
										
										
										
											2021-06-06 21:38:53 +02:00
										 |  |  | {% if recipe_time_scale %} | 
					
						
							| 
									
										
										
										
											2021-07-06 23:55:30 +02:00
										 |  |  | {%- for recipe_name, recipe in recipes.items() %} | 
					
						
							|  |  |  | {%- if recipe.category != "mining" %} | 
					
						
							| 
									
										
										
										
											2021-07-31 20:20:59 +02:00
										 |  |  | adjust_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_scale) }}) | 
					
						
							| 
									
										
										
										
											2021-07-06 23:55:30 +02:00
										 |  |  | {%- endif %} | 
					
						
							| 
									
										
										
										
											2021-06-06 21:11:58 +02:00
										 |  |  | {%- endfor -%} | 
					
						
							| 
									
										
										
										
											2021-11-23 19:10:26 +01:00
										 |  |  | {% elif recipe_time_range %} | 
					
						
							|  |  |  | {%- for recipe_name, recipe in recipes.items() %} | 
					
						
							|  |  |  | {%- if recipe.category != "mining" %} | 
					
						
							|  |  |  | set_energy("{{ recipe_name }}", {{ flop_random(*recipe_time_range) }}) | 
					
						
							|  |  |  | {%- endif %} | 
					
						
							|  |  |  | {%- endfor -%} | 
					
						
							| 
									
										
										
										
											2021-07-25 22:12:03 +02:00
										 |  |  | {% endif %} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | {%- if silo==2 %} | 
					
						
							|  |  |  | -- disable silo research for pre-placed silo | 
					
						
							| 
									
										
										
										
											2021-10-13 07:03:18 -07:00
										 |  |  | technologies["rocket-silo"].enabled = false | 
					
						
							|  |  |  | technologies["rocket-silo"].visible_when_disabled = false | 
					
						
							| 
									
										
										
										
											2021-07-25 22:12:03 +02:00
										 |  |  | {%- endif %} |