AICSAR - added SRS option, made it easy to customize messages

This commit is contained in:
Applevangelist 2022-01-04 15:09:47 +01:00
parent a94098494a
commit 65abbf9563

View File

@ -50,7 +50,7 @@
--- *I once donated a pint of my finest red corpuscles to the great American Red Cross and the doctor opined my blood was very helpful; contained so much alcohol they could use it to sterilize their instruments.*
-- W.C. Fields
-- W.C.Fields
--
-- ===
--
@ -89,7 +89,7 @@
-- @field #AICSAR
AICSAR = {
ClassName = "AICSAR",
version = "0.0.1",
version = "0.0.2",
lid = "",
coalition = coalition.side.BLUE,
template = "",
@ -106,6 +106,52 @@ AICSAR = {
rescued = {},
autoonoff = true,
playerset = nil,
Messages = {},
SRS = nil,
SRSRadio = false,
SRSFrequency = 243,
SRSPath = "\\",
SRSModulation = radio.modulation.AM,
SRSSoundPath = nil, -- defaults to "l10n/DEFAULT/", i.e. add messages by "Sount to..." in the ME
}
-- TODO Messages
--- Messages enum
-- @field Messages
AICSAR.Messages = {
INITIALOK = "Roger, Pilot, we hear you. Stay where you are, a helo is on the way!",
INITIALNOTOK = "Sorry, Pilot. You're behind maximum operational distance! Good Luck!",
PILOTDOWN = "Pilot down at %s!",
PILOTKIA = "Pilot KIA!",
HELODOWN = "CSAR Helo Down!",
PILOTRESCUED = "Pilot rescued!",
PILOTINHELO = "Pilot picked up!",
}
-- TODO Radio Messages
--- Radio Messages enum for ogg files
-- @field RadioMessages
AICSAR.RadioMessages = {
INITIALOK = "initialok.ogg", -- 4.1 secs
INITIALNOTOK = "initialnotok.ogg", -- 4.6 secs
PILOTDOWN = "pilotdown.ogg", -- 2.6 secs
PILOTKIA = "pilotkia.ogg", -- 1.1 sec
HELODOWN = "helodown.ogg", -- 2.1 secs
PILOTRESCUED = "pilotrescued.ogg", -- 3.5 secs
PILOTINHELO = "pilotinhelo.ogg", -- 2.6 secs
}
-- TODO Radio Messages
--- Radio Messages enum for ogg files length in secs
-- @field RadioLength
AICSAR.RadioLength = {
INITIALOK = 4.1,
INITIALNOTOK = 4.6,
PILOTDOWN = 2.6,
PILOTKIA = 1.1,
HELODOWN = 2.1,
PILOTRESCUED = 3.5,
PILOTINHELO = 2.6,
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -163,7 +209,15 @@ 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()
-- Radio
self.SRS = nil
self.SRSRadio = false
self.SRSFrequency = 243
self.SRSPath = "\\"
self.SRSModulation = radio.modulation.AM
self.SRSSoundPath = nil -- defaults to "l10n/DEFAULT/", i.e. add messages by "Sound to..." in the ME
-- 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")
@ -258,6 +312,27 @@ end
-- Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- [User] Switch sound output on and use SRS
-- @param #AICSAR self
-- @param #boolean OnOff Switch on (true) or off (false).
-- @param #string Path Path to your SRS Server Component, e.g. "E:\\\\Program Files\\\\DCS-SimpleRadio-Standalone"
-- @param #number Frequency Defaults to 243 (guard)
-- @param #number Modulation Radio modulation. Defaults to radio.modulation.AM
-- @param #string SoundPath Where to find the audio files. Defaults to nil, i.e. add messages by "Sound to..." in the Mission Editor.
-- @return #AICSAR self
function AICSAR:SetSRSRadio(OnOff,Path,Frequency,Modulation,SoundPath)
self:T(self.lid .. "SetSRSRadio to "..tostring(OnOff))
self.SRSRadio = OnOff or true
self.SRSFrequency = Frequency or 243
self.SRSPath = Path or "c:\\"
self.SRSModulation = Modulation or radio.modulation.AM
self.SRSSoundPath = SoundPath or nil -- defaults to "l10n/DEFAULT/", i.e. add messages by "Sound to..." in the ME
if OnOff then
self.SRS = MSRS:New(Path,Frequency,Modulation)
end
return self
end
--- [Internal] Catch the landing after ejection and spawn a pilot in situ.
-- @param #AICSAR self
-- @param Core.Event#EVENTDATA EventData
@ -296,17 +371,27 @@ function AICSAR:OnEventLandingAfterEjection(EventData)
Unit.destroy(_event.initiator) -- shagrat remove static Pilot model
self:__PilotDown(2,_LandingPos,true)
if self.verbose then
local text = "Roger, Pilot, we hear you. Stay where you are, a helo is on the way!"
--local text = "Roger, Pilot, we hear you. Stay where you are, a helo is on the way!"
local text = AICSAR.Messages.INITIALOK
MESSAGE:New(text,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.INITIALOK,nil,AICSAR.RadioLength.INITIALOK)
self.SRS:PlaySoundFile(sound,2)
end
elseif _coalition == self.coalition and distancetofarp > self.maxdistance then
-- apologies, too far off
self:T(self.lid .. "Pilot out of reach")
self:__PilotDown(2,_LandingPos,false)
if self.verbose then
local text = "Sorry, Pilot. You're behind maximum operational distance! Good Luck!"
local text = AICSAR.Messages.INITIALNOTOK
--local text = "Sorry, Pilot. You're behind maximum operational distance! Good Luck!"
MESSAGE:New(text,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.INITIALNOTOK,nil,AICSAR.RadioLength.INITIALNOTOK)
self.SRS:PlaySoundFile(sound,2)
end
end
return self
end
@ -501,11 +586,17 @@ function AICSAR:onafterPilotDown(From, Event, To, Coordinate, InReach)
self:T({From, Event, To})
local CoordinateText = Coordinate:ToStringMGRS()
local inreach = tostring(InReach)
local text = string.format("Pilot down at %s. In reach = %s",CoordinateText,inreach)
--local text = string.format("Pilot down at %s. In reach = %s",CoordinateText,inreach)
local text = string.format(AICSAR.Messages.PILOTDOWN,CoordinateText)
self:T(text)
if self.verbose then
MESSAGE:New(text,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.PILOTDOWN,nil,AICSAR.RadioLength.PILOTDOWN)
self.SRS:PlaySoundFile(sound,2)
end
return self
end
@ -518,7 +609,11 @@ end
function AICSAR:onafterPilotKIA(From, Event, To)
self:T({From, Event, To})
if self.verbose then
MESSAGE:New("Pilot KIA!",15,"AICSAR"):ToCoalition(self.coalition)
MESSAGE:New(AICSAR.Messages.PILOTKIA,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.PILOTKIA,nil,AICSAR.RadioLength.PILOTKIA)
self.SRS:PlaySoundFile(sound,2)
end
return self
end
@ -534,7 +629,11 @@ end
function AICSAR:onafterHeloDown(From, Event, To, Helo, Index)
self:T({From, Event, To})
if self.verbose then
MESSAGE:New("CSAR Helo Down!",15,"AICSAR"):ToCoalition(self.coalition)
MESSAGE:New(AICSAR.Messages.HELODOWN,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.HELODOWN,nil,AICSAR.RadioLength.HELODOWN)
self.SRS:PlaySoundFile(sound,2)
end
local findex = 0
local fhname = Helo:GetName()
@ -578,7 +677,11 @@ end
function AICSAR:onafterPilotRescued(From, Event, To)
self:T({From, Event, To})
if self.verbose then
MESSAGE:New("Pilot rescued!",15,"AICSAR"):ToCoalition(self.coalition)
MESSAGE:New(AICSAR.Messages.PILOTRESCUED,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.PILOTRESCUED,nil,AICSAR.RadioLength.PILOTRESCUED)
self.SRS:PlaySoundFile(sound,2)
end
return self
end
@ -595,7 +698,11 @@ end
function AICSAR:onafterPilotPickedUp(From, Event, To, Helo, CargoTable, Index)
self:T({From, Event, To})
if self.verbose then
MESSAGE:New("Pilot picked up!",15,"AICSAR"):ToCoalition(self.coalition)
MESSAGE:New(AICSAR.Messages.PILOTINHELO,15,"AICSAR"):ToCoalition(self.coalition)
end
if self.SRSRadio then
local sound = SOUNDFILE:New(AICSAR.RadioMessages.PILOTINHELO,nil,AICSAR.RadioLength.PILOTINHELO)
self.SRS:PlaySoundFile(sound,2)
end
local findex = 0
local fhname = Helo:GetName()
@ -620,3 +727,7 @@ function AICSAR:onafterPilotPickedUp(From, Event, To, Helo, CargoTable, Index)
end
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- END AICSAR
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------