mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
#GROUP
* changes from Dev #UNIT * changes from Dev
This commit is contained in:
parent
c137a4b06d
commit
3f052ef1da
@ -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_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_TRUCK Unarmed ground vehicles, which has the DCS "Truck" attribute.
|
||||||
-- @field #string GROUND_INFANTRY Ground infantry assets.
|
-- @field #string GROUND_INFANTRY Ground infantry assets.
|
||||||
|
-- @field #string GROUND_IFV Ground Infantry Fighting Vehicle.
|
||||||
-- @field #string GROUND_ARTILLERY Artillery assets.
|
-- @field #string GROUND_ARTILLERY Artillery assets.
|
||||||
-- @field #string GROUND_TANK Tanks (modern or old).
|
-- @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.
|
-- @field #string GROUND_TRAIN Trains. Not that trains are **not** yet properly implemented in DCS and cannot be used currently.
|
||||||
@ -530,26 +531,32 @@ function GROUP:HasAttribute(attribute, all)
|
|||||||
-- Get all units of the group.
|
-- Get all units of the group.
|
||||||
local _units=self:GetUnits()
|
local _units=self:GetUnits()
|
||||||
|
|
||||||
local _allhave=true
|
if _units then
|
||||||
local _onehas=false
|
|
||||||
|
|
||||||
for _,_unit in pairs(_units) do
|
local _allhave=true
|
||||||
local _unit=_unit --Wrapper.Unit#UNIT
|
local _onehas=false
|
||||||
if _unit then
|
|
||||||
local _hastit=_unit:HasAttribute(attribute)
|
for _,_unit in pairs(_units) do
|
||||||
if _hastit==true then
|
local _unit=_unit --Wrapper.Unit#UNIT
|
||||||
_onehas=true
|
if _unit then
|
||||||
else
|
local _hastit=_unit:HasAttribute(attribute)
|
||||||
_allhave=false
|
if _hastit==true then
|
||||||
end
|
_onehas=true
|
||||||
end
|
else
|
||||||
|
_allhave=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if all==true then
|
||||||
|
return _allhave
|
||||||
|
else
|
||||||
|
return _onehas
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if all==true then
|
return nil
|
||||||
return _allhave
|
|
||||||
else
|
|
||||||
return _onehas
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns the maximum speed of the group.
|
--- Returns the maximum speed of the group.
|
||||||
@ -568,12 +575,15 @@ function GROUP:GetSpeedMax()
|
|||||||
|
|
||||||
for _,unit in pairs(Units) do
|
for _,unit in pairs(Units) do
|
||||||
local unit=unit --Wrapper.Unit#UNIT
|
local unit=unit --Wrapper.Unit#UNIT
|
||||||
|
|
||||||
local speed=unit:GetSpeedMax()
|
local speed=unit:GetSpeedMax()
|
||||||
if speedmax==0 then
|
|
||||||
speedmax=speed
|
if speedmax==nil or speed<speedmax then
|
||||||
elseif speed<speedmax then
|
|
||||||
speedmax=speed
|
speedmax=speed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--env.info(string.format("FF unit %s: speed=%.1f, speedmax=%.1f", unit:GetName(), speed, speedmax))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return speedmax
|
return speedmax
|
||||||
@ -659,6 +669,29 @@ function GROUP:GetPlayerUnits()
|
|||||||
return nil
|
return nil
|
||||||
end
|
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.
|
--- Returns the UNIT wrapper class with number UnitNumber.
|
||||||
-- If the underlying DCS Unit does not exist, the method will return nil. .
|
-- If the underlying DCS Unit does not exist, the method will return nil. .
|
||||||
@ -670,15 +703,26 @@ function GROUP:GetUnit( UnitNumber )
|
|||||||
local DCSGroup = self:GetDCSObject()
|
local DCSGroup = self:GetDCSObject()
|
||||||
|
|
||||||
if DCSGroup then
|
if DCSGroup then
|
||||||
|
|
||||||
local DCSUnit = DCSGroup:getUnit( UnitNumber )
|
|
||||||
|
|
||||||
local UnitFound = UNIT:Find(DCSUnit)
|
local UnitFound = nil
|
||||||
|
-- 2.7.1 dead event bug, return the first alive unit instead
|
||||||
|
local units = DCSGroup:getUnits() or {}
|
||||||
|
|
||||||
|
for _,_unit in pairs(units) do
|
||||||
|
|
||||||
|
local UnitFound = UNIT:Find(_unit)
|
||||||
|
|
||||||
|
if UnitFound then
|
||||||
|
|
||||||
|
return UnitFound
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return UnitFound
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if an (air) group is a client or player slot. Information is retrieved from the group template.
|
--- Check if an (air) group is a client or player slot. Information is retrieved from the group template.
|
||||||
@ -1056,8 +1100,9 @@ end
|
|||||||
-- @param Wrapper.Group#GROUP self
|
-- @param Wrapper.Group#GROUP self
|
||||||
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.
|
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.
|
||||||
function GROUP:GetCoordinate()
|
function GROUP:GetCoordinate()
|
||||||
|
|
||||||
local Units = self:GetUnits() or {}
|
|
||||||
|
local Units = self:GetUnits() or {}
|
||||||
|
|
||||||
for _,_unit in pairs(Units) do
|
for _,_unit in pairs(Units) do
|
||||||
local FirstUnit = _unit -- Wrapper.Unit#UNIT
|
local FirstUnit = _unit -- Wrapper.Unit#UNIT
|
||||||
@ -1204,7 +1249,8 @@ end
|
|||||||
-- @return #number Number of shells left.
|
-- @return #number Number of shells left.
|
||||||
-- @return #number Number of rockets left.
|
-- @return #number Number of rockets left.
|
||||||
-- @return #number Number of bombs left.
|
-- @return #number Number of bombs left.
|
||||||
-- @return #number Number of missiles 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()
|
function GROUP:GetAmmunition()
|
||||||
self:F( self.ControllableName )
|
self:F( self.ControllableName )
|
||||||
|
|
||||||
@ -1215,6 +1261,7 @@ function GROUP:GetAmmunition()
|
|||||||
local Nrockets=0
|
local Nrockets=0
|
||||||
local Nmissiles=0
|
local Nmissiles=0
|
||||||
local Nbombs=0
|
local Nbombs=0
|
||||||
|
local Narti=0
|
||||||
|
|
||||||
if DCSControllable then
|
if DCSControllable then
|
||||||
|
|
||||||
@ -1223,19 +1270,19 @@ function GROUP:GetAmmunition()
|
|||||||
local Unit = UnitData -- Wrapper.Unit#UNIT
|
local Unit = UnitData -- Wrapper.Unit#UNIT
|
||||||
|
|
||||||
-- Get ammo of the 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
|
Ntot=Ntot+ntot
|
||||||
Nshells=Nshells+nshells
|
Nshells=Nshells+nshells
|
||||||
Nrockets=Nrockets+nrockets
|
Nrockets=Nrockets+nrockets
|
||||||
Nmissiles=Nmissiles+nmissiles
|
Nmissiles=Nmissiles+nmissiles
|
||||||
Nbombs=Nbombs+nbombs
|
Nbombs=Nbombs+nbombs
|
||||||
|
Narti=Narti+narti
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Ntot, Nshells, Nrockets, Nbombs, Nmissiles
|
return Ntot, Nshells, Nrockets, Nbombs, Nmissiles, Narti
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -2423,13 +2470,13 @@ function GROUP:GetAttribute()
|
|||||||
elseif artillery then
|
elseif artillery then
|
||||||
attribute=GROUP.Attribute.GROUND_ARTILLERY
|
attribute=GROUP.Attribute.GROUND_ARTILLERY
|
||||||
elseif tank then
|
elseif tank then
|
||||||
attribute=GROUP.Attribute.GROUND_TANK
|
attribute=GROUP.Attribute.GROUND_TANK
|
||||||
elseif ifv then
|
elseif ifv then
|
||||||
attribute=GROUP.Attribute.GROUND_IFV
|
attribute=GROUP.Attribute.GROUND_IFV
|
||||||
elseif apc then
|
elseif apc then
|
||||||
attribute=GROUP.Attribute.GROUND_APC
|
attribute=GROUP.Attribute.GROUND_APC
|
||||||
elseif infantry then
|
elseif infantry then
|
||||||
attribute=GROUP.Attribute.GROUND_INFANTRY
|
attribute=GROUP.Attribute.GROUND_INFANTRY
|
||||||
elseif truck then
|
elseif truck then
|
||||||
attribute=GROUP.Attribute.GROUND_TRUCK
|
attribute=GROUP.Attribute.GROUND_TRUCK
|
||||||
elseif train then
|
elseif train then
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
--- @type UNIT
|
--- @type UNIT
|
||||||
-- @field #string ClassName Name of the class.
|
-- @field #string ClassName Name of the class.
|
||||||
-- @field #string UnitName Name of the unit.
|
-- @field #string UnitName Name of the unit.
|
||||||
|
-- @field #string GroupName Name of the group the unit belongs to.
|
||||||
-- @extends Wrapper.Controllable#CONTROLLABLE
|
-- @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.
|
--- 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.
|
-- * Use the @{#UNIT.IsLOS}() method to check if the given unit is within line of sight.
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
-- @field #UNIT UNIT
|
-- @field #UNIT
|
||||||
UNIT = {
|
UNIT = {
|
||||||
ClassName="UNIT",
|
ClassName="UNIT",
|
||||||
UnitName=nil,
|
UnitName=nil,
|
||||||
@ -697,6 +698,7 @@ end
|
|||||||
-- @return #number Number of rockets left.
|
-- @return #number Number of rockets left.
|
||||||
-- @return #number Number of bombs left.
|
-- @return #number Number of bombs left.
|
||||||
-- @return #number Number of missiles 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()
|
function UNIT:GetAmmunition()
|
||||||
|
|
||||||
-- Init counter.
|
-- Init counter.
|
||||||
@ -705,6 +707,7 @@ function UNIT:GetAmmunition()
|
|||||||
local nrockets=0
|
local nrockets=0
|
||||||
local nmissiles=0
|
local nmissiles=0
|
||||||
local nbombs=0
|
local nbombs=0
|
||||||
|
local narti=0
|
||||||
|
|
||||||
local unit=self
|
local unit=self
|
||||||
|
|
||||||
@ -741,7 +744,11 @@ function UNIT:GetAmmunition()
|
|||||||
|
|
||||||
-- Add up all shells.
|
-- Add up all shells.
|
||||||
nshells=nshells+Nammo
|
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
|
elseif Category==Weapon.Category.ROCKET then
|
||||||
|
|
||||||
-- Add up all rockets.
|
-- Add up all rockets.
|
||||||
@ -778,7 +785,7 @@ function UNIT:GetAmmunition()
|
|||||||
-- Total amount of ammunition.
|
-- Total amount of ammunition.
|
||||||
nammo=nshells+nrockets+nmissiles+nbombs
|
nammo=nshells+nrockets+nmissiles+nbombs
|
||||||
|
|
||||||
return nammo, nshells, nrockets, nbombs, nmissiles
|
return nammo, nshells, nrockets, nbombs, nmissiles, narti
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Returns the unit sensors.
|
--- Returns the unit sensors.
|
||||||
@ -830,7 +837,7 @@ function UNIT:HasSEAD()
|
|||||||
local HasSEAD = false
|
local HasSEAD = false
|
||||||
if UnitSEADAttributes["RADAR_BAND1_FOR_ARM"] and UnitSEADAttributes["RADAR_BAND1_FOR_ARM"] == true or
|
if UnitSEADAttributes["RADAR_BAND1_FOR_ARM"] and UnitSEADAttributes["RADAR_BAND1_FOR_ARM"] == true or
|
||||||
UnitSEADAttributes["RADAR_BAND2_FOR_ARM"] and UnitSEADAttributes["RADAR_BAND2_FOR_ARM"] == true or
|
UnitSEADAttributes["RADAR_BAND2_FOR_ARM"] and UnitSEADAttributes["RADAR_BAND2_FOR_ARM"] == true or
|
||||||
UnitSEADAttributes["Optical Tracker"] and UnitSEADAttributes["Optical Tracker"] == true
|
UnitSEADAttributes["Optical Tracker"] and UnitSEADAttributes["Optical Tracker"] == true
|
||||||
then
|
then
|
||||||
HasSEAD = true
|
HasSEAD = true
|
||||||
end
|
end
|
||||||
@ -1068,7 +1075,7 @@ function UNIT:GetThreatLevel()
|
|||||||
if Descriptor then
|
if Descriptor then
|
||||||
|
|
||||||
local Attributes = Descriptor.attributes
|
local Attributes = Descriptor.attributes
|
||||||
|
|
||||||
if self:IsGround() then
|
if self:IsGround() then
|
||||||
|
|
||||||
local ThreatLevels = {
|
local ThreatLevels = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user