defineProperty("annun1_aur", globalPropertyf("sim/custom/xap/annun1_aur"))
defineProperty("annun2_aur", globalPropertyf("sim/custom/xap/annun2_aur"))

defineProperty("taws_test_aur", globalPropertyf("sim/custom/xap/taws_test_aur"))
defineProperty("fire_test_aur", globalPropertyf("sim/custom/xap/fire_test_aur"))
defineProperty("stall_warn_test", globalPropertyi("sim/custom/xap/stall_warn_test"))

defineProperty("poweron_p", globalPropertyi("sim/custom/xap/poweron_p"))

defineProperty("sound_vol", globalPropertyf("sim/custom/xap/sound_vol"))
defineProperty("sound_mute", globalPropertyi("sim/custom/xap/sound_mute"))

defineProperty("mfd_pan_cas", globalPropertyi("sim/custom/xap/mfd_pan_cas"))
defineProperty("machno", globalPropertyf("sim/flightmodel/misc/machno"))
defineProperty("ind_speed", globalPropertyf("sim/flightmodel/position/indicated_airspeed"))
defineProperty("flaprat", globalPropertyf("sim/flightmodel/controls/flaprat"))
defineProperty("flaprqst", globalPropertyf("sim/flightmodel/controls/flaprqst"))

defineProperty("lan_gear_warn", globalPropertyi("sim/custom/xap/lan_gear_warn"))
defineProperty("gear_warn", globalPropertyi("sim/custom/xap/gear_warn"))
defineProperty("gear_warn_w", globalPropertyi("sim/custom/xap/gear_warn_w"))
defineProperty("flaps_warn", globalPropertyi("sim/custom/xap/flaps_warn"))
defineProperty("terr_warn", globalPropertyi("sim/custom/xap/terr_warn"))

defineProperty("rel_lbrakes", globalPropertyi("sim/operation/failures/rel_lbrakes"))
defineProperty("rel_rbrakes", globalPropertyi("sim/operation/failures/rel_rbrakes"))

defineProperty("rel_engfir0", globalPropertyi("sim/operation/failures/rel_engfir0"))
defineProperty("rel_engfir1", globalPropertyi("sim/operation/failures/rel_engfir1"))

defineProperty("config_warn", globalPropertyi("sim/custom/xap/config_warn"))
defineProperty("cabalt_warn", globalPropertyi("sim/custom/xap/cabalt_warn"))


defineProperty("roll_AHARS_deg_pilot", globalPropertyf("sim/cockpit2/gauges/indicators/roll_AHARS_deg_pilot"))
defineProperty("radio_altimeter_height_ft_pilot", globalPropertyf("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot"))


defineProperty("frame_rate_period", globalPropertyf("sim/operation/misc/frame_rate_period"))
defineProperty("replay_mode", globalPropertyi("sim/operation/prefs/replay_mode"))

defineProperty("red_cas", globalPropertyi("sim/custom/xap/red_cas"))
defineProperty("yellow_cas", globalPropertyi("sim/custom/xap/yellow_cas"))

defineProperty("dcp_radar", globalPropertyi("sim/custom/xap/dcp_radar"))
defineProperty("dcp_refs", globalPropertyi("sim/custom/xap/dcp_refs"))
defineProperty("dcp_dmeh", globalPropertyi("sim/custom/xap/dcp_dmeh"))
defineProperty("dcp_1_2", globalPropertyi("sim/custom/xap/dcp_1_2"))
defineProperty("dcp_range", globalPropertyi("sim/custom/xap/dcp_range"))
defineProperty("dcp_tilt", globalPropertyi("sim/custom/xap/dcp_tilt"))

defineProperty("mfd_sel_state_h", globalPropertyi("sim/custom/xap/mfd_sel_state_h"))

defineProperty("mfd_checkl_l", globalPropertyi("sim/custom/xap/mfd_checkl_l"))
defineProperty("mfd_hydr_l", globalPropertyi("sim/custom/xap/mfd_hydr_l"))
defineProperty("mfd_fuel_l", globalPropertyi("sim/custom/xap/mfd_fuel_l"))
defineProperty("mfd_flt_ctr_l", globalPropertyi("sim/custom/xap/mfd_flt_ctr_l"))
defineProperty("mfd_electr_l", globalPropertyi("sim/custom/xap/mfd_electr_l"))
defineProperty("mfd_ecs_l", globalPropertyi("sim/custom/xap/mfd_ecs_l"))
defineProperty("mfd_antice_l", globalPropertyi("sim/custom/xap/mfd_antice_l"))
defineProperty("mfd_frmt_l", globalPropertyi("sim/custom/xap/mfd_frmt_l"))
defineProperty("mfd_sumry_l", globalPropertyi("sim/custom/xap/mfd_sumry_l"))

defineProperty("mfd_checkl_r", globalPropertyi("sim/custom/xap/mfd_checkl_r"))
defineProperty("mfd_hydr_r", globalPropertyi("sim/custom/xap/mfd_hydr_r"))
defineProperty("mfd_fuel_r", globalPropertyi("sim/custom/xap/mfd_fuel_r"))
defineProperty("mfd_flt_ctr_r", globalPropertyi("sim/custom/xap/mfd_flt_ctr_r"))
defineProperty("mfd_electr_r", globalPropertyi("sim/custom/xap/mfd_electr_r"))
defineProperty("mfd_ecs_r", globalPropertyi("sim/custom/xap/mfd_ecs_r"))
defineProperty("mfd_antice_r", globalPropertyi("sim/custom/xap/mfd_antice_r"))
defineProperty("mfd_frmt_r", globalPropertyi("sim/custom/xap/mfd_frmt_r"))
defineProperty("mfd_sumry_r", globalPropertyi("sim/custom/xap/mfd_sumry_r"))
defineProperty("map_mode", globalPropertyi("sim/cockpit2/EFIS/map_mode"))
defineProperty("EFIS_tcas_on", globalPropertyi("sim/cockpit2/EFIS/EFIS_tcas_on"))
defineProperty("EFIS_weather_on", globalPropertyi("sim/cockpit2/EFIS/EFIS_weather_on"))

defineProperty("dcp_tune1_rot", globalPropertyi("sim/custom/xap/dcp_tune1_rot"))
defineProperty("dcp_tune2_rot", globalPropertyi("sim/custom/xap/dcp_tune2_rot"))
defineProperty("dcp_menu1_rot", globalPropertyi("sim/custom/xap/dcp_menu1_rot"))
defineProperty("dcp_menu2_rot", globalPropertyi("sim/custom/xap/dcp_menu2_rot"))

defineProperty("dcp_navsrc", globalPropertyi("sim/custom/xap/dcp_navsrc"))
defineProperty("autop_brgsrc", globalPropertyi("sim/custom/xap/autop_brgsrc"))
defineProperty("HSI_source_select_pilot", globalPropertyi("sim/cockpit2/radios/actuators/HSI_source_select_pilot"))
defineProperty("nav1_obs_deg_mag_pilot", globalPropertyi("sim/cockpit2/radios/actuators/nav1_obs_deg_mag_pilot"))
defineProperty("nav2_obs_deg_mag_pilot", globalPropertyi("sim/cockpit2/radios/actuators/nav2_obs_deg_mag_pilot"))

defineProperty("vvi_dial_fpm", globalPropertyf("sim/cockpit2/autopilot/vvi_dial_fpm"))
defineProperty("hsi_obs_deg_mag_pilot", globalPropertyf("sim/cockpit2/radios/actuators/hsi_obs_deg_mag_pilot"))
defineProperty("heading_dial_deg_mag_pilot", globalPropertyf("sim/cockpit2/autopilot/heading_dial_deg_mag_pilot"))
defineProperty("airspeed_dial_kts_mach", globalPropertyf("sim/cockpit2/autopilot/airspeed_dial_kts_mach"))
defineProperty("altitude_dial_ft", globalPropertyf("sim/cockpit2/autopilot/altitude_dial_ft"))

defineProperty("stbi_cage_h", globalPropertyi("sim/custom/xap/stbi_cage_h"))
defineProperty("stby_ins_dim_brt", globalPropertyi("sim/custom/xap/stby_ins_dim_brt"))

defineProperty("autop_yd_h", globalPropertyi("sim/custom/xap/autop_yd_h"))
defineProperty("autop_xfr_h", globalPropertyi("sim/custom/xap/autop_xfr_h"))
defineProperty("autop_ap_h", globalPropertyi("sim/custom/xap/autop_ap_h"))
defineProperty("autop_alt_h", globalPropertyi("sim/custom/xap/autop_alt_h"))
defineProperty("autop_vnav_h", globalPropertyi("sim/custom/xap/autop_vnav_h"))
defineProperty("autop_vs_h", globalPropertyi("sim/custom/xap/autop_vs_h"))
defineProperty("autop_flc_h", globalPropertyi("sim/custom/xap/autop_flc_h"))
defineProperty("autop_bc_h", globalPropertyi("sim/custom/xap/autop_bc_h"))
defineProperty("autop_appr_h", globalPropertyi("sim/custom/xap/autop_appr_h"))
defineProperty("autop_hdg_h", globalPropertyi("sim/custom/xap/autop_hdg_h"))
defineProperty("autop_nav_h", globalPropertyi("sim/custom/xap/autop_nav_h"))
defineProperty("autop_fdir_h", globalPropertyi("sim/custom/xap/autop_fdir_h"))
defineProperty("half_bank_h", globalPropertyi("sim/custom/xap/half_bank_h"))

defineProperty("clock_timer_h", globalPropertyi("sim/custom/xap/clock_timer_h"))
defineProperty("clock_gps", globalPropertyi("sim/custom/xap/clock_gps"))
defineProperty("clock_flt", globalPropertyi("sim/custom/xap/clock_flt"))
defineProperty("clock_mode", globalPropertyi("sim/custom/xap/clock_mode"))



defineProperty("pedals_fwd_bwd_l", globalPropertyf("sim/custom/xap/pedals_fwd_bwd_l"))
defineProperty("pedals_fwd_bwd_r", globalPropertyf("sim/custom/xap/pedals_fwd_bwd_r"))


defineProperty("pitch_d_2", globalPropertyi("sim/custom/xap/pitch_d_2"))
defineProperty("pitch_d_1", globalPropertyi("sim/custom/xap/pitch_d_1"))
defineProperty("lg_man", globalPropertyi("sim/custom/xap/lg_man"))

defineProperty("mfdpan_lr_sw", globalPropertyi("sim/custom/xap/mfdpan_lr_sw"))

defineProperty("aud_pa_r_h", globalPropertyi("sim/custom/xap/aud_pa_r_h"))
defineProperty("aud_cab_r_h", globalPropertyi("sim/custom/xap/aud_cab_r_h"))
defineProperty("aud_hf2_r_h", globalPropertyi("sim/custom/xap/aud_hf2_r_h"))
defineProperty("aud_hf1_r_h", globalPropertyi("sim/custom/xap/aud_hf1_r_h"))
defineProperty("aud_com3_r_h", globalPropertyi("sim/custom/xap/aud_com3_r_h"))
defineProperty("aud_com2_r_h", globalPropertyi("sim/custom/xap/aud_com2_r_h"))
defineProperty("aud_com1_r_h", globalPropertyi("sim/custom/xap/aud_com1_r_h"))

defineProperty("aud_pa_l_h", globalPropertyi("sim/custom/xap/aud_pa_l_h"))
defineProperty("aud_cab_l_h", globalPropertyi("sim/custom/xap/aud_cab_l_h"))
defineProperty("aud_hf2_l_h", globalPropertyi("sim/custom/xap/aud_hf2_l_h"))
defineProperty("aud_hf1_l_h", globalPropertyi("sim/custom/xap/aud_hf1_l_h"))
defineProperty("aud_com3_l_h", globalPropertyi("sim/custom/xap/aud_com3_l_h"))
defineProperty("aud_com2_l_h", globalPropertyi("sim/custom/xap/aud_com2_l_h"))
defineProperty("aud_com1_l_h", globalPropertyi("sim/custom/xap/aud_com1_l_h"))


defineProperty("barometer_setting_in_hg_pilot", globalPropertyf("sim/cockpit2/gauges/actuators/barometer_setting_in_hg_pilot"))

defineProperty("aud_o2m_l_sw", globalPropertyi("sim/custom/xap/aud_o2m_l_sw"))
defineProperty("aud_emer_l_sw", globalPropertyi("sim/custom/xap/aud_emer_l_sw"))
defineProperty("aud_voice_l_sw", globalPropertyi("sim/custom/xap/aud_voice_l_sw"))
defineProperty("comps_slew_l_sw", globalPropertyi("sim/custom/xap/comps_slew_l_sw"))
defineProperty("rudd_ped_l_sw", globalPropertyi("sim/custom/xap/rudd_ped_l_sw"))
defineProperty("aud_o2m_r_sw", globalPropertyi("sim/custom/xap/aud_o2m_r_sw"))
defineProperty("aud_emer_r_sw", globalPropertyi("sim/custom/xap/aud_emer_r_sw"))
defineProperty("aud_voice_r_sw", globalPropertyi("sim/custom/xap/aud_voice_r_sw"))
defineProperty("comps_slew_r_sw", globalPropertyi("sim/custom/xap/comps_slew_r_sw"))
defineProperty("rudd_ped_r_sw", globalPropertyi("sim/custom/xap/rudd_ped_r_sw"))
defineProperty("comps_head_l_h", globalPropertyi("sim/custom/xap/comps_head_l_h"))
defineProperty("comps_head_r_h", globalPropertyi("sim/custom/xap/comps_head_r_h"))



