RANGE etc

RANGE v2.2.3
- Added relay unit option.

TIMER
- Fixed bug.

Minor other stuff
This commit is contained in:
Frank 2020-09-01 17:30:26 +02:00
parent 848336f8ac
commit 26a935c29c
8 changed files with 431 additions and 371 deletions

View File

@ -561,7 +561,8 @@ do -- COORDINATE
return self
else
--env.info("FF translate with NEW coordinate T="..timer.getTime())
return COORDINATE:New(x, y, z)
local coord=COORDINATE:New(x, y, z)
return coord
end
end
@ -761,7 +762,8 @@ do -- COORDINATE
-- Move the vector to start at the end of A.
vec=UTILS.VecAdd(self, vec)
return self:New(vec.x,vec.y,vec.z)
local coord=COORDINATE:New(vec.x,vec.y,vec.z)
return coord
end
--- Return the 2D distance in meters between the target COORDINATE and the COORDINATE.

View File

@ -38,6 +38,8 @@
--
-- The TIMER class is the little sister of the SCHEDULER class. It does the same thing but is a bit easier to use and has less overhead. It should be sufficient in many cases.
--
-- It provides an easy interface to the DCS [timer.scheduleFunction](https://wiki.hoggitworld.com/view/DCS_func_scheduleFunction).
--
-- # Construction
--
-- A new TIMER is created by the @{#TIMER.New}(*func*, *...*) function
@ -100,6 +102,12 @@ TIMER = {
lid = nil,
}
--- Timer ID.
_TIMERID=0
--- Timer data base.
--_TIMERDB={}
--- TIMER class version.
-- @field #string version
TIMER.version="0.1.0"
@ -125,8 +133,6 @@ function TIMER:New(Function, ...)
-- Inherit BASE.
local self=BASE:Inherit(self, BASE:New()) --#TIMER
self.lid="TIMER | "
-- Function to call.
self.func=Function
@ -136,6 +142,18 @@ function TIMER:New(Function, ...)
-- Number of function calls.
self.ncalls=0
-- Increase counter
_TIMERID=_TIMERID+1
-- Set UID.
self.uid=_TIMERID
-- Log id.
self.lid=string.format("TIMER UID=%d | ", self.uid)
-- Add to DB.
--_TIMERDB[self.uid]=self
return self
end
@ -151,7 +169,7 @@ function TIMER:Start(Tstart, dT, Duration)
local Tnow=timer.getTime()
-- Start time in sec.
self.Tstart=Tstart or Tnow
self.Tstart=Tstart and Tnow+Tstart or Tnow+0.001 -- one millisecond delay if Tstart=nil
-- Set time interval.
self.dT=dT
@ -162,10 +180,10 @@ function TIMER:Start(Tstart, dT, Duration)
end
-- Call DCS timer function.
self.tid=timer.scheduleFunction(TIMER._Function, self, self.Tstart)
self.tid=timer.scheduleFunction(self._Function, self, self.Tstart)
-- Set log id.
self.lid=string.format("TIMER ID=%d | ", self.tid)
self.lid=string.format("TIMER UID=%d/%d | ", self.uid, self.tid)
-- Debug info.
self:T(self.lid..string.format("Starting Timer in %.3f sec, dT=%s, Tstop=%s", self.Tstart-Tnow, tostring(self.dT), tostring(self.Tstop)))
@ -186,8 +204,14 @@ function TIMER:Stop(Delay)
else
if self.tid then
-- Remove timer function.
self:T(self.lid..string.format("Stopping timer by removing timer function after %d calls!", self.ncalls))
timer.removeFunction(self.tid)
-- Remove DB entry.
--_TIMERDB[self.uid]=nil
end
end

View File

@ -93,6 +93,8 @@
-- @field Core.RadioQueue#RADIOQUEUE instructor Instructor radio queue.
-- @field #number rangecontrolfreq Frequency on which the range control transmitts.
-- @field Core.RadioQueue#RADIOQUEUE rangecontrol Range control radio queue.
-- @field #string rangecontrolrelayname Name of relay unit.
-- @field #string instructorrelayname Name of relay unit.
-- @field #string soundpath Path inside miz file where the sound files are located. Default is "Range Soundfiles/".
-- @extends Core.Fsm#FSM
@ -516,7 +518,7 @@ RANGE.MenuF10Root=nil
--- Range script version.
-- @field #string version
RANGE.version="2.2.2"
RANGE.version="2.2.3"
--TODO list:
--TODO: Verbosity level for messages.
@ -770,6 +772,7 @@ function RANGE:onafterStart()
-- Set location where the messages are transmitted from.
self.rangecontrol:SetSenderCoordinate(self.location)
self.rangecontrol:SetSenderUnitName(self.rangecontrolrelayname)
-- Start range control radio queue.
self.rangecontrol:Start(1, 0.1)
@ -794,6 +797,7 @@ function RANGE:onafterStart()
-- Set location where the messages are transmitted from.
self.instructor:SetSenderCoordinate(self.location)
self.instructor:SetSenderUnitName(self.instructorrelayname)
-- Start instructor radio queue.
self.instructor:Start(1, 0.1)
@ -1067,18 +1071,22 @@ end
--- Enable range control and set frequency.
-- @param #RANGE self
-- @param #number frequency Frequency in MHz. Default 256 MHz.
-- @param #string relayunitname Name of the unit used for transmission.
-- @return #RANGE self
function RANGE:SetRangeControl(frequency)
function RANGE:SetRangeControl(frequency, relayunitname)
self.rangecontrolfreq=frequency or 256
self.rangecontrolrelayname=relayunitname
return self
end
--- Enable instructor radio and set frequency.
-- @param #RANGE self
-- @param #number frequency Frequency in MHz. Default 305 MHz.
-- @param #string relayunitname Name of the unit used for transmission.
-- @return #RANGE self
function RANGE:SetInstructorRadio(frequency)
function RANGE:SetInstructorRadio(frequency, relayunitname)
self.instructorfreq=frequency or 305
self.instructorrelayname=relayunitname
return self
end
@ -1908,8 +1916,35 @@ end
-- @param #string To To state.
function RANGE:onafterStatus(From, Event, To)
local fsmstate=self:GetState()
local text=string.format("Range status: %s", fsmstate)
if self.instructor then
local alive="N/A"
if self.instructorrelayname then
local relay=UNIT:FindByName(self.instructorrelayname)
if relay then
alive=tostring(relay:IsAlive())
end
end
text=text..string.format(", Instructor %.3f MHz (Relay=%s alive=%s)", self.instructorfreq, tostring(self.instructorrelayname), alive)
end
if self.rangecontrol then
local alive="N/A"
if self.rangecontrolrelayname then
local relay=UNIT:FindByName(self.rangecontrolrelayname)
if relay then
alive=tostring(relay:IsAlive())
end
end
text=text..string.format(", Control %.3f MHz (Relay=%s alive=%s)", self.rangecontrolfreq, tostring(self.rangecontrolrelayname), alive)
end
-- Check range status.
self:I(self.id..string.format("Range status: %s", self:GetState()))
self:I(self.id..text)
-- Check player status.
self:_CheckPlayers()

View File

@ -1377,7 +1377,7 @@ function AIRBASE:GetRunwayData(magvar, mark)
runway.endpoint=c2
-- Debug info.
self:I(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m i=%d j=%d", self:GetName(), runway.idx, runway.heading, runway.length, i, j))
--self:I(string.format("Airbase %s: Adding runway id=%s, heading=%03d, length=%d m i=%d j=%d", self:GetName(), runway.idx, runway.heading, runway.length, i, j))
-- Debug mark
if mark then

View File

@ -951,7 +951,8 @@ function GROUP:GetVec2()
local Unit=self:GetUnit(1)
if Unit then
return Unit:GetVec2()
local vec2=Unit:GetVec2()
return vec2
end
end
@ -965,7 +966,8 @@ function GROUP:GetVec3()
local unit=self:GetUnit(1)
if unit then
return unit:GetVec3()
local vec3=unit:GetVec3()
return vec3
end
self:E("ERROR: Cannot get Vec3 of group "..tostring(self.GroupName))
@ -996,13 +998,11 @@ end
-- @param Wrapper.Group#GROUP self
-- @return Core.Point#COORDINATE The COORDINATE of the GROUP.
function GROUP:GetCoordinate()
self:F2( self.PositionableName )
local FirstUnit = self:GetUnit(1)
if FirstUnit then
local FirstUnitCoordinate = FirstUnit:GetCoordinate()
self:T3(FirstUnitCoordinate)
return FirstUnitCoordinate
end
@ -1176,7 +1176,7 @@ do -- Is Zone methods
--- Check if any unit of a group is inside a @{Zone}.
-- @param #GROUP self
-- @param Core.Zone#ZONE_BASE Zone The zone to test.
-- @return #boolean Returns true if at least one unit is inside the zone or false if no unit is inside.
-- @return #boolean Returns `true` if *at least one unit* is inside the zone or `false` if *no* unit is inside.
function GROUP:IsInZone( Zone )
if self:IsAlive() then
@ -1184,7 +1184,10 @@ function GROUP:IsInZone( Zone )
for UnitID, UnitData in pairs(self:GetUnits()) do
local Unit = UnitData -- Wrapper.Unit#UNIT
if Zone:IsVec3InZone(Unit:GetVec3()) then
-- Get 2D vector. That's all we need for the zone check.
local vec2=Unit:GetVec2()
if Zone:IsVec2InZone(vec2) then
return true -- At least one unit is in the zone. That is enough.
else
-- This one is not but another could be.

View File

@ -375,8 +375,10 @@ function POSITIONABLE:GetCoordinate()
-- Get the current position.
local PositionableVec3 = self:GetVec3()
local coord=COORDINATE:NewFromVec3(PositionableVec3)
-- Return a new coordiante object.
return COORDINATE:NewFromVec3(PositionableVec3)
return coord
end
@ -420,8 +422,10 @@ function POSITIONABLE:GetOffsetCoordinate(x,y,z)
-- Translate offset vector from map origin to the unit: v=u+a.
local v={x=a.x+u.x, y=a.y+u.y, z=a.z+u.z}
local coord=COORDINATE:NewFromVec3(v)
-- Return the offset coordinate.
return COORDINATE:NewFromVec3(v)
return coord
end
--- Returns a random @{DCS#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission.

View File

@ -258,8 +258,7 @@ end
--- Returns if the unit is activated.
-- @param #UNIT self
-- @return #boolean true if Unit is activated.
-- @return #nil The DCS Unit is not existing or alive.
-- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive.
function UNIT:IsActive()
self:F2( self.UnitName )
@ -279,9 +278,7 @@ end
-- If the Unit is alive and active, true is returned.
-- If the Unit is alive but not active, false is returned.
-- @param #UNIT self
-- @return #boolean true if Unit is alive and active.
-- @return #boolean false if Unit is alive but not active.
-- @return #nil if the Unit is not existing or is not alive.
-- @return #boolean `true` if Unit is alive and active. `false` if Unit is alive but not active. `nil` if the Unit is not existing or is not alive.
function UNIT:IsAlive()
self:F3( self.UnitName )
@ -300,7 +297,6 @@ end
--- Returns the Unit's callsign - the localized string.
-- @param #UNIT self
-- @return #string The Callsign of the Unit.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetCallsign()
self:F2( self.UnitName )
@ -640,8 +636,7 @@ end
--- Returns the unit sensors.
-- @param #UNIT self
-- @return DCS#Unit.Sensors
-- @return #nil The DCS Unit is not existing or alive.
-- @return DCS#Unit.Sensors Table of sensors.
function UNIT:GetSensors()
self:F2( self.UnitName )
@ -661,7 +656,6 @@ end
--- Returns if the unit has sensors of a certain type.
-- @param #UNIT self
-- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:HasSensors( ... )
self:F2( arg )
@ -678,7 +672,6 @@ end
--- Returns if the unit is SEADable.
-- @param #UNIT self
-- @return #boolean returns true if the unit is SEADable.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:HasSEAD()
self:F2()
@ -705,7 +698,6 @@ end
-- @param #UNIT self
-- @return #boolean Indicates if at least one of the unit's radar(s) is on.
-- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
-- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetRadar()
self:F2( self.UnitName )