This commit is contained in:
Frank 2020-08-18 18:15:22 +02:00
parent e9e6a63e6a
commit 114032a743
9 changed files with 191 additions and 87 deletions

View File

@ -3238,13 +3238,13 @@ do -- SET_STATIC
self:F3( { Event } ) self:F3( { Event } )
if Event.IniObjectCategory == Object.Category.STATIC then if Event.IniObjectCategory == Object.Category.STATIC then
if not self.Database[Event.IniDCSStaticName] then if not self.Database[Event.IniDCSUnitName] then
self.Database[Event.IniDCSStaticName] = STATIC:Register( Event.IniDCSStaticName ) self.Database[Event.IniDCSUnitName] = STATIC:Register( Event.IniDCSUnitName )
self:T3( self.Database[Event.IniDCSStaticName] ) self:T3( self.Database[Event.IniDCSUnitName] )
end end
end end
return Event.IniDCSStaticName, self.Database[Event.IniDCSStaticName] return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName]
end end
--- Handles the Database to check on any event that Object exists in the Database. --- Handles the Database to check on any event that Object exists in the Database.
@ -3254,10 +3254,7 @@ do -- SET_STATIC
-- @return #string The name of the STATIC -- @return #string The name of the STATIC
-- @return #table The STATIC -- @return #table The STATIC
function SET_STATIC:FindInDatabase( Event ) function SET_STATIC:FindInDatabase( Event )
self:F2( { Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName], Event } ) return Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName]
return Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName]
end end

View File

@ -1544,6 +1544,11 @@ function AIRWING:onafterSquadAssetReturned(From, Event, To, Squadron, Asset)
-- Return payload. -- Return payload.
self:ReturnPayloadFromAsset(Asset) self:ReturnPayloadFromAsset(Asset)
-- Return tacan channel.
if Asset.tacan then
Squadron:ReturnTacan(Asset.tacan)
end
-- Set timestamp. -- Set timestamp.
Asset.Treturned=timer.getAbsTime() Asset.Treturned=timer.getAbsTime()
end end
@ -1566,48 +1571,52 @@ function AIRWING:onafterAssetSpawned(From, Event, To, group, asset, request)
-- Create a flight group. -- Create a flight group.
local flightgroup=self:_CreateFlightGroup(asset) local flightgroup=self:_CreateFlightGroup(asset)
-- Set airwing. ---
flightgroup:SetAirwing(self) -- Asset
---
-- Set asset flightgroup. -- Set asset flightgroup.
asset.flightgroup=flightgroup asset.flightgroup=flightgroup
-- Get the SQUADRON of the asset.
local squadron=self:GetSquadronOfAsset(asset)
-- Set default TACAN channel.
local Tacan=squadron:GetTACAN()
if Tacan then
flightgroup:SetDefaultTACAN(Tacan)
end
-- Set radio frequency and modulation
local radioFreq, radioModu=squadron:GetRadio()
if radioFreq then
flightgroup:SetDefaultRadio(radioFreq, radioModu)
end
-- Not requested any more. -- Not requested any more.
asset.requested=nil asset.requested=nil
-- Did not return yet. -- Did not return yet.
asset.Treturned=nil asset.Treturned=nil
---
-- Squadron
---
-- Get the SQUADRON of the asset.
local squadron=self:GetSquadronOfAsset(asset)
-- Set default TACAN channel.
local Tacan=squadron:FetchTacan()
if Tacan then
flightgroup:SwitchTACAN(Tacan, Morse, UnitName, Band)
asset.tacan=Tacan
end
-- Set radio frequency and modulation
local radioFreq, radioModu=squadron:GetRadio()
if radioFreq then
flightgroup:SwitchRadio(radioFreq, radioModu)
end
-- Set RTB on fuel critical. -- Set RTB on fuel critical.
flightgroup:SetFuelCriticalThreshold() flightgroup:SetFuelCriticalThreshold()
---
-- Mission
---
-- Get Mission (if any). -- Get Mission (if any).
local mission=self:GetMissionByID(request.assignment) local mission=self:GetMissionByID(request.assignment)
-- Add mission to flightgroup queue. -- Add mission to flightgroup queue.
if mission then if mission then
-- RTB on low fuel if on GCCAP.
if mission.type==AUFTRAG.Type.GCCAP then
flightgroup:SetFuelLowThreshold(25)
flightgroup:SetFuelLowRTB(true)
end
-- Add mission to flightgroup queue. -- Add mission to flightgroup queue.
asset.flightgroup:AddMission(mission) asset.flightgroup:AddMission(mission)