defineProperty("elt_h", globalPropertyi("sim/custom/xap/elt_h"))

defineProperty("dcu_b_cov", globalPropertyi("sim/custom/xap/dcu_b_cov"))
defineProperty("dcu_b_h", globalPropertyi("sim/custom/xap/dcu_b_h"))
defineProperty("dcu_a_cov", globalPropertyi("sim/custom/xap/dcu_a_cov"))
defineProperty("dcu_a_h", globalPropertyi("sim/custom/xap/dcu_a_h"))


defineProperty("cab_ac_cov", globalPropertyi("sim/custom/xap/cab_ac_cov"))
defineProperty("cab_ac_h", globalPropertyi("sim/custom/xap/cab_ac_h"))
defineProperty("cab_dc_cov", globalPropertyi("sim/custom/xap/cab_dc_cov"))
defineProperty("cab_dc_h", globalPropertyi("sim/custom/xap/cab_dc_h"))

defineProperty("oxigen_ox", globalPropertyi("sim/custom/xap/oxigen_ox"))
defineProperty("oxigen_terap_cov", globalPropertyi("sim/custom/xap/oxigen_terap_cov"))
defineProperty("oxigen_terap_h", globalPropertyi("sim/custom/xap/oxigen_terap_h"))

defineProperty("fire_engn_r_cov", globalPropertyi("sim/custom/xap/fire_engn_r_cov"))
defineProperty("fire_engn_r_h", globalPropertyi("sim/custom/xap/fire_engn_r_h"))
defineProperty("fire_engn_l_cov", globalPropertyi("sim/custom/xap/fire_engn_l_cov"))
defineProperty("fire_engn_l_h", globalPropertyi("sim/custom/xap/fire_engn_l_h"))
defineProperty("fire_apu_cov", globalPropertyi("sim/custom/xap/fire_apu_cov"))
defineProperty("fire_apu_h", globalPropertyi("sim/custom/xap/fire_apu_h"))
defineProperty("fire_ext_2_cov", globalPropertyi("sim/custom/xap/fire_ext_2_cov"))
defineProperty("fire_ext_2_h", globalPropertyi("sim/custom/xap/fire_ext_2_h"))
defineProperty("fire_ext_1_cov", globalPropertyi("sim/custom/xap/fire_ext_1_cov"))
defineProperty("fire_ext_1_h", globalPropertyi("sim/custom/xap/fire_ext_1_h"))
defineProperty("fire_autoapr_cov", globalPropertyi("sim/custom/xap/fire_autoapr_cov"))
defineProperty("fire_autoapr_h", globalPropertyi("sim/custom/xap/fire_autoapr_h"))
defineProperty("engn_mach_h", globalPropertyi("sim/custom/xap/engn_mach_h"))
defineProperty("engn_ign_h", globalPropertyi("sim/custom/xap/engn_ign_h"))

defineProperty("test_rot", globalPropertyi("sim/custom/xap/test_rot"))

defineProperty("trim_rud", globalPropertyf("sim/custom/xap/trim_rud"))
defineProperty("trim_stab", globalPropertyi("sim/custom/xap/trim_stab"))
defineProperty("trim_pusher_h", globalPropertyi("sim/custom/xap/trim_pusher_h"))
defineProperty("trim_pusher_cov", globalPropertyi("sim/custom/xap/trim_pusher_cov"))


defineProperty("hydr_altn_flp_cov", globalPropertyi("sim/custom/xap/hydr_altn_flp_cov"))
defineProperty("hydr_l_sov_cov", globalPropertyi("sim/custom/xap/hydr_l_sov_cov"))
defineProperty("hydr_r_sov_cov", globalPropertyi("sim/custom/xap/hydr_r_sov_cov"))
defineProperty("hydr_altn_flp_h", globalPropertyi("sim/custom/xap/hydr_altn_flp_h"))
defineProperty("hydr_l_sov_h", globalPropertyi("sim/custom/xap/hydr_l_sov_h"))
defineProperty("hydr_r_sov_h", globalPropertyi("sim/custom/xap/hydr_r_sov_h"))



defineProperty("electr_apugen_h", globalPropertyi("sim/custom/xap/electr_apugen_h"))
defineProperty("electr_gen_r_h", globalPropertyi("sim/custom/xap/electr_gen_r_h"))
defineProperty("electr_gen_l_h", globalPropertyi("sim/custom/xap/electr_gen_l_h"))
defineProperty("electr_stbi_h", globalPropertyi("sim/custom/xap/electr_stbi_h"))
defineProperty("electr_extp_h", globalPropertyi("sim/custom/xap/electr_extp_h"))


defineProperty("antice_wngsource_r", globalPropertyi("sim/custom/xap/antice_wngsource_r"))
defineProperty("antice_wshld_r_h", globalPropertyi("sim/custom/xap/antice_wshld_r_h"))
defineProperty("antice_wshld_l_h", globalPropertyi("sim/custom/xap/antice_wshld_l_h"))
defineProperty("antice_engn_r_h", globalPropertyi("sim/custom/xap/antice_engn_r_h"))
defineProperty("antice_engn_l_h", globalPropertyi("sim/custom/xap/antice_engn_l_h"))
defineProperty("antice_probe_r_h", globalPropertyi("sim/custom/xap/antice_probe_r_h"))
defineProperty("antice_probe_l_h", globalPropertyi("sim/custom/xap/antice_probe_l_h"))
defineProperty("antice_wing_h", globalPropertyi("sim/custom/xap/antice_wing_h"))


defineProperty("pressure_lndg_alt_1", globalPropertyi("sim/custom/xap/pressure_lndg_alt_1"))
defineProperty("pressure_lndg_alt_2", globalPropertyf("sim/custom/xap/pressure_lndg_alt_2"))
defineProperty("pressure_manrate", globalPropertyf("sim/custom/xap/pressure_manrate"))

defineProperty("pressure_emer_depr_h", globalPropertyi("sim/custom/xap/pressure_emer_depr_h"))
defineProperty("pressure_ditch_h", globalPropertyi("sim/custom/xap/pressure_ditch_h"))
defineProperty("pressure_man_h", globalPropertyi("sim/custom/xap/pressure_man_h"))
defineProperty("pressure_ditch_cov", globalPropertyi("sim/custom/xap/pressure_ditch_cov"))
defineProperty("pressure_emer_depr_cov", globalPropertyi("sim/custom/xap/pressure_emer_depr_cov"))

defineProperty("aircond_ramair_cov", globalPropertyi("sim/custom/xap/aircond_ramair_cov"))
defineProperty("taws_ter_cov", globalPropertyi("sim/custom/xap/taws_ter_cov"))
defineProperty("taws_flp_cov", globalPropertyi("sim/custom/xap/taws_flp_cov"))
defineProperty("taws_gs_cov", globalPropertyi("sim/custom/xap/taws_gs_cov"))
defineProperty("flight_spoil_cov", globalPropertyi("sim/custom/xap/flight_spoil_cov"))

defineProperty("gust_lock", globalPropertyf("sim/custom/xap/gust_lock"))
defineProperty("parking_brake_ratio", globalPropertyi("sim/cockpit2/controls/parking_brake_ratio"))

defineProperty("aircond_cockpit_temp", globalPropertyf("sim/custom/xap/aircond_cockpit_temp"))
defineProperty("aircond_cabin_temp", globalPropertyf("sim/custom/xap/aircond_cabin_temp"))
defineProperty("aircond_airsource", globalPropertyi("sim/custom/xap/aircond_airsource"))
defineProperty("aircond_man_temp_h", globalPropertyi("sim/custom/xap/aircond_man_temp_h"))
defineProperty("aircond_ramair_h", globalPropertyi("sim/custom/xap/aircond_ramair_h"))


defineProperty("nws_h", globalPropertyi("sim/custom/xap/nws_h"))

defineProperty("taws_ter_h", globalPropertyi("sim/custom/xap/taws_ter_h"))
defineProperty("taws_flp_h", globalPropertyi("sim/custom/xap/taws_flp_h"))
defineProperty("taws_gs_h", globalPropertyi("sim/custom/xap/taws_gs_h"))

defineProperty("fuel_xflow_up_h", globalPropertyi("sim/custom/xap/fuel_xflow_up_h"))
defineProperty("fuel_xflow_dn_h", globalPropertyi("sim/custom/xap/fuel_xflow_dn_h"))
defineProperty("fuel_xpump_r", globalPropertyi("sim/custom/xap/fuel_xpump_r"))
defineProperty("fuel_xpump_l", globalPropertyi("sim/custom/xap/fuel_xpump_l"))

defineProperty("rev_air_dat", globalPropertyi("sim/custom/xap/rev_air_dat"))
defineProperty("rev_att_hd", globalPropertyi("sim/custom/xap/rev_att_hd"))
defineProperty("rev_tune", globalPropertyi("sim/custom/xap/rev_tune"))
defineProperty("rev_pan_l", globalPropertyi("sim/custom/xap/rev_pan_l"))
defineProperty("rev_pan_r", globalPropertyi("sim/custom/xap/rev_pan_r"))


defineProperty("jet_sync_mode", globalPropertyi("sim/cockpit2/switches/jet_sync_mode"))

defineProperty("bleed_xbleed_h", globalPropertyi("sim/custom/xap/bleed_xbleed_h"))
defineProperty("bleed_en_l_h", globalPropertyi("sim/custom/xap/bleed_en_l_h"))
defineProperty("bleed_en_r_h", globalPropertyi("sim/custom/xap/bleed_en_r_h"))
defineProperty("bleed_apu_h", globalPropertyi("sim/custom/xap/bleed_apu_h"))


defineProperty("APU_starter_switch", globalPropertyi("sim/cockpit2/electrical/APU_starter_switch"))
defineProperty("flight_spoil_h", globalPropertyi("sim/custom/xap/flight_spoil_h"))
defineProperty("ground_sp_h", globalPropertyi("sim/custom/xap/ground_sp_h"))

defineProperty("en_starter_l", globalPropertyi("sim/custom/xap/en_starter_l"))
defineProperty("en_starter_r", globalPropertyi("sim/custom/xap/en_starter_r"))
defineProperty("en_but_run_l", globalPropertyi("sim/custom/xap/en_but_run_l"))
defineProperty("en_but_run_r", globalPropertyi("sim/custom/xap/en_but_run_r"))

defineProperty("aux_hpump_h", globalPropertyi("sim/custom/xap/aux_hpump_h"))
defineProperty("l_hpump_h", globalPropertyi("sim/custom/xap/l_hpump_h"))
defineProperty("r_hpump_h", globalPropertyi("sim/custom/xap/r_hpump_h"))
defineProperty("ptu_h", globalPropertyi("sim/custom/xap/ptu_h"))

defineProperty("gear_handle_status", globalPropertyi("sim/cockpit/switches/gear_handle_status"))

defineProperty("left_bat_h", globalPropertyi("sim/custom/xap/left_bat_h"))
defineProperty("right_bat_h", globalPropertyi("sim/custom/xap/right_bat_h"))
defineProperty("bus_tie_h", globalPropertyf("sim/custom/xap/bus_tie_h"))

defineProperty("emeright_h", globalPropertyf("sim/custom/xap/emeright_h"))
defineProperty("landlight1h", globalPropertyf("sim/custom/xap/landlight1_h"))
defineProperty("landlight2h", globalPropertyf("sim/custom/xap/landlight2_h"))
defineProperty("xaptaxilighth", globalPropertyf("sim/custom/xap/xap_taxilight_h"))
defineProperty("cablight_h", globalPropertyf("sim/custom/xap/cablight_h"))
defineProperty("entrlight_h", globalPropertyf("sim/custom/xap/entrlight_h"))
defineProperty("crewlit_h", globalPropertyf("sim/custom/xap/crewlit_h"))
defineProperty("crewlit2_h", globalPropertyf("sim/custom/xap/crewlit2_h"))

defineProperty("strobe_h", globalPropertyf("sim/custom/xap/strobe_h"))
defineProperty("nav_h", globalPropertyf("sim/custom/xap/nav_h"))

defineProperty("wing_insp_h", globalPropertyf("sim/custom/xap/wing_insp_h"))

defineProperty("temp_out", globalPropertyf("sim/weather/temperature_ambient_c"))
defineProperty("windspeed", globalPropertyf("sim/weather/wind_speed_kt"))
defineProperty("rain_p", globalPropertyf("sim/weather/rain_percent"))

defineProperty("night_lights", globalPropertyf("sim/graphics/scenery/percent_lights_on"))

defineProperty("cockavl", globalPropertyf("sim/custom/xap/cockavl"))

defineProperty("sbrk_h", globalPropertyf("sim/custom/xap/sbrk_h"))

defineProperty("cmfd_h", globalPropertyf("sim/custom/xap/cmfd_h"))
defineProperty("cpfd_h", globalPropertyf("sim/custom/xap/cpfd_h"))
defineProperty("pmfd_h", globalPropertyf("sim/custom/xap/pmfd_h"))
defineProperty("ppfd_h", globalPropertyf("sim/custom/xap/ppfd_h"))
defineProperty("dome_h", globalPropertyf("sim/custom/xap/dome_h"))
defineProperty("annun_h", globalPropertyf("sim/custom/xap/annun_h"))
defineProperty("cbp_h", globalPropertyf("sim/custom/xap/cbp_h"))
defineProperty("gshldr_h", globalPropertyf("sim/custom/xap/gshldr_h"))
defineProperty("pedestal_h", globalPropertyf("sim/custom/xap/pedestal_h"))
defineProperty("gshldl_h", globalPropertyf("sim/custom/xap/gshldl_h"))

