-- View scripts 
-- Copyright (C) 2004, Eagle Dynamics.

-- Don't change existing values, they are requested from Ñ++!
-- Use these indices in Snap and CockpitLocalPoint tables.
dofile("Scripts/Database/wsTypes.lua")
PlaneIndex = {
iSu_27 = 1,
iSu_33 = 2,
iSu_25 = 3,
iSu_39 = 4,		-- Su-39 or Su-25T
iMiG_29 = 5,
iMiG_29K = 6,
iA_10 = 7,
iF_15 = 8,
iKA_50 = 9,
iMI_24W = 10,
iKA_52 = 11,
iMI_28N = 12,
iAH_64A = 13,
iAH_64D = 14,
iAH_1W = 15,
iOH_58D = 16,
iSea_Lynx = 17,
iMI_8MT = 18,
iMI_26 = 20,
iKA_27 = 21,
iCH_47D = 22,
iCH_53E = 23,
iSH_60B = 24,
iUH_60A = 25,
iSH_3H = 26,
iAB_212 = 27,
}

PlaneIndexByType =
{
	[MiG_29]  = PlaneIndex.iMiG_29,
	[Su_27]   = PlaneIndex.iSu_27,
	[Su_33]   = PlaneIndex.iSu_33,
	[F_15]    = PlaneIndex.iF_15,
	[Su_25]   = PlaneIndex.iSu_25,
	[A_10]    = PlaneIndex.iA_10,
	[MIG_29K] = PlaneIndex.iMiG_29K,
	[Su_39]   = PlaneIndex.iSu_39,
	[MiG_29G] = PlaneIndex.iMiG_29,
	[MiG_29C] = PlaneIndex.iMiG_29,
	[Su_25T]  = PlaneIndex.iSu_39,
	[KA_50]   = PlaneIndex.iKA_50,
	[MI_24W]   = PlaneIndex.iMI_24W,
	[KA_52]   = PlaneIndex.iKA_52,
	[MI_28N]   = PlaneIndex.iMI_28N,
	[AH_64A]   = PlaneIndex.iAH_64A,
	[AH_64D]   = PlaneIndex.iAH_64D,
	[AH_1W]   = PlaneIndex.iAH_1W,
	[OH_58D]   = PlaneIndex.iOH_58D,
	[Sea_Lynx]   = PlaneIndex.iSea_Lynx,
	[MI_8MT]   = PlaneIndex.iMI_8MT,
	[MI_26]   = PlaneIndex.iMI_26,
	[KA_27]   = PlaneIndex.iKA_27,
	[CH_47D]   = PlaneIndex.iCH_47D,
	[CH_53E]   = PlaneIndex.iCH_53E,
	[SH_60B]   = PlaneIndex.iSH_60B,
	[UH_60A]   = PlaneIndex.iUH_60A,
	[SH_3H]   = PlaneIndex.iSH_3H,
	[AB_212]   = PlaneIndex.iAB_212,	
}

function validate(tbl,itype)
	return tbl[itype] or tbl[Su_27]
end

DisableCombatViews = false -- F5 & Ctrl-F5
ExternalObjectsLockDistance = 10000.0
ShowTargetInfo = false
CameraTerrainRestriction = true
					--   p1 , p2 ,p3
CockpitLocalPoint = {}
CockpitLocalPoint[PlaneIndex.iSu_27] = {8.15, 1.38, 0.0}
CockpitLocalPoint[PlaneIndex.iSu_33] = {8.35, 1.35, 0.0}
CockpitLocalPoint[PlaneIndex.iSu_25] = {3.5 , 0.4 , 0.0}
CockpitLocalPoint[PlaneIndex.iSu_39] = {3.406, 0.466, 0.0}
CockpitLocalPoint[PlaneIndex.iMiG_29] = {4.92, 1.35, 0.0}
CockpitLocalPoint[PlaneIndex.iMiG_29K] = {4.9, 1.254, 0.0}
CockpitLocalPoint[PlaneIndex.iA_10] = {3.991, 1.55, 0.0}
CockpitLocalPoint[PlaneIndex.iF_15] = {6.5, 1.238, 0.0}
CockpitLocalPoint[PlaneIndex.iKA_50] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iMI_24W] = {5.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iKA_52] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iMI_28N] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iAH_64A] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iAH_64D] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iAH_1W] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iOH_58D] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iSea_Lynx] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iMI_8MT] = {7.5, 0.2, 0.0}
CockpitLocalPoint[PlaneIndex.iMI_26] = {6.0, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iKA_27] = {4.5, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iCH_47D] = {6.5, 0.10, 0.0}
CockpitLocalPoint[PlaneIndex.iCH_53E] = {5.4, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iSH_60B] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iUH_60A] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iSH_3H] = {3.188, 0.39, 0.0}
CockpitLocalPoint[PlaneIndex.iAB_212] = {3.188, 0.39, 0.0}