View File

@ -333,7 +333,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
if self.option.Alarm then if self.option.Alarm then
self:SwitchAlarmstate(self.option.Alarm) self:SwitchAlarmstate(self.option.Alarm)
else else
self:SwitchAlarmstate(0) self:SwitchAlarmstate(ENUMS.AlarmState.Auto)
end end
-- Turn TACAN beacon on. -- Turn TACAN beacon on.

View File

@ -98,6 +98,9 @@
-- @field #table enrouteTasks Mission enroute tasks. -- @field #table enrouteTasks Mission enroute tasks.
-- --
-- @field #number repeated Number of times mission was repeated. -- @field #number repeated Number of times mission was repeated.
-- @field #number repeatedSuccess Number of times mission was repeated after a success.
-- @field #number repeatedFailure Number of times mission was repeated after a failure.
-- @field #number Nrepeat Number of times the mission is repeated.
-- @field #number NrepeatFailure Number of times mission is repeated if failed. -- @field #number NrepeatFailure Number of times mission is repeated if failed.
-- @field #number NrepeatSuccess Number of times mission is repeated if successful. -- @field #number NrepeatSuccess Number of times mission is repeated if successful.
-- --
@ -486,6 +489,9 @@ function AUFTRAG:New(Type)
self:SetTime() self:SetTime()
self.engageAsGroup=true self.engageAsGroup=true
self.repeated=0 self.repeated=0
self.repeatedSuccess=0
self.repeatedFailure=0
self.Nrepeat=0
self.NrepeatFailure=0 self.NrepeatFailure=0
self.NrepeatSuccess=0 self.NrepeatSuccess=0
self.nassets=1 self.nassets=1
@ -1415,6 +1421,15 @@ function AUFTRAG:SetPriority(Prio, Urgent, Importance)
return self return self
end end
--- Set how many times the mission is repeated. Only valid if the mission is handled by an AIRWING or higher level.
-- @param #AUFTRAG self
-- @param #number Nrepeat Number of repeats. Default 0.
-- @return #AUFTRAG self
function AUFTRAG:SetRepeatOnFailure(Nrepeat)
self.Nrepeat=Nrepeat or 0
return self
end
--- Set how many times the mission is repeated if it fails. Only valid if the mission is handled by an AIRWING or higher level. --- Set how many times the mission is repeated if it fails. Only valid if the mission is handled by an AIRWING or higher level.
-- @param #AUFTRAG self -- @param #AUFTRAG self
-- @param #number Nrepeat Number of repeats. Default 0. -- @param #number Nrepeat Number of repeats. Default 0.
@ -2535,8 +2550,9 @@ function AUFTRAG:onafterCancel(From, Event, To)
self.Tover=timer.getAbsTime() self.Tover=timer.getAbsTime()
-- No more repeats. -- No more repeats.
self.NrepeatFailure=self.repeated self.Nrepeat=self.repeated
self.NrepeatSuccess=self.repeated self.NrepeatFailure=self.repeatedFailure
self.NrepeatSuccess=self.repeatedSuccess
-- Not necessary to delay the evaluaton?! -- Not necessary to delay the evaluaton?!
self.dTevaluate=0 self.dTevaluate=0
@ -2583,16 +2599,18 @@ function AUFTRAG:onafterSuccess(From, Event, To)
self.status=AUFTRAG.Status.SUCCESS self.status=AUFTRAG.Status.SUCCESS
self:T(self.lid..string.format("New mission status=%s", self.status)) self:T(self.lid..string.format("New mission status=%s", self.status))
if self.repeated>=self.NrepeatSuccess then if self.repeatedSuccess>=self.NrepeatSuccess then
-- Stop mission. -- Stop mission.
self:I(self.lid..string.format("Mission SUCCESS! Number of max repeats reached [%d>=%d] ==> Stopping mission!", self.repeated, self.NrepeatSuccess)) self:I(self.lid..string.format("Mission SUCCESS! Number of max repeats reached [%d>=%d] ==> Stopping mission!", self.repeatedSuccess, self.NrepeatSuccess))
self:Stop() self:Stop()
else else
self.repeatedSuccess=self.repeatedSuccess+1
-- Repeat mission. -- Repeat mission.
self:I(self.lid..string.format("Mission SUCCESS! Repeating mission for the %d time (max %d times) ==> Repeat mission!", self.repeated+1, self.NrepeatSuccess)) self:I(self.lid..string.format("Mission SUCCESS! Repeating mission for the %d time (max %d times) ==> Repeat mission!", self.repeatedSuccess, self.NrepeatSuccess))
self:Repeat() self:Repeat()
end end
@ -2609,16 +2627,23 @@ function AUFTRAG:onafterFailed(From, Event, To)
self.status=AUFTRAG.Status.FAILED self.status=AUFTRAG.Status.FAILED
self:T(self.lid..string.format("New mission status=%s", self.status)) self:T(self.lid..string.format("New mission status=%s", self.status))
if self.repeated>=self.NrepeatFailure then local repeatme=self.repeatedFailure<self.NrepeatFailure or self.repeated<self.Nrepeat
if self.repeatedFailure>=self.NrepeatFailure then
self.repeatedFailure=self.repeatedFailure+1
local N=math.max(self.NrepeatFailure, self.Nrepeat)
-- Repeat mission.
self:I(self.lid..string.format("Mission FAILED! Repeating mission for the %d time (max %d times) ==> Repeat mission!", self.repeated+1, N))
self:Repeat()
self:I(self.lid..string.format("Mission FAILED! Number of max repeats reached [%d>=%d] ==> Stopping mission!", self.repeated, self.NrepeatFailure))
self:Stop()
else else
-- Repeat mission. self:I(self.lid..string.format("Mission FAILED! Number of max repeats %d reached ==> Stopping mission!", self.repeated+1))
self:I(self.lid..string.format("Mission FAILED! Repeating mission for the %d time (max %d times) ==> Repeat mission!", self.repeated+1, self.NrepeatFailure)) self:Stop()
self:Repeat()
end end