defineProperty("groundspeed", globalPropertyi("sim/flightmodel/position/groundspeed"))
defineProperty("onground_all", globalPropertyi("sim/flightmodel/failures/onground_all"))
defineProperty("paused", globalPropertyi("sim/time/sim_speed"))

defineProperty("sunscreen20", globalPropertyf("sim/custom/xap/sunscreen20"))
defineProperty("sunscreen10", globalPropertyf("sim/custom/xap/sunscreen10"))
defineProperty("sunscreen21", globalPropertyf("sim/custom/xap/sunscreen21"))
defineProperty("sunscreen11", globalPropertyf("sim/custom/xap/sunscreen11"))

defineProperty("elbus1", globalPropertyf("sim/cockpit2/electrical/bus_volts[0]"))
defineProperty("elbus2", globalPropertyf("sim/cockpit2/electrical/bus_volts[1]"))
defineProperty("elbus3", globalPropertyf("sim/cockpit2/electrical/bus_volts[2]"))

defineProperty("belt", globalPropertyi("sim/custom/xap/belt"))
defineProperty("smoke", globalPropertyi("sim/custom/xap/smoke"))
defineProperty("smokebelts_h", globalPropertyi("sim/custom/xap/smokebelts_h"))

defineProperty("mastervol", globalPropertyi("sim/custom/xap/master_vol"))

defineProperty("local_time_sec", globalPropertyf("sim/cockpit2/clock_timer/local_time_seconds"))

defineProperty("pulse", globalPropertyf("sim/graphics/animation/lights/pulse"))

defineProperty("disp_music_r", globalPropertyf("sim/custom/xap/disp_music_r"))

defineProperty("headposx", globalPropertyf("sim/graphics/view/pilots_head_x"))
defineProperty("headposy", globalPropertyf("sim/graphics/view/pilots_head_y"))
defineProperty("headposz", globalPropertyf("sim/graphics/view/pilots_head_z"))

defineProperty("door1", globalPropertyf("sim/flightmodel2/misc/custom_slider_ratio[5]"))
defineProperty("door2", globalPropertyf("sim/flightmodel2/misc/custom_slider_ratio[6]"))
defineProperty("door3", globalPropertyf("sim/custom/xap/customslider2_r"))
defineProperty("door4", globalPropertyf("sim/custom/xap/customslider4_r"))
defineProperty("door5", globalPropertyf("sim/custom/xap/customslider3_r"))

defineProperty("viewX", globalPropertyf("sim/graphics/view/view_x"))
defineProperty("viewY", globalPropertyf("sim/graphics/view/view_y"))
defineProperty("viewZ", globalPropertyf("sim/graphics/view/view_z"))
defineProperty("acfposX", globalPropertyf("sim/flightmodel/position/local_x"))
defineProperty("acfposY", globalPropertyf("sim/flightmodel/position/local_y"))
defineProperty("acfposZ", globalPropertyf("sim/flightmodel/position/local_z"))

defineProperty("acf_hdg", globalPropertyf("sim/flightmodel/position/psi"))
defineProperty("acf_pitch", globalPropertyf("sim/flightmodel/position/theta"))
defineProperty("acf_roll", globalPropertyf("sim/flightmodel/position/phi"))
defineProperty("view_hdg", globalPropertyf("sim/graphics/view/view_heading"))
defineProperty("cock_view_hdg", globalPropertyf("sim/graphics/view/cockpit_roll")) -- dataref name is wrong
defineProperty("cock_view_roll", globalPropertyf("sim/graphics/view/cockpit_heading")) -- dataref name is wrong

defineProperty("jalousie1", globalPropertyf("sim/custom/xap/jalousie1"))
defineProperty("jalousie2", globalPropertyf("sim/custom/xap/jalousie2"))
defineProperty("jalousie3", globalPropertyf("sim/custom/xap/jalousie3"))
defineProperty("jalousie4", globalPropertyf("sim/custom/xap/jalousie4"))
defineProperty("jalousie5", globalPropertyf("sim/custom/xap/jalousie5"))
defineProperty("jalousie6", globalPropertyf("sim/custom/xap/jalousie6"))
defineProperty("jalousie7", globalPropertyf("sim/custom/xap/jalousie7"))
defineProperty("jalousie8", globalPropertyf("sim/custom/xap/jalousie8"))
defineProperty("jalousie9", globalPropertyf("sim/custom/xap/jalousie9"))
defineProperty("jalousie10", globalPropertyf("sim/custom/xap/jalousie10"))
defineProperty("jalousie11", globalPropertyf("sim/custom/xap/jalousie11"))
defineProperty("jalousie12", globalPropertyf("sim/custom/xap/jalousie12"))

defineProperty("table1", globalPropertyf("sim/custom/xap/table1"))
defineProperty("table2", globalPropertyf("sim/custom/xap/table2"))
defineProperty("table3", globalPropertyf("sim/custom/xap/table3"))
defineProperty("table4", globalPropertyf("sim/custom/xap/table4"))

defineProperty("p_cush", globalPropertyf("sim/custom/xap/p_cush"))

defineProperty("disp", globalPropertyf("sim/custom/xap/disp"))
defineProperty("disp2", globalPropertyf("sim/custom/xap/disp2"))
defineProperty("disp3", globalPropertyf("sim/custom/xap/disp3"))
defineProperty("disp4", globalPropertyf("sim/custom/xap/disp4"))

defineProperty("flight_time", globalPropertyf("sim/time/total_flight_time_sec"))

defineProperty("acfpitch", globalPropertyf("sim/flightmodel/position/theta"))
defineProperty("acfyaw", globalPropertyf("sim/flightmodel/position/beta"))
defineProperty("acfroll", globalPropertyf("sim/flightmodel/position/phi"))

defineProperty("view", globalPropertyf("sim/graphics/view/view_is_external"))


defineProperty("mplayer", globalPropertyi("sim/custom/xap/music"))

defineProperty("s_master_gain", globalPropertyi("sim/custom/xap/s_master_gain"))






local font1 = loadFont('font_2.fnt')


local music1 = loadSample('sounds/music/music1.wav')
local music2 = loadSample('sounds/music/music2.wav')
local music3 = loadSample('sounds/music/music3.wav')

blinds = loadSample('sounds/systems/blinds.wav')
tablesound = loadSample('sounds/systems/table.wav')
tablesound2 = loadSample('sounds/systems/table2.wav')
tablesound3 = loadSample('sounds/systems/table3.wav')
lock = loadSample('sounds/systems/lock.wav')
stop = loadSample('sounds/systems/stop.wav')
stop2 = loadSample('sounds/systems/stop.wav')
emerex = loadSample('sounds/systems/emerex.wav')
emerex2 = loadSample('sounds/systems/emerex.wav')
leather = loadSample('sounds/systems/leather.wav')
elctrdoor = loadSample('sounds/systems/elctrdoor.wav')
elctrdoor2 = loadSample('sounds/systems/elctrdoor.wav')
passwarn = loadSample('sounds/systems/passwarn.wav')
switch1 = loadSample('sounds/systems/switch1.wav')
switch2 = loadSample('sounds/systems/switch2.wav')
slide = loadSample('sounds/systems/slide.wav')
squeak = loadSample('sounds/systems/squeak.wav')
ambient = loadSample('sounds/weather/ambient.wav')
nightamb = loadSample('sounds/weather/nightamb.wav')
ratchet = loadSample('sounds/systems/ratchet.wav')
click = loadSample('sounds/systems/click2.wav')
wind1 = loadSample('sounds/weather/wind1.wav')
rain1 = loadSample('sounds/weather/rain1.wav')
rain2 = loadSample('sounds/weather/rain2.wav')
hd_brake = loadSample('sounds/systems/handbrake_1.wav')
cover = loadSample('sounds/systems/cover.wav')
pull1 = loadSample('sounds/systems/pull1.wav')
tolowflaps = loadSample('sounds/alert/tolowflaps.wav')
tolowgear = loadSample('sounds/alert/tolowgear.wav')
gear = loadSample('sounds/alert/gear.wav')
tolowterrain = loadSample('sounds/alert/tolowterrain.wav')
overspeed = loadSample('sounds/alert/overspeed.wav')
stall = loadSample('sounds/alert/stall.wav')

one_chime = loadSample('sounds/alert/one_chime.wav')
triple_chime = loadSample('sounds/alert/triple_chime.wav')
config = loadSample('sounds/alert/configuration.wav')
cabin_alt_w = loadSample('sounds/alert/cabin_alt.wav')
l_eng_fire = loadSample('sounds/alert/l_eng_fire.wav')
r_eng_fire = loadSample('sounds/alert/r_eng_fire.wav')
apu_fire = loadSample('sounds/alert/apufire.wav')
nbrakes_fail = loadSample('sounds/alert/nbrakes_fail.wav')
land_gear = loadSample('sounds/alert/land_gear.wav')

bank_angl = loadSample('sounds/alert/bank_angl.wav')

pedals = loadSample('sounds/systems/pedals.wav')

click5 = loadSample('sounds/click5.wav')

avionics_inn = loadSample('sounds/systems/avionics_inn.wav')
avionics_inn = loadSample('sounds/systems/avionics_inn.wav')

lock2 = loadSample('sounds/systems/lock2.wav')

local angl = 0
local angl_fn = 0
local alfa = 0
local alphaP = 0
local zeta=0
local distance = 0
local distance_last = 0


local sound_dir = 90
local sdir_gainL = 0
local sdir_gainR = 0

local musgain = 800
local musgain2 = 300
local musgainR = 0
local musgainL = 0

local temp=0
local temp1=0
local t=0
local test1 = 0

local cws_temp = 0
local althold_temp = 0

local n = 1

local flight_time_last = get(flight_time)

av_hide = 0

stopsound = 0

bank_warn = 0

power_on = 0

blinds_last = {get(jalousie1), get(jalousie2), get(jalousie3), get(jalousie4), get(jalousie5), get(jalousie6), get(jalousie7), get(jalousie8), get(jalousie9), get(jalousie10), get(jalousie11), get(jalousie12), get(sunscreen10), get(sunscreen11), get(sunscreen20), get(sunscreen21)}
table_last = {get(table1), get(table2), get(table3), get(table4)}
p_cush_last = {get(p_cush)}
sound_pos = {0, 0, 0}
door_last = {get(door1), get(door2), get(door3), get(door4), get(door5)}
switches_last = {get(belt), get(smoke), get(smokebelts_h), get(gshldl_h), get(pedestal_h), get(gshldr_h), get(cbp_h), get(dome_h), get(cmfd_h), get(cpfd_h), get(pmfd_h), get(ppfd_h), get(annun_h), get(wing_insp_h), get(strobe_h), get(nav_h), get(landlight1h), get(landlight2h), get(xaptaxilighth), get(emeright_h), get(entrlight_h), get(cablight_h), get(crewlit_h), get(left_bat_h), get(right_bat_h), get(l_hpump_h), get(r_hpump_h), get(aux_hpump_h), get(ptu_h), get(bus_tie_h), get(flight_spoil_h), get(ground_sp_h)}

switches_last2 = {get(en_starter_l), get(en_starter_r),get(en_but_run_l), get(en_but_run_r), get(APU_starter_switch), get(bleed_xbleed_h), get(bleed_en_l_h), get(bleed_en_r_h), get(bleed_apu_h), get(jet_sync_mode), get(antice_wngsource_r),get(trim_pusher_cov),get(test_rot),get(cab_ac_cov),get(cab_dc_cov),get(cab_ac_h),get(cab_dc_h),get(dcu_b_cov),get(dcu_a_cov),get(dcu_b_h),get(dcu_a_h)}

switches_last3 = {get(half_bank_h),get(rev_pan_l),get(rev_pan_r),get(rev_tune),get(rev_att_hd),get(rev_air_dat),get(fuel_xpump_l),get(fuel_xpump_r),get(fuel_xflow_dn_h),get(fuel_xflow_up_h),get(nws_h),get(taws_gs_h),get(taws_flp_h),get(taws_ter_h),get(aircond_man_temp_h),get(aircond_ramair_h),get(aircond_airsource),get(aircond_cabin_temp),get(aircond_cockpit_temp), get(parking_brake_ratio)}--

switches_last4 = {get(flight_spoil_cov), get(taws_gs_cov),get(taws_flp_cov), get(taws_ter_cov), get(aircond_ramair_cov), get(pressure_ditch_cov), get(pressure_emer_depr_cov), get(pressure_emer_depr_h), get(pressure_ditch_h), get(pressure_man_h),get(pressure_manrate),get(pressure_lndg_alt_2),get(pressure_lndg_alt_1),get(trim_rud),get(trim_stab),get(trim_pusher_h)}

switches_last5 = {get(antice_wing_h),get(antice_probe_l_h),get(antice_probe_r_h),get(antice_engn_l_h),get(antice_engn_r_h),get(antice_wshld_l_h),get(antice_wshld_r_h),get(electr_apugen_h),get(electr_gen_r_h),get(electr_gen_l_h),get(electr_stbi_h),get(electr_extp_h),get(hydr_altn_flp_h),get(hydr_l_sov_h),get(hydr_r_sov_h),get(hydr_altn_flp_cov),get(hydr_l_sov_cov),get(hydr_r_sov_cov)}

switches_last6 = {get(fire_engn_r_cov),get(fire_engn_l_cov),get(fire_apu_cov),get(fire_ext_2_cov),get(fire_ext_1_cov),get(fire_autoapr_cov),get(fire_engn_r_h),get(fire_engn_l_h),get(fire_apu_h),get(fire_ext_2_h),get(fire_ext_1_h),get(fire_autoapr_h),get(engn_mach_h),get(engn_ign_h),get(oxigen_ox),get(oxigen_terap_cov),get(oxigen_terap_h),get(elt_h),get(stbi_cage_h),get(stby_ins_dim_brt)}

