Small changes

#CSAR - add option for IR strobe
This commit is contained in:
Applevangelist 2024-09-08 13:22:10 +02:00
parent d62025dfe0
commit 7f572a1a9b
3 changed files with 149 additions and 73 deletions

View File

@ -117,6 +117,8 @@
-- mycsar.topmenuname = "CSAR" -- set the menu entry name -- mycsar.topmenuname = "CSAR" -- set the menu entry name
-- mycsar.ADFRadioPwr = 1000 -- ADF Beacons sending with 1KW as default -- mycsar.ADFRadioPwr = 1000 -- ADF Beacons sending with 1KW as default
-- mycsar.PilotWeight = 80 -- Loaded pilots weigh 80kgs each -- mycsar.PilotWeight = 80 -- Loaded pilots weigh 80kgs each
-- mycsar.AllowIRStrobe = false -- Allow a menu item to request an IR strobe to find a downed pilot at night (requires NVGs to see it).
-- mycsar.IRStrobeRuntime = 300 -- If an IR Strobe is activated, it runs for 300 seconds (5 mins).
-- --
-- ## 2.1 Create own SET_GROUP to manage CTLD Pilot groups -- ## 2.1 Create own SET_GROUP to manage CTLD Pilot groups
-- --
@ -267,6 +269,8 @@ CSAR = {
PilotWeight = 80, PilotWeight = 80,
CreateRadioBeacons = true, CreateRadioBeacons = true,
UserSetGroup = nil, UserSetGroup = nil,
AllowIRStrobe = false,
IRStrobeRuntime = 300,
} }
--- Downed pilots info. --- Downed pilots info.
@ -309,7 +313,7 @@ CSAR.AircraftType["CH-47Fbl1"] = 31
--- CSAR class version. --- CSAR class version.
-- @field #string version -- @field #string version
CSAR.version="1.0.28" CSAR.version="1.0.29"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list -- ToDo list
@ -753,7 +757,6 @@ function CSAR:_SpawnPilotInField(country,point,frequency,wetfeet)
:NewWithAlias(template,alias) :NewWithAlias(template,alias)
:InitCoalition(coalition) :InitCoalition(coalition)
:InitCountry(country) :InitCountry(country)
--:InitAIOnOff(pilotcacontrol)
:InitDelayOff() :InitDelayOff()
:SpawnFromCoordinate(point) :SpawnFromCoordinate(point)
@ -1818,9 +1821,6 @@ function CSAR:_DisplayMessageToSAR(_unit, _text, _time, _clear, _speak, _overrid
end end
_text = string.gsub(_text,"km"," kilometer") _text = string.gsub(_text,"km"," kilometer")
_text = string.gsub(_text,"nm"," nautical miles") _text = string.gsub(_text,"nm"," nautical miles")
--self.msrs:SetVoice(self.SRSVoice)
--self.SRSQueue:NewTransmission(_text,nil,self.msrs,nil,1)
--self:I("Voice = "..self.SRSVoice)
self.SRSQueue:NewTransmission(_text,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,self.SRSVoice,volume,label,coord) self.SRSQueue:NewTransmission(_text,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,self.SRSVoice,volume,label,coord)
end end
return self return self
@ -1966,7 +1966,7 @@ function CSAR:_SignalFlare(_unitName)
else else
_distance = string.format("%.1fkm",_closest.distance/1000) _distance = string.format("%.1fkm",_closest.distance/1000)
end end
local _msg = string.format("%s - Popping signal flare at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance) local _msg = string.format("%s - Firing signal flare at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance)
self:_DisplayMessageToSAR(_heli, _msg, self.messageTime, false, true, true) self:_DisplayMessageToSAR(_heli, _msg, self.messageTime, false, true, true)
local _coord = _closest.pilot:GetCoordinate() local _coord = _closest.pilot:GetCoordinate()
@ -2000,7 +2000,7 @@ function CSAR:_DisplayToAllSAR(_message, _side, _messagetime,ToSRS,ToScreen)
if self.msrs:GetProvider() == MSRS.Provider.WINDOWS then if self.msrs:GetProvider() == MSRS.Provider.WINDOWS then
voice = self.CSARVoiceMS or MSRS.Voices.Microsoft.Hedda voice = self.CSARVoiceMS or MSRS.Voices.Microsoft.Hedda
end end
self:F("Voice = "..voice) --self:F("Voice = "..voice)
self.SRSQueue:NewTransmission(_message,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,voice,volume,label,self.coordinate) self.SRSQueue:NewTransmission(_message,duration,self.msrs,tstart,2,subgroups,subtitle,subduration,self.SRSchannel,self.SRSModulation,gender,culture,voice,volume,label,self.coordinate)
end end
if ToScreen == true or ToScreen == nil then if ToScreen == true or ToScreen == nil then
@ -2014,6 +2014,41 @@ function CSAR:_DisplayToAllSAR(_message, _side, _messagetime,ToSRS,ToScreen)
return self return self
end end
---(Internal) Request IR Strobe at closest downed pilot.
--@param #CSAR self
--@param #string _unitName Name of the helicopter
function CSAR:_ReqIRStrobe( _unitName )
self:T(self.lid .. " _ReqIRStrobe")
local _heli = self:_GetSARHeli(_unitName)
if _heli == nil then
return
end
local smokedist = 8000
if smokedist < self.approachdist_far then smokedist = self.approachdist_far end
local _closest = self:_GetClosestDownedPilot(_heli)
if _closest ~= nil and _closest.pilot ~= nil and _closest.distance > 0 and _closest.distance < smokedist then
local _clockDir = self:_GetClockDirection(_heli, _closest.pilot)
local _distance = string.format("%.1fkm",_closest.distance/1000)
if _SETTINGS:IsImperial() then
_distance = string.format("%.1fnm",UTILS.MetersToNM(_closest.distance))
else
_distance = string.format("%.1fkm",_closest.distance/1000)
end
local _msg = string.format("%s - IR Strobe active at your %s o\'clock. Distance %s", self:_GetCustomCallSign(_unitName), _clockDir, _distance)
self:_DisplayMessageToSAR(_heli, _msg, self.messageTime, false, true, true)
_closest.pilot:NewIRMarker(true,self.IRStrobeRuntime or 300)
else
local _distance = string.format("%.1fkm",smokedist/1000)
if _SETTINGS:IsImperial() then
_distance = string.format("%.1fnm",UTILS.MetersToNM(smokedist))
else
_distance = string.format("%.1fkm",smokedist/1000)
end
self:_DisplayMessageToSAR(_heli, string.format("No Pilots within %s",_distance), self.messageTime, false, false, true)
end
return self
end
---(Internal) Request smoke at closest downed pilot. ---(Internal) Request smoke at closest downed pilot.
--@param #CSAR self --@param #CSAR self
--@param #string _unitName Name of the helicopter --@param #string _unitName Name of the helicopter
@ -2165,7 +2200,12 @@ function CSAR:_AddMedevacMenuItem()
local _rootMenu1 = MENU_GROUP_COMMAND:New(_group,"List Active CSAR",_rootPath, self._DisplayActiveSAR,self,_unitName) local _rootMenu1 = MENU_GROUP_COMMAND:New(_group,"List Active CSAR",_rootPath, self._DisplayActiveSAR,self,_unitName)
local _rootMenu2 = MENU_GROUP_COMMAND:New(_group,"Check Onboard",_rootPath, self._CheckOnboard,self,_unitName) local _rootMenu2 = MENU_GROUP_COMMAND:New(_group,"Check Onboard",_rootPath, self._CheckOnboard,self,_unitName)
local _rootMenu3 = MENU_GROUP_COMMAND:New(_group,"Request Signal Flare",_rootPath, self._SignalFlare,self,_unitName) local _rootMenu3 = MENU_GROUP_COMMAND:New(_group,"Request Signal Flare",_rootPath, self._SignalFlare,self,_unitName)
local _rootMenu4 = MENU_GROUP_COMMAND:New(_group,"Request Smoke",_rootPath, self._Reqsmoke,self,_unitName):Refresh() local _rootMenu4 = MENU_GROUP_COMMAND:New(_group,"Request Smoke",_rootPath, self._Reqsmoke,self,_unitName)
if self.AllowIRStrobe then
local _rootMenu5 = MENU_GROUP_COMMAND:New(_group,"Request IR Strobe",_rootPath, self._ReqIRStrobe,self,_unitName):Refresh()
else
_rootMenu4:Refresh()
end
end end
end end
end end

View File

@ -360,14 +360,25 @@ end
-- @return DCS#Group The DCS Group. -- @return DCS#Group The DCS Group.
function GROUP:GetDCSObject() function GROUP:GetDCSObject()
if (not self.LastCallDCSObject) or (self.LastCallDCSObject and timer.getTime() - self.LastCallDCSObject > 1) then
-- Get DCS group. -- Get DCS group.
local DCSGroup = Group.getByName( self.GroupName ) local DCSGroup = Group.getByName( self.GroupName )
if DCSGroup then if DCSGroup then
self.LastCallDCSObject = timer.getTime()
self.DCSObject = DCSGroup
return DCSGroup return DCSGroup
else
self.DCSObject = nil
self.LastCallDCSObject = nil
end end
--self:T2(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.GroupName))) else
return self.DCSObject
end
--self:E(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.GroupName)))
return nil return nil
end end

