Skip to content

Instantly share code, notes, and snippets.

@yiyuezhuo
Last active February 20, 2023 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yiyuezhuo/70337fe80737be8f3806a59d53a2671d to your computer and use it in GitHub Desktop.
Save yiyuezhuo/70337fe80737be8f3806a59d53a2671d to your computer and use it in GitHub Desktop.
CMO_Detection_Test_automation
Executor = {
attacker_list=nil,
defender=nil,
}
Executor.__index = Executor
function Executor:new()
local o = {}
setmetatable(o, self)
return o
end
function Executor:clear()
if self.defender ~= nil then
ScenEdit_DeleteUnit({side=self.defender.side, unitname=self.defender.name}, true)
end
self.defender = nil
if self.attacker_list ~= nil then
for _, unit in ipairs(self.attacker_list) do
ScenEdit_DeleteUnit({side=unit.side, unitname=unit.name}, true)
end
end
self.attacker_list = nil
end
function Executor:execute(attacker_desc, defender_desc, schedule, EMCON_str)
-- desc = {type ='Air', loadoutid =16934, dbid =3500, side =side, alt=10000}
-- EMCON_str = "Radar=Active", "Radar=Active;OECM=Active"
local point = ScenEdit_GetReferencePoint{ side=schedule.rp_side, name=schedule.rp_name}
if point == nil then
print("point doesn't exist")
return
end
self:clear()
local defender_args = {unitname="name", Lat=point.latitude, Lon=point.longitude}
for k,v in pairs(defender_desc) do defender_args[k] = v end
self.defender = ScenEdit_AddUnit(defender_args) -- "setmetatable" doesn't do the trick here, we must copy
ScenEdit_SetUnit{guid=self.defender.guid, newname=self.defender.guid}
ScenEdit_SetEMCON("Unit", self.defender.name, "Radar=Active")
if self.defender == nil then
print("Failed to create defender:" .. self.defender)
return
end
self.attacker_list = {}
local offset_rad = math.rad(schedule.offset_deg)
for i= 1, schedule.batch_size do
local p = i / schedule.batch_size
local latitude = point.latitude + schedule.radius * math.cos(p * math.pi * 2 + offset_rad)
local longitude = point.longitude + schedule.radius * math.sin(p * math.pi*2 + offset_rad)
local attacker_args = {unitname="name", Lat=latitude, Lon=longitude}
for k,v in pairs(attacker_desc) do attacker_args[k] = v end
local attacker = ScenEdit_AddUnit(attacker_args)
if attacker == nil then
print("failed to create attacker:" .. attacker)
return
end
ScenEdit_SetUnit{
guid=attacker.guid,
newname=attacker.guid,
manualaltitude=attacker.altitude,
course={[1] = {lat=point.latitude, lon=point.longitude}}
}
ScenEdit_SetEMCON("Unit", attacker.name, EMCON_str)
table.insert(self.attacker_list, attacker)
end
end
attacker_desc = {
type ='AIRCRAFT',
loadoutid =32334, -- AGM-158B JASSM-ER (Standoff Strike, Land)
dbid =6158, -- B-21
side ="Blue",
alt="High" -- "High", "Medium", ... or meters (yeah... while they show ft only in the UI)
-- alt=500
-- alt=600
}
defender_desc = {
type = "FACILITY",
-- dbid = 2442, -- S-400 (China, 2018)
dbid = 3280, -- SAM Bn (HQ-9B) (China-2010)
-- dbid = 386, -- SAM Bn (SA-20b Gargoyle [S-300PMU-2 Favorit]) (China - 2008)
-- dbid = 2442, -- SAM Bn (SA-21a/b Growler [S-400E Triumf]) (China - 2018)
-- dbid = 3598, -- Radar (China HT-233 [HQ-9]) (China 2015)
-- dbid = 2991, -- SAM Bty (HQ-16B) (China -2016)
-- dbid = 3036, -- SAM Plt (HQ-17 [SA-15 Copy] + 35mm PGZ-07 SPAAG) (China-2016)
-- dbid = 3281, -- SAM Bn (HQ-22) (China - 2018)
-- dbid = 2537, -- Radar (China JY-26) (China - 2015)
side = "Red"
}
schedule = {
rp_side="Red",
rp_name="Test",
radius=1.0,
batch_size=5,
offset_deg=0
}
-- EMCON_str = "Radar=Active;OECM=Active"
EMCON_str = "Radar=Passive;OECM=Active"
-- EMCON_str = "Radar=Passive;OECM=Passive"
-- executor = Executor:new()
executor:execute(attacker_desc, defender_desc, schedule, EMCON_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment