Add function Utils.getWayPoints()
This commit is contained in:
@@ -230,5 +230,53 @@ do
|
||||
end
|
||||
|
||||
|
||||
--- Returns an array containing a group's units positions.
|
||||
-- e.g.
|
||||
-- {
|
||||
-- [1] = {x = 299435.224, y = -1146632.6773},
|
||||
-- [2] = {x = 663324.6563, y = 322424.1112}
|
||||
-- }
|
||||
-- @tparam number|string groupIdent group id or name
|
||||
-- @treturn table array containing positions of each group member
|
||||
function Utils.getWayPoints(groupIdent)
|
||||
-- search by groupId and allow groupId and groupName as inputs
|
||||
local gpId = groupIdent
|
||||
if type(groupIdent) == 'string' and not tonumber(groupIdent) then
|
||||
local group = Group.getByName(groupIdent)
|
||||
if not group then return end
|
||||
|
||||
gpId = group:getID()
|
||||
end
|
||||
|
||||
for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
if type(coa_data) == 'table' then
|
||||
if coa_data.country then --there is a country table
|
||||
for cntry_id, cntry_data in pairs(coa_data.country) do
|
||||
for obj_cat_name, obj_cat_data in pairs(cntry_data) do
|
||||
if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" then -- only these types have points
|
||||
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
||||
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||
if group_data and group_data.groupId == gpId then -- this is the group we are looking for
|
||||
if group_data.route and group_data.route.points and #group_data.route.points > 0 then
|
||||
local points = {}
|
||||
for point_num, point in pairs(group_data.route.points) do
|
||||
if not point.point then
|
||||
points[point_num] = { x = point.x, y = point.y }
|
||||
else
|
||||
points[point_num] = point.point --it's possible that the ME could move to the point = Vec2 notation.
|
||||
end
|
||||
end
|
||||
return points
|
||||
end
|
||||
return
|
||||
end --if group_data and group_data.name and group_data.name == 'groupname'
|
||||
end --for group_num, group_data in pairs(obj_cat_data.group) do
|
||||
end --if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then
|
||||
end --if obj_cat_name == "helicopter" or obj_cat_name == "ship" or obj_cat_name == "plane" or obj_cat_name == "vehicle" or obj_cat_name == "static" then
|
||||
end --for obj_cat_name, obj_cat_data in pairs(cntry_data) do
|
||||
end --for cntry_id, cntry_data in pairs(coa_data.country) do
|
||||
end --if coa_data.country then --there is a country table
|
||||
end --if coa_name == 'red' or coa_name == 'blue' and type(coa_data) == 'table' then
|
||||
end --for coa_name, coa_data in pairs(mission.coalition) do
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user