diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index d7eed88..0537517 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -11,6 +11,9 @@
PR #17
Supply crate spawning now checks for free space and will not spawn if the area is too crowded.
Additionally different units will spawn in different areas depending on loading side.
+- PR #15
+ Fixed command wiring for supply hubs for better and more accurate detection of units spawning and entering/exiting zone.
+
## [0.12.1] 2026-07
diff --git a/config.lua b/config.lua
index 44014cf..cc7da67 100644
--- a/config.lua
+++ b/config.lua
@@ -6,7 +6,7 @@ SpearheadConfig = {
--- The time briefings should be displayed by default.
--- Players can always "Clear Messages" through the F10 menu, so setting it to a high value can be
- briefingMessageDuration = 30, --default 30
+ briefingMessageDuration = 60, --default 60
CapConfig = {
--quickly enable of disable the entire CAP Logic
diff --git a/src/classes/configuration/GlobalConfig.lua b/src/classes/configuration/GlobalConfig.lua
index 102703c..4e5ba74 100644
--- a/src/classes/configuration/GlobalConfig.lua
+++ b/src/classes/configuration/GlobalConfig.lua
@@ -25,7 +25,7 @@ function GlobalConfig.New()
end
function GlobalConfig:getBriefingTime()
- return self._briefingTime or 30
+ return self._briefingTime or 60
end
diff --git a/src/classes/stageClasses/helpers/MissionCommandsHelper.lua b/src/classes/stageClasses/helpers/MissionCommandsHelper.lua
index a519d0f..1328af3 100644
--- a/src/classes/stageClasses/helpers/MissionCommandsHelper.lua
+++ b/src/classes/stageClasses/helpers/MissionCommandsHelper.lua
@@ -14,7 +14,6 @@ local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHel
---@field updateContinuous fun(self: MissionCommandsHelper, time: number): number @function to update commands continuously
---@field pinnedByGroup table @table of pinned missions by group ID
---@field private _stageBriefings table @table of stage briefings by stage name
----@field private _supplyHubGroups table @table of supply hub groups by their ID
---@field private _logger Logger @logger instance for logging
---@field private _supplyUnitsTracker SupplyUnitsTracker @supply units tracker instance
local MissionCommandsHelper = {}
@@ -49,11 +48,28 @@ function MissionCommandsHelper.getOrCreate(logLevel)
instance.updateNeeded = false
instance.pinnedByGroup = {}
instance.lastUpdate = 0
- instance._supplyHubGroups = {}
instance._stageBriefings = {}
instance._supplyUnitsTracker = SupplyUnitsTracker.getOrCreate(logLevel)
+ instance._supplyUnitsTracker:AddOnSupplyUnitEventListener(
+ {
+ enteredSupplyHub = function(self, unit)
+ if unit == nil then return end
+ instance.updateNeeded = true
+ instance:updateCommandsForGroup(unit:getGroup():getID())
+ end,
+ exitedSupplyHub = function(self, unit)
+ instance.updateNeeded = true
+ instance:updateCommandsForGroup(unit:getGroup():getID())
+ end,
+ supplyUnitSpawned = function(self, unit)
+ instance.updateNeeded = true
+ instance:updateCommandsForGroup(unit:getGroup():getID())
+ end
+ }
+ )
+
---comment
---@param selfA MissionCommandsHelper
---@param time number
@@ -108,32 +124,6 @@ function MissionCommandsHelper:RemoveMissionToCommands(mission)
self.updateNeeded = true
end
----@param groupID number
-function MissionCommandsHelper:MarkUnitInSupplyHub(groupID)
- self._logger:debug("Marking unit in supply hub: " .. tostring(groupID))
- local updateNeeded = false
- if self._supplyHubGroups[tostring(groupID)] ~= true then
- updateNeeded = true
- end
-
- self._supplyHubGroups[tostring(groupID)] = true
- if updateNeeded == true then self:updateCommandsForGroup(groupID) end
-end
-
-
----@param groupID number
-function MissionCommandsHelper:MarkUnitOutsideSupplyHub(groupID)
- self._logger:debug("Marking unit outide supply hub: " .. tostring(groupID))
- local updateNeeded = false
- if self._supplyHubGroups[tostring(groupID)] == true then
- updateNeeded = true
- end
-
- self._supplyHubGroups[tostring(groupID)] = false
- if updateNeeded == true then self:updateCommandsForGroup(groupID) end
-end
-
-
---@param unit Unit
function MissionCommandsHelper:OnPlayerEntersUnit(unit)
@@ -438,7 +428,7 @@ end
---@param groupID integer
function MissionCommandsHelper:AddSupplyHubCommandsIfApplicable(groupID)
- if self._supplyHubGroups[tostring(groupID)] ~= true then return end
+ if self._supplyUnitsTracker:IsGroupLeadInSupplyHub(groupID) ~= true then return end
self._logger:debug("Adding supply hub commands for group: " .. tostring(groupID))
@@ -536,8 +526,7 @@ function MissionCommandsHelper:addMissionFolders(groupId)
missionCommands.addSubMenuForGroup(groupId, folderNames.primary)
missionCommands.addSubMenuForGroup(groupId, folderNames.secondary)
- if self._supplyHubGroups[tostring(groupId)] == true then
- self._logger:debug("Adding supply hub commands folder for group: " .. tostring(groupId))
+ if self._supplyUnitsTracker:IsGroupLeadInSupplyHub(groupId) == true then
missionCommands.addSubMenuForGroup(groupId, folderNames.supplyHub)
end
diff --git a/src/classes/stageClasses/helpers/SupplyUnitsTracker.lua b/src/classes/stageClasses/helpers/SupplyUnitsTracker.lua
index d26d863..f6376f1 100644
--- a/src/classes/stageClasses/helpers/SupplyUnitsTracker.lua
+++ b/src/classes/stageClasses/helpers/SupplyUnitsTracker.lua
@@ -94,7 +94,7 @@ end
---@param listener SupplyUnitEventListener
-function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
+function SupplyUnitsTracker:AddOnSupplyUnitEventListener(listener)
if listener == nil then return end
if self._supplyUnitEventsListeners == nil then
@@ -104,6 +104,26 @@ function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
table.insert(self._supplyUnitEventsListeners, listener)
end
+---@param unit Unit
+---@return boolean
+function SupplyUnitsTracker:IsUnitInSupplyHub(unit)
+ if unit == nil then return false end
+ local unitIDStr = tostring(unit:getID())
+ return self._unitInSupplyHub[unitIDStr] == true
+end
+
+---@param groupID number
+---@return boolean
+function SupplyUnitsTracker:IsGroupLeadInSupplyHub(groupID)
+ local group = DcsUtil.GetPlayerGroupByGroupID(groupID)
+ if group == nil then return false end
+
+ local unit = group:getUnit(1)
+ if unit == nil then return false end
+
+ return self:IsUnitInSupplyHub(unit)
+end
+
function SupplyUnitsTracker:Update()
local players = DcsUtil.getAllPlayerUnits()
for _, player in pairs(players) do
@@ -211,7 +231,6 @@ function SupplyUnitsTracker:CheckUnitsInZones()
if Util.is3dPointInZone(pos, zone) then
if self._unitInSupplyHub[tostring(unit:getID())] ~= true then
self._unitInSupplyHub[tostring(unit:getID())] = true
-
for _, listener in pairs(self._supplyUnitEventsListeners) do
pcall(function()
if listener.enteredSupplyHub then
diff --git a/src/classes/stageClasses/missions/BuildableMission.lua b/src/classes/stageClasses/missions/BuildableMission.lua
index c270945..4a7a8ac 100644
--- a/src/classes/stageClasses/missions/BuildableMission.lua
+++ b/src/classes/stageClasses/missions/BuildableMission.lua
@@ -197,7 +197,7 @@ function BuildableMission:SpawnActive()
self._state = "ACTIVE"
self._missionCommandsHelper:AddMissionToCommands(self)
- self._supplyUnitsTracker:AddOnSupplyUnitSpawnedListener(self)
+ self._supplyUnitsTracker:AddOnSupplyUnitEventListener(self)
local units = self._supplyUnitsTracker:GetUnits()
if units then