diff --git a/Moose_CTLD.lua b/Moose_CTLD.lua index 39b17e6..3ebf3a9 100644 --- a/Moose_CTLD.lua +++ b/Moose_CTLD.lua @@ -7044,7 +7044,7 @@ function CTLD:BuildSpecificAtGroup(group, recipeKey, opts) end -- Current launchers in site - local curLaunchers = (bestInfo.byType[tpl.launcherType] or 0) + local curLaunchers = (bestInfo and bestInfo.byType and bestInfo.byType[tpl.launcherType]) or 0 local maxL = tpl.maxLaunchers or (curLaunchers + cratesAvail) local canAdd = math.max(0, (maxL - curLaunchers)) if canAdd <= 0 then @@ -7083,8 +7083,12 @@ function CTLD:BuildSpecificAtGroup(group, recipeKey, opts) -- Destroy old group, spawn new one local oldName = bestG:getName() local newLauncherCount = curLaunchers + addNum - local center = bestInfo.center - local headingDeg = bestInfo.headingDeg() + local center = bestInfo and bestInfo.center + if not center then + _msgGroup(group, 'Failed to determine SAM site center position.') + return + end + local headingDeg = (bestInfo and bestInfo.headingDeg and bestInfo.headingDeg()) or 0 if Group.getByName(oldName) then pcall(function() Group.getByName(oldName):destroy() end) end local gdata = buildSite({ x = center.x, z = center.z }, headingDeg, tpl.side, newLauncherCount) local newG = _coalitionAddGroup(tpl.side, Group.Category.GROUND, gdata, self.Config) @@ -10699,7 +10703,6 @@ function CTLD:SpawnFARPStatics(zoneName, stage, centerPoint, coalitionId) local serviceVehicles = { ["M978 HEMTT Tanker"] = true, -- Refuel service ["Ural-375 PBU"] = true, -- Fuel support - ["M978 HEMTT Tanker"] = true, -- Additional fuel ["Ural-4320 APA-5D"] = true, -- Ammo truck for rearm ["M1043 HMMWV Armament"] = true, -- Command/coordination ["GAZ-66"] = true, -- Support vehicle @@ -11509,7 +11512,10 @@ function CTLD:_SpawnMEDEVACCrew(eventData, catalogEntry) survivalChance = cfg.CrewSurvivalChance[self.Side] or 0.02 else -- Legacy single value config (backward compatibility) - survivalChance = cfg.CrewSurvivalChance + local chanceValue = cfg.CrewSurvivalChance + if type(chanceValue) == 'number' then + survivalChance = chanceValue + end end end @@ -11637,7 +11643,10 @@ function CTLD:_SpawnMEDEVACCrew(eventData, catalogEntry) manPadChance = cfg.ManPadSpawnChance[selfref.Side] or 0.1 else -- Legacy single value config (backward compatibility) - manPadChance = cfg.ManPadSpawnChance + local chanceValue = cfg.ManPadSpawnChance + if type(chanceValue) == 'number' then + manPadChance = chanceValue + end end end local spawnManPad = math.random() <= manPadChance @@ -13663,7 +13672,7 @@ function CTLD:PopSmokeAtMEDEVACSites(group) end local count = 0 - _logVerbose(string.format('[MEDEVAC] Checking %d crew entries', CTLD._medevacCrews and table.getn(CTLD._medevacCrews) or 0)) + _logVerbose(string.format('[MEDEVAC] Checking %d crew entries', CTLD._medevacCrews and #CTLD._medevacCrews or 0)) for crewGroupName, data in pairs(CTLD._medevacCrews) do if data and data.side == self.Side and data.requestTime and data.position then @@ -14992,7 +15001,7 @@ function CTLD:ShowNearestSalvageCrate(group) end end - if not nearestName then + if not nearestName or not nearestMeta or not nearestMeta.position then local msg = self.Messages.slingload_salvage_no_crates or 'No active salvage crates available.' _msgGroup(group, msg) return diff --git a/Moose_CTLD_FAC.lua b/Moose_CTLD_FAC.lua index 79aeb13..4498b66 100644 --- a/Moose_CTLD_FAC.lua +++ b/Moose_CTLD_FAC.lua @@ -233,7 +233,7 @@ end local function _bearingDeg(from, to) local dx = (to.x - from.x) local dz = (to.z - from.z) - local ang = math.deg(math.atan2(dx, dz)) + local ang = math.deg(math.atan(dx, dz)) if ang < 0 then ang = ang + 360 end return math.floor(ang + 0.5) end @@ -248,12 +248,13 @@ local function _getHeading(unit) -- Approximate true heading using unit orientation + true north correction local pos = unit:getPosition() if pos then - local heading = math.atan2(pos.x.z, pos.x.x) + ---@diagnostic disable-next-line: deprecated + local heading = math.atan(pos.x.z, pos.x.x) -- add true-north correction local p = pos.p local lat, lon = coord.LOtoLL(p) local northPos = coord.LLtoLO(lat + 1, lon) - heading = heading + math.atan2(northPos.z - p.z, northPos.x - p.x) + heading = heading + math.atan(northPos.z - p.z, northPos.x - p.x) if heading < 0 then heading = heading + 2*math.pi end return heading end @@ -1225,8 +1226,11 @@ function FAC:_findNearestEnemy(facUnit, targetType) local d = _distance(up, origin) if d >= best then return end local allowed = true - if targetType == 'vehicle' then allowed = _isVehicle(u) - elseif targetType == 'troop' then allowed = _isInfantry(u) end + if targetType == 'vehicle' then + allowed = _isVehicle(u) and true or false + elseif targetType == 'troop' then + allowed = _isInfantry(u) and true or false + end if not allowed then return end if land.isVisible({x=up.x,y=up.y+2,z=up.z}, {x=origin.x,y=origin.y+2,z=origin.z}) and u:isActive() then best = d; nearest = u @@ -1360,7 +1364,7 @@ function FAC:_scanManualList(group) local p = v:getPoint() local d = _distance(p, origin) local dy, dx = p.z - origin.z, p.x - origin.x - local hdg = math.deg(math.atan2(dx, dy)) + local hdg = math.deg(math.atan(dx, dy)) if hdg < 0 then hdg = hdg + 360 end if gid then trigger.action.outTextForGroup(gid, string.format('Target %d: %s Bearing %d Range %dm/%dft', i, v:getTypeName(), math.floor(hdg+0.5), math.floor(d), math.floor(d*3.28084)), 30) diff --git a/catalogs/Moose_CTLD_Catalog.lua b/catalogs/Moose_CTLD_Catalog.lua index 76fc66b..2ec09ff 100644 --- a/catalogs/Moose_CTLD_Catalog.lua +++ b/catalogs/Moose_CTLD_Catalog.lua @@ -86,7 +86,7 @@ local function multiUnits(units) local function off(dx, dz) return { x = point.x + dx, z = point.z + dz } end local list = {} for i,u in ipairs(units) do - local p = off(u.dx or 0, u.dz or 3*i) + local p = off(u.dx or 0, u.dz or (3*i)) table.insert(list, { type = u.type, name = string.format('CTLD-%s-%d', u.type, math.random(100000,999999)), x = p.x, y = p.z, heading = hdg diff --git a/catalogs/Moose_CTLD_Catalog_LowCounts.lua b/catalogs/Moose_CTLD_Catalog_LowCounts.lua index d5c5fd0..f9b451a 100644 --- a/catalogs/Moose_CTLD_Catalog_LowCounts.lua +++ b/catalogs/Moose_CTLD_Catalog_LowCounts.lua @@ -85,7 +85,7 @@ local function multiUnits(units) local function off(dx, dz) return { x = point.x + dx, z = point.z + dz } end local list = {} for i,u in ipairs(units) do - local p = off(u.dx or 0, u.dz or 3*i) + local p = off(u.dx or 0, u.dz or (3*i)) table.insert(list, { type = u.type, name = string.format('CTLD-%s-%d', u.type, math.random(100000,999999)), x = p.x, y = p.z, heading = hdg