resolved conflict from develop
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
#start
|
#start
|
||||||
|
|
||||||
name: update newsletters
|
name: Release
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
- develop
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
buildandpush:
|
buildandpush:
|
||||||
@@ -61,8 +62,16 @@ jobs:
|
|||||||
- run: npm i markdown-to-html-cli -g
|
- run: npm i markdown-to-html-cli -g
|
||||||
- run: markdown-to-html --title 'Spearhead' --dark-mode auto --keywords "dcs,spearhead,tdcs,mission,campaign,tactical dcs,tactical" --no-dark-mode --markdown-style-theme dark --source ./spearhead/_docs/$sourcefileA.md --output ./$repo/Spearhead/$sourcefileA.html
|
- run: markdown-to-html --title 'Spearhead' --dark-mode auto --keywords "dcs,spearhead,tdcs,mission,campaign,tactical dcs,tactical" --no-dark-mode --markdown-style-theme dark --source ./spearhead/_docs/$sourcefileA.md --output ./$repo/Spearhead/$sourcefileA.html
|
||||||
- run: markdown-to-html --title 'Spearhead' --dark-mode auto --keywords "dcs,spearhead,tdcs,mission,campaign,tactical dcs,tactical" --no-dark-mode --markdown-style-theme dark --source ./spearhead/_docs/$sourcefileB.md --output ./$repo/Spearhead/$sourcefileB.html
|
- run: markdown-to-html --title 'Spearhead' --dark-mode auto --keywords "dcs,spearhead,tdcs,mission,campaign,tactical dcs,tactical" --no-dark-mode --markdown-style-theme dark --source ./spearhead/_docs/$sourcefileB.md --output ./$repo/Spearhead/$sourcefileB.html
|
||||||
|
|
||||||
- run: python3 ./spearhead/SpearheadCompile.py "./spearhead" "./$repo/Spearhead/spearhead.lua"
|
- run: python3 ./spearhead/SpearheadCompile.py "./spearhead" "./$repo/Spearhead/spearhead.lua"
|
||||||
- run: cp "./spearhead/config.lua" "./$repo/Spearhead/spearheadConfig.lua"
|
if: github.ref == 'refs/heads/master'
|
||||||
|
|
||||||
|
- run: mkdir -p ./$repo/Spearhead/beta
|
||||||
|
if: github.ref == 'refs/heads/develop'
|
||||||
|
|
||||||
|
- run: python3 ./spearhead/SpearheadCompile.py "./spearhead" "./$repo/Spearhead/beta/spearhead.lua"
|
||||||
|
if: github.ref == 'refs/heads/develop'
|
||||||
|
|
||||||
- run: cp -a ./spearhead/_docs/img/. ./$repo/Spearhead/img/
|
- run: cp -a ./spearhead/_docs/img/. ./$repo/Spearhead/img/
|
||||||
- name: ls
|
- name: ls
|
||||||
run: ls
|
run: ls
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ In the example we'll show how you can create a simple island hopping mission
|
|||||||
|
|
||||||
Firstly include the script.
|
Firstly include the script.
|
||||||
<a download="spearhead.lua" href="./spearhead.lua" target="_blank" rel="noopener noreferrer">Download Script</a>
|
<a download="spearhead.lua" href="./spearhead.lua" target="_blank" rel="noopener noreferrer">Download Script</a>
|
||||||
|
<br/>Or if you want to use the latest beta version:
|
||||||
|
<a download="spearhead.lua" href="./beta/spearhead.lua" target="_blank" rel="noopener noreferrer">Download Beta Script</a>
|
||||||
|
|
||||||
Then run the script in the mission. <br/>
|
Then run the script in the mission. <br/>
|
||||||
Please do exactly as it's done below. <br/>
|
Please do exactly as it's done below. <br/>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,8 @@ function CapConfig:new()
|
|||||||
if SpearheadConfig == nil then SpearheadConfig = {} end
|
if SpearheadConfig == nil then SpearheadConfig = {} end
|
||||||
if SpearheadConfig.CapConfig == nil then SpearheadConfig.CapConfig = {} end
|
if SpearheadConfig.CapConfig == nil then SpearheadConfig.CapConfig = {} end
|
||||||
|
|
||||||
local enabled = SpearheadConfig.CapConfig.enabled or true
|
local enabled = SpearheadConfig.CapConfig.enabled
|
||||||
|
if enabled == nil then enabled = true end
|
||||||
---@return boolean
|
---@return boolean
|
||||||
o.isEnabled = function(self) return enabled == true end
|
o.isEnabled = function(self) return enabled == true end
|
||||||
|
|
||||||
|
|||||||
@@ -7,22 +7,35 @@ function StageConfig:new()
|
|||||||
if SpearheadConfig == nil then SpearheadConfig = {} end
|
if SpearheadConfig == nil then SpearheadConfig = {} end
|
||||||
if SpearheadConfig.StageConfig == nil then SpearheadConfig.StageConfig = {} end
|
if SpearheadConfig.StageConfig == nil then SpearheadConfig.StageConfig = {} end
|
||||||
|
|
||||||
local enabled = SpearheadConfig.StageConfig.enabled or true
|
local enabled = SpearheadConfig.StageConfig.enabled
|
||||||
|
if enabled == nil then enabled = true end
|
||||||
---@return boolean
|
---@return boolean
|
||||||
o.isEnabled = function(self) return enabled == true end
|
o.isEnabled = function(self) return enabled == true end
|
||||||
|
|
||||||
local drawStages = SpearheadConfig.StageConfig.drawStages or true
|
local drawStages = SpearheadConfig.StageConfig.drawStages
|
||||||
|
if drawStages == nil then drawStages = true end
|
||||||
---@return boolean
|
---@return boolean
|
||||||
o.isDrawStagesEnabled = function(self) return drawStages == true end
|
o.isDrawStagesEnabled = function(self) return drawStages == true end
|
||||||
|
|
||||||
local autoStages = SpearheadConfig.StageConfig.autoStages or true
|
local autoStages = SpearheadConfig.StageConfig.autoStages or true
|
||||||
|
if autoStages == nil then autoStages = true end
|
||||||
---@return boolean
|
---@return boolean
|
||||||
o.isAutoStages = function(self) return autoStages end
|
o.isAutoStages = function(self) return autoStages end
|
||||||
|
|
||||||
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
|
local maxMissionsPerStage = SpearheadConfig.StageConfig.maxMissionStage
|
||||||
o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end
|
o.getMaxMissionsPerStage = function(self) return maxMissionsPerStage end
|
||||||
|
|
||||||
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.DEBUG
|
o.logLevel = Spearhead.LoggerTemplate.LogLevelOptions.INFO
|
||||||
|
|
||||||
|
o.toString = function()
|
||||||
|
return Spearhead.Util.toString({
|
||||||
|
maxMissionsPerStage = maxMissionsPerStage,
|
||||||
|
enabled = enabled,
|
||||||
|
drawStages = drawStages,
|
||||||
|
autoStages = autoStages
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ local fleetGroups = {}
|
|||||||
|
|
||||||
GlobalFleetManager.start = function(database)
|
GlobalFleetManager.start = function(database)
|
||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate:new("CARRIERFLEET", Spearhead.LoggerTemplate.LogLevelOptions.DEBUG)
|
local logger = Spearhead.LoggerTemplate:new("CARRIERFLEET", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||||
|
|
||||||
local all_groups = Spearhead.DcsUtil.getAllGroupNames()
|
local all_groups = Spearhead.DcsUtil.getAllGroupNames()
|
||||||
for _, groupName in pairs(all_groups) do
|
for _, groupName in pairs(all_groups) do
|
||||||
@@ -18,4 +18,5 @@ GlobalFleetManager.start = function(database)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not Spearhead.internal then Spearhead.internal = {} end
|
||||||
Spearhead.internal.GlobalFleetManager = GlobalFleetManager
|
Spearhead.internal.GlobalFleetManager = GlobalFleetManager
|
||||||
@@ -445,9 +445,13 @@ do -- INIT DCS_UTIL
|
|||||||
---checks if the groupname is a static group
|
---checks if the groupname is a static group
|
||||||
---@param groupName any
|
---@param groupName any
|
||||||
function DCS_UTIL.IsGroupStatic(groupName)
|
function DCS_UTIL.IsGroupStatic(groupName)
|
||||||
|
if DCS_UTIL.__miz_groups[groupName] then
|
||||||
return DCS_UTIL.__miz_groups[groupName].category == 5;
|
return DCS_UTIL.__miz_groups[groupName].category == 5;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return StaticObject.getByName(groupName) ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param groupName string destroy the given group
|
---@param groupName string destroy the given group
|
||||||
function DCS_UTIL.DestroyGroup(groupName)
|
function DCS_UTIL.DestroyGroup(groupName)
|
||||||
@@ -739,8 +743,8 @@ do -- INIT DCS_UTIL
|
|||||||
---@return table units
|
---@return table units
|
||||||
function DCS_UTIL.getAllPlayerUnits()
|
function DCS_UTIL.getAllPlayerUnits()
|
||||||
local units = {}
|
local units = {}
|
||||||
for key, value in pairs({ 1, 2, 3 }) do
|
for i = 0,2 do
|
||||||
local players = coalition.getPlayers(value)
|
local players = coalition.getPlayers(i)
|
||||||
for key, unit in pairs(players) do
|
for key, unit in pairs(players) do
|
||||||
units[#units + 1] = unit
|
units[#units + 1] = unit
|
||||||
end
|
end
|
||||||
@@ -782,29 +786,6 @@ do -- INIT DCS_UTIL
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
---Gets all groups that have players
|
|
||||||
---@return table groups
|
|
||||||
function DCS_UTIL.getAllPlayerGroups()
|
|
||||||
local groupNames = {}
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs({ 1, 2, 3 }) do
|
|
||||||
local players = coalition.getPlayers(value)
|
|
||||||
for key, unit in pairs(players) do
|
|
||||||
local group = unit:getGroup()
|
|
||||||
if group ~= nil then
|
|
||||||
local name = group:getName()
|
|
||||||
if name ~= nil then
|
|
||||||
if groupNames[name] ~= nil then
|
|
||||||
groupNames[name] = 1
|
|
||||||
table.insert(result, group)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
--- spawns the units as specified in the mission file itself
|
--- spawns the units as specified in the mission file itself
|
||||||
--- location and route can be nil and will then use default route
|
--- location and route can be nil and will then use default route
|
||||||
---@param groupName string
|
---@param groupName string
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ do -- DB
|
|||||||
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, 1)"
|
functionString = functionString .. "{0,1,0,1}, {0,1,0,1}, 1)"
|
||||||
|
|
||||||
env.info(functionString)
|
env.info(functionString)
|
||||||
|
---@diagnostic disable-next-line: deprecated
|
||||||
local f, err = loadstring(functionString)
|
local f, err = loadstring(functionString)
|
||||||
if f then
|
if f then
|
||||||
f()
|
f()
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
|
|
||||||
local SpearheadEvents = {}
|
local SpearheadEvents = {}
|
||||||
do
|
do
|
||||||
local SpearheadLogger = Spearhead.LoggerTemplate:new("Spearhead Events",
|
|
||||||
Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
|
||||||
|
|
||||||
do -- STAGE NUMBER CHANGED
|
do -- STAGE NUMBER CHANGED
|
||||||
local OnStageNumberChangedListeners = {}
|
local OnStageNumberChangedListeners = {}
|
||||||
local OnStageNumberChangedHandlers = {}
|
local OnStageNumberChangedHandlers = {}
|
||||||
|
|
||||||
|
|
||||||
|
local warn = function(text)
|
||||||
|
env.warn("[Spearhead][Events] " .. (text or "nil"))
|
||||||
|
end
|
||||||
|
|
||||||
|
local error = function(text)
|
||||||
|
env.error("[Spearhead][Events] " .. (text or "nil"))
|
||||||
|
end
|
||||||
|
|
||||||
---Add a stage zone number changed listener
|
---Add a stage zone number changed listener
|
||||||
---@param listener table object with function OnStageNumberChanged(self, number)
|
---@param listener table object with function OnStageNumberChanged(self, number)
|
||||||
SpearheadEvents.AddStageNumberChangedListener = function(listener)
|
SpearheadEvents.AddStageNumberChangedListener = function(listener)
|
||||||
if type(listener) ~= "table" then
|
if type(listener) ~= "table" then
|
||||||
SpearheadLogger:warn("Event listener not of type table, did you mean to use handler?")
|
warn("Event listener not of type table, did you mean to use handler?")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
table.insert(OnStageNumberChangedListeners, listener)
|
table.insert(OnStageNumberChangedListeners, listener)
|
||||||
@@ -22,7 +28,7 @@ do
|
|||||||
---@param handler function function(number)
|
---@param handler function function(number)
|
||||||
SpearheadEvents.AddStageNumberChangedHandler = function(handler)
|
SpearheadEvents.AddStageNumberChangedHandler = function(handler)
|
||||||
if type(handler) ~= "function" then
|
if type(handler) ~= "function" then
|
||||||
SpearheadLogger:warn("Event handler not of type function, did you mean to use listener?")
|
warn("Event handler not of type function, did you mean to use listener?")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
table.insert(OnStageNumberChangedHandlers, handler)
|
table.insert(OnStageNumberChangedHandlers, handler)
|
||||||
@@ -35,31 +41,31 @@ do
|
|||||||
callable:OnStageNumberChanged(newStageNumber)
|
callable:OnStageNumberChanged(newStageNumber)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, callable in pairs(OnStageNumberChangedHandlers) do
|
for _, callable in pairs(OnStageNumberChangedHandlers) do
|
||||||
local succ, err = pcall(callable, newStageNumber)
|
local succ, err = pcall(callable, newStageNumber)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local onLandEventListeners = {}
|
local onLandEventListeners = {}
|
||||||
---Add an event listener to a specific unit
|
---Add an event listener to a specific unit
|
||||||
---@param unitName string to call when the unit lands
|
---@param unitName string to call when the unit lands
|
||||||
---@param landListener table table with function OnUnitLanded(self, initiatorUnit, airbase)
|
---@param landListener table table with function OnUnitLanded(self, initiatorUnit, airbase)
|
||||||
SpearheadEvents.addOnUnitLandEventListener = function(unitName, landListener)
|
SpearheadEvents.addOnUnitLandEventListener = function(unitName, landListener)
|
||||||
if type(landListener) ~= "table" then
|
if type(landListener) ~= "table" then
|
||||||
SpearheadLogger:warn("Event handler not of type table/object")
|
warn("Event handler not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
SpearheadLogger:debug("Added Land event handler for unit: " .. unitName)
|
|
||||||
|
|
||||||
if onLandEventListeners[unitName] == nil then
|
if onLandEventListeners[unitName] == nil then
|
||||||
onLandEventListeners[unitName] = {}
|
onLandEventListeners[unitName] = {}
|
||||||
end
|
end
|
||||||
@@ -73,7 +79,7 @@ do
|
|||||||
---@param unitLostListener table Object with function: OnUnitLost(initiatorUnit)
|
---@param unitLostListener table Object with function: OnUnitLost(initiatorUnit)
|
||||||
SpearheadEvents.addOnUnitLostEventListener = function(unitName, unitLostListener)
|
SpearheadEvents.addOnUnitLostEventListener = function(unitName, unitLostListener)
|
||||||
if type(unitLostListener) ~= "table" then
|
if type(unitLostListener) ~= "table" then
|
||||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
warn("Unit lost Event listener not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -92,7 +98,7 @@ do
|
|||||||
---@param handlingObject table object with OnGroupRTB(self, groupName)
|
---@param handlingObject table object with OnGroupRTB(self, groupName)
|
||||||
SpearheadEvents.addOnGroupRTBListener = function(groupName, handlingObject)
|
SpearheadEvents.addOnGroupRTBListener = function(groupName, handlingObject)
|
||||||
if type(handlingObject) ~= "table" then
|
if type(handlingObject) ~= "table" then
|
||||||
SpearheadLogger:warn("Event handler not of type table/object")
|
warn("Event handler not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,7 +112,6 @@ do
|
|||||||
---Publish the Group to RTB
|
---Publish the Group to RTB
|
||||||
---@param groupName string
|
---@param groupName string
|
||||||
SpearheadEvents.PublishRTB = function(groupName)
|
SpearheadEvents.PublishRTB = function(groupName)
|
||||||
SpearheadLogger:debug("Publishing RTB event for group " .. groupName)
|
|
||||||
if groupName ~= nil then
|
if groupName ~= nil then
|
||||||
if OnGroupRTBListeners[groupName] then
|
if OnGroupRTBListeners[groupName] then
|
||||||
for _, callable in pairs(OnGroupRTBListeners[groupName]) do
|
for _, callable in pairs(OnGroupRTBListeners[groupName]) do
|
||||||
@@ -114,7 +119,7 @@ do
|
|||||||
callable:OnGroupRTB(groupName)
|
callable:OnGroupRTB(groupName)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -128,7 +133,7 @@ do
|
|||||||
---@param handlingObject table object with OnGroupRTBInTen(self, groupName)
|
---@param handlingObject table object with OnGroupRTBInTen(self, groupName)
|
||||||
SpearheadEvents.addOnGroupRTBInTenListener = function(groupName, handlingObject)
|
SpearheadEvents.addOnGroupRTBInTenListener = function(groupName, handlingObject)
|
||||||
if type(handlingObject) ~= "table" then
|
if type(handlingObject) ~= "table" then
|
||||||
SpearheadLogger:warn("Event handler not of type table/object")
|
warn("Event handler not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -142,7 +147,6 @@ do
|
|||||||
---Publish the Group is RTB
|
---Publish the Group is RTB
|
||||||
---@param groupName string
|
---@param groupName string
|
||||||
SpearheadEvents.PublishRTBInTen = function(groupName)
|
SpearheadEvents.PublishRTBInTen = function(groupName)
|
||||||
SpearheadLogger:debug("Publishing RTB in TEN event for group " .. groupName)
|
|
||||||
if groupName ~= nil then
|
if groupName ~= nil then
|
||||||
if OnGroupRTBInTenListeners[groupName] then
|
if OnGroupRTBInTenListeners[groupName] then
|
||||||
for _, callable in pairs(OnGroupRTBInTenListeners[groupName]) do
|
for _, callable in pairs(OnGroupRTBInTenListeners[groupName]) do
|
||||||
@@ -150,7 +154,7 @@ do
|
|||||||
callable:OnGroupRTBInTen(groupName)
|
callable:OnGroupRTBInTen(groupName)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -165,7 +169,7 @@ do
|
|||||||
---@param groupName string the groupname to expect
|
---@param groupName string the groupname to expect
|
||||||
SpearheadEvents.addOnGroupOnStationListener = function(groupName, handlingObject)
|
SpearheadEvents.addOnGroupOnStationListener = function(groupName, handlingObject)
|
||||||
if type(handlingObject) ~= "table" then
|
if type(handlingObject) ~= "table" then
|
||||||
SpearheadLogger:warn("Event handler not of type table/object")
|
warn("Event handler not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -179,7 +183,6 @@ do
|
|||||||
---Publish the Group to RTB
|
---Publish the Group to RTB
|
||||||
---@param groupName string
|
---@param groupName string
|
||||||
SpearheadEvents.PublishOnStation = function(groupName)
|
SpearheadEvents.PublishOnStation = function(groupName)
|
||||||
SpearheadLogger:debug("Publishing onStation event for group " .. groupName)
|
|
||||||
if groupName ~= nil then
|
if groupName ~= nil then
|
||||||
if OnGroupOnStationListeners[groupName] then
|
if OnGroupOnStationListeners[groupName] then
|
||||||
for _, callable in pairs(OnGroupOnStationListeners[groupName]) do
|
for _, callable in pairs(OnGroupOnStationListeners[groupName]) do
|
||||||
@@ -187,7 +190,7 @@ do
|
|||||||
callable:OnGroupOnStation(groupName)
|
callable:OnGroupOnStation(groupName)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -202,7 +205,7 @@ do
|
|||||||
---@param listener table object with OnStatusRequestReceived(self, groupId)
|
---@param listener table object with OnStatusRequestReceived(self, groupId)
|
||||||
SpearheadEvents.AddOnStatusRequestReceivedListener = function(listener)
|
SpearheadEvents.AddOnStatusRequestReceivedListener = function(listener)
|
||||||
if type(listener) ~= "table" then
|
if type(listener) ~= "table" then
|
||||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
warn("Unit lost Event listener not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -231,10 +234,10 @@ do
|
|||||||
do -- PLAYER ENTER UNIT
|
do -- PLAYER ENTER UNIT
|
||||||
local playerEnterUnitListeners = {}
|
local playerEnterUnitListeners = {}
|
||||||
---comment
|
---comment
|
||||||
---@param listener table object with OnPlayerEnterUnit(self, unit)
|
---@param listener table object with OnPlayerEntersUnit(self, unit)
|
||||||
SpearheadEvents.AddOnPlayerEnterUnitListener = function(listener)
|
SpearheadEvents.AddOnPlayerEnterUnitListener = function(listener)
|
||||||
if type(listener) ~= "table" then
|
if type(listener) ~= "table" then
|
||||||
SpearheadLogger:warn("Unit lost Event listener not of type table/object")
|
warn("Unit lost Event listener not of type table/object")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -246,10 +249,10 @@ do
|
|||||||
if playerEnterUnitListeners then
|
if playerEnterUnitListeners then
|
||||||
for _, callable in pairs(playerEnterUnitListeners) do
|
for _, callable in pairs(playerEnterUnitListeners) do
|
||||||
local succ, err = pcall(function()
|
local succ, err = pcall(function()
|
||||||
callable:OnPlayerEnterUnit(unit)
|
callable:OnPlayerEntersUnit(unit)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -270,7 +273,7 @@ do
|
|||||||
callable:OnUnitLanded(unit, airbase)
|
callable:OnUnitLanded(unit, airbase)
|
||||||
end)
|
end)
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -289,16 +292,51 @@ do
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
if err then
|
if err then
|
||||||
SpearheadLogger:error(err)
|
error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
local AI_GROUPS = {}
|
||||||
env.info("blaat player entering unit")
|
|
||||||
local groupId = event.initiator:getGroup():getID()
|
local function CheckAndTriggerSpawnAsync(unit, time)
|
||||||
|
local function isPlayer(unit)
|
||||||
|
if unit == nil then return false, "unit is nil" end
|
||||||
|
if unit:isExist() ~= true then return false, "unit does not exist" end
|
||||||
|
local group = unit:getGroup()
|
||||||
|
if group ~= nil then
|
||||||
|
if Spearhead.DcsUtil.IsGroupStatic(group:getName()) == true then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if AI_GROUPS[group:getName()] == true then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local players = Spearhead.DcsUtil.getAllPlayerUnits()
|
||||||
|
local unitName = unit:getName()
|
||||||
|
for i, unit in pairs(players) do
|
||||||
|
if unit:getName() == unitName then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
AI_GROUPS[group:getName()] = true
|
||||||
|
end
|
||||||
|
return false, "unit is nil or does not exist"
|
||||||
|
end
|
||||||
|
|
||||||
|
if isPlayer(unit) == true then
|
||||||
|
local groupId = unit:getGroup():getID()
|
||||||
SpearheadEvents.AddCommandsToGroup(groupId)
|
SpearheadEvents.AddCommandsToGroup(groupId)
|
||||||
|
SpearheadEvents.TriggerPlayerEntersUnit(unit)
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if event.id == world.event.S_EVENT_BIRTH then
|
||||||
|
timer.scheduleFunction(CheckAndTriggerSpawnAsync, event.initiator, timer.getTime() + 3)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ local StagesByIndex = {}
|
|||||||
|
|
||||||
GlobalStageManager = {}
|
GlobalStageManager = {}
|
||||||
function GlobalStageManager:NewAndStart(database, stageConfig)
|
function GlobalStageManager:NewAndStart(database, stageConfig)
|
||||||
|
local logger = Spearhead.LoggerTemplate:new("StageManager", stageConfig.logLevel)
|
||||||
local o = {}
|
local o = {}
|
||||||
setmetatable(o, { __index = self })
|
setmetatable(o, { __index = self })
|
||||||
|
|
||||||
o.onStageCompleted = function(stage)
|
o.logger = logger
|
||||||
|
|
||||||
|
o.onStageCompleted = function(self, stage)
|
||||||
local stageNumber = tostring(stage.stageNumber)
|
local stageNumber = tostring(stage.stageNumber)
|
||||||
local anyActive = false
|
local anyActive = false
|
||||||
for _, stage in pairs(StagesByIndex[stageNumber] or {}) do
|
for _, stage in pairs(StagesByIndex[stageNumber] or {}) do
|
||||||
@@ -24,8 +25,6 @@ function GlobalStageManager:NewAndStart(database, stageConfig)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local logger = Spearhead.LoggerTemplate:new("StageManager", stageConfig.logLevel)
|
|
||||||
|
|
||||||
for _, stageName in pairs(database:getStagezoneNames()) do
|
for _, stageName in pairs(database:getStagezoneNames()) do
|
||||||
|
|
||||||
local stagelogger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
local stagelogger = Spearhead.LoggerTemplate:new(stageName, stageConfig.logLevel)
|
||||||
|
|||||||
@@ -183,17 +183,35 @@ do -- INIT Mission Class
|
|||||||
timer.scheduleFunction(CheckAndUpdate, self, timer.getTime() + 300)
|
timer.scheduleFunction(CheckAndUpdate, self, timer.getTime() + 300)
|
||||||
end
|
end
|
||||||
|
|
||||||
local CleanupDelayedAsync = function (self, time)
|
|
||||||
self:Cleanup()
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
---comment
|
---comment
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param checkUnitHealth boolean?
|
---@param checkUnitHealth boolean?
|
||||||
o.CheckAndUpdateSelf = function(self, checkUnitHealth)
|
o.CheckAndUpdateSelf = function(self, checkUnitHealth)
|
||||||
if not checkUnitHealth then checkUnitHealth = false end
|
if not checkUnitHealth then checkUnitHealth = false end
|
||||||
|
|
||||||
|
if checkUnitHealth == true then
|
||||||
|
local function unitAliveState(unitName)
|
||||||
|
local unit = Unit.getByName(unitName)
|
||||||
|
return unit ~= nil and unit:isExist() == true and unit:getLife() > 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
for groupName, unitNameDict in pairs(self.groupUnitAliveDict) do
|
||||||
|
for unitName, isAlive in pairs(unitNameDict) do
|
||||||
|
if isAlive == true then
|
||||||
|
self.groupUnitAliveDict[groupName][unitName] = unitAliveState(unitName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for groupName, unitNameDict in pairs(self.targetAliveStates) do
|
||||||
|
for unitName, isAlive in pairs(unitNameDict) do
|
||||||
|
if isAlive == true then
|
||||||
|
self.targetAliveStates[groupName][unitName] = unitAliveState(unitName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if self.missionState == Mission.MissionState.COMPLETED then
|
if self.missionState == Mission.MissionState.COMPLETED then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ do --init STAGE DIRECTOR
|
|||||||
o.db.blueSamGroups = {}
|
o.db.blueSamGroups = {}
|
||||||
o.db.airbaseIds = {}
|
o.db.airbaseIds = {}
|
||||||
o.db.farps = {}
|
o.db.farps = {}
|
||||||
o.activeStage = 0
|
o.activeStage = -99
|
||||||
o.preActivated = false
|
o.preActivated = false
|
||||||
o.stageConfig = stageConfig or {}
|
o.stageConfig = stageConfig or {}
|
||||||
o.stageDrawingId = stageDrawingId + 1
|
o.stageDrawingId = stageDrawingId + 1
|
||||||
@@ -146,7 +146,6 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
o.IsComplete = function(self)
|
o.IsComplete = function(self)
|
||||||
for i, mission in pairs(self.db.missions) do
|
for i, mission in pairs(self.db.missions) do
|
||||||
local state = mission:GetState()
|
local state = mission:GetState()
|
||||||
@@ -157,6 +156,19 @@ do --init STAGE DIRECTOR
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local CheckContinuousAsync = function(self, time)
|
||||||
|
self.logger:info("Checking stage completion for stage: " .. self.zoneName)
|
||||||
|
if self.activeStage == self.stageNumber then
|
||||||
|
return nil -- stop looping if this stage is not even active
|
||||||
|
end
|
||||||
|
|
||||||
|
if self:IsComplete() == true then
|
||||||
|
triggerStageCompleteListeners(self)
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return time + 60
|
||||||
|
end
|
||||||
|
|
||||||
---Activates all SAMS, Airbase units etc all at once.
|
---Activates all SAMS, Airbase units etc all at once.
|
||||||
---@param self table
|
---@param self table
|
||||||
o.PreActivate = function(self)
|
o.PreActivate = function(self)
|
||||||
@@ -230,6 +242,8 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 5)
|
timer.scheduleFunction(activateMissionsIfApplicableAsync, self, timer.getTime() + 5)
|
||||||
|
|
||||||
|
timer.scheduleFunction(CheckContinuousAsync, self, timer.getTime() + 60)
|
||||||
end
|
end
|
||||||
|
|
||||||
o.ActivateMissionsIfApplicable = function (self)
|
o.ActivateMissionsIfApplicable = function (self)
|
||||||
@@ -267,6 +281,7 @@ do --init STAGE DIRECTOR
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Cleans up all missions
|
---Cleans up all missions
|
||||||
@@ -471,6 +486,7 @@ do --init STAGE DIRECTOR
|
|||||||
mission:AddMissionCompleteListener(o)
|
mission:AddMissionCompleteListener(o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Spearhead.Events.AddOnPlayerEnterUnitListener(o)
|
||||||
Spearhead.Events.AddOnStatusRequestReceivedListener(o)
|
Spearhead.Events.AddOnStatusRequestReceivedListener(o)
|
||||||
Spearhead.Events.AddStageNumberChangedListener(o)
|
Spearhead.Events.AddStageNumberChangedListener(o)
|
||||||
return o
|
return o
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ SpearheadConfig = {
|
|||||||
enabled = true, -- default true
|
enabled = true, -- default true
|
||||||
|
|
||||||
--Will draw the active and the next stage
|
--Will draw the active and the next stage
|
||||||
drawStages = true, -- default true
|
drawStages = false, -- default true
|
||||||
|
|
||||||
--AutoStages will continue to the next stage automatically on completion of the missions within the stage.
|
--AutoStages will continue to the next stage automatically on completion of the missions within the stage.
|
||||||
-- If you want to make it so the next stage triggers only when you want to disable it here and manually implement the actions needed.
|
-- If you want to make it so the next stage triggers only when you want to disable it here and manually implement the actions needed.
|
||||||
|
|||||||
@@ -8,11 +8,15 @@ if id == 0 then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
local dbLogger = Spearhead.LoggerTemplate:new("database", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||||
|
local standardLogger = Spearhead.LoggerTemplate:new("", Spearhead.LoggerTemplate.LogLevelOptions.INFO)
|
||||||
local databaseManager = Spearhead.DB:new(dbLogger, debug)
|
local databaseManager = Spearhead.DB:new(dbLogger, debug)
|
||||||
|
|
||||||
local capConfig = Spearhead.internal.configuration.CapConfig:new();
|
local capConfig = Spearhead.internal.configuration.CapConfig:new();
|
||||||
local stageConfig = Spearhead.internal.configuration.StageConfig:new();
|
local stageConfig = Spearhead.internal.configuration.StageConfig:new();
|
||||||
|
|
||||||
|
standardLogger:info("Using StageConfig: ".. stageConfig:toString())
|
||||||
|
|
||||||
|
|
||||||
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
Spearhead.internal.GlobalCapManager.start(databaseManager, capConfig, stageConfig)
|
||||||
Spearhead.internal.GlobalStageManager:NewAndStart(databaseManager, stageConfig)
|
Spearhead.internal.GlobalStageManager:NewAndStart(databaseManager, stageConfig)
|
||||||
Spearhead.internal.GlobalFleetManager.start(databaseManager)
|
Spearhead.internal.GlobalFleetManager.start(databaseManager)
|
||||||
@@ -29,9 +33,6 @@ Spearhead.LoadingDone()
|
|||||||
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }; && GCI . -Include *.lua* -Recurse | foreach{(GC $_).Count} | measure-object -sum | % Sum
|
-- Get-ChildItem . -Include *.lua -Recurse | foreach {""+(Get-Content $_).Count + " => " + $_.name }; && GCI . -Include *.lua* -Recurse | foreach{(GC $_).Count} | measure-object -sum | % Sum
|
||||||
-- find . -name '*.lua' | xargs wc -l
|
-- find . -name '*.lua' | xargs wc -l
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--- ==================== DEBUG ORDER OR ZONE VEC ===========================
|
--- ==================== DEBUG ORDER OR ZONE VEC ===========================
|
||||||
-- local zone = Spearhead.DcsUtil.getZoneByName("MISSIONSTAGE_99")
|
-- local zone = Spearhead.DcsUtil.getZoneByName("MISSIONSTAGE_99")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user