require("factsheet")

replace_recipe_io(
	data.raw.recipe["textplate-small-uranium"],
	"uranium-238",
	"adamo-nuclear-DU-oxide"
)

replace_recipe_io(
	data.raw.recipe["textplate-large-uranium"],
	"uranium-238",
	"adamo-nuclear-DU-oxide"
)

if appmod and type(appmod) == "table" then
	appmod.blacklist["centrifuge"] = true
end

if appmod and type(appmod) == "table" then
	appmod.blacklist["adamo-nuclear-production-reactor"] = true
end

data.raw.item["centrifuge"].subgroup = "adamo-nuclear-production-machine"
data.raw.item["centrifuge"].order = "n[centrifuge]"
data.raw["assembling-machine"]
.centrifuge.fluid_boxes = centrifuge_fluid_boxes()

local reactor_coolant_color = {r = 1,g = 0.9,b = 0.8,a = 1}

-- Hide vanilla items.
data.raw.item["uranium-235"].hidden = true
data.raw.item["uranium-238"].hidden = true
if not data.raw.item["uranium-235"].flags then
	data.raw.item["uranium-235"].flags = {}
end
if not data.raw.item["uranium-238"].flags then
	data.raw.item["uranium-238"].flags = {}
end
table.insert(data.raw.item["uranium-235"].flags,"hidden")
table.insert(data.raw.item["uranium-238"].flags,"hidden")
data.raw.recipe["kovarex-enrichment-process"].hidden = true
data.raw.recipe["nuclear-fuel-reprocessing"].hidden = true
data.raw.recipe["uranium-processing"].hidden = true

-- Hide some mod recipes
if data.raw.recipe["MOX-fuel"] then
	data.raw.recipe["MOX-fuel"].hidden = true
end
if data.raw.recipe["MOX-fuel-reprocessing"] then
	data.raw.recipe["MOX-fuel-reprocessing"].hidden = true
end
if data.raw.recipe["advanced-nuclear-fuel-reprocessing"] then
	data.raw.recipe["advanced-nuclear-fuel-reprocessing"].hidden = true
end
if data.raw.recipe["plutonium-238-nuclesynthesis"] then
	data.raw.recipe["plutonium-238-nuclesynthesis"].hidden = true
end
if data.raw.recipe["uranium-238-excess-neutron-capture"] then
	data.raw.recipe["uranium-238-excess-neutron-capture"].hidden = true
end
if data.raw.recipe["plutonium-239-alpha-decay"] then
	data.raw.recipe["plutonium-239-alpha-decay"].hidden = true
end

local ore = data.raw.item["uranium-ore"]
local heu_fuel_recipe = data.raw.recipe["uranium-fuel-cell"]
local heu_fuel_item = data.raw.item["uranium-fuel-cell"]
local heu_used_fuel_item = data.raw.item["used-up-uranium-fuel-cell"]
local nuclear_fuel_recipe = data.raw.recipe["nuclear-fuel"]
local nuclear_fuel_item = data.raw.item["nuclear-fuel"]
local ammo = data.raw.recipe["uranium-rounds-magazine"]
local shell = data.raw.recipe["uranium-cannon-shell"]
local explosive_shell = data.raw.recipe["explosive-uranium-cannon-shell"]
local atomic_bomb = data.raw.recipe["atomic-bomb"]
local reactor_item = data.raw.item["nuclear-reactor"]
local reactor = data.raw.reactor["nuclear-reactor"]

ore.icon = "__adamo-nuclear__/graphics/icons/yellowcake.png"
ore.icon_size = 32
ore.icon_mipmaps = nil
ore.pictures = nil
ore.group = "adamo-nuclear-group"
ore.subgroup = "adamo-nuclear-processing-group"
ore.order = "m"


heu_fuel_recipe.ingredients = {
	{"adamo-nuclear-HEU-oxide",1},
	{"iron-plate",1}
}
heu_fuel_recipe.category = "advanced-crafting"
heu_fuel_recipe.result = "uranium-fuel-cell"
heu_fuel_recipe.result_count = nil
heu_fuel_recipe.results = nil
heu_fuel_recipe.group = nil
heu_fuel_recipe.subgroup = nil
heu_fuel_recipe.order = nil

table.insert(
	data.raw.technology["nuclear-power"].effects,
	{
		type = "unlock-recipe",
		recipe = "uranium-fuel-cell"
	}
)

for _,effect in pairs(
	data.raw.technology["uranium-processing"].effects
) do
	if effect.recipe:match "uranium-fuel-cell" then
		data.raw.technology["uranium-processing"].effects[_] = nil
	end
end

