-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskynet-iads-harm-detection.lua
More file actions
138 lines (120 loc) · 4.37 KB
/
skynet-iads-harm-detection.lua
File metadata and controls
138 lines (120 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
do
SkynetIADSHARMDetection = {}
SkynetIADSHARMDetection.__index = SkynetIADSHARMDetection
SkynetIADSHARMDetection.HARM_THRESHOLD_SPEED_KTS = 800
function SkynetIADSHARMDetection:create(iads)
local harmDetection = {}
setmetatable(harmDetection, self)
harmDetection.contacts = {}
harmDetection.iads = iads
harmDetection.contactRadarsEvaluated = {}
return harmDetection
end
function SkynetIADSHARMDetection:setContacts(contacts)
self.contacts = contacts
end
function SkynetIADSHARMDetection:evaluateContacts()
self:cleanAgedContacts()
for i = 1, #self.contacts do
local contact = self.contacts[i]
local groundSpeed = contact:getGroundSpeedInKnots(0)
--if a contact has only been hit by a radar once it's speed is 0
if groundSpeed == 0 then
return
end
local simpleAltitudeProfile = contact:getSimpleAltitudeProfile()
local newRadarsToEvaluate = self:getNewRadarsThatHaveDetectedContact(contact)
--self.iads:printOutputToLog(contact:getName().." new Radars to evaluate: "..#newRadarsToEvaluate)
--self.iads:printOutputToLog(contact:getName().." ground speed: "..groundSpeed)
if ( #newRadarsToEvaluate > 0 and contact:isIdentifiedAsHARM() == false and ( groundSpeed > SkynetIADSHARMDetection.HARM_THRESHOLD_SPEED_KTS and #simpleAltitudeProfile <= 2 ) ) then
local detectionProbability = self:getDetectionProbability(newRadarsToEvaluate)
--self.iads:printOutputToLog("DETECTION PROB: "..detectionProbability)
if ( self:shallReactToHARM(detectionProbability) ) then
contact:setHARMState(SkynetIADSContact.HARM)
if (self.iads:getDebugSettings().harmDefence ) then
self.iads:printOutputToLog("HARM IDENTIFIED: "..contact:getTypeName().." | DETECTION PROBABILITY WAS: "..detectionProbability.."%")
end
else
contact:setHARMState(SkynetIADSContact.NOT_HARM)
if (self.iads:getDebugSettings().harmDefence ) then
self.iads:printOutputToLog("HARM NOT IDENTIFIED: "..contact:getTypeName().." | DETECTION PROBABILITY WAS: "..detectionProbability.."%")
end
end
end
if ( #simpleAltitudeProfile > 2 and contact:isIdentifiedAsHARM() ) then
contact:setHARMState(SkynetIADSContact.HARM_UNKNOWN)
if (self.iads:getDebugSettings().harmDefence ) then
self.iads:printOutputToLog("CORRECTING HARM STATE: CONTACT IS NOT A HARM: "..contact:getName())
end
end
if ( contact:isIdentifiedAsHARM() ) then
self:informRadarsOfHARM(contact)
end
end
end
function SkynetIADSHARMDetection:cleanAgedContacts()
local activeContactRadars = {}
for contact, radars in pairs (self.contactRadarsEvaluated) do
if contact:getAge() < 32 then
activeContactRadars[contact] = radars
end
end
self.contactRadarsEvaluated = activeContactRadars
end
function SkynetIADSHARMDetection:getNewRadarsThatHaveDetectedContact(contact)
local newRadars = contact:getAbstractRadarElementsDetected()
local radars = self.contactRadarsEvaluated[contact]
if radars then
newRadars = {}
local contactRadars = contact:getAbstractRadarElementsDetected()
for i = 1, #contactRadars do
local contactRadar = contactRadars[i]
local newRadar = self:isElementInTable(radars, contactRadar)
if newRadar ~= nil then
table.insert(newRadars, newRadar)
end
end
end
self.contactRadarsEvaluated[contact] = contact:getAbstractRadarElementsDetected()
return newRadars
end
function SkynetIADSHARMDetection:isElementInTable(tbl, element)
for i = 1, #tbl do
tblElement = tbl[i]
if tblElement == element then
return nil
end
end
return element
end
function SkynetIADSHARMDetection:informRadarsOfHARM(contact)
local samSites = self.iads:getUsableSAMSites()
self:updateRadarsOfSites(samSites, contact)
local ewRadars = self.iads:getUsableEarlyWarningRadars()
self:updateRadarsOfSites(ewRadars, contact)
end
function SkynetIADSHARMDetection:updateRadarsOfSites(sites, contact)
for i = 1, #sites do
local site = sites[i]
site:informOfHARM(contact)
end
end
function SkynetIADSHARMDetection:shallReactToHARM(chance)
return chance >= math.random(1, 100)
end
function SkynetIADSHARMDetection:getDetectionProbability(radars)
local detectionChance = 0
local missChance = 100
local detection = 0
for i = 1, #radars do
detection = radars[i]:getHARMDetectionChance()
if ( detectionChance == 0 ) then
detectionChance = detection
else
detectionChance = detectionChance + (detection * (missChance / 100))
end
missChance = 100 - detection
end
return detectionChance
end
end