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
|
||||
|
||||
Reference in New Issue
Block a user