-- region RATConfigFunctions -- @type RATConfig -- @field #string name Name of the RAT scenario. -- @field #boolean enable Enable the RAT scenario. -- @field #number constant_alive_groups Number of groups to keep alive at all times. -- @field #RATGroupConfig[] aircrafts_groupconfigs Table of aircraft group configurations. -- @type RATGroupConfig -- @field #string[] templatename Template name (string or table of strings). -- @field #number minimun_spawns Minimum number of spawns. -- @field #number inactive_timer Inactive timer in seconds. -- @field #boolean atcmessage_enable Enable ATC messages. -- @field #number flightlevelmin Flight level in feet. -- @field #number flightlevelmaw Flight level in feet. -- @field #number speed Speed in knots. -- @field #table liveries Table of liveries. -- @field #boolean allow_immortal Allow immortal groups. -- @field #boolean allow_invisible Allow invisible groups. -- @field #boolean commute Allow commute. -- @field #boolean despawnAirborne Allow Despawn when entering arrival zone. -- @field #RATAirbasesConfig airbases_names Table of airbases names. -- @type RATAirbasesConfig -- @field #string[] departure Departure airbases or zone names. -- @field #string[] arrival Arrival airbases or zone names. --- Parse a RAT config Object. -- @param #JsonObject config Config object to parse -- @return #RATConfig ratConfigJson Parsed QRA config object function ParseRATConfigJson(config) local json = require('Scripts/json') local parser_name = "RAT" -- ************************************************************************** -- enable -- ************************************************************************** local ratConfigJson = {} if config.enable == true then ratConfigJson = config else ratConfigJson = { enable = false, } end Jtff_log.debug( string.format( "parsed RAT config for %s, resulting config :\n%s", config.name or "", json:encode( ratConfigJson, { indent = true } ) ), parser_name ) return ratConfigJson end -- endregion RATConfigFunctions -- region RATFunctions -- endregion RATFunctions -- ***************************************************************************** -- ** Random Air Traffic ** -- ********************************************************* RATManagerArray = {} local compteur = #RATManagerArray for index, currentRATConfigObject in ipairs(RATConfig) do local ratconfig = ParseRATConfigJson(currentRATConfigObject) if ratconfig.enable == true then Jtff_log.info( string.format( "RATManager %s Enable", ratconfig.name ), "RAT" ) compteur = compteur +1 local ratManagerName = ratconfig.name or "unknown" RATManagerArray[compteur] = RATMANAGER:New(ratconfig.constant_alive_groups or nil) RATManagerArray[compteur].RATObjectsArray = {} for index_planegroup, planegroupconfig in ipairs(ratconfig.aircrafts_groupconfigs) do if (type(planegroupconfig.templatename) == "string") then planegroupconfig.templatename = {planegroupconfig.templatename} end if (type(planegroupconfig.templatename) == "table") then for templateindex, templatename in ipairs(planegroupconfig.templatename) do Jtff_log.debug( string.format( "RATManager %s - template %s", ratManagerName, templatename ), "RAT" ) RATManagerArray[compteur].RATObjectsArray[templateindex] = RAT:New(templatename) if (type(planegroupconfig.airbases_names) == "table" ) then RATManagerArray[compteur].RATObjectsArray[templateindex]:SetTakeoff("cold") for airstartindex, airstartname in ipairs(planegroupconfig.airbases_names.departure) do if not(RATManagerArray[compteur].RATObjectsArray[templateindex]:_AirportExists(airstartname)) then RATManagerArray[compteur].RATObjectsArray[templateindex]:SetTakeoff("air") end end for airstopindex, airstopname in ipairs(planegroupconfig.airbases_names.arrival) do if not(RATManagerArray[compteur].RATObjectsArray[templateindex]:_AirportExists(airstopname)) then RATManagerArray[compteur].RATObjectsArray[templateindex]:DestinationZone() end end if (type(planegroupconfig.despawnAirborne) == "boolean" and planegroupconfig.despawnAirborne == true) then RATManagerArray[compteur].RATObjectsArray[templateindex]:DestinationZone() end RATManagerArray[compteur].RATObjectsArray[templateindex]:SetDeparture(planegroupconfig.airbases_names.departure) RATManagerArray[compteur].RATObjectsArray[templateindex]:SetDestination(planegroupconfig.airbases_names.arrival) end if (type(planegroupconfig.inactive_timer) == "number" ) then RATManagerArray[compteur].RATObjectsArray[templateindex]:TimeDestroyInactive(planegroupconfig.inactive_timer) end if (type(planegroupconfig.atcmessage_enable) == "boolean" ) then RATManagerArray[compteur].RATObjectsArray[templateindex]:ATC_Messages(planegroupconfig.atcmessage_enable) else RATManagerArray[compteur].RATObjectsArray[templateindex]:ATC_Messages(false) end if (type(planegroupconfig.flightlevelmin) == "number" ) then RATManagerArray[compteur].RATObjectsArray[templateindex]:SetFLmin(planegroupconfig.flightlevelmin) end if (type(planegroupconfig.flightlevelmax) == "number" ) then RATManagerArray[compteur].RATObjectsArray[templateindex]:SetFLmax(planegroupconfig.flightlevelmax) end if (type(planegroupconfig.speed) == "number") then RATManagerArray[compteur].RATObjectsArray[templateindex]:SetMaxCruiseSpeed(UTILS.KnotsToKmph(planegroupconfig.speed)) end if (planegroupconfig.liveries) then RATManagerArray[compteur].RATObjectsArray[templateindex]:Livery(planegroupconfig.liveries) end if (type(planegroupconfig.allow_immortal) == "boolean" and planegroupconfig.allow_immortal == true) then RATManagerArray[compteur].RATObjectsArray[templateindex]:Immortal() end if not(type(planegroupconfig.allow_invisible) == "boolean" and planegroupconfig.allow_invisible == false) then RATManagerArray[compteur].RATObjectsArray[templateindex]:Invisible() end if (type(planegroupconfig.commute) == "boolean" and planegroupconfig.commute == true) then RATManagerArray[compteur].RATObjectsArray[templateindex]:Commute(true) end RATManagerArray[compteur].RATObjectsArray[templateindex]:SetEPLRS(true) RATManagerArray[compteur].RATObjectsArray[templateindex]:SetROT(ENUMS.ROT.NoReaction) RATManagerArray[compteur]:Add(RATManagerArray[compteur].RATObjectsArray[templateindex], planegroupconfig.minimun_spawns) end else Jtff_log.error( string.format( "RAT error in template name type : %s", planegroupconfig.templatename ), "RAT" ) end end RATManagerArray[compteur].customconfig = ratconfig RATManagerArray[compteur]:Start(SpawnStandardDelay) end end