--Various debug file exports
--Initiated by MAIN_NextMission.lua (unless disabled there)
-------------------------------------------------------------------------------------------------------
-- last modification: adjustment_c
if not versionDCE then versionDCE = {} end
versionDCE["UTIL_Debug.lua"] = "1.2.4"
------------------------------------------------------------------------------------------------------- 

-- adjustment_c						(ac affiche le nombre d element dans la mission)
------------------------------------------------------------------------------------------------------- 


if Debug.debug then
	--local sorties_str = "draft_sorties = " .. TableSerialization(draft_sorties, 0)		--this can take up to 30 seconds for parge missions, only activate if really needed
	--local sortiesFile = io.open("Debug/ATO_draft_sorties.lua", "w")
	--sortiesFile:write(sorties_str)
	--sortiesFile:close()

	local ato_str = "ATO = " .. TableSerialization(ATO, 0)
	local atoFile = io.open("Debug/ATO.lua", "w")
	atoFile:write(ato_str)
	atoFile:close()


	local ground_str = "groundthreats = " .. TableSerialization(groundthreats, 0)
	local air_str = "fighterthreats = " .. TableSerialization(fighterthreats, 0)
	local ewr_str = "ewr = " .. TableSerialization(ewr, 0)
	local threatFile = io.open("Debug/threat.lua", "w")
	threatFile:write(ground_str .. "\n\n" .. air_str .. "\n\n" .. ewr_str)
	threatFile:close()
	
	
	local available_str = "aircraft_availability = " .. TableSerialization(aircraft_availability, 0)
	local availableFile = io.open("Debug/AircraftAvailability.lua", "w")
	availableFile:write(available_str)
	availableFile:close()

end

--compte le nombre d'élément dans la mission.
local NbGrPlane, NbGrHelico, NbGrShip, NbGrvehicle, NbGrStatic = 0, 0, 0, 0, 0 
local NbPlane, NbHelico, NbShip, Nbvehicle, NbStatic = 0, 0, 0, 0, 0

for _side,side in pairs(mission.coalition) do	
	for _country, country in pairs(side.country) do
		if country.plane  then
			NbGrPlane = NbGrPlane + #country.plane.group
			for Ngroup, group in ipairs(country.plane.group) do
				NbPlane = NbPlane + #group.units
			end
		end
		if country.helicopter  then
			NbGrHelico = NbGrHelico + #country.helicopter.group
			for Ngroup, group in ipairs(country.helicopter.group) do
				NbHelico = NbHelico + #group.units
			end
		end
		if country.ship  then
			NbGrShip = NbGrShip + #country.ship.group
			for Ngroup, group in ipairs(country.ship.group) do
				NbShip = NbShip + #group.units
			end
		end
		if country.vehicle  then
			NbGrvehicle = NbGrvehicle + #country.vehicle.group
			for Ngroup, group in ipairs(country.vehicle.group) do
				Nbvehicle = Nbvehicle + #group.units
			end
		end
		if country.static  then
			NbGrStatic = NbGrStatic + #country.static.group
			for Ngroup, group in ipairs(country.static.group) do
				NbStatic = NbStatic + #group.units
			end
		end
	end
end

print()
print("Number of aircraft groups: "..tostring(NbGrPlane).." |Number of planes: "..tostring(NbPlane))
print("Number of helicopter groups: "..tostring(NbGrHelico).." |Number of helicopters: "..tostring(NbHelico))
print("Number of ship groups: "..tostring(NbGrShip).." |Number of ships: "..tostring(NbShip))
print("Number of vehicle groups: "..tostring(NbGrvehicle).." |Number of vehicules: "..tostring(Nbvehicle))
print("Number of static groups: "..tostring(NbGrStatic).." |Number of statics: "..tostring(NbStatic))
print()