switches_last7 = {get(aud_o2m_l_sw),get(aud_emer_l_sw),get(aud_voice_l_sw),get(comps_slew_l_sw),get(rudd_ped_l_sw),get(aud_o2m_r_sw),get(aud_emer_r_sw),get(aud_voice_r_sw),get(comps_slew_r_sw),get(rudd_ped_r_sw),get(comps_head_l_h),get(comps_head_r_h),get(barometer_setting_in_hg_pilot),get(lg_man),get(pitch_d_1),get(pitch_d_2),get(clock_timer_h),get(clock_gps),get(clock_flt),get(clock_mode)}

switches_last8 = {get(aud_pa_r_h),get(aud_cab_r_h),get(aud_hf2_r_h),get(aud_hf1_r_h),get(aud_com3_r_h),get(aud_com2_r_h),get(aud_com1_r_h),get(aud_pa_l_h),get(aud_cab_l_h),get(aud_hf2_l_h),get(aud_hf1_l_h),get(aud_com3_l_h),get(aud_com2_l_h),get(aud_com1_l_h),get(mfdpan_lr_sw),get(gear_handle_status),get(sbrk_h),get(gust_lock), get(crewlit_h), get(pedals_fwd_bwd_l), get(pedals_fwd_bwd_r), get(crewlit2_h)}

switches_last9 = {get(nav1_obs_deg_mag_pilot),get(heading_dial_deg_mag_pilot),get(airspeed_dial_kts_mach),get(altitude_dial_ft),get(vvi_dial_fpm),cws_temp, get(dcp_tilt), get(dcp_range),get(EFIS_tcas_on),get(EFIS_weather_on),get(dcp_tune1_rot),get(dcp_tune2_rot),get(dcp_menu1_rot),get(dcp_menu2_rot), get(mfd_sel_state_h),get(nav2_obs_deg_mag_pilot),get(dcp_navsrc),get(autop_brgsrc),get(dcp_radar),get(dcp_refs),get(dcp_dmeh),get(dcp_1_2),get(mfd_pan_cas)}

autop_last = {get(half_bank_h), get(autop_fdir_h), get(autop_nav_h), get(autop_hdg_h), get(autop_appr_h), get(autop_bc_h), get(autop_flc_h), get(autop_vs_h), get(autop_vnav_h), get(autop_alt_h), get(autop_ap_h), get(autop_xfr_h), get(autop_yd_h), get(HSI_source_select_pilot)}

mfd_sel_last = {get(mfd_checkl_l),get(mfd_hydr_l),get(mfd_fuel_l),get(mfd_flt_ctr_l),get(mfd_electr_l),get(mfd_ecs_l),get(mfd_antice_l),get(mfd_frmt_l),get(mfd_sumry_l),get(mfd_checkl_r),get(mfd_hydr_r),get(mfd_fuel_r),get(mfd_flt_ctr_r),get(mfd_electr_r),get(mfd_ecs_r),get(mfd_antice_r),get(mfd_frmt_r),get(mfd_sumry_r),get(map_mode)}

warn_caut_last = {1-get(red_cas),1-get(yellow_cas),bank_warn}



































cws_command = findCommand("sim/autopilot/control_wheel_steer")
 function cwscommHandler(phase)
     if 1 == phase then
		cws_temp = 1
		else
		cws_temp = 0
     end
     return 0
 end

 registerCommandHandler(cws_command, 0, cwscommHandler);


aut_altitude_hold = findCommand("sim/autopilot/altitude_hold")
 function aholdcommHandler(phase)
     if 1 == phase then
		althold_temp = 1
		else
		althold_temp = 0
     end
     return 0
 end

 registerCommandHandler(aut_altitude_hold, 0, aholdcommHandler);





warn_butt = findCommand("sim/annunciator/clear_master_warning")
 function warn_buttHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
 end

registerCommandHandler(warn_butt, 1, warn_buttHandler);



caut_butt = findCommand("sim/annunciator/clear_master_caution")
 function caut_buttHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
 end

registerCommandHandler(caut_butt, 1, caut_buttHandler);

dcp_tune_stb = findCommand("xap/DCP/dcp_tune_stb")
function dcptunestbHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
end

registerCommandHandler(dcp_tune_stb, 1, dcptunestbHandler)

dcp_data_sel = findCommand("xap/DCP/dcp_data_sel")
function dcpdataselHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
end

registerCommandHandler(dcp_data_sel, 1, dcpdataselHandler)

chklist_skip = findCommand("sim/custom/xap/chklist_skip")
function chklistskiplHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
end

registerCommandHandler(chklist_skip, 1, chklistskiplHandler)

chklist_enter = findCommand("sim/custom/xap/chklist_enter")
function chklistenterHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
end

registerCommandHandler(chklist_enter, 1, chklistenterHandler)


chklist_jright = findCommand("sim/custom/xap/chklist_jright")
 function chklistjrightHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
 end

 registerCommandHandler(chklist_jright, 1, chklistjrightHandler);

chklist_jleft = findCommand("sim/custom/xap/chklist_jleft")
 function chklistjleftHandler(phase)
     if 0 == phase then
		playSample(click5, 0)
     end
     return 1
 end

 registerCommandHandler(chklist_jleft, 1, chklistjleftHandler);










-- apu generator

apugen_c = findCommand("xap/apugen_button")
 function apugen_cHandler(phase)
     if 0 == phase then
playSample(click, 0)
     end
     return 1
 end
registerCommandHandler(apugen_c, 1, apugen_cHandler);

--
-- left generator

elec_gen_l_c = findCommand("xap/elec_gen_l_button")
 function elec_gen_l_cHandler(phase)
     if 0 == phase then
playSample(click, 0)
     end
     return 1
 end
registerCommandHandler(elec_gen_l_c, 1, elec_gen_l_cHandler);

--
-- right generator

elec_gen_r_c = findCommand("xap/elec_gen_r_button")
 function elec_gen_r_cHandler(phase)
     if 0 == phase then
playSample(click, 0)
     end
     return 1
 end
registerCommandHandler(elec_gen_r_c, 1, elec_gen_r_cHandler);

--
-- bus tie

bus_tie_c = findCommand("xap/bus_tie_h_button")
 function bus_tie_cHandler(phase)
     if 0 == phase then
playSample(click, 0)
     end
     return 1
 end
registerCommandHandler(bus_tie_c, 1, bus_tie_cHandler);

--

-- nose dn pitch

ns_dn_pt = findCommand("sim/autopilot/nose_down_pitch_mode")
 function ns_dn_ptHandler(phase)
     if 1 == phase then
		if isSamplePlaying(ratchet) == false then
		playSample(ratchet, 0)
		end
     end
     return 0
 end
registerCommandHandler(ns_dn_pt, 0, ns_dn_ptHandler);

--
-- nose up pitch

ns_up_pt = findCommand("sim/autopilot/nose_up_pitch_mode")
 function ns_up_ptHandler(phase)
     if 1 == phase then
		if isSamplePlaying(ratchet) == false then
		playSample(ratchet, 0)
		end
     end
     return 0
 end
registerCommandHandler(ns_up_pt, 0, ns_up_ptHandler);














-------------------------------------------------
-------------------------------------------------
function update ()
-------------------------------------------------
-------------------------------------------------

if get(elbus1) >= 10 or get(elbus2) >= 10 then
power_on = 1
else
power_on = 0
end


if get(elbus3) >= 10 or get(elbus1) >= 10 or get(elbus2) >= 10 then
set(poweron_p, 1)
else
set(poweron_p, 0)
end





-- bank warn
if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if get(radio_altimeter_height_ft_pilot) > 50 and get(radio_altimeter_height_ft_pilot) < 150 then
		if math.abs(get(roll_AHARS_deg_pilot)) > 10 + (get(radio_altimeter_height_ft_pilot) - 50)/3.333 then
		bank_warn = 1
		else
		bank_warn = 0
		end
	else
		if get(radio_altimeter_height_ft_pilot) > 150 and get(radio_altimeter_height_ft_pilot) < 1200 then
			if math.abs(get(roll_AHARS_deg_pilot)) > 40 + (get(radio_altimeter_height_ft_pilot) - 150)/80 then
			bank_warn = 1
			else
			bank_warn = 0
			end
		else
			if get(radio_altimeter_height_ft_pilot) > 1200 and get(radio_altimeter_height_ft_pilot) < 2450 then
				if math.abs(get(roll_AHARS_deg_pilot)) > 55 then
				bank_warn = 1
				else
				bank_warn = 0
				end
			else
			bank_warn = 0
			end
		end
	end
else
bank_warn = 0
end






local LOC={0, -2, 0}

local beta=get(view_hdg)
local gamma=get(acf_hdg)

local W=-get(acfpitch)*3.141592/180
local U=-get(acfroll)*3.141592/180
local V=get(acf_hdg)*3.141592/180

--local x1 = get(acfposX) + sound_pos[1]
local x2 = get(viewX)
--local y1 = get(acfposY) + sound_pos[2]
local y2 = get(viewY)
--local z1 = get(acfposZ) + sound_pos[3]
local z2 = get(viewZ)


local x0 = get(acfposX)
local y0 = get(acfposY)
local z0 = get(acfposZ)



music = {music1, music2, music3}

--local sph_r = math.sqrt()



--cs = {math.cos(math.rad(get(acf_roll))),math.cos(math.rad(get(acf_pitch))),math.cos(math.rad(-get(acf_hdg)))}
--sn = {math.sin(math.rad(get(acf_roll))),math.sin(math.rad(get(acf_pitch))),math.sin(math.rad(-get(acf_hdg)))}

SHIFT={LOC[1]*math.cos(U)-LOC[3]*math.sin(U), LOC[2], LOC[3]*math.cos(U)+LOC[1]*math.sin(U)}
LOC=SHIFT
SHIFT={LOC[1], LOC[2]*math.cos(W)-LOC[3]*math.sin(W), LOC[3]*math.cos(W)+LOC[2]*math.sin(W)}
LOC=SHIFT
SHIFT={LOC[1]*math.cos(V)-LOC[2]*math.sin(V), LOC[2]*math.cos(V)+LOC[1]*math.sin(V), LOC[3]}

--t1 = {x0+(x1-x0)*cs[3]+(z1-z0)*sn[3], y1, z0+(x0-x1)*sn[3]+(z1-z0)*cs[3]}
--t2 = {y0, y0+(t1[2]-y0)*cs[2]+(z0-t1[3])*sn[2], z0+(t1[2]-y0)*sn[2]+(t1[3]-z0)*cs[2]}
--t3 = {x0+(t1[1]-x0)*cs[1]+(y0-t2[2])*sn[1], y0+(t1[1]-x0)*sn[1]+(t2[2]-y0)*cs[1], z0}


--t2 = {y0, y0+(y1-y0)*cs[1]+(z0-z1)*sn[1], z0+(y1-y0)*sn[1]+(z1-z0)*cs[1]}

--+(z0-z1)*sn[1], z0+(y1-y0)*sn[1]+(z1-z0)*cs[1]}




--t1 = {x1, ya*cs[1]-z1*sn[1], y1*sn[1]+z1*cs[1]}
--t2 = {t1[1]*cs[2]-t1[3]*sn[2], t1[2], t1[1]*sn[2]+t1[3]*cs[2]}
--t3 = {t2[1]*cs[3]-t2[2]*sn[3], t2[1]*sn[3]+t2[2]*cs[3], t2[3]}

local Ox=get(acfposX)+SHIFT[1]
local Oz=get(acfposZ)+SHIFT[2]
local Oy=get(acfposY)+SHIFT[3]

cam_pos = {x2 - Ox, y2 - Oy, z2 - Oz}
--cam_pos2 = {x2 - get(acfposX), y2 - get(acfposY), z2 - get(acfposZ)}
cam_pos2 = {x2 - Ox, y2 - Oy, z2 - Oz}

headgain = {get(headposx), get(headposy)-1, get(headposz)+2.2192}

musgain = (50*math.exp(-((cam_pos[1])^2 + (cam_pos[2])^2 + (cam_pos[3])^2)/100))

if get(view) == 0 then
musgain2 = (math.exp(-((headgain[1])^2 + (headgain[2])^2 + (headgain[3])^2)/12))
else
musgain2 = (math.exp(-((cam_pos2[1])^2 + (cam_pos2[2])^2 + (cam_pos2[3])^2)/400))
end

distance = math.sqrt(((cam_pos[1])^2 + (cam_pos[2])^2 + (cam_pos[3])^2))


--if x2 > Ox then
 --    if z2 > Oz then
--	    alpha = 90 - math.deg(math.atan(math.abs((z2 - Oz)/(x2-Ox))))
--	 else
--		alpha = 180 -(math.deg(math.atan(math.abs((x2 - Ox)/(z2-Oz)))))
--	 end
--	else
--	 if z2 < Oz then
--		alpha = 180 +(math.deg(math.atan(math.abs((x2 - Ox)/(z2-Oz)))))
--	 else
--		alpha = 270 + (math.deg(math.atan(math.abs((z2 - Oz)/(x2-Ox)))))
--	 end
--end



musgainL = musgain
musgainR = musgain

if get(view) == 1 then
	if (Ox-x2)<0 then
		alpha = 180/3.141592*math.atan((Oz-z2)/(Ox-x2))+270
	else
		alpha = 180/3.141592*math.atan((Oz-z2)/(Ox-x2))+90
	end
	else
	if (Ox-x2)<0 then
		alpha = 180/3.141592*math.atan((Oz-z2)/(Ox-x2))+270
	else
		alpha = 180/3.141592*math.atan((Oz-z2)/(Ox-x2))+90
	end
