mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Fixed bugs with new option table.
This commit is contained in:
parent
286e34e057
commit
775b9e9fde
@ -1,6 +1,7 @@
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Enums.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Routines.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Utils.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Utilities/Profiler.lua' )
|
||||
|
||||
__Moose.Include( 'Scripts/Moose/Core/Base.lua' )
|
||||
__Moose.Include( 'Scripts/Moose/Core/UserFlag.lua' )
|
||||
|
||||
@ -1392,8 +1392,8 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
|
||||
if self.ai then
|
||||
|
||||
-- Set default ROE and ROT options.
|
||||
self:SetOptionROE(self.roe)
|
||||
self:SetOptionROT(self.rot)
|
||||
self:SwitchROE(self.option.ROE)
|
||||
self:SwitchROT(self.option.ROT)
|
||||
|
||||
-- TODO: make this input.
|
||||
self.group:SetOption(AI.Option.Air.id.PROHIBIT_JETT, true)
|
||||
@ -1402,18 +1402,19 @@ function FLIGHTGROUP:onafterSpawned(From, Event, To)
|
||||
--self.group:SetOption(AI.Option.Air.id.RADAR_USING, AI.Option.Air.val.RADAR_USING.FOR_CONTINUOUS_SEARCH)
|
||||
|
||||
-- Turn TACAN beacon on.
|
||||
if self.tacanChannelDefault then
|
||||
self:SwitchTACANOn(self.tacanChannelDefault, self.tacanMorseDefault)
|
||||
if self.tacanDefault.Channel then
|
||||
self:SwitchTACAN(self.tacanDefault.Channel, self.tacanDefault.Morse)
|
||||
end
|
||||
|
||||
-- Turn on the radio.
|
||||
if self.radioFreqDefault then
|
||||
self:SwitchRadioOn(self.radioFreqDefault, self.radioModuDefault)
|
||||
if self.radioDefault.Freq then
|
||||
self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu)
|
||||
end
|
||||
|
||||
-- Set callsign.
|
||||
if self.callsignNameDefault then
|
||||
if self.callsignDefault.Name then
|
||||
self:SwitchCallsign(self.callsignNameDefault, self.callsignNumberDefault)
|
||||
else
|
||||
end
|
||||
|
||||
-- Update route.
|
||||
@ -2510,36 +2511,28 @@ function FLIGHTGROUP:_InitGroup()
|
||||
|
||||
-- Radio parameters from template.
|
||||
self.radioOn=self.template.communication
|
||||
self.radioFreq=self.template.frequency
|
||||
self.radioModu=self.template.modulation
|
||||
|
||||
-- If not set by the use explicitly yet, we take the template values as defaults.
|
||||
if not self.radioFreqDefault then
|
||||
self.radioFreqDefault=self.radioFreq
|
||||
self.radioModuDefault=self.radioModu
|
||||
end
|
||||
self.radio.Freq=self.template.frequency
|
||||
self.radio.Modu=self.template.modulation
|
||||
self.radioDefault.Freq=self.radio.Freq
|
||||
self.radioDefault.Modu=self.radio.Modu
|
||||
|
||||
-- Set default formation.
|
||||
if not self.formationDefault then
|
||||
if self.ishelo then
|
||||
self.formationDefault=ENUMS.Formation.RotaryWing.EchelonLeft.D300
|
||||
else
|
||||
self.formationDefault=ENUMS.Formation.FixedWing.EchelonLeft.Group
|
||||
end
|
||||
if self.ishelo then
|
||||
self.optionDefault.Formation=ENUMS.Formation.RotaryWing.EchelonLeft.D300
|
||||
else
|
||||
self.optionDefault.Formation=ENUMS.Formation.FixedWing.EchelonLeft.Group
|
||||
end
|
||||
|
||||
-- Is this purely AI?
|
||||
self.ai=not self:_IsHuman(self.group)
|
||||
|
||||
-- Create Menu.
|
||||
if not self.ai then
|
||||
self.menu=self.menu or {}
|
||||
self.menu.atc=self.menu.atc or {}
|
||||
self.menu.atc.root=self.menu.atc.root or MENU_GROUP:New(self.group, "ATC")
|
||||
end
|
||||
|
||||
-- Switch to default formation.
|
||||
-- TODO: Should this be moved to onafterspawned?
|
||||
self:SwitchFormation(self.formationDefault)
|
||||
|
||||
-- Add elemets.
|
||||
for _,unit in pairs(self.group:GetUnits()) do
|
||||
local element=self:AddElementByName(unit:GetName())
|
||||
@ -2573,7 +2566,7 @@ function FLIGHTGROUP:_InitGroup()
|
||||
text=text..string.format("Helicopter = %s\n", tostring(self.group:IsHelicopter()))
|
||||
text=text..string.format("Elements = %d\n", #self.elements)
|
||||
text=text..string.format("Waypoints = %d\n", #self.waypoints)
|
||||
text=text..string.format("Radio = %.1f MHz %s %s\n", self.radioFreq, UTILS.GetModulationName(self.radioModu), tostring(self.radioOn))
|
||||
text=text..string.format("Radio = %.1f MHz %s %s\n", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu), tostring(self.radioOn))
|
||||
text=text..string.format("Ammo = %d (G=%d/R=%d/B=%d/M=%d)\n", self.ammo.Total, self.ammo.Guns, self.ammo.Rockets, self.ammo.Bombs, self.ammo.Missiles)
|
||||
text=text..string.format("FSM state = %s\n", self:GetState())
|
||||
text=text..string.format("Is alive = %s\n", tostring(self.group:IsAlive()))
|
||||
@ -2965,28 +2958,34 @@ end
|
||||
--- Add an AIR waypoint to the flight plan.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param Core.Point#COORDINATE coordinate The coordinate of the waypoint. Use COORDINATE:SetAltitude(altitude) to define the altitude.
|
||||
-- @param #number speed Speed in knots. Default 350 kts.
|
||||
-- @param #number wpnumber Waypoint number. Default at the end.
|
||||
-- @param #boolean updateroute If true or nil, call UpdateRoute. If false, no call.
|
||||
-- @param #number Speed Speed in knots. Default 350 kts.
|
||||
-- @param #number AfterWaypointWithID Insert waypoint after waypoint given ID. Default is to insert as last waypoint.
|
||||
-- @param #boolean Updateroute If true or nil, call UpdateRoute. If false, no call.
|
||||
-- @return Ops.OpsGroup#OPSGROUP.Waypoint Waypoint table.
|
||||
function FLIGHTGROUP:AddWaypoint(coordinate, speed, wpnumber, updateroute)
|
||||
function FLIGHTGROUP:AddWaypoint(Coordinate, Speed, AfterWaypointWithID, Updateroute)
|
||||
|
||||
-- Waypoint number. Default is at the end.
|
||||
wpnumber=wpnumber or #self.waypoints+1
|
||||
-- Set waypoint index.
|
||||
local wpnumber=#self.waypoints+1
|
||||
if wpnumber then
|
||||
local index=self:GetWaypointIndex(AfterWaypointWithID)
|
||||
if index then
|
||||
wpnumber=index+1
|
||||
end
|
||||
end
|
||||
|
||||
if wpnumber>self.currentwp then
|
||||
self.passedfinalwp=false
|
||||
end
|
||||
|
||||
-- Speed in knots.
|
||||
speed=speed or 350
|
||||
Speed=Speed or 350
|
||||
|
||||
-- Speed at waypoint.
|
||||
local speedkmh=UTILS.KnotsToKmph(speed)
|
||||
local speedkmh=UTILS.KnotsToKmph(Speed)
|
||||
|
||||
-- Create air waypoint.
|
||||
local name=string.format("Added Waypoint #%d", wpnumber)
|
||||
local wp=coordinate:WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speedkmh, true, nil, {}, name)
|
||||
local wp=Coordinate:WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speedkmh, true, nil, {}, name)
|
||||
|
||||
-- Create waypoint data table.
|
||||
local waypoint=self:_CreateWaypoint(wp)
|
||||
@ -2995,10 +2994,10 @@ function FLIGHTGROUP:AddWaypoint(coordinate, speed, wpnumber, updateroute)
|
||||
self:_AddWaypoint(waypoint, wpnumber)
|
||||
|
||||
-- Debug info.
|
||||
self:T(self.lid..string.format("Adding AIR waypoint #%d, speed=%.1f knots. Last waypoint passed was #%s. Total waypoints #%d", wpnumber, speed, self.currentwp, #self.waypoints))
|
||||
self:T(self.lid..string.format("Adding AIR waypoint #%d, speed=%.1f knots. Last waypoint passed was #%s. Total waypoints #%d", wpnumber, Speed, self.currentwp, #self.waypoints))
|
||||
|
||||
-- Update route.
|
||||
if updateroute==nil or updateroute==true then
|
||||
if Updateroute==nil or Updateroute==true then
|
||||
self:__UpdateRoute(-1)
|
||||
end
|
||||
|
||||
|
||||
@ -550,8 +550,8 @@ function NAVYGROUP:onafterSpawned(From, Event, To)
|
||||
if self.ai then
|
||||
|
||||
-- Set default ROE and Alarmstate options.
|
||||
self:SetOptionROE(self.roe)
|
||||
self:SetOptionAlarmstate(self.alarmstate)
|
||||
self:SwitchROE(self.option.ROE)
|
||||
self:SwitchAlarmstate(self.option.Alarm)
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -52,8 +52,9 @@
|
||||
-- @field Core.Point#COORDINATE position Position of the group at last status check.
|
||||
-- @field #number traveldist Distance traveled in meters. This is a lower bound!
|
||||
-- @field #number traveltime Time.
|
||||
-- @field #boolean ispathfinding If true, group is on pathfinding route.
|
||||
--
|
||||
-- @field Core.Astar#ASTAR Astar path finding.
|
||||
-- @field #boolean ispathfinding If true, group is on pathfinding route.
|
||||
--
|
||||
-- @field #OPSGROUP.Radio radio Current radio settings.
|
||||
-- @field #OPSGROUP.Radio radioDefault Default radio settings.
|
||||
@ -69,9 +70,10 @@
|
||||
-- @field #boolean iclsOn If true, ICLS is currently active.
|
||||
--
|
||||
-- @field #OPSGROUP.Option option Current optional settings.
|
||||
-- @field #OPSGROUP.Option optionDefault Default option settings.
|
||||
-- @field #OPSGROUP.Option optionDefault Default option settings.
|
||||
--
|
||||
-- @field Core.Astar#ASTAR Astar path finding.
|
||||
-- @field #OPSGROUP.Callsign callsign Current callsign settings.
|
||||
-- @field #OPSGROUP.Callsign callsignDefault Default callsign settings.
|
||||
--
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
@ -2763,7 +2765,7 @@ function OPSGROUP:SwitchROE(roe)
|
||||
|
||||
self.group:OptionROE(self.option.ROE)
|
||||
|
||||
self:I(self.lid..string.format("Setting current ROE=%d (0=WeaponFree, 1=OpenFireWeaponFree, 2=OpenFire, 3=ReturnFire, 4=WeaponHold)", self.roe))
|
||||
self:I(self.lid..string.format("Setting current ROE=%d (0=WeaponFree, 1=OpenFireWeaponFree, 2=OpenFire, 3=ReturnFire, 4=WeaponHold)", self.option.ROE))
|
||||
else
|
||||
-- TODO WARNING
|
||||
end
|
||||
@ -2799,7 +2801,7 @@ function OPSGROUP:SwitchROT(rot)
|
||||
|
||||
self.group:OptionROT(self.option.ROT)
|
||||
|
||||
self:T2(self.lid..string.format("Setting current ROT=%d (0=NoReaction, 1=Passive, 2=Evade, 3=ByPass, 4=AllowAbort)", self.rot))
|
||||
self:T2(self.lid..string.format("Setting current ROT=%d (0=NoReaction, 1=Passive, 2=Evade, 3=ByPass, 4=AllowAbort)", self.option.ROT))
|
||||
else
|
||||
-- TODO WARNING
|
||||
end
|
||||
@ -2880,10 +2882,11 @@ end
|
||||
|
||||
--- Activate TACAN beacon.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #number TACANChannel TACAN Channel.
|
||||
-- @param #string TACANMorse TACAN morse code.
|
||||
-- @param #number Channel TACAN Channel.
|
||||
-- @param #string Morse TACAN morse code.
|
||||
-- @param #string Band TACAN channel mode "X" or "Y". Default is "Y" for aircraft and "X" for ground and naval groups.
|
||||
-- @return #OPSGROUP self
|
||||
function OPSGROUP:SwitchTACAN(TACANChannel, TACANMorse)
|
||||
function OPSGROUP:SwitchTACAN(Channel, Morse, Band)
|
||||
|
||||
if self:IsAlive() then
|
||||
|
||||
@ -2891,21 +2894,36 @@ function OPSGROUP:SwitchTACAN(TACANChannel, TACANMorse)
|
||||
|
||||
if unit and unit:IsAlive() then
|
||||
|
||||
local Type=4
|
||||
local System=5
|
||||
local UnitID=unit:GetID()
|
||||
local TACANMode="Y"
|
||||
local Frequency=UTILS.TACANToFrequency(TACANChannel, TACANMode)
|
||||
|
||||
unit:CommandActivateBeacon(Type, System, Frequency, UnitID, TACANChannel, TACANMode, true, TACANMorse, true)
|
||||
local Type=BEACON.Type.TACAN
|
||||
local System=BEACON.System.TACAN
|
||||
|
||||
--local TACANMode="Y"
|
||||
if self.isAircraft then
|
||||
Type=4
|
||||
System=5
|
||||
Band=Band or "Y"
|
||||
else
|
||||
Band=Band or "X"
|
||||
end
|
||||
|
||||
-- Tacan frequency.
|
||||
local Frequency=UTILS.TACANToFrequency(Channel, Band)
|
||||
|
||||
unit:CommandActivateBeacon(Type, System, Frequency, UnitID, Channel, Band, true, Morse, true)
|
||||
|
||||
self.tacanBeacon=unit
|
||||
self.tacanChannel=TACANChannel
|
||||
self.tacanMorse=TACANMorse
|
||||
|
||||
self.tacan.Channel=Channel
|
||||
self.tacan.Morse=Morse
|
||||
self.tacan.Band=Band
|
||||
self.tacan.UnitName=unit:GetName()
|
||||
|
||||
-- TACAN is now on.
|
||||
self.tacanOn=true
|
||||
|
||||
self:I(self.lid..string.format("Switching TACAN to Channel %dY Morse %s", self.tacanChannel, tostring(self.tacanMorse)))
|
||||
self:I(self.lid..string.format("Switching TACAN to Channel %d%s Morse %s on unit %s", self.tacan.Channel, self.tacan.Band, tostring(self.tacan.Morse), self.tacan.UnitName))
|
||||
|
||||
end
|
||||
|
||||
@ -2963,7 +2981,7 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
|
||||
|
||||
local group=self.group --Wrapper.Group#GROUP
|
||||
|
||||
if not self.radioOn then
|
||||
if self.isAircraft and not self.radioOn then
|
||||
group:SetOption(AI.Option.Air.id.SILENCE, false)
|
||||
end
|
||||
|
||||
@ -2975,7 +2993,7 @@ function OPSGROUP:SwitchRadio(Frequency, Modulation)
|
||||
-- Radio is on.
|
||||
self.radioOn=true
|
||||
|
||||
self:I(self.lid..string.format("Switching radio to frequency %.3f MHz %s", self.radioFreq, UTILS.GetModulationName(self.radioModu)))
|
||||
self:I(self.lid..string.format("Switching radio to frequency %.3f MHz %s", self.radio.Freq, UTILS.GetModulationName(self.radio.Modu)))
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -27,7 +27,8 @@
|
||||
--
|
||||
-- # The PROFILER Concept
|
||||
--
|
||||
-- Profile your lua code.
|
||||
-- Profile your lua code. This tells you, which functions are called very often and which consume most CPU time.
|
||||
-- With this information you could optimize the perfomance of your code.
|
||||
--
|
||||
-- # Prerequisites
|
||||
--
|
||||
@ -56,7 +57,7 @@
|
||||
--
|
||||
-- X:\User\<Your User Name>\Saved Games\DCS OpenBeta\Logs
|
||||
--
|
||||
-- ## Sort By
|
||||
-- ## Sort Output
|
||||
--
|
||||
-- By default the output is sorted with respect to the total time a function used.
|
||||
--
|
||||
@ -64,7 +65,6 @@
|
||||
--
|
||||
-- PROFILER.sortBy=1
|
||||
--
|
||||
-- Lua profiler.
|
||||
-- @field #PROFILER
|
||||
PROFILER = {
|
||||
ClassName = "PROFILER",
|
||||
@ -84,6 +84,7 @@ PROFILER = {
|
||||
PROFILER.sortBy=1 -- Sort reports by 0=Count, 1=Total time by function
|
||||
PROFILER.logUnknown=false -- Log unknown functions
|
||||
PROFILER.lowCpsThres=5 -- Skip results with less than X calls per second
|
||||
PROFILER.fileName="_LuaProfiler.txt"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- Start/Stop Profiler
|
||||
@ -95,9 +96,6 @@ function PROFILER.Start()
|
||||
PROFILER.startTime=timer.getTime()
|
||||
PROFILER.endTime=0
|
||||
PROFILER.runTime=0
|
||||
|
||||
-- Set hook.
|
||||
debug.sethook(PROFILER.hook, "cr")
|
||||
|
||||
-- Add event handler.
|
||||
world.addEventHandler(PROFILER.eventHandler)
|
||||
@ -111,6 +109,12 @@ function PROFILER.Start()
|
||||
-- Message.
|
||||
showProfilerRunning()
|
||||
|
||||
-- Info in log.
|
||||
BASE:I('############################ Profiler Started ############################')
|
||||
|
||||
-- Set hook.
|
||||
debug.sethook(PROFILER.hook, "cr")
|
||||
|
||||
end
|
||||
|
||||
--- Stop profiler.
|
||||
@ -207,7 +211,6 @@ end
|
||||
function PROFILER._flog(f, txt)
|
||||
f:write(txt.."\r\n")
|
||||
env.info("Profiler Analysis")
|
||||
env.info(txt)
|
||||
end
|
||||
|
||||
--- Show table.
|
||||
@ -235,9 +238,11 @@ end
|
||||
function PROFILER.showInfo()
|
||||
|
||||
-- Output file.
|
||||
local file=lfs.writedir()..[[Logs\]].."_LuaProfiler.txt"
|
||||
local file=lfs.writedir()..[[Logs\]]..PROFILER.fileName
|
||||
local f=io.open(file, 'w')
|
||||
|
||||
BASE:I(string.format("### Profiler: Writing result to file ", file))
|
||||
|
||||
-- Gather data.
|
||||
local t={}
|
||||
for func, count in pairs(PROFILER.Counters) do
|
||||
|
||||
@ -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 )
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
Utilities/Routines.lua
|
||||
Utilities/Utils.lua
|
||||
Utilities/Enums.lua
|
||||
Utilities/Profiler.lua
|
||||
|
||||
Core/Base.lua
|
||||
Core/UserFlag.lua
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user