added lua check CI step (#49)
Publish Release / build (push) Failing after 3s

Reviewed-on: #49
Co-authored-by: dutchie031 <timrorije@gmail.com>
This commit was merged in pull request #49.
This commit is contained in:
2026-09-20 16:08:04 +00:00
committed by dutchie031
parent 9b2540d461
commit 9549e8c48e
61 changed files with 1058 additions and 881 deletions
+79 -44
View File
@@ -32,6 +32,10 @@ do -- INIT DCS_UTIL
---| "Cilinder"
---| "Polygon"
---@class KeyValuePair
---@field key string
---@field value any
---@class SpearheadTriggerZone
---@field name string
---@field location Vec2
@@ -40,7 +44,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,18 +70,21 @@ 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
do --init trigger zones
for i, trigger_zone in pairs(env.mission.triggers.zones) do
for _, trigger_zone in pairs(env.mission.triggers.zones) do
-- reorder verts as they are not ordered correctly in the ME
local verts = {}
if Util.tableLength(trigger_zone.verticies) >= 4 then
@@ -104,8 +111,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 +123,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 +134,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
@@ -192,7 +200,7 @@ do -- INIT DCS_UTIL
BLUE = 2
}
]] --
local input = string.lower(input)
input = string.lower(input)
if input == 'neutrals' or input == "neutral" or input == "0" then
return DCS_UTIL.Coalition.NEUTRAL
end
@@ -218,11 +226,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>
@@ -235,20 +245,25 @@ do -- INIT DCS_UTIL
end
end
for index, zone_name in pairs(zone_names) do
for _, zone_name in pairs(zone_names) do
local zone = DCS_UTIL.__trigger_zones[zone_name]
if zone then
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_name, 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 +277,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,11 +292,13 @@ 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
for k = 1, #group_names do
local entry = nil
---@type { unit : Unit|StaticObject|nil, groupname: string }|nil
local entry
local group = Group.getByName(group_names[k])
if group ~= nil then
entry = { unit = group:getUnit(1), groupname = group_names[k] }
@@ -290,7 +307,7 @@ do -- INIT DCS_UTIL
end
if entry and entry.unit and entry.unit:isExist() == true then
units[#units + 1] = entry
units[#units + 1] = { groupname = entry.groupname, unit = entry.unit }
end
end
@@ -308,20 +325,20 @@ 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 = {}
for index, zone_name in pairs(zone_names) do
for _, zone_name in pairs(zone_names) do
local zone = DCS_UTIL.__trigger_zones[zone_name]
if zone then
zones[#zones + 1] = zone
end
end
---@type Array<string>
local result_zones = {}
for zone_name, zone in pairs(zones) do
for _, zone in pairs(zones) do
if Util.is3dPointInZone({ x = x, z = z, y = 0 }, zone) == true then
result_zones[#result_zones + 1] = zone.name
end
@@ -396,6 +413,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,13 +437,14 @@ 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)
local vec3 = { x = location.x, y = height, z = location.y }
local unitType = string.lower(unitType or "")
unitType = string.lower(unitType or "")
local conversionType = config[unitType]
if not conversionType then conversionType = "DDM" end
@@ -429,6 +459,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 +471,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
@@ -471,7 +502,7 @@ do -- INIT DCS_UTIL
lon_hemisphere, math.abs(lon_deg), lon_min_display, lon_sec_display,
altitude * 3,28084)
end
end
---@param zone SpearheadTriggerZone
@@ -559,6 +590,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,10 +603,11 @@ 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)
for key, unit in pairs(players) do
for _, unit in pairs(players) do
units[#units + 1] = unit
end
end
@@ -616,9 +649,9 @@ do -- INIT DCS_UTIL
return result
end
---@param unitName string
function DCS_UTIL.CleanCorpse(unitName)
local unitName = "dead_" .. unitName
unitName = "dead_" .. unitName
local object = StaticObject.getByName(unitName)
if object then
@@ -632,11 +665,11 @@ do -- INIT DCS_UTIL
---@field b number
---@field a number
local drawID = 4210
local __drawID = 4210
function DCS_UTIL.GetNextDrawID()
drawID = drawID + 1
return drawID
__drawID = __drawID + 1
return __drawID
end
---@param groupID number
@@ -644,9 +677,9 @@ do -- INIT DCS_UTIL
---@param location Vec3
---@return number markID
function DCS_UTIL.AddMarkToGroup(groupID, text, location)
local drawID = DCS_UTIL.GetNextDrawID()
trigger.action.markToGroup(drawID, text, location, groupID, true, nil)
return drawID
local nextId = DCS_UTIL.GetNextDrawID()
trigger.action.markToGroup(nextId, text, location, groupID, true, nil)
return nextId
end
---comment
@@ -654,9 +687,9 @@ do -- INIT DCS_UTIL
---@param location Vec3
---@return integer
function DCS_UTIL.AddMarkToAll(text, location)
local drawID = DCS_UTIL.GetNextDrawID()
trigger.action.markToAll(drawID, text, location, true, nil)
return drawID
local nextId = DCS_UTIL.GetNextDrawID()
trigger.action.markToAll(nextId, text, location, true, nil)
return nextId
end
---@param markId number
@@ -705,7 +738,7 @@ do -- INIT DCS_UTIL
---@return number? id
function DCS_UTIL.GetNeutralCountry()
for name, id in pairs(country.id) do
for _, id in pairs(country.id) do
if coalition.getCountryCoalition(id) == DCS_UTIL.Coalition.NEUTRAL then
return id
end
@@ -735,6 +768,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
@@ -759,7 +794,7 @@ do -- INIT DCS_UTIL
function DCS_UTIL.GetPlayerGroupByGroupID(groupId)
for i = 0, 2 do
local players = coalition.getPlayers(i)
for key, unit in pairs(players) do
for _, unit in pairs(players) do
if unit and unit:isExist() == true then
local group = unit:getGroup()
if group and group:getID() == groupId then
@@ -775,7 +810,7 @@ do -- INIT DCS_UTIL
function DCS_UTIL.GetPlayerUnitByID(unitID)
for i = 0, 2 do
local players = coalition.getPlayers(i)
for key, unit in pairs(players) do
for _, unit in pairs(players) do
if unit and unit:getID() == unitID then
return unit
end