end



--if get(view) == 1 then
if alfa + get(view_hdg) < 360 then
angl_fn = alfa  else
angl_fn = alfa  + 360
end
--+ get(view_hdg)
--+ get(view_hdg)
--else
--if alfa + get(cock_view_hdg) < 360 then
--angl_fn = alfa + get(cock_view_hdg) else
--angl_fn = alfa + get(cock_view_hdg) - 360
--end
--end

	--if x2 > Ox then
--     if y2 > Oy then
--	    alfa = 90 - math.deg(math.atan(math.abs((z2 - Oz)/(x2-Ox))))
--	 else
--		alfa = 180 -(math.deg(math.atan(math.abs((x2 - Ox)/(z2-Oz)))))
--	 end
--	else
--	 if y2 < Oy then
--		alfa = 180 +(math.deg(math.atan(math.abs((x2 - Ox)/(z2-Oz)))))
--	 else
--		alfa = 270 + (math.deg(math.atan(math.abs((z2 - Oz)/(x2-Ox)))))
--	 end
--end



if get(view) == 1 then
	if beta>alpha then
		temp=(beta-alpha)/180-1
	else
		temp=-(alpha-beta)/180+1
	end
	else
	if beta>alpha then
		temp=(beta-alpha+get(cock_view_hdg))/180-1
	else
		temp=-(alpha-beta-get(cock_view_hdg))/180+1
	end
end




	if temp>0.5 then t=1-temp
	elseif temp<-0.5 then t=-temp-1
	else t=temp
	end

--if angl_fn > 0 and angl_fn < 90 then
--	musgainR = musgain - 0.9*musgain*(angl_fn/90)
--		elseif angl_fn > 90 and angl_fn < 180 then musgainR = musgain - 0.9*musgain*((180 - angl_fn)/90)
--			else
--	if angl_fn > 180 and angl_fn < 270 then
--		musgainL = musgain - 0.9*musgain*((angl_fn-180)/90)
--		elseif angl_fn > 270 and angl_fn < 360 then musgainL = musgain - 0.9*musgain*((360 - angl_fn)/90)
--	end
--end
--musgainL = musgain
--musgainR = musgain
--

sdir_gainL = get(acf_hdg)
--[=[
setSamplePitch(music_r, 1000+(distance_last-distance)*20)
setSamplePitch(music_l, 1000+(distance_last-distance)*20)

setSampleGain(music_r, musgain*(1+2*t))
setSampleGain(music_l, musgain*(1-2*t))

setSampleGain(music_r, 0)
setSampleGain(music_l, 0)


if isSamplePlaying(music_l) == false and isSamplePlaying(music_r) == false then
playSample(music_l, 1)
playSample(music_r, 1)
end
--]=]








setSampleGain(blinds, 80*get(mastervol)*(1-get(view)))

setSamplePitch(blinds, 5000)

if blinds_last[1] - get(jalousie1) ~= 0 or blinds_last[2] - get(jalousie2) ~= 0 or blinds_last[3] - get(jalousie3) ~= 0  or blinds_last[4] - get(jalousie4) ~= 0  or blinds_last[5] - get(jalousie5) ~= 0  or blinds_last[6] - get(jalousie6) ~= 0  or blinds_last[7] - get(jalousie7) ~= 0 or blinds_last[8] - get(jalousie8) ~= 0 or blinds_last[9] - get(jalousie9) ~= 0  or blinds_last[10] - get(jalousie10) ~= 0 or blinds_last[11] - get(jalousie11) ~= 0 or blinds_last[12] - get(jalousie12) ~= 0 or p_cush_last[1] - get(p_cush) ~= 0 and get(view) == 0 then
if isSamplePlaying(blinds) == false then
playSample(blinds, 1)
end
else
stopSample(blinds, 1)
end


-- gains and pitches

if  get(view) == 0 then
  setSampleGain(elctrdoor, 600*get(mastervol)*stopsound)
  setSamplePitch(elctrdoor, 1300)
  setSampleGain(elctrdoor2, 200*get(mastervol)*stopsound)
  setSamplePitch(elctrdoor2, 1400)

  setSampleGain(emerex, 500*get(mastervol)*stopsound)
  setSamplePitch(emerex, 1800)

  setSampleGain(emerex2, 500*get(mastervol)*stopsound)
  setSamplePitch(emerex2, 1500)

  setSampleGain(stop, 1000*get(mastervol)*stopsound)
  setSamplePitch(stop, 1000)

  setSampleGain(passwarn, 1000*get(mastervol)*stopsound*musgain2)
  setSamplePitch(passwarn, 1100)

  setSampleGain(music1, 200*musgain2*get(mastervol)*stopsound)
  setSampleGain(music2, 200*musgain2*get(mastervol)*stopsound)
  setSampleGain(music3, 200*musgain2*get(mastervol)*stopsound)

  setSampleGain(switch1, 300*get(mastervol)*stopsound)

  setSampleGain(switch2, 200*get(mastervol)*stopsound)
  setSamplePitch(switch2, 2300)

  setSampleGain(click, 200*get(mastervol)*stopsound)
  setSamplePitch(click, 1800)

  setSampleGain(slide, 20*get(mastervol)*stopsound)
  setSamplePitch(slide, 3800)

  setSampleGain(squeak, 40*get(mastervol)*stopsound)
  setSamplePitch(squeak, 1700)

  setSampleGain(ratchet, 200*get(mastervol)*stopsound)
  setSamplePitch(ratchet, 1500)
if get(temp_out) > -10 and  get(temp_out) < 40 then
  setSampleGain(ambient,  1*(10-get(groundspeed))*get(mastervol)*stopsound*(1-(get(night_lights)*get(night_lights)*get(night_lights)))*((0.2/(get(rain_p)+0.17))-0.17)*((0.2/((get(windspeed)/20)+0.17))-0.17)*((get(door4)+get(door3))))
  setSampleGain(nightamb,  1*(10-get(groundspeed))*get(mastervol)*stopsound*(get(night_lights))*(get(night_lights))*((0.2/(get(rain_p)+0.17))-0.17)*((0.2/((get(windspeed)/20)+0.17))-0.17)*((get(door4)+get(door3))))
else
setSampleGain(ambient, 0)
setSampleGain(nightamb, 0)
end
  setSampleGain(wind1,  100*get(mastervol)*stopsound*(get(windspeed)/50)*((get(door4)+get(door3))))
  setSamplePitch(wind1, 1700)
if get(temp_out) > 0 then
  setSampleGain(rain2, 30*get(mastervol)*stopsound*get(rain_p))
  setSampleGain(rain1,  100*get(mastervol)*stopsound*get(rain_p)*((get(door4)+get(door3))))
  else
  setSampleGain(rain1, 0)
  setSampleGain(rain2, 0)
  end
  setSamplePitch(rain1, 700)
 setSamplePitch(rain2, 700)

  else

  setSampleGain(elctrdoor, 400*musgain2*get(mastervol)*stopsound)
  setSamplePitch(elctrdoor, 1600)

  setSampleGain(elctrdoor2, 300*musgain2*get(mastervol)*stopsound)
  setSamplePitch(elctrdoor2, 1700)

  setSampleGain(emerex, 300*musgain2*get(mastervol)*stopsound)
  setSamplePitch(emerex, 1800)

  setSampleGain(emerex2, 300*musgain2*get(mastervol)*stopsound)
  setSamplePitch(emerex2, 1500)

  setSampleGain(stop, 300*get(mastervol)*stopsound)
  setSamplePitch(stop, 1300)

  setSampleGain(passwarn, 0)
  setSamplePitch(passwarn, 1200)

  setSampleGain(music1, 20*(math.exp(-((cam_pos2[1])^2 + (cam_pos2[2])^2 + (cam_pos2[3])^2)/300))*get(mastervol)*stopsound*get(door3))
  setSampleGain(music2, 20*(math.exp(-((cam_pos2[1])^2 + (cam_pos2[2])^2 + (cam_pos2[3])^2)/300))*get(mastervol)*stopsound*get(door3))
  setSampleGain(music3, 20*(math.exp(-((cam_pos2[1])^2 + (cam_pos2[2])^2 + (cam_pos2[3])^2)/300))*get(mastervol)*stopsound*get(door3))

  setSampleGain(switch1, 0)
  setSampleGain(switch2, 0)

  setSampleGain(slide, 0)

  setSampleGain(squeak, 0)

  setSampleGain(ratchet, 0)

if get(temp_out) > -10 and  get(temp_out) < 40 then
  setSampleGain(ambient, 7*(10-get(groundspeed))*get(mastervol)*stopsound*(1-(get(night_lights)*get(night_lights)*get(night_lights)))*((0.2/(get(rain_p)+0.17))-0.17)*((0.2/((get(windspeed)/20)+0.17))-0.17) )
  setSampleGain(nightamb, 10*(10-get(groundspeed))*get(mastervol)*stopsound*(get(night_lights))*(get(night_lights))*((0.2/(get(rain_p)+0.17))-0.17)*((0.2/((get(windspeed)/20)+0.17))-0.17) )
else
setSampleGain(ambient, 0)
setSampleGain(nightamb, 0)
end

  setSampleGain(wind1,  700*get(mastervol)*stopsound*(get(windspeed)/50))
  setSamplePitch(wind1, 1000)
if get(temp_out) > 0 then
  setSampleGain(rain1,  700*get(mastervol)*stopsound*get(rain_p))
   setSampleGain(rain2,  70*get(mastervol)*stopsound*get(rain_p)*musgain2)
  else
  setSampleGain(rain1, 0)
    setSampleGain(rain2, 0)
  end
  setSamplePitch(rain1, 1000)
  setSamplePitch(rain2, 1000)
  setSampleGain(click, 0)


end


setSampleGain(tablesound, 900*get(mastervol)*stopsound*(1-get(view)))
setSamplePitch(tablesound, 1300)


setSampleGain(tablesound2, 200*get(mastervol)*stopsound*(1-get(view)))
setSamplePitch(tablesound2, 1200)

setSampleGain(tablesound3, 500*get(mastervol)*stopsound*(1-get(view)))
setSamplePitch(tablesound3, 1000)


-- ambient
if isSamplePlaying(ambient) == false then
if get(view) == 0 and get(onground_all) == 1 and get(groundspeed) <= 10  then
playSample(ambient, 1)
else
stopSample(ambient)
end
end

if isSamplePlaying(nightamb) == false then
if get(view) == 0 and get(onground_all) == 1 and get(groundspeed) <= 10  then
playSample(nightamb, 1)
else
stopSample(nightamb)
end
end

if isSamplePlaying(wind1) == false then
if get(view) == 0 then
playSample(wind1, 1)
else
stopSample(wind1)
end
end

if isSamplePlaying(rain1) == false then
if get(view) == 0 then
playSample(rain1, 1)
else
stopSample(rain1)
end
end

if isSamplePlaying(rain2) == false then
if get(view) == 0 then
playSample(rain2, 1)
else
stopSample(rain2)
end
end



--gust lock
setSampleGain(lock2, 50*get(mastervol)*stopsound*(1-get(view)))
setSamplePitch(lock2, 1600)
if switches_last8[18] - get(gust_lock) ~= 0  then
    if isSamplePlaying(lock2) == false then
		if get(gust_lock) == 0 or get(gust_lock) == 1 then
		   playSample(lock2, 0)
		end
	end
end



--sunscreens



if blinds_last[13] - get(sunscreen10) ~= 0 or blinds_last[15] - get(sunscreen20) ~= 0 or switches_last8[17] - get(sbrk_h) ~= 0 and get(view) == 0 and get(flight_time) > 2 then--
    if isSamplePlaying(slide) == false then
       playSample(slide, 1)
	   end
	else
	stopSample(slide)
end


if blinds_last[14] - get(sunscreen11) ~= 0 or blinds_last[16] - get(sunscreen21) ~= 0 and get(view) == 0 and get(flight_time) > 2 then
    if isSamplePlaying(squeak) == false then
       playSample(squeak, 1)
	   end
	else
	stopSample(squeak)
end




--//Tables

if table_last[1] - get(table1) ~=0 or table_last[2] - get(table2) ~=0 or table_last[3] - get(table3) ~=0 or table_last[4] - get(table4) ~=0 or door_last[1] - get(door1) ~=0 or door_last[2] - get(door2) ~=0 and get(view) == 0 and get(flight_time) > 2 then

if isSamplePlaying(tablesound) == false then
playSample(tablesound, 1)
end
else
stopSample(tablesound, 1)
end




--//

if get(view) == 0 and get(table1) == 0 and isSamplePlaying(tablesound2) == false and table_last[1] - get(table1) ~=0 and get(flight_time) > 2 then
 playSample(tablesound2, 0)
end

if get(view) == 0 and get(table2) == 0 and isSamplePlaying(tablesound2) == false and table_last[2] - get(table2) ~=0 and get(flight_time) > 2 then
 playSample(tablesound2, 0)
end

if get(view) == 0 and get(table3) == 0 and isSamplePlaying(tablesound2) == false and table_last[3] - get(table3) ~=0 and get(flight_time) > 2 then
 playSample(tablesound2, 0)
end

if get(view) == 0 and get(table4) == 0 and isSamplePlaying(tablesound2) == false and table_last[4] - get(table4) ~=0 and get(flight_time) > 2 then
 playSample(tablesound2, 0)
end

--//

