* Initial Methods for SpearheadAPI

* Added Spearhead API

* Added Spearhead API

* fixed compile for api

* Added notes for API in beta

* Added notes for API in beta

* Added Menu to all doc pages

* Added Menu to all doc pages

* added it for real

* added it for real

* fixed develop

* fixed develop

* fixed develop

* wip

* wip

* updated

* work in progress

* work in progress

* added empty docs page

* wip

* removed SAR files from persistence branch

* Added Blue Sams as seperate class

* added initial persistance

* added initial persistance

* added initial persistance

* added initial persistance

* added initial persistance

* added menu to persistence markdown

* added menu to persistence markdown

* added menu to persistence markdown

* docs update

* wip

* wip

* Refactor of Stage classes.

* wip

* wip

* wip

* reworked bluesam and stagebase

* Added waiting stage functionality

* updated docs

* wip

* wip

* wip

* updated

* wip

* wip

* wip

* refactored without issues, needs testing

---------

Co-authored-by: Dutchie <54616262+dutchie032@users.noreply.github.com>
Co-authored-by: dutchie032 <dutchie032>
Co-authored-by: ex61wi <tim.rorije@ing.com>
This commit is contained in:
2025-04-22 14:39:22 +02:00
committed by GitHub
co-authored by Dutchie dutchie032 <dutchie032> ex61wi
parent 9c6a5ed217
commit ff392e0e7e
37 changed files with 4494 additions and 1732 deletions
+96 -46
View File
@@ -78,8 +78,14 @@ do -- INIT UTIL
---comment
---@param str string
---@param findable string
---@param ignoreCase boolean?
---@return boolean
UTIL.startswith = function(str, findable)
UTIL.startswith = function(str, findable, ignoreCase)
if ignoreCase == true then
return string.lower(str):find('^' .. string.lower(findable)) ~= nil
end
return str:find('^' .. findable) ~= nil
end
@@ -114,6 +120,14 @@ do -- INIT UTIL
end
end
---comment
---@param a table DCS Point vector {x, z , y}
---@param b table DCS Point vector {x, z , y}
---@return number
function UTIL.VectorDistance(a, b)
return math.sqrt((b.x - a.x) ^ 2 + (b.z - a.z) ^ 2)
end
---comment
---@param polygon table of pairs { x, z }
---@param x number X location
@@ -452,8 +466,8 @@ do -- INIT DCS_UTIL
return StaticObject.getByName(groupName) ~= nil
end
---comment
---@param groupName string destroy the given group
---destroy the given group
---@param groupName string
function DCS_UTIL.DestroyGroup(groupName)
if DCS_UTIL.IsGroupStatic(groupName) then
local object = StaticObject.getByName(groupName)
@@ -468,6 +482,22 @@ do -- INIT DCS_UTIL
end
end
---destroy the given unit
function DCS_UTIL.DestroyUnit(unitName)
if DCS_UTIL.IsGroupStatic(unitName) == true then
local object = StaticObject.getByName(unitName)
if object ~= nil then
object:destroy()
end
else
local unit = Unit.getByName(unitName)
if unit and unit:isExist() then
unit:destroy()
end
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
@@ -604,7 +634,7 @@ 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_name table zone names
---@param zone_name string zone name
---@return boolean result
function DCS_UTIL.isPositionInZone(x, z, zone_name)
local zone = DCS_UTIL.__trigger_zones[zone_name]
@@ -786,6 +816,37 @@ do -- INIT DCS_UTIL
return result
end
---Spawn an corpse
---@param countryId number countryId
---@param unitType string
---@param location table { z, y, z}
---@param heading number
function DCS_UTIL.SpawnCorpse(countryId, unitName, unitType, location, heading)
local name = "dead_" .. unitName
local staticObj = {
["heading"] = heading,
--["shape_name"] = "stolovaya",
["type"] = unitType,
["name"] = name,
["y"] = location.z,
["x"] = location.x,
["dead"] = true,
}
coalition.addStaticObject(countryId, staticObj)
end
function DCS_UTIL.CleanCorpse(unitName)
local unitName = "dead_" .. unitName
local object = StaticObject.getByName(unitName)
if object then
object:destroy()
end
end
--- spawns the units as specified in the mission file itself
--- location and route can be nil and will then use default route
---@param groupName string
@@ -793,19 +854,20 @@ do -- INIT DCS_UTIL
---@param route table? route of the group. If nil wil be the default route.
---@param uncontrolled boolean? Sets the group to be uncontrolled on spawn
---@return table? new_group the Group class that was spawned
---@return boolean? isStatic whether the group is a static or not
function DCS_UTIL.SpawnGroupTemplate(groupName, location, route, uncontrolled)
if groupName == nil then
return
return nil, nil
end
local template = DCS_UTIL.GetMizGroupOrDefault(groupName, nil)
if template == nil then
return nil
return nil, nil
end
if template.category == DCS_UTIL.GroupCategory.STATIC then
--TODO: Implement location and route stuff
local spawn_template = template.group_template
coalition.addStaticObject(template.country_id, spawn_template)
return coalition.addStaticObject(template.country_id, spawn_template), true
else
local spawn_template = template.group_template
if location ~= nil then
@@ -833,7 +895,7 @@ do -- INIT DCS_UTIL
spawn_template.uncontrolled = uncontrolled
end
local new_group = coalition.addGroup(template.country_id, template.category, spawn_template)
return new_group
return new_group, false
end
end
@@ -843,11 +905,14 @@ do -- INIT DCS_UTIL
bingoSetting = bingoSetting + offset
local group = Group.getByName(groupName)
for _, unit in pairs(group:getUnits()) do
if unit and unit:isExist() == true and unit:inAir() == true and unit:getFuel() < bingoSetting then
return true
if group then
for _, unit in pairs(group:getUnits()) do
if unit and unit:isExist() == true and unit:inAir() == true and unit:getFuel() < bingoSetting then
return true
end
end
end
return false
end
@@ -857,22 +922,25 @@ Spearhead.DcsUtil = DCS_UTIL
local LOGGER = {}
do
LOGGER.LogLevelOptions = {
DEBUG = 0,
INFO = 1,
WARN = 2,
ERROR = 3,
NONE = 4
}
local PreFix = "Spearhead"
function LOGGER:new(logger_name, logLevel, liveLoggingLevel)
--- @class Logger
--- @field debug fun(self:Logger, text:string)
--- @field info fun(self:Logger, text:string)
--- @field warn fun(self:Logger, text:string)
--- @field error fun(self:Logger, text:string)
---comment
---@param logger_name any
---@param logLevel LogLevel
---@return Logger
function LOGGER:new(logger_name, logLevel)
local o = {}
setmetatable(o, { __index = self })
o.LoggerName = logger_name or "(loggername not set)"
o.LogLevel = logLevel or LOGGER.LogLevelOptions.INFO
o.LiveLoggingLevel = liveLoggingLevel or LOGGER.LogLevelOptions.NONE
o.LogLevel = logLevel or "INFO"
---comment
---@param self table self logger
@@ -883,13 +951,9 @@ do
end
message = UTIL.toString(message)
if self.LogLevel <= LOGGER.LogLevelOptions.INFO then
if self.LogLevel == "INFO" or self.LogLevel == "DEBUG" then
env.info("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "] " .. message)
end
if self.LiveLoggingLevel <= LOGGER.LogLevelOptions.INFO then
trigger.action.outText(message, 20)
end
end
---comment
@@ -900,12 +964,8 @@ do
end
message = UTIL.toString(message)
if self.LogLevel <= LOGGER.LogLevelOptions.WARN then
env.warning("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "] " .. message)
end
if self.LiveLoggingLevel <= LOGGER.LogLevelOptions.WARN then
trigger.action.outText(message, 20)
if self.LogLevel == "INFO" or self.LogLevel == "DEBUG" or self.LogLevel == "WARN" then
env.info("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "] " .. message)
end
end
@@ -919,12 +979,8 @@ do
message = UTIL.toString(message)
if self.LogLevel <= LOGGER.LogLevelOptions.ERROR then
env.error("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "] " .. message)
end
if self.LiveLoggingLevel <= LOGGER.LogLevelOptions.ERROR then
trigger.action.outText(message, 20)
if self.LogLevel == "INFO" or self.LogLevel == "DEBUG" or self.LogLevel == "WARN" or self.logLevel == "ERROR" then
env.info("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "] " .. message)
end
end
@@ -937,13 +993,9 @@ do
end
message = UTIL.toString(message)
if self.LogLevel <= LOGGER.LogLevelOptions.DEBUG then
if self.LogLevel == "DEBUG" then
env.info("[" .. PreFix .. "]" .. "[" .. self.LoggerName .. "][DEBUG] " .. message)
end
if self.LiveLoggingLevel <= LOGGER.LogLevelOptions.DEBUG then
trigger.action.outText(message, 20)
end
end
@@ -957,15 +1009,13 @@ function Spearhead.AddMissionEditorWarning(warningMessage)
table.insert(Spearhead.MissionEditingWarnings, warningMessage or "skip")
end
missionCommands.addSubMenu("Missions")
local loadDone = false
Spearhead.LoadingDone = function()
if loadDone == true then
return
end
local warningLogger = Spearhead.LoggerTemplate:new("MISSIONPARSER", Spearhead.LoggerTemplate.LogLevelOptions.INFO, 4)
local warningLogger = Spearhead.LoggerTemplate:new("MISSIONPARSER", "INFO")
if Spearhead.Util.tableLength(Spearhead.MissionEditingWarnings) > 0 then
for key, message in pairs(Spearhead.MissionEditingWarnings) do
warningLogger:warn(message)