From 20c1f6bab4f8946a2a67f0449b5aeae1b6eed141 Mon Sep 17 00:00:00 2001 From: Jonathan Toppins Date: Mon, 18 Jun 2018 10:00:34 -0400 Subject: [PATCH] GROUP: provide a new GetFuelMin() method Taking the average fuel available across an entire flight is not really realistic and does not present an accurate representation of if a group needs to be sent to refuel or rtb. An example, a flight of 2 planes; plane 1 has 45% and plane 2 has 25% (45 + 25)/2 = 35, and 25% is the RTB threshold, plane 2 needs to go home now. However with the current averaging function plane 2 will have as little as 15% fuel (assume equal consumption) before the flight gets ordered home. Signed-off-by: Jonathan Toppins --- Moose Development/Moose/Wrapper/Group.lua | 44 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 776cf923c..0ea42e035 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -768,11 +768,41 @@ function GROUP:GetHeading() end ---- Returns relative amount of fuel (from 0.0 to 1.0) the group has in its internal tanks. If there are additional fuel tanks the value may be greater than 1.0. +--- Return the fuel state and unit reference for the unit with the least +-- amount of fuel in the group. +-- @param #GROUP self +-- @return #number The fuel state of the unit with the least amount of fuel +-- @return #Unit reference to #Unit object for further processing +function GROUP:GetFuelMin() + self:F(self.ControllableName) + + if not self:GetDCSObject() then + BASE:E( { "Cannot GetFuel", Group = self, Alive = self:IsAlive() } ) + return 0 + end + + local min = 65535 -- some sufficiently large number to init with + local unit = nil + local tmp = nil + + for UnitID, UnitData in pairs( self:GetUnits() ) do + tmp = UnitData:GetFuel() + if tmp < min then + min = tmp + unit = UnitData + end + end + + return min, unit +end + +--- Returns relative amount of fuel (from 0.0 to 1.0) the group has in its +-- internal tanks. If there are additional fuel tanks the value may be +-- greater than 1.0. -- @param #GROUP self -- @return #number The relative amount of fuel (from 0.0 to 1.0). --- @return #nil The GROUP is not existing or alive. -function GROUP:GetFuel() +-- @return #nil The GROUP is not existing or alive. +function GROUP:GetFuelAvg() self:F( self.ControllableName ) local DCSControllable = self:GetDCSObject() @@ -795,6 +825,14 @@ function GROUP:GetFuel() return 0 end +--- Returns relative amount of fuel (from 0.0 to 1.0) the group has in its internal tanks. If there are additional fuel tanks the value may be greater than 1.0. +-- @param #GROUP self +-- @return #number The relative amount of fuel (from 0.0 to 1.0). +-- @return #nil The GROUP is not existing or alive. +function GROUP:GetFuel() + return self:GetFuelAvg() +end + do -- Is Zone methods