All luals findings solved
This commit is contained in:
@@ -40,7 +40,7 @@ do -- INIT DCS_UTIL
|
||||
---@field zone_type SpearheadTriggerZoneType
|
||||
---@field properties Array<KeyValuePair>?
|
||||
|
||||
---@type Array<SpearheadTriggerZone>
|
||||
---@type table<string, SpearheadTriggerZone>
|
||||
DCS_UTIL.__trigger_zones = {}
|
||||
end
|
||||
|
||||
@@ -66,12 +66,15 @@ do -- INIT DCS_UTIL
|
||||
STATIC = 5 --CUSTOM CATEGORY
|
||||
}
|
||||
|
||||
---@type table<string, string>
|
||||
DCS_UTIL.__airbaseNamesById = {}
|
||||
|
||||
---@type table<string, SpearheadTriggerZone>
|
||||
DCS_UTIL.__airbaseZonesByName = {}
|
||||
|
||||
---@type table<string, CoalitionSide>
|
||||
DCS_UTIL.__airportsStartingCoalition = {}
|
||||
---@type table<string, CoalitionSide>
|
||||
DCS_UTIL.__warehouseStartingCoalition = {}
|
||||
function DCS_UTIL.__INIT()
|
||||
do -- INITS ALL TABLES WITH DATA THAT's from the MIZ environment
|
||||
@@ -104,8 +107,8 @@ do -- INIT DCS_UTIL
|
||||
|
||||
if trigger_zone.properties then
|
||||
for _, kvPair in pairs(trigger_zone.properties) do
|
||||
local key = kvPair["key"]
|
||||
local value = kvPair["value"]
|
||||
local key = kvPair.key
|
||||
local value = kvPair.value
|
||||
zone.properties[#zone.properties + 1] = { key = key, value = value }
|
||||
end
|
||||
end
|
||||
@@ -116,6 +119,7 @@ do -- INIT DCS_UTIL
|
||||
|
||||
do -- init airports and warehouses
|
||||
if env.warehouses.airports then
|
||||
env.warehouses.airports = env.warehouses.airports --[[@as table<string, any>]]
|
||||
for warehouse_id, value in pairs(env.warehouses.airports) do
|
||||
if warehouse_id ~= nil then
|
||||
warehouse_id = tostring(warehouse_id) or "nil"
|
||||
@@ -126,12 +130,12 @@ do -- INIT DCS_UTIL
|
||||
end
|
||||
|
||||
if env.warehouses.warehouses then
|
||||
DCS_UTIL.__warehouseStartingCoalition[-1] = "placeholder"
|
||||
env.warehouses.warehouses = env.warehouses.warehouses --[[@as table<number, any>]]
|
||||
for warehouse_id, value in pairs(env.warehouses.warehouses) do
|
||||
if warehouse_id ~= nil then
|
||||
warehouse_id = tostring(warehouse_id) or "nil"
|
||||
local warehouse_id_str = tostring(warehouse_id) or "nil"
|
||||
local coalitionNumber = DCS_UTIL.stringToCoalition(value.coalition)
|
||||
DCS_UTIL.__warehouseStartingCoalition[warehouse_id] = coalitionNumber
|
||||
DCS_UTIL.__warehouseStartingCoalition[warehouse_id_str] = coalitionNumber
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -218,11 +222,13 @@ do -- INIT DCS_UTIL
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- takes a list of units and returns all the units that are in any of the zones
|
||||
---@param unit_names table unit names
|
||||
---@param zone_names table zone names
|
||||
---@return table unit list of objects { unit = UNIT, zone_name = zoneName}
|
||||
---@param unit_names Array<string> unit names
|
||||
---@param zone_names Array<string> zone names
|
||||
---@return table<number, { unit : Unit|StaticObject, zone_name: string }>
|
||||
function DCS_UTIL.getUnitsInZones(unit_names, zone_names)
|
||||
---@type Array<Unit|StaticObject>
|
||||
local units = {}
|
||||
|
||||
---@type Array<SpearheadTriggerZone>
|
||||
@@ -241,14 +247,19 @@ do -- INIT DCS_UTIL
|
||||
zones[#zones + 1] = zone
|
||||
end
|
||||
end
|
||||
|
||||
---@type table<number, { unit : Unit|StaticObject, zone_name: string }>
|
||||
local in_zone_units = {}
|
||||
for units_ind = 1, #units do
|
||||
local lUnit = units[units_ind]
|
||||
local unit_pos = lUnit:getPosition().p
|
||||
local isActive = true
|
||||
local lCat = Object.getCategory(lUnit)
|
||||
for _, zone in pairs(zones) do
|
||||
if unit_pos and ((lCat == 1 and lUnit:isActive() == true) or lCat ~= 1) then -- it is a unit and is active or it is not a unit
|
||||
if lCat == Object.Category.UNIT then
|
||||
local unit = lUnit --[[@as Unit]]
|
||||
isActive = unit:isActive() == true
|
||||
end
|
||||
local unit_pos = lUnit:getPosition().p
|
||||
for _, zone in pairs(zones) do
|
||||
if unit_pos and isActive == true then -- it is a unit and is active or it is not a unit
|
||||
local isInZone = Util.is3dPointInZone(unit_pos, zone)
|
||||
if isInZone == true then
|
||||
in_zone_units[#in_zone_units + 1] = { unit = lUnit, zone_name = zone.name }
|
||||
@@ -262,9 +273,9 @@ do -- INIT DCS_UTIL
|
||||
--- takes a list of groups and returns all the group leaders that are in any of the zones
|
||||
---@param group_names table unit names
|
||||
---@param zone_name string zone names
|
||||
---@return table groupnames list of group names
|
||||
---@return Array<string> groupnames list of group names
|
||||
function DCS_UTIL.getGroupsInZone(group_names, zone_name)
|
||||
local zone = DCS_UTIL.__trigger_zones[zone_name]
|
||||
local zone = DCS_UTIL.__trigger_zones[zone_name] --[[@as SpearheadTriggerZone?]]
|
||||
if zone == nil then
|
||||
return {}
|
||||
end
|
||||
@@ -277,6 +288,7 @@ do -- INIT DCS_UTIL
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@return Array<string> groupnames list of groups that are in the zone
|
||||
function DCS_UTIL.areGroupsInCustomZone(group_names, zone)
|
||||
---@type Array<{ unit : Unit|StaticObject, groupname: string }>
|
||||
local units = {}
|
||||
if Util.tableLength(group_names) < 1 then return {} end
|
||||
|
||||
@@ -308,8 +320,8 @@ do -- INIT DCS_UTIL
|
||||
--- takes a x, y poistion and checks if it is inside any of the zones
|
||||
---@param x number North South position
|
||||
---@param z number West East position
|
||||
---@param zone_names table zone names
|
||||
---@return table zones list of objects { zone_name = zoneName}
|
||||
---@param zone_names Array<string> zone names
|
||||
---@return Array<string> zones list of objects { zone_name = zoneName}
|
||||
function DCS_UTIL.isPositionInZones(x, z, zone_names)
|
||||
---@type Array<SpearheadTriggerZone>
|
||||
local zones = {}
|
||||
@@ -319,7 +331,7 @@ do -- INIT DCS_UTIL
|
||||
zones[#zones + 1] = zone
|
||||
end
|
||||
end
|
||||
|
||||
---@type Array<string>
|
||||
local result_zones = {}
|
||||
for _, zone in pairs(zones) do
|
||||
if Util.is3dPointInZone({ x = x, z = z, y = 0 }, zone) == true then
|
||||
@@ -396,6 +408,18 @@ do -- INIT DCS_UTIL
|
||||
return nil;
|
||||
end
|
||||
|
||||
---@return Array<string>
|
||||
function DCS_UTIL.getAllGroupCategoryNames()
|
||||
return {
|
||||
"airplane",
|
||||
"helicopter",
|
||||
"ground",
|
||||
"ship",
|
||||
"train",
|
||||
"static"
|
||||
}
|
||||
end
|
||||
|
||||
---@type table<string, CoordType>
|
||||
local config =
|
||||
{
|
||||
@@ -408,7 +432,8 @@ do -- INIT DCS_UTIL
|
||||
|
||||
|
||||
---@param location Vec2
|
||||
---@param unitType string
|
||||
---@param unitType string?
|
||||
---@return string?
|
||||
function DCS_UTIL.convertVec2ToUnitUsableType(location, unitType)
|
||||
|
||||
local height = land.getHeight(location)
|
||||
@@ -429,6 +454,7 @@ do -- INIT DCS_UTIL
|
||||
---@private
|
||||
---@param location Vec3
|
||||
---@param coordType CoordType
|
||||
---@return string?
|
||||
function DCS_UTIL.convertToDisplayCoord(location, coordType)
|
||||
local lattitude, longitude, altitude = coord.LOtoLL(location)
|
||||
|
||||
@@ -440,7 +466,7 @@ do -- INIT DCS_UTIL
|
||||
-- Convert DD to DDM (Degrees Decimal Minutes)
|
||||
local function dd_to_ddm(dd)
|
||||
local degrees = math.floor(math.abs(dd))
|
||||
local minutes = (math.abs(dd) - degrees) * 60
|
||||
local minutes = (math.abs(dd) - degrees) * 60 --[[@as number]]
|
||||
local sign = dd >= 0 and 1 or -1
|
||||
return degrees * sign, minutes
|
||||
end
|
||||
@@ -559,6 +585,7 @@ do -- INIT DCS_UTIL
|
||||
end
|
||||
|
||||
---@param group Group
|
||||
---@return string? unit type name
|
||||
function DCS_UTIL.getUnitTypeFromGroup(group)
|
||||
for _, unit in pairs(group:getUnits()) do
|
||||
if unit and unit:isExist() then
|
||||
@@ -571,6 +598,7 @@ do -- INIT DCS_UTIL
|
||||
---comment Get all units that are players
|
||||
---@return Array<Unit> units
|
||||
function DCS_UTIL.getAllPlayerUnits()
|
||||
---@type Array<Unit>
|
||||
local units = {}
|
||||
for i = 0, 2 do
|
||||
local players = coalition.getPlayers(i)
|
||||
@@ -616,6 +644,7 @@ do -- INIT DCS_UTIL
|
||||
return result
|
||||
end
|
||||
|
||||
---@param unitName string
|
||||
function DCS_UTIL.CleanCorpse(unitName)
|
||||
unitName = "dead_" .. unitName
|
||||
local object = StaticObject.getByName(unitName)
|
||||
@@ -734,6 +763,8 @@ do -- INIT DCS_UTIL
|
||||
return false
|
||||
end
|
||||
|
||||
---@param groupName string
|
||||
---@param offset number?
|
||||
---@return boolean
|
||||
function DCS_UTIL.IsBingoFuel(groupName, offset)
|
||||
if offset == nil then offset = 0 end
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
|
||||
---@class MissionEditingWarnings
|
||||
local MissionEditingWarnings = {}
|
||||
|
||||
---@type table<number, string>
|
||||
MissionEditingWarnings.warnings = {}
|
||||
|
||||
function MissionEditingWarnings.Add(warningMessage)
|
||||
table.insert(MissionEditingWarnings, warningMessage or "skip")
|
||||
table.insert(MissionEditingWarnings.warnings, warningMessage or "skip")
|
||||
end
|
||||
|
||||
---@param logger Logger
|
||||
@@ -12,12 +16,12 @@ function MissionEditingWarnings.WriteAll(logger)
|
||||
return
|
||||
end
|
||||
|
||||
if not MissionEditingWarnings or #MissionEditingWarnings == 0 then
|
||||
if not MissionEditingWarnings.warnings or #MissionEditingWarnings.warnings == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
logger:warn("Mission Editor Warnings:")
|
||||
for _, warning in ipairs(MissionEditingWarnings) do
|
||||
for _, warning in ipairs(MissionEditingWarnings.warnings) do
|
||||
logger:warn("- " .. warning)
|
||||
end
|
||||
|
||||
|
||||
+40
-17
@@ -22,7 +22,7 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param table any
|
||||
---@param table table<any, any>
|
||||
---@return number
|
||||
function UTIL.tableLength(table)
|
||||
if table == nil then return 0 end
|
||||
@@ -35,23 +35,34 @@ do -- INIT UTIL
|
||||
---@param orig table
|
||||
---@return table copy
|
||||
function UTIL.deepCopyTable(orig)
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[UTIL.deepCopyTable(orig_key)] = UTIL.deepCopyTable(orig_value)
|
||||
|
||||
---@param original any
|
||||
---@return any
|
||||
local function deepCopy(original)
|
||||
local orig_type = type(original)
|
||||
---@type any
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
original = original --[[@as table<any, any>]]
|
||||
copy = {} --[[@as table<any, any>]]
|
||||
for orig_key, orig_value in pairs(original) do
|
||||
local copiedKey = deepCopy(orig_key) --[[@as any]]
|
||||
copy[copiedKey] = deepCopy(orig_value)
|
||||
end
|
||||
setmetatable(copy, deepCopy(getmetatable(original)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = original --[[@as any]]
|
||||
end
|
||||
setmetatable(copy, UTIL.deepCopyTable(getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
return copy
|
||||
end
|
||||
return copy
|
||||
|
||||
return deepCopy(orig)
|
||||
end
|
||||
|
||||
---Gets a random from the list
|
||||
---@param list Array
|
||||
---@return any @random element from the list
|
||||
---@generic T
|
||||
---@param list Array<T>
|
||||
---@return T @random element from the list
|
||||
function UTIL.randomFromList(list)
|
||||
local max = #list
|
||||
|
||||
@@ -65,11 +76,13 @@ do -- INIT UTIL
|
||||
return list[random]
|
||||
end
|
||||
|
||||
---@param list Array
|
||||
---@generic T
|
||||
---@param list Array<T>
|
||||
---@param start number start
|
||||
---@param n number length
|
||||
---@return Array
|
||||
---@return Array<T>
|
||||
function UTIL.sublist(list, start, n)
|
||||
---@type table<number, any>
|
||||
local result = {}
|
||||
for i = start, n do
|
||||
result[#result + 1] = list[i]
|
||||
@@ -90,9 +103,10 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
local function table_print(tt, indent, done)
|
||||
done = done or {}
|
||||
done = done or {} --[[@as table<any, boolean>]]
|
||||
indent = indent or 0
|
||||
if type(tt) == "table" then
|
||||
tt = tt --[[@as table<any, any>]]
|
||||
local sb = {}
|
||||
for key, value in pairs(tt) do
|
||||
table.insert(sb, string.rep(" ", indent)) -- indent it
|
||||
@@ -146,7 +160,7 @@ do -- INIT UTIL
|
||||
|
||||
---comment
|
||||
---@param str string
|
||||
---@param findableTable table
|
||||
---@param findableTable table<any,any>
|
||||
---@return boolean
|
||||
UTIL.startswithAny = function(str, findableTable)
|
||||
for _, value in pairs(findableTable) do
|
||||
@@ -244,6 +258,7 @@ do -- INIT UTIL
|
||||
---@return boolean
|
||||
local function isInComplexPolygon(polygon, x, y)
|
||||
---@param poly Array<Vec2> of pairs { x, y }
|
||||
---@return Array<{ x1: number, z1: number, x2: number, z2: number }>
|
||||
local function getEdges(poly)
|
||||
local result = {}
|
||||
for i = 1, #poly do
|
||||
@@ -280,6 +295,7 @@ do -- INIT UTIL
|
||||
|
||||
---@param point Vec3
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@return boolean
|
||||
function UTIL.is3dPointInZone(point, zone)
|
||||
if zone.zone_type == "Polygon" and zone.verts then
|
||||
if UTIL.IsPointInPolygon(zone.verts, point.x, point.z) == true then
|
||||
@@ -296,6 +312,7 @@ do -- INIT UTIL
|
||||
|
||||
---@param point Vec2
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@return boolean
|
||||
function UTIL.is2dPointInZone(point, zone)
|
||||
if zone.zone_type == "Polygon" and zone.verts then
|
||||
if UTIL.IsPointInPolygon(zone.verts, point.x, point.y) == true then
|
||||
@@ -447,6 +464,8 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
---@param points Array<Vec2>
|
||||
---@param meters number
|
||||
---@return Array<Vec2>
|
||||
function UTIL.enlargeConvexHull(points, meters)
|
||||
if points == nil or #points == 0 then
|
||||
return {}
|
||||
@@ -524,6 +543,10 @@ function UTIL.GetTangentHullPointsFromOrigin(hull, origin)
|
||||
return {}
|
||||
end
|
||||
|
||||
---@param a Vec2
|
||||
---@param b Vec2
|
||||
---@param c Vec2
|
||||
---@return number
|
||||
local function orientation(a, b, c)
|
||||
-- Returns >0 if c is to the left of ab, <0 if to the right, 0 if colinear
|
||||
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||
|
||||
Reference in New Issue
Block a user