* changes from Dev
#UNIT
* changes from Dev
This commit is contained in:
Applevangelist 2022-09-08 15:49:53 +02:00
parent c137a4b06d
commit 3f052ef1da
2 changed files with 92 additions and 38 deletions

View File

@ -187,6 +187,7 @@ GROUPTEMPLATE.Takeoff = {
-- @field #string GROUND_APC Infantry carriers, in particular Amoured Personell Carrier. This can be used to transport other assets.
-- @field #string GROUND_TRUCK Unarmed ground vehicles, which has the DCS "Truck" attribute.
-- @field #string GROUND_INFANTRY Ground infantry assets.
-- @field #string GROUND_IFV Ground Infantry Fighting Vehicle.
-- @field #string GROUND_ARTILLERY Artillery assets.
-- @field #string GROUND_TANK Tanks (modern or old).
-- @field #string GROUND_TRAIN Trains. Not that trains are **not** yet properly implemented in DCS and cannot be used currently.
@ -530,6 +531,8 @@ function GROUP:HasAttribute(attribute, all)
-- Get all units of the group.
local _units=self:GetUnits()
if _units then
local _allhave=true
local _onehas=false
@ -550,6 +553,10 @@ function GROUP:HasAttribute(attribute, all)
else
return _onehas
end
end
return nil
end
--- Returns the maximum speed of the group.
@ -568,12 +575,15 @@ function GROUP:GetSpeedMax()
for _,unit in pairs(Units) do
local unit=unit --Wrapper.Unit#UNIT
local speed=unit:GetSpeedMax()
if speedmax==0 then
speedmax=speed
elseif speed<speedmax then
if speedmax==nil or speed<speedmax then
speedmax=speed
end
--env.info(string.format("FF unit %s: speed=%.1f, speedmax=%.1f", unit:GetName(), speed, speedmax))
end
return speedmax
@ -659,6 +669,29 @@ function GROUP:GetPlayerUnits()
return nil
end
--- Check if an (air) group is a client or player slot. Information is retrieved from the group template.
-- @param #GROUP self
-- @return #boolean If true, group is associated with a client or player slot.
function GROUP:IsPlayer()
-- Get group.
-- local group=self:GetGroup()
-- Units of template group.
local units=self:GetTemplate().units
-- Get numbers.
for _,unit in pairs(units) do
-- Check if unit name matach and skill is Client or Player.
if unit.name==self:GetName() and (unit.skill=="Client" or unit.skill=="Player") then
return true
end
end
return false
end
--- Returns the UNIT wrapper class with number UnitNumber.
-- If the underlying DCS Unit does not exist, the method will return nil. .
@ -671,14 +704,25 @@ function GROUP:GetUnit( UnitNumber )
if DCSGroup then
local DCSUnit = DCSGroup:getUnit( UnitNumber )
local UnitFound = nil
-- 2.7.1 dead event bug, return the first alive unit instead
local units = DCSGroup:getUnits() or {}
local UnitFound = UNIT:Find(DCSUnit)
for _,_unit in pairs(units) do
local UnitFound = UNIT:Find(_unit)
if UnitFound then
return UnitFound
end
end
end
return nil
end
--- Check if an (air) group is a client or player slot. Information is retrieved from the group template.
@ -1057,6 +1101,7 @@ end
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.
function GROUP:GetCoordinate()
local Units = self:GetUnits() or {}
for _,_unit in pairs(Units) do
@ -1205,6 +1250,7 @@ end
-- @return #number Number of rockets left.
-- @return #number Number of bombs left.
-- @return #number Number of missiles left.
-- @return #number Number of artillery shells left (with explosive mass, included in shells; shells can also be machine gun ammo)
function GROUP:GetAmmunition()
self:F( self.ControllableName )
@ -1215,6 +1261,7 @@ function GROUP:GetAmmunition()
local Nrockets=0
local Nmissiles=0
local Nbombs=0
local Narti=0
if DCSControllable then
@ -1223,19 +1270,19 @@ function GROUP:GetAmmunition()
local Unit = UnitData -- Wrapper.Unit#UNIT
-- Get ammo of the unit
local ntot, nshells, nrockets, nbombs, nmissiles = Unit:GetAmmunition()
local ntot, nshells, nrockets, nbombs, nmissiles, narti = Unit:GetAmmunition()
Ntot=Ntot+ntot
Nshells=Nshells+nshells
Nrockets=Nrockets+nrockets
Nmissiles=Nmissiles+nmissiles
Nbombs=Nbombs+nbombs
Narti=Narti+narti
end
end
return Ntot, Nshells, Nrockets, Nbombs, Nmissiles
return Ntot, Nshells, Nrockets, Nbombs, Nmissiles, Narti
end

View File

@ -24,6 +24,7 @@
--- @type UNIT
-- @field #string ClassName Name of the class.
-- @field #string UnitName Name of the unit.
-- @field #string GroupName Name of the group the unit belongs to.
-- @extends Wrapper.Controllable#CONTROLLABLE
--- For each DCS Unit object alive within a running mission, a UNIT wrapper object (instance) will be created within the _@{DATABASE} object.
@ -86,7 +87,7 @@
-- * Use the @{#UNIT.IsLOS}() method to check if the given unit is within line of sight.
--
--
-- @field #UNIT UNIT
-- @field #UNIT
UNIT = {
ClassName="UNIT",
UnitName=nil,
@ -697,6 +698,7 @@ end
-- @return #number Number of rockets left.
-- @return #number Number of bombs left.
-- @return #number Number of missiles left.
-- @return #number Number of artillery shells left (with explosive mass, included in shells; shells can also be machine gun ammo)
function UNIT:GetAmmunition()
-- Init counter.
@ -705,6 +707,7 @@ function UNIT:GetAmmunition()
local nrockets=0
local nmissiles=0
local nbombs=0
local narti=0
local unit=self
@ -742,6 +745,10 @@ function UNIT:GetAmmunition()
-- Add up all shells.
nshells=nshells+Nammo
if ammotable[w].desc.warhead and ammotable[w].desc.warhead.explosiveMass and ammotable[w].desc.warhead.explosiveMass > 0 then
narti=narti+Nammo
end
elseif Category==Weapon.Category.ROCKET then
-- Add up all rockets.
@ -778,7 +785,7 @@ function UNIT:GetAmmunition()
-- Total amount of ammunition.
nammo=nshells+nrockets+nmissiles+nbombs
return nammo, nshells, nrockets, nbombs, nmissiles
return nammo, nshells, nrockets, nbombs, nmissiles, narti
end
--- Returns the unit sensors.