diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index d54f54a71..fb9e31513 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -1510,7 +1510,7 @@ do -- AI_A2A_DISPATCHER local Message = "Clearing (" .. DefenderTask.Type .. ") " Message = Message .. Defender:GetName() if Target then - Message = Message .. ( Target and ( " from " .. Target.Index .. " [" .. Target.Set:Count() .. "]" ) ) or "" + Message = Message .. ((Target and (" from " .. Target.Index .. " [" .. Target.Set:Count() .. "]")) or "") end self:F( { Target = Message } ) end @@ -1559,7 +1559,7 @@ do -- AI_A2A_DISPATCHER local Message = "(" .. self.DefenderTasks[Defender].Type .. ") " Message = Message .. Defender:GetName() - Message = Message .. ( AttackerDetection and ( " target " .. AttackerDetection.Index .. " [" .. AttackerDetection.Set:Count() .. "]" ) ) or "" + Message = Message .. ((AttackerDetection and (" target " .. AttackerDetection.Index .. " [" .. AttackerDetection.Set:Count() .. "]")) or "") self:F( { AttackerDetection = Message } ) if AttackerDetection then self.DefenderTasks[Defender].Target = AttackerDetection @@ -2653,7 +2653,7 @@ do -- AI_A2A_DISPATCHER -- -- Let flights by default land and despawn at engine shutdown. -- A2ADispatcher:SetDefaultLandingAtEngineShutdown() -- - function AI_A2A_DISPATCHER:SetDefaultLandingAtEngineShutdown() + function AI_A2A_DISPATCHER:SetDefaultLandingAtEngineShutdown() self:SetDefaultLanding( AI_A2A_DISPATCHER.Landing.AtEngineShutdown ) diff --git a/Moose Development/Moose/Wrapper/Airbase.lua b/Moose Development/Moose/Wrapper/Airbase.lua index fbac09d45..492d5af24 100644 --- a/Moose Development/Moose/Wrapper/Airbase.lua +++ b/Moose Development/Moose/Wrapper/Airbase.lua @@ -11,7 +11,6 @@ -- @module Wrapper.Airbase -- @image Wrapper_Airbase.JPG - --- @type AIRBASE -- @field #string ClassName Name of the class, i.e. "AIRBASE". -- @field #table CategoryName Names of airbase categories. @@ -52,7 +51,7 @@ -- * @{#AIRBASE.Find}(): Find a AIRBASE instance from the _DATABASE object using a DCS Airbase object. -- * @{#AIRBASE.FindByName}(): Find a AIRBASE instance from the _DATABASE object using a DCS Airbase name. -- --- IMPORTANT: ONE SHOULD NEVER SANATIZE these AIRBASE OBJECT REFERENCES! (make the AIRBASE object references nil). +-- IMPORTANT: ONE SHOULD NEVER SANITIZE these AIRBASE OBJECT REFERENCES! (make the AIRBASE object references nil). -- -- ## DCS Airbase APIs -- @@ -63,14 +62,14 @@ -- -- @field #AIRBASE AIRBASE AIRBASE = { - ClassName="AIRBASE", + ClassName = "AIRBASE", CategoryName = { - [Airbase.Category.AIRDROME] = "Airdrome", - [Airbase.Category.HELIPAD] = "Helipad", - [Airbase.Category.SHIP] = "Ship", - }, - activerwyno=nil, - } + [Airbase.Category.AIRDROME] = "Airdrome", + [Airbase.Category.HELIPAD] = "Helipad", + [Airbase.Category.SHIP] = "Ship", + }, + activerwyno = nil, +} --- Enumeration to identify the airbases in the Caucasus region. -- @@ -121,7 +120,7 @@ AIRBASE.Caucasus = { ["Nalchik"] = "Nalchik", ["Mozdok"] = "Mozdok", ["Beslan"] = "Beslan", - } +} --- Airbases of the Nevada map: -- @@ -162,7 +161,7 @@ AIRBASE.Nevada = { ["Pahute_Mesa_Airstrip"] = "Pahute Mesa", ["Tonopah_Airport"] = "Tonopah", ["Tonopah_Test_Range_Airfield"] = "Tonopah Test Range", - } +} --- Airbases of the Normandy map: -- @@ -386,64 +385,62 @@ AIRBASE.TheChannel = { -- * AIRBASE.Syria.An_Nasiriyah -- * AIRBASE.Syria.Abu_al_Duhur -- ---@field Syria -AIRBASE.Syria={ - ["Kuweires"]="Kuweires", - ["Marj_Ruhayyil"]="Marj Ruhayyil", - ["Kiryat_Shmona"]="Kiryat Shmona", - ["Marj_as_Sultan_North"]="Marj as Sultan North", - ["Eyn_Shemer"]="Eyn Shemer", - ["Incirlik"]="Incirlik", - ["Damascus"]="Damascus", - ["Bassel_Al_Assad"]="Bassel Al-Assad", - ["Rosh_Pina"]="Rosh Pina", - ["Aleppo"]="Aleppo", - ["Al_Qusayr"]="Al Qusayr", - ["Wujah_Al_Hajar"]="Wujah Al Hajar", - ["Al_Dumayr"]="Al-Dumayr", - ["Gazipasa"]="Gazipasa", - ["Ru_Convoy_4"]="Ru Convoy-4", - ["Hatay"]="Hatay", - ["Nicosia"]="Nicosia", - ["Pinarbashi"]="Pinarbashi", - ["Paphos"]="Paphos", - ["Kingsfield"]="Kingsfield", - ["Thalah"]="Tha'lah", - ["Haifa"]="Haifa", - ["Khalkhalah"]="Khalkhalah", - ["Megiddo"]="Megiddo", - ["Lakatamia"]="Lakatamia", - ["Rayak"]="Rayak", - ["Larnaca"]="Larnaca", - ["Mezzeh"]="Mezzeh", - ["Gecitkale"]="Gecitkale", - ["Akrotiri"]="Akrotiri", - ["Naqoura"]="Naqoura", - ["Gaziantep"]="Gaziantep", - ["Sayqal"]="Sayqal", - ["Tiyas"]="Tiyas", - ["Shayrat"]="Shayrat", - ["Taftanaz"]="Taftanaz", - ["H4"]="H4", - ["King_Hussein_Air_College"]="King Hussein Air College", - ["Rene_Mouawad"]="Rene Mouawad", - ["Jirah"]="Jirah", - ["Ramat_David"]="Ramat David", - ["Qabr_as_Sitt"]="Qabr as Sitt", - ["Minakh"]="Minakh", - ["Adana_Sakirpasa"]="Adana Sakirpasa", - ["Palmyra"]="Palmyra", - ["Hama"]="Hama", - ["Ercan"]="Ercan", - ["Marj_as_Sultan_South"]="Marj as Sultan South", - ["Tabqa"]="Tabqa", - ["Beirut_Rafic_Hariri"]="Beirut-Rafic Hariri", - ["An_Nasiriyah"]="An Nasiriyah", - ["Abu_al_Duhur"]="Abu al-Duhur", +-- @field Syria +AIRBASE.Syria = { + ["Kuweires"] = "Kuweires", + ["Marj_Ruhayyil"] = "Marj Ruhayyil", + ["Kiryat_Shmona"] = "Kiryat Shmona", + ["Marj_as_Sultan_North"] = "Marj as Sultan North", + ["Eyn_Shemer"] = "Eyn Shemer", + ["Incirlik"] = "Incirlik", + ["Damascus"] = "Damascus", + ["Bassel_Al_Assad"] = "Bassel Al-Assad", + ["Rosh_Pina"] = "Rosh Pina", + ["Aleppo"] = "Aleppo", + ["Al_Qusayr"] = "Al Qusayr", + ["Wujah_Al_Hajar"] = "Wujah Al Hajar", + ["Al_Dumayr"] = "Al-Dumayr", + ["Gazipasa"] = "Gazipasa", + ["Ru_Convoy_4"] = "Ru Convoy-4", + ["Hatay"] = "Hatay", + ["Nicosia"] = "Nicosia", + ["Pinarbashi"] = "Pinarbashi", + ["Paphos"] = "Paphos", + ["Kingsfield"] = "Kingsfield", + ["Thalah"] = "Tha'lah", + ["Haifa"] = "Haifa", + ["Khalkhalah"] = "Khalkhalah", + ["Megiddo"] = "Megiddo", + ["Lakatamia"] = "Lakatamia", + ["Rayak"] = "Rayak", + ["Larnaca"] = "Larnaca", + ["Mezzeh"] = "Mezzeh", + ["Gecitkale"] = "Gecitkale", + ["Akrotiri"] = "Akrotiri", + ["Naqoura"] = "Naqoura", + ["Gaziantep"] = "Gaziantep", + ["Sayqal"] = "Sayqal", + ["Tiyas"] = "Tiyas", + ["Shayrat"] = "Shayrat", + ["Taftanaz"] = "Taftanaz", + ["H4"] = "H4", + ["King_Hussein_Air_College"] = "King Hussein Air College", + ["Rene_Mouawad"] = "Rene Mouawad", + ["Jirah"] = "Jirah", + ["Ramat_David"] = "Ramat David", + ["Qabr_as_Sitt"] = "Qabr as Sitt", + ["Minakh"] = "Minakh", + ["Adana_Sakirpasa"] = "Adana Sakirpasa", + ["Palmyra"] = "Palmyra", + ["Hama"] = "Hama", + ["Ercan"] = "Ercan", + ["Marj_as_Sultan_South"] = "Marj as Sultan South", + ["Tabqa"] = "Tabqa", + ["Beirut_Rafic_Hariri"] = "Beirut-Rafic Hariri", + ["An_Nasiriyah"] = "An Nasiriyah", + ["Abu_al_Duhur"] = "Abu al-Duhur", } - - --- Airbases of the Mariana Islands map: -- -- * AIRBASE.MarianaIslands.Rota_Intl @@ -453,17 +450,16 @@ AIRBASE.Syria={ -- * AIRBASE.MarianaIslands.Tinian_Intl -- * AIRBASE.MarianaIslands.Olf_Orote -- ---@field MarianaIslands -AIRBASE.MarianaIslands={ - ["Rota_Intl"]="Rota Intl", - ["Andersen_AFB"]="Andersen AFB", - ["Antonio_B_Won_Pat_Intl"]="Antonio B. Won Pat Intl", - ["Saipan_Intl"]="Saipan Intl", - ["Tinian_Intl"]="Tinian Intl", - ["Olf_Orote"]="Olf Orote", +-- @field MarianaIslands +AIRBASE.MarianaIslands = { + ["Rota_Intl"] = "Rota Intl", + ["Andersen_AFB"] = "Andersen AFB", + ["Antonio_B_Won_Pat_Intl"] = "Antonio B. Won Pat Intl", + ["Saipan_Intl"] = "Saipan Intl", + ["Tinian_Intl"] = "Tinian Intl", + ["Olf_Orote"] = "Olf Orote", } - --- AIRBASE.ParkingSpot ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy". -- @type AIRBASE.ParkingSpot -- @field Core.Point#COORDINATE Coordinate Coordinate of the parking spot. @@ -497,14 +493,14 @@ AIRBASE.MarianaIslands={ -- @field #number HelicopterUsable 216: Combines HelicopterOnly, OpenMed and OpenBig. -- @field #number FighterAircraft 244: Combines Shelter. OpenMed and OpenBig spots. So effectively all spots usable by fixed wing aircraft. AIRBASE.TerminalType = { - Runway=16, - HelicopterOnly=40, - Shelter=68, - OpenMed=72, - OpenBig=104, - OpenMedOrBig=176, - HelicopterUsable=216, - FighterAircraft=244, + Runway = 16, + HelicopterOnly = 40, + Shelter = 68, + OpenMed = 72, + OpenBig = 104, + OpenMedOrBig = 176, + HelicopterUsable = 216, + FighterAircraft = 244, } --- Runway data. @@ -523,59 +519,59 @@ AIRBASE.TerminalType = { -- @param #AIRBASE self -- @param #string AirbaseName The name of the airbase. -- @return #AIRBASE self -function AIRBASE:Register(AirbaseName) +function AIRBASE:Register( AirbaseName ) -- Inherit everything from positionable. - local self=BASE:Inherit(self, POSITIONABLE:New(AirbaseName)) --#AIRBASE + local self = BASE:Inherit( self, POSITIONABLE:New( AirbaseName ) ) -- #AIRBASE -- Set airbase name. - self.AirbaseName=AirbaseName + self.AirbaseName = AirbaseName -- Set airbase ID. - self.AirbaseID=self:GetID(true) + self.AirbaseID = self:GetID( true ) -- Get descriptors. - self.descriptors=self:GetDesc() + self.descriptors = self:GetDesc() -- Category. - self.category=self.descriptors and self.descriptors.category or Airbase.Category.AIRDROME + self.category = self.descriptors and self.descriptors.category or Airbase.Category.AIRDROME -- Set category. - if self.category==Airbase.Category.AIRDROME then - self.isAirdrome=true - elseif self.category==Airbase.Category.HELIPAD then - self.isHelipad=true - elseif self.category==Airbase.Category.SHIP then - self.isShip=true + if self.category == Airbase.Category.AIRDROME then + self.isAirdrome = true + elseif self.category == Airbase.Category.HELIPAD then + self.isHelipad = true + elseif self.category == Airbase.Category.SHIP then + self.isShip = true -- DCS bug: Oil rigs and gas platforms have category=2 (ship). Also they cannot be retrieved by coalition.getStaticObjects() - if self.descriptors.typeName=="Oil rig" or self.descriptors.typeName=="Ga" then - self.isHelipad=true - self.isShip=false - self.category=Airbase.Category.HELIPAD - _DATABASE:AddStatic(AirbaseName) - end + if self.descriptors.typeName == "Oil rig" or self.descriptors.typeName == "Ga" then + self.isHelipad = true + self.isShip = false + self.category = Airbase.Category.HELIPAD + _DATABASE:AddStatic( AirbaseName ) + end else - self:E("ERROR: Unknown airbase category!") + self:E( "ERROR: Unknown airbase category!" ) end self:_InitParkingSpots() - local vec2=self:GetVec2() + local vec2 = self:GetVec2() -- Init coordinate. self:GetCoordinate() if vec2 then if self.isShip then - local unit=UNIT:FindByName(AirbaseName) + local unit = UNIT:FindByName( AirbaseName ) if unit then - self.AirbaseZone=ZONE_UNIT:New(AirbaseName, unit, 2500) + self.AirbaseZone = ZONE_UNIT:New( AirbaseName, unit, 2500 ) end else - self.AirbaseZone=ZONE_RADIUS:New(AirbaseName, vec2, 2500) + self.AirbaseZone = ZONE_RADIUS:New( AirbaseName, vec2, 2500 ) end else - self:E(string.format("ERROR: Cound not get position Vec2 of airbase %s", AirbaseName)) + self:E( string.format( "ERROR: Cound not get position Vec2 of airbase %s", AirbaseName ) ) end return self @@ -610,14 +606,14 @@ end -- @param #AIRBASE self -- @param #number id Airbase ID. -- @return #AIRBASE self -function AIRBASE:FindByID(id) +function AIRBASE:FindByID( id ) - for name,_airbase in pairs(_DATABASE.AIRBASES) do - local airbase=_airbase --#AIRBASE + for name, _airbase in pairs( _DATABASE.AIRBASES ) do + local airbase = _airbase -- #AIRBASE - local aid=tonumber(airbase:GetID(true)) + local aid = tonumber( airbase:GetID( true ) ) - if aid==id then + if aid == id then return airbase end @@ -632,7 +628,7 @@ end function AIRBASE:GetDCSObject() -- Get the DCS object. - local DCSAirbase = Airbase.getByName(self.AirbaseName) + local DCSAirbase = Airbase.getByName( self.AirbaseName ) if DCSAirbase then return DCSAirbase @@ -652,14 +648,14 @@ end -- @param DCS#Coalition coalition (Optional) Return only airbases belonging to the specified coalition. By default, all airbases of the map are returned. -- @param #number category (Optional) Return only airbases of a certain category, e.g. Airbase.Category.FARP -- @return #table Table containing all airbase objects of the current map. -function AIRBASE.GetAllAirbases(coalition, category) +function AIRBASE.GetAllAirbases( coalition, category ) - local airbases={} - for _,_airbase in pairs(_DATABASE.AIRBASES) do - local airbase=_airbase --#AIRBASE - if coalition==nil or airbase:GetCoalition()==coalition then - if category==nil or category==airbase:GetAirbaseCategory() then - table.insert(airbases, airbase) + local airbases = {} + for _, _airbase in pairs( _DATABASE.AIRBASES ) do + local airbase = _airbase -- #AIRBASE + if coalition == nil or airbase:GetCoalition() == coalition then + if category == nil or category == airbase:GetAirbaseCategory() then + table.insert( airbases, airbase ) end end end @@ -671,14 +667,14 @@ end -- @param DCS#Coalition coalition (Optional) Return only airbases belonging to the specified coalition. By default, all airbases of the map are returned. -- @param #number category (Optional) Return only airbases of a certain category, e.g. `Airbase.Category.HELIPAD`. -- @return #table Table containing all airbase names of the current map. -function AIRBASE.GetAllAirbaseNames(coalition, category) +function AIRBASE.GetAllAirbaseNames( coalition, category ) - local airbases={} - for airbasename,_airbase in pairs(_DATABASE.AIRBASES) do - local airbase=_airbase --#AIRBASE - if coalition==nil or airbase:GetCoalition()==coalition then - if category==nil or category==airbase:GetAirbaseCategory() then - table.insert(airbases, airbasename) + local airbases = {} + for airbasename, _airbase in pairs( _DATABASE.AIRBASES ) do + local airbase = _airbase -- #AIRBASE + if coalition == nil or airbase:GetCoalition() == coalition then + if category == nil or category == airbase:GetAirbaseCategory() then + table.insert( airbases, airbasename ) end end end @@ -690,26 +686,26 @@ end -- @param #AIRBASE self -- @param #boolean unique (Optional) If true, ships will get a negative sign as the unit ID might be the same as an airbase ID. Default off! -- @return #number The airbase ID. -function AIRBASE:GetID(unique) +function AIRBASE:GetID( unique ) if self.AirbaseID then - return unique and self.AirbaseID or math.abs(self.AirbaseID) + return unique and self.AirbaseID or math.abs( self.AirbaseID ) else - for DCSAirbaseId, DCSAirbase in ipairs(world.getAirbases()) do + for DCSAirbaseId, DCSAirbase in ipairs( world.getAirbases() ) do -- Get the airbase name. local AirbaseName = DCSAirbase:getName() -- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6! - local airbaseID=tonumber(DCSAirbase:getID()) + local airbaseID = tonumber( DCSAirbase:getID() ) - local airbaseCategory=self:GetAirbaseCategory() + local airbaseCategory = self:GetAirbaseCategory() - if AirbaseName==self.AirbaseName then - if airbaseCategory==Airbase.Category.SHIP or airbaseCategory==Airbase.Category.HELIPAD then + if AirbaseName == self.AirbaseName then + if airbaseCategory == Airbase.Category.SHIP or airbaseCategory == Airbase.Category.HELIPAD then -- Ships get a negative sign as their unit number might be the same as the ID of another airbase. return unique and -airbaseID or airbaseID else @@ -731,19 +727,19 @@ end -- @param #table TerminalIdBlacklist Table of white listed terminal IDs. -- @return #AIRBASE self -- @usage AIRBASE:FindByName("Batumi"):SetParkingSpotWhitelist({2, 3, 4}) --Only allow terminal IDs 2, 3, 4 -function AIRBASE:SetParkingSpotWhitelist(TerminalIdWhitelist) +function AIRBASE:SetParkingSpotWhitelist( TerminalIdWhitelist ) - if TerminalIdWhitelist==nil then - self.parkingWhitelist={} + if TerminalIdWhitelist == nil then + self.parkingWhitelist = {} return self end -- Ensure we got a table. - if type(TerminalIdWhitelist)~="table" then - TerminalIdWhitelist={TerminalIdWhitelist} + if type( TerminalIdWhitelist ) ~= "table" then + TerminalIdWhitelist = { TerminalIdWhitelist } end - self.parkingWhitelist=TerminalIdWhitelist + self.parkingWhitelist = TerminalIdWhitelist return self end @@ -755,24 +751,23 @@ end -- @param #table TerminalIdBlacklist Table of black listed terminal IDs. -- @return #AIRBASE self -- @usage AIRBASE:FindByName("Batumi"):SetParkingSpotBlacklist({2, 3, 4}) --Forbit terminal IDs 2, 3, 4 -function AIRBASE:SetParkingSpotBlacklist(TerminalIdBlacklist) +function AIRBASE:SetParkingSpotBlacklist( TerminalIdBlacklist ) - if TerminalIdBlacklist==nil then - self.parkingBlacklist={} + if TerminalIdBlacklist == nil then + self.parkingBlacklist = {} return self end -- Ensure we got a table. - if type(TerminalIdBlacklist)~="table" then - TerminalIdBlacklist={TerminalIdBlacklist} + if type( TerminalIdBlacklist ) ~= "table" then + TerminalIdBlacklist = { TerminalIdBlacklist } end - self.parkingBlacklist=TerminalIdBlacklist + self.parkingBlacklist = TerminalIdBlacklist return self end - --- Get category of airbase. -- @param #AIRBASE self -- @return #number Category of airbase from GetDesc().category. @@ -825,19 +820,19 @@ end -- @param #AIRBASE self -- @param #boolean available If true, only available parking spots will be returned. -- @return #table Table with parking data. See https://wiki.hoggitworld.com/view/DCS_func_getParking -function AIRBASE:GetParkingData(available) - self:F2(available) +function AIRBASE:GetParkingData( available ) + self:F2( available ) -- Get DCS airbase object. - local DCSAirbase=self:GetDCSObject() + local DCSAirbase = self:GetDCSObject() -- Get parking data. - local parkingdata=nil + local parkingdata = nil if DCSAirbase then - parkingdata=DCSAirbase:getParking(available) + parkingdata = DCSAirbase:getParking( available ) end - self:T2({parkingdata=parkingdata}) + self:T2( { parkingdata = parkingdata } ) return parkingdata end @@ -845,15 +840,15 @@ end -- @param #AIRBASE self -- @param #AIRBASE.TerminalType termtype Terminal type of which the number of spots is counted. Default all spots but spawn points on runway. -- @return #number Number of parking spots at this airbase. -function AIRBASE:GetParkingSpotsNumber(termtype) +function AIRBASE:GetParkingSpotsNumber( termtype ) -- Get free parking spots data. - local parkingdata=self:GetParkingData(false) + local parkingdata = self:GetParkingData( false ) - local nspots=0 - for _,parkingspot in pairs(parkingdata) do - if AIRBASE._CheckTerminalType(parkingspot.Term_Type, termtype) then - nspots=nspots+1 + local nspots = 0 + for _, parkingspot in pairs( parkingdata ) do + if AIRBASE._CheckTerminalType( parkingspot.Term_Type, termtype ) then + nspots = nspots + 1 end end @@ -865,17 +860,17 @@ end -- @param #AIRBASE.TerminalType termtype Terminal type. -- @param #boolean allowTOAC If true, spots are considered free even though TO_AC is true. Default is off which is saver to avoid spawning aircraft on top of each other. Option might be enabled for FARPS and ships. -- @return #number Number of free parking spots at this airbase. -function AIRBASE:GetFreeParkingSpotsNumber(termtype, allowTOAC) +function AIRBASE:GetFreeParkingSpotsNumber( termtype, allowTOAC ) -- Get free parking spots data. - local parkingdata=self:GetParkingData(true) + local parkingdata = self:GetParkingData( true ) - local nfree=0 - for _,parkingspot in pairs(parkingdata) do + local nfree = 0 + for _, parkingspot in pairs( parkingdata ) do -- Spots on runway are not counted unless explicitly requested. - if AIRBASE._CheckTerminalType(parkingspot.Term_Type, termtype) then - if (allowTOAC and allowTOAC==true) or parkingspot.TO_AC==false then - nfree=nfree+1 + if AIRBASE._CheckTerminalType( parkingspot.Term_Type, termtype ) then + if (allowTOAC and allowTOAC == true) or parkingspot.TO_AC == false then + nfree = nfree + 1 end end end @@ -888,18 +883,18 @@ end -- @param #AIRBASE.TerminalType termtype Terminal type. -- @param #boolean allowTOAC If true, spots are considered free even though TO_AC is true. Default is off which is saver to avoid spawning aircraft on top of each other. Option might be enabled for FARPS and ships. -- @return #table Table of coordinates of the free parking spots. -function AIRBASE:GetFreeParkingSpotsCoordinates(termtype, allowTOAC) +function AIRBASE:GetFreeParkingSpotsCoordinates( termtype, allowTOAC ) -- Get free parking spots data. - local parkingdata=self:GetParkingData(true) + local parkingdata = self:GetParkingData( true ) -- Put coordinates of free spots into table. - local spots={} - for _,parkingspot in pairs(parkingdata) do + local spots = {} + for _, parkingspot in pairs( parkingdata ) do -- Coordinates on runway are not returned unless explicitly requested. - if AIRBASE._CheckTerminalType(parkingspot.Term_Type, termtype) then - if (allowTOAC and allowTOAC==true) or parkingspot.TO_AC==false then - table.insert(spots, COORDINATE:NewFromVec3(parkingspot.vTerminalPos)) + if AIRBASE._CheckTerminalType( parkingspot.Term_Type, termtype ) then + if (allowTOAC and allowTOAC == true) or parkingspot.TO_AC == false then + table.insert( spots, COORDINATE:NewFromVec3( parkingspot.vTerminalPos ) ) end end end @@ -911,23 +906,23 @@ end -- @param #AIRBASE self -- @param #AIRBASE.TerminalType termtype (Optional) Terminal type. Default all. -- @return #table Table of coordinates of parking spots. -function AIRBASE:GetParkingSpotsCoordinates(termtype) +function AIRBASE:GetParkingSpotsCoordinates( termtype ) -- Get all parking spots data. - local parkingdata=self:GetParkingData(false) + local parkingdata = self:GetParkingData( false ) -- Put coordinates of free spots into table. - local spots={} - for _,parkingspot in ipairs(parkingdata) do + local spots = {} + for _, parkingspot in ipairs( parkingdata ) do -- Coordinates on runway are not returned unless explicitly requested. - if AIRBASE._CheckTerminalType(parkingspot.Term_Type, termtype) then + if AIRBASE._CheckTerminalType( parkingspot.Term_Type, termtype ) then -- Get coordinate from Vec3 terminal position. - local _coord=COORDINATE:NewFromVec3(parkingspot.vTerminalPos) + local _coord = COORDINATE:NewFromVec3( parkingspot.vTerminalPos ) -- Add to table. - table.insert(spots, _coord) + table.insert( spots, _coord ) end end @@ -941,42 +936,42 @@ end function AIRBASE:_InitParkingSpots() -- Get parking data of all spots (free or occupied) - local parkingdata=self:GetParkingData(false) + local parkingdata = self:GetParkingData( false ) -- Init table. - self.parking={} - self.parkingByID={} + self.parking = {} + self.parkingByID = {} - self.NparkingTotal=0 - self.NparkingTerminal={} - for _,terminalType in pairs(AIRBASE.TerminalType) do - self.NparkingTerminal[terminalType]=0 + self.NparkingTotal = 0 + self.NparkingTerminal = {} + for _, terminalType in pairs( AIRBASE.TerminalType ) do + self.NparkingTerminal[terminalType] = 0 end -- Put coordinates of parking spots into table. - for _,spot in pairs(parkingdata) do + for _, spot in pairs( parkingdata ) do -- New parking spot. - local park={} --#AIRBASE.ParkingSpot - park.Vec3=spot.vTerminalPos - park.Coordinate=COORDINATE:NewFromVec3(spot.vTerminalPos) - park.DistToRwy=spot.fDistToRW - park.Free=nil - park.TerminalID=spot.Term_Index - park.TerminalID0=spot.Term_Index_0 - park.TerminalType=spot.Term_Type - park.TOAC=spot.TO_AC + local park = {} -- #AIRBASE.ParkingSpot + park.Vec3 = spot.vTerminalPos + park.Coordinate = COORDINATE:NewFromVec3( spot.vTerminalPos ) + park.DistToRwy = spot.fDistToRW + park.Free = nil + park.TerminalID = spot.Term_Index + park.TerminalID0 = spot.Term_Index_0 + park.TerminalType = spot.Term_Type + park.TOAC = spot.TO_AC - self.NparkingTotal=self.NparkingTotal+1 + self.NparkingTotal = self.NparkingTotal + 1 - for _,terminalType in pairs(AIRBASE.TerminalType) do - if self._CheckTerminalType(terminalType, park.TerminalType) then - self.NparkingTerminal[terminalType]=self.NparkingTerminal[terminalType]+1 + for _, terminalType in pairs( AIRBASE.TerminalType ) do + if self._CheckTerminalType( terminalType, park.TerminalType ) then + self.NparkingTerminal[terminalType] = self.NparkingTerminal[terminalType] + 1 end end - self.parkingByID[park.TerminalID]=park - table.insert(self.parking, park) + self.parkingByID[park.TerminalID] = park + table.insert( self.parking, park ) end return self @@ -986,7 +981,7 @@ end -- @param #AIRBASE self -- @param #number TerminalID Terminal ID. -- @return #AIRBASE.ParkingSpot Parking spot. -function AIRBASE:_GetParkingSpotByID(TerminalID) +function AIRBASE:_GetParkingSpotByID( TerminalID ) return self.parkingByID[TerminalID] end @@ -994,18 +989,18 @@ end -- @param #AIRBASE self -- @param #AIRBASE.TerminalType termtype Terminal type. -- @return #table Table free parking spots. Table has the elements ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy". -function AIRBASE:GetParkingSpotsTable(termtype) +function AIRBASE:GetParkingSpotsTable( termtype ) -- Get parking data of all spots (free or occupied) - local parkingdata=self:GetParkingData(false) + local parkingdata = self:GetParkingData( false ) -- Get parking data of all free spots. - local parkingfree=self:GetParkingData(true) + local parkingfree = self:GetParkingData( true ) -- Function to ckeck if any parking spot is free. - local function _isfree(_tocheck) - for _,_spot in pairs(parkingfree) do - if _spot.Term_Index==_tocheck.Term_Index then + local function _isfree( _tocheck ) + for _, _spot in pairs( parkingfree ) do + if _spot.Term_Index == _tocheck.Term_Index then return true end end @@ -1013,23 +1008,23 @@ function AIRBASE:GetParkingSpotsTable(termtype) end -- Put coordinates of parking spots into table. - local spots={} - for _,_spot in pairs(parkingdata) do + local spots = {} + for _, _spot in pairs( parkingdata ) do - if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) then + if AIRBASE._CheckTerminalType( _spot.Term_Type, termtype ) then - local spot=self:_GetParkingSpotByID(_spot.Term_Index) + local spot = self:_GetParkingSpotByID( _spot.Term_Index ) if spot then - spot.Free=_isfree(_spot) -- updated - spot.TOAC=_spot.TO_AC -- updated + spot.Free = _isfree( _spot ) -- updated + spot.TOAC = _spot.TO_AC -- updated - table.insert(spots, spot) + table.insert( spots, spot ) else - self:E(string.format("ERROR: Parking spot %s is nil!", tostring(_spot.Term_Index))) + self:E( string.format( "ERROR: Parking spot %s is nil!", tostring( _spot.Term_Index ) ) ) end @@ -1045,23 +1040,23 @@ end -- @param #AIRBASE.TerminalType termtype Terminal type. -- @param #boolean allowTOAC If true, spots are considered free even though TO_AC is true. Default is off which is saver to avoid spawning aircraft on top of each other. Option might be enabled for FARPS and ships. -- @return #table Table free parking spots. Table has the elements ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy". -function AIRBASE:GetFreeParkingSpotsTable(termtype, allowTOAC) +function AIRBASE:GetFreeParkingSpotsTable( termtype, allowTOAC ) -- Get parking data of all free spots. - local parkingfree=self:GetParkingData(true) + local parkingfree = self:GetParkingData( true ) -- Put coordinates of free spots into table. - local freespots={} - for _,_spot in pairs(parkingfree) do - if AIRBASE._CheckTerminalType(_spot.Term_Type, termtype) and _spot.Term_Index>0 then - if (allowTOAC and allowTOAC==true) or _spot.TO_AC==false then + local freespots = {} + for _, _spot in pairs( parkingfree ) do + if AIRBASE._CheckTerminalType( _spot.Term_Type, termtype ) and _spot.Term_Index > 0 then + if (allowTOAC and allowTOAC == true) or _spot.TO_AC == false then - local spot=self:_GetParkingSpotByID(_spot.Term_Index) + local spot = self:_GetParkingSpotByID( _spot.Term_Index ) - spot.Free=true -- updated - spot.TOAC=_spot.TO_AC -- updated + spot.Free = true -- updated + spot.TOAC = _spot.TO_AC -- updated - table.insert(freespots, spot) + table.insert( freespots, spot ) end end @@ -1074,20 +1069,20 @@ end -- @param #AIRBASE self -- @param #number TerminalID The terminal ID of the parking spot. -- @return #AIRBASE.ParkingSpot Table free parking spots. Table has the elements ".Coordinate, ".TerminalID", ".TerminalType", ".TOAC", ".Free", ".TerminalID0", ".DistToRwy". -function AIRBASE:GetParkingSpotData(TerminalID) +function AIRBASE:GetParkingSpotData( TerminalID ) -- Get parking data. - local parkingdata=self:GetParkingSpotsTable() + local parkingdata = self:GetParkingSpotsTable() - for _,_spot in pairs(parkingdata) do - local spot=_spot --#AIRBASE.ParkingSpot - self:T({TerminalID=spot.TerminalID,TerminalType=spot.TerminalType}) - if TerminalID==spot.TerminalID then + for _, _spot in pairs( parkingdata ) do + local spot = _spot -- #AIRBASE.ParkingSpot + self:T( { TerminalID = spot.TerminalID, TerminalType = spot.TerminalType } ) + if TerminalID == spot.TerminalID then return spot end end - self:E("ERROR: Could not find spot with Terminal ID="..tostring(TerminalID)) + self:E( "ERROR: Could not find spot with Terminal ID=" .. tostring( TerminalID ) ) return nil end @@ -1095,35 +1090,33 @@ end -- @param #AIRBASE self -- @param #AIRBASE.TerminalType termtype Terminal type for which marks should be placed. -- @param #boolean mark If false, do not place markers but only give output to DCS.log file. Default true. -function AIRBASE:MarkParkingSpots(termtype, mark) +function AIRBASE:MarkParkingSpots( termtype, mark ) -- Default is true. - if mark==nil then - mark=true + if mark == nil then + mark = true end -- Get parking data from getParking() wrapper function. - local parkingdata=self:GetParkingSpotsTable(termtype) + local parkingdata = self:GetParkingSpotsTable( termtype ) -- Get airbase name. - local airbasename=self:GetName() - self:E(string.format("Parking spots at %s for terminal type %s:", airbasename, tostring(termtype))) + local airbasename = self:GetName() + self:E( string.format( "Parking spots at %s for terminal type %s:", airbasename, tostring( termtype ) ) ) - for _,_spot in pairs(parkingdata) do + for _, _spot in pairs( parkingdata ) do -- Mark text. - local _text=string.format("Term Index=%d, Term Type=%d, Free=%s, TOAC=%s, Term ID0=%d, Dist2Rwy=%.1f m", - _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy) + local _text = string.format( "Term Index=%d, Term Type=%d, Free=%s, TOAC=%s, Term ID0=%d, Dist2Rwy=%.1f m", _spot.TerminalID, _spot.TerminalType, tostring( _spot.Free ), tostring( _spot.TOAC ), _spot.TerminalID0, _spot.DistToRwy ) -- Create mark on the F10 map. if mark then - _spot.Coordinate:MarkToAll(_text) + _spot.Coordinate:MarkToAll( _text ) end -- Info to DCS.log file. - local _text=string.format("%s, Term Index=%3d, Term Type=%03d, Free=%5s, TOAC=%5s, Term ID0=%3d, Dist2Rwy=%.1f m", - airbasename, _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy) - self:E(_text) + local _text = string.format( "%s, Term Index=%3d, Term Type=%03d, Free=%5s, TOAC=%5s, Term ID0=%3d, Dist2Rwy=%.1f m", airbasename, _spot.TerminalID, _spot.TerminalType, tostring( _spot.Free ), tostring( _spot.TOAC ), _spot.TerminalID0, _spot.DistToRwy ) + self:E( _text ) end end @@ -1140,33 +1133,33 @@ end -- @param #number nspots (Optional) Number of freeparking spots requested. Default is the number of aircraft in the group. -- @param #table parkingdata (Optional) Parking spots data table. If not given it is automatically derived from the GetParkingSpotsTable() function. -- @return #table Table of coordinates and terminal IDs of free parking spots. Each table entry has the elements .Coordinate and .TerminalID. -function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nspots, parkingdata) - +function AIRBASE:FindFreeParkingSpotForAircraft( group, terminaltype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nspots, parkingdata ) + -- Init default - scanradius=scanradius or 50 - if scanunits==nil then - scanunits=true + scanradius = scanradius or 50 + if scanunits == nil then + scanunits = true end - if scanstatics==nil then - scanstatics=true + if scanstatics == nil then + scanstatics = true end - if scanscenery==nil then - scanscenery=false + if scanscenery == nil then + scanscenery = false end - if verysafe==nil then - verysafe=false + if verysafe == nil then + verysafe = false end -- Function calculating the overlap of two (square) objects. - local function _overlap(object1, object2, dist) - local pos1=object1 --Wrapper.Positionable#POSITIONABLE - local pos2=object2 --Wrapper.Positionable#POSITIONABLE - local r1=pos1:GetBoundingRadius() - local r2=pos2:GetBoundingRadius() + local function _overlap( object1, object2, dist ) + local pos1 = object1 -- Wrapper.Positionable#POSITIONABLE + local pos2 = object2 -- Wrapper.Positionable#POSITIONABLE + local r1 = pos1:GetBoundingRadius() + local r2 = pos2:GetBoundingRadius() if r1 and r2 then - local safedist=(r1+r2)*1.1 + local safedist = (r1 + r2) * 1.1 local safe = (dist > safedist) - self:T2(string.format("r1=%.1f r2=%.1f s=%.1f d=%.1f ==> safe=%s", r1, r2, safedist, dist, tostring(safe))) + self:T2( string.format( "r1=%.1f r2=%.1f s=%.1f d=%.1f ==> safe=%s", r1, r2, safedist, dist, tostring( safe ) ) ) return safe else return true @@ -1174,21 +1167,21 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, end -- Get airport name. - local airport=self:GetName() + local airport = self:GetName() -- Get parking spot data table. This contains free and "non-free" spots. -- Note that there are three major issues with the DCS getParking() function: -- 1. A spot is considered as NOT free until an aircraft that is present has finally taken off. This might be a bit long especiall at smaller airports. -- 2. A "free" spot does not take the aircraft size into accound. So if two big aircraft are spawned on spots next to each other, they might overlap and get destroyed. -- 3. The routine return a free spot, if there a static objects placed on the spot. - parkingdata=parkingdata or self:GetParkingSpotsTable(terminaltype) + parkingdata = parkingdata or self:GetParkingSpotsTable( terminaltype ) -- Get the aircraft size, i.e. it's longest side of x,z. local aircraft = nil -- fix local problem below - local _aircraftsize, ax,ay,az + local _aircraftsize, ax, ay, az if group and group.ClassName == "GROUP" then - aircraft=group:GetUnit(1) - _aircraftsize, ax,ay,az=aircraft:GetObjectSize() + aircraft = group:GetUnit( 1 ) + _aircraftsize, ax, ay, az = aircraft:GetObjectSize() else -- SU27 dimensions _aircraftsize = 23 @@ -1197,127 +1190,126 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, az = 17 -- width end - -- Number of spots we are looking for. Note that, e.g. grouping can require a number different from the group size! - local _nspots=nspots or group:GetSize() + local _nspots = nspots or group:GetSize() -- Debug info. - self:E(string.format("%s: Looking for %d parking spot(s) for aircraft of size %.1f m (x=%.1f,y=%.1f,z=%.1f) at terminal type %s.", airport, _nspots, _aircraftsize, ax, ay, az, tostring(terminaltype))) + self:E( string.format( "%s: Looking for %d parking spot(s) for aircraft of size %.1f m (x=%.1f,y=%.1f,z=%.1f) at terminal type %s.", airport, _nspots, _aircraftsize, ax, ay, az, tostring( terminaltype ) ) ) -- Table of valid spots. - local validspots={} - local nvalid=0 + local validspots = {} + local nvalid = 0 -- Test other stuff if no parking spot is available. - local _test=false + local _test = false if _test then return validspots end -- Mark all found obstacles on F10 map for debugging. - local markobstacles=false + local markobstacles = false -- Loop over all known parking spots - for _,parkingspot in pairs(parkingdata) do + for _, parkingspot in pairs( parkingdata ) do -- Coordinate of the parking spot. - local _spot=parkingspot.Coordinate -- Core.Point#COORDINATE - local _termid=parkingspot.TerminalID + local _spot = parkingspot.Coordinate -- Core.Point#COORDINATE + local _termid = parkingspot.TerminalID -- Check terminal type and black/white listed parking spots. - if AIRBASE._CheckTerminalType(parkingspot.TerminalType, terminaltype) and self:_CheckParkingLists(_termid) then + if AIRBASE._CheckTerminalType( parkingspot.TerminalType, terminaltype ) and self:_CheckParkingLists( _termid ) then -- Very safe uses the DCS getParking() info to check if a spot is free. Unfortunately, the function returns free=false until the aircraft has actually taken-off. - if verysafe and (parkingspot.Free==false or parkingspot.TOAC==true) then + if verysafe and (parkingspot.Free == false or parkingspot.TOAC == true) then -- DCS getParking() routine returned that spot is not free. - self:T(string.format("%s: Parking spot id %d NOT free (or aircraft has not taken off yet). Free=%s, TOAC=%s.", airport, parkingspot.TerminalID, tostring(parkingspot.Free), tostring(parkingspot.TOAC))) + self:T( string.format( "%s: Parking spot id %d NOT free (or aircraft has not taken off yet). Free=%s, TOAC=%s.", airport, parkingspot.TerminalID, tostring( parkingspot.Free ), tostring( parkingspot.TOAC ) ) ) else -- Scan a radius of 50 meters around the spot. - local _,_,_,_units,_statics,_sceneries=_spot:ScanObjects(scanradius, scanunits, scanstatics, scanscenery) + local _, _, _, _units, _statics, _sceneries = _spot:ScanObjects( scanradius, scanunits, scanstatics, scanscenery ) -- Loop over objects within scan radius. - local occupied=false + local occupied = false -- Check all units. - for _,unit in pairs(_units) do - local _coord=unit:GetCoordinate() - local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft, unit, _dist) + for _, unit in pairs( _units ) do + local _coord = unit:GetCoordinate() + local _dist = _coord:Get2DDistance( _spot ) + local _safe = _overlap( aircraft, unit, _dist ) if markobstacles then - local l,x,y,z=unit:GetObjectSize() - _coord:MarkToAll(string.format("Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:GetName(),x,y,z,l,_dist, _termid, tostring(_safe))) + local l, x, y, z = unit:GetObjectSize() + _coord:MarkToAll( string.format( "Unit %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", unit:GetName(), x, y, z, l, _dist, _termid, tostring( _safe ) ) ) end if scanunits and not _safe then - occupied=true + occupied = true end end -- Check all statics. - for _,static in pairs(_statics) do - local _static=STATIC:Find(static) - local _vec3=static:getPoint() - local _coord=COORDINATE:NewFromVec3(_vec3) - local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft,_static,_dist) + for _, static in pairs( _statics ) do + local _static = STATIC:Find( static ) + local _vec3 = static:getPoint() + local _coord = COORDINATE:NewFromVec3( _vec3 ) + local _dist = _coord:Get2DDistance( _spot ) + local _safe = _overlap( aircraft, _static, _dist ) if markobstacles then - local l,x,y,z=_static:GetObjectSize() - _coord:MarkToAll(string.format("Static %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", static:getName(),x,y,z,l,_dist, _termid, tostring(_safe))) + local l, x, y, z = _static:GetObjectSize() + _coord:MarkToAll( string.format( "Static %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", static:getName(), x, y, z, l, _dist, _termid, tostring( _safe ) ) ) end if scanstatics and not _safe then - occupied=true + occupied = true end end -- Check all scenery. - for _,scenery in pairs(_sceneries) do - local _scenery=SCENERY:Register(scenery:getTypeName(), scenery) - local _vec3=scenery:getPoint() - local _coord=COORDINATE:NewFromVec3(_vec3) - local _dist=_coord:Get2DDistance(_spot) - local _safe=_overlap(aircraft,_scenery,_dist) + for _, scenery in pairs( _sceneries ) do + local _scenery = SCENERY:Register( scenery:getTypeName(), scenery ) + local _vec3 = scenery:getPoint() + local _coord = COORDINATE:NewFromVec3( _vec3 ) + local _dist = _coord:Get2DDistance( _spot ) + local _safe = _overlap( aircraft, _scenery, _dist ) if markobstacles then - local l,x,y,z=scenery:GetObjectSize(scenery) - _coord:MarkToAll(string.format("Scenery %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", scenery:getTypeName(),x,y,z,l,_dist, _termid, tostring(_safe))) + local l, x, y, z = scenery:GetObjectSize( scenery ) + _coord:MarkToAll( string.format( "Scenery %s\nx=%.1f y=%.1f z=%.1f\nl=%.1f d=%.1f\nspot %d safe=%s", scenery:getTypeName(), x, y, z, l, _dist, _termid, tostring( _safe ) ) ) end if scanscenery and not _safe then - occupied=true + occupied = true end end -- Now check the already given spots so that we do not put a large aircraft next to one we already assigned a nearby spot. - for _,_takenspot in pairs(validspots) do - local _dist=_takenspot.Coordinate:Get2DDistance(_spot) - local _safe=_overlap(aircraft, aircraft, _dist) + for _, _takenspot in pairs( validspots ) do + local _dist = _takenspot.Coordinate:Get2DDistance( _spot ) + local _safe = _overlap( aircraft, aircraft, _dist ) if not _safe then - occupied=true + occupied = true end end - --_spot:MarkToAll(string.format("Parking spot %d free=%s", parkingspot.TerminalID, tostring(not occupied))) + -- _spot:MarkToAll(string.format("Parking spot %d free=%s", parkingspot.TerminalID, tostring(not occupied))) if occupied then - self:I(string.format("%s: Parking spot id %d occupied.", airport, _termid)) + self:I( string.format( "%s: Parking spot id %d occupied.", airport, _termid ) ) else - self:I(string.format("%s: Parking spot id %d free.", airport, _termid)) - if nvalid<_nspots then - table.insert(validspots, {Coordinate=_spot, TerminalID=_termid}) + self:I( string.format( "%s: Parking spot id %d free.", airport, _termid ) ) + if nvalid < _nspots then + table.insert( validspots, { Coordinate = _spot, TerminalID = _termid } ) end - nvalid=nvalid+1 - self:I(string.format("%s: Parking spot id %d free. Nfree=%d/%d.", airport, _termid, nvalid,_nspots)) + nvalid = nvalid + 1 + self:I( string.format( "%s: Parking spot id %d free. Nfree=%d/%d.", airport, _termid, nvalid, _nspots ) ) end end -- loop over units -- We found enough spots. - if nvalid>=_nspots then + if nvalid >= _nspots then return validspots end end -- check terminal type @@ -1325,30 +1317,29 @@ function AIRBASE:FindFreeParkingSpotForAircraft(group, terminaltype, scanradius, -- Retrun spots we found, even if there were not enough. return validspots - + end --- Check black and white lists. -- @param #AIRBASE self -- @param #number TerminalID Terminal ID to check. -- @return #boolean `true` if this is a valid spot. -function AIRBASE:_CheckParkingLists(TerminalID) +function AIRBASE:_CheckParkingLists( TerminalID ) -- First check the black list. If we find a match, this spot is forbidden! - if self.parkingBlacklist and #self.parkingBlacklist>0 then - for _,terminalID in pairs(self.parkingBlacklist or {}) do - if terminalID==TerminalID then + if self.parkingBlacklist and #self.parkingBlacklist > 0 then + for _, terminalID in pairs( self.parkingBlacklist or {} ) do + if terminalID == TerminalID then -- This is a invalid spot. return false end end end - -- Check if a whitelist was defined. - if self.parkingWhitelist and #self.parkingWhitelist>0 then - for _,terminalID in pairs(self.parkingWhitelist or {}) do - if terminalID==TerminalID then + if self.parkingWhitelist and #self.parkingWhitelist > 0 then + for _, terminalID in pairs( self.parkingWhitelist or {} ) do + if terminalID == TerminalID then -- This is a valid spot. return true end @@ -1365,16 +1356,16 @@ end -- @param #number Term_Type Termial type from getParking routine. -- @param #AIRBASE.TerminalType termtype Terminal type from AIRBASE.TerminalType enumerator. -- @return #boolean True if terminal types match. -function AIRBASE._CheckTerminalType(Term_Type, termtype) +function AIRBASE._CheckTerminalType( Term_Type, termtype ) -- Nill check for Term_Type. - if Term_Type==nil then + if Term_Type == nil then return false end -- If no terminal type is requested, we return true. BUT runways are excluded unless explicitly requested. - if termtype==nil then - if Term_Type==AIRBASE.TerminalType.Runway then + if termtype == nil then + if Term_Type == AIRBASE.TerminalType.Runway then return false else return true @@ -1382,25 +1373,25 @@ function AIRBASE._CheckTerminalType(Term_Type, termtype) end -- Init no match. - local match=false + local match = false -- Standar case. - if Term_Type==termtype then - match=true + if Term_Type == termtype then + match = true end -- Artificial cases. Combination of terminal types. - if termtype==AIRBASE.TerminalType.OpenMedOrBig then - if Term_Type==AIRBASE.TerminalType.OpenMed or Term_Type==AIRBASE.TerminalType.OpenBig then - match=true + if termtype == AIRBASE.TerminalType.OpenMedOrBig then + if Term_Type == AIRBASE.TerminalType.OpenMed or Term_Type == AIRBASE.TerminalType.OpenBig then + match = true end - elseif termtype==AIRBASE.TerminalType.HelicopterUsable then - if Term_Type==AIRBASE.TerminalType.OpenMed or Term_Type==AIRBASE.TerminalType.OpenBig or Term_Type==AIRBASE.TerminalType.HelicopterOnly then - match=true - end - elseif termtype==AIRBASE.TerminalType.FighterAircraft then - if Term_Type==AIRBASE.TerminalType.OpenMed or Term_Type==AIRBASE.TerminalType.OpenBig or Term_Type==AIRBASE.TerminalType.Shelter then - match=true + elseif termtype == AIRBASE.TerminalType.HelicopterUsable then + if Term_Type == AIRBASE.TerminalType.OpenMed or Term_Type == AIRBASE.TerminalType.OpenBig or Term_Type == AIRBASE.TerminalType.HelicopterOnly then + match = true + end + elseif termtype == AIRBASE.TerminalType.FighterAircraft then + if Term_Type == AIRBASE.TerminalType.OpenMed or Term_Type == AIRBASE.TerminalType.OpenBig or Term_Type == AIRBASE.TerminalType.Shelter then + match = true end end @@ -1416,162 +1407,160 @@ end -- @param #number magvar (Optional) Magnetic variation in degrees. -- @param #boolean mark (Optional) Place markers with runway data on F10 map. -- @return #table Runway data. -function AIRBASE:GetRunwayData(magvar, mark) +function AIRBASE:GetRunwayData( magvar, mark ) -- Runway table. - local runways={} + local runways = {} - if self:GetAirbaseCategory()~=Airbase.Category.AIRDROME then + if self:GetAirbaseCategory() ~= Airbase.Category.AIRDROME then return {} end -- Get spawn points on runway. These can be used to determine the runway heading. - local runwaycoords=self:GetParkingSpotsCoordinates(AIRBASE.TerminalType.Runway) + local runwaycoords = self:GetParkingSpotsCoordinates( AIRBASE.TerminalType.Runway ) -- Debug: For finding the numbers of the spawn points belonging to each runway. if false then - for i,_coord in pairs(runwaycoords) do - local coord=_coord --Core.Point#COORDINATE - coord:Translate(100, 0):MarkToAll("Runway i="..i) + for i, _coord in pairs( runwaycoords ) do + local coord = _coord -- Core.Point#COORDINATE + coord:Translate( 100, 0 ):MarkToAll( "Runway i=" .. i ) end end -- Magnetic declination. - magvar=magvar or UTILS.GetMagneticDeclination() + magvar = magvar or UTILS.GetMagneticDeclination() -- Number of runways. - local N=#runwaycoords - local N2=N/2 - local exception=false + local N = #runwaycoords + local N2 = N / 2 + local exception = false -- Airbase name. - local name=self:GetName() - + local name = self:GetName() -- Exceptions - if name==AIRBASE.Nevada.Jean_Airport or - name==AIRBASE.Nevada.Creech_AFB or - name==AIRBASE.PersianGulf.Abu_Dhabi_International_Airport or - name==AIRBASE.PersianGulf.Dubai_Intl or - name==AIRBASE.PersianGulf.Shiraz_International_Airport or - name==AIRBASE.PersianGulf.Kish_International_Airport or - name==AIRBASE.MarianaIslands.Andersen_AFB then + if name == AIRBASE.Nevada.Jean_Airport or + name == AIRBASE.Nevada.Creech_AFB or + name == AIRBASE.PersianGulf.Abu_Dhabi_International_Airport or + name == AIRBASE.PersianGulf.Dubai_Intl or + name == AIRBASE.PersianGulf.Shiraz_International_Airport or + name == AIRBASE.PersianGulf.Kish_International_Airport or + name == AIRBASE.MarianaIslands.Andersen_AFB then -- 1-->4, 2-->3, 3-->2, 4-->1 - exception=1 + exception = 1 - elseif UTILS.GetDCSMap()==DCSMAP.Syria and N>=2 and - name~=AIRBASE.Syria.Minakh and - name~=AIRBASE.Syria.Damascus and - name~=AIRBASE.Syria.Khalkhalah and - name~=AIRBASE.Syria.Marj_Ruhayyil and - name~=AIRBASE.Syria.Beirut_Rafic_Hariri then + elseif UTILS.GetDCSMap() == DCSMAP.Syria and N >= 2 and + name ~= AIRBASE.Syria.Minakh and + name ~= AIRBASE.Syria.Damascus and + name ~= AIRBASE.Syria.Khalkhalah and + name ~= AIRBASE.Syria.Marj_Ruhayyil and + name ~= AIRBASE.Syria.Beirut_Rafic_Hariri then -- 1-->3, 2-->4, 3-->1, 4-->2 - exception=2 + exception = 2 end --- Function returning the index of the runway coordinate belonding to the given index i. - local function f(i) + local function f( i ) local j - if exception==1 then + if exception == 1 then - j=N-(i-1) -- 1-->4, 2-->3 + j = N - (i - 1) -- 1-->4, 2-->3 - elseif exception==2 then + elseif exception == 2 then - if i<=N2 then - j=i+N2 -- 1-->3, 2-->4 + if i <= N2 then + j = i + N2 -- 1-->3, 2-->4 else - j=i-N2 -- 3-->1, 4-->3 + j = i - N2 -- 3-->1, 4-->3 end else - if i%2==0 then - j=i-1 -- even 2-->1, 4-->3 + if i % 2 == 0 then + j = i - 1 -- even 2-->1, 4-->3 else - j=i+1 -- odd 1-->2, 3-->4 + j = i + 1 -- odd 1-->2, 3-->4 end end -- Special case where there is no obvious order. - if name==AIRBASE.Syria.Beirut_Rafic_Hariri then - if i==1 then - j=3 - elseif i==2 then - j=6 - elseif i==3 then - j=1 - elseif i==4 then - j=5 - elseif i==5 then - j=4 - elseif i==6 then - j=2 + if name == AIRBASE.Syria.Beirut_Rafic_Hariri then + if i == 1 then + j = 3 + elseif i == 2 then + j = 6 + elseif i == 3 then + j = 1 + elseif i == 4 then + j = 5 + elseif i == 5 then + j = 4 + elseif i == 6 then + j = 2 end end - if name==AIRBASE.Syria.Ramat_David then - if i==1 then - j=4 - elseif i==2 then - j=6 - elseif i==3 then - j=5 - elseif i==4 then - j=1 - elseif i==5 then - j=3 - elseif i==6 then - j=2 + if name == AIRBASE.Syria.Ramat_David then + if i == 1 then + j = 4 + elseif i == 2 then + j = 6 + elseif i == 3 then + j = 5 + elseif i == 4 then + j = 1 + elseif i == 5 then + j = 3 + elseif i == 6 then + j = 2 end end return j end - - for i=1,N do + for i = 1, N do -- Get the other spawn point coordinate. - local j=f(i) + local j = f( i ) -- Debug info. - --env.info(string.format("Runway i=%s j=%s (N=%d #runwaycoord=%d)", tostring(i), tostring(j), N, #runwaycoords)) + -- env.info(string.format("Runway i=%s j=%s (N=%d #runwaycoord=%d)", tostring(i), tostring(j), N, #runwaycoords)) -- Coordinates of the two runway points. - local c1=runwaycoords[i] --Core.Point#COORDINATE - local c2=runwaycoords[j] --Core.Point#COORDINATE + local c1 = runwaycoords[i] -- Core.Point#COORDINATE + local c2 = runwaycoords[j] -- Core.Point#COORDINATE -- Heading of runway. - local hdg=c1:HeadingTo(c2) + local hdg = c1:HeadingTo( c2 ) -- Runway ID: heading=070° ==> idx="07" - local idx=string.format("%02d", UTILS.Round((hdg-magvar)/10, 0)) + local idx = string.format( "%02d", UTILS.Round( (hdg - magvar) / 10, 0 ) ) -- Runway table. - local runway={} --#AIRBASE.Runway - runway.heading=hdg - runway.idx=idx - runway.length=c1:Get2DDistance(c2) - runway.position=c1 - runway.endpoint=c2 + local runway = {} -- #AIRBASE.Runway + runway.heading = hdg + runway.idx = idx + runway.length = c1:Get2DDistance( c2 ) + runway.position = c1 + runway.endpoint = c2 -- Debug info. - --self:I(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m i=%d j=%d", self:GetName(), runway.idx, runway.heading, runway.length, i, j)) + -- self:I(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m i=%d j=%d", self:GetName(), runway.idx, runway.heading, runway.length, i, j)) -- Debug mark if mark then - runway.position:MarkToAll(string.format("Runway %s: true heading=%03d (magvar=%d), length=%d m, i=%d, j=%d", runway.idx, runway.heading, magvar, runway.length, i, j)) + runway.position:MarkToAll( string.format( "Runway %s: true heading=%03d (magvar=%d), length=%d m, i=%d, j=%d", runway.idx, runway.heading, magvar, runway.length, i, j ) ) end -- Add runway. - table.insert(runways, runway) + table.insert( runways, runway ) end @@ -1581,18 +1570,18 @@ end --- Set the active runway in case it cannot be determined by the wind direction. -- @param #AIRBASE self -- @param #number iactive Number of the active runway in the runway data table. -function AIRBASE:SetActiveRunway(iactive) - self.activerwyno=iactive +function AIRBASE:SetActiveRunway( iactive ) + self.activerwyno = iactive end --- Get the active runway based on current wind direction. -- @param #AIRBASE self -- @param #number magvar (Optional) Magnetic variation in degrees. -- @return #AIRBASE.Runway Active runway data table. -function AIRBASE:GetActiveRunway(magvar) +function AIRBASE:GetActiveRunway( magvar ) -- Get runways data (initialize if necessary). - local runways=self:GetRunwayData(magvar) + local runways = self:GetRunwayData( magvar ) -- Return user forced active runway if it was set. if self.activerwyno then @@ -1600,46 +1589,46 @@ function AIRBASE:GetActiveRunway(magvar) end -- Get wind vector. - local Vwind=self:GetCoordinate():GetWindWithTurbulenceVec3() - local norm=UTILS.VecNorm(Vwind) + local Vwind = self:GetCoordinate():GetWindWithTurbulenceVec3() + local norm = UTILS.VecNorm( Vwind ) -- Active runway number. - local iact=1 + local iact = 1 -- Check if wind is blowing (norm>0). - if norm>0 then + if norm > 0 then -- Normalize wind (not necessary). - Vwind.x=Vwind.x/norm - Vwind.y=0 - Vwind.z=Vwind.z/norm + Vwind.x = Vwind.x / norm + Vwind.y = 0 + Vwind.z = Vwind.z / norm -- Loop over runways. - local dotmin=nil - for i,_runway in pairs(runways) do - local runway=_runway --#AIRBASE.Runway + local dotmin = nil + for i, _runway in pairs( runways ) do + local runway = _runway -- #AIRBASE.Runway -- Angle in rad. - local alpha=math.rad(runway.heading) + local alpha = math.rad( runway.heading ) -- Runway vector. - local Vrunway={x=math.cos(alpha), y=0, z=math.sin(alpha)} + local Vrunway = { x = math.cos( alpha ), y = 0, z = math.sin( alpha ) } -- Dot product: parallel component of the two vectors. - local dot=UTILS.VecDot(Vwind, Vrunway) + local dot = UTILS.VecDot( Vwind, Vrunway ) -- Debug. - --env.info(string.format("runway=%03d° dot=%.3f", runway.heading, dot)) + -- env.info(string.format("runway=%03d° dot=%.3f", runway.heading, dot)) -- New min? - if dotmin==nil or dot radius %.1f m. Despawn = %s.", self:GetName(), unit:GetName(), group:GetName(),_i, dist, radius, tostring(despawn))) - --unit:FlareGreen() + self:T( string.format( "%s, unit %s of group %s was NOT spawned on runway #%d. Distance %.1f > radius %.1f m. Despawn = %s.", self:GetName(), unit:GetName(), group:GetName(), _i, dist, radius, tostring( despawn ) ) ) + -- unit:FlareGreen() end end else - self:T(string.format("%s, checking if unit %s of group %s is on runway. Unit is NOT alive.",self:GetName(), unit:GetName(), group:GetName())) + self:T( string.format( "%s, checking if unit %s of group %s is on runway. Unit is NOT alive.", self:GetName(), unit:GetName(), group:GetName() ) ) end end else - self:T(string.format("%s, checking if group %s is on runway. Group is NOT alive.",self:GetName(), group:GetName())) + self:T( string.format( "%s, checking if group %s is on runway. Group is NOT alive.", self:GetName(), group:GetName() ) ) end return false