From dd2a4ee7ff9b3f4dd2d215675c288aa51d3cbc26 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 8 Jan 2023 19:32:38 +0100 Subject: [PATCH 1/2] COORDINATE - Added `GetMagneticDeclination` function --- Moose Development/Moose/Core/Point.lua | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index fe4863f54..a52f4a9da 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -406,6 +406,42 @@ do -- COORDINATE return self end + --- Returns the magnetic declination at the given coordinate. + -- NOTE that this needs `require` to be available so you need to desanitize the `MissionScripting.lua` file in your DCS/Scrips folder. + -- If `require` is not available, a constant value for the whole map. + -- @param #COORDINATE self + -- @param #number Month (Optional) The month at which the declination is calculated. Default is the mission month. + -- @param #number Year (Optional) The year at which the declination is calculated. Default is the mission year. + -- @return #number Magnetic declination in degrees. + function COORDINATE:GetMagneticDeclination(Month, Year) + + local decl=UTILS.GetMagneticDeclination() + + if require then + + local magvar = require('magvar') + + if magvar then + + local date, year, month, day=UTILS.GetDCSMissionDate() + + magvar.init(Month or month, Year or year) + + local lat, lon=self:GetLLDDM() + + decl=magvar.get_mag_decl(lat, lon) + + if decl then + decl=math.deg(decl) + end + + end + else + self:T("The require package is not available. Using constant value for magnetic declination") + end + + return decl + end --- Returns the coordinate from the latitude and longitude given in decimal degrees. -- @param #COORDINATE self From 91801d441f00991933a2d7e1a7b01f2cb84cf8eb Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 9 Jan 2023 17:07:17 +0100 Subject: [PATCH 2/2] #GROUP * Improve functionality of GetUnit(x) * Added GetFirstUnit() --- Moose Development/Moose/Wrapper/Group.lua | 57 +++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 08853948a..19c2b9fd6 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -624,10 +624,9 @@ function GROUP:GetRange() return nil end - --- Returns a list of @{Wrapper.Unit} objects of the @{Wrapper.Group}. -- @param #GROUP self --- @return #list The list of @{Wrapper.Unit} objects of the @{Wrapper.Group}. +-- @return #table of Wrapper.Unit#UNIT objects, indexed by number. function GROUP:GetUnits() self:F2( { self.GroupName } ) local DCSGroup = self:GetDCSObject() @@ -645,7 +644,6 @@ function GROUP:GetUnits() return nil end - --- Returns a list of @{Wrapper.Unit} objects of the @{Wrapper.Group} that are occupied by a player. -- @param #GROUP self -- @return #list The list of player occupied @{Wrapper.Unit} objects of the @{Wrapper.Group}. @@ -676,41 +674,38 @@ function GROUP:IsPlayer() return self:GetUnit(1):IsPlayer() end ---- Returns the UNIT wrapper class with number UnitNumber. --- If the underlying DCS Unit does not exist, the method will return nil. . +--- Returns the UNIT wrapper object with number UnitNumber. If it doesn't exist, tries to return the next available unit. +-- If no underlying DCS Units exist, the method will return nil. -- @param #GROUP self -- @param #number UnitNumber The number of the UNIT wrapper class to be returned. --- @return Wrapper.Unit#UNIT The UNIT wrapper class. +-- @return Wrapper.Unit#UNIT The UNIT object or nil function GROUP:GetUnit( UnitNumber ) - local DCSGroup = self:GetDCSObject() - - if DCSGroup then - + if DCSGroup then local UnitFound = nil -- 2.7.1 dead event bug, return the first alive unit instead - local units = DCSGroup:getUnits() or {} - - for _,_unit in pairs(units) do - - local UnitFound = UNIT:Find(_unit) - + -- Maybe fixed with 2.8? + local units = DCSGroup:getUnits() or {} + if units[UnitNumber] then + local UnitFound = UNIT:Find(units[UnitNumber]) if UnitFound then - return UnitFound - + end + else + for _,_unit in pairs(units) do + local UnitFound = UNIT:Find(_unit) + if UnitFound then + return UnitFound + end end end - end - - return nil - + return nil end --- Returns the DCS Unit with number UnitNumber. --- If the underlying DCS Unit does not exist, the method will return nil. . +-- If the underlying DCS Unit does not exist, the method will return try to find the next unit. Returns nil if no units are found. -- @param #GROUP self -- @param #number UnitNumber The number of the DCS Unit to be returned. -- @return DCS#Unit The DCS Unit. @@ -723,8 +718,7 @@ function GROUP:GetDCSUnit( UnitNumber ) if DCSGroup.getUnit and DCSGroup:getUnit( UnitNumber ) then return DCSGroup:getUnit( UnitNumber ) else - - local UnitFound = nil + -- 2.7.1 dead event bug, return the first alive unit instead local units = DCSGroup:getUnits() or {} @@ -803,7 +797,20 @@ function GROUP:GetFirstUnitAlive() return nil end +--- Get the first unit of the group. Might be nil! +-- @param #GROUP self +-- @return Wrapper.Unit#UNIT First unit or nil if it does not exist. +function GROUP:GetFirstUnit() + self:F3({self.GroupName}) + local DCSGroup = self:GetDCSObject() + if DCSGroup then + local units=self:GetUnits() + return units[1] + end + + return nil +end --- Returns the average velocity Vec3 vector. -- @param Wrapper.Group#GROUP self