From 114032a743ee6143a69fb86d3cf09b75af6d8df8 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 18 Aug 2020 18:15:22 +0200 Subject: [PATCH] Ops --- Moose Development/Moose/Core/Set.lua | 13 +-- Moose Development/Moose/Ops/AirWing.lua | 59 ++++++----- Moose Development/Moose/Ops/ArmyGroup.lua | 2 +- Moose Development/Moose/Ops/Auftrag.lua | 45 +++++++-- Moose Development/Moose/Ops/FlightGroup.lua | 2 + Moose Development/Moose/Ops/OpsGroup.lua | 2 +- Moose Development/Moose/Ops/Squadron.lua | 47 ++++++--- Moose Development/Moose/Ops/Target.lua | 106 ++++++++++++++------ Moose Development/Moose/Wrapper/Group.lua | 2 + 9 files changed, 191 insertions(+), 87 deletions(-) diff --git a/Moose Development/Moose/Core/Set.lua b/Moose Development/Moose/Core/Set.lua index a677f1135..13f0f6f31 100644 --- a/Moose Development/Moose/Core/Set.lua +++ b/Moose Development/Moose/Core/Set.lua @@ -3238,13 +3238,13 @@ do -- SET_STATIC self:F3( { Event } ) if Event.IniObjectCategory == Object.Category.STATIC then - if not self.Database[Event.IniDCSStaticName] then - self.Database[Event.IniDCSStaticName] = STATIC:Register( Event.IniDCSStaticName ) - self:T3( self.Database[Event.IniDCSStaticName] ) + if not self.Database[Event.IniDCSUnitName] then + self.Database[Event.IniDCSUnitName] = STATIC:Register( Event.IniDCSUnitName ) + self:T3( self.Database[Event.IniDCSUnitName] ) end end - return Event.IniDCSStaticName, self.Database[Event.IniDCSStaticName] + return Event.IniDCSUnitName, self.Database[Event.IniDCSUnitName] end --- 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 #table The STATIC function SET_STATIC:FindInDatabase( Event ) - self:F2( { Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName], Event } ) - - - return Event.IniDCSStaticName, self.Set[Event.IniDCSStaticName] + return Event.IniDCSUnitName, self.Set[Event.IniDCSUnitName] end diff --git a/Moose Development/Moose/Ops/AirWing.lua b/Moose Development/Moose/Ops/AirWing.lua index fa3e963a5..d88e65a85 100644 --- a/Moose Development/Moose/Ops/AirWing.lua +++ b/Moose Development/Moose/Ops/AirWing.lua @@ -1544,6 +1544,11 @@ function AIRWING:onafterSquadAssetReturned(From, Event, To, Squadron, Asset) -- Return payload. self:ReturnPayloadFromAsset(Asset) + -- Return tacan channel. + if Asset.tacan then + Squadron:ReturnTacan(Asset.tacan) + end + -- Set timestamp. Asset.Treturned=timer.getAbsTime() end @@ -1565,48 +1570,52 @@ function AIRWING:onafterAssetSpawned(From, Event, To, group, asset, request) -- Create a flight group. local flightgroup=self:_CreateFlightGroup(asset) - - -- Set airwing. - flightgroup:SetAirwing(self) + + --- + -- Asset + --- -- Set asset 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. asset.requested=nil -- 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. flightgroup:SetFuelCriticalThreshold() + + --- + -- Mission + --- -- Get Mission (if any). local mission=self:GetMissionByID(request.assignment) -- Add mission to flightgroup queue. 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. asset.flightgroup:AddMission(mission) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index 341727192..2593978ee 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -333,7 +333,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To) if self.option.Alarm then self:SwitchAlarmstate(self.option.Alarm) else - self:SwitchAlarmstate(0) + self:SwitchAlarmstate(ENUMS.AlarmState.Auto) end -- Turn TACAN beacon on. diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index 8c81992c8..5733adf65 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -98,6 +98,9 @@ -- @field #table enrouteTasks Mission enroute tasks. -- -- @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 NrepeatSuccess Number of times mission is repeated if successful. -- @@ -486,6 +489,9 @@ function AUFTRAG:New(Type) self:SetTime() self.engageAsGroup=true self.repeated=0 + self.repeatedSuccess=0 + self.repeatedFailure=0 + self.Nrepeat=0 self.NrepeatFailure=0 self.NrepeatSuccess=0 self.nassets=1 @@ -1415,6 +1421,15 @@ function AUFTRAG:SetPriority(Prio, Urgent, Importance) return self 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. -- @param #AUFTRAG self -- @param #number Nrepeat Number of repeats. Default 0. @@ -2535,8 +2550,9 @@ function AUFTRAG:onafterCancel(From, Event, To) self.Tover=timer.getAbsTime() -- No more repeats. - self.NrepeatFailure=self.repeated - self.NrepeatSuccess=self.repeated + self.Nrepeat=self.repeated + self.NrepeatFailure=self.repeatedFailure + self.NrepeatSuccess=self.repeatedSuccess -- Not necessary to delay the evaluaton?! self.dTevaluate=0 @@ -2583,16 +2599,18 @@ function AUFTRAG:onafterSuccess(From, Event, To) self.status=AUFTRAG.Status.SUCCESS 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. - 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() else + + self.repeatedSuccess=self.repeatedSuccess+1 -- 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() end @@ -2609,16 +2627,23 @@ function AUFTRAG:onafterFailed(From, Event, To) self.status=AUFTRAG.Status.FAILED self:T(self.lid..string.format("New mission status=%s", self.status)) - if self.repeated>=self.NrepeatFailure then + local repeatme=self.repeatedFailure=%d] ==> Stopping mission!", self.repeated, self.NrepeatFailure)) - self:Stop() + if self.repeatedFailure>=self.NrepeatFailure then + + self.repeatedFailure=self.repeatedFailure+1 - else + 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, self.NrepeatFailure)) + 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() + + + else + + self:I(self.lid..string.format("Mission FAILED! Number of max repeats %d reached ==> Stopping mission!", self.repeated+1)) + self:Stop() end diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 5ac377611..221c09112 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -227,7 +227,9 @@ function FLIGHTGROUP:New(group) -- Defaults self:SetFuelLowThreshold() + self:SetFuelLowRTB() self:SetFuelCriticalThreshold() + self:SetFuelCriticalRTB() self:SetDefaultROE() self:SetDefaultROT() self:SetDetection() diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index d6fb149fa..051f31476 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3324,7 +3324,7 @@ function OPSGROUP:TurnOffICLS() end self:I(self.lid..string.format("Switching ICLS OFF")) - self.iclsOn=false + self.icls.On=false end diff --git a/Moose Development/Moose/Ops/Squadron.lua b/Moose Development/Moose/Ops/Squadron.lua index b37ce8fe9..e1ff5f966 100644 --- a/Moose Development/Moose/Ops/Squadron.lua +++ b/Moose Development/Moose/Ops/Squadron.lua @@ -395,6 +395,15 @@ function SQUADRON:SetModex(Modex, Prefix, Suffix) return self 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. -- @param #SQUADRON self -- @param Ops.AirWing#AIRWING Airwing The airwing. @@ -500,23 +509,33 @@ function SQUADRON:GetModex(Asset) 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. -- @param #SQUADRON self --- @param Ops.AirWing#AIRWING.SquadronAsset Asset The airwing asset. -- @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=self.TACANmin, self.TACANmax do - - if not self.TACANused[channel] then - self.TACANused[channel]=true - return channel - end - + for channel,free in pairs(self.tacanChannel) do + if free then + self.tacanChannel[channel]=false + return channel end - end return nil @@ -525,8 +544,8 @@ end --- "Return" a used TACAN channel. -- @param #SQUADRON self -- @param #number channel The channel that is available again. -function SQUADRON:ReturnTACAN(channel) - self.TACANused[channel]=false +function SQUADRON:ReturnTacan(channel) + self.tacanChannel[channel]=true end --- Check if squadron is "OnDuty". diff --git a/Moose Development/Moose/Ops/Target.lua b/Moose Development/Moose/Ops/Target.lua index e5b2f3a22..f35f7e6df 100644 --- a/Moose Development/Moose/Ops/Target.lua +++ b/Moose Development/Moose/Ops/Target.lua @@ -103,6 +103,7 @@ TARGET.ObjectStatus={ -- @field #number Life Life points on last status update. -- @field #number Life0 Life points of completely healthy target. -- @field #string Status Status "Alive" or "Dead". +-- @field Core.Point#COORDINATE Coordinate of the target object. --- Global target ID counter. _TARGETID=0 @@ -436,7 +437,9 @@ function TARGET:_AddObject(Object) local group=Object --Wrapper.Group#GROUP target.Type=TARGET.ObjectType.GROUP - target.Name=group:GetName() + target.Name=group:GetName() + + target.Coordinate=group:GetCoordinate() local units=group:GetUnits() @@ -461,6 +464,8 @@ function TARGET:_AddObject(Object) target.Type=TARGET.ObjectType.UNIT target.Name=unit:GetName() + target.Coordinate=unit:GetCoordinate() + if unit and unit:IsAlive() then target.Life=unit:GetLife() 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.Name=static:GetName() + target.Coordinate=static:GetCoordinate() + if static and static:IsAlive() then target.Life0=1 target.Life=1 @@ -491,6 +498,8 @@ function TARGET:_AddObject(Object) target.Type=TARGET.ObjectType.AIRBASE target.Name=airbase:GetName() + + target.Coordinate=airbase:GetCoordinate() target.Life0=1 target.Life=1 @@ -503,6 +512,8 @@ function TARGET:_AddObject(Object) target.Type=TARGET.ObjectType.COORDINATE target.Name=coord:ToStringMGRS() + + target.Coordinate=Object target.Life0=1 target.Life=1 @@ -621,6 +632,56 @@ function TARGET:GetLife() return N 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. @@ -629,36 +690,25 @@ end -- @return Core.Point#COORDINATE Coordinate of the target. function TARGET:GetTargetCoordinate(Target) - if Target.Type==TARGET.ObjectType.GROUP 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 + if Target.Type==TARGET.ObjectType.COORDINATE then + -- Coordinate is the object itself. 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 return nil diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 82b0ea1c7..fda0abe58 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -261,7 +261,9 @@ end -- @param #string GroupName The Group name -- @return #GROUP self function GROUP:Register( GroupName ) + local self = BASE:Inherit( self, CONTROLLABLE:New( GroupName ) ) -- #GROUP + self.GroupName = GroupName self:SetEventPriority( 4 )