if get(view) == 0 and get(table1) > 0.745 and get(table1) < 0.76 and isSamplePlaying(tablesound3) == false and table_last[1] - get(table1) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table2) > 0.745 and get(table2) < 0.76 and isSamplePlaying(tablesound3) == false and table_last[2] - get(table2) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table3) > 0.745 and get(table3) < 0.76 and isSamplePlaying(tablesound3) == false and table_last[3] - get(table3) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table4) > 0.745 and get(table4) < 0.76 and isSamplePlaying(tablesound3) == false and table_last[4] - get(table4) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

--//

if get(view) == 0 and get(table1) == 1 and isSamplePlaying(tablesound3) == false and table_last[1] - get(table1) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table2) == 1 and isSamplePlaying(tablesound3) == false and table_last[2] - get(table2) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table3) == 1 and isSamplePlaying(tablesound3) == false and table_last[3] - get(table3) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

if get(view) == 0 and get(table4) == 1 and isSamplePlaying(tablesound3) == false and table_last[4] - get(table4) ~=0 and get(flight_time) > 2 then
 playSample(tablesound3, 0)
end

--//

--interrior doors


if get(view) == 0 and get(door1) > 0 and get(door1) < 0.1 and isSamplePlaying(lock) == false and door_last[1] - get(door1) ~=0 and get(flight_time) > 4 then
setSampleGain(lock, 100*get(mastervol)*stopsound)
setSamplePitch(lock, 1300)
 playSample(lock, 0)
end



if get(view) == 0 and get(door2) > 0 and get(door2) < 0.1 and isSamplePlaying(lock) == false and door_last[2] - get(door2) ~=0 and get(flight_time) > 4 then

setSampleGain(lock, 100*get(mastervol)*stopsound)
setSamplePitch(lock, 900)

setSampleGain(tablesound, 600*get(mastervol)*stopsound)
setSamplePitch(tablesound, 1000)


 playSample(lock, 0)
end

--

if get(view) == 0 and get(door1) == 1 and isSamplePlaying(stop2) == false and door_last[1] - get(door1) ~=0 and get(flight_time) > 4 then
setSampleGain(stop2, 1000*get(mastervol)*stopsound)
setSamplePitch(stop2, 900)
 playSample(stop2, 0)
end



if get(view) == 0 and get(door2) == 1 and isSamplePlaying(stop2) == false and door_last[2] - get(door2) ~=0 and get(flight_time) > 4 then

setSampleGain(stop2, 800*get(mastervol)*stopsound)
setSamplePitch(stop2, 900)
 playSample(stop2, 0)
end



if get(view) == 0 and get(door1) == 0 and isSamplePlaying(stop2) == false and door_last[1] - get(door1) ~=0 and get(flight_time) > 4 then
setSampleGain(stop2, 1000*get(mastervol)*stopsound)
setSamplePitch(stop2, 900)
 playSample(stop2, 0)
end



if get(view) == 0 and get(door2) == 0 and isSamplePlaying(stop2) == false and door_last[2] - get(door2) ~=0 and get(flight_time) > 4 then

setSampleGain(stop2, 800*get(mastervol)*stopsound)
setSamplePitch(stop2, 900)
 playSample(stop2, 0)
end


--//

--emer door




if get(door4) > 0.1 and get(door4) < 0.2 and isSamplePlaying(emerex2) == false and door_last[4] - get(door4) ~=0 and get(flight_time) > 2 then
 playSample(emerex2, 0)
end
if get(view) == 0 and get(door4) >= 0.8 and isSamplePlaying(leather) == false and door_last[4] - get(door4) ~=0 and get(flight_time) > 2 then
setSampleGain(leather, 80*get(mastervol)*stopsound)
setSamplePitch(leather, 1000)
 playSample(leather, 0)
end

--//
--main door




if door_last[3] - get(door3) ~=0  and get(door3) < 1 and get(door3) > 0 and get(flight_time) > 2 then

if isSamplePlaying(elctrdoor) == false then
playSample(elctrdoor, 0)
end
else
stopSample(elctrdoor)
end


if get(door3) >= 0 and get(door3) < 0.03 and isSamplePlaying(emerex) == false and door_last[3] - get(door3) ~=0 and get(door3) < 1 and get(door3) > 0 and get(flight_time) > 2 then
 playSample(emerex, 0)
end
if get(door3) <= 1 and get(door3) > 0.97 and isSamplePlaying(emerex) == false and door_last[3] - get(door3) ~=0 and get(door3) < 1 and get(door3) > 0 and get(flight_time) > 2 then
 playSample(emerex, 0)
end


--baggage door

if door_last[5] - get(door5) ~=0 and get(flight_time) > 2 then
	if isSamplePlaying(elctrdoor2) == false then
		playSample(elctrdoor2, 1)
	end
else
	stopSample(elctrdoor2)
end

if get(door5) >= 0 and get(door5) <= 0.3 and get(flight_time) > 2 then
stopSample(elctrdoor2)
end


if get(door5) >= 0 and get(door5) < 0.03 and isSamplePlaying(emerex) == false and door_last[5] - get(door5) ~=0 and get(flight_time) > 2 then
 playSample(emerex, 0)
end

if get(door5) == 1 and isSamplePlaying(emerex) == false and door_last[5] - get(door5) ~=0 and get(flight_time) > 2 then
 playSample(stop, 0)
end


--//

--//






if get(elbus1) >= 10 and get(mplayer) == 1 then
set(disp_music_r, get(pulse))
   if isSamplePlaying(music[1]) == false and isSamplePlaying(music[2]) == false and isSamplePlaying(music[3]) == false then
 playSample(music[n], 0)
 n = n + 1
   end
 else
 set(disp_music_r, 0)
 stopSample(music[1])
 stopSample(music[2])
 stopSample(music[3])
end

if n > 3 then
n = 1
end


--// Smokebelt
if get(elbus1) >= 10 and isSamplePlaying(passwarn) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last[1] - get(belt) ~= 0 or switches_last[2] - get(smoke) ~= 0 then
playSample(passwarn, 0)
end
end

--// parking brake
if isSamplePlaying(passwarn) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last3[20] - get(parking_brake_ratio) ~= 0 and get(parking_brake_ratio) == 1 then
setSampleGain(hd_brake, 400*get(mastervol)*stopsound)
playSample(hd_brake, 0)
end
end

if isSamplePlaying(passwarn) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last3[20] - get(parking_brake_ratio) ~= 0 and get(parking_brake_ratio) == 0 then
setSampleGain(stop2, 800*get(mastervol)*stopsound)
playSample(stop2, 0)
end
end



--//switches and buttons

-- pedals
if isSamplePlaying(pedals) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last8[20] - get(pedals_fwd_bwd_l) ~= 0 or switches_last8[21] - get(pedals_fwd_bwd_r) ~= 0 then--
setSampleGain(pedals, 60*get(mastervol)*stopsound)
setSamplePitch(pedals, 1000)
playSample(pedals, 1)
end
end

if switches_last8[20] - get(pedals_fwd_bwd_l) == 0 and switches_last8[21] - get(pedals_fwd_bwd_r) == 0 then stopSample(pedals) end

-- handles pull
if isSamplePlaying(pull1) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last7[14] - get(get(lg_man)) ~= 0 or switches_last8[16] - get(gear_handle_status) ~= 0 then--
setSampleGain(pull1, 400*get(mastervol)*stopsound)
setSamplePitch(pull1, 1200)
playSample(pull1, 0)
end
end

if isSamplePlaying(pull1) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last7[15] - get(pitch_d_1) ~= 0 then--
setSampleGain(pull1, 400*get(mastervol)*stopsound)
setSamplePitch(pull1, 1500)
playSample(pull1, 0)
end
end

if isSamplePlaying(pull1) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last7[16] - get(pitch_d_2) ~= 0 then--
setSampleGain(pull1, 300*get(mastervol)*stopsound)
setSamplePitch(pull1, 2400)
playSample(pull1, 0)
end
end


--// covers
if isSamplePlaying(cover) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last4[1] - get(flight_spoil_cov) ~= 0 or switches_last4[2] - get(taws_gs_cov) ~= 0 or switches_last4[3] - get(taws_flp_cov) ~= 0 or switches_last4[4] - get(taws_ter_cov) ~= 0 or switches_last4[5] - get(aircond_ramair_cov) ~= 0 or switches_last4[6] - get(pressure_ditch_cov) ~= 0 or switches_last4[7] - get(pressure_emer_depr_cov) ~= 0 or switches_last5[16] - get(hydr_altn_flp_cov) ~= 0 or switches_last5[17] - get(hydr_l_sov_cov) ~= 0 or switches_last5[18] - get(hydr_r_sov_cov) ~= 0 or switches_last2[12] - get(trim_pusher_cov) ~= 0 or switches_last6[1] - get(fire_engn_r_cov) ~= 0 or switches_last6[2] - get(fire_engn_l_cov) ~= 0 or switches_last6[3] - get(fire_apu_cov) ~= 0 or switches_last6[4] - get(fire_ext_2_cov) ~= 0 or switches_last6[5] - get(fire_ext_1_cov) ~= 0 or switches_last6[6] - get(fire_autoapr_cov) ~= 0 or switches_last6[16] - get(oxigen_terap_cov) ~= 0 or switches_last2[14] - get(cab_ac_cov) ~= 0 or switches_last2[15] - get(cab_dc_cov) ~= 0 or switches_last2[18] - get(dcu_b_cov) ~= 0 or switches_last2[19] - get(dcu_a_cov) ~= 0 then--
setSampleGain(cover, 100*get(mastervol)*stopsound)
setSamplePitch(cover, 1400)
playSample(cover, 0)
end
end



--buttons
if isSamplePlaying(click) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last[21] - get(entrlight_h) ~= 0 or switches_last[22] - get(cablight_h) ~= 0 or switches_last[24] - get(left_bat_h) ~= 0 or switches_last[25] - get(right_bat_h) ~= 0 or switches_last[31] - get(flight_spoil_h) ~= 0 or switches_last2[6] - get(bleed_xbleed_h) ~= 0 or switches_last2[7] - get(bleed_en_l_h) ~= 0 or switches_last2[8] - get(bleed_en_r_h) ~= 0 or switches_last2[9] - get(bleed_apu_h) ~= 0 or switches_last3[9] - get(fuel_xflow_dn_h) ~= 0 or switches_last3[10] - get(fuel_xflow_up_h) ~= 0 or switches_last3[11] - get(nws_h) ~= 0 or switches_last3[12] - get(taws_gs_h) ~= 0 or switches_last3[13] - get(taws_flp_h) ~= 0 or switches_last3[14] - get(taws_ter_h) ~= 0 or switches_last3[15] - get(aircond_man_temp_h) ~= 0 or switches_last3[16] - get(aircond_ramair_h) ~= 0 or switches_last4[8] - get(pressure_emer_depr_h) ~= 0 or switches_last4[9] - get(pressure_ditch_h) ~= 0 or switches_last4[10] - get(pressure_man_h) ~= 0 or switches_last5[1] - get(antice_wing_h) ~= 0 or switches_last5[2] - get(antice_probe_l_h) ~= 0 or switches_last5[3] - get(antice_probe_r_h) ~= 0 or switches_last5[4] - get(antice_engn_l_h) ~= 0 or switches_last5[5] - get(antice_engn_r_h) ~= 0 or switches_last5[6] - get(antice_wshld_l_h) ~= 0 or switches_last5[7] - get(antice_wshld_r_h) ~= 0 or switches_last5[11] - get(electr_stbi_h) ~= 0 or switches_last5[12] - get(electr_extp_h) ~= 0 or switches_last5[13] - get(hydr_altn_flp_h) ~= 0 or switches_last5[14] - get(hydr_l_sov_h) ~= 0 or switches_last5[15] - get(hydr_r_sov_h) ~= 0 or switches_last4[16] - get(trim_pusher_h) ~= 0 or switches_last6[7] - get(fire_engn_r_h) ~= 0 or switches_last6[8] - get(fire_engn_l_h) ~= 0 or switches_last6[9] - get(fire_apu_h) ~= 0 or switches_last6[10] - get(fire_ext_2_h) ~= 0 or switches_last6[11] - get(fire_ext_1_h) ~= 0 or switches_last6[12] - get(fire_autoapr_h) ~= 0 or switches_last6[13] - get(engn_mach_h) ~= 0 or switches_last6[14] - get(engn_ign_h) ~= 0 or switches_last6[17] - get(oxigen_terap_h) ~= 0 or switches_last2[16] - get(cab_ac_h) ~= 0 or switches_last2[17] - get(cab_dc_h) ~= 0 or switches_last2[20] - get(dcu_b_h) ~= 0 or switches_last2[21] - get(dcu_a_h) ~= 0 or switches_last7[11] - get(comps_head_l_h) ~= 0 or switches_last7[12] - get(comps_head_r_h) ~= 0 or switches_last8[1] - get(aud_pa_r_h) ~= 0 or switches_last8[2] - get(aud_cab_r_h) ~= 0 or switches_last8[3] - get(aud_hf2_r_h) ~= 0 or switches_last8[4] - get(aud_hf1_r_h) ~= 0 or switches_last8[5] - get(aud_com3_r_h) ~= 0 or switches_last8[6] - get(aud_com2_r_h) ~= 0 or switches_last8[7] - get(aud_com1_r_h) ~= 0 or switches_last8[8] - get(aud_pa_l_h) ~= 0 or switches_last8[9] - get(aud_cab_l_h) ~= 0 or switches_last8[10] - get(aud_hf2_l_h) ~= 0 or switches_last8[11] - get(aud_hf1_l_h) ~= 0 or switches_last8[12] - get(aud_com3_l_h) ~= 0 or switches_last8[13] - get(aud_com2_l_h) ~= 0 or switches_last8[14] - get(aud_com1_l_h) ~= 0 then--,,,,,,,,,,,,,
playSample(click, 0)
end
end



