I began by creating two CAPs, using the same CAP area but with different mission starting times. This got the airplanes up at the right times. In this case they are "East CAP" and "East CAP (Second Shift)." Their mission start times are one hour apart. For precision, I calculated their required mission start times on scenario load:
Code: Select all
-- US base guids
hickamAfb = 'gwkw9v-0hlsepaaej1ro'
-- F-22 constants
f22CruiseSpeed = 480 -- knots
-- important times
time0000Z = os.time{year=2020, month=1, day=1, hour=0}
time0100Z = os.time{year=2020, month=1, day=1, hour=1}
time0200Z = os.time{year=2020, month=1, day=1, hour=2}
time0300Z = os.time{year=2020, month=1, day=1, hour=3}
time0400Z = os.time{year=2020, month=1, day=1, hour=4}
time0500Z = os.time{year=2020, month=1, day=1, hour=5}
time0600Z = os.time{year=2020, month=1, day=1, hour=6}
time0700Z = os.time{year=2020, month=1, day=1, hour=7}
time0800Z = os.time{year=2020, month=1, day=1, hour=8}
timeline = {time0000Z, time0100Z, time0200Z, time0300Z, time0400Z, time0500Z, time0600Z, time0700Z, time0800Z }
-- important distance calculations
capEastMarker = ScenEdit_GetReferencePoint( {side='USA', name='CAP East Marker' } )
capWestMarker = ScenEdit_GetReferencePoint( {side='USA', name='CAP West Marker' } )
hickamToCAPEastDistance = Tool_Range(hickamAfb, {latitude=capEastMarker.latitude, longitude=capEastMarker.longitude})
hickamToCAPWestDistance = Tool_Range(hickamAfb, {latitude=capWestMarker.latitude, longitude=capWestMarker.longitude})
Code: Select all
-- important time calculations and constants / conversion factors
oneSecond = 1
oneMinute = 60 * oneSecond
thirtyMinutes = 30 * oneMinute
halfHour = thirtyMinutes
oneHour = 2 * halfHour
hickamToCAPEastF22Time = hickamToCAPEastDistance / f22CruiseSpeed * oneHour
hickamToCAPWestF22Time = hickamToCAPWestDistance / f22CruiseSpeed * oneHour
--missions and mission start times
capEastMission = ScenEdit_GetMission('USA', 'CAP East')
capEastSecondShiftMission = ScenEdit_GetMission('USA', 'CAP East (Second Shift)')
capWestMission = ScenEdit_GetMission('USA', 'CAP West')
capEastFirstShiftCheckInTime =time0100Z
capWestFirstShiftCheckInTime = time0100Z
capEastMissionStartTime = capEastFirstShiftCheckInTime - hickamToCAPEastF22Time
capWestMissionStartTime = capWestFirstShiftCheckInTime - hickamToCAPWestF22Time
Code: Select all
ScenEdit_SetMission('USA', capEastMission.guid , {starttime= os.date("%m/%d/%Y %I:%M:%S %p", capEastMissionStartTime )})
ScenEdit_SetMission('USA', capWestMission.guid, {starttime = os.date("%m/%d/%Y %I:%M:%S %p", capWestMissionStartTime )})
capEastSecondShiftCheckInTime =time0200Z
capWestSecondShiftCheckInTime = time0200Z
capEastMissionSecondShiftStartTime = capEastSecondShiftCheckInTime - hickamToCAPEastF22Time
ScenEdit_SetMission('USA', capEastSecondShiftMission.guid , {starttime= os.date("%m/%d/%Y %I:%M:%S %p", capEastMissionSecondShiftStartTime )})
Next I created two data structures for storing the relevant CAP information:
Code: Select all
-- build array of all fighters
f22id = 2201
fighters = {}
base = ScenEdit_GetUnit( {guid=hickamAfb} )
aircraftAtBase = base.embarkedUnits.Aircraft
for i, a in ipairs(aircraftAtBase) do
u = ScenEdit_GetUnit( {guid=a} )
if (u.dbid == f22id) then
fighters[#fighters + 1] = u.guid
end
end
Code: Select all
-- build control structures for fighters
fighterStatus = {}
-- assign the first 8 fighters to capEast
for i, a in ipairs(capEastMission.unitlist) do
fighterStatus[ a ] = {
mission = capEastMission.guid,
tanker = tankerCapEastMission.guid,
timeForNextHookup = time0200Z,
timeForNextOnStation = time0200Z + oneHour
}
end
for i, a in ipairs(capEastSecondShiftMission.unitlist) do
fighterStatus[ a ] = {
mission = capEastMission.guid,
tanker = tankerCapEastMission.guid,
timeForNextHookup = time0300Z,
timeForNextOnStation = time0300Z + oneHour
}
end
Finally, I wrote a little snippet of code to run every 15 minutes:
Code: Select all
currentTime = ScenEdit_CurrentTime() + 5*oneHour -- five hours behind for some unclear reason *bug work around?*
for i, f in ipairs(fighters) do
if (fighterStatus[ f ] ~= nil) then
if ( currentTime >= fighterStatus[ f ].timeForNextHookup ) then
u = ScenEdit_GetUnit({ guid=f })
if( u.mission.guid ~= fighterStatus.tanker ) then
ScenEdit_AssignUnitToMission( f, fighterStatus[ f ].tanker )
fighterStatus[ f ].timeForNextHookup = fighterStatus[ f ].timeForNextHookup + 2 * oneHour -- two hours, time for tanking + capping
-- fighterStatus[ f ].timeForNextOnStation = fighterStatus[ f ].timeForNextOnStation + oneHour
end
elseif ( currentTime >= fighterStatus[ f ].timeForNextOnStation ) then
u = ScenEdit_GetUnit({ guid=f })
if( u.mission.guid ~= fighterStatus.tanker ) then
ScenEdit_AssignUnitToMission( f, fighterStatus[ f ].mission )
-- fighterStatus[ f ].timeForNextHookup = fighterStatus[ f ].timeForNextHookup + oneHour
fighterStatus[ f ].timeForNextOnStation = fighterStatus[ f ].timeForNextOnStation + 2* oneHour -- two hours, time for tanking + capping
end
end
end
end
There's a little bit of extraneous code in there I don't need. I'll try to clean it up later.
