-- BELHARRA

-- AI Ship MOD for DCS WORLD

GT = {};
GT_t.ws = 0;

set_recursive_metatable(GT, GT_t.generic_ship)

GT.visual = {}
GT.visual.shape = "fdi_belharra"
GT.visual.shape_dstr = ""
GT.animation_arguments.alarm_state = -1;
GT.toggle_alarm_state_interval = 5.0;
GT.animation_arguments.radar1_rotation = 6;
GT.radar1_period = 2;
--GT.animation_arguments.luna_lights = -1;
--GT.animation_arguments.headlights = 1;
GT.animation_arguments.flag_animation = 11;
GT.animation_arguments.water_propeller = 30;
GT.propeller_omega_max = 300.0;
GT.snd.move = "Ships/ShipMove";
GT.snd.engine = "Ships/ShipEngine";
GT.life = 2200
GT.mass = 9.59e+006;
GT.max_velocity = 15.4333
GT.race_velocity = 15.4333
GT.economy_velocity = 10.2889
GT.economy_distance = 1.1112e+007
GT.race_distance = 2.778e+006
GT.shipLength = 122
GT.Width = 14.8
GT.Height = 37.2
GT.Length = 122.5
GT.DeckLevel = 8
GT.X_nose = 63.0

GT.X_tail = - 60 -- -55-- -70


GT.Tail_Width = 15
GT.Gamma_max = 0.35
GT.Om = 0.05
GT.speedup = 0.229734
GT.R_min = 345.6
GT.distFindObstacles = 568.4
GT.numParking = 1
GT.Plane_Num_ = 0
GT.Helicopter_Num_ = 1
GT.airWeaponDist = 100000
GT.airFindDist = 150000

GT.RCS = 72000  -- Radar Cross Section en  m2  valeur du Type26 -> susceptibilité d'être détecté par un radar. valeur 700000 pour un CNV

GT.exhaust = {
[1] = { size = 0.60 , pos = {-6.0, 18.0, 0 } },
[2] = { size = 0.60 , pos = {-8.0, 17.0, 0 } },
}

GT.Landing_Point = {-52.092, 6.507, 0.2}

GT.DM = {
	{ area_name = "HULL", 				area_arg = 82,	area_life = 500, area_fire = { pos = {9.152, 10.971, -0.0}, size = 0.4}},
	{ area_name = "BRIDGE",  			area_arg = 80,	area_life = 600},
	{ area_name = "BOW",  				area_arg = 83,	area_life = 500, area_fire = { pos = {51.969, 5.120, -0.0}, size = 0.4}},
	{ area_name = "FLIGHT_DECK",  		area_arg = 84,	area_life = 500, area_fire = { pos = {-35.508, 5.120, -0.0}, size = 0.4}},
	{ area_name = "OTO_TURRET", 		area_arg = 83,	area_life = 100},
	{ area_name = "UPPER", 				area_arg = 81,	area_life = 500},
	{ area_name = "SILOS_SAM", 			area_arg = 83,	area_life = 100},
	{ area_name = "SILOS_ASTER", 		area_arg = 83,	area_life = 100},
	{ area_name = "HARPOONS", 			area_arg = 77,	area_life = 100}, 
	{ area_name = "RAMTURRET", 			area_arg = 82,	area_life = 100},
	}	

-- weapon systems

GT.WS = {}
local ws;
GT.WS.maxTargetDetectionRange = 250000;
GT.WS.radar_type = 102
GT.WS.searchRadarMaxElevation = math.rad(80);
GT.WS.searchRadarFrequencies = {{50.0e6, 54.0e6}, {2.0e9, 2.2e9}}

-- Lionfish 20mm

def_mg_LN = {
    type = 9, --machinegun
    distanceMin = 0,
    reactionTime = 0.5,
    reflection_limit = 0.22,
    connectorFire = true,
    sensor = {},
    PL = {},
}
set_recursive_metatable(def_mg_LN.sensor, GT_t.WSN_t[1]);

