I'm creating a small scenario that gives some solid replay value.
Goal is to have random opfor aircraft patrols start & launch from single unit airfields
I have code generating randomized single unit airbases - 4 different locations
I want to then take the location of that single unit base and generate a patrol for that given location
I'm going to share what I've managed to put together but I would appreciate thoughts on how to create a patrol mission around the farp without hardcoding the locations. Code is incomplete
Code: Select all
math.randomseed(os.time())
math.random(); math.random(); math.random()
a = math.random(1,3) -- random airbase locations and cap missions
b = math.random(1,6) -- random additional A/C
function CreateAirBase(basename,latlonTable, singleunitAF, sam, radar)
local lat=latlonTable['latitude']
local lon=latlonTable['longitude']
for i=1,singleunitAF do
local u = ScenEdit_AddUnit({side='PLA', type='Facility', name='Single Unit Airfield '..i, autodetectable="false", dbid=1593, Lat=lat, Lon=lon})
u.group ='PLA AB (PLAAF)'
lat=lat +.004
end
lon=latlonTable['longitude'] + .008
for i=1,sam do
local u = ScenEdit_AddUnit({side='PLA', type='Facility', name='sam'..i, autodetectable="false", dbid=2991, Lat=lat, Lon=lon}) --HQ-16B
u.group ='PLA AB (PLAAF)'
lat=lat +.002
end
lon=latlonTable['longitude'] + .008
for i=1,radar do
local u = ScenEdit_AddUnit({side='PLA', type='Facility', name='radar'..i, autodetectable="false", dbid=2537, Lat=lat, Lon=lon}) --JY-26
u.group ='PLA AB (PLAAF)'
lat=lat +.002
end
end
local function AddACToBase(side,baseName,aircraftDBID,aircraftQty,aircraftNamePrefix,loadoutDBID,missionName)
local baseData = ScenEdit_GetUnit({side=side,name=baseName})
for i = 1,aircraftQty do
local unit = ScenEdit_AddUnit({
side=side,
name=aircraftNamePrefix.." #"..i,
type='Aircraft',
dbid=aircraftDBID,
loadoutid=loadoutDBID,
base=baseData.guid,
})
if missionName ~= nil then
local missionData = ScenEdit_GetMission(side,missionName)
ScenEdit_AssignUnitToMission(unit.guid,missionData.guid)
end
end
print (baseName..' done..........')
end
if a == 1 then
CreateAirBase('PLA AB (PLAAF)',{},1,1,1) -- need to find suitiable locations
--[[ ScenEdit_AddReferencePoint(
{side='PLA', name='CAP1A', RelativeTo='PLA AB (PLAAF)', bearing=0 ,distance=35, clear=true },
{side='PLA', name='CAP1B', RelativeTo='PLA AB (PLAAF)', bearing=45 ,distance=35, clear=true }, -- need to figure out how to add a table of RPs dynamic to a generated unit
{side='PLA', name='CAP1C', RelativeTo='PLA AB (PLAAF)', bearing=90 ,distance=35, clear=true },
{side='PLA', name='CAP1D', RelativeTo='PLA AB (PLAAF)', bearing=180 ,distance=35, clear=true })
ScenEdit_AddMission('PLA','CAP1','patrol',{type='AAW'})
ScenEdit_SetMission('PLA', 'CAP1', {isactive=true,{} }) -- need to add the table of RPs to this
]]--
AddACToBase('PLA AB (PLAAF)', 2463, 12, 'J-20B Mighty', 9606, 'CAP1')
AddACToBase('PLA AB (PLAAF)', 5013, 24, 'J-20B-', 28006, 'CAP1')
AddACToBase('PLA AB (PLAAF)', 5013, 12, 'J-20B-', 28006, 'CAP1')
AddACToBase('PLA AB (PLAAF)', 5435, 16, 'J-6F-', 29946, 'Mock')
AddACToBase('PLA AB (PLAAF)', 4547, 12, 'Su-35K Flanker E-', 23066, 'CAP1')
elseif a == 2 then
--- wip
elseif a == 3 then
--- wip