-- Weapons for Type 055 Destroyer by Currenthill

-- =============================== YJ-18 ship-launched anti ship missile ==========================================

local YJ18_warhead = {
    mass                 = 300, 
    caliber              = 500,
    expl_mass            = 300, 
    piercing_mass        = 300, 
    other_factors        = { 1.0, 1.0, 1.0 },
    concrete_factors     = { 2.0, 1.0, 1.0 },
    concrete_obj_factor  = 2.0,
    obj_factors          = { 2.0, 1.0 },
    cumulative_factor    = 2.0,
    cumulative_thickness = 0.0,
}

local TYPE_055_YJ_18 = {
	category		= CAT_MISSILES,
	name			= "TYPE055_YJ18",
	user_name	 	= _("YJ-18"),
	mass			= 850,
	model			= 'Type055_YJ-18',
	wsTypeOfWeapon  = {wsType_Weapon,wsType_Missile,wsType_AS_Missile,WSTYPE_PLACEHOLDER},
	Escort 			= 0,
	Head_Type 		= 5,  
	sigma 			= {8, 8, 8},
	M 				= 850.0,   
	H_max 			= 30000.0,  
	H_min 			= -1,  
	Diam 			= 343.0,
	Cx_pil 			= 4,   
	D_max 			= 380000.0, 
	D_min 			= 2000.0,
	Head_Form 		= 1, 
	Life_Time 		= 1800.0,   
	Nr_max 			= 18,  
	v_min 			= 170.0,
	v_mid 			= 450.0,  
	Mach_max 		= 1.3,  
	t_b 			= 0.0,
	t_acc 			= 4.0, 
	t_marsh         = 1800.0,  
	Range_max 		= 380000.0, 
	H_min_t 		= 0.0,
	Fi_start 		= 3.14152,
    Fi_rak 			= 3.14152,
    Fi_excort 		= 3.14152,
    Fi_search 		= 99.9,
    OmViz_max 		= 99.9,	
	Stage			= 2,
	Engine_Type		= 6,
	exhaust1 		= { 1, 1, 1, 1 },
	X_back 			= -9.0,  
	Y_back 			= 0.0, 
	Z_back 			= 0.0,  
	X_back_acc 		= -10.2,
    Y_back_acc 		= 0.0,
    Z_back_acc 		= 0.0,
	Reflection 		= 0.8, 
	KillDistance 	= 0.0, 
	add_attributes = {"Cruise missiles"},	

	warhead	= YJ18_warhead,
	warhead_air = YJ18_warhead,

	shape_table_data = 
	{
		{

			name	 = "TYPE055_YJ18";
			file  	 = "Type055_YJ-18";   		
			life  	 = 1;
			fire  	 = { 0, 1};
			username = _("YJ-18");
			index = WSTYPE_PLACEHOLDER;
		},
	},

   class_name      = "wAmmunitionSelfHoming",
    scheme          = "anti_ship_missile_tb",

    fm = {
		A 			= 0.36,
		I 			= 1104.5,
		I_x 		= 60,
		L 			= 4.7,
		Ma 			= 0.4,
		Ma_x 		= 0.001,
		Mw 			= 1.2,
		Mw_x 		= 0.15,
		Sw 			= 0.7,
		caliber 	= 0.36,
		cx_coeff	= {1, 0.3, 0.65, 0.023, 1.6},			
		dCydA 		= { 0.07, 0.036 },
		finsTau 	= 0.1,
		lockRoll 	= 1,
		mass 		= 600,
		maxAoa 		= 0.28,
		wind_sigma 	= 0,
		wind_time 	= 0,
    },

    simple_seeker = {
        delay        = 1.0,
        FOV          = math.rad(120),
        stTime       = 0.5,
        opTime       = 9999,
    },
	
	simple_gyrostab_seeker = {
		omega_max	= math.rad(120)
	},	

    autopilot =    --inertial autopilot + horiz correction when seeker is on
    {
        delay                      = 1,        -- time delay
        Kpv                        = 0.02,     -- vertical control PID
        Kdv                        = 2,
        Kiv                        = 0.00006,
        Kph                        = 500.0,    -- horiz control PID
        Kdh                        = 5.0,
        Kih                        = 0.0,
        glide_height               = 6.0,      -- cruise glide height
        use_current_height         = 1,        -- keep launch height
        max_vert_speed             = 4.0,      -- max vertical speed kept from launch height to glide height
        altim_vel_k                = 1.0,      -- proximity sensor correction by velocity coeff
        finsLimit                  = 0.9,      -- max signal value from autopilot to fins
        inertial_km_error          = 0.75,      -- inertial guidance error coeff to 1 km flight distance
    },

    final_autopilot =        -- final stage guidance with terminal maneuver
    {
        delay                    = 0,
        K                        = 60,       -- autopilot P
        Ki                       = 0,        -- I
        Kg                       = 6,        -- D
        finsLimit                = 0.9, 
        useJumpByDefault         = 0,        
        J_Power_K                = 2.0,      -- terminal maneuver params: P
        J_Diff_K                 = 0.8,      -- D
        J_Int_K                  = 0,        -- I
        J_Angle_K                = 0.7,      -- jump maneuver angle
        J_FinAngle_K             = 0.52,     -- jump inactivation trigger angle to target
        J_Angle_W                = 3.0,      -- max maneuver angle speed
        bang_bang                = 0,        -- use only -1, 1 values to control fins
        J_Trigger_Vert           = 1,        -- use global y axis
		
    },

    h_glide_on = {            -- turn on seeker and start horiz. correction if target is locked on
        delay                   = 1,
        trigger_dist            = 30000,
    },

    mode_switcher = {        -- use final maneuver if target is locked on
        delay           = 1,
        trigger_dist    = 3000,
    },

    self_destruct =         -- if seeker still can not find a target explode warhead
    {
        delay = 1,
        trigger_dist            = 1000,
        inactivation_dist       = 900,
    },

    controller = {
        boost_start = 0.1,
        march_start = 4.0,
    },

    boost = {
        impulse                             = 270,
        fuel_mass                           = 225,
        work_time                           = 4,
        boost_time                          = 0,
        boost_factor                        = 0,
        nozzle_position                     = {{-10.4, 0, 0}},
        nozzle_orientationXYZ               = {{0, 0, 0}},
        tail_width                          = 2.8,
        smoke_color                         = {1, 1, 1},
        smoke_transparency                  = 0.1,
        custom_smoke_dissipation_factor     = 0.2,
    },

    booster_animation = {
        start_val = 1, -- start arg.1 value ( default value without animation)
    },

    play_booster_animation = {
        val = 1, -- 1/0
    },

    encyclopediaAnimation = {
        args = {
            [1] = 1.00,
        },
    },

    march = {
        impulse          = 760,
        fuel_mass        = 450, 
        work_time        = 9999,
        min_fuel_rate    = 0.005,
        min_thrust       = 0,
        max_thrust       = 6500,
        thrust_Tau       = 0.0017,
    },

    engine_control = {
        default_speed   = 1930,
        K               = 300,
        Kd              = 0.01,
        Ki              = 0.001,
        burst_signal    = 9999, -- used in 'anti_ship_missile_tb' scheme
    },	
	
}