EyePoint = {}
EyePoint[PlaneIndex.iSu_27] = {0,0,0}
EyePoint[PlaneIndex.iSu_33] = {0,0,0}
EyePoint[PlaneIndex.iSu_25] = {0,0,0}
EyePoint[PlaneIndex.iSu_39] = {0,0,0}
EyePoint[PlaneIndex.iMiG_29] = {0,0,0}
EyePoint[PlaneIndex.iMiG_29K] = {0,0,0}
EyePoint[PlaneIndex.iA_10] = {0,0,0}
EyePoint[PlaneIndex.iF_15] = {0,0,0}
EyePoint[PlaneIndex.iKA_50] = {0.09, 0, 0}
EyePoint[PlaneIndex.iMI_24W] = {0.09, 0, 0}
EyePoint[PlaneIndex.iKA_52] = {0.09, 0, 0}
EyePoint[PlaneIndex.iMI_28N] = {0.09, 0, 0}
EyePoint[PlaneIndex.iAH_64A] = {0.09, 0, 0}
EyePoint[PlaneIndex.iAH_64D] = {0.09, 0, 0}
EyePoint[PlaneIndex.iAH_1W] = {0.09, 0, 0}
EyePoint[PlaneIndex.iOH_58D] = {0.09, 0, 0}
EyePoint[PlaneIndex.iSea_Lynx] = {0.09, 0, 0}
EyePoint[PlaneIndex.iMI_8MT] = {0.09, 0, 0}
EyePoint[PlaneIndex.iMI_26] = {0.09, 0, 0}
EyePoint[PlaneIndex.iKA_27] = {0.09, 0, 0}
EyePoint[PlaneIndex.iCH_47D] = {0.09, 0, 0}
EyePoint[PlaneIndex.iCH_53E] = {0.09, 0, 0}
EyePoint[PlaneIndex.iSH_60B] = {0.09, 0, 0}
EyePoint[PlaneIndex.iUH_60A] = {0.09, 0, 0}
EyePoint[PlaneIndex.iSH_3H] = {0.09, 0, 0}
EyePoint[PlaneIndex.iAB_212] = {0.09, 0, 0}

--local old_aircrafts_6DOF  = {x = {-2,2},y = {-2,2},z = {-2,2},roll = 90.0} -- {x = {0,0},y = {0,0},z = {0,0},roll = 0}
local old_aircrafts_6DOF  = {x = {-0.02,0.05},y = {-0.03,0.03},z = {-0.03,0.03},roll = 90.0}

limits_6DOF = {}
limits_6DOF[PlaneIndex.iSu_27]   = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iSu_33]   = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iSu_25]   = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iSu_39]   = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iMiG_29]  = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iMiG_29K] = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iA_10]    = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iF_15]    = old_aircrafts_6DOF
limits_6DOF[PlaneIndex.iKA_50]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iMI_24W]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iKA_52]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iMI_28N]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iAH_64A]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iAH_64D]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iAH_1W]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iOH_58D]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iSea_Lynx]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iMI_8MT]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iMI_26]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iKA_27]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iCH_47D]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iCH_53E]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iSH_60B]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iUH_60A]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iSH_3H]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}
limits_6DOF[PlaneIndex.iAB_212]   = {x = {-0.02,0.35},y = {-0.15,0.21},z = {-0.26,0.26},roll = 90.0}


function GetCockpitLocalPoint(iType)
	local p = CockpitLocalPoint[iType]
	return p[1], p[2], p[3]
end

function GetEyePoint(iType)
	local p = EyePoint[iType]
	return p[1], p[2], p[3]
end

function Get_6DOF_limits(iType)
	local p = limits_6DOF[iType]
	return p.x[1],
		   p.x[2],
		   p.y[1],
		   p.y[2],
		   p.z[1],
		   p.z[2],
		   p.roll
end

function SetCockpitLocalPoint(iType, x, y, z)
	local p = CockpitLocalPoint[iType]
	p[1] = x
	p[2] = y
	p[3] = z
end

