From 378e76e45b0a1c84766287adff66e258bc386f0d Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Wed, 13 Mar 2024 09:08:39 +0100 Subject: [PATCH] Added UTILS.ClockHeadingString(refHdg,tgtHdg) thanks to @statua --- Moose Development/Moose/Utilities/Utils.lua | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 25cfb7853..6bf7e1fc9 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -3815,3 +3815,31 @@ function UTILS.LoadSetOfOpsGroups(Path,Filename) return datatable end +--- Get the clock position from a relative heading +-- @param #number refHdg The heading of the reference object (such as a Wrapper.UNIT) in 0-360 +-- @param #number tgtHdg The absolute heading from the reference object to the target object/point in 0-360 +-- @return #string text Text in clock heading such as "4 O'CLOCK" +-- @usage Display the range and clock distance of a BTR in relation to REAPER 1-1's heading: +-- +-- myUnit = UNIT:FindByName( "REAPER 1-1" ) +-- myTarget = GROUP:FindByName( "BTR-1" ) +-- +-- coordUnit = myUnit:GetCoordinate() +-- coordTarget = myTarget:GetCoordinate() +-- +-- hdgUnit = myUnit:GetHeading() +-- hdgTarget = coordUnit:HeadingTo( coordTarget ) +-- distTarget = coordUnit:Get3DDistance( coordTarget ) +-- +-- clockString = UTILS.ClockHeadingString( hdgUnit, hdgTarget ) +-- +-- -- Will show this message to REAPER 1-1 in-game: Contact BTR at 3 o'clock for 1134m! +-- MESSAGE:New("Contact BTR at " .. clockString .. " for " .. distTarget .. "m!):ToUnit( myUnit ) +function UTILS.ClockHeadingString(refHdg,tgtHdg) + local relativeAngle = tgtHdg - refHdg + if relativeAngle < 0 then + relativeAngle = relativeAngle + 360 + end + local clockPos = math.ceil((relativeAngle % 360) / 30) + return clockPos.." o'clock" +end