View File

@ -227,7 +227,9 @@ function FLIGHTGROUP:New(group)
-- Defaults -- Defaults
self:SetFuelLowThreshold() self:SetFuelLowThreshold()
self:SetFuelLowRTB()
self:SetFuelCriticalThreshold() self:SetFuelCriticalThreshold()
self:SetFuelCriticalRTB()
self:SetDefaultROE() self:SetDefaultROE()
self:SetDefaultROT() self:SetDefaultROT()
self:SetDetection() self:SetDetection()

View File

@ -3324,7 +3324,7 @@ function OPSGROUP:TurnOffICLS()
end end
self:I(self.lid..string.format("Switching ICLS OFF")) self:I(self.lid..string.format("Switching ICLS OFF"))
self.iclsOn=false self.icls.On=false
end end

View File

@ -395,6 +395,15 @@ function SQUADRON:SetModex(Modex, Prefix, Suffix)
return self return self
end end
--- Set low fuel threshold.
-- @param #SQUADRON self
-- @param #number LowFuel Low fuel threshold in percent. Default 25.
-- @return #SQUADRON self
function SQUADRON:SetLowFuelThreshold(LowFuel)
self.fuellow=LowFuel or 25
return self
end
--- Set airwing. --- Set airwing.
-- @param #SQUADRON self -- @param #SQUADRON self
-- @param Ops.AirWing#AIRWING Airwing The airwing. -- @param Ops.AirWing#AIRWING Airwing The airwing.
@ -500,23 +509,33 @@ function SQUADRON:GetModex(Asset)
end end
--- Add TACAN channels to the squadron. Note that channels can only range from 1 to 126.
-- @param #SQUADRON self
-- @param #number ChannelMin Channel.
-- @param #number ChannelMax Channel.
-- @return #SQUADRON self
-- @usage mysquad:AddTacanChannel(64,69) -- adds channels 64, 65, 66, 67, 68, 69
function SQUADRON:AddTacanChannel(ChannelMin, ChannelMax)
ChannelMax=ChannelMax or ChannelMin
for i=ChannelMin,ChannelMax do
self.tacanChannel[i]=true
end
end
--- Get an unused TACAN channel. --- Get an unused TACAN channel.
-- @param #SQUADRON self -- @param #SQUADRON self
-- @param Ops.AirWing#AIRWING.SquadronAsset Asset The airwing asset.
-- @return #number TACAN channel or *nil* if no channel is free. -- @return #number TACAN channel or *nil* if no channel is free.
function SQUADRON:GetTACAN() function SQUADRON:FetchTacan()
if self.TACANmin and self.TACANmax then for channel,free in pairs(self.tacanChannel) do
if free then
for channel=self.TACANmin, self.TACANmax do self.tacanChannel[channel]=false
if not self.TACANused[channel] then
self.TACANused[channel]=true
return channel return channel
end end
end
end end
return nil return nil
@ -525,8 +544,8 @@ end
--- "Return" a used TACAN channel. --- "Return" a used TACAN channel.
-- @param #SQUADRON self -- @param #SQUADRON self
-- @param #number channel The channel that is available again. -- @param #number channel The channel that is available again.
function SQUADRON:ReturnTACAN(channel) function SQUADRON:ReturnTacan(channel)
self.TACANused[channel]=false self.tacanChannel[channel]=true
end end
--- Check if squadron is "OnDuty". --- Check if squadron is "OnDuty".

