wip
This commit is contained in:
@@ -453,6 +453,7 @@ function MissionCommandsHelper:AddSupplyHubCommandsIfApplicable(groupID)
|
||||
---@field groupID number
|
||||
---@field crateType CrateType
|
||||
---@field supplyUnitsTracker SupplyUnitsTracker
|
||||
---@field commandHelper MissionCommandsHelper
|
||||
|
||||
---comment
|
||||
---@param params LoadCargoCommandParams
|
||||
@@ -460,31 +461,31 @@ function MissionCommandsHelper:AddSupplyHubCommandsIfApplicable(groupID)
|
||||
local crateType = params.crateType
|
||||
local supplyUnitsTracker = params.supplyUnitsTracker
|
||||
if supplyUnitsTracker then
|
||||
supplyUnitsTracker:UnitRequestCrateLoading(params.groupID, crateType)
|
||||
supplyUnitsTracker:UnitRequestCrateLoading(params.groupID, crateType, params.commandHelper)
|
||||
end
|
||||
end
|
||||
|
||||
local path = { [1] = folderNames.supplyHub }
|
||||
|
||||
---@type LoadCargoCommandParams
|
||||
local farpParams1000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "FARP_CRATE_1000", supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
local farpParams1000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "FARP_CRATE_1000", supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Load FARP Crate (1000)", path, loadCargoCommand, farpParams1000)
|
||||
|
||||
---@type LoadCargoCommandParams
|
||||
local farpParams2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "FARP_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
local farpParams2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "FARP_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Load FARP Crate (2000)", path, loadCargoCommand, farpParams2000)
|
||||
|
||||
---@type LoadCargoCommandParams
|
||||
local samParms1000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "SAM_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
local samParms1000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "SAM_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Load SAM Crate (1000)", path, loadCargoCommand, samParms1000)
|
||||
|
||||
---@type LoadCargoCommandParams
|
||||
local samParms2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "SAM_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
local samParms2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "SAM_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Load SAM Crate (2000)", path, loadCargoCommand, samParms2000)
|
||||
|
||||
---@type LoadCargoCommandParams
|
||||
local samParms2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "AIRBASE_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
missionCommands.addCommandForGroup(groupID, "Airbase Crate (2000)", path, loadCargoCommand, samParms2000)
|
||||
local airbaseParms2000 = { unitID = unit:getID(), groupID = group:getID(), crateType = "AIRBASE_CRATE_2000", supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Airbase Crate (2000)", path, loadCargoCommand, airbaseParms2000)
|
||||
end
|
||||
|
||||
function MissionCommandsHelper:AddCargoCommands(groupID)
|
||||
@@ -499,13 +500,15 @@ function MissionCommandsHelper:AddCargoCommands(groupID)
|
||||
---@field unitID number
|
||||
---@field crateType CrateType
|
||||
---@field supplyUnitsTracker SupplyUnitsTracker
|
||||
---@field commandHelper MissionCommandsHelper
|
||||
|
||||
---comment
|
||||
---@param params UnloadCargoCommandParams
|
||||
local unloadCargoCommand = function(params)
|
||||
local unitID = params.unitID
|
||||
local crateType = params.crateType
|
||||
params.supplyUnitsTracker:UnloadRequested(unitID, crateType)
|
||||
local supplyUnitsTracker = params.supplyUnitsTracker
|
||||
params.supplyUnitsTracker:UnloadRequested(unitID, crateType, params.commandHelper)
|
||||
end
|
||||
|
||||
local cargo = self._supplyUnitsTracker:GetCargoInUnit(unit:getID())
|
||||
@@ -516,7 +519,7 @@ function MissionCommandsHelper:AddCargoCommands(groupID)
|
||||
for i = 1, amount do
|
||||
local path = { [1] = folderNames.cargo }
|
||||
---@type UnloadCargoCommandParams
|
||||
local params = { unitID = unit:getID(), crateType = cargoType, supplyUnitsTracker = self._supplyUnitsTracker }
|
||||
local params = { unitID = unit:getID(), crateType = cargoType, supplyUnitsTracker = self._supplyUnitsTracker, commandHelper = self }
|
||||
missionCommands.addCommandForGroup(groupID, "Unload " .. cargoConfig.displayName, path, unloadCargoCommand, params)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
|
||||
local Logger = require("classes.util.Logger")
|
||||
local Util = require("classes.util.Util")
|
||||
local DcsUtil = require("classes.util.DcsUtil")
|
||||
local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionCommandsHelper")
|
||||
local SpearheadEvents = require("classes.spearhead_events")
|
||||
local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper")
|
||||
local MaxLoadConfig = require("classes.stageClasses.helpers.MaxLoadConfig")
|
||||
|
||||
env.info("Spearhead SupplyUnitsTracker loaded")
|
||||
|
||||
---@class SupplyUnitEventListener
|
||||
---@field supplyUnitSpawned fun(self:SupplyUnitEventListener, unit:Unit) | nil
|
||||
---@field enteredSupplyHub fun(self:SupplyUnitEventListener, unit:Unit, hub:SupplyHub) | nil
|
||||
---@field exitedSupplyHub fun(self:SupplyUnitEventListener, unit:Unit, hub:SupplyHub) | nil
|
||||
|
||||
---@class SupplyUnitsTracker
|
||||
---@field private _supplyUnitsByName table<string, Unit>
|
||||
---@field private _cargoInUnits table<string, table<CrateType, number>>
|
||||
---@field private _logger Logger
|
||||
---@field private _unitPositions table<string, Vec3>
|
||||
---@field private _commandsHelper MissionCommandsHelper
|
||||
---@field private _unitInSupplyHub table<string, boolean>
|
||||
---@field private _droppedCrates table<string, StaticObject>
|
||||
---@field private _registeredHubs table<SupplyHub, boolean>
|
||||
---@field private _supplyUnitSpawnedListener Array<SupplyUnitSpawnedListener>
|
||||
---@field private _supplyUnitEventsListeners Array<SupplyUnitEventListener>
|
||||
local SupplyUnitsTracker = {}
|
||||
SupplyUnitsTracker.__index = SupplyUnitsTracker
|
||||
|
||||
@@ -37,10 +40,9 @@ function SupplyUnitsTracker.getOrCreate(logLevel)
|
||||
singleton._supplyUnitsByName = {}
|
||||
singleton._droppedCrates = {}
|
||||
singleton._registeredHubs = {}
|
||||
singleton._supplyUnitSpawnedListener = {}
|
||||
singleton._supplyUnitEventsListeners = {}
|
||||
singleton._unitInSupplyHub = {}
|
||||
|
||||
singleton._commandsHelper = MissionCommandsHelper.getOrCreate(singleton._logger.LogLevel)
|
||||
|
||||
SpearheadEvents.AddOnPlayerEnterUnitListener(singleton)
|
||||
|
||||
---@param selfA SupplyUnitsTracker
|
||||
@@ -78,29 +80,30 @@ function SupplyUnitsTracker:OnPlayerEntersUnit(unit)
|
||||
if self:IsSupplyUnit(unit) == true then
|
||||
self._supplyUnitsByName[unit:getName()] = unit
|
||||
self._cargoInUnits[tostring(unit:getID())] = nil
|
||||
self._unitInSupplyHub[tostring(unit:getID())] = false
|
||||
self._unitPositions[tostring(unit:getID())] = unit:getPoint()
|
||||
end
|
||||
|
||||
for _, listener in pairs(self._supplyUnitSpawnedListener) do
|
||||
for _, listener in pairs(self._supplyUnitEventsListeners) do
|
||||
pcall(function()
|
||||
listener:SupplyUnitSpawned(unit)
|
||||
if listener.supplyUnitSpawned then
|
||||
listener:supplyUnitSpawned(unit)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
---@class SupplyUnitSpawnedListener
|
||||
---@field SupplyUnitSpawned fun(self:SupplyUnitSpawnedListener, unit:Unit)
|
||||
|
||||
---@param listener SupplyUnitSpawnedListener
|
||||
---@param listener SupplyUnitEventListener
|
||||
function SupplyUnitsTracker:AddOnSupplyUnitSpawnedListener(listener)
|
||||
if listener == nil then return end
|
||||
|
||||
if self._supplyUnitSpawnedListener == nil then
|
||||
self._supplyUnitSpawnedListener = {}
|
||||
if self._supplyUnitEventsListeners == nil then
|
||||
self._supplyUnitEventsListeners = {}
|
||||
end
|
||||
|
||||
table.insert(self._supplyUnitSpawnedListener, listener)
|
||||
table.insert(self._supplyUnitEventsListeners, listener)
|
||||
end
|
||||
|
||||
function SupplyUnitsTracker:Update()
|
||||
@@ -150,6 +153,7 @@ function SupplyUnitsTracker:AddCargoToUnit(unitID, crateType)
|
||||
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param unitID number
|
||||
---@param crateType CrateType
|
||||
function SupplyUnitsTracker:RemoveCargoFromUnit(unitID, crateType)
|
||||
@@ -176,6 +180,7 @@ function SupplyUnitsTracker:RemoveCargoFromUnit(unitID, crateType)
|
||||
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param unit Unit
|
||||
function SupplyUnitsTracker:UpdateWeightForUnit(unit)
|
||||
|
||||
@@ -206,9 +211,29 @@ function SupplyUnitsTracker:CheckUnitsInZones()
|
||||
local zone = hub:GetZone()
|
||||
if zone ~= nil then
|
||||
if Util.is3dPointInZone(pos, zone) then
|
||||
self._commandsHelper:MarkUnitInSupplyHub(group:getID())
|
||||
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
|
||||
listener:enteredSupplyHub(unit, hub)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
self._commandsHelper:MarkUnitOutsideSupplyHub(group:getID())
|
||||
if self._unitInSupplyHub[tostring(unit:getID())] == true then
|
||||
self._unitInSupplyHub[tostring(unit:getID())] = false
|
||||
for _, listener in pairs(self._supplyUnitEventsListeners) do
|
||||
pcall(function()
|
||||
if listener.exitedSupplyHub then
|
||||
listener:exitedSupplyHub(unit, hub)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -245,7 +270,12 @@ function SupplyUnitsTracker:GetUnits()
|
||||
end
|
||||
|
||||
local cargoCount = 0
|
||||
function SupplyUnitsTracker:UnloadRequested(unitID, crateType)
|
||||
|
||||
---comment
|
||||
---@param unitID number
|
||||
---@param crateType CrateType
|
||||
---@param missionCommandsHelper MissionCommandsHelper
|
||||
function SupplyUnitsTracker:UnloadRequested(unitID, crateType, missionCommandsHelper)
|
||||
|
||||
self._logger:debug("Unload requested for unit: " .. unitID .. " crateType: " .. crateType)
|
||||
|
||||
@@ -278,7 +308,7 @@ function SupplyUnitsTracker:UnloadRequested(unitID, crateType)
|
||||
|
||||
local spawned = coalition.addStaticObject(unit:getCoalition(), cargoSpawnObject)
|
||||
self._droppedCrates[cargoSpawnObject.name] = spawned
|
||||
self._commandsHelper:updateCommandsForGroup(group:getID())
|
||||
missionCommandsHelper:updateCommandsForGroup(group:getID())
|
||||
end
|
||||
|
||||
---@return table<string,StaticObject>
|
||||
@@ -289,7 +319,8 @@ end
|
||||
---Loads a crate directly into the unit
|
||||
---@param groupID number
|
||||
---@param crateType CrateType
|
||||
function SupplyUnitsTracker:UnitRequestCrateLoading(groupID, crateType)
|
||||
---@param missionCommandsHelper MissionCommandsHelper
|
||||
function SupplyUnitsTracker:UnitRequestCrateLoading(groupID, crateType, missionCommandsHelper)
|
||||
|
||||
self._logger:debug("UnitRequestCrateLoading called with groupID: " .. groupID .. " and crateType: " .. crateType)
|
||||
|
||||
@@ -320,11 +351,12 @@ function SupplyUnitsTracker:UnitRequestCrateLoading(groupID, crateType)
|
||||
---@field unit Unit
|
||||
---@field groupID number
|
||||
---@field crateType CrateType
|
||||
---@field commandHelper MissionCommandsHelper
|
||||
|
||||
---@param params LoadCargoParams
|
||||
local LoadCrateTask = function(params)
|
||||
|
||||
local loaded = params.self:TryLoadCrateInUnit(params.unit, params.crateType)
|
||||
local loaded = params.self:TryLoadCrateInUnit(params.unit, params.crateType, params.commandHelper)
|
||||
if loaded ~= false then
|
||||
trigger.action.outTextForUnit(unit:getID(), "Loaded crate :" .. params.crateType, 10)
|
||||
end
|
||||
@@ -335,7 +367,8 @@ function SupplyUnitsTracker:UnitRequestCrateLoading(groupID, crateType)
|
||||
self = self,
|
||||
unit = unit,
|
||||
crateType = crateType,
|
||||
groupID = groupID
|
||||
groupID = groupID,
|
||||
commandHelper = missionCommandsHelper
|
||||
}
|
||||
|
||||
timer.scheduleFunction(LoadCrateTask, params, timer.getTime() + 15)
|
||||
@@ -346,8 +379,9 @@ end
|
||||
---comment
|
||||
---@param unit Unit
|
||||
---@param crateType CrateType
|
||||
---@param commandHelper MissionCommandsHelper
|
||||
---@return boolean
|
||||
function SupplyUnitsTracker:TryLoadCrateInUnit(unit, crateType)
|
||||
function SupplyUnitsTracker:TryLoadCrateInUnit(unit, crateType, commandHelper)
|
||||
|
||||
local crateConfigA = SupplyConfigHelper.getSupplyConfig(crateType)
|
||||
if crateConfigA == nil then
|
||||
@@ -381,7 +415,7 @@ function SupplyUnitsTracker:TryLoadCrateInUnit(unit, crateType)
|
||||
local group = unit:getGroup()
|
||||
if group == nil then return false end
|
||||
local groupID = group:getID()
|
||||
self._commandsHelper:updateCommandsForGroup(groupID)
|
||||
commandHelper:updateCommandsForGroup(groupID)
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -412,19 +446,19 @@ end
|
||||
function SupplyUnitsTracker:GetCargoPlacePosition(unit)
|
||||
|
||||
local pos = unit:getPosition()
|
||||
local preferedPos = {
|
||||
local preferredPos = {
|
||||
x = pos.p.x - 10 * pos.x.x,
|
||||
y = pos.p.y - 10 * pos.x.y,
|
||||
z = pos.p.z - 10 * pos.x.z
|
||||
}
|
||||
|
||||
return preferedPos
|
||||
return preferredPos
|
||||
|
||||
|
||||
-- local volume = {
|
||||
-- id = world.VolumeType.SPHERE,
|
||||
-- params = {
|
||||
-- point = preferedPos,
|
||||
-- point = preferredPos,
|
||||
-- radius = 10
|
||||
-- }
|
||||
-- }
|
||||
|
||||
@@ -6,7 +6,7 @@ local MissionCommandsHelper = require("classes.stageClasses.helpers.MissionComma
|
||||
local GlobalConfig = require("classes.configuration.GlobalConfig")
|
||||
local SupplyConfigHelper = require("classes.stageClasses.helpers.SupplyConfigHelper")
|
||||
|
||||
---@class BuildableMission : Mission, SupplyUnitSpawnedListener
|
||||
---@class BuildableMission : Mission, SupplyUnitEventListener
|
||||
---@field private _requiredKilos number
|
||||
---@field private _droppedKilos number
|
||||
---@field private _crateType SupplyType
|
||||
|
||||
Reference in New Issue
Block a user