declare_weapon(TYPE_055_YJ_18)

GT_t.WS_t.Type055_YJ18 = {} 
GT_t.WS_t.Type055_YJ18.angles = {
					{math.rad(180), math.rad(-180), math.rad(-90), math.rad(90)},
					};
GT_t.WS_t.Type055_YJ18.moveable = false
GT_t.WS_t.Type055_YJ18.LN = {}
GT_t.WS_t.Type055_YJ18.LN[1] = {}
GT_t.WS_t.Type055_YJ18.LN[1].type = 1
GT_t.WS_t.Type055_YJ18.LN[1].distanceMin = 2000
GT_t.WS_t.Type055_YJ18.LN[1].distanceMax = 380000
GT_t.WS_t.Type055_YJ18.LN[1].reactionTime = 1;
GT_t.WS_t.Type055_YJ18.LN[1].launch_delay = 1;
GT_t.WS_t.Type055_YJ18.LN[1].max_number_of_missiles_channels = 16
GT_t.WS_t.Type055_YJ18.LN[1].sensor = {}
set_recursive_metatable(GT_t.WS_t.Type055_YJ18.LN[1].sensor, GT_t.WSN_t[0])
GT_t.WS_t.Type055_YJ18.LN[1].external_tracking_awacs = true
GT_t.WS_t.Type055_YJ18.LN[1].show_external_missile = true
GT_t.WS_t.Type055_YJ18.LN[1].PL = {}
GT_t.WS_t.Type055_YJ18.LN[1].PL[1] = {}
GT_t.WS_t.Type055_YJ18.LN[1].PL[1].ammo_capacity = 16
GT_t.WS_t.Type055_YJ18.LN[1].PL[1].type_ammunition = TYPE_055_YJ_18.wsTypeOfWeapon
GT_t.WS_t.Type055_YJ18.LN[1].PL[1].reload_time = 1000000; 
GT_t.WS_t.Type055_YJ18.LN[1].PL[1].shot_delay = 0.1;
GT_t.WS_t.Type055_YJ18.LN[1].BR = { {pos = {0, 0, 0} } }
