mirror of
https://github.com/ciribob/DCS-CTLD.git
synced 2025-08-15 06:17:22 +00:00
Merge pull request #129 from ciribob/bugfix/BF-2025.01.04
## Bugfix/BF-2025.01.04 - removed unneeded tracing in ctld.i18n_translate() - bug: corrected listNearbyCrates() method not returning anything - bug: corrected ctld.dropSlingCrate() method crashing before unloading a crate - bug: corrected the way we handle dynamic slots; it used to cause random CTDs
This commit is contained in:
commit
adc9aa110b
121
CTLD.lua
121
CTLD.lua
@ -35,7 +35,7 @@ ctld = {} -- DONT REMOVE!
|
||||
ctld.Id = "CTLD - "
|
||||
|
||||
--- Version.
|
||||
ctld.Version = "1.2.1"
|
||||
ctld.Version = "1.2.2"
|
||||
|
||||
-- To add debugging messages to dcs.log, change the following log levels to `true`; `Debug` is less detailed than `Trace`
|
||||
ctld.Debug = false
|
||||
@ -814,77 +814,8 @@ ctld.i18n["es"]["Reset TGT Selection"] = "Restablecer selección TGT"
|
||||
---@param ... any (list) The parameters to replace in the text, in order (all paremeters will be converted to string)
|
||||
---@return string the translated and formatted text
|
||||
function ctld.i18n_translate(text, ...)
|
||||
local function p(o, level)
|
||||
local MAX_LEVEL = 20
|
||||
if level == nil then level = 0 end
|
||||
if level > MAX_LEVEL then
|
||||
return ""
|
||||
end
|
||||
local text = ""
|
||||
if (type(o) == "table") then
|
||||
text = "\n"
|
||||
for key,value in pairs(o) do
|
||||
for i=0, level do
|
||||
text = text .. " "
|
||||
end
|
||||
text = text .. ".".. key.."="..p(value, level+1) .. "\n"
|
||||
end
|
||||
elseif (type(o) == "function") then
|
||||
text = "[function]"
|
||||
elseif (type(o) == "boolean") then
|
||||
if o == true then
|
||||
text = "[true]"
|
||||
else
|
||||
text = "[false]"
|
||||
end
|
||||
else
|
||||
if o == nil then
|
||||
text = "[nil]"
|
||||
else
|
||||
text = tostring(o)
|
||||
end
|
||||
end
|
||||
return text
|
||||
end
|
||||
local function formatText(text, ...)
|
||||
if not text then
|
||||
return ""
|
||||
end
|
||||
if type(text) ~= 'string' then
|
||||
text = p(text)
|
||||
else
|
||||
local args = ...
|
||||
if args and args.n and args.n > 0 then
|
||||
local pArgs = {}
|
||||
for i=1,args.n do
|
||||
pArgs[i] = p(args[i])
|
||||
end
|
||||
text = text:format(unpack(pArgs))
|
||||
end
|
||||
end
|
||||
local fName = nil
|
||||
local cLine = nil
|
||||
if debug and debug.getinfo then
|
||||
local dInfo = debug.getinfo(3)
|
||||
fName = dInfo.name
|
||||
cLine = dInfo.currentline
|
||||
end
|
||||
if fName and cLine then
|
||||
return fName .. '|' .. cLine .. ': ' .. text
|
||||
elseif cLine then
|
||||
return cLine .. ': ' .. text
|
||||
else
|
||||
return ' ' .. text
|
||||
end
|
||||
end
|
||||
local function logTrace(message, ...)
|
||||
message = formatText(message, arg)
|
||||
env.info(" T - " .. ctld.Id .. message)
|
||||
end
|
||||
|
||||
logTrace("ctld.i18n_translate(lang=%s, text=%s", p(ctld.i18n_lang), p(text))
|
||||
local _text = ctld.i18n[ctld.i18n_lang][text]
|
||||
logTrace("_text=%s", p(_text))
|
||||
|
||||
-- default to english
|
||||
if _text == nil then
|
||||
@ -899,14 +830,13 @@ function ctld.i18n_translate(text, ...)
|
||||
if arg and arg.n and arg.n > 0 then
|
||||
local _args = {}
|
||||
for i=1,arg.n do
|
||||
_args[i] = p(arg[i])
|
||||
_args[i] = tostring(arg[i]) or ""
|
||||
end
|
||||
for i = 1, #_args do
|
||||
_text = string.gsub(_text, "%%" .. i, _args[i])
|
||||
end
|
||||
end
|
||||
|
||||
logTrace("returning %s", p(_text))
|
||||
return _text
|
||||
end
|
||||
|
||||
@ -4038,7 +3968,7 @@ function ctld.listNearbyCrates(_args)
|
||||
local _txt = ctld.i18n_translate("No Nearby Crates")
|
||||
if _message ~= "" or _fobMsg ~= "" then
|
||||
|
||||
local _txt = ""
|
||||
_txt = ""
|
||||
|
||||
if _message ~= "" then
|
||||
_txt = ctld.i18n_translate("Nearby Crates:\n%1", _message)
|
||||
@ -4500,8 +4430,14 @@ function ctld.dropSlingCrate(_args)
|
||||
local _heightDiff = ctld.heightDiff(_heli)
|
||||
|
||||
if ctld.inAir(_heli) == false or _heightDiff <= 7.5 then
|
||||
ctld.displayMessageToGroup(_heli, ctld.i18n_translate("%1 crate has been safely unhooked and is at your %2 o'clock", _currentCrate.desc, ctld.getClockDirection(_heli, _currentCrate.crateUnit)), 10)
|
||||
_point = ctld.getPointAt12Oclock(_heli, 30)
|
||||
local _position = "12"
|
||||
|
||||
if ctld.unitDynamicCargoCapable(_heli) then
|
||||
_point = ctld.getPointAt6Oclock(_heli, 15)
|
||||
_position = "6"
|
||||
end
|
||||
ctld.displayMessageToGroup(_heli, ctld.i18n_translate("%1 crate has been safely unhooked and is at your %2 o'clock", _currentCrate.desc, _position), 10)
|
||||
elseif _heightDiff > 7.5 and _heightDiff <= 40.0 then
|
||||
ctld.displayMessageToGroup(_heli, ctld.i18n_translate("%1 crate has been safely dropped below you", _currentCrate.desc), 10)
|
||||
else -- _heightDiff > 40.0, destroy crate
|
||||
@ -8207,40 +8143,47 @@ end
|
||||
--- Handle world events.
|
||||
ctld.eventHandler = {}
|
||||
function ctld.eventHandler:onEvent(event)
|
||||
ctld.logTrace("ctld.eventHandler:onEvent(), event = %s", ctld.p(event))
|
||||
ctld.logTrace("ctld.eventHandler:onEvent()")
|
||||
if event == nil then
|
||||
ctld.logError("Event handler was called with a nil event!")
|
||||
return
|
||||
end
|
||||
|
||||
local eventName = "unknown"
|
||||
-- check that we know the event
|
||||
if event.id ~= 20 then -- S_EVENT_PLAYER_ENTER_UNIT
|
||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
||||
eventName = "S_EVENT_PLAYER_ENTER_UNIT"
|
||||
elseif event.id == world.event.S_EVENT_BIRTH then
|
||||
eventName = "S_EVENT_BIRTH"
|
||||
else
|
||||
ctld.logTrace("Ignoring event %s", ctld.p(event))
|
||||
return
|
||||
end
|
||||
ctld.logDebug("caught event %s: %s", ctld.p(eventName), ctld.p(event))
|
||||
|
||||
-- find the originator unit
|
||||
local unitName = nil
|
||||
if event.initiator ~= nil and event.initiator.getName then
|
||||
unitName = event.initiator:getName()
|
||||
ctld.logDebug("caught event S_EVENT_PLAYER_ENTER_UNIT for unit [%s]", ctld.p(unitName))
|
||||
ctld.logDebug("unitName = [%s]", ctld.p(unitName))
|
||||
end
|
||||
if not unitName then
|
||||
ctld.logWarning("no unitname found in event %s", ctld.p(event))
|
||||
ctld.logInfo("no unitname found in event %s", ctld.p(event))
|
||||
return
|
||||
end
|
||||
|
||||
local nextSteps = coroutine.create(function()
|
||||
ctld.logTrace("in the 'nextSteps' coroutine")
|
||||
local function processHumanPlayer()
|
||||
ctld.logTrace("in the 'processHumanPlayer' function")
|
||||
if mist.DBs.humansByName[unitName] then -- it's a human unit
|
||||
ctld.logDebug("caught event S_EVENT_PLAYER_ENTER_UNIT for human unit [%s]", ctld.p(unitName))
|
||||
ctld.logDebug("caught event %s for human unit [%s]", ctld.p(eventName), ctld.p(unitName))
|
||||
local _unit = Unit.getByName(unitName)
|
||||
if _unit ~= nil then
|
||||
-- assign transport pilot
|
||||
ctld.logTrace("_unit = %s", ctld.p(_unit))
|
||||
|
||||
|
||||
local playerTypeName = _unit:getTypeName()
|
||||
ctld.logTrace("playerTypeName = %s", ctld.p(playerTypeName))
|
||||
|
||||
|
||||
-- Allow units to CTLD by aircraft type and not by pilot name
|
||||
if ctld.addPlayerAircraftByType then
|
||||
for _,aircraftType in pairs(ctld.aircraftTypeTable) do
|
||||
@ -8265,18 +8208,18 @@ function ctld.eventHandler:onEvent(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if not mist.DBs.humansByName[unitName] then
|
||||
-- give a few milliseconds for MiST to handle the BIRTH event too
|
||||
ctld.logTrace("give MiST some time to handle the BIRTH event too")
|
||||
timer.scheduleFunction(function()
|
||||
ctld.logTrace("resuming the 'nextSteps' coroutine in a timer")
|
||||
coroutine.resume(nextSteps)
|
||||
end, nil, timer.getTime() + 0.5)
|
||||
ctld.logTrace("calling the 'processHumanPlayer' function in a timer")
|
||||
processHumanPlayer()
|
||||
end, nil, timer.getTime()+0.5)
|
||||
else
|
||||
ctld.logTrace("resuming the 'nextSteps' coroutine immediately")
|
||||
coroutine.resume(nextSteps)
|
||||
ctld.logTrace("calling the 'processHumanPlayer' function immediately")
|
||||
processHumanPlayer()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
BIN
demo-mission.miz
Normal file
BIN
demo-mission.miz
Normal file
Binary file not shown.
Binary file not shown.
BIN
test-dev-static.miz
Normal file
BIN
test-dev-static.miz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user