diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index 78b69202a..0f5320ff8 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -1346,7 +1346,7 @@ function EVENT:onEvent( Event ) -- Weapon. if Event.weapon then Event.Weapon = Event.weapon - Event.WeaponName = Event.Weapon:getTypeName() + Event.WeaponName = Event.weapon:isExist() and Event.weapon:getTypeName() or "Unknown Weapon" Event.WeaponUNIT = CLIENT:Find( Event.Weapon, '', true ) -- Sometimes, the weapon is a player unit! Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon.getPlayerName and Event.Weapon:getPlayerName() --Event.WeaponPlayerName = Event.WeaponUNIT and Event.Weapon:getPlayerName() diff --git a/Moose Development/Moose/Functional/Range.lua b/Moose Development/Moose/Functional/Range.lua index 3472132b5..eb3fc4f28 100644 --- a/Moose Development/Moose/Functional/Range.lua +++ b/Moose Development/Moose/Functional/Range.lua @@ -106,6 +106,7 @@ -- @field Sound.SRS#MSRS instructmsrs SRS wrapper for range instructor. -- @field Sound.SRS#MSRSQUEUE instructsrsQ SRS queue for range instructor. -- @field #number Coalition Coalition side for the menu, if any. +-- @field Core.Menu#MENU_MISSION menuF10root Specific user defined root F10 menu. -- @extends Core.Fsm#FSM --- *Don't only practice your art, but force your way into its secrets; art deserves that, for it and knowledge can raise man to the Divine.* - Ludwig van Beethoven @@ -593,13 +594,14 @@ RANGE.MenuF10Root = nil --- Range script version. -- @field #string version -RANGE.version = "2.7.3" +RANGE.version = "2.8.0" -- TODO list: -- TODO: Verbosity level for messages. -- TODO: Add option for default settings such as smoke off. -- TODO: Add custom weapons, which can be specified by the user. -- TODO: Check if units are still alive. +-- TODO: Option for custom sound files. -- DONE: Scenery as targets. -- DONE: Add statics for strafe pits. -- DONE: Add missiles. @@ -858,16 +860,16 @@ function RANGE:onafterStart() self.rangecontrol.schedonce = true -- Init numbers. - self.rangecontrol:SetDigit( 0, RANGE.Sound.RC0.filename, RANGE.Sound.RC0.duration, self.soundpath ) - self.rangecontrol:SetDigit( 1, RANGE.Sound.RC1.filename, RANGE.Sound.RC1.duration, self.soundpath ) - self.rangecontrol:SetDigit( 2, RANGE.Sound.RC2.filename, RANGE.Sound.RC2.duration, self.soundpath ) - self.rangecontrol:SetDigit( 3, RANGE.Sound.RC3.filename, RANGE.Sound.RC3.duration, self.soundpath ) - self.rangecontrol:SetDigit( 4, RANGE.Sound.RC4.filename, RANGE.Sound.RC4.duration, self.soundpath ) - self.rangecontrol:SetDigit( 5, RANGE.Sound.RC5.filename, RANGE.Sound.RC5.duration, self.soundpath ) - self.rangecontrol:SetDigit( 6, RANGE.Sound.RC6.filename, RANGE.Sound.RC6.duration, self.soundpath ) - self.rangecontrol:SetDigit( 7, RANGE.Sound.RC7.filename, RANGE.Sound.RC7.duration, self.soundpath ) - self.rangecontrol:SetDigit( 8, RANGE.Sound.RC8.filename, RANGE.Sound.RC8.duration, self.soundpath ) - self.rangecontrol:SetDigit( 9, RANGE.Sound.RC9.filename, RANGE.Sound.RC9.duration, self.soundpath ) + self.rangecontrol:SetDigit( 0, self.Sound.RC0.filename, self.Sound.RC0.duration, self.soundpath ) + self.rangecontrol:SetDigit( 1, self.Sound.RC1.filename, self.Sound.RC1.duration, self.soundpath ) + self.rangecontrol:SetDigit( 2, self.Sound.RC2.filename, self.Sound.RC2.duration, self.soundpath ) + self.rangecontrol:SetDigit( 3, self.Sound.RC3.filename, self.Sound.RC3.duration, self.soundpath ) + self.rangecontrol:SetDigit( 4, self.Sound.RC4.filename, self.Sound.RC4.duration, self.soundpath ) + self.rangecontrol:SetDigit( 5, self.Sound.RC5.filename, self.Sound.RC5.duration, self.soundpath ) + self.rangecontrol:SetDigit( 6, self.Sound.RC6.filename, self.Sound.RC6.duration, self.soundpath ) + self.rangecontrol:SetDigit( 7, self.Sound.RC7.filename, self.Sound.RC7.duration, self.soundpath ) + self.rangecontrol:SetDigit( 8, self.Sound.RC8.filename, self.Sound.RC8.duration, self.soundpath ) + self.rangecontrol:SetDigit( 9, self.Sound.RC9.filename, self.Sound.RC9.duration, self.soundpath ) -- Set location where the messages are transmitted from. self.rangecontrol:SetSenderCoordinate( self.location ) @@ -884,16 +886,16 @@ function RANGE:onafterStart() self.instructor.schedonce = true -- Init numbers. - self.instructor:SetDigit( 0, RANGE.Sound.IR0.filename, RANGE.Sound.IR0.duration, self.soundpath ) - self.instructor:SetDigit( 1, RANGE.Sound.IR1.filename, RANGE.Sound.IR1.duration, self.soundpath ) - self.instructor:SetDigit( 2, RANGE.Sound.IR2.filename, RANGE.Sound.IR2.duration, self.soundpath ) - self.instructor:SetDigit( 3, RANGE.Sound.IR3.filename, RANGE.Sound.IR3.duration, self.soundpath ) - self.instructor:SetDigit( 4, RANGE.Sound.IR4.filename, RANGE.Sound.IR4.duration, self.soundpath ) - self.instructor:SetDigit( 5, RANGE.Sound.IR5.filename, RANGE.Sound.IR5.duration, self.soundpath ) - self.instructor:SetDigit( 6, RANGE.Sound.IR6.filename, RANGE.Sound.IR6.duration, self.soundpath ) - self.instructor:SetDigit( 7, RANGE.Sound.IR7.filename, RANGE.Sound.IR7.duration, self.soundpath ) - self.instructor:SetDigit( 8, RANGE.Sound.IR8.filename, RANGE.Sound.IR8.duration, self.soundpath ) - self.instructor:SetDigit( 9, RANGE.Sound.IR9.filename, RANGE.Sound.IR9.duration, self.soundpath ) + self.instructor:SetDigit( 0, self.Sound.IR0.filename, self.Sound.IR0.duration, self.soundpath ) + self.instructor:SetDigit( 1, self.Sound.IR1.filename, self.Sound.IR1.duration, self.soundpath ) + self.instructor:SetDigit( 2, self.Sound.IR2.filename, self.Sound.IR2.duration, self.soundpath ) + self.instructor:SetDigit( 3, self.Sound.IR3.filename, self.Sound.IR3.duration, self.soundpath ) + self.instructor:SetDigit( 4, self.Sound.IR4.filename, self.Sound.IR4.duration, self.soundpath ) + self.instructor:SetDigit( 5, self.Sound.IR5.filename, self.Sound.IR5.duration, self.soundpath ) + self.instructor:SetDigit( 6, self.Sound.IR6.filename, self.Sound.IR6.duration, self.soundpath ) + self.instructor:SetDigit( 7, self.Sound.IR7.filename, self.Sound.IR7.duration, self.soundpath ) + self.instructor:SetDigit( 8, self.Sound.IR8.filename, self.Sound.IR8.duration, self.soundpath ) + self.instructor:SetDigit( 9, self.Sound.IR9.filename, self.Sound.IR9.duration, self.soundpath ) -- Set location where the messages are transmitted from. self.instructor:SetSenderCoordinate( self.location ) @@ -920,13 +922,23 @@ function RANGE:onafterStart() self.rangezone:SmokeZone( SMOKECOLOR.White ) end - self:__Status( -60 ) + self:__Status( -10 ) end ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- User Functions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +--- Set the root F10 menu under which the range F10 menu is created. +-- @param #RANGE self +-- @param Core.Menu#MENU_MISSION menu The root F10 menu. +-- @return #RANGE self +function RANGE:SetMenuRoot(menu) + self.menuF10root=menu + return self +end + + --- Set maximal strafing altitude. Player entering a strafe pit above that altitude are not registered for a valid pass. -- @param #RANGE self -- @param #number maxalt Maximum altitude in meters AGL. Default is 914 m = 3000 ft. @@ -1066,6 +1078,9 @@ end -- @param Core.Zone#ZONE zone MOOSE zone defining the range perimeters. -- @return #RANGE self function RANGE:SetRangeZone( zone ) + if zone and type(zone)=="string" then + zone=ZONE:FindByName(zone) + end self.rangezone = zone return self end @@ -1327,6 +1342,53 @@ function RANGE:SetSoundfilesPath( path ) return self end +--- Set the path to the csv file that contains information about the used sound files. +-- The parameter file has to be located on your local disk (**not** inside the miz file). +-- @param #RANGE self +-- @param #string csvfile Full path to the csv file on your local disk. +-- @return #RANGE self +function RANGE:SetSoundfilesInfo( csvfile ) + + --- Local function to return the ATIS.Soundfile for a given file name + local function getSound(filename) + for key,_soundfile in pairs(self.Sound) do + local soundfile=_soundfile --#RANGE.Soundfile + if filename==soundfile.filename then + return soundfile + end + end + return nil + end + + -- Read csv file + local data=UTILS.ReadCSV(csvfile) + + if data then + + for i,sound in pairs(data) do + + -- Get the ATIS.Soundfile + local soundfile=getSound(sound.filename..".ogg") --#RANGE.Soundfile + + if soundfile then + + -- Set duration + soundfile.duration=tonumber(sound.duration) + + else + self:E(string.format("ERROR: Could not get info for sound file %s", sound.filename)) + end + + end + else + self:E(string.format("ERROR: Could not read sound csv file!")) + end + + + return self +end + + --- Add new strafe pit. For a strafe pit, hits from guns are counted. One pit can consist of several units. -- A strafe run approach is only valid if the player enters via a zone in front of the pit, which is defined by boxlength, boxwidth, and heading. -- Furthermore, the player must not be too high and fly in the direction of the pit to make a valid target apporoach. @@ -1665,12 +1727,16 @@ end --- Add all units of a group as bombing targets. -- @param #RANGE self --- @param Wrapper.Group#GROUP group Group of bombing targets. +-- @param Wrapper.Group#GROUP group Group of bombing targets. Can also be given as group name. -- @param #number goodhitrange Max distance from unit which is considered as a good hit. -- @param #boolean randommove If true, unit will move randomly within the range. Default is false. -- @return #RANGE self function RANGE:AddBombingTargetGroup( group, goodhitrange, randommove ) self:F( { group = group, goodhitrange = goodhitrange, randommove = randommove } ) + + if group and type(group)=="string" then + group=GROUP:FindByName(group) + end if group then @@ -2016,7 +2082,7 @@ function RANGE._OnImpact(weapon, self, playerData, attackHdg, attackAlt, attackV if self.useSRS then self.controlsrsQ:NewTransmission(_message,nil,self.controlmsrs,nil,1) else - self.rangecontrol:NewTransmission( RANGE.Sound.RCWeaponImpactedTooFar.filename, RANGE.Sound.RCWeaponImpactedTooFar.duration, self.soundpath, nil, nil, _message, self.subduration ) + self.rangecontrol:NewTransmission( self.Sound.RCWeaponImpactedTooFar.filename, self.Sound.RCWeaponImpactedTooFar.duration, self.soundpath, nil, nil, _message, self.subduration ) end end @@ -2163,15 +2229,15 @@ function RANGE:onafterEnterRange( From, Event, To, player ) -- Radio message that player entered the range -- You entered the bombing range. For hit assessment, contact the range controller at xy MHz - self.instructor:NewTransmission( RANGE.Sound.IREnterRange.filename, RANGE.Sound.IREnterRange.duration, self.soundpath ) + self.instructor:NewTransmission( self.Sound.IREnterRange.filename, self.Sound.IREnterRange.duration, self.soundpath ) self.instructor:Number2Transmission( RF[1] ) if tonumber( RF[2] ) > 0 then - self.instructor:NewTransmission( RANGE.Sound.IRDecimal.filename, RANGE.Sound.IRDecimal.duration, self.soundpath ) + self.instructor:NewTransmission( self.Sound.IRDecimal.filename, self.Sound.IRDecimal.duration, self.soundpath ) self.instructor:Number2Transmission( RF[2] ) end - self.instructor:NewTransmission( RANGE.Sound.IRMegaHertz.filename, RANGE.Sound.IRMegaHertz.duration, self.soundpath ) + self.instructor:NewTransmission( self.Sound.IRMegaHertz.filename, self.Sound.IRMegaHertz.duration, self.soundpath ) end end @@ -2207,7 +2273,7 @@ function RANGE:onafterExitRange( From, Event, To, player ) self.instructsrsQ:NewTransmission(text, nil, self.instructmsrs, nil, 1, {player.client:GetGroup()}, text, 10) else - self.instructor:NewTransmission( RANGE.Sound.IRExitRange.filename, RANGE.Sound.IRExitRange.duration, self.soundpath ) + self.instructor:NewTransmission( self.Sound.IRExitRange.filename, self.Sound.IRExitRange.duration, self.soundpath ) end end @@ -2243,20 +2309,20 @@ function RANGE:onafterImpact( From, Event, To, result, player ) local group = player.client:GetGroup() self.controlsrsQ:NewTransmission(text,nil,self.controlmsrs,nil,1,{group},text,10) else - self.rangecontrol:NewTransmission( RANGE.Sound.RCImpact.filename, RANGE.Sound.RCImpact.duration, self.soundpath, nil, nil, text, self.subduration ) + self.rangecontrol:NewTransmission( self.Sound.RCImpact.filename, self.Sound.RCImpact.duration, self.soundpath, nil, nil, text, self.subduration ) self.rangecontrol:Number2Transmission( string.format( "%03d", result.radial ), nil, 0.1 ) - self.rangecontrol:NewTransmission( RANGE.Sound.RCDegrees.filename, RANGE.Sound.RCDegrees.duration, self.soundpath ) - self.rangecontrol:NewTransmission( RANGE.Sound.RCFor.filename, RANGE.Sound.RCFor.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCDegrees.filename, self.Sound.RCDegrees.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCFor.filename, self.Sound.RCFor.duration, self.soundpath ) self.rangecontrol:Number2Transmission( string.format( "%d", UTILS.MetersToFeet( result.distance ) ) ) - self.rangecontrol:NewTransmission( RANGE.Sound.RCFeet.filename, RANGE.Sound.RCFeet.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCFeet.filename, self.Sound.RCFeet.duration, self.soundpath ) if result.quality == "POOR" then - self.rangecontrol:NewTransmission( RANGE.Sound.RCPoorHit.filename, RANGE.Sound.RCPoorHit.duration, self.soundpath, nil, 0.5 ) + self.rangecontrol:NewTransmission( self.Sound.RCPoorHit.filename, self.Sound.RCPoorHit.duration, self.soundpath, nil, 0.5 ) elseif result.quality == "INEFFECTIVE" then - self.rangecontrol:NewTransmission( RANGE.Sound.RCIneffectiveHit.filename, RANGE.Sound.RCIneffectiveHit.duration, self.soundpath, nil, 0.5 ) + self.rangecontrol:NewTransmission( self.Sound.RCIneffectiveHit.filename, self.Sound.RCIneffectiveHit.duration, self.soundpath, nil, 0.5 ) elseif result.quality == "GOOD" then - self.rangecontrol:NewTransmission( RANGE.Sound.RCGoodHit.filename, RANGE.Sound.RCGoodHit.duration, self.soundpath, nil, 0.5 ) + self.rangecontrol:NewTransmission( self.Sound.RCGoodHit.filename, self.Sound.RCGoodHit.duration, self.soundpath, nil, 0.5 ) elseif result.quality == "EXCELLENT" then - self.rangecontrol:NewTransmission( RANGE.Sound.RCExcellentHit.filename, RANGE.Sound.RCExcellentHit.duration, self.soundpath, nil, 0.5 ) + self.rangecontrol:NewTransmission( self.Sound.RCExcellentHit.filename, self.Sound.RCExcellentHit.duration, self.soundpath, nil, 0.5 ) end end end @@ -3152,7 +3218,7 @@ function RANGE:_CheckInZone( _unitName ) self.controlsrsQ:NewTransmission(text,nil,self.controlmsrs,nil,1) else -- You left the strafing zone too quickly! No score! - self.rangecontrol:NewTransmission( RANGE.Sound.RCLeftStrafePitTooQuickly.filename, RANGE.Sound.RCLeftStrafePitTooQuickly.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCLeftStrafePitTooQuickly.filename, self.Sound.RCLeftStrafePitTooQuickly.duration, self.soundpath ) end end else @@ -3179,23 +3245,23 @@ function RANGE:_CheckInZone( _unitName ) local resulttext="" if _result.pastfoulline == true then -- resulttext = "* INVALID - PASSED FOUL LINE *" - _sound = RANGE.Sound.RCPoorPass -- + _sound = self.Sound.RCPoorPass -- else if accur >= 90 then resulttext = "DEADEYE PASS" - _sound = RANGE.Sound.RCExcellentPass + _sound = self.Sound.RCExcellentPass elseif accur >= 75 then resulttext = "EXCELLENT PASS" - _sound = RANGE.Sound.RCExcellentPass + _sound = self.Sound.RCExcellentPass elseif accur >= 50 then resulttext = "GOOD PASS" - _sound = RANGE.Sound.RCGoodPass + _sound = self.Sound.RCGoodPass elseif accur >= 25 then resulttext = "INEFFECTIVE PASS" - _sound = RANGE.Sound.RCIneffectivePass + _sound = self.Sound.RCIneffectivePass else resulttext = "POOR PASS" - _sound = RANGE.Sound.RCPoorPass + _sound = self.Sound.RCPoorPass end end @@ -3242,14 +3308,14 @@ function RANGE:_CheckInZone( _unitName ) if self.useSRS then self.controlsrsQ:NewTransmission(ttstext,nil,self.controlmsrs,nil,1) else - self.rangecontrol:NewTransmission( RANGE.Sound.RCHitsOnTarget.filename, RANGE.Sound.RCHitsOnTarget.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCHitsOnTarget.filename, self.Sound.RCHitsOnTarget.duration, self.soundpath ) self.rangecontrol:Number2Transmission( string.format( "%d", _result.hits ) ) if shots and accur then - self.rangecontrol:NewTransmission( RANGE.Sound.RCTotalRoundsFired.filename, RANGE.Sound.RCTotalRoundsFired.duration, self.soundpath, nil, 0.2 ) + self.rangecontrol:NewTransmission( self.Sound.RCTotalRoundsFired.filename, self.Sound.RCTotalRoundsFired.duration, self.soundpath, nil, 0.2 ) self.rangecontrol:Number2Transmission( string.format( "%d", shots ), nil, 0.2 ) - self.rangecontrol:NewTransmission( RANGE.Sound.RCAccuracy.filename, RANGE.Sound.RCAccuracy.duration, self.soundpath, nil, 0.2 ) + self.rangecontrol:NewTransmission( self.Sound.RCAccuracy.filename, self.Sound.RCAccuracy.duration, self.soundpath, nil, 0.2 ) self.rangecontrol:Number2Transmission( string.format( "%d", UTILS.Round( accur, 0 ) ) ) - self.rangecontrol:NewTransmission( RANGE.Sound.RCPercent.filename, RANGE.Sound.RCPercent.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCPercent.filename, self.Sound.RCPercent.duration, self.soundpath ) end self.rangecontrol:NewTransmission( _sound.filename, _sound.duration, self.soundpath, nil, 0.5 ) end @@ -3294,7 +3360,7 @@ function RANGE:_CheckInZone( _unitName ) if self.useSRS then self.controlsrsQ:NewTransmission(_msg,nil,self.controlmsrs,nil,1) else - self.rangecontrol:NewTransmission( RANGE.Sound.RCRollingInOnStrafeTarget.filename, RANGE.Sound.RCRollingInOnStrafeTarget.duration, self.soundpath ) + self.rangecontrol:NewTransmission( self.Sound.RCRollingInOnStrafeTarget.filename, self.Sound.RCRollingInOnStrafeTarget.duration, self.soundpath ) end end @@ -3343,16 +3409,23 @@ function RANGE:_AddF10Commands( _unitName ) self.MenuAddedTo[_gid] = true -- Range root menu path. - local _rangePath = nil - - if RANGE.MenuF10Root then + local _rootMenu = nil + if self.menuF10root then + ------------------- -- MISSION LEVEL -- - ------------------- + ------------------- + + --_rootMenu = MENU_GROUP:New( group, self.rangename, self.menuF10root ) + _rootMenu = self.menuF10root + self:T2(self.lid..string.format("Creating F10 menu for group %s", group:GetName())) - -- _rangePath = missionCommands.addSubMenuForGroup(_gid, self.rangename, RANGE.MenuF10Root) - _rangePath = MENU_GROUP:New( group, "On the Range" ) + elseif RANGE.MenuF10Root then + + -- Main F10 menu: F10// + --_rootMenu = MENU_GROUP:New( group, self.rangename, RANGE.MenuF10Root ) + _rootMenu = RANGE.MenuF10Root else @@ -3362,12 +3435,17 @@ function RANGE:_AddF10Commands( _unitName ) -- Main F10 menu: F10/On the Range// if RANGE.MenuF10[_gid] == nil then - -- RANGE.MenuF10[_gid]=missionCommands.addSubMenuForGroup(_gid, "On the Range") - RANGE.MenuF10[_gid] = MENU_GROUP:New( group, "On the Range" ) + self:T2(self.lid..string.format("Creating F10 menu 'On the Range' for group %s", group:GetName())) + else + self:T2(self.lid..string.format("F10 menu 'On the Range' already EXISTS for group %s", group:GetName())) end - -- _rangePath = missionCommands.addSubMenuForGroup(_gid, self.rangename, RANGE.MenuF10[_gid]) - _rangePath = MENU_GROUP:New( group, self.rangename, RANGE.MenuF10[_gid] ) + + _rootMenu=RANGE.MenuF10[_gid] or MENU_GROUP:New( group, "On the Range" ) + end + + -- Range menu + local _rangePath = MENU_GROUP:New( group, self.rangename, _rootMenu ) local _statsPath = MENU_GROUP:New( group, "Statistics", _rangePath ) local _markPath = MENU_GROUP:New( group, "Mark Targets", _rangePath ) diff --git a/Moose Development/Moose/Ops/ATIS.lua b/Moose Development/Moose/Ops/ATIS.lua index 2ca3b7036..700cc74bd 100644 --- a/Moose Development/Moose/Ops/ATIS.lua +++ b/Moose Development/Moose/Ops/ATIS.lua @@ -317,18 +317,18 @@ -- atis:Start() -- -- This uses a male voice with US accent. It requires SRS to be installed in the `D:\DCS\_SRS\` directory. Note that backslashes need to be escaped or simply use slashes (as in linux). --- --- ### SRS can use multiple frequencies: --- +-- +-- ### SRS can use multiple frequencies: +-- -- atis=ATIS:New("Batumi", {305,103.85}, {radio.modulation.AM,radio.modulation.FM}) -- atis:SetSRS("D:\\DCS\\_SRS\\", "male", "en-US") -- atis:Start() --- +-- -- ### SRS Localization --- +-- -- You can localize the SRS output, all you need is to provide a table of translations and set the `locale` of your instance. You need to provide the translations in your script **before you instantiate your ATIS**. -- The German localization (already provided in the code) e.g. looks like follows: --- +-- -- ATIS.Messages.DE = -- { -- HOURS = "Uhr", @@ -389,13 +389,13 @@ -- FARP = "Farp", -- DELIMITER = "Komma", -- decimal delimiter -- } --- +-- -- Then set up your ATIS and set the locale: --- +-- -- atis=ATIS:New("Batumi", 305, radio.modulation.AM) -- atis:SetSRS("D:\\DCS\\_SRS\\", "female", "de_DE") -- atis:SetLocale("de") -- available locales from source are "en", "de" and "es" --- atis:Start() +-- atis:Start() -- -- ## FARPS -- @@ -497,7 +497,7 @@ ATIS.Alphabet = { -- @field #number TheChannel -10° (West). -- @field #number Syria +5° (East). -- @field #number MarianaIslands +2° (East). --- @field #number SinaiMao +5° (East). +-- @field #number SinaiMap +5° (East). ATIS.RunwayM2T = { Caucasus = 0, Nevada = 12, @@ -620,6 +620,8 @@ ATIS.ICAOPhraseology = { -- @field #ATIS.Soundfile VORFrequency ATIS.Sound = { ActiveRunway = { filename = "ActiveRunway.ogg", duration = 0.99 }, + ActiveRunwayDeparture = { filename = "ActiveRunwayDeparture.ogg", duration = 0.99 }, + ActiveRunwayArrival = { filename = "ActiveRunwayArrival.ogg", duration = 0.99 }, AdviceOnInitial = { filename = "AdviceOnInitial.ogg", duration = 3.00 }, Airport = { filename = "Airport.ogg", duration = 0.66 }, Altimeter = { filename = "Altimeter.ogg", duration = 0.68 }, @@ -899,6 +901,7 @@ ATIS.version = "1.0.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Correct fog for elevation. +-- TODO: Generalize sound files input to be able to use custom made sounds. -- DONE: Option to add multiple frequencies for SRS -- DONE: Zulu time --> Zulu in output. -- DONE: Fix for AB not having a runway - Helopost like Naqoura @@ -1102,6 +1105,52 @@ function ATIS:SetSoundfilesPath( pathMain, pathAirports, pathNato ) return self end +--- Set the path to the csv file that contains information about the used sound files. +-- The parameter file has to be located on your local disk (**not** inside the miz file). +-- @param #ATIS self +-- @param #string csvfile Full path to the csv file on your local disk. +-- @return #ATIS self +function ATIS:SetSoundfilesInfo( csvfile ) + + --- Local function to return the ATIS.Soundfile for a given file name + local function getSound(filename) + for key,_soundfile in pairs(self.Sound) do + local soundfile=_soundfile --#ATIS.Soundfile + if filename==soundfile.filename then + return soundfile + end + end + return nil + end + + -- Read csv file + local data=UTILS.ReadCSV(csvfile) + + if data then + + for i,sound in pairs(data) do + + -- Get the ATIS.Soundfile + local soundfile=getSound(sound.filename..".ogg") --#ATIS.Soundfile + + if soundfile then + + -- Set duration + soundfile.duration=tonumber(sound.duration) + + else + self:E(string.format("ERROR: Could not get info for sound file %s", sound.filename)) + end + + end + else + self:E(string.format("ERROR: Could not read sound csv file!")) + end + + + return self +end + --- Set airborne unit (airplane or helicopter), used to transmit radio messages including subtitles. -- Best is to place the unit on a parking spot of the airbase and set it to *uncontrolled* in the mission editor. -- @param #ATIS self @@ -1552,13 +1601,13 @@ end function ATIS:SetSRS(PathToSRS, Gender, Culture, Voice, Port, GoogleKey) --if PathToSRS or MSRS.path then self.useSRS=true - + local path = PathToSRS or MSRS.path local gender = Gender or MSRS.gender local culture = Culture or MSRS.culture local voice = Voice or MSRS.voice local port = Port or MSRS.port or 5002 - + self.msrs=MSRS:New(path, self.frequency, self.modulation) self.msrs:SetGender(gender) self.msrs:SetCulture(culture) @@ -1667,16 +1716,16 @@ function ATIS:onafterStart( From, Event, To ) self.radioqueue:SetRadioPower( self.power ) -- Init numbers. - self.radioqueue:SetDigit( 0, ATIS.Sound.N0.filename, ATIS.Sound.N0.duration, self.soundpath ) - self.radioqueue:SetDigit( 1, ATIS.Sound.N1.filename, ATIS.Sound.N1.duration, self.soundpath ) - self.radioqueue:SetDigit( 2, ATIS.Sound.N2.filename, ATIS.Sound.N2.duration, self.soundpath ) - self.radioqueue:SetDigit( 3, ATIS.Sound.N3.filename, ATIS.Sound.N3.duration, self.soundpath ) - self.radioqueue:SetDigit( 4, ATIS.Sound.N4.filename, ATIS.Sound.N4.duration, self.soundpath ) - self.radioqueue:SetDigit( 5, ATIS.Sound.N5.filename, ATIS.Sound.N5.duration, self.soundpath ) - self.radioqueue:SetDigit( 6, ATIS.Sound.N6.filename, ATIS.Sound.N6.duration, self.soundpath ) - self.radioqueue:SetDigit( 7, ATIS.Sound.N7.filename, ATIS.Sound.N7.duration, self.soundpath ) - self.radioqueue:SetDigit( 8, ATIS.Sound.N8.filename, ATIS.Sound.N8.duration, self.soundpath ) - self.radioqueue:SetDigit( 9, ATIS.Sound.N9.filename, ATIS.Sound.N9.duration, self.soundpath ) + self.radioqueue:SetDigit( 0, self.Sound.N0.filename, self.Sound.N0.duration, self.soundpath ) + self.radioqueue:SetDigit( 1, self.Sound.N1.filename, self.Sound.N1.duration, self.soundpath ) + self.radioqueue:SetDigit( 2, self.Sound.N2.filename, self.Sound.N2.duration, self.soundpath ) + self.radioqueue:SetDigit( 3, self.Sound.N3.filename, self.Sound.N3.duration, self.soundpath ) + self.radioqueue:SetDigit( 4, self.Sound.N4.filename, self.Sound.N4.duration, self.soundpath ) + self.radioqueue:SetDigit( 5, self.Sound.N5.filename, self.Sound.N5.duration, self.soundpath ) + self.radioqueue:SetDigit( 6, self.Sound.N6.filename, self.Sound.N6.duration, self.soundpath ) + self.radioqueue:SetDigit( 7, self.Sound.N7.filename, self.Sound.N7.duration, self.soundpath ) + self.radioqueue:SetDigit( 8, self.Sound.N8.filename, self.Sound.N8.duration, self.soundpath ) + self.radioqueue:SetDigit( 9, self.Sound.N9.filename, self.Sound.N9.duration, self.soundpath ) -- Start radio queue. self.radioqueue:Start( 1, 0.1 ) @@ -1923,7 +1972,7 @@ function ATIS:onafterBroadcast( From, Event, To ) -------------------------- --- Sunrise and Sunset --- -------------------------- - + local hours = self.gettext:GetEntry("HOURS",self.locale) local sunrise = coord:GetSunrise() sunrise = UTILS.Split( sunrise, ":" ) @@ -2023,8 +2072,6 @@ function ATIS:onafterBroadcast( From, Event, To ) -- Cloud preset (DCS 2.7) local cloudspreset = clouds.preset or "Nothing" - - env.info("FF cloud preset "..cloudspreset) -- Precepitation: 0=None, 1=Rain, 2=Thunderstorm, 3=Snow, 4=Snowstorm. local precepitation = 0 @@ -2053,7 +2100,6 @@ function ATIS:onafterBroadcast( From, Event, To ) else precepitation = 3 -- snow end - env.info("Fprecipt "..precepitation) elseif cloudspreset:find( "RainyPreset" ) then -- Overcast + Rain clouddens = 9 @@ -2061,7 +2107,7 @@ function ATIS:onafterBroadcast( From, Event, To ) precepitation = 1 -- rain else precepitation = 3 -- snow - end + end elseif cloudspreset:find( "Preset10" ) then -- Scattered 5 clouddens = 4 @@ -2166,36 +2212,36 @@ function ATIS:onafterBroadcast( From, Event, To ) -- No cloud info for dynamic weather. local CloudCover = {} -- #ATIS.Soundfile - CloudCover = ATIS.Sound.CloudsNotAvailable + CloudCover = self.Sound.CloudsNotAvailable --local CLOUDSsub = "Cloud coverage information not available" local CLOUDSsub = self.gettext:GetEntry("NOCLOUDINFO",self.locale) -- Only valid for static weather. if static then if clouddens >= 9 then -- Overcast 9,10 - CloudCover = ATIS.Sound.CloudsOvercast + CloudCover = self.Sound.CloudsOvercast --CLOUDSsub = "Overcast" CLOUDSsub = self.gettext:GetEntry("OVERCAST",self.locale) elseif clouddens >= 7 then -- Broken 7,8 - CloudCover = ATIS.Sound.CloudsBroken + CloudCover = self.Sound.CloudsBroken --CLOUDSsub = "Broken clouds" CLOUDSsub = self.gettext:GetEntry("BROKEN",self.locale) elseif clouddens >= 4 then -- Scattered 4,5,6 - CloudCover = ATIS.Sound.CloudsScattered + CloudCover = self.Sound.CloudsScattered --CLOUDSsub = "Scattered clouds" CLOUDSsub = self.gettext:GetEntry("SCATTERED",self.locale) elseif clouddens >= 1 then -- Few 1,2,3 - CloudCover = ATIS.Sound.CloudsFew + CloudCover = self.Sound.CloudsFew --CLOUDSsub = "Few clouds" CLOUDSsub = self.gettext:GetEntry("FEWCLOUDS",self.locale) else -- No clouds CLOUDBASE = nil CLOUDCEIL = nil - CloudCover = ATIS.Sound.CloudsNo + CloudCover = self.Sound.CloudsNo --CLOUDSsub = "No clouds" CLOUDSsub = self.gettext:GetEntry("NOCLOUDS",self.locale) end @@ -2229,7 +2275,7 @@ function ATIS:onafterBroadcast( From, Event, To ) subtitle = string.format( "%s %s", information, NATO ) local _INFORMATION = subtitle if not self.useSRS then - self:Transmission( ATIS.Sound.Information, 0.5, subtitle ) + self:Transmission( self.Sound.Information, 0.5, subtitle ) self.radioqueue:NewTransmission( string.format( "%s.ogg", NATO ), 0.75, self.soundpathNato ) end alltext = alltext .. ";\n" .. subtitle @@ -2238,7 +2284,7 @@ function ATIS:onafterBroadcast( From, Event, To ) subtitle = string.format( "%s Zulu", ZULU ) if not self.useSRS then self.radioqueue:Number2Transmission( ZULU, nil, 0.5 ) - self:Transmission( ATIS.Sound.Zulu, 0.2, subtitle ) + self:Transmission( self.Sound.Zulu, 0.2, subtitle ) end alltext = alltext .. ";\n" .. subtitle @@ -2249,9 +2295,9 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Sunrise at %s local time", SUNRISE ) subtitle = string.format( sunrise, SUNRISE ) if not self.useSRS then - self:Transmission( ATIS.Sound.SunriseAt, 0.5, subtitle ) + self:Transmission( self.Sound.SunriseAt, 0.5, subtitle ) self.radioqueue:Number2Transmission( SUNRISE, nil, 0.2 ) - self:Transmission( ATIS.Sound.TimeLocal, 0.2 ) + self:Transmission( self.Sound.TimeLocal, 0.2 ) end alltext = alltext .. ";\n" .. subtitle @@ -2260,9 +2306,9 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Sunset at %s local time", SUNSET ) subtitle = string.format( sunset, SUNSET ) if not self.useSRS then - self:Transmission( ATIS.Sound.SunsetAt, 0.5, subtitle ) + self:Transmission( self.Sound.SunsetAt, 0.5, subtitle ) self.radioqueue:Number2Transmission( SUNSET, nil, 0.5 ) - self:Transmission( ATIS.Sound.TimeLocal, 0.2 ) + self:Transmission( self.Sound.TimeLocal, 0.2 ) end alltext = alltext .. ";\n" .. subtitle end @@ -2287,17 +2333,17 @@ function ATIS:onafterBroadcast( From, Event, To ) end local _WIND = subtitle if not self.useSRS then - self:Transmission( ATIS.Sound.WindFrom, 1.0, subtitle ) + self:Transmission( self.Sound.WindFrom, 1.0, subtitle ) self.radioqueue:Number2Transmission( WINDFROM ) - self:Transmission( ATIS.Sound.At, 0.2 ) + self:Transmission( self.Sound.At, 0.2 ) self.radioqueue:Number2Transmission( WINDSPEED ) if self.metric then - self:Transmission( ATIS.Sound.MetersPerSecond, 0.2 ) + self:Transmission( self.Sound.MetersPerSecond, 0.2 ) else - self:Transmission( ATIS.Sound.Knots, 0.2 ) + self:Transmission( self.Sound.Knots, 0.2 ) end if turbulence > 0 then - self:Transmission( ATIS.Sound.Gusting, 0.2 ) + self:Transmission( self.Sound.Gusting, 0.2 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2313,12 +2359,12 @@ function ATIS:onafterBroadcast( From, Event, To ) subtitle = string.format( visi, VISIBILITY ) end if not self.useSRS then - self:Transmission( ATIS.Sound.Visibilty, 1.0, subtitle ) + self:Transmission( self.Sound.Visibilty, 1.0, subtitle ) self.radioqueue:Number2Transmission( VISIBILITY ) if self.metric then - self:Transmission( ATIS.Sound.Kilometers, 0.2 ) + self:Transmission( self.Sound.Kilometers, 0.2 ) else - self:Transmission( ATIS.Sound.StatuteMiles, 0.2 ) + self:Transmission( self.Sound.StatuteMiles, 0.2 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2369,21 +2415,21 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Weather phenomena: %s", wpsub ) subtitle = string.format( "%s: %s", phenos, wpsub ) if not self.useSRS then - self:Transmission( ATIS.Sound.WeatherPhenomena, 1.0, subtitle ) + self:Transmission( self.Sound.WeatherPhenomena, 1.0, subtitle ) if precepitation == 1 then - self:Transmission( ATIS.Sound.Rain, 0.5 ) + self:Transmission( self.Sound.Rain, 0.5 ) elseif precepitation == 2 then - self:Transmission( ATIS.Sound.ThunderStorm, 0.5 ) + self:Transmission( self.Sound.ThunderStorm, 0.5 ) elseif precepitation == 3 then - self:Transmission( ATIS.Sound.Snow, 0.5 ) + self:Transmission( self.Sound.Snow, 0.5 ) elseif precepitation == 4 then - self:Transmission( ATIS.Sound.SnowStorm, 0.5 ) + self:Transmission( self.Sound.SnowStorm, 0.5 ) end if fog then - self:Transmission( ATIS.Sound.Fog, 0.5 ) + self:Transmission( self.Sound.Fog, 0.5 ) end if dust then - self:Transmission( ATIS.Sound.Dust, 0.5 ) + self:Transmission( self.Sound.Dust, 0.5 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2409,29 +2455,29 @@ function ATIS:onafterBroadcast( From, Event, To ) subtitle = string.format( cloudbase, cbase, cceil ) end if not self.useSRS then - self:Transmission( ATIS.Sound.CloudBase, 1.0, subtitle ) + self:Transmission( self.Sound.CloudBase, 1.0, subtitle ) if tonumber( CLOUDBASE1000 ) > 0 then self.radioqueue:Number2Transmission( CLOUDBASE1000 ) - self:Transmission( ATIS.Sound.Thousand, 0.1 ) + self:Transmission( self.Sound.Thousand, 0.1 ) end if tonumber( CLOUDBASE0100 ) > 0 then self.radioqueue:Number2Transmission( CLOUDBASE0100 ) - self:Transmission( ATIS.Sound.Hundred, 0.1 ) + self:Transmission( self.Sound.Hundred, 0.1 ) end -- Ceiling - self:Transmission( ATIS.Sound.CloudCeiling, 0.5 ) + self:Transmission( self.Sound.CloudCeiling, 0.5 ) if tonumber( CLOUDCEIL1000 ) > 0 then self.radioqueue:Number2Transmission( CLOUDCEIL1000 ) - self:Transmission( ATIS.Sound.Thousand, 0.1 ) + self:Transmission( self.Sound.Thousand, 0.1 ) end if tonumber( CLOUDCEIL0100 ) > 0 then self.radioqueue:Number2Transmission( CLOUDCEIL0100 ) - self:Transmission( ATIS.Sound.Hundred, 0.1 ) + self:Transmission( self.Sound.Hundred, 0.1 ) end if self.metric then - self:Transmission( ATIS.Sound.Meters, 0.1 ) + self:Transmission( self.Sound.Meters, 0.1 ) else - self:Transmission( ATIS.Sound.Feet, 0.1 ) + self:Transmission( self.Sound.Feet, 0.1 ) end end end @@ -2459,15 +2505,15 @@ function ATIS:onafterBroadcast( From, Event, To ) end local _TEMPERATURE = subtitle if not self.useSRS then - self:Transmission( ATIS.Sound.Temperature, 1.0, subtitle ) + self:Transmission( self.Sound.Temperature, 1.0, subtitle ) if temperature < 0 then - self:Transmission( ATIS.Sound.Minus, 0.2 ) + self:Transmission( self.Sound.Minus, 0.2 ) end self.radioqueue:Number2Transmission( TEMPERATURE ) if self.TDegF then - self:Transmission( ATIS.Sound.DegreesFahrenheit, 0.2 ) + self:Transmission( self.Sound.DegreesFahrenheit, 0.2 ) else - self:Transmission( ATIS.Sound.DegreesCelsius, 0.2 ) + self:Transmission( self.Sound.DegreesCelsius, 0.2 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2493,15 +2539,15 @@ function ATIS:onafterBroadcast( From, Event, To ) end local _DEWPOINT = subtitle if not self.useSRS then - self:Transmission( ATIS.Sound.DewPoint, 1.0, subtitle ) + self:Transmission( self.Sound.DewPoint, 1.0, subtitle ) if dewpoint < 0 then - self:Transmission( ATIS.Sound.Minus, 0.2 ) + self:Transmission( self.Sound.Minus, 0.2 ) end self.radioqueue:Number2Transmission( DEWPOINT ) if self.TDegF then - self:Transmission( ATIS.Sound.DegreesFahrenheit, 0.2 ) + self:Transmission( self.Sound.DegreesFahrenheit, 0.2 ) else - self:Transmission( ATIS.Sound.DegreesCelsius, 0.2 ) + self:Transmission( self.Sound.DegreesCelsius, 0.2 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2548,33 +2594,33 @@ function ATIS:onafterBroadcast( From, Event, To ) local _ALTIMETER = subtitle if not self.useSRS then - self:Transmission( ATIS.Sound.Altimeter, 1.0, subtitle ) + self:Transmission( self.Sound.Altimeter, 1.0, subtitle ) if not self.qnhonly then - self:Transmission( ATIS.Sound.QNH, 0.5 ) + self:Transmission( self.Sound.QNH, 0.5 ) end self.radioqueue:Number2Transmission( QNH[1] ) if ATIS.ICAOPhraseology[UTILS.GetDCSMap()] then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) end self.radioqueue:Number2Transmission( QNH[2] ) if not self.qnhonly then - self:Transmission( ATIS.Sound.QFE, 0.75 ) + self:Transmission( self.Sound.QFE, 0.75 ) self.radioqueue:Number2Transmission( QFE[1] ) if ATIS.ICAOPhraseology[UTILS.GetDCSMap()] then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) end self.radioqueue:Number2Transmission( QFE[2] ) end if self.PmmHg then - self:Transmission( ATIS.Sound.MillimetersOfMercury, 0.1 ) + self:Transmission( self.Sound.MillimetersOfMercury, 0.1 ) else if self.metric then - self:Transmission( ATIS.Sound.HectoPascal, 0.1 ) + self:Transmission( self.Sound.HectoPascal, 0.1 ) else - self:Transmission( ATIS.Sound.InchesOfMercury, 0.1 ) + self:Transmission( self.Sound.InchesOfMercury, 0.1 ) end end end @@ -2586,40 +2632,54 @@ function ATIS:onafterBroadcast( From, Event, To ) -- Active runway. local subtitle = "" if runwayLanding then + local actrun = self.gettext:GetEntry("ACTIVELANDING",self.locale) - --subtitle=string.format("Active runway landing %s", runwayLanding) + subtitle=string.format("%s %s", actrun, runwayLanding) if rwyLandingLeft==true then - --subtitle=subtitle.." Left" subtitle=subtitle.." "..self.gettext:GetEntry("LEFT",self.locale) elseif rwyLandingLeft==false then - --subtitle=subtitle.." Right" subtitle=subtitle.." "..self.gettext:GetEntry("RIGHT",self.locale) end alltext = alltext .. ";\n" .. subtitle - end + + if not self.useSRS then + self:Transmission(self.Sound.ActiveRunwayArrival, 1.0, subtitle) + self.radioqueue:Number2Transmission(runwayLanding) + if rwyLandingLeft==true then + self:Transmission(self.Sound.Left, 0.2) + elseif rwyLandingLeft==false then + self:Transmission(self.Sound.Right, 0.2) + end + end + + end + if runwayTakeoff then + local actrun = self.gettext:GetEntry("ACTIVERUN",self.locale) - --subtitle=string.format("Active runway %s", runwayLanding) + subtitle=string.format("%s %s", actrun, runwayTakeoff) if rwyTakeoffLeft==true then - --subtitle=subtitle.." Left" subtitle=subtitle.." "..self.gettext:GetEntry("LEFT",self.locale) elseif rwyTakeoffLeft==false then - --subtitle=subtitle.." Right" subtitle=subtitle.." "..self.gettext:GetEntry("RIGHT",self.locale) end + alltext = alltext .. ";\n" .. subtitle + + if not self.useSRS then + self:Transmission(self.Sound.ActiveRunwayDeparture, 1.0, subtitle) + self.radioqueue:Number2Transmission(runwayTakeoff) + if rwyTakeoffLeft==true then + self:Transmission(self.Sound.Left, 0.2) + elseif rwyTakeoffLeft==false then + self:Transmission(self.Sound.Right, 0.2) + end + end + + end _RUNACT = subtitle - if not self.useSRS then - self:Transmission(ATIS.Sound.ActiveRunway, 1.0, subtitle) - self.radioqueue:Number2Transmission(runwayLanding) - if rwyLandingLeft==true then - self:Transmission(ATIS.Sound.Left, 0.2) - elseif rwyLandingLeft==false then - self:Transmission(ATIS.Sound.Right, 0.2) - end - end alltext = alltext .. ";\n" .. subtitle -- Runway length. @@ -2648,31 +2708,32 @@ function ATIS:onafterBroadcast( From, Event, To ) -- Transmit. if not self.useSRS then - self:Transmission( ATIS.Sound.RunwayLength, 1.0, subtitle ) + self:Transmission( self.Sound.RunwayLength, 1.0, subtitle ) if tonumber( L1000 ) > 0 then self.radioqueue:Number2Transmission( L1000 ) - self:Transmission( ATIS.Sound.Thousand, 0.1 ) + self:Transmission( self.Sound.Thousand, 0.1 ) end if tonumber( L0100 ) > 0 then self.radioqueue:Number2Transmission( L0100 ) - self:Transmission( ATIS.Sound.Hundred, 0.1 ) + self:Transmission( self.Sound.Hundred, 0.1 ) end if self.metric then - self:Transmission( ATIS.Sound.Meters, 0.1 ) + self:Transmission( self.Sound.Meters, 0.1 ) else - self:Transmission( ATIS.Sound.Feet, 0.1 ) + self:Transmission( self.Sound.Feet, 0.1 ) end end alltext = alltext .. ";\n" .. subtitle end end + -- Airfield elevation if self.elevation then - + local elev = self.gettext:GetEntry("ELEVATION",self.locale) local meters = self.gettext:GetEntry("METERS",self.locale) local feet = self.gettext:GetEntry("FEET",self.locale) - + local elevation = self.airbase:GetHeight() if not self.metric then elevation = UTILS.MetersToFeet( elevation ) @@ -2692,19 +2753,19 @@ function ATIS:onafterBroadcast( From, Event, To ) -- Transmit. if not self.useSRS then - self:Transmission( ATIS.Sound.Elevation, 1.0, subtitle ) + self:Transmission( self.Sound.Elevation, 1.0, subtitle ) if tonumber( L1000 ) > 0 then self.radioqueue:Number2Transmission( L1000 ) - self:Transmission( ATIS.Sound.Thousand, 0.1 ) + self:Transmission( self.Sound.Thousand, 0.1 ) end if tonumber( L0100 ) > 0 then self.radioqueue:Number2Transmission( L0100 ) - self:Transmission( ATIS.Sound.Hundred, 0.1 ) + self:Transmission( self.Sound.Hundred, 0.1 ) end if self.metric then - self:Transmission( ATIS.Sound.Meters, 0.1 ) + self:Transmission( self.Sound.Meters, 0.1 ) else - self:Transmission( ATIS.Sound.Feet, 0.1 ) + self:Transmission( self.Sound.Feet, 0.1 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2723,16 +2784,16 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Tower frequency %s", freqs ) subtitle = string.format( "%s %s", twrfrq, freqs ) if not self.useSRS then - self:Transmission( ATIS.Sound.TowerFrequency, 1.0, subtitle ) + self:Transmission( self.Sound.TowerFrequency, 1.0, subtitle ) for _, freq in pairs( self.towerfrequency ) do local f = string.format( "%.3f", freq ) f = UTILS.Split( f, "." ) self.radioqueue:Number2Transmission( f[1], nil, 0.5 ) if tonumber( f[2] ) > 0 then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) self.radioqueue:Number2Transmission( f[2] ) end - self:Transmission( ATIS.Sound.MegaHertz, 0.2 ) + self:Transmission( self.Sound.MegaHertz, 0.2 ) end end alltext = alltext .. ";\n" .. subtitle @@ -2745,15 +2806,15 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "ILS frequency %.2f MHz", ils.frequency ) subtitle = string.format( "%s %.2f MHz", ilstxt, ils.frequency ) if not self.useSRS then - self:Transmission( ATIS.Sound.ILSFrequency, 1.0, subtitle ) + self:Transmission( self.Sound.ILSFrequency, 1.0, subtitle ) local f = string.format( "%.2f", ils.frequency ) f = UTILS.Split( f, "." ) self.radioqueue:Number2Transmission( f[1], nil, 0.5 ) if tonumber( f[2] ) > 0 then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) self.radioqueue:Number2Transmission( f[2] ) end - self:Transmission( ATIS.Sound.MegaHertz, 0.2 ) + self:Transmission( self.Sound.MegaHertz, 0.2 ) end alltext = alltext .. ";\n" .. subtitle end @@ -2765,15 +2826,15 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Outer NDB frequency %.2f MHz", ndb.frequency ) subtitle = string.format( "%s %.2f MHz", ndbtxt, ndb.frequency ) if not self.useSRS then - self:Transmission( ATIS.Sound.OuterNDBFrequency, 1.0, subtitle ) + self:Transmission( self.Sound.OuterNDBFrequency, 1.0, subtitle ) local f = string.format( "%.2f", ndb.frequency ) f = UTILS.Split( f, "." ) self.radioqueue:Number2Transmission( f[1], nil, 0.5 ) if tonumber( f[2] ) > 0 then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) self.radioqueue:Number2Transmission( f[2] ) end - self:Transmission( ATIS.Sound.MegaHertz, 0.2 ) + self:Transmission( self.Sound.MegaHertz, 0.2 ) end alltext = alltext .. ";\n" .. subtitle end @@ -2785,15 +2846,15 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Inner NDB frequency %.2f MHz", ndb.frequency ) subtitle = string.format( "%s %.2f MHz", ndbtxt, ndb.frequency ) if not self.useSRS then - self:Transmission( ATIS.Sound.InnerNDBFrequency, 1.0, subtitle ) + self:Transmission( self.Sound.InnerNDBFrequency, 1.0, subtitle ) local f = string.format( "%.2f", ndb.frequency ) f = UTILS.Split( f, "." ) self.radioqueue:Number2Transmission( f[1], nil, 0.5 ) if tonumber( f[2] ) > 0 then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) self.radioqueue:Number2Transmission( f[2] ) end - self:Transmission( ATIS.Sound.MegaHertz, 0.2 ) + self:Transmission( self.Sound.MegaHertz, 0.2 ) end alltext = alltext .. ";\n" .. subtitle end @@ -2809,15 +2870,15 @@ function ATIS:onafterBroadcast( From, Event, To ) subtitle = string.format( "%s %.2f MHz", vorttstxt, self.vor ) end if not self.useSRS then - self:Transmission( ATIS.Sound.VORFrequency, 1.0, subtitle ) + self:Transmission( self.Sound.VORFrequency, 1.0, subtitle ) local f = string.format( "%.2f", self.vor ) f = UTILS.Split( f, "." ) self.radioqueue:Number2Transmission( f[1], nil, 0.5 ) if tonumber( f[2] ) > 0 then - self:Transmission( ATIS.Sound.Decimal, 0.2 ) + self:Transmission( self.Sound.Decimal, 0.2 ) self.radioqueue:Number2Transmission( f[2] ) end - self:Transmission( ATIS.Sound.MegaHertz, 0.2 ) + self:Transmission( self.Sound.MegaHertz, 0.2 ) end alltext = alltext .. ";\n" .. subtitle end @@ -2828,7 +2889,7 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle=string.format("TACAN channel %dX Ray", self.tacan) subtitle=string.format(tactxt, self.tacan) if not self.useSRS then - self:Transmission( ATIS.Sound.TACANChannel, 1.0, subtitle ) + self:Transmission( self.Sound.TACANChannel, 1.0, subtitle ) self.radioqueue:Number2Transmission( tostring( self.tacan ), nil, 0.2 ) self.radioqueue:NewTransmission( "Xray.ogg", 0.75, self.soundpathNato, nil, 0.2 ) end @@ -2841,7 +2902,7 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "RSBN channel %d", self.rsbn ) subtitle = string.format( "%s %d", rsbntxt, self.rsbn ) if not self.useSRS then - self:Transmission( ATIS.Sound.RSBNChannel, 1.0, subtitle ) + self:Transmission( self.Sound.RSBNChannel, 1.0, subtitle ) self.radioqueue:Number2Transmission( tostring( self.rsbn ), nil, 0.2 ) end alltext = alltext .. ";\n" .. subtitle @@ -2854,7 +2915,7 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "PRMG channel %d", ndb.frequency ) subtitle = string.format( "%s %d", prmtxt, ndb.frequency ) if not self.useSRS then - self:Transmission( ATIS.Sound.PRMGChannel, 1.0, subtitle ) + self:Transmission( self.Sound.PRMGChannel, 1.0, subtitle ) self.radioqueue:Number2Transmission( tostring( ndb.frequency ), nil, 0.5 ) end alltext = alltext .. ";\n" .. subtitle @@ -2870,7 +2931,7 @@ function ATIS:onafterBroadcast( From, Event, To ) --subtitle = string.format( "Advise on initial contact, you have information %s", NATO ) subtitle = string.format( "%s %s", advtxt, NATO ) if not self.useSRS then - self:Transmission( ATIS.Sound.AdviceOnInitial, 0.5, subtitle ) + self:Transmission( self.Sound.AdviceOnInitial, 0.5, subtitle ) self.radioqueue:NewTransmission( string.format( "%s.ogg", NATO ), 0.75, self.soundpathNato ) end alltext = alltext .. ";\n" .. subtitle @@ -2910,8 +2971,8 @@ function ATIS:onafterReport( From, Event, To, Text ) local emes = self.gettext:GetEntry("METERSPER",self.locale) local tacan = self.gettext:GetEntry("TACAN",self.locale) local farp = self.gettext:GetEntry("FARP",self.locale) - - + + local text = string.gsub( text, "SM", statute ) text = string.gsub( text, "°C", degc ) text = string.gsub( text, "°F", degf ) @@ -2921,13 +2982,13 @@ function ATIS:onafterReport( From, Event, To, Text ) text = string.gsub( text, "m/s", emes ) text = string.gsub( text, "TACAN", tacan ) text = string.gsub( text, "FARP", farp ) - + local delimiter = self.gettext:GetEntry("DELIMITER",self.locale) - + if string.lower(self.locale) ~= "en" then text = string.gsub(text,"(%d+)(%.)(%d+)","%1 "..delimiter.." %3") end - + -- Replace ";" by "." local text = string.gsub( text, ";", " . " ) diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index b5ed5647c..0592046df 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -3240,7 +3240,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) else -- Mission not supported. - self:E(self.lid..string.format("ERROR: Mission type not supported for OPSZONE! Unrecruiting assets...")) + self:E(self.lid..string.format("ERROR: Mission type %s not supported for OPSZONE! Unrecruiting assets...", tostring(MissionType))) LEGION.UnRecruitAssets(assets) return false diff --git a/Moose Development/Moose/Ops/EasyGCICAP.lua b/Moose Development/Moose/Ops/EasyGCICAP.lua index e9db4aea1..06ae1d6ca 100644 --- a/Moose Development/Moose/Ops/EasyGCICAP.lua +++ b/Moose Development/Moose/Ops/EasyGCICAP.lua @@ -65,6 +65,8 @@ -- @field #boolean TankerInvisible -- @field #number CapFormation -- @field #table ReadyFlightGroups +-- @field #boolean DespawnAfterLanding +-- @field #boolean DespawnAfterHolding -- @extends Core.Fsm#FSM --- *“Airspeed, altitude, and brains. Two are always needed to successfully complete the flight.”* -- Unknown. @@ -209,6 +211,8 @@ EASYGCICAP = { TankerInvisible = true, CapFormation = nil, ReadyFlightGroups = {}, + DespawnAfterLanding = false, + DespawnAfterHolding = true, } --- Internal Squadron data type @@ -244,7 +248,7 @@ EASYGCICAP = { --- EASYGCICAP class version. -- @field #string version -EASYGCICAP.version="0.1.10" +EASYGCICAP.version="0.1.11" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -292,6 +296,8 @@ function EASYGCICAP:New(Alias, AirbaseName, Coalition, EWRName) self.Monitor = false self.TankerInvisible = true self.CapFormation = ENUMS.Formation.FixedWing.FingerFour.Group + self.DespawnAfterLanding = false + self.DespawnAfterHolding = true -- Set some string id for output to DCS.log file. self.lid=string.format("EASYGCICAP %s | ", self.alias) @@ -341,7 +347,7 @@ end -- @param #number Maxiumum Maxmimum number of parallel missions allowed. Count is Cap-Missions + Intercept-Missions + Alert5-Missionsm default is 6 -- @return #EASYGCICAP self function EASYGCICAP:SetMaxAliveMissions(Maxiumum) - self:T(self.lid.."SetDefaultResurrection") + self:T(self.lid.."SetMaxAliveMissions") self.MaxAliveMissions = Maxiumum or 8 return self end @@ -458,6 +464,26 @@ function EASYGCICAP:SetDefaultOverhead(Overhead) return self end +--- Set default despawning after landing. +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultDespawnAfterLanding() + self:T(self.lid.."SetDefaultDespawnAfterLanding") + self.DespawnAfterLanding = true + self.DespawnAfterHolding = false + return self +end + +--- Set default despawning after holding (despawn in air close to AFB). +-- @param #EASYGCICAP self +-- @return #EASYGCICAP self +function EASYGCICAP:SetDefaultDespawnAfterHolding() + self:T(self.lid.."SetDefaultDespawnAfterLanding") + self.DespawnAfterLanding = false + self.DespawnAfterHolding = true + return self +end + --- Set CAP mission start to vary randomly between Start end End seconds. -- @param #EASYGCICAP self -- @param #number Start @@ -512,6 +538,8 @@ function EASYGCICAP:_AddAirwing(Airbasename, Alias) self:T(self.lid.."_AddAirwing "..Airbasename) local CapFormation = self.CapFormation + local DespawnAfterLanding = self.DespawnAfterLanding + local DespawnAfterHolding = self.DespawnAfterHolding -- Create Airwing local CAP_Wing = AIRWING:New(Airbasename,Alias) @@ -553,8 +581,11 @@ function EASYGCICAP:_AddAirwing(Airbasename, Alias) function CAP_Wing:OnAfterFlightOnMission(From, Event, To, Flightgroup, Mission) local flightgroup = Flightgroup -- Ops.FlightGroup#FLIGHTGROUP - --flightgroup:SetDespawnAfterLanding() - flightgroup:SetDespawnAfterHolding() + if DespawnAfterLanding then + flightgroup:SetDespawnAfterLanding() + elseif DespawnAfterHolding then + flightgroup:SetDespawnAfterHolding() + end flightgroup:SetDestinationbase(AIRBASE:FindByName(Airbasename)) flightgroup:GetGroup():CommandEPLRS(true,5) flightgroup:GetGroup():SetOptionRadarUsingForContinousSearch() @@ -577,10 +608,11 @@ function EASYGCICAP:_AddAirwing(Airbasename, Alias) flightgroup:GetGroup():OptionROTEvadeFire() flightgroup:SetFuelLowRTB(true) Intel:AddAgent(flightgroup) - function flightgroup:OnAfterHolding(From,Event,To) - self:Despawn(1,true) - end - + if DespawnAfterHolding then + function flightgroup:OnAfterHolding(From,Event,To) + self:Despawn(1,true) + end + end end if self.noaltert5 > 0 then diff --git a/Moose Development/Moose/Sound/RadioQueue.lua b/Moose Development/Moose/Sound/RadioQueue.lua index 7f320cedc..43a5c6aac 100644 --- a/Moose Development/Moose/Sound/RadioQueue.lua +++ b/Moose Development/Moose/Sound/RadioQueue.lua @@ -268,7 +268,7 @@ function RADIOQUEUE:NewTransmission(filename, duration, path, tstart, interval, return nil end if type(duration)~="number" then - self:E(self.lid.."ERROR: Duration specified is NOT a number.") + self:E(self.lid..string.format("ERROR: Duration specified is NOT a number but type=%s. Filename=%s, duration=%s", type(duration), tostring(filename), tostring(duration))) return nil end @@ -361,6 +361,7 @@ end -- @param #RADIOQUEUE self -- @param #RADIOQUEUE.Transmission transmission The transmission. function RADIOQUEUE:Broadcast(transmission) + self:T("Broarcast") if ((transmission.soundfile and transmission.soundfile.useSRS) or transmission.soundtext) and self.msrs then self:_BroadcastSRS(transmission) @@ -425,7 +426,7 @@ function RADIOQUEUE:Broadcast(transmission) else -- Broadcasting from carrier. No subtitle possible. Need to send messages to players. - self:T(self.lid..string.format("Broadcasting via trigger.action.radioTransmission().")) + self:T(self.lid..string.format("Broadcasting via trigger.action.radioTransmission()")) -- Position from where to transmit. local vec3=nil @@ -453,6 +454,8 @@ function RADIOQUEUE:Broadcast(transmission) local text=string.format("file=%s, freq=%.2f MHz, duration=%.2f sec, subtitle=%s", filename, self.frequency/1000000, transmission.duration, transmission.subtitle or "") MESSAGE:New(string.format(text, filename, transmission.duration, transmission.subtitle or ""), 5, "RADIOQUEUE "..self.alias):ToAll() end + else + self:E("ERROR: Could not get vec3 to determin transmission origin! Did you specify a sender and is it still alive?") end end @@ -482,7 +485,6 @@ end --- Check radio queue for transmissions to be broadcasted. -- @param #RADIOQUEUE self function RADIOQUEUE:_CheckRadioQueue() - --env.info("FF check radio queue "..self.alias) -- Check if queue is empty. if #self.queue==0 then diff --git a/Moose Development/Moose/Sound/SoundOutput.lua b/Moose Development/Moose/Sound/SoundOutput.lua index 537255dac..466d0fa22 100644 --- a/Moose Development/Moose/Sound/SoundOutput.lua +++ b/Moose Development/Moose/Sound/SoundOutput.lua @@ -160,7 +160,7 @@ do -- Sound File -- @param #string FileName The name of the sound file, e.g. "Hello World.ogg". -- @param #string Path The path of the directory, where the sound file is located. Default is "l10n/DEFAULT/" within the miz file. -- @param #number Duration Duration in seconds, how long it takes to play the sound file. Default is 3 seconds. - -- @param #bolean UseSrs Set if SRS should be used to play this file. Default is false. + -- @param #boolean UseSrs Set if SRS should be used to play this file. Default is false. -- @return #SOUNDFILE self function SOUNDFILE:New(FileName, Path, Duration, UseSrs) @@ -249,6 +249,9 @@ do -- Sound File -- @param #string Duration Duration in seconds. Default 3 seconds. -- @return #SOUNDFILE self function SOUNDFILE:SetDuration(Duration) + if Duration and type(Duration)=="string" then + Duration=tonumber(Duration) + end self.duration=Duration or 3 return self end diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index a8d9677da..3bd3bf716 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -3497,14 +3497,14 @@ end --- Checks if the current time is in between start_time and end_time -- @param #string time_string_01 Time string like "07:15:22" -- @param #string time_string_02 Time string like "08:11:27" --- @return #bool True if it is, False if it's not +-- @return #boolean True if it is, False if it's not function UTILS.TimeBetween(start_time, end_time) return UTILS.TimeLaterThan(start_time) and UTILS.TimeBefore(end_time) end --- Easy to read one line to roll the dice on something. 1% is very unlikely to happen, 99% is very likely to happen -- @param #number chance (optional) Percentage chance you want something to happen. Defaults to a random number if not given --- @return #bool True if the dice roll was within the given percentage chance of happening +-- @return #boolean True if the dice roll was within the given percentage chance of happening function UTILS.PercentageChance(chance) chance = chance or math.random(0, 100) chance = UTILS.Clamp(chance, 0, 100) @@ -3557,10 +3557,10 @@ function UTILS.RemapValue(value, old_min, old_max, new_min, new_max) end --- Given a triangle made out of 3 vector 2s, return a vec2 that is a random number in this triangle --- @param #Vec2 pt1 Min value to remap from --- @param #Vec2 pt2 Max value to remap from --- @param #Vec2 pt3 Max value to remap from --- @return #Vec2 Random point in triangle +-- @param DCS#Vec2 pt1 Min value to remap from +-- @param DCS#Vec2 pt2 Max value to remap from +-- @param DCS#Vec2 pt3 Max value to remap from +-- @return DCS#Vec2 Random point in triangle function UTILS.RandomPointInTriangle(pt1, pt2, pt3) local pt = {math.random(), math.random()} table.sort(pt) @@ -3578,7 +3578,7 @@ end -- @param #number angle Min value to remap from -- @param #number min Max value to remap from -- @param #number max Max value to remap from --- @return #bool +-- @return #boolean function UTILS.AngleBetween(angle, min, max) angle = (360 + (angle % 360)) % 360 min = (360 + min % 360) % 360 @@ -3638,10 +3638,10 @@ end --- Rotates a point around another point with a given angle. Useful if you're loading in groups or --- statics but you want to rotate them all as a collection. You can get the center point of everything --- and then rotate all the positions of every object around this center point. --- @param #Vec2 point Point that you want to rotate --- @param #Vec2 pivot Pivot point of the rotation +-- @param DCS#Vec2 point Point that you want to rotate +-- @param DCS#Vec2 pivot Pivot point of the rotation -- @param #number angle How many degrees the point should be rotated --- @return #Vec Rotated point +-- @return DCS#Vec2 Rotated point function UTILS.RotatePointAroundPivot(point, pivot, angle) local radians = math.rad(angle) @@ -3673,7 +3673,7 @@ end --- Check if a string starts with something -- @param #string str String to check -- @param #string value --- @return #bool True if str starts with value +-- @return #boolean True if str starts with value function string.startswith(str, value) return string.sub(str,1,string.len(value)) == value end @@ -3682,7 +3682,7 @@ end --- Check if a string ends with something -- @param #string str String to check -- @param #string value --- @return #bool True if str ends with value +-- @return #boolean True if str ends with value function string.endswith(str, value) return value == "" or str:sub(-#value) == value end @@ -3705,16 +3705,16 @@ end --- string.split("hello_dcs_world", "-") would return {"hello", "dcs", "world"} -- @param #string str -- @param #string value --- @return #bool True if str contains value +-- @return #boolean True if str contains value function string.contains(str, value) return string.match(str, value) end --- Moves an object from one table to another --- @param #obj object to move --- @param #from_table table to move from --- @param #to_table table to move to +-- @param #table obj object to move +-- @param #table from_table table to move from +-- @param #table to_table table to move to function table.move_object(obj, from_table, to_table) local index for i, v in pairs(from_table) do @@ -3733,7 +3733,7 @@ end --- The table can be made up out of complex tables or values as well -- @param #table tbl -- @param #string element --- @return #bool True if tbl contains element +-- @return #boolean True if tbl contains element function table.contains(tbl, element) if element == nil or tbl == nil then return false end @@ -3750,7 +3750,7 @@ end --- Checks if a table contains a specific key. -- @param #table tbl Table to check -- @param #string key Key to look for --- @return #bool True if tbl contains key +-- @return #boolean True if tbl contains key function table.contains_key(tbl, key) if tbl[key] ~= nil then return true else return false end end @@ -3797,7 +3797,7 @@ end --- Finds the index of an element in a table. -- @param #table table Table to search -- @param #string element Element to find --- @return #int Index of the element, or nil if not found +-- @return #number Index of the element, or nil if not found function table.index_of(table, element) for i, v in ipairs(table) do if v == element then @@ -3809,7 +3809,7 @@ end --- Counts the number of elements in a table. -- @param #table T Table to count --- @return #int Number of elements in the table +-- @return #number Number of elements in the table function table.length(T) local count = 0 for _ in pairs(T) do count = count + 1 end @@ -3818,8 +3818,8 @@ end --- Slices a table between two indices, much like Python's my_list[2:-1] -- @param #table tbl Table to slice --- @param #int first Starting index --- @param #int last Ending index +-- @param #number first Starting index +-- @param #number last Ending index -- @return #table Sliced table function table.slice(tbl, first, last) local sliced = {} @@ -3840,7 +3840,7 @@ end --- Counts the number of occurrences of a value in a table. -- @param #table tbl Table to search -- @param #string value Value to count --- @return #int Number of occurrences of the value +-- @return #number Number of occurrences of the value function table.count_value(tbl, value) local count = 0 for _, item in pairs(tbl) do @@ -4121,3 +4121,62 @@ function UTILS.MGRSStringToSRSFriendly(Text,Slow) Text = "MGRS;"..Text return Text end + + +--- Read csv file and convert it to a lua table. +-- The csv must have a header specifing the names of the columns. The column names are used as table keys. +-- @param #string filename File name including full path on local disk. +-- @return #table The table filled with data from the csv file. +function UTILS.ReadCSV(filename) + + if not UTILS.FileExists(filename) then + env.error("File does not exist") + return nil + end + + --- Function that load data from a file. + local function _loadfile( filename ) + local f = io.open( filename, "rb" ) + if f then + local data = f:read( "*all" ) + f:close() + return data + else + BASE:E(string.format( "WARNING: Could read data from file %s!", tostring( filename ) ) ) + return nil + end + end + + -- Load asset data from file. + local data = _loadfile( filename ) + + local lines=UTILS.Split(data, "\n" ) + + -- Remove carriage returns from end of lines + for _,line in pairs(lines) do + line=string.gsub(line, "[\n\r]","") + end + + local sep=";" + + local columns=UTILS.Split(lines[1], sep) + + -- Remove header line. + table.remove(lines, 1) + + local csvdata={} + for i, line in pairs(lines) do + line=string.gsub(line, "[\n\r]","") + + local row={} + for j, value in pairs(UTILS.Split(line, sep)) do + + local key=string.gsub(columns[j], "[\n\r]","") + row[key]=value + end + table.insert(csvdata, row) + + end + + return csvdata +end