require("factsheet")

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

adamo.recipe.replace.resource(
	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

-- 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 vanilla_uranium_235   = data.raw.item["uranium-235"]
local vanilla_uranium_238   = data.raw.item["uranium-238"]
local kovarex_recipe        = data.raw.recipe["kovarex-enrichment-process"]
local kovarex_tech          = data.raw.technology["kovarex-enrichment-process"]
local reprocessing_recipe   = data.raw.recipe["nuclear-fuel-reprocessing"]
local reprocessing_tech     = data.raw.technology["nuclear-fuel-reprocessing"]
local vanilla_processing    = data.raw.recipe["uranium-processing"]
local centrifuge_item       = data.raw.item["centrifuge"]
local centrifuge_entity     = data.raw["assembling-machine"].centrifuge
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.ammo["atomic-bomb"]
local atomic_bomb_recipe    = data.raw.recipe["atomic-bomb"]
local nuclear_power_tech    = data.raw.technology["nuclear-power"]
local uranium_tech          = data.raw.technology["uranium-processing"]
local reactor_item          = data.raw.item["nuclear-reactor"]
local reactor_recipe        = data.raw.recipe["nuclear-reactor"]
local reactor               = data.raw.reactor["nuclear-reactor"]
local hf_fluid              = data.raw.fluid["adamo-chemical-hydrofluoric-acid"]
local FeU_recipe            = table.deepcopy(data.raw.recipe["steel-plate"])
local fe_name,fe_count      = adamo.recipe.get.ingredient(FeU_recipe,'iron-plate')
local reactor_heat_layer    = reactor.heat_buffer.heat_picture
local reactor_glow_layer    = reactor.heat_buffer.heat_glow
local reactor_coolant_color = {r = 1,g = 0.9,b = 0.8,a = 1}

adamo.recipe.set.tech(nuclear_power_tech.name,heu_fuel_recipe.name)

if not hf_fluid then adamo.apply.hf_from_stone("adamo-nuclear",uranium_tech.name) end

FeU_recipe.name = "adamo-nuclear-steel-plate"
FeU_recipe.subgroup = products_group.name
adamo.recipe.add.ingredient(FeU_recipe,'adamo-nuclear-DU-oxide',fe_count)
adamo.recipe.replace.resource(FeU_recipe,'iron-plate','iron-ore')
adamo.recipe.scale.resources(FeU_recipe,2,'steel-plate')
adamo.recipe.set.productivity(FeU_recipe)
data:extend({FeU_recipe})

adamo.tech.add.recipe("uranium-processing","adamo-nuclear-steel-plate")
adamo.tech.add.prereq(kovarex_tech.name,reprocessing_tech.name)

kovarex_recipe.hidden = true
reprocessing_recipe.hidden = true
vanilla_processing.hidden = true
vanilla_uranium_235.hidden = true
vanilla_uranium_238.hidden = true

if not vanilla_uranium_235.flags then vanilla_uranium_235.flags = {} end
if not vanilla_uranium_238.flags then vanilla_uranium_238.flags = {} end
table.insert(vanilla_uranium_235.flags,"hidden")
table.insert(vanilla_uranium_238.flags,"hidden")

centrifuge_item.subgroup = machine_group.name
centrifuge_item.order = "n[centrifuge]"
centrifuge_entity.fluid_boxes = adamo.centrifuge.fluid_boxes()

ore.icon = "__adamo-nuclear__/graphics/icons/yellowcake.png"
ore.icon_size = 32
ore.icon_mipmaps = nil
ore.pictures = nil
ore.group = nuclear_group.name
ore.subgroup = processing_group.name
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       = heu_fuel_item.name
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

heu_fuel_item.fuel_value = "122GJ"
heu_fuel_item.icon_size = 32
heu_fuel_item.icon = "__adamo-nuclear__/graphics/icons/yellow-fuel-cell.png"
heu_fuel_item.group = nuclear_group.name
heu_fuel_item.subgroup = fuel_group.name
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/red-fuel-cell.png"
heu_used_fuel_item.group = nuclear_group.name
heu_used_fuel_item.subgroup = spent_fuel_group.name
heu_used_fuel_item.order = "m2"

nuclear_fuel_recipe.ingredients = {
	{type = "item",name = "adamo-nuclear-DU-oxide",amount = 1},
	{type = "item",name = "rocket-fuel",amount = 1},
	{type = "fluid",name = "water",amount = 1000}
}
nuclear_fuel_recipe.category="neutron-bombardment"
nuclear_fuel_recipe.energy_required=60
nuclear_fuel_item.subgroup = products_group.name
nuclear_fuel_item.order = "n"

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_recipe.ingredients = {
	{"rocket",1},
	{"explosives",2},
	{"rocket-control-unit",1},
	{"adamo-nuclear-DU-oxide",2},
	{"adamo-nuclear-WGU-oxide",2}
}
-- atomic_bomb_recipe.icon = "__adamo-nuclear__/graphics/icons/fission-rocket.png"
-- atomic_bomb_recipe.icon_size = 32
-- atomic_bomb.icon = "__adamo-nuclear__/graphics/icons/fission-rocket.png"
-- atomic_bomb.icon_size = 32

reactor_item.icon = "__adamo-nuclear__/graphics/icons/nuclear-reactor.png"
reactor_item.icon_size = 32
adamo.recipe.add.ingredient(reactor_recipe,"adamo-nuclear-DU-oxide",200)
reactor.default_fuel_glow_color = reactor_coolant_color
reactor.use_fuel_glow_color = true
-- Not necessary as long as Factorio base data
-- includes no light on nuclear-reactor.
-- 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 = adamo.sprite.empty()
reactor.heat_buffer.heat_picture = {
	layers = {
		reactor_heat_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"
			}
		}
	}
}
reactor.heat_buffer.heat_glow = {
	layers = {
		reactor_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 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

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


