- Finish base functions of 'RadioManager.lua'.

- TODO fix logic bug at line 120-145.
This commit is contained in:
2024-12-23 21:45:13 +08:00
parent 5655f931ea
commit ba3bd8f516
5 changed files with 176 additions and 14 deletions
Binary file not shown.
+7 -3
View File
@@ -58,7 +58,8 @@ do
[BAirboss.CarrierType.FORRESTAL] = {
Morse = 'FRS',
ATC = 269000000,
ATC = RadioManager.RegisterChannel(269000000,RadioManager.RadioTypes.Carrier),
-- ATC = 269000000,
MarshalRadio = nil,
LSORadio = nil,
@@ -79,7 +80,8 @@ do
[BAirboss.CarrierType.ROOSEVELT] = {
Morse = 'RSV',
ATC = 261000000,
ATC = RadioManager.RegisterChannel(261000000,RadioManager.RadioTypes.Carrier),
-- ATC = 261000000,
MarshalRadio = nil,
LSORadio = nil,
@@ -100,7 +102,9 @@ do
[BAirboss.CarrierType.STENNIS] = {
Morse = 'STN',
ATC = 264000000,
ATC = RadioManager.RegisterChannel(264000000),
-- ATC = RadioManager.RegisterChannel(264000000,RadioManager.RadioTypes.Carrier),
-- ATC = 264000000,
MarshalRadio = nil,
LSORadio = nil,
+1
View File
@@ -7,6 +7,7 @@ local script_list =
'Localizations.lua',
'Utils.lua',
-- "spawnListener.lua",
"RadioManager.lua",
"Buta's_Airboss.lua",
-- "Airboss[CN].lua",
}
+144 -11
View File
@@ -1,20 +1,153 @@
RadioManager = {}
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
RadioManager.RadioList = {}
local Mhz = 1000000
RadioManager.UHF = {
min = 200000000,
max = 399975000,
}
-- 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
RadioManager.VHF = {
min = 30000000,
max = 159975000,
}
local special = false
for specialType, range in pairs(RadioManager.SpecialRadioRange) do
if i >= range.min and i <= range.max then
special = specialType
end
end
function RadioManager:New()
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
+24
View File
@@ -1,6 +1,30 @@
Utils = {}
do
function Utils.Debug(text,displayTime,clearview)
if not text then text = 'nil or false' end
if type(text) ~= 'string' then
if type(text) ~= 'table' then
text = tostring(text)
end
if type(text) == 'table' then
if mist then
text = mist.utils.tableShow(text)
else
text = 'no mist, please use mist to debug a table.'
end
end
end
displayTime = displayTime or 10
clearview = clearview or false
trigger.action.outText(text,displayTime,clearview)
end
--- Creates a deep copy of a object.
-- Usually this object is a table.
-- See also: from http://lua-users.org/wiki/CopyTable