From 19197bf23463c61d8d149607b212c0d319569056 Mon Sep 17 00:00:00 2001 From: funkyfranky Date: Mon, 18 Jun 2018 23:13:21 +0200 Subject: [PATCH] Min Fuel Fixes AI_A2A and AI_Patrol: Changed average fuel for controllable to new min fuel function. Hopefully provides better RTB behavior. CONTROLLABLE: Added GetFuelMin and GetFuelAve functions to ensure polymorphic behavior. UNIT: Added GetFuelMin and GetFuelAve functions for completeness and potential polymorphism. --- Moose Development/Moose/AI/AI_A2A.lua | 2 +- Moose Development/Moose/AI/AI_Patrol.lua | 2 +- .../Moose/Wrapper/Controllable.lua | 22 +++++++++++++++++-- Moose Development/Moose/Wrapper/Unit.lua | 20 +++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2A.lua b/Moose Development/Moose/AI/AI_A2A.lua index 4fbe0f37d..154e99013 100644 --- a/Moose Development/Moose/AI/AI_A2A.lua +++ b/Moose Development/Moose/AI/AI_A2A.lua @@ -452,7 +452,7 @@ function AI_A2A:onafterStatus() if not self:Is( "Fuel" ) and not self:Is( "Home" ) then - local Fuel = self.Controllable:GetFuel() + local Fuel = self.Controllable:GetFuelMin() self:F({Fuel=Fuel}) if Fuel < self.PatrolFuelThresholdPercentage then if self.TankerName then diff --git a/Moose Development/Moose/AI/AI_Patrol.lua b/Moose Development/Moose/AI/AI_Patrol.lua index 1f70d0015..ecedcf697 100644 --- a/Moose Development/Moose/AI/AI_Patrol.lua +++ b/Moose Development/Moose/AI/AI_Patrol.lua @@ -824,7 +824,7 @@ function AI_PATROL_ZONE:onafterStatus() local RTB = false - local Fuel = self.Controllable:GetUnit(1):GetFuel() + local Fuel = self.Controllable:GetFuelMin() if Fuel < self.PatrolFuelThresholdPercentage then self:E( self.Controllable:GetName() .. " is out of fuel:" .. Fuel .. ", RTB!" ) local OldAIControllable = self.Controllable diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 0b56cc0d7..3199393b4 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -259,6 +259,26 @@ function CONTROLLABLE:GetLife0() return nil end +--- Returns relative minimum amount of fuel (from 0.0 to 1.0) a unit or group has in its internal tanks. +-- This method returns nil to ensure polymorphic behaviour! This method needs to be overridden by GROUP or UNIT. +-- @param #CONTROLLABLE self +-- @return #nil The CONTROLLABLE is not existing or alive. +function CONTROLLABLE:GetFuelMin() + self:F( self.ControllableName ) + + return nil +end + +--- Returns relative average amount of fuel (from 0.0 to 1.0) a unit or group has in its internal tanks. +-- This method returns nil to ensure polymorphic behaviour! This method needs to be overridden by GROUP or UNIT. +-- @param #CONTROLLABLE self +-- @return #nil The CONTROLLABLE is not existing or alive. +function CONTROLLABLE:GetFuelAve() + self:F( self.ControllableName ) + + return nil +end + --- Returns relative amount of fuel (from 0.0 to 1.0) the unit has in its internal tanks. -- This method returns nil to ensure polymorphic behaviour! This method needs to be overridden by GROUP or UNIT. -- @param #CONTROLLABLE self @@ -270,8 +290,6 @@ function CONTROLLABLE:GetFuel() end - - -- Tasks --- Clear all tasks from the controllable. diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 753b842f4..91d138ab8 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -571,6 +571,26 @@ function UNIT:GetFuel() return nil end +--- Returns relative amount of fuel (from 0.0 to 1.0) the UNIT has in its internal tanks. If there are additional fuel tanks the value may be greater than 1.0. +-- @param #UNIT self +-- @return #number The relative amount of fuel (from 0.0 to 1.0). +-- @return #nil The DCS Unit is not existing or alive. +function UNIT:GetFuelMin() + self:F( self.UnitName ) + + self:GetFuel() +end + +--- Returns relative amount of fuel (from 0.0 to 1.0) the UNIT has in its internal tanks. If there are additional fuel tanks the value may be greater than 1.0. +-- @param #UNIT self +-- @return #number The relative amount of fuel (from 0.0 to 1.0). +-- @return #nil The DCS Unit is not existing or alive. +function UNIT:GetFuelAve() + self:F( self.UnitName ) + + self:GetFuel() +end + --- Returns a list of one @{Wrapper.Unit}. -- @param #UNIT self -- @return #list A list of one @{Wrapper.Unit}.