mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'develop' into FF/Ops
This commit is contained in:
@@ -52,6 +52,11 @@
|
||||
-- @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)
|
||||
-- @field Utilities.FiFo#FIFO PilotStore
|
||||
-- @field #number Altitude Default altitude setting for the helicopter FLIGHTGROUP 1500ft.
|
||||
-- @field #number Speed Default speed setting for the helicopter FLIGHTGROUP is 100kn.
|
||||
-- @field #boolean UseEventEject In case Event LandingAfterEjection isn't working, use set this to true.
|
||||
-- @field #number Delay In case of UseEventEject wait this long until we spawn a landed pilot.
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
|
||||
@@ -77,7 +82,7 @@
|
||||
-- -- @param #string Alias Name of this instance.
|
||||
-- -- @param #number Coalition Coalition as in coalition.side.BLUE, can also be passed as "blue", "red" or "neutral"
|
||||
-- -- @param #string Pilottemplate Pilot template name.
|
||||
-- -- @param #string Helotemplate Helicopter template name.
|
||||
-- -- @param #string Helotemplate Helicopter template name. Set the template to "cold start". Hueys work best.
|
||||
-- -- @param Wrapper.Airbase#AIRBASE FARP FARP object or Airbase from where to start.
|
||||
-- -- @param Core.Zone#ZONE MASHZone Zone where to drop pilots after rescue.
|
||||
-- local my_aicsar=AICSAR:New("Luftrettung",coalition.side.BLUE,"Downed Pilot","Rescue Helo",AIRBASE:FindByName("Test FARP"),ZONE:New("MASH"))
|
||||
@@ -186,7 +191,7 @@
|
||||
-- @field #AICSAR
|
||||
AICSAR = {
|
||||
ClassName = "AICSAR",
|
||||
version = "0.1.9",
|
||||
version = "0.1.14",
|
||||
lid = "",
|
||||
coalition = coalition.side.BLUE,
|
||||
template = "",
|
||||
@@ -226,6 +231,11 @@ AICSAR = {
|
||||
SRSPilotVoice = false,
|
||||
SRSOperator = nil,
|
||||
SRSOperatorVoice = false,
|
||||
PilotStore = nil,
|
||||
Speed = 100,
|
||||
Altitude = 1500,
|
||||
UseEventEject = false,
|
||||
Delay = 100,
|
||||
}
|
||||
|
||||
-- TODO Messages
|
||||
@@ -337,6 +347,8 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
|
||||
self.farp = FARP
|
||||
self.farpzone = MASHZone
|
||||
self.playerset = SET_CLIENT:New():FilterActive(true):FilterCategories("helicopter"):FilterStart()
|
||||
self.UseEventEject = false
|
||||
self.Delay = 300
|
||||
|
||||
-- Radio
|
||||
self.SRS = nil
|
||||
@@ -369,6 +381,9 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
|
||||
-- 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")
|
||||
|
||||
--Pilot Store
|
||||
self.PilotStore = FIFO:New()
|
||||
|
||||
-- Start State.
|
||||
self:SetStartState("Stopped")
|
||||
|
||||
@@ -384,7 +399,8 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
|
||||
self:AddTransition("*", "HeloDown", "*") -- Helo dead
|
||||
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
||||
|
||||
self:HandleEvent(EVENTS.LandingAfterEjection)
|
||||
self:HandleEvent(EVENTS.LandingAfterEjection,self._EventHandler)
|
||||
self:HandleEvent(EVENTS.Ejection,self._EjectEventHandler)
|
||||
|
||||
self:__Start(math.random(2,5))
|
||||
|
||||
@@ -438,7 +454,8 @@ function AICSAR:New(Alias,Coalition,Pilottemplate,Helotemplate,FARP,MASHZone)
|
||||
-- @param #AICSAR self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
-- @param #string To To state.
|
||||
-- @param #string PilotName
|
||||
|
||||
--- On after "PilotUnloaded" event.
|
||||
-- @function [parent=#AICSAR] OnAfterPilotUnloaded
|
||||
@@ -648,11 +665,103 @@ function AICSAR:DCSRadioBroadcast(Soundfile,Duration,Subtitle)
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Catch the landing after ejection and spawn a pilot in situ.
|
||||
--- [Internal] Catch the ejection and save the pilot name
|
||||
-- @param #AICSAR self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:OnEventLandingAfterEjection(EventData)
|
||||
function AICSAR:_EjectEventHandler(EventData)
|
||||
local _event = EventData -- Core.Event#EVENTDATA
|
||||
if _event.IniPlayerName then
|
||||
self.PilotStore:Push(_event.IniPlayerName)
|
||||
self:T(self.lid.."Pilot Ejected: ".._event.IniPlayerName)
|
||||
if self.UseEventEject then
|
||||
-- get position and spawn in a template pilot
|
||||
local _LandingPos = COORDINATE:NewFromVec3(_event.initiator:getPosition().p)
|
||||
local _country = _event.initiator:getCountry()
|
||||
local _coalition = coalition.getCountryCoalition( _country )
|
||||
local data = UTILS.DeepCopy(EventData)
|
||||
Unit.destroy(_event.initiator) -- shagrat remove static Pilot model
|
||||
self:ScheduleOnce(self.Delay,self._DelayedSpawnPilot,self,_LandingPos,_coalition)
|
||||
end
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Spawn a pilot
|
||||
-- @param #AICSAR self
|
||||
-- @param Core.Point#COORDINATE _LandingPos Landing Postion
|
||||
-- @param #number _coalition Coalition side
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:_DelayedSpawnPilot(_LandingPos,_coalition)
|
||||
|
||||
local distancetofarp = _LandingPos:Get2DDistance(self.farp:GetCoordinate())
|
||||
-- Mayday Message
|
||||
local Text,Soundfile,Soundlength,Subtitle = self.gettext:GetEntry("PILOTDOWN",self.locale)
|
||||
local text = ""
|
||||
local setting = {}
|
||||
setting.MGRS_Accuracy = self.MGRS_Accuracy
|
||||
local location = _LandingPos:ToStringMGRS(setting)
|
||||
local msgtxt = Text..location.."!"
|
||||
location = string.gsub(location,"MGRS ","")
|
||||
location = string.gsub(location,"%s+","")
|
||||
location = string.gsub(location,"([%a%d])","%1;") -- "0 5 1 "
|
||||
location = string.gsub(location,"0","zero")
|
||||
location = string.gsub(location,"9","niner")
|
||||
location = "MGRS;"..location
|
||||
if self.SRSGoogle then
|
||||
location = string.format("<say-as interpret-as='characters'>%s</say-as>",location)
|
||||
end
|
||||
text = Text .. location .. "!"
|
||||
local ttstext = Text .. location .. "! Repeat! "..location
|
||||
if _coalition == self.coalition then
|
||||
if self.verbose then
|
||||
MESSAGE:New(msgtxt,15,"AICSAR"):ToCoalition(self.coalition)
|
||||
-- MESSAGE:New(msgtxt,15,"AICSAR"):ToLog()
|
||||
end
|
||||
if self.SRSRadio then
|
||||
local sound = SOUNDFILE:New(Soundfile,self.SRSSoundPath,Soundlength)
|
||||
sound:SetPlayWithSRS(true)
|
||||
self.SRS:PlaySoundFile(sound,2)
|
||||
elseif self.DCSRadio then
|
||||
self:DCSRadioBroadcast(Soundfile,Soundlength,text)
|
||||
elseif self.SRSTTSRadio then
|
||||
if self.SRSPilotVoice then
|
||||
self.SRSQ:NewTransmission(ttstext,nil,self.SRSPilot,nil,1)
|
||||
else
|
||||
self.SRSQ:NewTransmission(ttstext,nil,self.SRS,nil,1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- further processing
|
||||
if _coalition == self.coalition and distancetofarp <= self.maxdistance then
|
||||
-- in reach
|
||||
self:T(self.lid .. "Spawning new Pilot")
|
||||
self.pilotindex = self.pilotindex + 1
|
||||
local newpilot = SPAWN:NewWithAlias(self.template,string.format("%s-AICSAR-%d",self.template, self.pilotindex))
|
||||
newpilot:InitDelayOff()
|
||||
newpilot:OnSpawnGroup(
|
||||
function (grp)
|
||||
self.pilotqueue[self.pilotindex] = grp
|
||||
end
|
||||
)
|
||||
newpilot:SpawnFromCoordinate(_LandingPos)
|
||||
|
||||
self:__PilotDown(2,_LandingPos,true)
|
||||
elseif _coalition == self.coalition and distancetofarp > self.maxdistance then
|
||||
-- out of reach, apologies, too far off
|
||||
self:T(self.lid .. "Pilot out of reach")
|
||||
self:__PilotDown(2,_LandingPos,false)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Catch the landing after ejection and spawn a pilot in situ.
|
||||
-- @param #AICSAR self
|
||||
-- @param Core.Event#EVENTDATA EventData
|
||||
-- @param #boolean FromEject
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:_EventHandler(EventData, FromEject)
|
||||
self:T(self.lid .. "OnEventLandingAfterEjection ID=" .. EventData.id)
|
||||
|
||||
-- autorescue on off?
|
||||
@@ -662,12 +771,14 @@ function AICSAR:OnEventLandingAfterEjection(EventData)
|
||||
end
|
||||
end
|
||||
|
||||
if self.UseEventEject and (not FromEject) then return self end
|
||||
|
||||
local _event = EventData -- Core.Event#EVENTDATA
|
||||
-- get position and spawn in a template pilot
|
||||
local _LandingPos = COORDINATE:NewFromVec3(_event.initiator:getPosition().p)
|
||||
local _country = _event.initiator:getCountry()
|
||||
local _coalition = coalition.getCountryCoalition( _country )
|
||||
|
||||
|
||||
-- DONE: add distance check
|
||||
local distancetofarp = _LandingPos:Get2DDistance(self.farp:GetCoordinate())
|
||||
|
||||
@@ -765,10 +876,15 @@ function AICSAR:_InitMission(Pilot,Index)
|
||||
-- Cargo transport assignment.
|
||||
local opstransport=OPSTRANSPORT:New(Pilot, pickupzone, self.farpzone)
|
||||
|
||||
|
||||
local helo = self:_GetFlight()
|
||||
-- inject reservation
|
||||
helo.AICSARReserved = true
|
||||
|
||||
helo:SetDefaultAltitude(self.Altitude or 1500)
|
||||
|
||||
helo:SetDefaultSpeed(self.Speed or 100)
|
||||
|
||||
-- Cargo transport assignment to first Huey group.
|
||||
helo:AddOpsTransport(opstransport)
|
||||
|
||||
@@ -815,6 +931,26 @@ function AICSAR:_CheckInMashZone(Pilot)
|
||||
end
|
||||
end
|
||||
|
||||
--- [User] Set default helo speed. Note - AI might have other ideas. Defaults to 100kn.
|
||||
-- @param #AICSAR self
|
||||
-- @param #number Knots Speed in knots.
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:SetDefaultSpeed(Knots)
|
||||
self:T(self.lid .. "SetDefaultSpeed")
|
||||
self.Speed = Knots or 100
|
||||
return self
|
||||
end
|
||||
|
||||
--- [User] Set default helo altitudeAGL. Note - AI might have other ideas. Defaults to 1500ft.
|
||||
-- @param #AICSAR self
|
||||
-- @param #number Feet AGL set in feet.
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:SetDefaultAltitude(Feet)
|
||||
self:T(self.lid .. "SetDefaultAltitude")
|
||||
self.Altitude = Feet or 1500
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Check helo queue
|
||||
-- @param #AICSAR self
|
||||
-- @return #AICSAR self
|
||||
@@ -858,6 +994,7 @@ function AICSAR:_CheckQueue(OpsGroup)
|
||||
for _index, _pilot in pairs(self.pilotqueue) do
|
||||
local classname = _pilot.ClassName and _pilot.ClassName or "NONE"
|
||||
local name = _pilot.GroupName and _pilot.GroupName or "NONE"
|
||||
local playername = "John Doe"
|
||||
local helocount = self:_CountHelos()
|
||||
--self:T("Looking at " .. classname .. " " .. name)
|
||||
-- find one w/o mission
|
||||
@@ -873,7 +1010,10 @@ function AICSAR:_CheckQueue(OpsGroup)
|
||||
end
|
||||
self.pilotqueue[_index] = nil
|
||||
self.rescued[_index] = true
|
||||
self:__PilotRescued(2)
|
||||
if self.PilotStore:Count() > 0 then
|
||||
playername = self.PilotStore:Pull()
|
||||
end
|
||||
self:__PilotRescued(2,playername)
|
||||
if flightgroup then
|
||||
flightgroup.AICSARReserved = false
|
||||
end
|
||||
@@ -1095,8 +1235,9 @@ end
|
||||
-- @param #string From
|
||||
-- @param #string Event
|
||||
-- @param #string To
|
||||
-- @param #string PilotName
|
||||
-- @return #AICSAR self
|
||||
function AICSAR:onafterPilotRescued(From, Event, To)
|
||||
function AICSAR:onafterPilotRescued(From, Event, To, PilotName)
|
||||
self:T({From, Event, To})
|
||||
local text,Soundfile,Soundlength,Subtitle = self.gettext:GetEntry("PILOTRESCUED",self.locale)
|
||||
if self.verbose then
|
||||
|
||||
Reference in New Issue
Block a user