GT_t.LN_t.automatic_gun_20mm = {name = "Lionfish_20", display_name = _("Lionfish 20")}
set_recursive_metatable(GT_t.LN_t.automatic_gun_20mm, def_mg_LN);
GT_t.LN_t.automatic_gun_20mm.type = 12;
GT_t.LN_t.automatic_gun_20mm.distanceMin = 10
GT_t.LN_t.automatic_gun_20mm.distanceMax = 2500
GT_t.LN_t.automatic_gun_20mm.max_trg_alt = 1200
GT_t.LN_t.automatic_gun_20mm.reactionTime = 1.8;
set_recursive_metatable(GT_t.LN_t.automatic_gun_20mm.sensor, GT_t.WSN_t[11])
GT_t.LN_t.automatic_gun_20mm.PL[1] = {}
GT_t.LN_t.automatic_gun_20mm.PL[1].switch_on_delay = 0;
GT_t.LN_t.automatic_gun_20mm.PL[1].shell_name = {"M242_25_HE_M792"};
GT_t.LN_t.automatic_gun_20mm.PL[1].ammo_capacity = 250;
GT_t.LN_t.automatic_gun_20mm.PL[1].portionAmmoCapacity = 250;
GT_t.LN_t.automatic_gun_20mm.PL[1].reload_time = 100;
GT_t.LN_t.automatic_gun_20mm.PL[1].shot_delay = 60/200;
GT_t.LN_t.automatic_gun_20mm.PL[2] = {};
set_recursive_metatable(GT_t.LN_t.automatic_gun_20mm.PL[2], GT_t.LN_t.automatic_gun_20mm.PL[1]);
GT_t.LN_t.automatic_gun_20mm.PL[2].ammo_capacity = 250;
GT_t.LN_t.automatic_gun_20mm.PL[2].portionAmmoCapacity = 250;
GT_t.LN_t.automatic_gun_20mm.PL[2].reload_time = 200;
GT_t.LN_t.automatic_gun_20mm.PL[2].shell_name = {"M242_25_AP_M791"};
GT_t.LN_t.automatic_gun_20mm.BR = { {pos = {2.7, 0, 0} } }



-- Lionfish Autogun
ws = GT_t.inc_ws();
GT.WS[ws] = {}
GT.WS[ws].center = 'LIONFISH_TURRETL'
GT.WS[ws].drawArgument1 = 21
GT.WS[ws].drawArgument2 = 22
GT.WS[ws].angles = {
                    {math.rad(170), math.rad(0), math.rad(-10), math.rad(45)},
                    };
--GT.WS[ws].reference_angle_Y = math.rad(90);
__LN = add_launcher(GT.WS[ws], GT_t.LN_t.automatic_gun_20mm);
__LN.BR[1].connector_name = 'LionfishL_point'

ws = GT_t.inc_ws();
GT.WS[ws] = {}
GT.WS[ws].center = 'LIONFISH_TURRETR'
GT.WS[ws].drawArgument1 = 42
GT.WS[ws].drawArgument2 = 43
GT.WS[ws].angles = {
                    {math.rad(0), math.rad(-170), math.rad(-10), math.rad(45)},
                    };
--GT.WS[ws].reference_angle_Y = math.rad(-90);
__LN = add_launcher(GT.WS[ws], GT_t.LN_t.automatic_gun_20mm);
__LN.BR[1].connector_name = 'LionfishR_point'

-- ================================= THALES SEAFIRE radar =========================================================================

ws = GT_t.inc_ws()
local first_SEAFIRE_tracker_id = ws
GT.WS[ws] = {
	center = 'CENTER_RADAR_01',
    omegaY = 2,
    omegaZ = 2,
    pidY = {p=100, i=0.05, d=12, inn = 50},
    pidZ = {p=100, i=0.05, d=12, inn = 50},
    angles = { {math.rad(180), math.rad(-180), math.rad(-90), math.rad(80)} },
    LN = {
        [1] = {
            type = 102,
            distanceMin = 4000,
            distanceMax = 400000,
            reactionTime = 2.0,
            reflection_limit = 0.03,
			frequencyRange = {0.5e9, 0.58e9},
            ECM_K = 0.5,
            min_trg_alt = 0,
            max_trg_alt = 30500,
            max_number_of_missiles_channels = 1,
            beamWidth = math.rad(90),
        }
    }
}

local SEAFIRE_tracker_ws = {{{'self', ws}}}

for i=2,32 do 
    ws = GT_t.inc_ws()
    GT.WS[ws] = {}
    set_recursive_metatable(GT.WS[ws], GT.WS[first_SEAFIRE_tracker_id])
    table.insert(SEAFIRE_tracker_ws, {{'self', ws}})
end	


---------------------------------------------------------------------------------------------------------------------------------------------------------

