This commit is contained in:
FullGas1
2025-03-29 23:49:50 +01:00
parent eb22f5dc67
commit 6fa12ca46f

View File

@@ -2073,7 +2073,7 @@ function ctld.repackVehicle(_params, t) -- scan rrs table 'repackRequestsStack'
end end
ctld.repackRequestsStack[ii] = nil ctld.repackRequestsStack[ii] = nil
end end
ctld.updateRepackMenu(playerUnitName) -- update the repack menu to process destroyed units --ctld.updateRepackMenu(playerUnitName) -- update the repack menu to process destroyed units
end end
if ctld.enableRepackingVehicles == true then if ctld.enableRepackingVehicles == true then
return t + 3 -- reschedule the function in 3 seconds return t + 3 -- reschedule the function in 3 seconds
@@ -5826,8 +5826,8 @@ function ctld.addTransportF10MenuOptions(_unitName)
missionCommands.addCommandForGroup(_groupId, ctld.i18n_translate("Load / Extract Vehicles"), missionCommands.addCommandForGroup(_groupId, ctld.i18n_translate("Load / Extract Vehicles"),
_vehicleCommandsPath, ctld.loadTroopsFromZone, { _unitName, false, "", true }) _vehicleCommandsPath, ctld.loadTroopsFromZone, { _unitName, false, "", true })
if ctld.vehicleCommandsPath == nil then if ctld.vehicleCommandsPath[_unitName] == nil then
ctld.vehicleCommandsPath = mist.utils.deepCopy(_vehicleCommandsPath) ctld.vehicleCommandsPath[_unitName] = mist.utils.deepCopy(_vehicleCommandsPath)
end end
if ctld.enableRepackingVehicles then if ctld.enableRepackingVehicles then
@@ -6005,26 +6005,26 @@ end
--****************************************************************************************************** --******************************************************************************************************
function ctld.updateRepackMenu(_playerUnitName) function ctld.updateRepackMenu(_playerUnitName)
ctld.logTrace("FG_ ctld.updateRepackMenu._playerUnitName = %s", ctld.p(_playerUnitName))
local playerUnit = ctld.getTransportUnit(_playerUnitName) local playerUnit = ctld.getTransportUnit(_playerUnitName)
if playerUnit then if playerUnit then
local _unitTypename = playerUnit:getTypeName() local _unitTypename = playerUnit:getTypeName()
local _groupId = ctld.getGroupId(playerUnit) local _groupId = ctld.getGroupId(playerUnit)
if ctld.enableRepackingVehicles then if ctld.enableRepackingVehicles then
local repackableVehicles = ctld.getUnitsInRepackRadius(_playerUnitName, local repackableVehicles = ctld.getUnitsInRepackRadius(_playerUnitName, ctld.maximumDistanceRepackableUnitsSearch)
ctld.maximumDistanceRepackableUnitsSearch)
if repackableVehicles then if repackableVehicles then
--ctld.logTrace("FG_ ctld.updateRepackMenu.ctld.vehicleCommandsPath = %s", ctld.p(ctld.vehicleCommandsPath)) ctld.logTrace("FG_ ctld.updateRepackMenu.ctld.vehicleCommandsPath[_playerUnitName] = %s", ctld.p(ctld.vehicleCommandsPath[_playerUnitName]))
local RepackCommandsPath = mist.utils.deepCopy(ctld.vehicleCommandsPath) local RepackCommandsPath = mist.utils.deepCopy(ctld.vehicleCommandsPath[_playerUnitName])
RepackCommandsPath[#RepackCommandsPath + 1] = ctld.i18n_translate("Repack Vehicles") RepackCommandsPath[#RepackCommandsPath + 1] = ctld.i18n_translate("Repack Vehicles")
--ctld.logTrace("FG_ ctld.updateRepackMenu.RepackCommandsPath = %s", ctld.p(RepackCommandsPath)) ctld.logTrace("FG_ ctld.updateRepackMenu.RepackCommandsPath = %s", ctld.p(RepackCommandsPath))
missionCommands.removeItemForGroup(1, RepackCommandsPath) -- remove the old repack menu missionCommands.removeItemForGroup(1, RepackCommandsPath) -- remove the old repack menu
local RepackmenuPath = missionCommands.addSubMenuForGroup(_groupId,ctld.i18n_translate("Repack Vehicles"), ctld.vehicleCommandsPath) local RepackmenuPath = missionCommands.addSubMenuForGroup(_groupId,ctld.i18n_translate("Repack Vehicles"), ctld.vehicleCommandsPath[_playerUnitName])
local menuEntries = {} local menuEntries = {}
for _, _vehicle in pairs(repackableVehicles) do for _, _vehicle in pairs(repackableVehicles) do
table.insert(menuEntries, { table.insert(menuEntries, {
text = ctld.i18n_translate("repack ") .. _vehicle.unit, text = ctld.i18n_translate("repack ") .. _vehicle.unit,
groupId = _groupId, groupId = _groupId,
subMenuPath = RepackCommandsPath, subMenuPath = RepackmenuPath,
menuFunction = ctld.repackVehicleRequest, menuFunction = ctld.repackVehicleRequest,
menuArgsTable = { _vehicle, _playerUnitName } menuArgsTable = { _vehicle, _playerUnitName }
}) })
@@ -6037,26 +6037,27 @@ end
--****************************************************************************************************** --******************************************************************************************************
function ctld.autoUpdateRepackMenu(p, t) -- auto update repack menus for each transport unit function ctld.autoUpdateRepackMenu(p, t) -- auto update repack menus for each transport unit
ctld.logTrace("FG_ ctld.autoUpdateRepackMenu.ctld.transportPilotNames = %s", ctld.p(mist.utils.tableShow(ctld.transportPilotNames))) --ctld.logTrace("FG_ ctld.autoUpdateRepackMenu.ctld.transportPilotNames = %s", ctld.p(mist.utils.tableShow(ctld.transportPilotNames)))
if t == nil then t = timer.getTime() end if t == nil then t = timer.getTime() end
if ctld.enableRepackingVehicles then if ctld.enableRepackingVehicles then
for _, _unitName in pairs(ctld.transportPilotNames) do for _, _unitName in pairs(ctld.transportPilotNames) do
local status, error = pcall( local status, error = pcall(
function() function()
local _unit = ctld.getTransportUnit(_unitName) local _unit = ctld.getTransportUnit(_unitName)
if _unit then if _unit then
-- if transport unit landed => update repack menus -- if transport unit landed => update repack menus
if (ctld.inAir(_unit) == false or (ctld.heightDiff(_unit) <= 0.1 + 3.0 and mist.vec.mag(_unit:getVelocity()) < 0.1)) then if (ctld.inAir(_unit) == false or (ctld.heightDiff(_unit) <= 0.1 + 3.0 and mist.vec.mag(_unit:getVelocity()) < 0.1)) then
local _unitTypename = _unit:getTypeName() local _unitTypename = _unit:getTypeName()
local _groupId = ctld.getGroupId(_unit) local _groupId = ctld.getGroupId(_unit)
if _groupId then if _groupId then
if ctld.addedTo[tostring(_groupId)] ~= nil then if ctld.addedTo[tostring(_groupId)] ~= nil then
ctld.updateRepackMenu(_unitName) ctld.logTrace("FG_ ctld.autoUpdateRepackMenu call ctld.updateRepackMenu ofr = %s", ctld.p(_unitName))
end ctld.updateRepackMenu(_unitName)
end end
end end
end end
end) end
end)
if (not status) then if (not status) then
env.error(string.format("Error in ctld.autoUpdateRepackMenu : %s", error), false) env.error(string.format("Error in ctld.autoUpdateRepackMenu : %s", error), false)
end end
@@ -7893,11 +7894,11 @@ function ctld.initialize()
ctld.extractZones = {} -- stored extract zones ctld.extractZones = {} -- stored extract zones
ctld.missionEditorCargoCrates = {} --crates added by mission editor for triggering cratesinzone ctld.missionEditorCargoCrates = {} -- crates added by mission editor for triggering cratesinzone
ctld.hoverStatus = {} -- tracks status of a helis hover above a crate ctld.hoverStatus = {} -- tracks status of a helis hover above a crate
ctld.callbacks = {} -- function callback ctld.callbacks = {} -- function callback
ctld.vehicleCommandsPath = {} -- memory of F10 c=CTLD menu path bay unitNames
-- Remove intransit troops when heli / cargo plane dies -- Remove intransit troops when heli / cargo plane dies
--ctld.eventHandler = {} --ctld.eventHandler = {}
@@ -8194,8 +8195,7 @@ function ctld.eventHandler:onEvent(event)
local function processHumanPlayer() local function processHumanPlayer()
ctld.logTrace("in the 'processHumanPlayer' function processHumanPlayer()- unitName = %s", ctld.p(unitName)) ctld.logTrace("in the 'processHumanPlayer' function processHumanPlayer()- unitName = %s", ctld.p(unitName))
ctld.logTrace("in the 'processHumanPlayer' function processHumanPlayer()- mist.DBs.humansByName[unitName] = %s", ctld.p(mist.DBs.humansByName[unitName])) --ctld.logTrace("in the 'processHumanPlayer' function processHumanPlayer()- mist.DBs.humansByName[unitName] = %s", ctld.p(mist.DBs.humansByName[unitName]))
ctld.logTrace("in the 'processHumanPlayer' function processHumanPlayer()- mist.DBs.humansByName = %s", ctld.p(mist.DBs.humansByName))
if mist.DBs.humansByName[unitName] then -- it's a human unit if mist.DBs.humansByName[unitName] then -- it's a human unit
ctld.logDebug("caught event %s for human unit [%s]", ctld.p(eventName), ctld.p(unitName)) ctld.logDebug("caught event %s for human unit [%s]", ctld.p(eventName), ctld.p(unitName))
local _unit = Unit.getByName(unitName) local _unit = Unit.getByName(unitName)
@@ -8209,7 +8209,6 @@ function ctld.eventHandler:onEvent(event)
-- Allow units to CTLD by aircraft type and not by pilot name -- Allow units to CTLD by aircraft type and not by pilot name
if ctld.addPlayerAircraftByType then if ctld.addPlayerAircraftByType then
for _, aircraftType in pairs(ctld.aircraftTypeTable) do for _, aircraftType in pairs(ctld.aircraftTypeTable) do
ctld.logTrace("FG_ XXXXXXXXXXXXXXXXXXX aircraftType == playerTypeName XXXXXXXXXXXXXXXXXXXXXXXX %s - %s", ctld.p(aircraftType), ctld.p(playerTypeName))
if aircraftType == playerTypeName and ctld.isValueInIpairTable(ctld.transportPilotNames, unitName) == false then if aircraftType == playerTypeName and ctld.isValueInIpairTable(ctld.transportPilotNames, unitName) == false then
ctld.logTrace("adding by aircraft type, unitName = %s", ctld.p(unitName)) ctld.logTrace("adding by aircraft type, unitName = %s", ctld.p(unitName))
-- add transport unit to the list -- add transport unit to the list