RadioManager = { 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 if i==RadioManager.DefaultPublic.UHF then isPublic = true 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, 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 if i==RadioManager.DefaultPublic.VHF then isPublic = true 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, special = special, } end -- Register function. function RadioManager.RegisterChannel(channel,radioType) 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] RadioManager.ChannelList[channel].used = true end -- 如果申请频道在 UHF 或 VHF 范围之内. local assignedChannel = channel if RadioManager.ChannelList[channel] then local status = RadioManager.ChannelList[channel] if status.used then -- 如果频道被占用 if not status.isPublic then -- 如果频道非公开且被占用 local range = RadioManager.SpecialRadioRange[radioType] or RadioManager[channelType] for i=range.min,range.max,RadioManager.ChannelInterval do if not status.used then local isSpecial = status.special or 'none' Utils.Debug('channel: '..channel) Utils.Debug('isSpecial: '..isSpecial) Utils.Debug('radioType: '..radioType) if isSpecial == radioType then assignedChannel = i break end end end end end end assignedChannel = assignedChannel or RadioManager.DefaultPublic[channelType] RadioManager.ChannelList[assignedChannel].used = true return assignedChannel*Mhz end end