heu_fuel_item.fuel_value = "164GJ"
heu_fuel_item.icon_size = 32
heu_fuel_item.icon = 
	"__adamo-nuclear__/graphics/icons/HEU-fuel-cell.png"
heu_fuel_item.group = "nuclear-group"
heu_fuel_item.subgroup = "adamo-nuclear-products-group"
heu_fuel_item.order = "n"
heu_fuel_item.fuel_glow_color = reactor_coolant_color

heu_used_fuel_item.icon_size = 32
heu_used_fuel_item.icon = 
	"__adamo-nuclear__/graphics/icons/used-up-HEU-fuel-cell.png"
heu_used_fuel_item.group = "nuclear-group"
heu_used_fuel_item.subgroup = 
	"adamo-nuclear-spent-fuel-group"
heu_used_fuel_item.order = "m2"

nuclear_fuel_recipe.ingredients = {
	{type = "item",name = "adamo-nuclear-HEU-oxide",amount = 1},
	{type = "item",name = "rocket-fuel",amount = 1}
}
nuclear_fuel_recipe.category = "advanced-crafting"
nuclear_fuel_recipe.subgroup = "adamo-nuclear-products-group"
nuclear_fuel_recipe.order = "q"
--nuclear_fuel_item.subgroup = "adamo-nuclear-products-group"
--nuclear_fuel_item.order = "q"

ammo.ingredients = {
	{"piercing-rounds-magazine", 1},
	{"adamo-nuclear-DU-oxide",1}
}
ammo.result_count = 1

shell.ingredients = {
	{"cannon-shell", 1},
	{"adamo-nuclear-DU-oxide",1}
}
shell.result_count = 1

explosive_shell.ingredients = {
	{"explosive-cannon-shell", 1},
	{"adamo-nuclear-DU-oxide",1}
}
explosive_shell.result_count = 1

atomic_bomb.ingredients = {
	{"rocket",1},
	{"explosives",1},
	{"rocket-control-unit",1},
	{"adamo-nuclear-DU-oxide",1},
	{"adamo-nuclear-WGU-oxide",1}
}
atomic_bomb.icon = 
	"__adamo-nuclear__/graphics/icons/fission-rocket.png"
atomic_bomb.icon_size = 32


if settings.startup["adamo-nuclear-uranium-belt-recipe-override"].value then
	if data.raw.recipe["uranium-transport-belt"] then
		data.raw.recipe["uranium-transport-belt"].normal.energy_required = 50
		data.raw.recipe["uranium-transport-belt"].normal.ingredients =
			{
			  {"iron-gear-wheel", 500},
			  {"express-transport-belt", 100},
			  {"adamo-nuclear-Pu238-oxide",1},
			  {type="fluid", name="lubricant", amount=1000},
			  {type="item", name="electric-engine-unit", amount=100}
			}
		data.raw.recipe["uranium-transport-belt"].expensive.energy_required = 50
		data.raw.recipe["uranium-transport-belt"].expensive.ingredients =
			{
			  {"iron-gear-wheel", 1000},
			  {"express-transport-belt", 100},
			  {"adamo-nuclear-Pu238-oxide",1},
			  {type="fluid", name="lubricant", amount=2000},
			  {type="item", name="electric-engine-unit", amount=100}
			}
		data.raw.recipe["uranium-transport-belt"].normal.result_count = 100
		data.raw.recipe["uranium-transport-belt"].expensive.result_count = 100
	end
	if data.raw.recipe["uranium-underground-belt"] then
		data.raw.recipe["uranium-underground-belt"].energy_required = 100
		data.raw.recipe["uranium-underground-belt"].ingredients =
			{
				{"iron-gear-wheel", 2000},
				{"express-underground-belt",100},
				{"adamo-nuclear-Pu238-oxide",1},
				{type="fluid", name="lubricant", amount=1000},
				{type="item", name="electric-engine-unit", amount=100}
			}
		data.raw.recipe["uranium-underground-belt"].result_count = 100
	end
	if data.raw.recipe["uranium-splitter"] then
		data.raw.recipe["uranium-splitter"].energy_required = 200
		data.raw.recipe["uranium-splitter"].ingredients =
			{
				{"express-splitter", 100},
				{"iron-gear-wheel", 1000},
				{"processing-unit", 100},
				{"adamo-nuclear-Pu238-oxide",1},
				{type="fluid", name="lubricant", amount=1000},
				{type="item", name="electric-engine-unit", amount=100}
			}
		data.raw.recipe["uranium-splitter"].result_count = 100
	end
end

reactor_item.icon = 
	"__adamo-nuclear__/graphics/icons/nuclear-reactor.png"
reactor_item.icon_size = 32

table.insert(data.raw.recipe["nuclear-reactor"].ingredients,
	{type = "item",name="adamo-nuclear-DU-oxide",amount=150})




