Merge remote-tracking branch 'origin/master' into branch

This commit is contained in:
Applevangelist 2025-02-02 12:56:05 +01:00
commit 3bb5d3709b
2 changed files with 1136 additions and 1025 deletions

View File

@ -3152,7 +3152,7 @@ function GROUP:IsSAM()
local units = self:GetUnits()
for _,_unit in pairs(units or {}) do
local unit = _unit -- Wrapper.Unit#UNIT
if unit:HasSEAD() and unit:IsGround() and (not unit:HasAttribute("Mobile AAA")) then
if unit:IsSAM() then
issam = true
break
end
@ -3162,18 +3162,16 @@ end
--- [GROUND] Determine if a GROUP has a AAA unit, i.e. has no radar or optical tracker but the AAA = true or the "Mobile AAA" = true attribute.
-- @param #GROUP self
-- @return #boolean IsSAM True if AAA, else false
-- @return #boolean IsAAA True if AAA, else false
function GROUP:IsAAA()
local issam = false
local isAAA = false
local units = self:GetUnits()
for _,_unit in pairs(units or {}) do
local unit = _unit -- Wrapper.Unit#UNIT
local desc = unit:GetDesc() or {}
local attr = desc.attributes or {}
if unit:HasSEAD() then return false end
if attr["AAA"] or attr["SAM related"] then
issam = true
if unit:IsAAA() then
isAAA = true
break
end
end
return issam
return isAAA
end

View File