-- soft buttons
if isSamplePlaying(click) == false and get(flight_time) > 2 and get(view) == 0 then--,,
if switches_last6[19] - get(stbi_cage_h) ~= 0 or switches_last6[20] - get(stby_ins_dim_brt) ~= 0 or switches_last7[17] - get(clock_timer_h) ~= 0 or switches_last7[18] - get(clock_gps) ~= 0 or switches_last7[19] - get(clock_flt) ~= 0 or switches_last7[20] - get(clock_mode) ~= 0 or autop_last[1] - get(half_bank_h) ~= 0 or autop_last[2] - get(autop_fdir_h) ~= 0 or autop_last[3] - get(autop_nav_h) ~= 0 or autop_last[4] - get(autop_hdg_h) ~= 0 or autop_last[5] - get(autop_appr_h) ~= 0 or autop_last[6] - get(autop_bc_h) ~= 0 or autop_last[7] - get(autop_flc_h) ~= 0 or autop_last[8] - get(autop_vs_h) ~= 0 or autop_last[9] - get(autop_vnav_h) ~= 0 or autop_last[10] - get(autop_alt_h) ~= 0 or autop_last[11] - get(autop_ap_h) ~= 0 or autop_last[12] - get(autop_xfr_h) ~= 0 or autop_last[13] - get(autop_yd_h) ~= 0 or mfd_sel_last[1] - get(mfd_checkl_l) ~= 0 or mfd_sel_last[2] - get(mfd_hydr_l) ~= 0 or mfd_sel_last[3] - get(mfd_fuel_l) ~= 0 or mfd_sel_last[4] - get(mfd_flt_ctr_l) ~= 0 or mfd_sel_last[5] - get(mfd_electr_l) ~= 0 or mfd_sel_last[6] - get(mfd_ecs_l) ~= 0 or mfd_sel_last[7] - get(mfd_antice_l) ~= 0 or mfd_sel_last[8] - get(mfd_frmt_l) ~= 0 or mfd_sel_last[9] - get(mfd_sumry_l) ~= 0 or mfd_sel_last[10] - get(mfd_checkl_r) ~= 0 or mfd_sel_last[11] - get(mfd_hydr_r) ~= 0 or mfd_sel_last[12] - get(mfd_fuel_r) ~= 0 or mfd_sel_last[13] - get(mfd_flt_ctr_r) ~= 0 or mfd_sel_last[14] - get(mfd_electr_r) ~= 0 or mfd_sel_last[15] - get(mfd_ecs_r) ~= 0 or mfd_sel_last[16] - get(mfd_antice_r) ~= 0 or mfd_sel_last[17] - get(mfd_frmt_r) ~= 0 or mfd_sel_last[18] - get(mfd_sumry_r) ~= 0 or mfd_sel_last[19] - get(map_mode) ~= 0 or switches_last9[9] - get(EFIS_tcas_on) ~= 0 or switches_last9[10] - get(EFIS_weather_on) ~= 0 or switches_last9[15] - get(mfd_sel_state_h) ~= 0 or switches_last9[19] - get(dcp_radar) ~= 0 or switches_last9[21] - get(dcp_dmeh) ~= 0 or switches_last9[22] - get(dcp_1_2) ~= 0 or switches_last9[23] - get(mfd_pan_cas) ~= 0 then --,,,,
setSampleGain(click5, 1300*get(mastervol)*stopsound)
playSample(click5, 0)
end
	if switches_last9[17] - get(dcp_navsrc) ~= 0 and get(dcp_navsrc) >= 0 then
	setSampleGain(click5, 1300*get(mastervol)*stopsound)
	playSample(click5, 0)
	end
	if switches_last9[18] - get(autop_brgsrc) ~= 0 and get(dcp_navsrc) >= 0 then
	setSampleGain(click5, 1300*get(mastervol)*stopsound)
	playSample(click5, 0)
	end
	if switches_last9[20] - get(dcp_refs) ~= 0 and get(dcp_refs) >= 0 then
	setSampleGain(click5, 1300*get(mastervol)*stopsound)
	playSample(click5, 0)
	end
end

--switches
if isSamplePlaying(switch1) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last[3] - get(smokebelts_h) ~= 0 or switches_last[14] - get(wing_insp_h) ~=0 or switches_last[15] - get(strobe_h) ~=0 or switches_last[16] - get(nav_h) ~=0 or switches_last[17] - get(landlight1h) ~= 0 or switches_last[18] - get(landlight2h) ~= 0 or switches_last[19] - get(xaptaxilighth) ~= 0 or switches_last[20] - get(emeright_h) ~= 0 or switches_last2[3] - get(en_but_run_l) ~= 0 or switches_last2[4] - get(en_but_run_r) ~= 0 or switches_last6[18] - get(elt_h) ~= 0 or switches_last7[1] - get(aud_o2m_l_sw) ~= 0 or switches_last7[2] - get(aud_emer_l_sw) ~= 0 or switches_last7[3] - get(aud_voice_l_sw) ~= 0 or switches_last7[4] - get(comps_slew_l_sw) ~= 0 or switches_last7[5] - get(rudd_ped_l_sw) ~= 0 or switches_last7[6] - get(aud_o2m_r_sw) ~= 0 or switches_last7[7] - get(aud_emer_r_sw) ~= 0 or switches_last7[8] - get(aud_voice_r_sw) ~= 0 or switches_last7[9] - get(comps_slew_r_sw) ~= 0 or switches_last7[10] - get(rudd_ped_r_sw) ~= 0 or switches_last8[15] - get(mfdpan_lr_sw) ~= 0 then--
playSample(switch1, 0)
end
end

-- ratchets
if isSamplePlaying(ratchet) == false and get(flight_time) > 2 and get(view) == 0 then--,
	if switches_last9[5] - get(vvi_dial_fpm) ~= 0 or switches_last9[2] - get(heading_dial_deg_mag_pilot) ~= 0 or switches_last9[3] - get(airspeed_dial_kts_mach) ~= 0 or switches_last[4] - get(gshldl_h) ~= 0 or switches_last[5] - get(pedestal_h) ~= 0 or switches_last[6] - get(gshldr_h) ~= 0 or switches_last[7] - get(cbp_h) ~= 0 or switches_last[8] - get(dome_h) ~= 0 or switches_last[9] - get(cmfd_h) ~= 0 or switches_last[10] - get(cpfd_h) ~= 0 or switches_last[11] - get(pmfd_h) ~= 0 or switches_last[12] - get(ppfd_h) ~= 0 or switches_last3[18] - get(aircond_cabin_temp) ~= 0 or switches_last3[19] - get(aircond_cockpit_temp) ~= 0 or switches_last4[11] - get(pressure_manrate) ~= 0 or switches_last4[12] - get(pressure_lndg_alt_2) ~= 0 or switches_last4[14] - get(trim_rud) ~= 0 or switches_last7[13] - get(barometer_setting_in_hg_pilot) ~= 0 or switches_last9[7] - get(dcp_tilt) ~= 0 or switches_last9[8] - get(dcp_range) ~= 0 or switches_last9[11] - get(dcp_tune1_rot) ~= 0 or switches_last9[12] - get(dcp_tune2_rot) ~= 0 or switches_last9[13] - get(dcp_menu1_rot) ~= 0 or switches_last9[14] - get(dcp_menu2_rot) ~= 0 then--,,,,
	playSample(ratchet, 0)
	end
	if autop_last[14] - get(HSI_source_select_pilot) == 0 and switches_last9[1] - get(nav1_obs_deg_mag_pilot) ~= 0  then--
	playSample(ratchet, 0)
	end

	if autop_last[14] - get(HSI_source_select_pilot) == 0 and switches_last9[16] - get(nav2_obs_deg_mag_pilot) ~= 0  then--
	playSample(ratchet, 0)
	end

	 if althold_temp == 0 and cws_temp == 0 and switches_last9[4] - get(altitude_dial_ft) ~= 0 then
	playSample(ratchet, 0)
	end

end



-- rotary
if isSamplePlaying(switch2) == false and get(flight_time) > 2 and get(view) == 0 then
if switches_last[13] - get(annun_h) ~= 0 or switches_last[23] - get(crewlit_h) ~= 0 or switches_last8[22] - get(crewlit2_h) ~= 0 or switches_last[26] - get(l_hpump_h) ~= 0 or switches_last[27] - get(r_hpump_h) ~= 0 or switches_last[28] - get(aux_hpump_h) ~= 0 or switches_last[29] - get(ptu_h) ~= 0 or switches_last[32] - get(ground_sp_h) ~= 0 or switches_last2[1] - get(en_starter_l) ~= 0 or switches_last2[2] - get(en_starter_r) ~= 0 or switches_last2[5] - get(APU_starter_switch) ~= 0 or switches_last2[10] - get(jet_sync_mode) ~= 0 or switches_last3[2] - get(rev_pan_l) ~= 0 or switches_last3[3] - get(rev_pan_r) ~= 0 or switches_last3[4] - get(rev_tune) ~= 0 or switches_last3[5] - get(rev_att_hd) ~= 0 or switches_last3[6] - get(rev_air_dat) ~= 0 or switches_last3[7] - get(fuel_xpump_l) ~= 0 or switches_last3[8] - get(fuel_xpump_r) ~= 0 or switches_last3[17] - get(aircond_airsource) ~= 0 or switches_last4[13] - get(pressure_lndg_alt_1) ~= 0 or switches_last2[11] - get(antice_wngsource_r) ~= 0 or switches_last4[15] - get(trim_stab) ~= 0 or switches_last2[13] - get(test_rot) ~= 0 or switches_last6[15] - get(oxigen_ox) ~= 0 then --
playSample(switch2, 0)
end
end

