Skip to content

Commit

Permalink
radio - sorted the callsigns in the unit based menus
Browse files Browse the repository at this point in the history
spawn - enhancements to the convoy informations
  • Loading branch information
davidp57 committed Oct 27, 2019
1 parent 6d48b12 commit 03eac78
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 42 deletions.
51 changes: 32 additions & 19 deletions src/scripts/veafRadio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ veafRadio.USAGE_ForUnit = 2

--- Humans Units (associative array unitName => unit)
veafRadio.humanUnits = {}
veafRadio.humanGroups = {}

--- This structure contains all the radio menus
veafRadio.radioMenu = {}
Expand Down Expand Up @@ -211,35 +212,34 @@ function veafRadio.refreshRadioSubmenu(parentRadioMenu, radioMenu)

-- build menu for each player group
local alreadyDoneGroups = {}
for unitName, unit in pairs(veafRadio.humanUnits) do
local unitCallsign = unit.callsign

-- add radio command by player unit or group
local parameters = command.parameters
if parameters == nil then
parameters = unitName
else
parameters = { command.parameters }
table.insert(parameters, unitName)
end
local groupId = unit.groupId
if not groupId then
veafRadio.logError("cannot find groupId for unit ".. unitName)
else
for groupId, groupData in pairs(veafRadio.humanGroups) do
for _, callsign in pairs(groupData.callsigns) do
local unitData = groupData.units[callsign]
local unitName = unitData.name

-- add radio command by player unit or group
local parameters = command.parameters
if parameters == nil then
parameters = unitName
else
parameters = { command.parameters }
table.insert(parameters, unitName)
end
local _title = command.title
if command.usage == veafRadio.USAGE_ForUnit then
_title = unitCallsign .. " - " .. command.title
_title = callsign .. " - " .. command.title
end
if alreadyDoneGroups[groupId] == nil or command.usage == veafRadio.USAGE_ForUnit then
veafRadio._addCommand(groupId, _title, radioMenu.dcsRadioMenu, command, parameters, trace)
end
alreadyDoneGroups[groupId] = true
end
end
end
else
veafRadio._addCommand(nil , command.title, radioMenu.dcsRadioMenu, command, command.parameters, trace)
veafRadio._addCommand(nil, command.title, radioMenu.dcsRadioMenu, command, command.parameters, trace)
end
end

-- recurse to create the submenus in the radio menu
for count = 1,#radioMenu.subMenus do
local subMenu = radioMenu.subMenus[count]
Expand Down Expand Up @@ -353,9 +353,22 @@ function veafRadio.buildHumanUnits()
local callsign = unit.callsign
if type(callsign) == "table" then callsign = callsign["name"] end
if type(callsign) == "number" then callsign = "" .. callsign end
veafRadio.humanUnits[unit.unitName] = {name=unit.unitName, groupId=unit.groupId, callsign=callsign}
local unitObject = {name=unit.unitName, groupId=unit.groupId, callsign=callsign}
veafRadio.humanUnits[unit.unitName] = unitObject
if not veafRadio.humanGroups[unit.groupId] then
veafRadio.humanGroups[unit.groupId] = {}
veafRadio.humanGroups[unit.groupId].callsigns = {}
veafRadio.humanGroups[unit.groupId].units = {}
end
table.insert(veafRadio.humanGroups[unit.groupId].callsigns,callsign)
veafRadio.humanGroups[unit.groupId].units[callsign] = unitObject
end
end

-- sort callsigns for each group
for _, groupData in pairs(veafRadio.humanGroups) do
table.sort(groupData.callsigns)
end
end

function veafRadio.radioRefreshWatchdog()
Expand Down
56 changes: 33 additions & 23 deletions src/scripts/veafSpawn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1107,42 +1107,52 @@ function veafSpawn._markClosestConvoyWithSmoke(unitName, markRoute)
trigger.action.smoke(averageGroupPosition, trigger.smokeColor.White)
veaf.outTextForUnit(unitName, closestConvoyName .. " marked with white smoke", 10)
end
else
veaf.outTextForUnit(unitName, "No convoy found", 10)
end
end

function veafSpawn.infoOnAllConvoys(unitName)
veafSpawn.logDebug(string.format("veafSpawn.infoOnAllConvoys(unitName=%s)",unitName))
local text = ""

for name, _ in pairs(veafSpawn.spawnedConvoys) do
local nbVehicles, nbInfantry = veafUnits.countInfantryAndVehicles(name)
if nbVehicles > 0 then
local averageGroupPosition = veaf.getAveragePosition(name)
local lat, lon = coord.LOtoLL(averageGroupPosition)
local llString = mist.tostringLL(lat, lon, 0, true)
text = text .. " - " .. name .. ", " .. nbVehicles .. " vehicles : " .. llString
else
text = text .. " - " .. name .. "has been destroyed"
-- convoy has been dispatched, remove it from the convoys list
veafSpawn.spawnedConvoys[name] = nil

if #veafSpawn.spawnedConvoys == 0 then
veaf.outTextForUnit(unitName, "No convoy found", 10)
else
local text = ""
for name, _ in pairs(veafSpawn.spawnedConvoys) do
local nbVehicles, nbInfantry = veafUnits.countInfantryAndVehicles(name)
if nbVehicles > 0 then
local averageGroupPosition = veaf.getAveragePosition(name)
local lat, lon = coord.LOtoLL(averageGroupPosition)
local llString = mist.tostringLL(lat, lon, 0, true)
text = text .. " - " .. name .. ", " .. nbVehicles .. " vehicles : " .. llString
else
text = text .. " - " .. name .. "has been destroyed"
-- convoy has been dispatched, remove it from the convoys list
veafSpawn.spawnedConvoys[name] = nil
end
end
veaf.outTextForUnit(unitName, text, 30)
end

veaf.outTextForUnit(unitName, text, 30)
end

function veafSpawn.cleanupAllConvoys()
veafSpawn.logDebug("veafSpawn.cleanupAllConvoys()")
for name, _ in pairs(veafSpawn.spawnedConvoys) do
local nbVehicles, nbInfantry = veafUnits.countInfantryAndVehicles(name)
if nbVehicles > 0 then
local group = Group.getByName(name)
if group then
Group.destroy(group)
if #veafSpawn.spawnedConvoys == 0 then
veaf.outTextForUnit(unitName, "No convoy found", 10)
else
for name, _ in pairs(veafSpawn.spawnedConvoys) do
local nbVehicles, nbInfantry = veafUnits.countInfantryAndVehicles(name)
if nbVehicles > 0 then
local group = Group.getByName(name)
if group then
Group.destroy(group)
end
end
-- convoy has been dispatched, remove it from the convoys list
veafSpawn.spawnedConvoys[name] = nil
end
-- convoy has been dispatched, remove it from the convoys list
veafSpawn.spawnedConvoys[name] = nil
veaf.outTextForUnit(unitName, "All convoys cleaned up", 10)
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 03eac78

Please sign in to comment.