mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Update CSAR.lua
Changes as per development version. Taking care of dead pilots correctly, added FSM event KIA
This commit is contained in:
parent
0db35a0e9f
commit
8cc1c24b64
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
--- **Ops** -- Combat Search and Rescue.
|
--- **Ops** -- Combat Search and Rescue.
|
||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
@ -212,6 +213,27 @@ CSAR = {
|
|||||||
-- @field #string player Player name if applicable.
|
-- @field #string player Player name if applicable.
|
||||||
-- @field Wrapper.Group#GROUP group Spawned group object.
|
-- @field Wrapper.Group#GROUP group Spawned group object.
|
||||||
-- @field #number timestamp Timestamp for approach process
|
-- @field #number timestamp Timestamp for approach process
|
||||||
|
-- @field #boolean alive Group is alive or dead/rescued
|
||||||
|
--
|
||||||
|
--- Updated and sorted list of known NDB beacons (in kHz!) from the available maps.
|
||||||
|
|
||||||
|
--[[ Moved to Utils
|
||||||
|
-- @field #CSAR.SkipFrequencies
|
||||||
|
CSAR.SkipFrequencies = {
|
||||||
|
214,274,291.5,295,297.5,
|
||||||
|
300.5,304,307,309.5,311,312,312.5,316,
|
||||||
|
320,324,328,329,330,336,337,
|
||||||
|
342,343,348,351,352,353,358,
|
||||||
|
363,365,368,372.5,374,
|
||||||
|
380,381,384,389,395,396,
|
||||||
|
414,420,430,432,435,440,450,455,462,470,485,
|
||||||
|
507,515,520,525,528,540,550,560,570,577,580,602,625,641,662,670,680,682,690,
|
||||||
|
705,720,722,730,735,740,745,750,770,795,
|
||||||
|
822,830,862,866,
|
||||||
|
905,907,920,935,942,950,995,
|
||||||
|
1000,1025,1030,1050,1065,1116,1175,1182,1210
|
||||||
|
}
|
||||||
|
--]]
|
||||||
|
|
||||||
--- All slot / Limit settings
|
--- All slot / Limit settings
|
||||||
-- @type CSAR.AircraftType
|
-- @type CSAR.AircraftType
|
||||||
@ -222,13 +244,14 @@ CSAR.AircraftType["SA342Minigun"] = 2
|
|||||||
CSAR.AircraftType["SA342L"] = 4
|
CSAR.AircraftType["SA342L"] = 4
|
||||||
CSAR.AircraftType["SA342M"] = 4
|
CSAR.AircraftType["SA342M"] = 4
|
||||||
CSAR.AircraftType["UH-1H"] = 8
|
CSAR.AircraftType["UH-1H"] = 8
|
||||||
CSAR.AircraftType["Mi-8MTV2"] = 12
|
CSAR.AircraftType["Mi-8MTV2"] = 12
|
||||||
|
CSAR.AircraftType["Mi-8MT"] = 12
|
||||||
CSAR.AircraftType["Mi-24P"] = 8
|
CSAR.AircraftType["Mi-24P"] = 8
|
||||||
CSAR.AircraftType["Mi-24V"] = 8
|
CSAR.AircraftType["Mi-24V"] = 8
|
||||||
|
|
||||||
--- CSAR class version.
|
--- CSAR class version.
|
||||||
-- @field #string version
|
-- @field #string version
|
||||||
CSAR.version="0.1.8r2"
|
CSAR.version="0.1.8r3"
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- ToDo list
|
-- ToDo list
|
||||||
@ -300,6 +323,7 @@ function CSAR:New(Coalition, Template, Alias)
|
|||||||
self:AddTransition("*", "Boarded", "*") -- Pilot boarded.
|
self:AddTransition("*", "Boarded", "*") -- Pilot boarded.
|
||||||
self:AddTransition("*", "Returning", "*") -- CSAR able to return to base.
|
self:AddTransition("*", "Returning", "*") -- CSAR able to return to base.
|
||||||
self:AddTransition("*", "Rescued", "*") -- Pilot at MASH.
|
self:AddTransition("*", "Rescued", "*") -- Pilot at MASH.
|
||||||
|
self:AddTransition("*", "KIA", "*") -- Pilot killed in action.
|
||||||
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
||||||
|
|
||||||
-- tables, mainly for tracking actions
|
-- tables, mainly for tracking actions
|
||||||
@ -441,6 +465,14 @@ function CSAR:New(Coalition, Template, Alias)
|
|||||||
-- @param #string HeliName Name of the helicopter group.
|
-- @param #string HeliName Name of the helicopter group.
|
||||||
-- @param #number PilotsSaved Number of the saved pilots on board when landing.
|
-- @param #number PilotsSaved Number of the saved pilots on board when landing.
|
||||||
|
|
||||||
|
--- On After "KIA" event. Pilot is dead.
|
||||||
|
-- @function [parent=#CSAR] OnAfterKIA
|
||||||
|
-- @param #CSAR self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param #string Pilotname Name of the pilot KIA.
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -474,6 +506,7 @@ function CSAR:_CreateDownedPilotTrack(Group,Groupname,Side,OriginalUnit,Descript
|
|||||||
DownedPilot.typename = Typename or ""
|
DownedPilot.typename = Typename or ""
|
||||||
DownedPilot.group = Group
|
DownedPilot.group = Group
|
||||||
DownedPilot.timestamp = 0
|
DownedPilot.timestamp = 0
|
||||||
|
DownedPilot.alive = true
|
||||||
|
|
||||||
-- Add Pilot
|
-- Add Pilot
|
||||||
local PilotTable = self.downedPilots
|
local PilotTable = self.downedPilots
|
||||||
@ -910,7 +943,7 @@ function CSAR:_CheckNameInDownedPilots(name)
|
|||||||
local found = false
|
local found = false
|
||||||
local table = nil
|
local table = nil
|
||||||
for _,_pilot in pairs(PilotTable) do
|
for _,_pilot in pairs(PilotTable) do
|
||||||
if _pilot.name == name then
|
if _pilot.name == name and _pilot.alive == true then
|
||||||
found = true
|
found = true
|
||||||
table = _pilot
|
table = _pilot
|
||||||
break
|
break
|
||||||
@ -927,25 +960,10 @@ end
|
|||||||
function CSAR:_RemoveNameFromDownedPilots(name,force)
|
function CSAR:_RemoveNameFromDownedPilots(name,force)
|
||||||
local PilotTable = self.downedPilots --#CSAR.DownedPilot
|
local PilotTable = self.downedPilots --#CSAR.DownedPilot
|
||||||
local found = false
|
local found = false
|
||||||
for _,_pilot in pairs(PilotTable) do
|
for _index,_pilot in pairs(PilotTable) do
|
||||||
if _pilot.name == name then
|
if _pilot.name == name then
|
||||||
local group = _pilot.group -- Wrapper.Group#GROUP
|
self.downedPilots[_index].alive = false
|
||||||
if group then
|
|
||||||
if (not group:IsAlive()) or ( force == true) then -- don\'t delete groups which still exist
|
|
||||||
found = true
|
|
||||||
_pilot.desc = nil
|
|
||||||
_pilot.frequency = nil
|
|
||||||
_pilot.index = nil
|
|
||||||
_pilot.name = nil
|
|
||||||
_pilot.originalUnit = nil
|
|
||||||
_pilot.player = nil
|
|
||||||
_pilot.side = nil
|
|
||||||
_pilot.typename = nil
|
|
||||||
_pilot.group = nil
|
|
||||||
_pilot.timestamp = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return found
|
return found
|
||||||
end
|
end
|
||||||
@ -968,7 +986,7 @@ function CSAR:_CheckWoundedGroupStatus(heliname,woundedgroupname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local _woundedGroup = _downedpilot.group
|
local _woundedGroup = _downedpilot.group
|
||||||
if _woundedGroup ~= nil then
|
if _woundedGroup ~= nil and _woundedGroup:IsAlive() then
|
||||||
local _heliUnit = self:_GetSARHeli(_heliName) -- Wrapper.Unit#UNIT
|
local _heliUnit = self:_GetSARHeli(_heliName) -- Wrapper.Unit#UNIT
|
||||||
|
|
||||||
local _lookupKeyHeli = _heliName .. "_" .. _woundedGroupName --lookup key for message state tracking
|
local _lookupKeyHeli = _heliName .. "_" .. _woundedGroupName --lookup key for message state tracking
|
||||||
@ -981,7 +999,6 @@ function CSAR:_CheckWoundedGroupStatus(heliname,woundedgroupname)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--if self:_CheckGroupNotKIA(_woundedGroup, _woundedGroupName, _heliUnit, _heliName) then
|
|
||||||
local _heliCoord = _heliUnit:GetCoordinate()
|
local _heliCoord = _heliUnit:GetCoordinate()
|
||||||
local _leaderCoord = _woundedGroup:GetCoordinate()
|
local _leaderCoord = _woundedGroup:GetCoordinate()
|
||||||
local _distance = self:_GetDistance(_heliCoord,_leaderCoord)
|
local _distance = self:_GetDistance(_heliCoord,_leaderCoord)
|
||||||
@ -999,7 +1016,10 @@ function CSAR:_CheckWoundedGroupStatus(heliname,woundedgroupname)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:T("...Downed Pilot KIA?!")
|
self:T("...Downed Pilot KIA?!")
|
||||||
self:_RemoveNameFromDownedPilots(_downedpilot.name)
|
if not _downedpilot.alive then
|
||||||
|
--self:__KIA(1,_downedpilot.name)
|
||||||
|
self:_RemoveNameFromDownedPilots(_downedpilot.name, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -1275,36 +1295,6 @@ function CSAR:_CheckCloseWoundedGroup(_distance, _heliUnit, _heliName, _woundedG
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (Internal) Check if group not KIA.
|
|
||||||
-- @param #CSAR self
|
|
||||||
-- @param Wrapper.Group#GROUP _woundedGroup
|
|
||||||
-- @param #string _woundedGroupName
|
|
||||||
-- @param Wrapper.Unit#UNIT _heliUnit
|
|
||||||
-- @param #string _heliName
|
|
||||||
-- @return #boolean Outcome
|
|
||||||
function CSAR:_CheckGroupNotKIA(_woundedGroup, _woundedGroupName, _heliUnit, _heliName)
|
|
||||||
self:T(self.lid .. " _CheckGroupNotKIA")
|
|
||||||
-- check if unit has died or been picked up
|
|
||||||
local inTransit = false
|
|
||||||
if _woundedGroup and _heliUnit then
|
|
||||||
for _currentHeli, _groups in pairs(self.inTransitGroups) do
|
|
||||||
if _groups[_woundedGroupName] then
|
|
||||||
inTransit = true
|
|
||||||
self:_DisplayToAllSAR(string.format("%s has been picked up by %s", _woundedGroupName, _currentHeli), self.coalition, self.messageTime)
|
|
||||||
break
|
|
||||||
end -- end name check
|
|
||||||
end -- end loop
|
|
||||||
if not inTransit then
|
|
||||||
-- KIA
|
|
||||||
self:_DisplayToAllSAR(string.format("%s is KIA ", _woundedGroupName), self.coalition, self.messageTime)
|
|
||||||
end
|
|
||||||
--stops the message being displayed again
|
|
||||||
self:_RemoveNameFromDownedPilots(_woundedGroupName)
|
|
||||||
end
|
|
||||||
--continue
|
|
||||||
return inTransit
|
|
||||||
end
|
|
||||||
|
|
||||||
--- (Internal) Monitor in-flight returning groups.
|
--- (Internal) Monitor in-flight returning groups.
|
||||||
-- @param #CSAR self
|
-- @param #CSAR self
|
||||||
-- @param #string heliname Heli name
|
-- @param #string heliname Heli name
|
||||||
@ -1455,7 +1445,7 @@ function CSAR:_DisplayActiveSAR(_unitName)
|
|||||||
self:T({Table=_value})
|
self:T({Table=_value})
|
||||||
--local _woundedGroup = GROUP:FindByName(_groupName)
|
--local _woundedGroup = GROUP:FindByName(_groupName)
|
||||||
local _woundedGroup = _value.group
|
local _woundedGroup = _value.group
|
||||||
if _woundedGroup then
|
if _woundedGroup and _value.alive then
|
||||||
local _coordinatesText = self:_GetPositionOfWounded(_woundedGroup)
|
local _coordinatesText = self:_GetPositionOfWounded(_woundedGroup)
|
||||||
local _helicoord = _heli:GetCoordinate()
|
local _helicoord = _heli:GetCoordinate()
|
||||||
local _woundcoord = _woundedGroup:GetCoordinate()
|
local _woundcoord = _woundedGroup:GetCoordinate()
|
||||||
@ -1745,7 +1735,9 @@ end
|
|||||||
--- (Internal) Populate table with available beacon frequencies.
|
--- (Internal) Populate table with available beacon frequencies.
|
||||||
-- @param #CSAR self
|
-- @param #CSAR self
|
||||||
function CSAR:_GenerateVHFrequencies()
|
function CSAR:_GenerateVHFrequencies()
|
||||||
self:T(self.lid .. " _GenerateVHFrequencies")
|
self:T(self.lid .. " _GenerateVHFrequencies")
|
||||||
|
--local _skipFrequencies = self.SkipFrequencies
|
||||||
|
|
||||||
local FreeVHFFrequencies = {}
|
local FreeVHFFrequencies = {}
|
||||||
FreeVHFFrequencies = UTILS.GenerateVHFrequencies()
|
FreeVHFFrequencies = UTILS.GenerateVHFrequencies()
|
||||||
self.FreeVHFFrequencies = FreeVHFFrequencies
|
self.FreeVHFFrequencies = FreeVHFFrequencies
|
||||||
@ -1844,8 +1836,8 @@ function CSAR:_CountActiveDownedPilots()
|
|||||||
self:T(self.lid .. " _CountActiveDownedPilots")
|
self:T(self.lid .. " _CountActiveDownedPilots")
|
||||||
local PilotsInFieldN = 0
|
local PilotsInFieldN = 0
|
||||||
for _, _unitName in pairs(self.downedPilots) do
|
for _, _unitName in pairs(self.downedPilots) do
|
||||||
self:T({_unitName})
|
self:T({_unitName.desc})
|
||||||
if _unitName.name ~= nil then
|
if _unitName.alive == true then
|
||||||
PilotsInFieldN = PilotsInFieldN + 1
|
PilotsInFieldN = PilotsInFieldN + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1896,6 +1888,26 @@ function CSAR:onafterStart(From, Event, To)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- (Internal) Function called before Status() event.
|
||||||
|
-- @param #CSAR self
|
||||||
|
function CSAR:_CheckDownedPilotTable()
|
||||||
|
local pilots = self.downedPilots
|
||||||
|
for _,_entry in pairs (pilots) do
|
||||||
|
self:T("Checking for " .. _entry.name)
|
||||||
|
self:T({entry=_entry})
|
||||||
|
local group = _entry.group
|
||||||
|
if not group:IsAlive() then
|
||||||
|
self:T("Group is dead")
|
||||||
|
if _entry.alive == true then
|
||||||
|
self:T("Switching .alive to false")
|
||||||
|
self:__KIA(1,_entry.desc)
|
||||||
|
self:_RemoveNameFromDownedPilots(_entry.name,true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--- (Internal) Function called before Status() event.
|
--- (Internal) Function called before Status() event.
|
||||||
-- @param #CSAR self.
|
-- @param #CSAR self.
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
@ -1906,15 +1918,18 @@ function CSAR:onbeforeStatus(From, Event, To)
|
|||||||
-- housekeeping
|
-- housekeeping
|
||||||
self:_AddMedevacMenuItem()
|
self:_AddMedevacMenuItem()
|
||||||
self:_RefreshRadioBeacons()
|
self:_RefreshRadioBeacons()
|
||||||
|
self:_CheckDownedPilotTable()
|
||||||
for _,_sar in pairs (self.csarUnits) do
|
for _,_sar in pairs (self.csarUnits) do
|
||||||
local PilotTable = self.downedPilots
|
local PilotTable = self.downedPilots
|
||||||
for _,_entry in pairs (PilotTable) do
|
for _,_entry in pairs (PilotTable) do
|
||||||
local entry = _entry -- #CSAR.DownedPilot
|
if _entry.alive then
|
||||||
local name = entry.name
|
local entry = _entry -- #CSAR.DownedPilot
|
||||||
local timestamp = entry.timestamp or 0
|
local name = entry.name
|
||||||
local now = timer.getAbsTime()
|
local timestamp = entry.timestamp or 0
|
||||||
if now - timestamp > 17 then -- only check if we\'re not in approach mode, which is iterations of 5 and 10.
|
local now = timer.getAbsTime()
|
||||||
self:_CheckWoundedGroupStatus(_sar,name)
|
if now - timestamp > 17 then -- only check if we\'re not in approach mode, which is iterations of 5 and 10.
|
||||||
|
self:_CheckWoundedGroupStatus(_sar,name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user