-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskynet-iads-contact.lua
More file actions
151 lines (124 loc) · 4.14 KB
/
skynet-iads-contact.lua
File metadata and controls
151 lines (124 loc) · 4.14 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
do
SkynetIADSContact = {}
SkynetIADSContact = inheritsFrom(SkynetIADSAbstractDCSObjectWrapper)
SkynetIADSContact.CLIMB = "CLIMB"
SkynetIADSContact.DESCEND = "DESCEND"
SkynetIADSContact.HARM = "HARM"
SkynetIADSContact.NOT_HARM = "NOT_HARM"
SkynetIADSContact.HARM_UNKNOWN = "HARM_UNKNOWN"
function SkynetIADSContact:create(dcsRadarTarget, abstractRadarElementDetected)
local instance = self:superClass():create(dcsRadarTarget.object)
setmetatable(instance, self)
self.__index = self
instance.abstractRadarElementsDetected = {}
table.insert(instance.abstractRadarElementsDetected, abstractRadarElementDetected)
instance.firstContactTime = timer.getAbsTime()
instance.lastTimeSeen = 0
instance.dcsRadarTarget = dcsRadarTarget
instance.position = instance:getDCSRepresentation():getPosition()
instance.numOfTimesRefreshed = 0
instance.speed = 0
instance.harmState = SkynetIADSContact.HARM_UNKNOWN
instance.simpleAltitudeProfile = {}
return instance
end
function SkynetIADSContact:setHARMState(state)
self.harmState = state
end
function SkynetIADSContact:getHARMState()
return self.harmState
end
function SkynetIADSContact:isIdentifiedAsHARM()
return self.harmState == SkynetIADSContact.HARM
end
function SkynetIADSContact:isHARMStateUnknown()
return self.harmState == SkynetIADSContact.HARM_UNKNOWN
end
function SkynetIADSContact:getMagneticHeading()
if ( self:isExist() ) then
return mist.utils.round(mist.utils.toDegree(mist.getHeading(self:getDCSRepresentation())))
else
return -1
end
end
function SkynetIADSContact:getAbstractRadarElementsDetected()
return self.abstractRadarElementsDetected
end
function SkynetIADSContact:addAbstractRadarElementDetected(radar)
self:insertToTableIfNotAlreadyAdded(self.abstractRadarElementsDetected, radar)
end
function SkynetIADSContact:isTypeKnown()
return self.dcsRadarTarget.type
end
function SkynetIADSContact:isDistanceKnown()
return self.dcsRadarTarget.distance
end
function SkynetIADSContact:getTypeName()
if self:isIdentifiedAsHARM() then
return SkynetIADSContact.HARM
end
local category = self:getDCSRepresentation():getCategory()
if category == Object.Category.UNIT then
return self.typeName
end
return "UNKNOWN"
end
function SkynetIADSContact:getPosition()
return self.position
end
function SkynetIADSContact:getGroundSpeedInKnots(decimals)
if decimals == nil then
decimals = 2
end
return mist.utils.round(self.speed, decimals)
end
function SkynetIADSContact:getHeightInFeetMSL()
if self:isExist() then
return mist.utils.round(mist.utils.metersToFeet(self:getDCSRepresentation():getPosition().p.y), 0)
else
return 0
end
end
function SkynetIADSContact:getDesc()
if self:isExist() then
return self:getDCSRepresentation():getDesc()
else
return {}
end
end
function SkynetIADSContact:getNumberOfTimesHitByRadar()
return self.numOfTimesRefreshed
end
function SkynetIADSContact:refresh()
if self:isExist() then
local timeDelta = (timer.getAbsTime() - self.lastTimeSeen)
if timeDelta > 0 then
self.numOfTimesRefreshed = self.numOfTimesRefreshed + 1
local distance = mist.utils.metersToNM(mist.utils.get2DDist(self.position.p, self:getDCSRepresentation():getPosition().p))
local hours = timeDelta / 3600
self.speed = (distance / hours)
self:updateSimpleAltitudeProfile()
self.position = self:getDCSRepresentation():getPosition()
end
end
self.lastTimeSeen = timer.getAbsTime()
end
function SkynetIADSContact:updateSimpleAltitudeProfile()
local currentAltitude = self:getDCSRepresentation():getPosition().p.y
local previousPath = ""
if #self.simpleAltitudeProfile > 0 then
previousPath = self.simpleAltitudeProfile[#self.simpleAltitudeProfile]
end
if self.position.p.y > currentAltitude and previousPath ~= SkynetIADSContact.DESCEND then
table.insert(self.simpleAltitudeProfile, SkynetIADSContact.DESCEND)
elseif self.position.p.y < currentAltitude and previousPath ~= SkynetIADSContact.CLIMB then
table.insert(self.simpleAltitudeProfile, SkynetIADSContact.CLIMB)
end
end
function SkynetIADSContact:getSimpleAltitudeProfile()
return self.simpleAltitudeProfile
end
function SkynetIADSContact:getAge()
return mist.utils.round(timer.getAbsTime() - self.lastTimeSeen)
end
end