db.Units.Planes = {};

db.Units.Planes.DefaultCategories = 
{
	{
        CLSID = "{C168A850-3C0B-436a-95B5-C4A015552560}",
        Name = "Plane",
	}
}

----------------------------------------------------------------------
-- TASKS
-- OldID is here for backward compatibility with old brain-damaged code
-- TODO: remove oldId completely!
----------------------------------------------------------------------
local function task(name, id, oldId)
    local res = { WorldID = id, Name = name }
    if oldId then
        res.OldID = oldId
    end
    return res
end

-- tasks mapped by task ID
local taskById = { }

local function add_task(name, id, oldId)
    local task = task(name, id, oldId)
    taskById[id] = task
    table.insert(db.Units.Planes.Tasks, task);
end

db.Units.Planes.Tasks = {};
add_task(_("Nothing"), Nothing, "Nothing");
add_task(_("SEAD"), SEAD, "SEAD");
add_task(_("Antiship Strike"), AntishipStrike, "Antiship Strike");
add_task(_("AWACS"), AWACS, "AWACS");
add_task(_("CAS"), CAS, "CAS");
add_task(_("CAP"), CAP, "CAP");
add_task(_("Escort"), Escort, "Escort");
add_task(_("Fighter Sweep"), FighterSweep, "Fighter Sweep");
add_task(_("GAI"), GAI, "GAI");
add_task(_("Ground Attack"), GroundAttack, "Ground Attack");
add_task(_("Intercept"), Intercept, "Intercept");
add_task(_("Observation"), Observation, "Observation");
add_task(_("AFAC"), AFAC, "AFAC");
add_task(_("Pinpoint Strike"), PinpointStrike, "Pinpoint Strike");
add_task(_("Reconnaissance"), Reconnaissance, "Reconnaissance");
add_task(_("Refueling"), Refueling, "Refueling");
add_task(_("Runway Attack"), RunwayAttack, "Runway Attack");
add_task(_("Transport"), Transport, "Transport");

db.Units.Planes.DefaultTask = { WorldID = Nothing };

----------------------------------------------------------------------
-- Route task categories
----------------------------------------------------------------------
local function route_task_cat(clsid, name, id, tasks)
	local res = {};
	
	res.CLSID = clsid;
	res.Name = name;
	res.ID = id;
	res.Tasks = tasks;
	
	table.insert(db.Units.Planes.RouteTaskCategories, res);
	
	return res;
end
db.Units.Planes.RouteTaskCategories = {};
               
route_task_cat("{8297D481-DF12-4adc-94EE-C4E1B94EE777}", _("TakeOff"), 1, {
	task(_("From Runway"), 13),
	task(_("From Parking Area"), 50),
});

route_task_cat("{1FA1B84A-3AD3-4353-8E0F-E9BB48251997}", _("Land"), 2, {
	task(_("Landing"), 14),
});

route_task_cat("{C039E533-6F90-43a1-A23E-0436D6D532F5}", _("Attack"), 3, {
	task(_("Attack Target"), 2),
});

route_task_cat("{6156D907-5E76-438d-8B73-64337E63703E}", _("Refueling"), 4, {
	task(_("Refueling"), 8),
});

route_task_cat("{2D0C3C57-2AB3-48ee-A1C2-BE75934F76F6}", _("Turning Point"), 5, {
	task(_("TurningPoint"), 0),
	task(_("FlyOverPoint"), 1),
	task(_("LockAltitude"), 9),
	task(_("UnlockAltitude"), 10),
	task(_("BeginLoop"), 11),
	task(_("EndLoop"), 12),
});


-------------------------------------------------------------------------
-- Planes
-------------------------------------------------------------------------
function plane(clsid, name, displayName, params, pylons, --[[payloads,]] tasks, default_task)
	local res = params;
	res.CLSID = clsid;
	res.Name = name;
	res.DisplayName = displayName;
	res.Pylons = pylons;
	res.Tasks = tasks;
	res.DefaultTask = default_task;
    
    res.AmmoWeight = get_aircraft_ammo_mass_by_wstype(res.WorldID);
	
	if (res.Picture == nil) then
		res.Picture = res.Name .. ".dds";
	end
	
	table.insert(db.Units.Planes.Plane, res);
	return res;
