CSAR and CTLD - use Frequency generation moved to UTILS

CTLD - added option to drop crates anywhere
MANTIS - added state tracker to call Green/Red state change events only once
UTILS - added Marianas NDBs to Frequency generation
This commit is contained in:
Applevangelist 2021-07-15 17:16:25 +02:00
parent 93a8086ff6
commit efe41a5e21
4 changed files with 80 additions and 41 deletions

View File

@ -1136,6 +1136,13 @@ do
-- @return #MANTIS self
function MANTIS:onafterStatus(From,Event,To)
self:T({From, Event, To})
-- Display some states
if self.debug then
self:I(self.lid .. "Status Report")
for _name,_state in pairs(self.SamStateTracker) do
self:I(string.format("Site %s\tStatus %s",_name,_state))
end
end
local interval = self.detectinterval * -1
self:__Status(interval)
return self

View File

@ -214,6 +214,8 @@ CSAR = {
-- @field #number timestamp Timestamp for approach process
--- Updated and sorted list of known NDB beacons (in kHz!) from the available maps.
--[[ Moved to Utils
-- @field #CSAR.SkipFrequencies
CSAR.SkipFrequencies = {
214,274,291.5,295,297.5,
@ -229,6 +231,7 @@ CSAR.SkipFrequencies = {
905,907,920,935,942,950,995,
1000,1025,1030,1050,1065,1116,1175,1182,1210
}
--]]
--- All slot / Limit settings
-- @type CSAR.AircraftType
@ -245,7 +248,7 @@ CSAR.AircraftType["Mi-24V"] = 8
--- CSAR class version.
-- @field #string version
CSAR.version="0.1.8r1"
CSAR.version="0.1.8r2"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- ToDo list
@ -872,7 +875,11 @@ function CSAR:_EventHandler(EventData)
end
if _place:GetCoalition() == self.coalition or _place:GetCoalition() == coalition.side.NEUTRAL then
if self.pilotmustopendoors and not self:_IsLoadingDoorOpen(_event.IniUnitName) then
self:_DisplayMessageToSAR(_unit, "Open the door to let me out!", self.messageTime, true)
else
self:_RescuePilots(_unit)
end
else
self:T(string.format("Airfield %d, Unit %d", _place:GetCoalition(), _unit:GetCoalition()))
end
@ -1113,27 +1120,27 @@ function CSAR:_IsLoadingDoorOpen( unit_name )
local type_name = unit:getTypeName()
if type_name == "Mi-8MT" and unit:getDrawArgumentValue(86) == 1 or unit:getDrawArgumentValue(250) == 1 then
self:I(unit_name .. " Cargo doors are open or cargo door not present")
self:T(unit_name .. " Cargo doors are open or cargo door not present")
ret_val = true
end
if type_name == "Mi-24P" and unit:getDrawArgumentValue(38) == 1 or unit:getDrawArgumentValue(86) == 1 then
self:I(unit_name .. " a side door is open")
self:T(unit_name .. " a side door is open")
ret_val = true
end
if type_name == "UH-1H" and unit:getDrawArgumentValue(43) == 1 or unit:getDrawArgumentValue(44) == 1 then
self:I(unit_name .. " a side door is open ")
self:T(unit_name .. " a side door is open ")
ret_val = true
end
if string.find(type_name, "SA342" ) and unit:getDrawArgumentValue(34) == 1 or unit:getDrawArgumentValue(38) == 1 then
self:I(unit_name .. " front door(s) are open")
self:T(unit_name .. " front door(s) are open")
ret_val = true
end
if ret_val == false then
self:I(unit_name .. " all doors are closed")
self:T(unit_name .. " all doors are closed")
end
return ret_val
@ -1346,9 +1353,13 @@ function CSAR:_ScheduledSARFlight(heliname,groupname)
end
if _dist < 200 and _heliUnit:InAir() == false then
if self.pilotmustopendoors and not self:_IsLoadingDoorOpen(heliname) then
self:_DisplayMessageToSAR(_heliUnit, "Open the door to let me out!", self.messageTime, true)
else
self:_RescuePilots(_heliUnit)
return
end
end
--queue up
self:__Returning(-5,heliname,_woundedGroupName)
@ -1755,11 +1766,13 @@ end
-- @param #CSAR self
function CSAR:_GenerateVHFrequencies()
self:T(self.lid .. " _GenerateVHFrequencies")
local _skipFrequencies = self.SkipFrequencies
--local _skipFrequencies = self.SkipFrequencies
local FreeVHFFrequencies = {}
local UsedVHFFrequencies = {}
--local UsedVHFFrequencies = {}
FreeVHFFrequencies = UTILS.GenerateVHFrequencies()
--[[ moved to UTILS
-- first range
local _start = 200000
while _start < 400000 do
@ -1819,6 +1832,7 @@ function CSAR:_GenerateVHFrequencies()
_start = _start + 50000
end
--]]
self.FreeVHFFrequencies = FreeVHFFrequencies
return self
end

View File

@ -262,6 +262,7 @@ do
--
-- my_ctld.useprefix = true -- (DO NOT SWITCH THIS OFF UNLESS YOU KNOW WHAT YOU ARE DOING!) Adjust **before** starting CTLD. If set to false, *all* choppers of the coalition side will be enabled for CTLD.
-- my_ctld.CrateDistance = 30 -- List and Load crates in this radius only.
-- my_ctld.dropcratesanywhere = false -- Option to allow crates to be dropped anywhere.
-- my_ctld.maximumHoverHeight = 15 -- Hover max this high to load.
-- my_ctld.minimumHoverHeight = 4 -- Hover min this low to load.
-- my_ctld.forcehoverload = true -- Crates (not: troops) can only be loaded while hovering.
@ -516,6 +517,8 @@ CTLD.UnitTypes = {
}
--- Updated and sorted known NDB beacons (in kHz!) from the available maps
--[[ -- Now in UTILS
-- @field #CTLD.SkipFrequencies
CTLD.SkipFrequencies = {
214,274,291.5,295,297.5,
@ -531,10 +534,11 @@ CTLD.SkipFrequencies = {
905,907,920,935,942,950,995,
1000,1025,1030,1050,1065,1116,1175,1182,1210
}
--]]
--- CTLD class version.
-- @field #string version
CTLD.version="0.1.3r2"
CTLD.version="0.1.4r1"
--- Instantiate a new CTLD.
-- @param #CTLD self
@ -643,6 +647,7 @@ function CTLD:New(Coalition, Prefixes, Alias)
self.minimumHoverHeight = 4
self.forcehoverload = true
self.hoverautoloading = true
self.dropcratesanywhere = false -- #1570
self.smokedistance = 2000
self.movetroopstowpzone = true
@ -794,13 +799,15 @@ end
function CTLD:_GenerateUHFrequencies()
self:T(self.lid .. " _GenerateUHFrequencies")
self.FreeUHFFrequencies = {}
self.FreeUHFFrequencies = UTILS.GenerateUHFrequencies()
--[[
local _start = 220000000
while _start < 399000000 do
table.insert(self.FreeUHFFrequencies, _start)
_start = _start + 500000
end
--]]
return self
end
@ -809,7 +816,8 @@ end
function CTLD:_GenerateFMFrequencies()
self:T(self.lid .. " _GenerateFMrequencies")
self.FreeFMFrequencies = {}
self.FreeFMFrequencies = UTILS.GenerateFMFrequencies()
--[[
for _first = 3, 7 do
for _second = 0, 5 do
for _third = 0, 9 do
@ -818,7 +826,7 @@ function CTLD:_GenerateFMFrequencies()
end
end
end
--]]
return self
end
@ -826,6 +834,13 @@ end
-- @param #CTLD self
function CTLD:_GenerateVHFrequencies()
self:T(self.lid .. " _GenerateVHFrequencies")
self.FreeVHFFrequencies = {}
self.UsedVHFFrequencies = {}
self.FreeVHFFrequencies = UTILS.GenerateVHFrequencies()
--[[
local _skipFrequencies = self.SkipFrequencies
self.FreeVHFFrequencies = {}
@ -882,10 +897,11 @@ function CTLD:_GenerateVHFrequencies()
end
_start = _start + 50000
end
--]]
return self
end
--[[ -- unused
--- (Internal) Function to generate valid laser codes.
-- @param #CTLD self
function CTLD:_GenerateLaserCodes()
@ -926,6 +942,8 @@ function CTLD:_ContainsDigit(_number, _numberToFind)
return false
end
--]]
--- (Internal) Event handler function
-- @param #CTLD self
-- @param Core.Event#EVENTDATA EventData
@ -1055,25 +1073,27 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
local drop = drop or false
if not drop then
inzone = self:IsUnitInZone(Unit,CTLD.CargoZoneType.LOAD)
else
if self.dropcratesanywhere then -- #1570
inzone = true
else
inzone = self:IsUnitInZone(Unit,CTLD.CargoZoneType.DROP)
end
end
if not inzone then
self:_SendMessage("You are not close enough to a logistics zone!", 10, false, Group)
--local m = MESSAGE:New("You are not close enough to a logistics zone!",15,"CTLD"):ToGroup(Group)
if not self.debug then return self end
end
-- avoid crate spam
local capabilities = self:_GetUnitCapabilities(Unit) -- #CTLD.UnitCapabilities
--local capabilities = self.UnitTypes[Unit:GetTypeName()] -- #CTLD.UnitCapabilities
local canloadcratesno = capabilities.cratelimit
local loaddist = self.CrateDistance or 30
local nearcrates, numbernearby = self:_FindCratesNearby(Group,Unit,loaddist)
if numbernearby >= canloadcratesno and not drop then
self:_SendMessage("There are enough crates nearby already! Take care of those first!", 10, false, Group)
--local m = MESSAGE:New("There are enough crates nearby already! Take care of those first!",15,"CTLD"):ToGroup(Group)
return self
end
-- spawn crates in front of helicopter
@ -1082,7 +1102,6 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
local number = number or cargotype:GetCratesNeeded() --#number
local cratesneeded = cargotype:GetCratesNeeded() --#number
local cratename = cargotype:GetName()
--self:Tself.lid .. string.format("Crate %s requested", cratename))
local cratetemplate = "Container"-- #string
-- get position and heading of heli
local position = Unit:GetCoordinate()
@ -1130,7 +1149,6 @@ function CTLD:_GetCrates(Group, Unit, Cargo, number, drop)
self:__CratesDropped(1, Group, Unit, droppedcargo)
end
self:_SendMessage(text, 10, false, Group)
--local m = MESSAGE:New(text,15,"CTLD",true):ToGroup(Group)
return self
end
@ -1149,7 +1167,6 @@ function CTLD:_ListCratesNearby( _group, _unit)
for _,_entry in pairs (crates) do
local entry = _entry -- #CTLD_CARGO
local name = entry:GetName() --#string
-- TODO Meaningful sorting/aggregation
local dropped = entry:WasDropped()
if dropped then
text:Add(string.format("Dropped crate for %s",name))
@ -1158,14 +1175,12 @@ function CTLD:_ListCratesNearby( _group, _unit)
end
end
if text:GetCount() == 1 then
text:Add("--------- N O N E ------------")
text:Add(" N O N E")
end
text:Add("------------------------------------------------------------")
self:_SendMessage(text:Text(), 30, true, _group)
--local m = MESSAGE:New(text:Text(),15,"CTLD",true):ToGroup(_group)
else
self:_SendMessage(string.format("No (loadable) crates within %d meters!",finddist), 10, false, _group)
--local m = MESSAGE:New(string.format("No (loadable) crates within %d meters!",finddist),15,"CTLD",true):ToGroup(_group)
end
return self
end
@ -1347,7 +1362,7 @@ function CTLD:_ListCargo(Group, Unit)
report:Add("------------------------------------------------------------")
report:Add(string.format("Troops: %d(%d), Crates: %d(%d)",no_troops,trooplimit,no_crates,cratelimit))
report:Add("------------------------------------------------------------")
report:Add("-- TROOPS --")
report:Add(" -- TROOPS --")
for _,_cargo in pairs(cargotable) do
local cargo = _cargo -- #CTLD_CARGO
local type = cargo:GetType() -- #CTLD_CARGO.Enum
@ -1356,10 +1371,10 @@ function CTLD:_ListCargo(Group, Unit)
end
end
if report:GetCount() == 4 then
report:Add("--------- N O N E ------------")
report:Add(" N O N E")
end
report:Add("------------------------------------------------------------")
report:Add("-- CRATES --")
report:Add(" -- CRATES --")
local cratecount = 0
for _,_cargo in pairs(cargotable) do
local cargo = _cargo -- #CTLD_CARGO
@ -1370,7 +1385,7 @@ function CTLD:_ListCargo(Group, Unit)
end
end
if cratecount == 0 then
report:Add("--------- N O N E ------------")
report:Add(" N O N E")
end
report:Add("------------------------------------------------------------")
local text = report:Text()
@ -1498,6 +1513,8 @@ end
-- @param Wrappe.Unit#UNIT Unit
function CTLD:_UnloadCrates(Group, Unit)
self:T(self.lid .. " _UnloadCrates")
if not self.dropcratesanywhere then -- #1570
-- check if we are in DROP zone
local inzone, zonename, zone, distance = self:IsUnitInZone(Unit,CTLD.CargoZoneType.DROP)
if not inzone then
@ -1507,6 +1524,7 @@ function CTLD:_UnloadCrates(Group, Unit)
return self
end
end
end
-- check for hover unload
local hoverunload = self:IsCorrectHover(Unit) --if true we\'re hovering in parameters
local IsHerc = self:IsHercules(Unit)
@ -2058,7 +2076,7 @@ function CTLD:_ListRadioBeacons(Group, Unit)
end
end
if report:GetCount() == 1 then
report:Add("--------- N O N E ------------")
report:Add(" N O N E")
end
report:Add("------------------------------------------------------------")
self:_SendMessage(report:Text(), 30, true, Group)

View File

@ -1631,10 +1631,10 @@ function UTILS.GenerateVHFrequencies()
local _skipFrequencies = {
214,274,291.5,295,297.5,
300.5,304,307,309.5,311,312,312.5,316,
320,324,328,329,330,336,337,
320,324,328,329,330,332,336,337,
342,343,348,351,352,353,358,
363,365,368,372.5,374,
380,381,384,389,395,396,
380,381,384,385,389,395,396,
414,420,430,432,435,440,450,455,462,470,485,
507,515,520,525,528,540,550,560,570,577,580,
602,625,641,662,670,680,682,690,