@ -470,7 +470,9 @@ function UNIT:IsPlayer()
-- Get group.
local group = self:GetGroup()
if not group then return false end
if not group then
return false
end
-- Units of template group.
local template = group:GetTemplate()
@ -478,7 +480,11 @@ function UNIT:IsPlayer()
if (template == nil) or (template.units == nil) then
local DCSObject = self:GetDCSObject()
if DCSObject then
if DCSObject:getPlayerName() ~= nil then return true else return false end
if DCSObject:getPlayerName() ~= nil then
return true
else
return false
end
else
return false
end
@ -939,7 +945,11 @@ end
-- @return #boolean HasAPShells
function UNIT:HasAPShells()
local _, _, _, _, _, _, shells = self:GetAmmunition()
if shells > 0 then return true else return false end
if shells > 0 then
return true
else
return false
end
end
--- Get number of AP shells from a tank.
@ -963,7 +973,11 @@ end
-- @return #boolean HasHEShells
function UNIT:HasHEShells()
local _, _, _, _, _, _, _, shells = self:GetAmmunition()
if shells > 0 then return true else return false end
if shells > 0 then
return true
else
return false
end
end
--- Checks if an artillery unit still has artillery shells.
@ -971,7 +985,11 @@ end
-- @return #boolean HasArtiShells
function UNIT:HasArtiShells()
local _, _, _, _, _, shells = self:GetAmmunition()
if shells > 0 then return true else return false end
if shells > 0 then
return true
else
return false
end
end
--- Get number of artillery shells from an artillery unit.
@ -1304,21 +1322,30 @@ function UNIT:GetThreatLevel()
[11] = "LR SAMs"
}
if Attributes["LR SAM"] then ThreatLevel = 10
elseif Attributes["MR SAM"] then ThreatLevel = 9
if Attributes["LR SAM"] then
ThreatLevel = 10
elseif Attributes["MR SAM"] then
ThreatLevel = 9
elseif Attributes["SR SAM"] and
not Attributes["IR Guided SAM"] then ThreatLevel = 8
not Attributes["IR Guided SAM"] then
ThreatLevel = 8
elseif (Attributes["SR SAM"] or Attributes["MANPADS"]) and
Attributes["IR Guided SAM"] then ThreatLevel = 7
elseif Attributes["AAA"] then ThreatLevel = 6
elseif Attributes["Modern Tanks"] then ThreatLevel = 5
Attributes["IR Guided SAM"] then
ThreatLevel = 7
elseif Attributes["AAA"] then
ThreatLevel = 6
elseif Attributes["Modern Tanks"] then
ThreatLevel = 5
elseif (Attributes["Tanks"] or Attributes["IFV"]) and
Attributes["ATGM"] then ThreatLevel = 4
Attributes["ATGM"] then
ThreatLevel = 4
elseif (Attributes["Tanks"] or Attributes["IFV"]) and
not Attributes["ATGM"] then ThreatLevel = 3
elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then ThreatLevel = 2
elseif Attributes["Infantry"] or Attributes["EWR"] then ThreatLevel = 1
not Attributes["ATGM"] then
ThreatLevel = 3
elseif Attributes["Old Tanks"] or Attributes["APC"] or Attributes["Artillery"] then
ThreatLevel = 2
elseif Attributes["Infantry"] or Attributes["EWR"] then
ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel + 1]
@ -1340,19 +1367,30 @@ function UNIT:GetThreatLevel()
[11] = "Fighter"
}
if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9
elseif Attributes["Interceptors"] then ThreatLevel = 9
elseif Attributes["Battleplanes"] then ThreatLevel = 8
elseif Attributes["Battle airplanes"] then ThreatLevel = 8
elseif Attributes["Attack helicopters"] then ThreatLevel = 7
elseif Attributes["Strategic bombers"] then ThreatLevel = 6
elseif Attributes["Bombers"] then ThreatLevel = 5
elseif Attributes["UAVs"] then ThreatLevel = 4
elseif Attributes["Transport helicopters"] then ThreatLevel = 3
elseif Attributes["AWACS"] then ThreatLevel = 2
elseif Attributes["Tankers"] then ThreatLevel = 1
if Attributes["Fighters"] then
ThreatLevel = 10
elseif Attributes["Multirole fighters"] then
ThreatLevel = 9
elseif Attributes["Interceptors"] then
ThreatLevel = 9
elseif Attributes["Battleplanes"] then
ThreatLevel = 8
elseif Attributes["Battle airplanes"] then
ThreatLevel = 8
elseif Attributes["Attack helicopters"] then
ThreatLevel = 7
elseif Attributes["Strategic bombers"] then
ThreatLevel = 6
elseif Attributes["Bombers"] then
ThreatLevel = 5
elseif Attributes["UAVs"] then
ThreatLevel = 4
elseif Attributes["Transport helicopters"] then
ThreatLevel = 3
elseif Attributes["AWACS"] then
ThreatLevel = 2
elseif Attributes["Tankers"] then
ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel + 1]
@ -1384,13 +1422,18 @@ function UNIT:GetThreatLevel()
[11] = "Aircraft Carrier"
}
if Attributes["Aircraft Carriers"] then ThreatLevel = 10
elseif Attributes["Destroyers"] then ThreatLevel = 8
elseif Attributes["Cruisers"] then ThreatLevel = 6
elseif Attributes["Frigates"] then ThreatLevel = 4
elseif Attributes["Corvettes"] then ThreatLevel = 2
elseif Attributes["Light armed ships"] then ThreatLevel = 1
if Attributes["Aircraft Carriers"] then
ThreatLevel = 10
elseif Attributes["Destroyers"] then
ThreatLevel = 8
elseif Attributes["Cruisers"] then
ThreatLevel = 6
elseif Attributes["Frigates"] then
ThreatLevel = 4
elseif Attributes["Corvettes"] then
ThreatLevel = 2
elseif Attributes["Light armed ships"] then
ThreatLevel = 1
end
ThreatText = ThreatLevels[ThreatLevel + 1]
@ -1548,7 +1591,8 @@ function UNIT:InAir(NoHeloCheck)
return nil
end
do -- Event Handling
do
-- Event Handling
--- Subscribe to a DCS Event.
-- @param #UNIT self
@ -1588,13 +1632,15 @@ do -- Event Handling
end
do -- Detection
do
-- Detection
--- Returns if a unit is detecting the TargetUnit.
-- @param #UNIT self
-- @param #UNIT TargetUnit
-- @return #boolean true If the TargetUnit is detected by the unit, otherwise false.
function UNIT:IsDetected( TargetUnit ) --R2.1
function UNIT:IsDetected(TargetUnit)
--R2.1
local TargetIsDetected, TargetIsVisible, TargetLastTime, TargetKnowType, TargetKnowDistance, TargetLastPos, TargetLastVelocity = self:IsTargetDetected(TargetUnit:GetDCSObject())
@ -1605,7 +1651,8 @@ do -- Detection
-- @param #UNIT self
-- @param #UNIT TargetUnit
-- @return #boolean true If the TargetUnit has LOS with the unit, otherwise false.
function UNIT:IsLOS( TargetUnit ) --R2.1
function UNIT:IsLOS(TargetUnit)
--R2.1
local IsLOS = self:GetPointVec3():IsLOS(TargetUnit:GetPointVec3())
@ -1797,3 +1844,69 @@ function UNIT:GetSTN()
end
return STN, VCL, VCN, FGL
end
do
-- AI methods
--- Turns the AI On or Off for the UNIT.
-- @param #UNIT self
-- @param #boolean AIOnOff The value true turns the AI On, the value false turns the AI Off.
-- @return #UNIT The UNIT.
function UNIT:SetAIOnOff(AIOnOff)
local DCSUnit = self:GetDCSObject() -- DCS#Group
if DCSUnit then
local DCSController = DCSUnit:getController() -- DCS#Controller
if DCSController then
DCSController:setOnOff(AIOnOff)
return self
end
end
return nil
end
--- Turns the AI On for the UNIT.
-- @param #UNIT self
-- @return #UNIT The UNIT.
function UNIT:SetAIOn()
return self:SetAIOnOff(true)
end
--- Turns the AI Off for the UNIT.
-- @param #UNIT self
-- @return #UNIT The UNIT.
function UNIT:SetAIOff()
return self:SetAIOnOff(false)
end
end
--- [GROUND] Determine if a UNIT is a SAM unit, i.e. has radar or optical tracker and is no mobile AAA.
-- @param #UNIT self
-- @return #boolean IsSAM True if SAM, else false
function UNIT:IsSAM()
if self:HasSEAD() and self:IsGround() and (not self:HasAttribute("Mobile AAA")) then
return true
end
return false
end
--- [GROUND] Determine if a UNIT is a AAA unit, i.e. has no radar or optical tracker but the AAA = true or the "Mobile AAA" = true attribute.
-- @param #UNIT self
-- @return #boolean IsAAA True if AAA, else false
function UNIT:IsAAA()
local unit = self -- Wrapper.Unit#UNIT
local desc = unit:GetDesc() or {}
local attr = desc.attributes or {}
if unit:HasSEAD() then
return false
end
if attr["AAA"] or attr["SAM related"] then
return true
end
return false
end