AIRBOSS v0.2.8

good commit, improved and fixed a lot of stuff.
This commit is contained in:
Frank
2018-11-18 00:45:18 +01:00
parent 9ad948632c
commit 9d9f233c15
4 changed files with 538 additions and 317 deletions
+50 -47
View File
@@ -76,7 +76,7 @@
-- * Note that if the transmission has a subtitle, it will be readable, regardless of the quality of the transmission. -- * Note that if the transmission has a subtitle, it will be readable, regardless of the quality of the transmission.
-- --
-- @type RADIO -- @type RADIO
-- @field Positionable#POSITIONABLE Positionable The transmiter. -- @field Wrapper.Controllable#CONTROLLABLE Positionable The @{#CONTROLLABLE} that will transmit the radio calls.
-- @field #string FileName Name of the sound file played. -- @field #string FileName Name of the sound file played.
-- @field #number Frequency Frequency of the transmission in Hz. -- @field #number Frequency Frequency of the transmission in Hz.
-- @field #number Modulation Modulation of the transmission (either radio.modulation.AM or radio.modulation.FM). -- @field #number Modulation Modulation of the transmission (either radio.modulation.AM or radio.modulation.FM).
@@ -93,7 +93,7 @@ RADIO = {
Subtitle = "", Subtitle = "",
SubtitleDuration = 0, SubtitleDuration = 0,
Power = 100, Power = 100,
Loop = true, Loop = false,
} }
--- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast. --- Create a new RADIO Object. This doesn't broadcast a transmission, though, use @{#RADIO.Broadcast} to actually broadcast.
@@ -102,9 +102,9 @@ RADIO = {
-- @param Wrapper.Positionable#POSITIONABLE Positionable The @{Positionable} that will receive radio capabilities. -- @param Wrapper.Positionable#POSITIONABLE Positionable The @{Positionable} that will receive radio capabilities.
-- @return #RADIO The RADIO object or #nil if Positionable is invalid. -- @return #RADIO The RADIO object or #nil if Positionable is invalid.
function RADIO:New(Positionable) function RADIO:New(Positionable)
-- Inherit base
local self = BASE:Inherit( self, BASE:New() ) -- Core.Radio#RADIO local self = BASE:Inherit( self, BASE:New() ) -- Core.Radio#RADIO
self.Loop = true -- default Loop to true (not sure the above RADIO definition actually is working)
self:F(Positionable) self:F(Positionable)
if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid if Positionable:GetPointVec2() then -- It's stupid, but the only way I found to make sure positionable is valid
@@ -155,18 +155,23 @@ function RADIO:SetFrequency(Frequency)
-- Convert frequency from MHz to Hz -- Convert frequency from MHz to Hz
self.Frequency = Frequency * 1000000 self.Frequency = Frequency * 1000000
local commandSetFrequency={
id = "SetFrequency",
params = {
frequency = self.Frequency,
modulation = self.Modulation,
}
}
-- If the RADIO is attached to a UNIT or a GROUP, we need to send the DCS Command "SetFrequency" to change the UNIT or GROUP frequency -- If the RADIO is attached to a UNIT or a GROUP, we need to send the DCS Command "SetFrequency" to change the UNIT or GROUP frequency
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
local commandSetFrequency={
id = "SetFrequency",
params = {
frequency = self.Frequency,
modulation = self.Modulation,
}
}
self:I(commandSetFrequency)
self.Positionable:SetCommand(commandSetFrequency) self.Positionable:SetCommand(commandSetFrequency)
end end
return self return self
end end
end end
@@ -280,28 +285,28 @@ end
-- but it will work for any @{Wrapper.Positionable#POSITIONABLE}. -- but it will work for any @{Wrapper.Positionable#POSITIONABLE}.
-- Only the RADIO and the Filename are mandatory. -- Only the RADIO and the Filename are mandatory.
-- @param #RADIO self -- @param #RADIO self
-- @param #string FileName -- @param #string FileName Name of sound file.
-- @param #string Subtitle -- @param #string Subtitle Subtitle to be displayed with sound file.
-- @param #number SubtitleDuration in s -- @param #number SubtitleDuration Duration of subtitle display in seconds.
-- @param #number Frequency in MHz -- @param #number Frequency Frequency in MHz.
-- @param #number Modulation either radio.modulation.AM or radio.modulation.FM -- @param #number Modulation Modulation which can be either radio.modulation.AM or radio.modulation.FM
-- @param #boolean Loop -- @param #boolean Loop If true, loop message.
-- @return #RADIO self -- @return #RADIO self
function RADIO:NewUnitTransmission(FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop) function RADIO:NewUnitTransmission(FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop)
self:F({FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop}) self:E({FileName, Subtitle, SubtitleDuration, Frequency, Modulation, Loop})
-- Set file name. -- Set file name.
self:SetFileName(FileName) self:SetFileName(FileName)
-- Set frequency.
if Frequency then
self:SetFrequency(Frequency)
end
-- Set modulation AM/FM. -- Set modulation AM/FM.
if Modulation then if Modulation then
self:SetModulation(Modulation) self:SetModulation(Modulation)
end end
-- Set frequency.
if Frequency then
self:SetFrequency(Frequency)
end
-- Set subtitle. -- Set subtitle.
if Subtitle then if Subtitle then
@@ -316,7 +321,7 @@ function RADIO:NewUnitTransmission(FileName, Subtitle, SubtitleDuration, Frequen
return self return self
end end
--- Actually Broadcast the transmission --- Broadcast the transmission.
-- * The Radio has to be populated with the new transmission before broadcasting. -- * The Radio has to be populated with the new transmission before broadcasting.
-- * Please use RADIO setters or either @{#RADIO.NewGenericTransmission} or @{#RADIO.NewUnitTransmission} -- * Please use RADIO setters or either @{#RADIO.NewGenericTransmission} or @{#RADIO.NewUnitTransmission}
-- * This class is in fact pretty smart, it determines the right DCS function to use depending on the type of POSITIONABLE -- * This class is in fact pretty smart, it determines the right DCS function to use depending on the type of POSITIONABLE
@@ -325,35 +330,33 @@ end
-- * If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored. -- * If your POSITIONABLE is a UNIT or a GROUP, the Power is ignored.
-- * If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration are ignored -- * If your POSITIONABLE is not a UNIT or a GROUP, the Subtitle, SubtitleDuration are ignored
-- @param #RADIO self -- @param #RADIO self
-- @param #string filename (Optinal) Sound file name. Default self.FileName. -- @param #boolean trigger Use trigger.action.radioTransmission() in any case, i.e. also for UNITS and GROUPS.
-- @param #string subtitle (Optional) Subtitle. Default self.Subtitle.
-- @param #number subtitleduraction (Optional) Subtitle duraction. Default self.SubtitleDuration.
-- @return #RADIO self -- @return #RADIO self
function RADIO:Broadcast(filename, subtitle, subtitleduration) function RADIO:Broadcast(viatrigger)
self:F() self:F({viatrigger=viatrigger})
filename=filename or self.FileName -- If the POSITIONABLE is actually a UNIT or a GROUP, use the more complicated DCS command system.
subtitle=subtitle or self.Subtitle if (self.Positionable.ClassName=="UNIT" or self.Positionable.ClassName=="GROUP") and (not viatrigger) then
subtitleduration=subtitleduration or self.SubtitleDuration self:I("Broadcasting from a UNIT or a GROUP")
-- If the POSITIONABLE is actually a UNIT or a GROUP, use the more complicated DCS command system local commandTransmitMessage={
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
self:T2("Broadcasting from a UNIT or a GROUP")
self.Positionable:SetCommand({
id = "TransmitMessage", id = "TransmitMessage",
params = { params = {
file = filename, file = self.FileName,
duration = subtitleduration, duration = self.SubtitleDuration,
subtitle = subtitle, subtitle = self.Subtitle,
loop = self.Loop, loop = self.Loop,
} }}
})
self:I(commandTransmitMessage)
self.Positionable:SetCommand(commandTransmitMessage)
else else
-- If the POSITIONABLE is anything else, we revert to the general singleton function -- If the POSITIONABLE is anything else, we revert to the general singleton function
-- I need to give it a unique name, so that the transmission can be stopped later. I use the class ID -- I need to give it a unique name, so that the transmission can be stopped later. I use the class ID
self:T2("Broadcasting from a POSITIONABLE") self:I("Broadcasting from a POSITIONABLE")
trigger.action.radioTransmission(self.FileName, self.Positionable:GetPositionVec3(), self.Modulation, self.Loop, self.Frequency, self.Power, tostring(self.ID)) trigger.action.radioTransmission(self.FileName, self.Positionable:GetPositionVec3(), self.Modulation, self.Loop, self.Frequency, self.Power, tostring(self.ID))
end end
return self return self
end end
@@ -367,10 +370,10 @@ function RADIO:StopBroadcast()
self:F() self:F()
-- If the POSITIONABLE is a UNIT or a GROUP, stop the transmission with the DCS "StopTransmission" command -- If the POSITIONABLE is a UNIT or a GROUP, stop the transmission with the DCS "StopTransmission" command
if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then if self.Positionable.ClassName == "UNIT" or self.Positionable.ClassName == "GROUP" then
self.Positionable:SetCommand({
id = "StopTransmission", local commandStopTransmission={id="StopTransmission", params={}}
params = {}
}) self.Positionable:SetCommand(commandStopTransmission)
else else
-- Else, we use the appropriate singleton funciton -- Else, we use the appropriate singleton funciton
trigger.action.stopRadioTransmission(tostring(self.ID)) trigger.action.stopRadioTransmission(tostring(self.ID))
File diff suppressed because it is too large Load Diff
@@ -67,12 +67,13 @@ RECOVERYTANKER = {
--- Class version. --- Class version.
-- @field #string version -- @field #string version
RECOVERYTANKER.version="0.9.0w" RECOVERYTANKER.version="0.9.1"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Possibility to add already present/spawned aircraft, e.g. for warehouse.
-- TODO: Write documenation. -- TODO: Write documenation.
-- TODO: Smarter pattern update function. E.g. (small) zone around carrier. Only update position when carrier leaves zone or changes heading? -- TODO: Smarter pattern update function. E.g. (small) zone around carrier. Only update position when carrier leaves zone or changes heading?
-- TODO: Maybe rework pattern update implementation altogether to make it smoother. -- TODO: Maybe rework pattern update implementation altogether to make it smoother.
+43 -13
View File
@@ -28,6 +28,9 @@
-- @field Core.Set#SET_GROUP followset Follow group set. -- @field Core.Set#SET_GROUP followset Follow group set.
-- @field AI.AI_Formation#AI_FORMATION formation AI_FORMATION object. -- @field AI.AI_Formation#AI_FORMATION formation AI_FORMATION object.
-- @field #number lowfuel Low fuel threshold of helo in percent. -- @field #number lowfuel Low fuel threshold of helo in percent.
-- @field #number altitude Altitude of helo in meters.
-- @field #number offsetX Offset in meters to carrier in longitudinal direction.
-- @field #number offsetZ Offset in meters to carrier in latitudinal direction.
-- @extends Core.Fsm#FSM -- @extends Core.Fsm#FSM
--- Rescue Helo --- Rescue Helo
@@ -52,16 +55,20 @@ RESCUEHELO = {
followset = nil, followset = nil,
formation = nil, formation = nil,
lowfuel = nil, lowfuel = nil,
altitude = nil,
offsetX = nil,
offsetZ = nil,
} }
--- Class version. --- Class version.
-- @field #string version -- @field #string version
RESCUEHELO.version="0.9.0w" RESCUEHELO.version="0.9.1"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Possibility to add already present/spawned aircraft, e.g. for warehouse.
-- TODO: Write documenation. -- TODO: Write documenation.
-- TODO: Add rescue event when aircraft crashes. -- TODO: Add rescue event when aircraft crashes.
-- TODO: Make offset input parameter. -- TODO: Make offset input parameter.
@@ -98,7 +105,10 @@ function RESCUEHELO:New(carrierunit, helogroupname)
-- Init defaults. -- Init defaults.
self:SetHomeBase(AIRBASE:FindByName(self.carrier:GetName())) self:SetHomeBase(AIRBASE:FindByName(self.carrier:GetName()))
self:SetTakeoffHot() self:SetTakeoffHot()
self:SetLowFuelThreshold(10) self:SetLowFuelThreshold()
self:SetAltitude()
self:SetOffsetX()
self:SetOffsetZ()
----------------------- -----------------------
--- FSM Transitions --- --- FSM Transitions ---
@@ -152,10 +162,10 @@ end
--- Set low fuel state of helo. When fuel is below this threshold, the helo will RTB or be respawned if takeoff type is in air. --- Set low fuel state of helo. When fuel is below this threshold, the helo will RTB or be respawned if takeoff type is in air.
-- @param #RESCUEHELO self -- @param #RESCUEHELO self
-- @param #number threshold Low fuel threshold in percent. Default 10. -- @param #number threshold Low fuel threshold in percent. Default 5%.
-- @return #RESCUEHELO self -- @return #RESCUEHELO self
function RESCUEHELO:SetLowFuelThreshold(threshold) function RESCUEHELO:SetLowFuelThreshold(threshold)
self.lowfuel=threshold or 10 self.lowfuel=threshold or 5
return self return self
end end
@@ -201,6 +211,33 @@ function RESCUEHELO:SetTakeoffAir()
return self return self
end end
--- Set altitude of helo.
-- @param #RESCUEHELO self
-- @param #number alt Altitude in meters. Default 70 m.
-- @return #RESCUEHELO self
function RESCUEHELO:SetAltitude(alt)
self.altitude=alt or 70
return self
end
--- Set latitudinal offset to carrier.
-- @param #RESCUEHELO self
-- @param #number distance Latitual offset distance in meters. Default 200 m.
-- @return #RESCUEHELO self
function RESCUEHELO:SetOffsetX(distance)
self.offsetX=distance or 200
return self
end
--- Set longitudal offset to carrier.
-- @param #RESCUEHELO self
-- @param #number distance Longitual offset distance in meters. Default 200 m.
-- @return #RESCUEHELO self
function RESCUEHELO:SetOffsetZ(distance)
self.offsetZ=distance or 200
return self
end
--- Check if tanker is returning to base. --- Check if tanker is returning to base.
-- @param #RESCUEHELO self -- @param #RESCUEHELO self
@@ -235,13 +272,6 @@ function RESCUEHELO:onafterStart(From, Event, To)
self:HandleEvent(EVENTS.Land) self:HandleEvent(EVENTS.Land)
--self:HandleEvent(EVENTS.Crash) --self:HandleEvent(EVENTS.Crash)
-- Offset [meters] in the direction of travelling. Positive values are in front of Mother.
local OffsetX=200
-- Offset [meters] perpendicular to travelling. Positive = Starboard (right of Mother), negative = Port (left of Mother).
local OffsetZ=200
-- Offset altitude. Should (obviously) always be positve.
local OffsetY=70
-- Delay before formation is started. -- Delay before formation is started.
local delay=120 local delay=120
@@ -258,7 +288,7 @@ function RESCUEHELO:onafterStart(From, Event, To)
local dist=UTILS.NMToMeters(0.2) local dist=UTILS.NMToMeters(0.2)
-- Coordinate behind the carrier -- Coordinate behind the carrier
local Carrier=self.carrier:GetCoordinate():SetAltitude(OffsetY):Translate(dist, hdg) local Carrier=self.carrier:GetCoordinate():SetAltitude(math.min(100, self.altitude)):Translate(dist, hdg)
-- Orientation of spawned group. -- Orientation of spawned group.
Spawn:InitHeading(hdg) Spawn:InitHeading(hdg)
@@ -295,7 +325,7 @@ function RESCUEHELO:onafterStart(From, Event, To)
self.formation=AI_FORMATION:New(self.carrier, self.followset, "Helo Formation with Carrier", "Follow Carrier at given parameters.") self.formation=AI_FORMATION:New(self.carrier, self.followset, "Helo Formation with Carrier", "Follow Carrier at given parameters.")
-- Formation parameters. -- Formation parameters.
self.formation:FormationCenterWing(-OffsetX, 50, math.abs(OffsetY), 50, OffsetZ, 50) self.formation:FormationCenterWing(-self.offsetX, 50, math.abs(self.altitude), 50, self.offsetZ, 50)
-- Start formation FSM. -- Start formation FSM.
self.formation:__Start(delay) self.formation:__Start(delay)