- 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
Binary file not shown.
+3 -4
View File
@@ -58,7 +58,7 @@ do
[BAirboss.CarrierType.FORRESTAL] = { [BAirboss.CarrierType.FORRESTAL] = {
Morse = 'FRS', Morse = 'FRS',
ATC = RadioManager.RegisterChannel(269000000,RadioManager.RadioTypes.Carrier), ATC = RadioManager.RegisterChannel(269000000,RadioManager.RadioTypes.Carrier,'CVN 59'),
-- ATC = 269000000, -- ATC = 269000000,
MarshalRadio = nil, MarshalRadio = nil,
@@ -80,7 +80,7 @@ do
[BAirboss.CarrierType.ROOSEVELT] = { [BAirboss.CarrierType.ROOSEVELT] = {
Morse = 'RSV', Morse = 'RSV',
ATC = RadioManager.RegisterChannel(261000000,RadioManager.RadioTypes.Carrier), ATC = RadioManager.RegisterChannel(261000000,RadioManager.RadioTypes.Carrier,'CVN 71'),
-- ATC = 261000000, -- ATC = 261000000,
MarshalRadio = nil, MarshalRadio = nil,
@@ -102,8 +102,7 @@ do
[BAirboss.CarrierType.STENNIS] = { [BAirboss.CarrierType.STENNIS] = {
Morse = 'STN', Morse = 'STN',
ATC = RadioManager.RegisterChannel(264000000), ATC = RadioManager.RegisterChannel(264000000,RadioManager.RadioTypes.Carrier,'CVN 74'),
-- ATC = RadioManager.RegisterChannel(264000000,RadioManager.RadioTypes.Carrier),
-- ATC = 264000000, -- ATC = 264000000,
MarshalRadio = nil, MarshalRadio = nil,
+13 -3
View File
@@ -5,14 +5,24 @@ Localizations = {
["en"] = { ["en"] = {
["ERROR: Carrier unit %s is not found in mission."] = "ERROR: Carrier unit %s is not found in mission.", ["ERROR: Carrier unit %s is not found in mission."] = "ERROR: Carrier unit %s is not found in mission.",
["world"] = "World", ["world"] = "World",
["welcome"] = "Welcome" ["welcome"] = "Welcome",
['Raion Info: '] = 'Raion Info: ',
['GCI'] = 'GCI',
['Tanker'] = 'Refuling tanker',
['JTAC'] = 'JTAC',
['Carrier'] = 'Carrier',
}, },
--中文 --中文
["zh"] = { ["cn"] = {
["ERROR: Carrier unit %s is not found in mission."] = "错误: 在任务中没有找到航母单位 %s .", ["ERROR: Carrier unit %s is not found in mission."] = "错误: 在任务中没有找到航母单位 %s .",
["world"] = "世界", ["world"] = "世界",
["welcome"] = "欢迎" ["welcome"] = "欢迎",
['Raion Info: '] = "无线电信息: ",
['GCI'] = 'GCI',
['Tanker'] = '空中加油机',
['JTAC'] = 'JTAC',
['Carrier'] = '航母',
} }
} }
+97 -19
View File
@@ -1,4 +1,6 @@
RadioManager = { RadioManager = {
drawMarkID = Utils.getMarkID(),
ChannelList = {}, ChannelList = {},
ChannelInterval = 0.025, ChannelInterval = 0.025,
@@ -53,8 +55,10 @@ do
i = math.floor(i*1000+0.5)/1000 i = math.floor(i*1000+0.5)/1000
local isPublic = false local isPublic = false
local UserCallsign = nil
if i==RadioManager.DefaultPublic.UHF then if i==RadioManager.DefaultPublic.UHF then
isPublic = true isPublic = true
UserCallsign = {}
end end
local special = false local special = false
@@ -67,6 +71,7 @@ do
RadioManager.ChannelList[i] = { RadioManager.ChannelList[i] = {
used = false, used = false,
isPublic = isPublic, isPublic = isPublic,
UserCallsign = UserCallsign,
special = special, special = special,
} }
end end
@@ -75,8 +80,10 @@ do
i = math.floor(i*1000+0.5)/1000 i = math.floor(i*1000+0.5)/1000
local isPublic = false local isPublic = false
local UserCallsign = nil
if i==RadioManager.DefaultPublic.VHF then if i==RadioManager.DefaultPublic.VHF then
isPublic = true isPublic = true
UserCallsign = {}
end end
local special = false local special = false
@@ -89,12 +96,13 @@ do
RadioManager.ChannelList[i] = { RadioManager.ChannelList[i] = {
used = false, used = false,
isPublic = isPublic, isPublic = isPublic,
UserCallsign = UserCallsign,
special = special, special = special,
} }
end end
-- Register function. -- Register function.
function RadioManager.RegisterChannel(channel,radioType) function RadioManager.RegisterChannel(channel,radioType,UserCallsign)
if not channel then return end if not channel then return end
if channel < 0 then return RadioManager.RubbishChannel*Mhz end if channel < 0 then return RadioManager.RubbishChannel*Mhz end
@@ -113,32 +121,41 @@ do
-- 如果申请频道不在UHF 和 VHF 范围之内, 则分配为默认公开频道. -- 如果申请频道不在UHF 和 VHF 范围之内, 则分配为默认公开频道.
if type(RadioManager.ChannelList[channel]) ~= 'table' then if type(RadioManager.ChannelList[channel]) ~= 'table' then
channel = RadioManager.DefaultPublic[channelType] channel = RadioManager.DefaultPublic[channelType]
if radioType then
RadioManager.ChannelList[channel].used = true channel = RadioManager.SpecialRadioRange[radioType].min
end
end end
-- 如果申请频道在 UHF 或 VHF 范围之内. -- 如果申请频道在 UHF 或 VHF 范围之内.
local assignedChannel = channel local assignedChannel = channel
if RadioManager.ChannelList[channel] then 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 RadioManager.ChannelList[channel].used then -- 如果频道无占用
if not status.isPublic then -- 如果频道非公开且被占用 local isSpecial = RadioManager.ChannelList[channel].special or 'none'
local range = RadioManager.SpecialRadioRange[radioType] or RadioManager[channelType] 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 status = RadioManager.ChannelList[i]
local isSpecial = status.special or 'none'
Utils.Debug('channel: '..channel) if not status.used then
Utils.Debug('isSpecial: '..isSpecial) local isSpecial = status.special or 'none'
Utils.Debug('radioType: '..radioType)
if isSpecial == radioType then if isSpecial == radioType then
assignedChannel = i assignedChannel = i
break break
end
end end
end end
end end
end end
@@ -147,11 +164,72 @@ do
assignedChannel = assignedChannel or RadioManager.DefaultPublic[channelType] assignedChannel = assignedChannel or RadioManager.DefaultPublic[channelType]
RadioManager.ChannelList[assignedChannel].used = true 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 return assignedChannel*Mhz
end 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 end
+22 -1
View File
@@ -1,6 +1,27 @@
Utils = {} Utils = {
MapMarkIDs = {
[1] = true,
},
}
do do
function Utils.getMarkID()
local result = nil
for i,value in ipairs(Utils.MapMarkIDs) do
if value then
result = i
end
end
if result == nil then
result = #Utils.MapMarkIDs + 1
Utils.MapMarkIDs[result] = false
end
return result
end
function Utils.Debug(text,displayTime,clearview) function Utils.Debug(text,displayTime,clearview)
if not text then text = 'nil or false' end if not text then text = 'nil or false' end