Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Blinking and Repositioning SAMs Demo

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Blinking and Repositioning SAMs Demo Page: [1]
Login
Message << Older Topic   Newer Topic >>
Blinking and Repositioning SAMs Demo - 12/14/2019 5:30:39 PM   
SeaQueen


Posts: 1215
Joined: 4/14/2007
From: Washington D.C.
Status: offline
SAMs blink their radars and reposition according to a set schedule set at the scenario start.

Attachment (1)
Post #: 1
RE: Blinking and Repositioning SAMs Demo - 12/14/2019 6:05:31 PM   
SeaQueen


Posts: 1215
Joined: 4/14/2007
From: Washington D.C.
Status: offline
There's two important portions to the code. The first set of lua code is executed at scenario load:

-- randomize the sam site states

samSites = { 'gwkw9v-0hls0ku7054ja', 'gwkw9v-0hls0ku7054ku', 'gwkw9v-0hls0ku7054nq', 'gwkw9v-0hls0ku7054mc'}  
samSiteState = {}

emitTime = 8 -- minutes
tearDownTime = 2 -- minutes
repositionTime = 2 -- minutes
setUpTime = 2 -- minutes
standByTime = 2 -- minutes

timeToCompleteEvolution = emitTime + tearDownTime + repositionTime + setUpTime + standByTime

timeToCeaseEmission = emitTime
timeToCompleteTearDown = timeToCeaseEmission + tearDownTime
timeToCompleteRelocation = timeToCompleteTearDown + repositionTime
timeToCompleteSetUp = timeToCompleteRelocation + setUpTime
timeToStandBy = timeToCompleteSetUp + standByTime

-- weapons control states
wcsFree = 0
wcsTight = 1
wcsHold = 2


for i, s in ipairs(samSites) do

    u = ScenEdit_GetUnit( { guid=s } )
    time = math.random(0, timeToCompleteEvolution )
    if time < timeToCeaseEmission then 
        samSiteState[s] = { state="emitting", minutesInState = time }
        ScenEdit_SetEMCON('Unit', s, 'Radar=Active')
        ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsTight  })
    elseif ( (time >= timeToCeaseEmission) and ( time < timeToCompleteTearDown )) then
        samSiteState[s] = { state="tearingDown", minutesInState = (time - timeToCeaseEmission) }
        ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })
        ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
    elseif ( ( time >= timeToCompleteTearDown ) and (time < timeToCompleteRelocation )) then
        samSiteState[s] = { state="repositioning", minutesInState = (time - timeToCompleteTearDown) }
        ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })
        ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
    elseif ( (time >= timeToCompleteRelocation ) and ( time < timeToCompleteSetUp )) then
        samSiteState[s] = { state="settingUp", minutesInState = (time - timeToCompleteRelocation) }
        ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })
        ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
    else
        samSiteState[s] = { state="standingBy", minutesInState = (time - timeToCompleteSetUp ) }
        ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })
        ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
    end
end



The second portion is executed by an action controlled by an "Every Minute" trigger.

function randomWaypoint(currentPosition, distance)

    math.randomseed( os.time() ) -- hopefully removes correlations


    local lat0 = currentPosition.latitude
    local lon0 = currentPosition.longitude
    local r = math.random(0, 359)
    local degreesPerNauticalMile = 1/60    

    local latDisplacementNauticalMiles = distance * math.cos( math.rad(r) )
    local lonDisplacementNauticalMiles = distance * math.sin( math.rad(r) )

    local latDisplacementDegrees = latDisplacementNauticalMiles * degreesPerNauticalMile  -- only strictly correct at the equator
    local lonDisplacementDegrees = lonDisplacementNauticalMiles * degreesPerNauticalMile
     
    local lat = lat0 + latDisplacementDegrees
    local lon = lon0 + lonDisplacementDegrees

    local randomWaypoint = {TypeOf = 'ManualPlottedCourseWaypoint', longitude = lon, latitude = lat}
    
    return randomWaypoint
end

for i, s in ipairs(samSites) do

       u = ScenEdit_GetUnit( { guid = s} )

       if samSiteState[s] ~= nil then   
         -- increment samsite time in state by one minute
         samSiteState[s].minutesInState = samSiteState[s].minutesInState + 1     

         if samSiteState[s].state == 'emitting' then
             ScenEdit_SetEMCON('Unit', s, 'Radar=Active')
             ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsTight  })
             ScenEdit_SetUnit({side='IRN', guid=s, course={}, speed = 0, holdposition=true  })
             if samSiteState[s].minutesInState >= emitTime then
                samSiteState[s].state = 'tearingDown'
                samSiteState[s].minutesInState = 0
                break
             end
         elseif samSiteState[s].state == 'tearingDown' then
             ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
             ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })
             ScenEdit_SetUnit({side='IRN', guid=s, course={}, speed = 0, holdposition=true  })
             if samSiteState[s].minutesInState >= tearDownTime then
                samSiteState[s].state = 'repositioning'
                samSiteState[s].minutesInState = 0
                break
             end

         elseif samSiteState[s].state == 'repositioning' then
              ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
              ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })              
              repositionSpeed = 35 -- knots
              ScenEdit_SetUnit({side='IRN', guid=s, course={randomWaypoint({latitude=u.latitude, longitude=u.longitude}, (repositionSpeed *repositionTime / 60)  )}, speed = repositionSpeed, holdposition=false  })
              if samSiteState[s].minutesInState >= repositionTime then
                samSiteState[s].state = 'settingUp' 
                samSiteState[s].minutesInState = 0        
                break
             end
         elseif samSiteState[s].state == 'settingUp' then
           ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
           ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold })   
           ScenEdit_SetUnit({side='IRN', guid=s, course={}, speed = 0, holdposition=true  })
           if samSiteState[s].minutesInState >= repositionTime then
                samSiteState[s].state = 'standingBy' 
                samSiteState[s].minutesInState = 0
                break
            end

         elseif samSiteState[s].state == 'standingBy' then
            ScenEdit_SetEMCON('Unit', s, 'Radar=Passive')
            ScenEdit_SetDoctrine({side = 'IRN', unitname=u.name }, { weapon_control_status_air = wcsHold  })        
            ScenEdit_SetUnit({side='IRN', guid=s, course={}, speed = 0, holdposition=true  })
             if samSiteState[s].minutesInState >= timeToCompleteEvolution then
                samSiteState[s].state = 'emitting'
                samSiteState[s].minutesInState = 0
                break
             end
        end
    end
end




< Message edited by SeaQueen -- 12/14/2019 6:08:40 PM >

(in reply to SeaQueen)
Post #: 2
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Blinking and Repositioning SAMs Demo Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.160