AICSAR - added limiter for available helos

This commit is contained in:
Applevangelist
2022-02-01 11:47:36 +01:00
parent 60a728d521
commit c3689aee93

View File

@@ -8,6 +8,7 @@
-- * Starting from a FARP or Airbase -- * Starting from a FARP or Airbase
-- * Dedicated MASH zone -- * Dedicated MASH zone
-- * Some FSM functions to include in your mission scripts -- * Some FSM functions to include in your mission scripts
-- * Limit number of available helos
-- --
-- === -- ===
-- --
@@ -45,7 +46,8 @@
-- @field #table rescued Track number of rescued pilot. -- @field #table rescued Track number of rescued pilot.
-- @field #boolean autoonoff Only send a helo when no human heli pilots are available. -- @field #boolean autoonoff Only send a helo when no human heli pilots are available.
-- @field Core.Set#SET_CLIENT playerset Track if alive heli pilots are available. -- @field Core.Set#SET_CLIENT playerset Track if alive heli pilots are available.
-- -- @field #boolean limithelos limit available number of helos going on mission (defaults to true)
-- @field #number helonumber number of helos available (default: 3)
-- @extends Core.Fsm#FSM -- @extends Core.Fsm#FSM
@@ -81,7 +83,9 @@
-- my_aicsar.maxdistance -- maximum operational distance in meters. Defaults to 50NM or 92.6km -- my_aicsar.maxdistance -- maximum operational distance in meters. Defaults to 50NM or 92.6km
-- my_aicsar.rescuezoneradius -- landing zone around downed pilot. Defaults to 200m -- my_aicsar.rescuezoneradius -- landing zone around downed pilot. Defaults to 200m
-- my_aicsar.autoonoff -- stop operations when human helicopter pilots are around. Defaults to true. -- my_aicsar.autoonoff -- stop operations when human helicopter pilots are around. Defaults to true.
-- my_aicsar.verbose -- text messages coalition side about ongoing operations. Defaults to true. -- my_aicsar.verbose -- text messages to own coalition about ongoing operations. Defaults to true.
-- my_aicsarlimithelos -- limit available number of helos going on mission (defaults to true)
-- my_aicsar.helonumber -- number of helos available (default: 3)
-- --
-- ## Radio options -- ## Radio options
-- --
@@ -148,7 +152,7 @@
-- @field #AICSAR -- @field #AICSAR
AICSAR = { AICSAR = {
ClassName = "AICSAR", ClassName = "AICSAR",
version = "0.0.3", version = "0.0.4",
lid = "", lid = "",
coalition = coalition.side.BLUE, coalition = coalition.side.BLUE,
template = "", template = "",
@@ -176,6 +180,8 @@ AICSAR = {
DCSFrequency = 243, DCSFrequency = 243,
DCSModulation = radio.modulation.AM, DCSModulation = radio.modulation.AM,
DCSRadioGroup = nil, DCSRadioGroup = nil,
limithelos = true,
helonumber = 3,
} }
-- TODO Messages -- TODO Messages
@@ -290,6 +296,10 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
self.MGRS_Accuracy = 2 self.MGRS_Accuracy = 2
-- limit number of available helos at the same time
self.limithelos = true
self.helonumber = 3
-- Set some string id for output to DCS.log file. -- Set some string id for output to DCS.log file.
self.lid=string.format("%s (%s) | ", self.alias, self.coalition and UTILS.GetCoalitionName(self.coalition) or "unknown") self.lid=string.format("%s (%s) | ", self.alias, self.coalition and UTILS.GetCoalitionName(self.coalition) or "unknown")
@@ -311,7 +321,9 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
self:__Start(math.random(2,5)) self:__Start(math.random(2,5))
self:I(self.lid .. " AI CSAR Starting") local text = string.format("%sAICSAR Version %s Starting",self.lid,self.version)
self:I(text)
------------------------ ------------------------
--- Pseudo Functions --- --- Pseudo Functions ---
@@ -606,6 +618,18 @@ function AICSAR:_CheckHelos()
return self return self
end end
--- [Internal] Count helos queue
-- @param #AICSAR self
-- @return #number Number of helos on mission
function AICSAR:_CountHelos()
self:T(self.lid .. "_CountHelos")
local count = 0
for _index,_helo in pairs(self.helos) do
count = count + 1
end
return count
end
--- [Internal] Check pilot queue for next mission --- [Internal] Check pilot queue for next mission
-- @param #AICSAR self -- @param #AICSAR self
-- @return #AICSAR self -- @return #AICSAR self
@@ -614,11 +638,29 @@ function AICSAR:_CheckQueue()
for _index, _pilot in pairs(self.pilotqueue) do for _index, _pilot in pairs(self.pilotqueue) do
local classname = _pilot.ClassName and _pilot.ClassName or "NONE" local classname = _pilot.ClassName and _pilot.ClassName or "NONE"
local name = _pilot.GroupName and _pilot.GroupName or "NONE" local name = _pilot.GroupName and _pilot.GroupName or "NONE"
local helocount = self:_CountHelos()
--self:T("Looking at " .. classname .. " " .. name) --self:T("Looking at " .. classname .. " " .. name)
-- find one w/o mission -- find one w/o mission
if _pilot and _pilot.ClassName and _pilot.ClassName == "GROUP" then if _pilot and _pilot.ClassName and _pilot.ClassName == "GROUP" then
local flightgroup = self.helos[_index] -- Ops.FlightGroup#FLIGHTGROUP
-- rescued?
if self:_CheckInMashZone(_pilot) then
self:T("Pilot" .. _pilot.GroupName .. " rescued!")
_pilot:Destroy(false)
self.pilotqueue[_index] = nil
self.rescued[_index] = true
self:__PilotRescued(2)
if flightgroup then
flightgroup.AICSARReserved = false
end
end -- end rescued
-- has no mission assigned? -- has no mission assigned?
if not _pilot.AICSAR then if not _pilot.AICSAR then
-- helo available?
if self.limithelos and helocount >= self.helonumber then
-- none free
break
end -- end limit
_pilot.AICSAR = {} _pilot.AICSAR = {}
_pilot.AICSAR.Status = "Initiated" _pilot.AICSAR.Status = "Initiated"
_pilot.AICSAR.Boarded = false _pilot.AICSAR.Boarded = false
@@ -626,23 +668,14 @@ function AICSAR:_CheckQueue()
break break
else else
-- update status from OPSGROUP -- update status from OPSGROUP
local flightgroup = self.helos[_index] -- Ops.FlightGroup#FLIGHTGROUP
if flightgroup then if flightgroup then
local state = flightgroup:GetState() local state = flightgroup:GetState()
_pilot.AICSAR.Status = state _pilot.AICSAR.Status = state
end end
--self:T("Flight for " .. _pilot.GroupName .. " in state " .. state) --self:T("Flight for " .. _pilot.GroupName .. " in state " .. state)
if self:_CheckInMashZone(_pilot) then end -- end has mission
self:T("Pilot" .. _pilot.GroupName .. " rescued!") end -- end if pilot
_pilot:Destroy(false) end -- end loop
self.pilotqueue[_index] = nil
self.rescued[_index] = true
self:__PilotRescued(2)
flightgroup.AICSARReserved = false
end
end
end
end
return self return self
end end