From a95f3f2fa1b01dc8cef3b795f8936db562e9aa47 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 26 Mar 2020 23:59:30 +0100 Subject: [PATCH] Ops --- .../Moose/Functional/Warehouse.lua | 4 +- Moose Development/Moose/Ops/Auftrag.lua | 13 ++++++- Moose Development/Moose/Ops/FlightControl.lua | 26 ++++++------- Moose Development/Moose/Ops/FlightGroup.lua | 37 +++++++++++++------ Moose Development/Moose/Ops/Intelligence.lua | 26 ++++++------- Moose Development/Moose/Ops/Squadron.lua | 19 ++++++++-- Moose Development/Moose/Ops/WingCommander.lua | 9 +++-- 7 files changed, 87 insertions(+), 47 deletions(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 13943ad0c..d36441d4c 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -3846,7 +3846,9 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu if group:IsAlive()==true then self:_DebugMessage(string.format("Removing group %s.", group:GetName()), 5) -- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic. - group:Destroy(false) + -- Create a RemoveUnit event to let the FLIGHTCONTROL now, the parking is now free. + -- TODO: Need to check if my above comment not to confuse the dispatcher logic is broken by this! + group:Destroy() end else diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index d6713aab9..6103b097f 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -281,7 +281,7 @@ function AUFTRAG:New(Type) -- Defaults self:SetName() self:SetPriority() - self:SetMissionTime() + self:SetTime() self.engageAsGroup=true self.missionRepeated=0 @@ -778,7 +778,7 @@ end -- @param #string ClockStart Time the mission is started, e.g. "05:00" for 5 am. If specified as a #number, it will be relative (in seconds) to the current mission time. Default is 5 seconds after mission was added. -- @param #string ClockStop (Optional) Time the mission is stopped, e.g. "13:00" for 1 pm. If mission could not be started at that time, it will be removed from the queue. If specified as a #number it will be relative (in seconds) to the current mission time. -- @return #AUFTRAG self -function AUFTRAG:SetMissionTime(ClockStart, ClockStop) +function AUFTRAG:SetTime(ClockStart, ClockStop) -- Current mission time. local Tnow=timer.getAbsTime() @@ -829,6 +829,15 @@ function AUFTRAG:SetRepeatOnFailure(Nrepeat) return self end +--- Define how many assets are required to do the job. +-- @param #AUFTRAG self +-- @param #number Nassets Number of asset groups. Default 1. +-- @return #AUFTRAG self +function AUFTRAG:SetRequiredAssets(Nassets) + self.nassets=Nassets or 1 + return self +end + --- Set mission name. -- @param #AUFTRAG self -- @param #string Name Name of the mission. diff --git a/Moose Development/Moose/Ops/FlightControl.lua b/Moose Development/Moose/Ops/FlightControl.lua index 3750fe04b..940376f3c 100644 --- a/Moose Development/Moose/Ops/FlightControl.lua +++ b/Moose Development/Moose/Ops/FlightControl.lua @@ -126,7 +126,7 @@ FLIGHTCONTROL.version="0.2.5" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO: Accept and forbit parking spots. --- TODO: Add FARPS? +-- NOGO: Add FARPS? -- TODO: Add helos. -- TODO: Talk me down option. -- TODO: ATIS option. @@ -546,8 +546,7 @@ function FLIGHTCONTROL:_CheckQueues() -- Give AI the landing signal. -- TODO: Humans have to confirm via F10 menu. - if flight.ai then - flight:FlightLanding() + if flight.ai then self:_LandAI(flight, parking) end @@ -689,7 +688,7 @@ function FLIGHTCONTROL:_GetNextFightHolding() local function _sortByTholding(a, b) local flightA=a --Ops.FlightGroup#FLIGHTGROUP local flightB=b --Ops.FlightGroup#FLIGHTGROUP - return flightA.Tholding>flightB.Tholding + return flightA.TholdingflightB.Tparking + return flightA.Tparking dead", element.name)) - --self:ElementDead(element) + self:I(self.lid..string.format("EVENT: Element %s removed ==> dead", element.name)) + self:ElementDead(element) end end @@ -2113,6 +2113,10 @@ end -- @param #FLIGHTGROUP.Element Element The flight group element. function FLIGHTGROUP:onafterElementDead(From, Event, To, Element) self:T(self.lid..string.format("Element dead %s.", Element.name)) + + if self.flightcontrol and Element.parking then + self.flightcontrol:SetParkingFree(Element.parking) + end -- Not parking any more. Element.parking=nil @@ -2313,7 +2317,7 @@ function FLIGHTGROUP:onafterFlightDead(From, Event, To) self.groupinitialized=false -- Remove flight from all FC queues. - if self.flightcontrol then + if self.flightcontrol then self.flightcontrol:_RemoveFlight(self) self.flightcontrol=nil end @@ -2738,21 +2742,22 @@ function FLIGHTGROUP:onafterRTB(From, Event, To, airbase, SpeedTo, SpeedHold, Sp -- Clear all tasks. self:ClearTasks() - -- Set holding flag to 333. - self.flaghold:Set(333) + -- Set holding flag to 0=false. + self.flaghold:Set(0) -- Task fuction when reached holding point. local TaskArrived=self.group:TaskFunction("FLIGHTGROUP._ReachedHolding", self) - -- Orbit until flaghold=1 (true) but max 10 min. + -- Orbit until flaghold=1 (true) but max 10 min if no FC is giving the landing clearance. local TaskOrbit=self.group:TaskOrbit(p0, nil, UTILS.KnotsToMps(SpeedHold), p1) - local TaskLand=self.group:TaskCondition(nil, self.flaghold.UserFlagName, 1, nil, 10*60) + local TaskLand=self.group:TaskCondition(nil, self.flaghold.UserFlagName, 1, nil, fc and nil or 10*60) local TaskHold=self.group:TaskControlled(TaskOrbit, TaskLand) + local TaskKlar=self.group:TaskFunction("FLIGHTGROUP._ClearedToLand", self) -- Once the holding flag becomes true, set trigger FLIGHTLANDING, i.e. set flight STATUS to LANDING. -- Waypoints from current position to holding point. local wp={} wp[#wp+1]=c0:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {}, "Current Pos") - wp[#wp+1]=p0:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {TaskArrived, TaskHold}, "Holding Point") + wp[#wp+1]=p0:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {TaskArrived, TaskHold, TaskKlar}, "Holding Point") -- Approach point: 10 NN in direction of runway. local papp=airbase:GetCoordinate():Translate(x1, runway.heading-180):SetAltitude(h1) @@ -2921,8 +2926,8 @@ end -- @param #string To To state. function FLIGHTGROUP:onafterHolding(From, Event, To) - -- Set holding flag to 666. - self.flaghold:Set(666) + -- Set holding flag to 0 (just in case). + self.flaghold:Set(0) local text=string.format("Flight group %s is HOLDING now", self.groupname) MESSAGE:New(text, 10, "DEBUG"):ToAllIf(self.Debug) @@ -3741,6 +3746,16 @@ function FLIGHTGROUP._ReachedHolding(group, flightgroup) flightgroup:__Holding(-1) end +--- Function called when flight has reached the holding point. +-- @param Wrapper.Group#GROUP group Group object. +-- @param #FLIGHTGROUP flightgroup Flight group object. +function FLIGHTGROUP._ClearedToLand(group, flightgroup) + flightgroup:I(flightgroup.lid..string.format("Group was cleared to land")) + + -- Trigger FlightLanding event. + flightgroup:__FlightLanding(-1) +end + --- Function called when flight finished refuelling. -- @param Wrapper.Group#GROUP group Group object. -- @param #FLIGHTGROUP flightgroup Flight group object. diff --git a/Moose Development/Moose/Ops/Intelligence.lua b/Moose Development/Moose/Ops/Intelligence.lua index c06ccff41..9a3b32925 100644 --- a/Moose Development/Moose/Ops/Intelligence.lua +++ b/Moose Development/Moose/Ops/Intelligence.lua @@ -73,6 +73,7 @@ INTEL.version="0.0.3" -- DONE: Accept zones. -- TODO: Reject zones. +-- TODO: Filter detection methods. -- NOGO: SetAttributeZone --> return groups of generalized attributes in a zone. -- DONE: Loose units only if they remain undetected for a given time interval. We want to avoid fast oscillation between detected/lost states. Maybe 1-5 min would be a good time interval?! -- DONE: Combine units to groups for all, new and lost. @@ -93,24 +94,21 @@ function INTEL:New(DetectionSet, Coalition) local self=BASE:Inherit(self, FSM:New()) -- #INTEL -- Detection set. - self.detectionset=DetectionSet - - local alias="SPECTRE" - - --[[ + self.detectionset=DetectionSet or SET_GROUP:New() -- Determine coalition from first group in set. - self.coalition=DetectionSet:GetFirst():GetCoalition() + self.coalition=Coalition or DetectionSet:CountAlive()>0 and DetectionSet:GetFirst():GetCoalition() or nil - local alias="SPECTRE" - if self.coalition==coalition.side.RED then - alias="KGB" - elseif self.coalition==coalition.side.BLUE then - alias="CIA" + -- Set alias. + local alias="SPECTRE" + if self.coalition then + if self.coalition==coalition.side.RED then + alias="KGB" + elseif self.coalition==coalition.side.BLUE then + alias="CIA" + end end - ]] - -- Set some string id for output to DCS.log file. self.lid=string.format("INTEL %s | ", alias) @@ -122,7 +120,7 @@ function INTEL:New(DetectionSet, Coalition) self:AddTransition("Stopped", "Start", "Running") -- Start FSM. self:AddTransition("*", "Status", "*") -- INTEL status update - self:AddTransition("*", "Detect", "*") -- INTEL status update + self:AddTransition("*", "Detect", "*") -- Start detection run. Not implemented yet! self:AddTransition("*", "NewContact", "*") -- New contact has been detected. self:AddTransition("*", "LostContact", "*") -- Contact could not be detected any more. diff --git a/Moose Development/Moose/Ops/Squadron.lua b/Moose Development/Moose/Ops/Squadron.lua index 408a10852..de9ba5c0a 100644 --- a/Moose Development/Moose/Ops/Squadron.lua +++ b/Moose Development/Moose/Ops/Squadron.lua @@ -255,6 +255,15 @@ function SQUADRON:SetCallsign(Callsign, Index) return self end +--- Set modex. +-- @param #SQUADRON self +-- @param #string Modex +-- @return #SQUADRON self +function SQUADRON:SetModex(Modex) + self.modex=Modex + return self +end + --- Set airwing. -- @param #SQUADRON self -- @param Ops.AirWing#AIRWING Airwing The airwing. @@ -303,7 +312,7 @@ function SQUADRON:GetCallsign(Asset) local callsign={} callsign[1]=self.callsignName - callsign[2]=self.callsigncounter / 10 + callsign[2]=math.floor(self.callsigncounter / 10) callsign[3]=self.callsigncounter % 10 if callsign[3]==0 then callsign[3]=1 @@ -313,6 +322,8 @@ function SQUADRON:GetCallsign(Asset) end Asset.callsign[i]=callsign + + self:I({callsign=callsign}) --TODO: there is also a table entry .name, which is a string. end @@ -328,15 +339,17 @@ end -- @return #SQUADRON self function SQUADRON:GetModex(Asset) - if self.callsignName then + if self.modex then Asset.modex={} for i=1,Asset.nunits do - Asset.modex[i]=tostring(self.modex+self.modexcounter) + Asset.modex[i]=string.format("%03d", self.modex+self.modexcounter) self.modexcounter=self.modexcounter+1 + + self:I({modex=Asset.modex[i]}) end diff --git a/Moose Development/Moose/Ops/WingCommander.lua b/Moose Development/Moose/Ops/WingCommander.lua index 98d6057e9..7162e4794 100644 --- a/Moose Development/Moose/Ops/WingCommander.lua +++ b/Moose Development/Moose/Ops/WingCommander.lua @@ -64,15 +64,18 @@ WINGCOMMANDER.version="0.0.3" --- Create a new WINGCOMMANDER object and start the FSM. -- @param #WINGCOMMANDER self --- @param Core.Set#SET_UNITS AgentSet Set of agents (units) providing intel. +-- @param Core.Set#SET_GROUP AgentSet Set of agents (groups) providing intel. Default is an empty set. +-- @param #number Coalition Coalition side, e.g. `coaliton.side.BLUE`. Can also be passed as a string "red", "blue" or "neutral". -- @return #WINGCOMMANDER self -function WINGCOMMANDER:New(AgentSet) +function WINGCOMMANDER:New(AgentSet, Coalition) + + AgentSet=AgentSet or SET_GROUP:New() -- Inherit everything from INTEL class. local self=BASE:Inherit(self, INTEL:New(AgentSet)) --#WINGCOMMANDER -- Set some string id for output to DCS.log file. - self.lid=string.format("WINGCOMMANDER | ") + --self.lid=string.format("WINGCOMMANDER | ") -- Add FSM transitions. -- From State --> Event --> To State