- Fix bug at 'RadioManager.lua'.

- TODO: change function BAirboss:setATC() to fit the usage of RadioManager.RegisterChannel(to request channel, handover the call sign and delete/update/release old channel.)
This commit is contained in:
2024-12-23 23:59:35 +08:00
parent ba3bd8f516
commit 4047499e22
5 changed files with 135 additions and 27 deletions
+97 -19
View File
@@ -1,4 +1,6 @@
RadioManager = {
drawMarkID = Utils.getMarkID(),
ChannelList = {},
ChannelInterval = 0.025,
@@ -53,8 +55,10 @@ 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
@@ -67,6 +71,7 @@ do
RadioManager.ChannelList[i] = {
used = false,
isPublic = isPublic,
UserCallsign = UserCallsign,
special = special,
}
end
@@ -75,8 +80,10 @@ 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
@@ -89,12 +96,13 @@ do
RadioManager.ChannelList[i] = {
used = false,
isPublic = isPublic,
UserCallsign = UserCallsign,
special = special,
}
end
-- Register function.
function RadioManager.RegisterChannel(channel,radioType)
function RadioManager.RegisterChannel(channel,radioType,UserCallsign)
if not channel then return end
if channel < 0 then return RadioManager.RubbishChannel*Mhz end
@@ -113,32 +121,41 @@ do
-- 如果申请频道不在UHF 和 VHF 范围之内, 则分配为默认公开频道.
if type(RadioManager.ChannelList[channel]) ~= 'table' then
channel = RadioManager.DefaultPublic[channelType]
RadioManager.ChannelList[channel].used = true
if radioType then
channel = RadioManager.SpecialRadioRange[radioType].min
end
end
-- 如果申请频道在 UHF 或 VHF 范围之内.
local assignedChannel = channel
if RadioManager.ChannelList[channel] then
local status = RadioManager.ChannelList[channel]
if RadioManager.ChannelList[channel].used then -- 如果频道被占用
assignedChannel = nil
end
if status.used then -- 如果频道被占用
if not status.isPublic then -- 如果频道非公开且被占用
local range = RadioManager.SpecialRadioRange[radioType] or RadioManager[channelType]
if not RadioManager.ChannelList[channel].used then -- 如果频道无占用
local isSpecial = RadioManager.ChannelList[channel].special or 'none'
if isSpecial ~= radioType then
assignedChannel = nil
end
end
for i=range.min,range.max,RadioManager.ChannelInterval do
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
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
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
@@ -147,11 +164,72 @@ do
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