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,6 +531,8 @@ 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()
|
||||||
|
|
||||||
|
if _units then
|
||||||
|
|
||||||
local _allhave=true
|
local _allhave=true
|
||||||
local _onehas=false
|
local _onehas=false
|
||||||
|
|
||||||
@ -550,6 +553,10 @@ function GROUP:HasAttribute(attribute, all)
|
|||||||
else
|
else
|
||||||
return _onehas
|
return _onehas
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
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. .
|
||||||
@ -671,14 +704,25 @@ function GROUP:GetUnit( UnitNumber )
|
|||||||
|
|
||||||
if DCSGroup then
|
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
|
return UnitFound
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
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.
|
||||||
@ -1057,6 +1101,7 @@ end
|
|||||||
-- @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
|
||||||
@ -1205,6 +1250,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 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
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
@ -742,6 +745,10 @@ 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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user