View File

@ -219,6 +219,7 @@ function UNIT:Name()
return self.UnitName return self.UnitName
end end
--[[
--- Get the DCS unit object. --- Get the DCS unit object.
-- @param #UNIT self -- @param #UNIT self
-- @return DCS#Unit The DCS unit object. -- @return DCS#Unit The DCS unit object.
@ -230,10 +231,34 @@ function UNIT:GetDCSObject()
return DCSUnit return DCSUnit
end end
--if self.DCSUnit then return nil
--return self.DCSUnit end
--end --]]
--- Returns the DCS Unit.
-- @param #UNIT self
-- @return DCS#Unit The DCS Group.
function UNIT:GetDCSObject()
if (not self.LastCallDCSObject) or (self.LastCallDCSObject and timer.getTime() - self.LastCallDCSObject > 1) then
-- Get DCS group.
local DCSUnit = Unit.getByName( self.UnitName )
if DCSUnit then
self.LastCallDCSObject = timer.getTime()
self.DCSObject = DCSUnit
return DCSUnit
else
self.DCSObject = nil
self.LastCallDCSObject = nil
end
else
return self.DCSObject
end
--self:E(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.UnitName)))
return nil return nil
end end
@ -243,7 +268,7 @@ end
-- @return #number The height of the group or nil if is not existing or alive. -- @return #number The height of the group or nil if is not existing or alive.
function UNIT:GetAltitude(FromGround) function UNIT:GetAltitude(FromGround)
local DCSUnit = Unit.getByName( self.UnitName ) local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local altitude = 0 local altitude = 0
@ -273,12 +298,12 @@ end
-- @param #number Heading The heading of the unit respawn. -- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawnAt( Coordinate, Heading ) function UNIT:ReSpawnAt( Coordinate, Heading )
self:T( self:Name() ) --self:T( self:Name() )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) ) local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
self:T( SpawnGroupTemplate ) --self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup() local SpawnGroup = self:GetGroup()
self:T( { SpawnGroup = SpawnGroup } ) --self:T( { SpawnGroup = SpawnGroup } )
if SpawnGroup then if SpawnGroup then
@ -286,10 +311,10 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.x = Coordinate.x SpawnGroupTemplate.x = Coordinate.x
SpawnGroupTemplate.y = Coordinate.z SpawnGroupTemplate.y = Coordinate.z
self:F( #SpawnGroupTemplate.units ) --self:F( #SpawnGroupTemplate.units )
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() or {} ) do for UnitID, UnitData in pairs( SpawnGroup:GetUnits() or {} ) do
local GroupUnit = UnitData -- #UNIT local GroupUnit = UnitData -- #UNIT
self:F( GroupUnit:GetName() ) --self:F( GroupUnit:GetName() )
if GroupUnit:IsAlive() then if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading() local GroupUnitHeading = GroupUnit:GetHeading()
@ -297,23 +322,23 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x
SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z
SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading
self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } ) --self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } )
end end
end end
end end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
self:T( { UnitTemplateData.name, self:Name() } ) --self:T( { UnitTemplateData.name, self:Name() } )
SpawnGroupTemplate.units[UnitTemplateID].unitId = nil SpawnGroupTemplate.units[UnitTemplateID].unitId = nil
if UnitTemplateData.name == self:Name() then if UnitTemplateData.name == self:Name() then
self:T("Adjusting") --self:T("Adjusting")
SpawnGroupTemplate.units[UnitTemplateID].alt = Coordinate.y SpawnGroupTemplate.units[UnitTemplateID].alt = Coordinate.y
SpawnGroupTemplate.units[UnitTemplateID].x = Coordinate.x SpawnGroupTemplate.units[UnitTemplateID].x = Coordinate.x
SpawnGroupTemplate.units[UnitTemplateID].y = Coordinate.z SpawnGroupTemplate.units[UnitTemplateID].y = Coordinate.z
SpawnGroupTemplate.units[UnitTemplateID].heading = Heading SpawnGroupTemplate.units[UnitTemplateID].heading = Heading
self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } ) --self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
else else
self:F( SpawnGroupTemplate.units[UnitTemplateID].name ) --self:F( SpawnGroupTemplate.units[UnitTemplateID].name )
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT
if GroupUnit and GroupUnit:IsAlive() then if GroupUnit and GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
@ -324,7 +349,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
UnitTemplateData.heading = GroupUnitHeading UnitTemplateData.heading = GroupUnitHeading
else else
if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then
self:T("nilling") --self:T("nilling")
SpawnGroupTemplate.units[UnitTemplateID].delete = true SpawnGroupTemplate.units[UnitTemplateID].delete = true
end end
end end
@ -336,7 +361,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
while i <= #SpawnGroupTemplate.units do while i <= #SpawnGroupTemplate.units do
local UnitTemplateData = SpawnGroupTemplate.units[i] local UnitTemplateData = SpawnGroupTemplate.units[i]
self:T( UnitTemplateData.name ) --self:T( UnitTemplateData.name )
if UnitTemplateData.delete then if UnitTemplateData.delete then
table.remove( SpawnGroupTemplate.units, i ) table.remove( SpawnGroupTemplate.units, i )
@ -347,7 +372,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.groupId = nil SpawnGroupTemplate.groupId = nil
self:T( SpawnGroupTemplate ) --self:T( SpawnGroupTemplate )
_DATABASE:Spawn( SpawnGroupTemplate ) _DATABASE:Spawn( SpawnGroupTemplate )
end end
@ -358,7 +383,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive. -- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive.
function UNIT:IsActive() function UNIT:IsActive()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -395,7 +420,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean Returns `true` if Unit is alive and active, `false` if it exists but is not active and `nil` if the object does not exist or DCS `isExist` function returns false. -- @return #boolean Returns `true` if Unit is alive and active, `false` if it exists but is not active and `nil` if the object does not exist or DCS `isExist` function returns false.
function UNIT:IsAlive() function UNIT:IsAlive()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit local DCSUnit = self:GetDCSObject() -- DCS#Unit
@ -418,7 +443,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string The Callsign of the Unit. -- @return #string The Callsign of the Unit.
function UNIT:GetCallsign() function UNIT:GetCallsign()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -430,7 +455,7 @@ function UNIT:GetCallsign()
return UnitCallSign return UnitCallSign
end end
self:F( self.ClassName .. " " .. self.UnitName .. " not found!" ) --self:F( self.ClassName .. " " .. self.UnitName .. " not found!" )
return nil return nil
end end
@ -477,7 +502,7 @@ end
-- @return #string Player Name -- @return #string Player Name
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPlayerName() function UNIT:GetPlayerName()
self:F( self.UnitName ) --self:F( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit local DCSUnit = self:GetDCSObject() -- DCS#Unit
@ -551,7 +576,7 @@ end
-- @return #number The Unit number. -- @return #number The Unit number.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetNumber() function UNIT:GetNumber()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -568,7 +593,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Speed in km/h. -- @return #number Speed in km/h.
function UNIT:GetSpeedMax() function UNIT:GetSpeedMax()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local Desc = self:GetDesc() local Desc = self:GetDesc()
@ -585,7 +610,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Range in meters. -- @return #number Range in meters.
function UNIT:GetRange() function UNIT:GetRange()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local Desc = self:GetDesc() local Desc = self:GetDesc()
@ -607,7 +632,7 @@ end
-- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable"). -- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable").
-- @return #number Refueling system (if any): 0=boom, 1=probe. -- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsRefuelable() function UNIT:IsRefuelable()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local refuelable=self:HasAttribute("Refuelable") local refuelable=self:HasAttribute("Refuelable")
@ -626,7 +651,7 @@ end
-- @return #boolean If true, unit is a tanker (checks for the attribute "Tankers"). -- @return #boolean If true, unit is a tanker (checks for the attribute "Tankers").
-- @return #number Refueling system (if any): 0=boom, 1=probe. -- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsTanker() function UNIT:IsTanker()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local tanker=self:HasAttribute("Tankers") local tanker=self:HasAttribute("Tankers")
@ -725,7 +750,7 @@ end
-- @param Wrapper.Unit#UNIT self -- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist. -- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist.
function UNIT:GetGroup() function UNIT:GetGroup()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local UnitGroup = GROUP:FindByName(self.GroupName) local UnitGroup = GROUP:FindByName(self.GroupName)
if UnitGroup then if UnitGroup then
return UnitGroup return UnitGroup
@ -749,13 +774,13 @@ end
-- @return #string The name of the DCS Unit. -- @return #string The name of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPrefix() function UNIT:GetPrefix()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 ) local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 )
self:T3( UnitPrefix ) --self:T3( UnitPrefix )
return UnitPrefix return UnitPrefix
end end
@ -766,7 +791,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table! -- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table!
function UNIT:GetAmmo() function UNIT:GetAmmo()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
--local status, unitammo = pcall( --local status, unitammo = pcall(
@ -958,7 +983,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return DCS#Unit.Sensors Table of sensors. -- @return DCS#Unit.Sensors Table of sensors.
function UNIT:GetSensors() function UNIT:GetSensors()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -977,7 +1002,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors. -- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors.
function UNIT:HasSensors( ... ) function UNIT:HasSensors( ... )
self:F2( arg ) --self:F2( arg )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -993,7 +1018,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean returns true if the unit is SEADable. -- @return #boolean returns true if the unit is SEADable.
function UNIT:HasSEAD() function UNIT:HasSEAD()
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1021,7 +1046,7 @@ end
-- @return #boolean Indicates if at least one of the unit's radar(s) is on. -- @return #boolean Indicates if at least one of the unit's radar(s) is on.
-- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target. -- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
function UNIT:GetRadar() function UNIT:GetRadar()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1037,7 +1062,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The relative amount of fuel (from 0.0 to 1.0) or *nil* if the DCS Unit is not existing or alive. -- @return #number The relative amount of fuel (from 0.0 to 1.0) or *nil* if the DCS Unit is not existing or alive.
function UNIT:GetFuel() function UNIT:GetFuel()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1054,14 +1079,14 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}. -- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}.
function UNIT:GetUnits() function UNIT:GetUnits()
self:F3( { self.UnitName } ) --self:F3( { self.UnitName } )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
local Units = {} local Units = {}
if DCSUnit then if DCSUnit then
Units[1] = UNIT:Find( DCSUnit ) Units[1] = UNIT:Find( DCSUnit )
self:T3( Units ) -self:T3( Units )
return Units return Units
end end
@ -1073,7 +1098,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's health value or -1 if unit does not exist any more. -- @return #number The Unit's health value or -1 if unit does not exist any more.
function UNIT:GetLife() function UNIT:GetLife()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1089,7 +1114,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's initial health value or 0 if unit does not exist any more. -- @return #number The Unit's initial health value or 0 if unit does not exist any more.
function UNIT:GetLife0() function UNIT:GetLife0()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1105,7 +1130,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more. -- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more.
function UNIT:GetLifeRelative() function UNIT:GetLifeRelative()
self:F2(self.UnitName) --self:F2(self.UnitName)
if self and self:IsAlive() then if self and self:IsAlive() then
local life0=self:GetLife0() local life0=self:GetLife0()
@ -1120,7 +1145,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more. -- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more.
function UNIT:GetDamageRelative() function UNIT:GetDamageRelative()
self:F2(self.UnitName) --self:F2(self.UnitName)
if self and self:IsAlive() then if self and self:IsAlive() then
return 1-self:GetLifeRelative() return 1-self:GetLifeRelative()
@ -1158,7 +1183,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Unit category from `getDesc().category`. -- @return #number Unit category from `getDesc().category`.
function UNIT:GetUnitCategory() function UNIT:GetUnitCategory()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
@ -1172,7 +1197,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship -- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship
function UNIT:GetCategoryName() function UNIT:GetCategoryName()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
@ -1184,7 +1209,7 @@ function UNIT:GetCategoryName()
[Unit.Category.STRUCTURE] = "Structure", [Unit.Category.STRUCTURE] = "Structure",
} }
local UnitCategory = DCSUnit:getDesc().category local UnitCategory = DCSUnit:getDesc().category
self:T3( UnitCategory ) --self:T3( UnitCategory )
return CategoryNames[UnitCategory] return CategoryNames[UnitCategory]
end end
@ -1412,7 +1437,7 @@ end
-- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit. -- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:OtherUnitInRadius( AwaitUnit, Radius ) function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } ) --self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@ -1421,10 +1446,10 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
local AwaitUnitVec3 = AwaitUnit:GetVec3() local AwaitUnitVec3 = AwaitUnit:GetVec3()
if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then
self:T3( "true" ) --self:T3( "true" )
return true return true
else else
self:T3( "false" ) --self:T3( "false" )
return false return false
end end
end end
@ -1442,17 +1467,17 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean IsFriendly evaluation result. -- @return #boolean IsFriendly evaluation result.
function UNIT:IsFriendly( FriendlyCoalition ) function UNIT:IsFriendly( FriendlyCoalition )
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitCoalition = DCSUnit:getCoalition() local UnitCoalition = DCSUnit:getCoalition()
self:T3( { UnitCoalition, FriendlyCoalition } ) --self:T3( { UnitCoalition, FriendlyCoalition } )
local IsFriendlyResult = ( UnitCoalition == FriendlyCoalition ) local IsFriendlyResult = ( UnitCoalition == FriendlyCoalition )
self:F( IsFriendlyResult ) --self:F( IsFriendlyResult )
return IsFriendlyResult return IsFriendlyResult
end end
@ -1464,17 +1489,17 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean Ship category evaluation result. -- @return #boolean Ship category evaluation result.
function UNIT:IsShip() function UNIT:IsShip()
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitDescriptor = DCSUnit:getDesc() local UnitDescriptor = DCSUnit:getDesc()
self:T3( { UnitDescriptor.category, Unit.Category.SHIP } ) --self:T3( { UnitDescriptor.category, Unit.Category.SHIP } )
local IsShipResult = ( UnitDescriptor.category == Unit.Category.SHIP ) local IsShipResult = ( UnitDescriptor.category == Unit.Category.SHIP )
self:T3( IsShipResult ) --self:T3( IsShipResult )
return IsShipResult return IsShipResult
end end
@ -1486,7 +1511,7 @@ end
-- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed. -- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed.
-- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive. -- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive.
function UNIT:InAir(NoHeloCheck) function UNIT:InAir(NoHeloCheck)
self:F2( self.UnitName ) --self:F2( self.UnitName )
-- Get DCS unit object. -- Get DCS unit object.
local DCSUnit = self:GetDCSObject() --DCS#Unit local DCSUnit = self:GetDCSObject() --DCS#Unit
@ -1513,7 +1538,7 @@ function UNIT:InAir(NoHeloCheck)
end end
end end
self:T3( UnitInAir ) --self:T3( UnitInAir )
return UnitInAir return UnitInAir
end end
@ -1708,7 +1733,7 @@ end
-- @param #boolean switch If true, emission is enabled. If false, emission is disabled. -- @param #boolean switch If true, emission is enabled. If false, emission is disabled.
-- @return #UNIT self -- @return #UNIT self
function UNIT:EnableEmission(switch) function UNIT:EnableEmission(switch)
self:F2( self.UnitName ) --self:F2( self.UnitName )
local switch = switch or false local switch = switch or false
@ -1727,7 +1752,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string Skill String of skill name. -- @return #string Skill String of skill name.
function UNIT:GetSkill() function UNIT:GetSkill()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local name = self.UnitName local name = self.UnitName
local skill = "Random" local skill = "Random"
if _DATABASE.Templates.Units[name] and _DATABASE.Templates.Units[name].Template and _DATABASE.Templates.Units[name].Template.skill then if _DATABASE.Templates.Units[name] and _DATABASE.Templates.Units[name].Template and _DATABASE.Templates.Units[name].Template.skill then
@ -1743,7 +1768,7 @@ end
-- @return #string VCN Voice Callsign Number or nil if not set/capable. -- @return #string VCN Voice Callsign Number or nil if not set/capable.
-- @return #string Lead If true, unit is Flight Lead, else false or nil. -- @return #string Lead If true, unit is Flight Lead, else false or nil.
function UNIT:GetSTN() function UNIT:GetSTN()
self:F2(self.UnitName) --self:F2(self.UnitName)
local STN = nil -- STN/TN local STN = nil -- STN/TN
local VCL = nil -- VoiceCallsignLabel local VCL = nil -- VoiceCallsignLabel
local VCN = nil -- VoiceCallsignNumber local VCN = nil -- VoiceCallsignNumber