dofile ("./Sounds/events_id.lua")

events = {}
function wingman_default(event)
    events[event] = {{"callsign"},sample(event)}
end

wingman_default(wsRepWingmenRequestPermissionToAttack)

function wingman_recon(event)
    events[event] = {
	                 {"subtitle",VOICE_ASSOCIATION_LEADER},
                     {"wingman",PHRASES_TO_TWO},
                     sample(event),
                     {"sample" ,PHRASES_1_KM + event - wsRepHumanHelReconnaissance_01},
                     {"sample" ,PHRASES_AZIMUTH},
                     {"bearing"}}                    
end

function to_wingman(event)
    local tbl = {}
    
    tbl[#tbl + 1] = {"subtitle",VOICE_ASSOCIATION_LEADER}
    
    local receiver = VOICE_ASSOCIATION_NULL
    
    if 	    event       == wsRepRequestEnginesLaunch or
    		event       == wsRepHumanRequestTaxiToRunway or
    		event       == wsRepHumanRequestTakeOff or
    		event       == wsRepHumanRequestLanding or
    		event       == wsRepHumanInbound or
    		event       == wsRepHumanRequestAzimuth or 
            event       == wsRepHumanRequestControlHover then
            receiver 	= VOICE_ASSOCIATION_TOWER
    elseif  event       == wsRepHumanVectorToNearestBandit or
            event       == wsRepHumanVectorToHomeplate or
            event       == wsRepHumanVectorToTanker or
            event       == wsRepHumanDeclare then
            receiver 	= VOICE_ASSOCIATION_AWACS;
    elseif  event ~= wsRepHumanRejoinFormation and ( 
           (event >= wsRepHumanGoCombatSpread and
             event <  wsRepHumanReturnToBase) or
            (event >  wsRepHumanGoRefueling and 
             event <= wsRepHumanOpenFormation) or
            (event >= wsRepHumanHelGoHeavy and 
             event <= wsRepHumanHelGoFloat)) then
            receiver = VOICE_ASSOCIATION_NULL--эти команды отдаются только звену целиком, поэтому "звену" не говорим
    else
			receiver = VOICE_ASSOCIATION_WINGMAN--команды отдельным ведомым или всему звену
    end
    
    if event == wsRepHumanInbound then
       tbl[#tbl + 1] = {"ATC_callsign",PHRASES_CALLSIGN_MIN} 
       tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
       tbl[#tbl + 1] = {"callsign"}--здесь называем свой позывной
       tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
	   tbl[#tbl + 1] = sample(event)
	   --tbl[#tbl + 1] = {"sample",ws_HOnlyInbound}
       events[event] = tbl 
       return;    
    end
    
    --кому
    if  receiver > VOICE_ASSOCIATION_NULL then
        if  receiver   == VOICE_ASSOCIATION_WINGMAN then
            tbl[#tbl + 1] = {"wingman",PHRASES_TO_TWO}
        elseif receiver  == VOICE_ASSOCIATION_TOWER then
            tbl[#tbl + 1] = {"ATC_callsign",PHRASES_CALLSIGN_MIN} 
            tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
        elseif receiver == VOICE_ASSOCIATION_AWACS then
            tbl[#tbl + 1] = {"sample",PHRASES_CALLNAME_AWACS}
			tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
        end
    end
    --называем себя
    if 	receiver == VOICE_ASSOCIATION_TOWER or
        receiver == VOICE_ASSOCIATION_AWACS then
        tbl[#tbl + 1] = {"callsign"}--здесь называем свой позывной
        tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
    end
    --собственно сообщение
    tbl[#tbl + 1] = sample(event)
    events[event] = tbl 
    return;
end

function fill_order_wingman(event)   
    local tbl = {}
    tbl[#tbl + 1] = {"association_subtitle"}
    tbl[#tbl + 1] = wingmanTemper(event)  
	tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
    tbl[#tbl + 1] = sample(event)

    if  event == wsRepWingmenSpike or 
        event == wsRepWingmenMudSpike or
        event == wsRepWingmenSAMLaunch or
        event == wsRepWingmenMissileLaunch or
        event == wsRepWingmenTallyBandit   then
        tbl[#tbl + 1] = {"bearing_o_clock", PHRASES_ONE_O_CLOCK}
	elseif event == wsRepWingmenReconBearing then
		tbl[#tbl + 1] = {"what_recon"}
		tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
		tbl[#tbl + 1] = {"bearing_o_clock", PHRASES_ONE_O_CLOCK}
    elseif event == wsRepWingmenContactBearingForMiles then
        --tbl[#tbl + 1] = {"bearing_for"}
		tbl[#tbl + 1] = {"bearing"}
		tbl[#tbl + 1] = {"sample", PHRASES_FOR}		
        tbl[#tbl + 1] = {"distance"}
    elseif  event == wsRepWingmenHelReconBearing then      
        tbl[#tbl + 1] = {"what_recon"}
        tbl[#tbl + 1] = {"sample",ws_WHRange}
        tbl[#tbl + 1] = {"distance"}
        tbl[#tbl + 1] = {"subtitle",PHRASES_MILES}
		tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
        tbl[#tbl + 1] = {"sample",ws_WHBearing}
        tbl[#tbl + 1] = {"bearing"}
    end
    if  event == wsRepWingmenHelReconEndFound or
        event == wsRepWingmenHelReconEndNotFound or
        event == wsRepWingmenHelLaunchAbortTask then  
        tbl[#tbl + 1] = {"sample",PHRASES_RETURNTOFORMATION}
    end
    events[event] = tbl 
end

for i = wsRepWingmenNull,wsRepWingmenMaximum                            do fill_order_wingman(i)  end
for i = wsRepHumanHelReconnaissance_01,wsRepHumanHelReconnaissance_10   do wingman_recon(i)  end
for i = wsRepHumanEngageMyTarget  ,wsRepHumanHelGoFloat                 do to_wingman(i) end
for i = wsRepRequestEnginesLaunch ,wsRepHumanInbound                    do to_wingman(i) end  
for i = wsRepHumanEngageDlinkTarget    ,wsRepHumanHold                  do to_wingman(i) end  

to_wingman(wsRepHumanRequestControlHover)

function add_wind(tbl)
	tbl[#tbl + 1]     = {"sample_if_wind",PHRASES_DELIMETER} 
    tbl[#tbl + 1]     = {"sample_if_wind",ws_HTowerWind} 
    tbl[#tbl + 1]     = {"wind_direction"}
    tbl[#tbl + 1]     = {"sample_if_wind",ws_HTowerWindSpeed} 
    tbl[#tbl + 1]     = {"wind_velocity"}
    tbl[#tbl + 1]     = {"sample_if_wind",ws_HTowerMetersPerSecond} 
end
function fill_order_tower(event)
    local tbl = {}
    
    if event == wsRepATCCheckLandingGear then
        tbl[#tbl + 1]     = {"ATC_callsign_subtitle",PHRASES_CALLSIGN_MIN}
        tbl[#tbl + 1]     = {"subtitle",PHRASES_COLON}
        tbl[#tbl + 1]     = {"callsign"}
        tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
        tbl[#tbl + 1]     = {"ATC_callsign",PHRASES_CALLSIGN_MIN}
		tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
        tbl[#tbl + 1]     = {"sample_if_runway",ws_HTowerRunwayNumber}
        tbl[#tbl + 1]     = {"runway"}
        add_wind(tbl)
		tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
        tbl[#tbl + 1]     = sample(event)
        events[event] = tbl
        return
    end
    
    tbl[#tbl + 1]     = {"ATC_callsign_subtitle",PHRASES_CALLSIGN_MIN}
    tbl[#tbl + 1]     = {"subtitle",PHRASES_COLON}
    tbl[#tbl + 1]     = {"callsign"}
    tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
    tbl[#tbl + 1]     = {"ATC_callsign",PHRASES_CALLSIGN_MIN}
	if event ~= wsRepATCAzimuth then
		tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
	end
    tbl[#tbl + 1]     = sample(event)
    
    if     event == wsRepATCYouAreClearedForTO      then 
           tbl[#tbl + 1]     = {"sample",ws_HTowerClimbTo300AtQFE}
           tbl[#tbl + 1]     = {"pressure"}
    elseif event == wsRepATCClearedToTaxiRunWay     then 
           tbl[#tbl + 1]      = {"runway"}
    elseif event == wsRepATCFlyHeading              then			
           tbl[#tbl + 1]     = {"bearing"}          
           tbl[#tbl + 1]     = {"sample",ws_HTowerRange}
           tbl[#tbl + 1]     = {"distance"}
		   tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
           tbl[#tbl + 1]     = {"sample",ws_HTowerQFE}
           tbl[#tbl + 1]     = {"pressure"}
		   tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
		   tbl[#tbl + 1]     = {"sample_if_runway",ws_HTowerRunwayNumber}
		   tbl[#tbl + 1]     = {"runway"}		   
		   tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}		   
           tbl[#tbl + 1]     = {"sample",ws_HTowerToPatternAltitude}
    elseif event == wsRepATCClearedForEngineStartUp then
           tbl[#tbl + 1]     = {"wind_direction"}
           tbl[#tbl + 1]     = {"sample_if_wind",ws_HTowerWindSpeed} 
           tbl[#tbl + 1]     = {"wind_velocity",1}
           tbl[#tbl + 1]     = {"sample",ws_HTowerMetersPerSecond}   
    elseif event == wsRepATCYouAreClearedForLanding then
			tbl[#tbl + 1]     = {"subtitle",PHRASES_DELIMETER}
			tbl[#tbl + 1]     = {"sample_if_runway",ws_HTowerRunwayNumber}
			tbl[#tbl + 1]     = {"runway"}
			add_wind(tbl)
    elseif event == wsRepATCClearedControlHover then
           add_wind(tbl)   
    elseif event == wsRepATCAzimuth                 then 
           tbl[#tbl + 1] = {"bearing"}
	elseif event == wsRepATCTrafficBearing 			then
			tbl[#tbl + 1] = {"bearing"}		   
    end
    events[event] = tbl
end

for i = wsRepATCNull,wsRepATCMaximum   do    fill_order_tower(i)  end

function fill_order_almaz(event)
    local tbl = {}
    
    tbl[#tbl + 1] = {"sample",ALMAZ_MESSAGE_BEGIN}

    if   event == wsRepALMAZ_LEFT_ENG_FIRE or
         event == wsRepALMAZ_RIGHT_ENG_FIRE or
         event == wsRepALMAZ_APU_FIRE or
         event == wsRepALMAZ_HYDRO_FIRE or
         event == wsRepALMAZ_FAN_FIRE then
        tbl[#tbl + 1] = {"sample",ALMAZ_BOARD}
        
        tbl[#tbl + 1] = {"boardnumber"}--это произнесение числа не по отдельным цифрам а как надо
        tbl[#tbl + 1] = {"sample",ALMAZ_MESSAGE_END}
        tbl[#tbl + 1] = {"sample",ALMAZ_MESSAGE_BEGIN}
    end
    tbl[#tbl + 1] = sample(event)
    tbl[#tbl + 1] = {"sample",ALMAZ_MESSAGE_END}
    events[event] = tbl
end

for i = wsRepALMAZ_Null,wsRepALMAZ_Maximum             do    fill_order_almaz(i)  end



function fill_order_awacs(event)
 
    local tbl = {}
    
    tbl[#tbl + 1] = {"subtitle",VOICE_ASSOCIATION_AWACS}
    tbl[#tbl + 1] = {"callsign"}
	tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
	tbl[#tbl + 1] = {"sample",PHRASES_CALLNAME_AWACS}
	tbl[#tbl + 1] = {"subtitle",PHRASES_DELIMETER}
    tbl[#tbl + 1] = sample(event)

    if event == wsRepAWACSBanditBearingForMiles or
       event == wsRepAWACSPopUpGroup  or
       event == wsRepAWACSHomeBearing or
       event == wsRepAWACSTankerBearing then
    
        --tbl[#tbl + 1] = {"bearing_for"}
		tbl[#tbl + 1] = {"bearing"}
		tbl[#tbl + 1] = {"sample", PHRASES_FOR}		
        tbl[#tbl + 1] = {"distance"}

        if  event == wsRepAWACSBanditBearingForMiles then
            tbl[#tbl + 1] = {"awacs_angles"}
            tbl[#tbl + 1] = {"awacs_hot"}
        end
    end
    events[event] = tbl
end

for i = wsRepAWACSNull,wsRepAWACSMaximum  do 
   fill_order_awacs(i) 
end

function fill_order_common(event)
    events[event] = {sample(event)}
end

for i = wsRepBettyNull,wsRepBettyMaximum do
    fill_order_common(i)
end

for i = wsRepA10_VMU_Null,wsRepA10_VMU_Maximum do
    fill_order_common(i)
end

function fill_order_tanker(event)
    events[event] = {	{"subtitle",VOICE_ASSOCIATION_TANKER},
						{"callsign"},
						{"subtitle",PHRASES_DELIMETER},
						{"sample",PHRASES_CALLNAME_TANKER},
						{"subtitle",PHRASES_DELIMETER},
						sample(event) }
end

for i = wsRepTankerNull,wsRepTankerMaximum do
    fill_order_tanker(i)
end

--ground service



function fill_order_ground_1(event)
    events[event] = {{"subtitle",VOICE_ASSOCIATION_LEADER},
                     sample(event)}
end
function fill_order_ground_2(event)
    events[event] = {{"subtitle",VOICE_ASSOCIATION_GROUND_SERVICE},
                     sample(event)}
end

for i = wsRepHumanHel_Refueling_25,wsRepHumanHel_Setup_NVG        do fill_order_ground_1(i) end
for i = wsRepHumanHel_LoadMin,wsRepHumanHel_LoadMax               do fill_order_ground_1(i) end
for i = wsRepHumanHel_Use_Turbo_Gear,wsRepHumanGroundElecPowerOff do fill_order_ground_1(i) end
for i = wsRepGroundServiceNull,wsRepGroundServiceMaximum do      fill_order_ground_2(i) end

fill_order_ground_1(wsRepHuman_Refueling_Start)
fill_order_ground_1(wsRepHuman_Refueling_End)