From a983d1b2d88f946fd98b57769fef2a2eb935298c Mon Sep 17 00:00:00 2001 From: Lugghawk Date: Mon, 24 Dec 2018 18:23:38 -0500 Subject: [PATCH 1/3] group_commands -> communication. spacing in utils.lua --- hoggit.lua | 2 +- lib/{group_commands.lua => communication.lua} | 0 lib/utils.lua | 30 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) rename lib/{group_commands.lua => communication.lua} (100%) diff --git a/hoggit.lua b/hoggit.lua index 7833ed9..c5418dc 100644 --- a/hoggit.lua +++ b/hoggit.lua @@ -2,4 +2,4 @@ dofile(HOGGIT.script_base..[[\HOGGIT\lib\error_handling.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\logging.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\utils.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\spawner.lua]]) -dofile(HOGGIT.script_base..[[\HOGGIT\lib\group_commands.lua]]) +dofile(HOGGIT.script_base..[[\HOGGIT\lib\communication.lua]]) diff --git a/lib/group_commands.lua b/lib/communication.lua similarity index 100% rename from lib/group_commands.lua rename to lib/communication.lua diff --git a/lib/utils.lua b/lib/utils.lua index 06d53de..0d0f821 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -1,22 +1,22 @@ HOGGIT.randomInList = function(list) - local idx = math.random(1, #list) - return list[idx] - end + local idx = math.random(1, #list) + return list[idx] +end HOGGIT.filterTable = function(t, filter) - local out = {} - for k,v in pairs(t) do - if filter(v) then out[k] = v end - end - return out + local out = {} + for k,v in pairs(t) do + if filter(v) then out[k] = v end + end + return out end - + HOGGIT.listContains = function(list, elem) - for _, value in ipairs(list) do - if value == elem then - return true - end + for _, value in ipairs(list) do + if value == elem then + return true end - - return false + end + + return false end From cfe5f1082344f49baf88363600f9d167e4037127 Mon Sep 17 00:00:00 2001 From: Lugghawk Date: Mon, 24 Dec 2018 18:39:56 -0500 Subject: [PATCH 2/3] adds group.lua. getLatLongString to utils. --- hoggit.lua | 1 + lib/group.lua | 8 ++++++++ lib/utils.lua | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 lib/group.lua diff --git a/hoggit.lua b/hoggit.lua index c5418dc..63cda70 100644 --- a/hoggit.lua +++ b/hoggit.lua @@ -3,3 +3,4 @@ dofile(HOGGIT.script_base..[[\HOGGIT\lib\logging.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\utils.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\spawner.lua]]) dofile(HOGGIT.script_base..[[\HOGGIT\lib\communication.lua]]) +dofile(HOGGIT.script_base..[[\HOGGIT\lib\group.lua]]) diff --git a/lib/group.lua b/lib/group.lua new file mode 100644 index 0000000..a7ee839 --- /dev/null +++ b/lib/group.lua @@ -0,0 +1,8 @@ +-- Returns the location of the first unit in a given group. +-- If the group is nil, this function returns nil. +HOGGIT.groupCoords = function(grp) + if grp ~= nil then + return grp:getUnits()[1]:getPosition().p + end + return nil +end diff --git a/lib/utils.lua b/lib/utils.lua index 0d0f821..0678804 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -20,3 +20,9 @@ HOGGIT.listContains = function(list, elem) return false end + +HOGGIT.getLatLongString = function(pos, decimal) + local lat, long = coord.LOtoLL(pos) + if decimal == nil then decimal = false end + return mist.tostringLL(lat, long, 3, decimal) +end From 450b97b91d734063dc83cc4acb2f4f7a7c178948 Mon Sep 17 00:00:00 2001 From: Lugghawk Date: Mon, 24 Dec 2018 19:18:10 -0500 Subject: [PATCH 3/3] adds smokeName and smokeAtGroup. --- lib/group.lua | 11 +++++++++++ lib/utils.lua | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/group.lua b/lib/group.lua index a7ee839..3f2383e 100644 --- a/lib/group.lua +++ b/lib/group.lua @@ -1,8 +1,19 @@ -- Returns the location of the first unit in a given group. -- If the group is nil, this function returns nil. +-- @param grp The group you want coordinates for. +-- @return Vec3 The group's first unit's coordinates, or nil if the group is nil HOGGIT.groupCoords = function(grp) if grp ~= nil then return grp:getUnits()[1]:getPosition().p end return nil end + +-- Starts a smoke beacon at the specified group's location +-- @param grp The group to smoke. Will be placed on or near the first unit. +-- @param smokeColor The trigger.smokeColor enum value to use. Defaults to White smoke +HOGGIT.smokeAtGroup = function(grp, smokeColor) + local pos = HOGGIT.groupCoords(grp) + if smokeColor == nil then smokeColor = trigger.smokeColor.White end + trigger.action.smoke(pos, smokeColor) +end diff --git a/lib/utils.lua b/lib/utils.lua index 0678804..9d0c109 100644 --- a/lib/utils.lua +++ b/lib/utils.lua @@ -26,3 +26,14 @@ HOGGIT.getLatLongString = function(pos, decimal) if decimal == nil then decimal = false end return mist.tostringLL(lat, long, 3, decimal) end + +-- Returns a textual smoke name based on the provided enum +-- @param a trigger.smokeColor enum +-- @return the English word as a string representing the color of the smoke. i.e. trigger.smokeColor.Red returns "Red" +HOGGIT.getSmokeName = function(smokeColor) + if smokeColor == trigger.smokeColor.Green then return "Green" end + if smokeColor == trigger.smokeColor.Red then return "Red" end + if smokeColor == trigger.smokeColor.White then return "White" end + if smokeColor == trigger.smokeColor.Orange then return "Orange" end + if smokeColor == trigger.smokeColor.Blue then return "Blue" end +end