reactor.default_fuel_glow_color = reactor_coolant_color
reactor.use_fuel_glow_color = true
reactor.light.intensity = 0
reactor.energy_source.light_flicker = {}
reactor.energy_source.light_flicker.minimum_intensity = 0.5
reactor.energy_source.light_flicker.maximum_intensity = 0.5
reactor.energy_source.light_flicker.minimum_light_size = 0
reactor.energy_source.light_flicker.light_intensity_to_size_coefficient = 0
reactor.working_light_picture = emptysprite()
local heat_picture_layer = reactor.heat_buffer.heat_picture
reactor.heat_buffer.heat_picture = {
	layers = {
		heat_picture_layer,
		{
			filename =
				"__adamo-nuclear__/graphics/entity/"
				.."reactor-lights-color.png",
			width = 160,
			height = 160,
			shift = { -0.03125, -0.1875 },
			blend_mode = "additive",
			hr_version =
			{
				filename =
				"__adamo-nuclear__/graphics/entity/"
				.."hr-reactor-lights-color.png",
				width = 320,
				height = 320,
				scale = 0.5,
				shift = { -0.03125, -0.1875 },
				blend_mode = "additive"
			}
		}
	}
}
local heat_glow_layer = reactor.heat_buffer.heat_glow
reactor.heat_buffer.heat_glow = {
	layers = {
		heat_glow_layer,
		{
			filename =
				"__adamo-nuclear__/graphics/entity/"
				.."reactor-lights-glow.png",
			flags = {"light"},
			width = 160,
			height = 160,
			blend_mode = "additive",
			tint = heat_glow_tint,
			shift = { -0.03125, -0.1875 }
		}
	}
}
if not data.raw.fluid["adamo-chemical-hydrofluoric-acid"] then
	local hydrofluoric_acid_fluid = {
		type = "fluid",
		name = "adamo-chemical-hydrofluoric-acid",
		order = "a[fluid]-g[adamo-chemical-hydrofluoric-acid]",
		icon = "__adamo-nuclear__/graphics/icons/hydrofluoride.png",
		icon_size = 32,
		base_color = colors.hf_base,
		flow_color = colors.hf_flow,
		default_temperature = 25,
		max_temperature = 100,
		heat_capacity = "0.1KJ",
	}
	local hydrofluoric_acid_recipe = {
		type = "recipe",
		name = "adamo-chemical-hydrofluoric-acid",
		category = "chemistry",
		subgroup = "fluid-recipes",
		enabled = false,
		energy_required = 1, -- same as sulfuric-acid
		ingredients = {{
				type = "item",
				name = "stone",
				amount = 50
			},{
				type = "fluid",
				name = "sulfuric-acid",
				amount = 50
			},{
				type = "fluid",
				name = "water",
				amount = 50
		}},
		results = {{
				type='fluid',
				name = "adamo-chemical-hydrofluoric-acid",
				amount = 50
		}},
		main_product = "adamo-chemical-hydrofluoric-acid",
		requester_paste_multiplier = 4,
		crafting_machine_tint = {
			primary = data.raw.fluid["sulfuric-acid"].flow_color,
			secondary = colors.hf_base,
			tertiary = data.raw.fluid["sulfuric-acid"].base_color,
		},
	}
	data:extend({
		hydrofluoric_acid_fluid,
		hydrofluoric_acid_recipe
	})
	table.insert(
		data.raw.technology["uranium-processing"].effects,
		{
			type = "unlock-recipe",
			recipe = "adamo-chemical-hydrofluoric-acid"
		}
	)
end


adamomods.logging=true

if settings.startup["adamo-nuclear-recipe-trolling"].value then
	for _,recipe in pairs(data.raw.recipe) do
		if recipe_uses(recipe,"uranium-238") then
			replace_recipe_io(
				recipe,
				"uranium-238",
				"adamo-nuclear-DU-oxide"
			)
		end
		if recipe_uses(recipe,"uranium-235") then
			replace_recipe_io(
				recipe,
				"uranium-235",
				"adamo-nuclear-HEU-oxide"
			)
		end
	end
end

local FeU_recipe = table.deepcopy(data.raw.recipe["steel-plate"])
FeU_recipe.name = "adamo-nuclear-steel-plate"
local fe_name,fe_count = get_ingredient(FeU_recipe,'iron-plate')
add_ingredient(FeU_recipe,'adamo-nuclear-DU-oxide',fe_count)
replace_recipe_io(FeU_recipe,'iron-plate','iron-ore')
mult_recipe_io(FeU_recipe,2,'steel-plate')
data:extend({FeU_recipe})
add_recipe_to_tech("uranium-processing","adamo-nuclear-steel-plate")

adamomods.logging=false