From ae6716ac0149691260b294211a58c9e39f15c20e Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sun, 5 Mar 2023 11:03:26 +0100 Subject: [PATCH 1/2] #GROUP * Callsign translation refactor --- Moose Development/Moose/Wrapper/Group.lua | 69 ++++++++++++----------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 99125e66a..5d1c895d4 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -2785,11 +2785,16 @@ end -- @param #GROUP self -- @param #boolean ShortCallsign Return a shortened customized callsign, i.e. "Ghostrider 9" and not "Ghostrider 9 1" -- @param #boolean Keepnumber (Player only) Return customized callsign, incl optional numbers at the end, e.g. "Aerial 1-1#Ghostrider 109" results in "Ghostrider 109", if you want to e.g. use historical US Navy Callsigns --- @param #table CallsignTranslations Table to translate between DCS standard callsigns and bespoke ones. Does not apply if using customized +-- @param #table CallsignTranslations Table to translate between DCS standard callsigns and bespoke ones. Overrides personal/parsed callsigns if set -- callsigns from playername or group name. -- @return #string Callsign -- @usage --- -- Set Custom CAP Flight Callsigns for use with TTS +-- -- suppose there are three groups with one (client) unit each: +-- -- Slot 1 -- with mission editor callsign Enfield-1 +-- -- Slot 2 # Apollo 403 -- with mission editor callsign Enfield-2 +-- -- Slot 3 | Apollo -- with mission editor callsign Enfield-3 +-- -- Slot 4 | Apollo -- with mission editor callsign Devil-4 +-- -- and suppose these Custom CAP Flight Callsigns for use with TTS are set -- mygroup:GetCustomCallSign(true,false,{ -- Devil = 'Bengal', -- Snake = 'Winder', @@ -2797,12 +2802,12 @@ end -- Enfield = 'Victory', -- Uzi = 'Evil Eye' -- }) --- --- results in this outcome if the group has Callsign "Enfield 9 1" on the 1st #UNIT of the group: --- --- 'Victory 9' --- --- +-- -- then GetCustomCallsign will return +-- -- Enfield-1 for Slot 1 +-- -- Apollo for Slot 2 or Apollo 403 if Keepnumber is set +-- -- Apollo for Slot 3 +-- -- Bengal-4 for Slot 4 + function GROUP:GetCustomCallSign(ShortCallsign,Keepnumber,CallsignTranslations) --self:I("GetCustomCallSign") @@ -2817,7 +2822,11 @@ function GROUP:GetCustomCallSign(ShortCallsign,Keepnumber,CallsignTranslations) local callnumbermajor = string.char(string.byte(callnumber,1)) -- 9 local callnumberminor = string.char(string.byte(callnumber,2)) -- 1 local personalized = false - if IsPlayer and string.find(groupname,"#") then + + -- prioritize bespoke callsigns over parsing, prefer parsing over default callsigns + if CallsignTranslations and CallsignTranslations[callsignroot] then + callsignroot = CallsignTranslations[callsignroot] + elseif IsPlayer and string.find(groupname,"#") then -- personalized flight name in group naming if Keepnumber then shortcallsign = string.match(groupname,"#(.+)") or "Ghost 111" -- Ghostrider 219 @@ -2830,32 +2839,28 @@ function GROUP:GetCustomCallSign(ShortCallsign,Keepnumber,CallsignTranslations) shortcallsign = string.match(self:GetPlayerName(),"|%s*([%a]+)") or string.match(self:GetPlayerName(),"|%s*([%d]+)") or "Ghost" -- Ghostrider personalized = true end - - if (not personalized) and CallsignTranslations and CallsignTranslations[callsignroot] then - callsignroot = CallsignTranslations[callsignroot] + + if personalized then + -- player personalized callsign + -- remove trailing/leading spaces + shortcallsign=string.gsub(shortcallsign,"^%s*","") + shortcallsign=string.gsub(shortcallsign,"%s*$","") + if Keepnumber then + return shortcallsign -- Ghostrider 219 + elseif ShortCallsign then + callsign = shortcallsign.." "..callnumbermajor -- Ghostrider 9 + else + callsign = shortcallsign.." "..callnumbermajor.." "..callnumberminor -- Ghostrider 9 1 + end + return callsign end - - if personalized then - -- player personalized callsign - -- remove trailing/leading spaces - shortcallsign=string.gsub(shortcallsign,"^%s*","") - shortcallsign=string.gsub(shortcallsign,"%s*$","") - if Keepnumber then - return shortcallsign -- Ghostrider 219 - elseif ShortCallsign then - callsign = shortcallsign.." "..callnumbermajor -- Ghostrider 9 + + -- AI or not personalized + if ShortCallsign then + callsign = callsignroot.." "..callnumbermajor -- Uzi/Victory 9 else - callsign = shortcallsign.." "..callnumbermajor.." "..callnumberminor -- Ghostrider 9 1 + callsign = callsignroot.." "..callnumbermajor.." "..callnumberminor -- Uzi/Victory 9 1 end - return callsign - end - - -- AI or not personalized - if ShortCallsign then - callsign = callsignroot.." "..callnumbermajor -- Uzi/Victory 9 - else - callsign = callsignroot.." "..callnumbermajor.." "..callnumberminor -- Uzi/Victory 9 1 - end --self:I("Generated Callsign = " .. callsign) end From c9a91d068371a2fab5fd2ce8b65aaca4a11664a3 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 9 Mar 2023 08:49:07 +0100 Subject: [PATCH 2/2] #GROUP * Fix for GetMaxHeight() --- Moose Development/Moose/Utilities/Utils.lua | 77 +++++++++++++++++++-- Moose Development/Moose/Wrapper/Group.lua | 6 +- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 73cddf307..14557fe47 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -667,7 +667,10 @@ function UTILS.Round( num, idp ) return math.floor( num * mult + 0.5 ) / mult end --- porting in Slmod's dostring +--- Porting in Slmod's dostring - execute a string as LUA code with error handling. +-- @param #string s The code as string to be executed +-- @return #boolean success If true, code was successfully executed, else false +-- @return #string Outcome Code outcome if successful or error string if not successful function UTILS.DoString( s ) local f, err = loadstring( s ) if f then @@ -677,7 +680,15 @@ function UTILS.DoString( s ) end end --- Here is a customized version of pairs, which I called spairs because it iterates over the table in a sorted order. +--- Here is a customized version of pairs, which I called spairs because it iterates over the table in a sorted order. +-- @param #table t The table +-- @param #string order (Optional) The sorting function +-- @return #string key The index key +-- @return #string value The value at the indexed key +-- @usage +-- for key,value in UTILS.spairs(mytable) do +-- -- your code here +-- end function UTILS.spairs( t, order ) -- collect the keys local keys = {} @@ -702,7 +713,16 @@ function UTILS.spairs( t, order ) end --- Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first. +--- Here is a customized version of pairs, which I called kpairs because it iterates over the table in a sorted order, based on a function that will determine the keys as reference first. +-- @param #table t The table +-- @param #string getkey The function to determine the keys for sorting +-- @param #string order (Optional) The sorting function itself +-- @return #string key The index key +-- @return #string value The value at the indexed key +-- @usage +-- for key,value in UTILS.kpairs(mytable, getkeyfunc) do +-- -- your code here +-- end function UTILS.kpairs( t, getkey, order ) -- collect the keys local keys = {} @@ -727,7 +747,14 @@ function UTILS.kpairs( t, getkey, order ) end end --- Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order. +--- Here is a customized version of pairs, which I called rpairs because it iterates over the table in a random order. +-- @param #table t The table +-- @return #string key The index key +-- @return #string value The value at the indexed key +-- @usage +-- for key,value in UTILS.rpairs(mytable) do +-- -- your code here +-- end function UTILS.rpairs( t ) -- collect the keys @@ -2846,3 +2873,45 @@ function UTILS.IsAnyInTable(Table, Objects, Key) return false end + +--- Helper function to plot a racetrack on the F10 Map - curtesy of Buur. +-- @param Core.Point#COORDINATE Coordinate +-- @param #number Altitude Altitude in feet +-- @param #number Speed Speed in knots +-- @param #number Heading Heading in degrees +-- @param #number Leg Leg in NM +-- @param #number Coalition Coalition side, e.g. coaltion.side.RED or coaltion.side.BLUE +-- @param #table Color Color of the line in RGB, e.g. {1,0,0} for red +-- @param #number Alpha Transparency factor, between 0.1 and 1 +-- @param #number LineType Line type to be used, line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 1=Solid. +-- @param #boolean ReadOnly +function UTILS.PlotRacetrack(Coordinate, Altitude, Speed, Heading, Leg, Coalition, Color, Alpha, LineType, ReadOnly) + local fix_coordinate = Coordinate + local altitude = Altitude + local speed = Speed or 350 + local heading = Heading or 270 + local leg_distance = Leg or 10 + + local coalition = Coalition or -1 + local color = Color or {1,0,0} + local alpha = Alpha or 1 + local lineType = LineType or 1 + + + speed = UTILS.IasToTas(speed, UTILS.FeetToMeters(altitude), oatcorr) + + local turn_radius = 0.0211 * speed -3.01 + + local point_two = fix_coordinate:Translate(UTILS.NMToMeters(leg_distance), heading, true, false) + local point_three = point_two:Translate(UTILS.NMToMeters(turn_radius)*2, heading - 90, true, false) + local point_four = fix_coordinate:Translate(UTILS.NMToMeters(turn_radius)*2, heading - 90, true, false) + local circle_center_fix_four = point_two:Translate(UTILS.NMToMeters(turn_radius), heading - 90, true, false) + local circle_center_two_three = fix_coordinate:Translate(UTILS.NMToMeters(turn_radius), heading - 90, true, false) + + + fix_coordinate:LineToAll(point_two, coalition, color, alpha, lineType) + point_four:LineToAll(point_three, coalition, color, alpha, lineType) + circle_center_fix_four:CircleToAll(UTILS.NMToMeters(turn_radius), coalition, color, alpha, nil, 0, lineType)--, ReadOnly, Text) + circle_center_two_three:CircleToAll(UTILS.NMToMeters(turn_radius), coalition, color, alpha, nil, 0, lineType)--, ReadOnly, Text) + +end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 5d1c895d4..fdc6c8f1e 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -1,4 +1,4 @@ ------ **Wrapper** - GROUP wraps the DCS Class Group objects. +--- **Wrapper** - GROUP wraps the DCS Class Group objects. -- -- === -- @@ -1653,7 +1653,7 @@ function GROUP:GetMinHeight() return nil end ---- Returns the current maximum height of the group. +--- Returns the current maximum height of the group, i.e. the highest unit height of that group. -- Each unit within the group gets evaluated, and the maximum height (= the unit which is the highest elevated) is returned. -- @param #GROUP self -- @return #number Maximum height found. @@ -1668,7 +1668,7 @@ function GROUP:GetMaxHeight() for Index, UnitData in pairs( DCSGroup:getUnits() ) do local UnitData = UnitData -- DCS#Unit - local UnitHeight = UnitData:getPoint() + local UnitHeight = UnitData:getPoint().p.y -- Height -- found by @Heavydrinker if UnitHeight > GroupHeightMax then GroupHeightMax = UnitHeight