View File

@ -103,6 +103,7 @@ TARGET.ObjectStatus={
-- @field #number Life Life points on last status update. -- @field #number Life Life points on last status update.
-- @field #number Life0 Life points of completely healthy target. -- @field #number Life0 Life points of completely healthy target.
-- @field #string Status Status "Alive" or "Dead". -- @field #string Status Status "Alive" or "Dead".
-- @field Core.Point#COORDINATE Coordinate of the target object.
--- Global target ID counter. --- Global target ID counter.
_TARGETID=0 _TARGETID=0
@ -438,6 +439,8 @@ function TARGET:_AddObject(Object)
target.Type=TARGET.ObjectType.GROUP target.Type=TARGET.ObjectType.GROUP
target.Name=group:GetName() target.Name=group:GetName()
target.Coordinate=group:GetCoordinate()
local units=group:GetUnits() local units=group:GetUnits()
target.Life=0 ; target.Life0=0 target.Life=0 ; target.Life0=0
@ -461,6 +464,8 @@ function TARGET:_AddObject(Object)
target.Type=TARGET.ObjectType.UNIT target.Type=TARGET.ObjectType.UNIT
target.Name=unit:GetName() target.Name=unit:GetName()
target.Coordinate=unit:GetCoordinate()
if unit and unit:IsAlive() then if unit and unit:IsAlive() then
target.Life=unit:GetLife() target.Life=unit:GetLife()
target.Life0=math.max(unit:GetLife0(), target.Life) -- There was an issue with ships that life is greater life0! target.Life0=math.max(unit:GetLife0(), target.Life) -- There was an issue with ships that life is greater life0!
@ -477,6 +482,8 @@ function TARGET:_AddObject(Object)
target.Type=TARGET.ObjectType.STATIC target.Type=TARGET.ObjectType.STATIC
target.Name=static:GetName() target.Name=static:GetName()
target.Coordinate=static:GetCoordinate()
if static and static:IsAlive() then if static and static:IsAlive() then
target.Life0=1 target.Life0=1
target.Life=1 target.Life=1
@ -492,6 +499,8 @@ function TARGET:_AddObject(Object)
target.Type=TARGET.ObjectType.AIRBASE target.Type=TARGET.ObjectType.AIRBASE
target.Name=airbase:GetName() target.Name=airbase:GetName()
target.Coordinate=airbase:GetCoordinate()
target.Life0=1 target.Life0=1
target.Life=1 target.Life=1
@ -504,6 +513,8 @@ function TARGET:_AddObject(Object)
target.Type=TARGET.ObjectType.COORDINATE target.Type=TARGET.ObjectType.COORDINATE
target.Name=coord:ToStringMGRS() target.Name=coord:ToStringMGRS()
target.Coordinate=Object
target.Life0=1 target.Life0=1
target.Life=1 target.Life=1
@ -621,6 +632,56 @@ function TARGET:GetLife()
return N return N
end end
--- Get target 3D position vector.
-- @param #TARGET self
-- @param #TARGET.Object Target Target object.
-- @return DCS#Vec3 Vector with x,y,z components
function TARGET:GetTargetVec3(Target)
if Target.Type==TARGET.ObjectType.GROUP then
local object=Target.Object --Wrapper.Group#GROUP
if object and object:IsAlive() then
return object:GetVec3()
end
elseif Target.Type==TARGET.ObjectType.UNIT then
local object=Target.Object --Wrapper.Unit#UNIT
if object and object:IsAlive() then
return object:GetVec3()
end
elseif Target.Type==TARGET.ObjectType.STATIC then
local object=Target.Object --Wrapper.Static#STATIC
if object and object:IsAlive() then
return Target.Object:GetCoordinate()
end
elseif Target.Type==TARGET.ObjectType.AIRBASE then
local object=Target.Object --Wrapper.Airbase#AIRBASE
return object:GetVec3()
--if Target.Status==TARGET.ObjectStatus.ALIVE then
--end
elseif Target.Type==TARGET.ObjectType.COORDINATE then
local object=Target.Object --Core.Point#COORDINATE
return {x=object.x, y=object.y, z=object.z}
end
end
--- Get target coordinate. --- Get target coordinate.
@ -629,36 +690,25 @@ end
-- @return Core.Point#COORDINATE Coordinate of the target. -- @return Core.Point#COORDINATE Coordinate of the target.
function TARGET:GetTargetCoordinate(Target) function TARGET:GetTargetCoordinate(Target)
if Target.Type==TARGET.ObjectType.GROUP then if Target.Type==TARGET.ObjectType.COORDINATE then
if Target.Object and Target.Object:IsAlive() then
return Target.Object:GetCoordinate()
end
elseif Target.Type==TARGET.ObjectType.UNIT then
if Target.Object and Target.Object:IsAlive() then
return Target.Object:GetCoordinate()
end
elseif Target.Type==TARGET.ObjectType.STATIC then
if Target.Object and Target.Object:IsAlive() then
return Target.Object:GetCoordinate()
end
elseif Target.Type==TARGET.ObjectType.AIRBASE then
if Target.Status==TARGET.ObjectStatus.ALIVE then
return Target.Object:GetCoordinate()
end
elseif Target.Type==TARGET.ObjectType.COORDINATE then
-- Coordinate is the object itself.
return Target.Object return Target.Object
else
-- Get updated position vector.
local vec3=self:GetTargetVec3(Target)
-- Update position. This saves us to create a new COORDINATE object each time.
if vec3 then
Target.Coordinate.x=vec3.x
Target.Coordinate.y=vec3.y
Target.Coordinate.z=vec3.z
end
return Target.Coordinate
end end
return nil return nil

View File

@ -261,7 +261,9 @@ end
-- @param #string GroupName The Group name -- @param #string GroupName The Group name
-- @return #GROUP self -- @return #GROUP self
function GROUP:Register( GroupName ) function GROUP:Register( GroupName )
local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP
self.GroupName = GroupName self.GroupName = GroupName
self:SetEventPriority( 4 ) self:SetEventPriority( 4 )