end

function pylon(number, tp, x, y, z, params, wcs)
	local res = params;
	
	res.Number = number;
	res.Type = tp;
	res.X = x;
	res.Y = y;
	res.Z = z;
	res.Launchers = wcs;
	
	return res;
end

function pylon_launcher(clsid)
	local res = {};
	
	res.CLSID = clsid;
	res.Name = get_weapon_name_by_clsid(clsid);
	
	return res;
end

function aircraft_task(id)
    local task = taskById[id]
    if not task then
        print('WARNING: task ' .. id .. ' is missing')
    end
    return task
end

function payload_pylon(id, clsid)
	local res = {};
	
	res.Num = id;
	res.LauncherCLSID = clsid;
	res.LauncherName = get_weapon_name_by_clsid(clsid);
	
	return res;
end

function color_scheme(clsid, name, id)
	local res = {};
	
	res.ID = id;
	res.CLSID = clsid;
	res.Name = name;
	
	return res;
end

function pl_cat(clsid, name)
	local res = {};
	
	res.CLSID = clsid;
	res.Name = name;
	
	return res;
end

db.Units.Planes.Plane = {}

function plane_file(f)
	dofile(db_path..f)._file = db_path..f;
end

plane_file("planes\\Tornado_GR3.lua");
plane_file("planes\\Tornado_IDS.lua");
plane_file("planes\\FA-18A.lua");
plane_file("planes\\FA-18C.lua");
plane_file("planes\\MiG-29S.lua");
plane_file("planes\\MiG-29A.lua");
plane_file("planes\\F-14A.lua");
plane_file("planes\\Tu-22M3.lua");
plane_file("planes\\F-4E.lua");
plane_file("planes\\B-52H.lua");
plane_file("planes\\MiG-27K.lua");
plane_file("planes\\F-111F.lua");
plane_file("planes\\A-10A.lua");
plane_file("planes\\Su-27.lua");
plane_file("planes\\MiG-29G.lua");
plane_file("planes\\MiG-23MLD.lua");
plane_file("planes\\Su-25.lua");
plane_file("planes\\Su-25TM.lua");
plane_file("planes\\Su-25T.lua");
plane_file("planes\\Su-33.lua");
plane_file("planes\\MiG-25PD.lua");
plane_file("planes\\MiG-25RBT.lua");
plane_file("planes\\Su-30.lua");
plane_file("planes\\Su-34.lua");
plane_file("planes\\Su-17M4.lua");
plane_file("planes\\MiG-31.lua");
plane_file("planes\\Tu-95MS.lua");
plane_file("planes\\Su-24M.lua");
plane_file("planes\\Tu-160.lua");
plane_file("planes\\F-117A.lua");
plane_file("planes\\B-1B.lua");
plane_file("planes\\S-3B.lua");
plane_file("planes\\S-3B-2.lua");
plane_file("planes\\Mirage_2000-5.lua");
plane_file("planes\\F-15C.lua");
plane_file("planes\\F-5E.lua");
plane_file("planes\\MiG-29K.lua");
plane_file("planes\\Tu-142.lua");
plane_file("planes\\C-130.lua");
plane_file("planes\\An-26B.lua");
plane_file("planes\\An-30M.lua");
plane_file("planes\\C-17A.lua");
plane_file("planes\\A-50.lua");
plane_file("planes\\E-3A.lua");
plane_file("planes\\IL-78M.lua");
plane_file("planes\\KC-10A.lua");
plane_file("planes\\E-2C.lua");
plane_file("planes\\IL-76MD.lua");
plane_file("planes\\F-16C.lua");
plane_file("planes\\F-16C-2.lua");
plane_file("planes\\Su-24MR.lua");
plane_file("planes\\F-16A.lua");
plane_file("planes\\F-16A-2.lua");
plane_file("planes\\BAE_Harrier.lua");
plane_file("planes\\RQ-1A_Predator.lua");
plane_file("planes\\yak-40.lua");

