require("util")

--========================
-- Locals and Functions
--========================
-- I grabbed these local function routines from Gleba Reborn, so credit to them for the routines
local function replace_ingredient(ingredients, old_ingredient, new_ingredient, new_amount)
	for i,ingredient in pairs(ingredients) do
		if ingredient.name then
			if ingredient.name == old_ingredient then
				ingredient.name = new_ingredient
				ingredient.amount = new_amount
			end
		elseif ingredient[1] == old_ingredient then
			ingredient[1] = new_ingredient
		end
	end
end

local function update_recipe(recipe, old_ingredient, new_ingredient, new_amount)
	if data.raw.recipe[recipe].ingredients then
		replace_ingredient(data.raw.recipe[recipe].ingredients, old_ingredient, new_ingredient, new_amount)
	end
	if data.raw.recipe[recipe].normal then
		replace_ingredient(data.raw.recipe[recipe].normal.ingredients, old_ingredient, new_ingredient, new_amount)
	end
	if data.raw.recipe[recipe].expensive then
		replace_ingredient(data.raw.recipe[recipe].expensive.ingredients, old_ingredient, new_ingredient, new_amount)
	end
end

local function update_recipe_compatable(old_recipe, old_ingredient, new_ingredient, new_amount)
	local new_recipe = util.table.deepcopy(data.raw.recipe[old_recipe])
	local new_name = compatable_name(new_recipe.name)
	new_recipe.name = new_name
	data.raw.recipe[new_name] = new_recipe
	update_recipe(new_name, old_ingredient, new_ingredient, new_amount)
	if data.raw.technology[old_recipe] then
		table.insert(data.raw.technology[old_recipe].effects, { type = "unlock-recipe", recipe = new_name })
	end
end

local function set_recipe_category(recipe, new_category)
	if data.raw.recipe[recipe] then
		data.raw.recipe[recipe].category = new_category
	end
end

data.raw["fluid"]["fusion-plasma"].base_color = { 0.3, 0.0, 0.0 }
data.raw["fluid"]["fusion-plasma"].flow_color = { 1, 1, 1 }
data.raw["fluid"]["fusion-plasma"].gas_temperature = 1000000
--data.raw["fluid"]["fusion-plasma"].fuel_value = "75000kJ"
--data.raw["fluid"]["fluoroketone-cold"].fuel_value = "75000kJ"
data.raw["technology"]["fusion-construction-robots"] = nil
data.raw["technology"]["fusion-logistic-robots"] = nil
--data.raw["recipe"]["fusion-construction-robot"] = nil
--data.raw["recipe"]["fusion-logistic-robot"] = nil

if mods["metal-and-stars"] then
	if settings.startup["ske_disable_metal_and_stars_bots"].value then
		data.raw["technology"]["antimatter-robots"] = nil
		data.raw["construction-robot"]["antimatter-construction-robot"] = nil
		data.raw["logistic-robot"]["antimatter-logistic-robot"] = nil
		data.raw["item"]["antimatter-construction-robot"] = nil
		data.raw["item"]["antimatter-logistic-robot"] = nil
		data.raw["recipe"]["antimatter-construction-robot"] = nil
		data.raw["recipe"]["antimatter-logistic-robot"] = nil
		data.raw["recipe"]["antimatter-construction-robot-recycling"] = nil
		data.raw["recipe"]["antimatter-logistic-robot-recycling"] = nil
	else end
else end

if mods["metal-and-stars"] and mods["Krastorio2-spaced-out"] then
	if settings.startup["ske_disable_metal_and_stars_bots"].value then
		data.raw["recipe"]["kr-crush-antimatter-construction-robot"] = nil
		data.raw["recipe"]["kr-crush-antimatter-logistic-robot"] = nil
	else end
else end

--if mods["fusion-thruster"] then
--	if settings.startup["ske_fusion_thruster"].value then
--		data.raw["technology"]["fusion-thruster"] = nil
--		data.raw["recipe"]["thruster-fusion-plasma"] = nil
--		data.raw["recipe"]["fusion-thruster"] = nil
--	else end
--else end

--if mods["Krastorio2-spaced-out"] then
--data.raw["recipe"]["ske_stone_to_sand_craft"] = nil
--else
--end
--========================
-- Laboratory handling stuff
--========================
local all_lab_types = data.raw['lab']
local handle_science_populate = true

if(handle_science_populate == true) then
  for k,v in pairs(all_lab_types) do
		table.insert(v.inputs,"gas-manipulation-science-pack") --add my science pack to all labs
  end
end