#GROUP, #UNIT

* Improve GetAmmunition() to include artillery shells
This commit is contained in:
Applevangelist 2022-09-08 15:51:07 +02:00
parent 3bc274a651
commit 31cd125954
2 changed files with 14 additions and 6 deletions

View File

@ -1250,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 )
@ -1260,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
@ -1268,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

View File

@ -698,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.
@ -706,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
@ -743,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.
@ -779,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.