setSampleGain(triple_chime, 1000*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(triple_chime, 1000)
--warn
if isSamplePlaying(triple_chime) == false and isSamplePlaying(one_chime) == false and get(flight_time) > 2 and get(view) == 0 then
if warn_caut_last[1] - get(red_cas) < 0 then
playSample(triple_chime, 0)
end
end

setSampleGain(one_chime, 1000*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(one_chime, 1000)
--caut
if isSamplePlaying(one_chime) == false and isSamplePlaying(triple_chime) == false and get(flight_time) > 2 and get(view) == 0 then
if warn_caut_last[2] - get(yellow_cas) < 0 then
playSample(one_chime, 0)
end
end

setSampleGain(bank_angl, 300*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(bank_angl, 1000)
--bank warn
if isSamplePlaying(bank_angl) == false and get(flight_time) > 2 and get(view) == 0 then
if bank_warn == 1 then
playSample(bank_angl, 0)
end
end


--cab alt
setSampleGain(cabin_alt_w, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(cabin_alt_w, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(cabin_alt_w) == false and get(cabalt_warn) == 2 and get(flight_time) > 2 and get(view) == 0 then
	playSample(cabin_alt_w, 0)
	end
end

-- config
setSampleGain(config, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(config, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(config) == false and get(config_warn) ~= 0 and get(flight_time) > 2 and get(view) == 0 then
	playSample(config, 0)
	end
end

--l engn fire
setSampleGain(l_eng_fire, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(l_eng_fire, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(r_eng_fire) == false and isSamplePlaying(l_eng_fire) == false and get(rel_engfir0) == 6 and get(flight_time) > 2 and get(view) == 0 then
	playSample(l_eng_fire, 0)
	end
end

-- r engn fire
setSampleGain(r_eng_fire, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(r_eng_fire, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(r_eng_fire) == false and isSamplePlaying(l_eng_fire) == false and get(rel_engfir1) == 6 and get(flight_time) > 2 and get(view) == 0 then
	playSample(r_eng_fire, 0)
	end
end

setSampleGain(nbrakes_fail, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(nbrakes_fail, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(nbrakes_fail) == false and get(flight_time) > 2 and get(view) == 0 then
		if get(rel_lbrakes) == 6 or get(rel_rbrakes) == 6 then
		playSample(nbrakes_fail, 0)
		end
	end
end


-- flaps & gear & terrain warn



setSampleGain(tolowflaps, 200*get(mastervol)*(1-get(view))*power_on*get(taws_flp_h))
setSamplePitch(tolowflaps, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if get(onground_all) == 0 and isSamplePlaying(tolowflaps) == false and isSamplePlaying(tolowgear) == false and isSamplePlaying(tolowterrain) == false and get(flight_time) > 2 and get(view) == 0 then
		if get(flaps_warn) == 1 then
		playSample(tolowflaps, 0)
		end
	end
end


setSampleGain(tolowgear, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(tolowgear, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(tolowgear) == false and isSamplePlaying(tolowterrain) == false and isSamplePlaying(tolowflaps) == false and get(flight_time) > 2 and get(view) == 0 then
		if get(gear_warn_w) == 1 then
		playSample(tolowgear, 0)
		end
	end
end


setSampleGain(tolowterrain, 200*get(mastervol)*(1-get(view))*power_on*get(taws_ter_h))
setSamplePitch(tolowterrain, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if get(onground_all) == 0 and isSamplePlaying(tolowgear) == false and isSamplePlaying(tolowterrain) == false and isSamplePlaying(tolowflaps) == false and get(flight_time) > 2 and get(view) == 0 then
		if get(terr_warn) == 1 then
		playSample(tolowterrain, 0)
		end
	end
end
--
--
--

-- gear failure
setSampleGain(gear, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(gear, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if isSamplePlaying(gear) == false and get(flight_time) > 2 and get(view) == 0 then
		if get(gear_warn) == 1 then
		playSample(gear, 0)
		end
	end
end

-- avionics



if power_on == 1 and av_hide <= 1 and get(paused) > 0 then
av_hide = av_hide + 0.03*((get(frame_rate_period)-0.02)*25 + 0.5)
end

if power_on == 0 and av_hide >= 0 and get(paused) > 0 then
av_hide = av_hide - 0.03*((get(frame_rate_period)-0.02)*25 + 0.5)
end


setSampleGain(avionics_inn, 60*get(mastervol)*(1-get(view))*av_hide*power_on)
setSamplePitch(avionics_inn, 1000*(av_hide*0.7+0.3))

if isSamplePlaying(avionics_inn) == false then
playSample(avionics_inn, 1)
end


over_st = 0
if get(ind_speed) > 320 or get(machno) > 0.83 then
over_st = 1
else
	if get(ind_speed) < 320 and get(ind_speed) > 210 and get(flaprqst) > 0.1 and get(flaprqst) < 0.68 then
	over_st = 1
	else
		if get(ind_speed) > 175 and get(flaprqst) > 0.68 then
		over_st = 1
		else
		over_st = 0
		end
	end
end



setSampleGain(overspeed, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(overspeed, 1000)

if get(elbus1) >= 10 or get(elbus2) >= 10 then
	if get(onground_all) == 0 and isSamplePlaying(overspeed) == false and get(flight_time) > 2 and get(view) == 0 then
		if over_st == 1 then
		playSample(overspeed, 0)
		end
	end
end

--


if get(annun1_aur) > 0 and get(annun1_aur) < 3 and power_on > 0 then
	if isSamplePlaying(triple_chime) == false and isSamplePlaying(one_chime) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(triple_chime, 0)
	end
end

if get(annun1_aur) > 5 and get(annun1_aur) < 6 and power_on > 0 then
	if isSamplePlaying(config) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(config, 0)
	end
end

if get(annun1_aur) > 8 and get(annun1_aur) < 9 and power_on > 0 then
	if isSamplePlaying(overspeed) == false and get(flight_time) > 2 and get(view) == 0 then
		playSample(overspeed, 0)
	end
end

if get(annun1_aur) > 11 and get(annun1_aur) < 12 and power_on > 0 then
	if isSamplePlaying(bank_angl) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(bank_angl, 0)
	end
end






if get(annun2_aur) > 0 and get(annun2_aur) < 1 and power_on > 0 then
	if isSamplePlaying(one_chime) == false and isSamplePlaying(triple_chime) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(one_chime, 0)
	end
end


if get(annun2_aur) > 3 and get(annun2_aur) < 4 and power_on > 0 then
	if isSamplePlaying(nbrakes_fail) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(nbrakes_fail, 0)
	end
end

if get(annun2_aur) > 6 and get(annun2_aur) < 7 and power_on > 0 then
	if isSamplePlaying(gear) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(gear, 0)
	end
end

if get(annun2_aur) > 9 and get(annun2_aur) < 10 and power_on > 0 then
	if isSamplePlaying(cabin_alt_w) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(cabin_alt_w, 0)
	end
end





-- fire test
setSampleGain(apu_fire, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(apu_fire, 1000)



if get(fire_test_aur) > 1 and get(fire_test_aur) < 2 and power_on > 0 then
	if isSamplePlaying(r_eng_fire) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(r_eng_fire, 0)
	end
end

if get(fire_test_aur) > 4 and get(fire_test_aur) < 5 and power_on > 0 then
	if isSamplePlaying(l_eng_fire) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(l_eng_fire, 0)
	end
end

if get(fire_test_aur) > 8 and get(fire_test_aur) < 9 and power_on > 0 then
	if isSamplePlaying(apu_fire) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(apu_fire, 0)
	end
end

--taws test

if get(taws_test_aur) > 1 and get(taws_test_aur) < 2 and power_on > 0 then
	if isSamplePlaying(tolowflaps) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(tolowflaps, 0)
	end
end

if get(taws_test_aur) > 4 and get(taws_test_aur) < 5 and power_on > 0 then
	if isSamplePlaying(tolowgear) == false and get(flight_time) > 2 and get(view) == 0 then
		playSample(tolowgear, 0)
		end
end

if get(taws_test_aur) > 7 and get(taws_test_aur) < 8 and power_on > 0 then
	if isSamplePlaying(tolowterrain) == false and get(flight_time) > 2 and get(view) == 0 then
		playSample(tolowterrain, 0)
		end
end

-- rud lim stall

setSampleGain(stall, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(stall, 1000)



if get(stall_warn_test) == 1 and power_on > 0 then
	if isSamplePlaying(stall) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(stall, 0)
	end
end

setSampleGain(land_gear, 200*get(mastervol)*(1-get(view))*power_on)
setSamplePitch(land_gear, 1000)



if get(lan_gear_warn) == 1 and power_on > 0 then
	if isSamplePlaying(land_gear) == false and get(flight_time) > 2 and get(view) == 0 then
	playSample(land_gear, 0)
	end
end

--
--
--


if get(flight_time)-flight_time_last == 0 and get(replay_mode) == 0 then
stopsound = 0
setMasterGain(0)
else
stopsound = 1
setMasterGain(get(s_master_gain))
end

if get(flight_time) < 1 or get(sound_mute) == 1 then
setMasterGain(0)
set(mastervol, 0)
end

if get(sound_mute) ~= 1 then
set(s_master_gain ,get(sound_vol))
set(mastervol, 1)
end
















--[=[
--]=]

--set(disp, r)
--set(disp2, musgain)
set(disp3, alpha)
set(disp4, get(view_hdg))

distance_last = distance
blinds_last = {get(jalousie1), get(jalousie2), get(jalousie3), get(jalousie4), get(jalousie5), get(jalousie6), get(jalousie7), get(jalousie8), get(jalousie9), get(jalousie10), get(jalousie11), get(jalousie12), get(sunscreen10), get(sunscreen11), get(sunscreen20), get(sunscreen21)}
table_last = {get(table1), get(table2), get(table3), get(table4)}
p_cush_last = {get(p_cush)}
door_last = {get(door1), get(door2), get(door3), get(door4), get(door5)}
flight_time_last = get(flight_time)

switches_last = {get(belt), get(smoke), get(smokebelts_h), get(gshldl_h), get(pedestal_h), get(gshldr_h), get(cbp_h), get(dome_h), get(cmfd_h), get(cpfd_h), get(pmfd_h), get(ppfd_h), get(annun_h), get(wing_insp_h), get(strobe_h), get(nav_h), get(landlight1h), get(landlight2h), get(xaptaxilighth), get(emeright_h), get(entrlight_h), get(cablight_h), get(crewlit_h), get(left_bat_h), get(right_bat_h), get(l_hpump_h), get(r_hpump_h), get(aux_hpump_h), get(ptu_h), get(bus_tie_h), get(flight_spoil_h), get(ground_sp_h)}

switches_last2 = {get(en_starter_l), get(en_starter_r),get(en_but_run_l), get(en_but_run_r), get(APU_starter_switch), get(bleed_xbleed_h), get(bleed_en_l_h), get(bleed_en_r_h), get(bleed_apu_h), get(jet_sync_mode), get(antice_wngsource_r),get(trim_pusher_cov),get(test_rot),get(cab_ac_cov),get(cab_dc_cov),get(cab_ac_h),get(cab_dc_h),get(dcu_b_cov),get(dcu_a_cov),get(dcu_b_h),get(dcu_a_h)}
--							1				2					3					4						5					6					7					8				9					10						11					12					13			14				15				16				17			18				19			20				21
switches_last3 = {get(half_bank_h),get(rev_pan_l),get(rev_pan_r),get(rev_tune),get(rev_att_hd),get(rev_air_dat),get(fuel_xpump_l),get(fuel_xpump_r),get(fuel_xflow_dn_h),get(fuel_xflow_up_h),get(nws_h),get(taws_gs_h),get(taws_flp_h),get(taws_ter_h),get(aircond_man_temp_h),get(aircond_ramair_h),get(aircond_airsource),get(aircond_cabin_temp),get(aircond_cockpit_temp), get(parking_brake_ratio)}
--						1					2			3				4				5				6					7				8				9						10				11			12				13				14					15					16						17						18						19							20
switches_last4 = {get(flight_spoil_cov), get(taws_gs_cov),get(taws_flp_cov), get(taws_ter_cov), get(aircond_ramair_cov), get(pressure_ditch_cov), get(pressure_emer_depr_cov), get(pressure_emer_depr_h), get(pressure_ditch_h), get(pressure_man_h),get(pressure_manrate),get(pressure_lndg_alt_2),get(pressure_lndg_alt_1),get(trim_rud),get(trim_stab),get(trim_pusher_h)}
--							1					2					3				4						5						6							7							8						9						10					11						12						13					14				15				16
switches_last5 = {get(antice_wing_h),get(antice_probe_l_h),get(antice_probe_r_h),get(antice_engn_l_h),get(antice_engn_r_h),get(antice_wshld_l_h),get(antice_wshld_r_h),get(electr_apugen_h),get(electr_gen_r_h),get(electr_gen_l_h),get(electr_stbi_h),get(electr_extp_h),get(hydr_altn_flp_h),get(hydr_l_sov_h),get(hydr_r_sov_h),get(hydr_altn_flp_cov),get(hydr_l_sov_cov),get(hydr_r_sov_cov)}
--							1					2					3						4					5						6					7					8					9					10					11					12					13					14					15				16						17					18
switches_last6 = {get(fire_engn_r_cov),get(fire_engn_l_cov),get(fire_apu_cov),get(fire_ext_2_cov),get(fire_ext_1_cov),get(fire_autoapr_cov),get(fire_engn_r_h),get(fire_engn_l_h),get(fire_apu_h),get(fire_ext_2_h),get(fire_ext_1_h),get(fire_autoapr_h),get(engn_mach_h),get(engn_ign_h),get(oxigen_ox),get(oxigen_terap_cov),get(oxigen_terap_h),get(elt_h),get(stbi_cage_h),get(stby_ins_dim_brt)}
--							1					2					3					4					5					6					7					8					9				10				11					12					13				14				15				16					17				18				19				  20
switches_last7 = {get(aud_o2m_l_sw),get(aud_emer_l_sw),get(aud_voice_l_sw),get(comps_slew_l_sw),get(rudd_ped_l_sw),get(aud_o2m_r_sw),get(aud_emer_r_sw),get(aud_voice_r_sw),get(comps_slew_r_sw),get(rudd_ped_r_sw),get(comps_head_l_h),get(comps_head_r_h),get(barometer_setting_in_hg_pilot),get(lg_man),get(pitch_d_1),get(pitch_d_2),get(clock_timer_h),get(clock_gps),get(clock_flt),get(clock_mode)}
--							1					2					3					4					5				6					7					8				9					10					11						12						13						14			15				16				17					18				19			20
switches_last8 = {get(aud_pa_r_h),get(aud_cab_r_h),get(aud_hf2_r_h),get(aud_hf1_r_h),get(aud_com3_r_h),get(aud_com2_r_h),get(aud_com1_r_h),get(aud_pa_l_h),get(aud_cab_l_h),get(aud_hf2_l_h),get(aud_hf1_l_h),get(aud_com3_l_h),get(aud_com2_l_h),get(aud_com1_l_h),get(mfdpan_lr_sw),get(gear_handle_status),get(sbrk_h),get(gust_lock), get(crewlit_h), get(pedals_fwd_bwd_l), get(pedals_fwd_bwd_r), get(crewlit2_h)}
--							1				2				3					4				5				6					7				8				9				10				11					12				13					14				15					16					17				18			19					20						21					22
autop_last = {get(half_bank_h), get(autop_fdir_h), get(autop_nav_h), get(autop_hdg_h), get(autop_appr_h), get(autop_bc_h), get(autop_flc_h), get(autop_vs_h), get(autop_vnav_h), get(autop_alt_h), get(autop_ap_h), get(autop_xfr_h), get(autop_yd_h), get(HSI_source_select_pilot)}
--						1				2					3				4					5				6				7					8					9				10					11				12				13						14
switches_last9 = {get(nav1_obs_deg_mag_pilot),get(heading_dial_deg_mag_pilot),get(airspeed_dial_kts_mach),get(altitude_dial_ft),get(vvi_dial_fpm),cws_temp, get(dcp_tilt), get(dcp_range),get(EFIS_tcas_on),get(EFIS_weather_on),get(dcp_tune1_rot),get(dcp_tune2_rot),get(dcp_menu1_rot),get(dcp_menu2_rot), get(mfd_sel_state_h),get(nav2_obs_deg_mag_pilot),get(dcp_navsrc),get(autop_brgsrc),get(dcp_radar),get(dcp_refs),get(dcp_dmeh),get(dcp_1_2),get(mfd_pan_cas)}
--								1								2							3						4					5			6			7				8					9				10					11					12					13					14				15							16						17				18				19			20				21			22				23
mfd_sel_last = {get(mfd_checkl_l),get(mfd_hydr_l),get(mfd_fuel_l),get(mfd_flt_ctr_l),get(mfd_electr_l),get(mfd_ecs_l),get(mfd_antice_l),get(mfd_frmt_l),get(mfd_sumry_l),get(mfd_checkl_r),get(mfd_hydr_r),get(mfd_fuel_r),get(mfd_flt_ctr_r),get(mfd_electr_r),get(mfd_ecs_r),get(mfd_antice_r),get(mfd_frmt_r),get(mfd_sumry_r),get(map_mode)}
--						1					2				3				4					5				6				7				8				9				10					11				12				13					14				15				16					17				18			19
warn_caut_last = {get(red_cas),get(yellow_cas),bank_warn}

end

