RadioManager = { drawMarkID = Utils.getMarkID(), ChannelList = {}, ChannelInterval = 0.025, DefaultPublic = { ['UHF'] = 251, ['VHF'] = 130, }, RubbishChannel = 159.975, ['UHF'] = { min = 200, max = 399.975, }, ['VHF'] = { min = 30, max = 159.950, }, RadioTypes = { GCI = 'GCI', Tanker = 'Tanker', JTAC = 'JTAC', Carrier = 'Carrier', }, SpecialRadioRange = { ['GCI'] = { min = 250, max = 259, }, ['Tanker'] = { min = 330, max = 339, }, ['JTAC'] = { min = 30, max = 39, }, ['Carrier'] = { min = 260, max = 269, }, }, } do local Mhz = 1000000 -- Init Channel List. for i=RadioManager.UHF.min,RadioManager.UHF.max,RadioManager.ChannelInterval do i = math.floor(i*1000+0.5)/1000 local isPublic = false local UserCallsign = nil if i==RadioManager.DefaultPublic.UHF then isPublic = true UserCallsign = {} end local special = false for specialType, range in pairs(RadioManager.SpecialRadioRange) do if i >= range.min and i <= range.max then special = specialType end end RadioManager.ChannelList[i] = { used = false, isPublic = isPublic, UserCallsign = UserCallsign, special = special, } end for i=RadioManager.VHF.min,RadioManager.VHF.max,RadioManager.ChannelInterval do i = math.floor(i*1000+0.5)/1000 local isPublic = false local UserCallsign = nil if i==RadioManager.DefaultPublic.VHF then isPublic = true UserCallsign = {} end local special = false for specialType, range in pairs(RadioManager.SpecialRadioRange) do if i >= range.min and i <= range.max then special = specialType end end RadioManager.ChannelList[i] = { used = false, isPublic = isPublic, UserCallsign = UserCallsign, special = special, } end -- Register function. function RadioManager.RegisterChannel(channel,radioType,UserCallsign) if not channel then return end if channel < 0 then return RadioManager.RubbishChannel*Mhz end -- Serializer radioType = radioType or 'none' if channel > RadioManager.UHF.max and channel >= Mhz then channel = math.floor(channel/Mhz*1000+0.5)/1000 end local channelType = 'UHF' if channel < RadioManager.UHF.min then channelType = 'VHF' end -- 如果申请频道不在UHF 和 VHF 范围之内, 则分配为默认公开频道. if type(RadioManager.ChannelList[channel]) ~= 'table' then channel = RadioManager.DefaultPublic[channelType] if radioType then channel = RadioManager.SpecialRadioRange[radioType].min end end -- 如果申请频道在 UHF 或 VHF 范围之内. local assignedChannel = channel if RadioManager.ChannelList[channel] then if RadioManager.ChannelList[channel].used then -- 如果频道被占用 assignedChannel = nil end if not RadioManager.ChannelList[channel].used then -- 如果频道无占用 local isSpecial = RadioManager.ChannelList[channel].special or 'none' if isSpecial ~= radioType then assignedChannel = nil end end if assignedChannel == nil then local range = RadioManager.SpecialRadioRange[radioType] or RadioManager[channelType] for i=range.min,range.max,RadioManager.ChannelInterval do i = math.floor(i*1000+0.5)/1000 local status = RadioManager.ChannelList[i] if not status.used then local isSpecial = status.special or 'none' if isSpecial == radioType then assignedChannel = i break end end end end end assignedChannel = assignedChannel or RadioManager.DefaultPublic[channelType] RadioManager.ChannelList[assignedChannel].used = true if not RadioManager.ChannelList[assignedChannel].isPublic then RadioManager.ChannelList[assignedChannel].UserCallsign = UserCallsign end if RadioManager.ChannelList[assignedChannel].isPublic then table.insert(RadioManager.ChannelList[assignedChannel].UserCallsign,UserCallsign) end return assignedChannel*Mhz end function RadioManager:drawMapMessageBox() local drawPoint = { x=-417751.093772, y=1, z=177329.42204673, } local text = Localizations:translate('Raion Info: ','cn') Utils.Debug(RadioManager.ChannelList[264]) for radioType, value in pairs(RadioManager.RadioTypes) do Utils.Debug(value) local result = false for i = RadioManager.SpecialRadioRange[value].min,RadioManager.SpecialRadioRange[value].max,RadioManager.ChannelInterval do i = math.floor(i*1000+0.5)/1000 if RadioManager.ChannelList[i].used then local data = { channel = i, UserCallsign = RadioManager.ChannelList[i].UserCallsign or 'no Callsign' } result = result or {} table.insert(result,data) end end Utils.Debug(result) if result then text = text..'\n'..(Localizations:translate(value,'cn'))..': ' for i,data in ipairs(result) do text = text..'\n'..data.channel..'Mhz: ' local UserCallsign = data.UserCallsign if type(UserCallsign) == 'table' then if #UserCallsign >0 then Utils.Debug(UserCallsign) for i, callsign in ipairs(UserCallsign) do text = text..callsign..' ' end end end if type(UserCallsign) == 'string' then text = text..UserCallsign end end end end trigger.action.textToAll(-1,RadioManager.drawMarkID, drawPoint, {1,1,0,1}, {0,0,0,0.32}, 19 , false, text) end -- timer.scheduleFunction(function () -- RadioManager:drawMapMessageBox() -- end,nil,timer.getTime()+5) end