--VLS Launcher SAM

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_MK41_SM2 )
GT.WS[ws].area = 'SILOS_SAM' 
GT.WS[ws].center = 'CENTER_SILOS_SAM'
--GT.WS[ws].drawArgument1 = 48
--GT.animation_arguments.alarm_state = 48;
GT.WS[ws].LN[1].depends_on_unit = AIGES_TRACKERS
GT.WS[ws].LN[1].PL[1].ammo_capacity = 32;
GT.WS[ws].LN[1].show_external_missile = false
GT.WS[ws].LN[1].BR = {
						{connector_name = 'POINT_ROCKET_1_1', recoilArgument = 172, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_1_2', recoilArgument = 173, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},	
						{connector_name = 'POINT_ROCKET_1_3', recoilArgument = 176, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_1_4', recoilArgument = 177, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_2_1', recoilArgument = 171, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_2_2', recoilArgument = 174, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_2_3', recoilArgument = 175, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_2_4', recoilArgument = 178, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},	
					}
					
					
---------------------------------------------------------------------------------------------------------------------------------------------------------		
					
--VLS Launcher Aster 30

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.Aster30 )
GT.WS[ws].area = 'SILOS_ASTER' 
GT.WS[ws].center = 'CENTER_SILOS_ASTER'
--GT.WS[ws].drawArgument1 = 48
--GT.animation_arguments.alarm_state = 48;
GT.WS[ws].LN[1].depends_on_unit = SEAFIRE_tracker_ws
GT.WS[ws].LN[1].PL[1].ammo_capacity = 32;
GT.WS[ws].LN[1].BR = {
						{connector_name = 'POINT_ROCKET_3_1', recoilArgument = 186, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_3_2', recoilArgument = 184, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},	
						{connector_name = 'POINT_ROCKET_3_3', recoilArgument = 182, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_3_4', recoilArgument = 180, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_4_1', recoilArgument = 183, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_4_2', recoilArgument = 185, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},	
						{connector_name = 'POINT_ROCKET_4_3', recoilArgument = 181, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
						{connector_name = 'POINT_ROCKET_4_4', recoilArgument = 179, recoilT0 = -2, recoilT1 = -1, recoilT2 = 1.0, recoilTime = 2},
					}				
					
---------------------------------------------------------------------------------------------------------------------------------------------------------

-- Mark 32 Surface Vessel Torpedoes

ws = GT_t.inc_ws();
GT.WS[ws] = {};
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_Torpedo84 );
--set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_mk46 );
GT.WS[ws].center = 'CENTER_TOWER_MK_32_01';
--GT.WS[ws].drawArgument1 = 25;
GT.WS[ws].angles = {{math.rad (180), math.rad (180), math.rad(0), math.rad(0)},}
GT.WS[ws].reference_angle_Y = math.rad(0);
GT.WS[ws].LN[1].show_external_missile = false
GT.WS[ws].LN[1].BR = {
	{connector_name = 'POINT_MK_32_01', recoilArgument = 209, recoilT0 = -1, recoilT1 = -0.5, recoilT2 = 0.5, recoilTime = 1.0 },  
}
--GT.WS[ws].LN[1].customViewPoint = { "genericMissile", {-2.0, 0.75, 0.0}, }; 

---------------------------------------------------------------------------------------------------------------------------------------------------------

-- Mark 32 Surface Vessel Torpedoes

ws = GT_t.inc_ws();
GT.WS[ws] = {};
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_Torpedo84 );
--set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_mk46 );
GT.WS[ws].center = 'CENTER_TOWER_MK_32_02';
--GT.WS[ws].drawArgument1 = 28;
GT.WS[ws].angles = {{math.rad (-180), math.rad (-180), math.rad(0), math.rad(0)},}
GT.WS[ws].reference_angle_Y = math.rad(0);
GT.WS[ws].LN[1].show_external_missile = false
GT.WS[ws].LN[1].BR = {
	{connector_name = 'POINT_MK_32_02', recoilArgument = 210, recoilT0 = -1, recoilT1 = -0.5, recoilT2 = 0.5, recoilTime = 1.0 }, 
}
--GT.WS[ws].LN[1].customViewPoint = { "genericMissile", {-2.0, 0.75, 0.0}, }; 

---------------------------------------------------------------------------------------------------------------------------------------------------------

-- RIM-116 Rolling Airframe Missile

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.RIM_116)
GT.WS[ws].area = 'RAMTURRET'
GT.WS[ws].angles[1][1] = {math.rad(180), math.rad(-45), math.rad(45), math.rad(80)};
GT.WS[ws].angles[1][2] = {math.rad(-45), math.rad(-180), math.rad(-5), math.rad(80)};
GT.WS[ws].reference_angle_Z = math.rad(0)
GT.WS[ws].reference_angle_Y = math.rad(-180)
GT.WS[ws].center = 'SeaRam_Center_Point'
GT.WS[ws].drawArgument1 = 23
GT.WS[ws].drawArgument2 = 24
local LN_ = GT.WS[ws].LN[1]
LN_.BR = {{connector_name = 'POINT_SEARAM', drawArgument = 198},}

---------------------------------------------------------------------------------------------------------------------------------------------------------

-- forward OTO Melara 76 mm
 --[[   --]]

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_MK75)
GT.WS[ws].area = 'OTO_TURRET'
GT.WS[ws].center = 'Turret_Center_Point'
GT.WS[ws].drawArgument1 = 0
GT.WS[ws].drawArgument2 = 1