-- Camera angle limits {horizontal angle max, vertical angle min, vertical angle max}
CameraAngleLimits = {}
CameraAngleLimits[PlaneIndex.iSu_27] = {140.0, -75.0, 90.0}
CameraAngleLimits[PlaneIndex.iSu_33] = {140.0, -75.0, 90.0}
CameraAngleLimits[PlaneIndex.iSu_25] = {95.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iSu_39] = {110.0, -80.0, 90.0}
CameraAngleLimits[PlaneIndex.iMiG_29] = {140.0, -75.0, 90.0}
CameraAngleLimits[PlaneIndex.iMiG_29K] = {140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iA_10] = {140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iF_15] = {140.0, -80.0, 90.0}
CameraAngleLimits[PlaneIndex.iKA_50] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iMI_24W] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iKA_52] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iMI_28N] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iAH_64A] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iAH_64D] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iAH_1W] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iOH_58D] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iSea_Lynx] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iMI_8MT] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iMI_26] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iKA_27] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iCH_47D] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iCH_53E] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iSH_60B] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iUH_60A] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iSH_3H] ={140.0, -65.0, 90.0}
CameraAngleLimits[PlaneIndex.iAB_212] ={140.0, -65.0, 90.0}


CameraAngleRestriction = {}
CameraAngleRestriction[PlaneIndex.iSu_27] =  {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iSu_33] =  {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iSu_25] =  {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iSu_39] =  {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iMiG_29] = {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iMiG_29K] ={1,60,0.4}
CameraAngleRestriction[PlaneIndex.iA_10]  =  {1,90,0.5}
CameraAngleRestriction[PlaneIndex.iF_15]  =  {1,60,0.4}
CameraAngleRestriction[PlaneIndex.iKA_50] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iMI_24W] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iKA_52] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iMI_28N] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iAH_64A] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iAH_64D] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iAH_1W] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iOH_58D] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iSea_Lynx] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iMI_8MT] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iMI_26] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iKA_27] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iCH_47D] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iCH_53E] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iSH_60B] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iUH_60A] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iSH_3H] =  {0,60,0.4}
CameraAngleRestriction[PlaneIndex.iAB_212] =  {0,60,0.4}


function GetCameraAngleLimits(iType)
	local p = CameraAngleLimits[iType]
	return p[1], p[2], p[3]
end




function GetCameraAngleRestriction(iType)
	local p = CameraAngleRestriction[iType]
	return  p[1], p[2], p[3]
end 



function SetCameraAngleLimits(iType, hAngMax, vAngMin, vAngMax)
	local p = CameraAngleLimits[iType]
	p[1] = hAngMax
	p[2] = vAngMin
	p[3] = vAngMax
end

-- Following values will not be saved in tracks in the current version!
hAngleRearDefault =  180
vAngleRearDefault = -8.0
vAngleRearMin     = -90 -- -8.0
vAngleRearMax     = 90.0



RearCameraPos = {}
RearCameraAnglesDefault = {}

for i = PlaneIndex.iSu_27,PlaneIndex.iKA_50 do
    local cockpit_point = CockpitLocalPoint[i]
    RearCameraAnglesDefault[i] =  {180,-8.0} 
    RearCameraPos[i]           =  {cockpit_point[1] - 3.7 ,cockpit_point[2] + 2.4, cockpit_point[3]}
end

ArcadeCameraPos = {}
ArcadeCameraAnglesDefault = {}

for i = PlaneIndex.iSu_27,PlaneIndex.iKA_50 do  
    local cockpit_point = CockpitLocalPoint[i]
    ArcadeCameraAnglesDefault[i] =  {0  ,-8.0}
    ArcadeCameraPos[i]           =  {cockpit_point[1] - 20  ,cockpit_point[2] + 5  , cockpit_point[3] + 0}  
end


function GetRearCameraPosition(iType)
	local  p = RearCameraPos[iType]
	return p[1], p[2], p[3]
end

function GetRearCameraAnglesDefault(iType)
    local p = RearCameraAnglesDefault[iType]
    if p == nil then    return hAngleRearDefault , vAngleRearDefault
    else                return p[1], p[2]    end
end


function GetArcadeCameraPosition(iType)
	local  p = ArcadeCameraPos[iType]
	return p[1], p[2], p[3]
end

function GetArcadeCameraAnglesDefault(iType)
    local p = ArcadeCameraAnglesDefault[iType]
    if p == nil then    return hAngleRearDefault , vAngleRearDefault
    else                return p[1], p[2]    end
end

-- LSO local position on the carrier: {x, y, z, rot_Y, rot_Z)
-- Note: tracks can't save modified LSO local positions in the current version!
LSOPosition = {}
LSOPosition["Vinson"] = {88.0, 28.0, 31.0, 0.0, 0.0} 
LSOPosition["Kouznetsov"] = {81.236, 24.0, 28.497, 10.0, 0.0} 

function GetLSOPosition(iType)
	local p = LSOPosition[iType]
	return p[1], p[2], p[3], p[4], p[5]
end




dbg_shell    = "weapons.shells.GSH23_23"
dbg_shell_v0 = -1
