From 1bd5e7472fbd7fea1eb84cd12ab0497a8cd5d5fd Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 2 Sep 2021 08:30:54 +0200 Subject: [PATCH] OPSTRANSPORT v0.4.2 - Some fixed. - All tested demo missions look nice --- Moose Development/Moose/Ops/FlightGroup.lua | 38 +++++++---- Moose Development/Moose/Ops/NavyGroup.lua | 4 +- Moose Development/Moose/Ops/OpsGroup.lua | 72 +++++++++++++------- Moose Development/Moose/Ops/OpsTransport.lua | 3 +- 4 files changed, 75 insertions(+), 42 deletions(-) diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index a8a4c19fe..33431370a 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -888,19 +888,25 @@ function FLIGHTGROUP:Status() -- Short info. if self.verbose>=1 then + local nelem=self:CountElements() + local Nelem=#self.elements local nTaskTot, nTaskSched, nTaskWP=self:CountRemainingTasks() local nMissions=self:CountRemainingMissison() + local currT=self.taskcurrent or "None" + local currM=self.currentmission or "None" + local currW=self.currentwp or 0 + local nWp=self.waypoints and #self.waypoints or 0 local home=self.homebase and self.homebase:GetName() or "unknown" local dest=self.destbase and self.destbase:GetName() or "unknown" local fc=self.flightcontrol and self.flightcontrol.airbasename or "N/A" local curr=self.currbase and self.currbase:GetName() or "N/A" - local nelem=self:CountElements() - local Nelem=#self.elements + local ndetected=self.detectionOn and tostring(self.detectedunits:Count()) or "OFF" - local text=string.format("Status %s [%d/%d]: Tasks=%d, Missions=%s, Waypoint=%d/%d [%s], Detected=%s, Home=%s, Destination=%s, Current=%s, FC=%s", - fsmstate, nelem, Nelem, nTaskTot, nMissions, self.currentwp or 0, self.waypoints and #self.waypoints or 0, tostring(self.passedfinalwp), - ndetected, home, dest, curr, fc) + local text=string.format("Status %s [%d/%d]: T/M=%d/%d [Current %s/%s] [%s], Waypoint=%d/%d [%s], Base=%s [%s-->%s]", + fsmstate, nelem, Nelem, + nTaskTot, nMissions, currT, currM, tostring(self:HasTaskController()), + currW, nWp, tostring(self.passedfinalwp), curr, home, dest) self:I(self.lid..text) end @@ -1813,10 +1819,6 @@ function FLIGHTGROUP:onafterLanded(From, Event, To, airbase) -- Add flight to taxiinb queue. self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.TAXIINB) end - - if airbase and self.isHelo then - self:Arrived() - end end @@ -1993,7 +1995,7 @@ function FLIGHTGROUP:onbeforeUpdateRoute(From, Event, To, n) allowed=false end - if self:IsUncontrolled() then + if allowed and self:IsUncontrolled() then -- Not airborne yet. Try again in 5 sec. self:T(self.lid.."Update route denied. Group is UNCONTROLLED ==> checking back in 5 sec") trepeat=-5 @@ -2244,9 +2246,13 @@ function FLIGHTGROUP:_CheckGroupDone(delay, waittime) self:T(self.lid..string.format("Passed Final WP and No current and/or future missions/tasks/transports. Waittime given ==> Waiting for %d sec!", waittime)) self:Wait(waittime) elseif destbase then - self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!") - --self:RTB(destbase) - self:__RTB(-0.1, destbase) + if self.currbase and self.currbase.AirbaseName==destbase.AirbaseName and self:IsParking() then + self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports AND parking at destination airbase ==> Arrived!") + self:__Arrived(0.1) + else + self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!") + self:__RTB(-0.1, destbase) + end elseif destzone then self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTZ!") self:__RTZ(-0.1, destzone) @@ -2493,8 +2499,8 @@ function FLIGHTGROUP:_LandAtAirbase(airbase, SpeedTo, SpeedHold, SpeedLand) local c2=c0:GetIntermediateCoordinate(p0, 0.75):SetAltitude(self.altitudeCruise, true) -- Altitude above ground for a glide slope of 3 degrees. - local x1=self.isHelo and UTILS.NMToMeters(5.0) or UTILS.NMToMeters(10) - local x2=self.isHelo and UTILS.NMToMeters(2.5) or UTILS.NMToMeters(5) + local x1=self.isHelo and UTILS.NMToMeters(2.0) or UTILS.NMToMeters(10) + local x2=self.isHelo and UTILS.NMToMeters(1.0) or UTILS.NMToMeters(5) local alpha=math.rad(3) local h1=x1*math.tan(alpha) local h2=x2*math.tan(alpha) @@ -2865,6 +2871,8 @@ function FLIGHTGROUP:onafterLandAt(From, Event, To, Coordinate, Duration) -- Duration. --Duration=Duration or 600 + + self:T(self.lid..string.format("Landing at Coordinate for %s seconds", tostring(Duration))) Coordinate=Coordinate or self:GetCoordinate() diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 500642a4e..65b32e2f3 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -1460,7 +1460,9 @@ end -- @param #NAVYGROUP self -- @return #boolean If true, a path was found. function NAVYGROUP:_FindPathToNextWaypoint() - env.info("FF Path finding") + self:T3(self.lid.."Path finding") + + --TODO: Do not create a new ASTAR object each time this function is called but make it self.astar and reuse. Should be better for performance. -- Pathfinding A* local astar=ASTAR:New() diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index ad94fc415..69455dd07 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -512,8 +512,6 @@ function OPSGROUP:New(group) end end - self.group:IsAir() - -- Set the template. self:_SetTemplate() @@ -1812,7 +1810,7 @@ function OPSGROUP:IsInZone(Zone) if vec2 then is=Zone:IsVec2InZone(vec2) else - env.info(self.lid.."FF cannot get vec2") + self:T3(self.lid.."WARNING: Cannot get vec2 at IsInZone()!") end return is end @@ -2783,14 +2781,13 @@ end --- Returns true if the DCS controller currently has a task. -- @param #OPSGROUP self --- @param #number Delay Delay in seconds. -- @return #boolean True or false if the controller has a task. Nil if no controller. -function OPSGROUP:HasTaskController(Delay) +function OPSGROUP:HasTaskController() local hastask=nil if self.controller then hastask=self.controller:hasTask() end - self:I(self.lid..string.format("Controller hasTask=%s", tostring(hastask))) + self:T3(self.lid..string.format("Controller hasTask=%s", tostring(hastask))) return hastask end @@ -3199,6 +3196,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) -- Insert into task queue. Not sure any more, why I added this. But probably if a task is just executed without having been put into the queue. if self:GetTaskCurrent()==nil then + --env.info("FF adding current task to queue") table.insert(self.taskqueue, Task) end @@ -3318,8 +3316,8 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) -- NOTE: I am pushing the task instead of setting it as it seems to keep the mission task alive. -- There were issues that flights did not proceed to a later waypoint because the task did not finish until the fired missiles -- impacted (took rather long). Then the flight flew to the nearest airbase and one lost completely the control over the group. - --self:PushTask(TaskFinal) - self:SetTask(TaskFinal) + self:PushTask(TaskFinal) + --self:SetTask(TaskFinal) elseif Task.type==OPSGROUP.TaskType.WAYPOINT then @@ -3467,7 +3465,7 @@ function OPSGROUP:onafterTaskDone(From, Event, To, Task) end if Task.description=="Task_Land_At" then - self:Wait(60, 100) + self:Wait(20, 100) else self:T(self.lid.."Task Done but NO mission found ==> _CheckGroupDone in 0 sec") self:_CheckGroupDone() @@ -5065,7 +5063,7 @@ end function OPSGROUP:onbeforeElementSpawned(From, Event, To, Element) if Element and Element.status==OPSGROUP.ElementStatus.SPAWNED then - self:I(self.lid..string.format("FF element %s is already spawned", Element.name)) + self:T2(self.lid..string.format("Element %s is already spawned ==> Transition denied!", Element.name)) return false end @@ -5333,7 +5331,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset) self:_InitWaypoints() -- Init Group. - self:_InitGroup() + self:_InitGroup(Template) -- Reset events. --self:ResetEvents() @@ -5883,7 +5881,6 @@ function OPSGROUP:_CheckDelivered(CargoTransport) elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then -- This one is dead. else - --env.info(string.format()) done=false --Someone is not done! end @@ -6416,7 +6413,7 @@ function OPSGROUP:onafterPickup(From, Event, To) end -- Order group to land at an airbase. - self:__LandAtAirbase(-0.5, airbasePickup) + self:__LandAtAirbase(-0.1, airbasePickup) elseif self.isHelo then @@ -6426,7 +6423,7 @@ function OPSGROUP:onafterPickup(From, Event, To) -- Activate uncontrolled group. if self:IsParking() and self:IsUncontrolled() then - self:StartUncontrolled(1) + self:StartUncontrolled(0.5) end -- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone. @@ -6436,6 +6433,16 @@ function OPSGROUP:onafterPickup(From, Event, To) self:E(self.lid.."ERROR: Transportcarrier aircraft cannot land in Pickup zone! Specify a ZONE_AIRBASE as pickup zone") end + -- Cancel landedAt task. This should trigger Cruise once airborne. + if self.isHelo and self:IsLandedAt() then + local Task=self:GetTaskCurrent() + if Task then + self:TaskCancel(Task) + else + self:E(self.lid.."ERROR: No current task but landed at?!") + end + end + elseif self:IsNavygroup() then --- @@ -6793,15 +6800,19 @@ function OPSGROUP:onafterTransport(From, Event, To) -- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone. local waypoint=FLIGHTGROUP.AddWaypoint(self, Coordinate, nil, self:GetWaypointCurrent().uid, UTILS.MetersToFeet(self.altitudeCruise), false) ; waypoint.detour=1 - -- Cancel landedAt task. This should trigger Cruise once airborne. - if self:IsFlightgroup() and self:IsLandedAt() then - local Task=self:GetTaskCurrent() - self:__TaskCancel(5, Task) - end - else - self:E(self.lid.."ERROR: Carrier aircraft cannot land in Deploy zone! Specify a ZONE_AIRBASE as deploy zone") + self:E(self.lid.."ERROR: Aircraft (cargo carrier) cannot land in Deploy zone! Specify a ZONE_AIRBASE as deploy zone") end + + -- Cancel landedAt task. This should trigger Cruise once airborne. + if self.isHelo and self:IsLandedAt() then + local Task=self:GetTaskCurrent() + if Task then + self:TaskCancel(Task) + else + self:E(self.lid.."ERROR: No current task but landed at?!") + end + end elseif self:IsArmygroup() then @@ -7179,9 +7190,22 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport) -- Startup uncontrolled aircraft to allow it to go back. if self:IsFlightgroup() then - if self:IsUncontrolled() then + + local function atbase(_airbase) + local airbase=_airbase --Wrapper.Airbase#AIRBASE + if airbase and self.currbase then + if airbase.AirbaseName==self.currbase.AirbaseName then + return true + end + end + return false + end + + -- Check if uncontrolled and NOT at destination. If so, start up uncontrolled and let flight return to whereever it wants to go. + if self:IsUncontrolled() and not atbase(self.destbase) then self:StartUncontrolled() - elseif self:IsLandedAt() then + end + if self:IsLandedAt() then local Task=self:GetTaskCurrent() self:TaskCancel(Task) end @@ -7191,7 +7215,7 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport) end -- Check group done. - self:T(self.lid.."All cargo delivered ==> check group done") + self:T(self.lid.."All cargo delivered ==> check group done in 0.2 sec") self:_CheckGroupDone(0.2) -- No current transport any more. diff --git a/Moose Development/Moose/Ops/OpsTransport.lua b/Moose Development/Moose/Ops/OpsTransport.lua index 48bbb0922..5e123a191 100644 --- a/Moose Development/Moose/Ops/OpsTransport.lua +++ b/Moose Development/Moose/Ops/OpsTransport.lua @@ -173,7 +173,7 @@ _OPSTRANSPORTID=0 --- Army Group version. -- @field #string version -OPSTRANSPORT.version="0.4.1" +OPSTRANSPORT.version="0.4.2" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -357,7 +357,6 @@ function OPSTRANSPORT:New(CargoGroups, PickupZone, DeployZone) -- @param Ops.OpsGroup#OPSGROUP OpsGroupCargo Cargo OPSGROUP that was unloaded from a carrier. -- @param Ops.OpsGroup#OPSGROUP OpsGroupCarrier Carrier OPSGROUP that unloaded the cargo. - --- On after "Unloaded" event. -- @function [parent=#OPSTRANSPORT] OnAfterUnloaded -- @param #OPSGROUP self