GT.WS[ws].angles = {
					{math.rad(170), math.rad(40), math.rad(-2.5), math.rad(65)},
					{math.rad(40), math.rad(-40), math.rad(0), math.rad(65)},
					{math.rad(-40), math.rad(-170), math.rad(-2.5), math.rad(65)},
					};

			

GT.WS[ws].LN[1].BR[1].connector_name = 'POINT_OTO_76'  --extremité du cannon
GT.WS[ws].LN[1].BR[1].recoilTime = 0.120;            -- recoil = recul

GT.WS[ws].LN[1].customViewPoint = { "genericHowitzer", {-3.8, 0.6, 0.0 }, }   -- x,y,z  x=  /  x= axe horizontal y= axe vertical / z = axe latéral

	


---------------------------------------------------------------------------------------------------------------------------------------------------------

-- Harpoon

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_HARPOON )
GT.WS[ws].area = 'HARPOONS';
GT.WS[ws].center = 'Rocket_Point_125'
GT.WS[ws].pos = {14.459,-0.989,9.471}

GT.WS[ws].LN[1].PL[1].ammo_capacity = 4;
GT.WS[ws].LN[1].BR = {
		{connector_name = 'Rocket_Point_123', drawArgument = 153},
		{connector_name = 'Rocket_Point_124', drawArgument = 154},
		{connector_name = 'Rocket_Point_125', drawArgument = 155},
		{connector_name = 'Rocket_Point_126', drawArgument = 156},
}

ws = GT_t.inc_ws();
GT.WS[ws] = {}
set_recursive_metatable(GT.WS[ws], GT_t.WS_t.ship_HARPOON )
GT.WS[ws].area = 'HARPOONS';
GT.WS[ws].center = 'Rocket_Point_129'
GT.WS[ws].pos = {14.459,0.68,7.65}

GT.WS[ws].LN[1].PL[1].ammo_capacity = 4;
GT.WS[ws].LN[1].BR = {
		{connector_name = 'Rocket_Point_127', drawArgument = 157},
		{connector_name = 'Rocket_Point_128', drawArgument = 158},
		{connector_name = 'Rocket_Point_129', drawArgument = 159},
		{connector_name = 'Rocket_Point_130', drawArgument = 160},
}

---------------------------------------------------------------------------------------------------------------------------------------------------------

-- 9 AIGES trackers
ws = GT_t.inc_ws();
local first_EGES_tracker_id = ws;
GT.WS[ws] = {
	omegaY = 2,
	omegaZ = 2,
	pidY = {p=100, i=0.05, d=12, inn = 50},
	pidZ = {p=100, i=0.05, d=12, inn = 50},
	area = 'RDR',
	pos = {0.0, 19.0, 0.0},
	angles = { {math.rad(180), math.rad(-180), math.rad(-90), math.rad(80)} },
	LN = {
		[1] = {
			type = 102,
			distanceMin = 1000,
			distanceMax = 150000,
			reactionTime = 2.0,
			reflection_limit = 0.1,
			ECM_K = 0.5,
			min_trg_alt = 5,
			max_trg_alt = 30000,
			max_number_of_missiles_channels = 2
		}
	}
};
local AIGES_TRACKERS = {{{'self', ws}}}

for i=2,9 do
	ws = GT_t.inc_ws();
	GT.WS[ws] = {};
	set_recursive_metatable(GT.WS[ws], GT.WS[first_EGES_tracker_id]);
	table.insert(AIGES_TRACKERS, {{'self', ws}})
end;

------------------------------------------------------------------------------------------------------
--      Final Part                                                                               --
------------------------------------------------------------------------------------------------------

GT.Name = "FDI_BELHARRA"
GT.DisplayName = _("FDI-Belharra Class")
GT.Rate = 2500

GT.Sensors = {  OPTIC = {"long-range naval optics", "long-range naval LLTV", "long-range naval FLIR",},
                RADAR = {
                "Patriot str",
                "perry search radar",
				"seasparrow tr",
                }
            };


			
GT.DetectionRange  = GT.airFindDist;
GT.ThreatRange = GT.airWeaponDist;

GT.Singleton   ="yes";
GT.mapclasskey = "P0091000069";
GT.attribute = {wsType_Navy,wsType_Ship,wsType_ArmedShip,PERRY,

					"Frigates",
                    "RADAR_BAND1_FOR_ARM",
                    "DetectionByAWACS",
					"Datalink",
				};
				
GT.Categories = {
					{name = "Armed Ship"},
					{name = "HelicopterCarrier"}
				};
						
						
--GT.tags  =
--{
--	"Frigate",
--}

GT.Countries = {"Greece", "France"}
						
add_surface_unit(GT)	
