OPSTRANSPORT v0.4.2

- Some fixed.
- All tested demo missions look nice
This commit is contained in:
Frank 2021-09-02 08:30:54 +02:00
parent 27632ecdd9
commit 1bd5e7472f
4 changed files with 75 additions and 42 deletions

View File

@ -888,19 +888,25 @@ function FLIGHTGROUP:Status()
-- Short info. -- Short info.
if self.verbose>=1 then if self.verbose>=1 then
local nelem=self:CountElements()
local Nelem=#self.elements
local nTaskTot, nTaskSched, nTaskWP=self:CountRemainingTasks() local nTaskTot, nTaskSched, nTaskWP=self:CountRemainingTasks()
local nMissions=self:CountRemainingMissison() 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 home=self.homebase and self.homebase:GetName() or "unknown"
local dest=self.destbase and self.destbase: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 fc=self.flightcontrol and self.flightcontrol.airbasename or "N/A"
local curr=self.currbase and self.currbase:GetName() 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 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", 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, self.currentwp or 0, self.waypoints and #self.waypoints or 0, tostring(self.passedfinalwp), fsmstate, nelem, Nelem,
ndetected, home, dest, curr, fc) nTaskTot, nMissions, currT, currM, tostring(self:HasTaskController()),
currW, nWp, tostring(self.passedfinalwp), curr, home, dest)
self:I(self.lid..text) self:I(self.lid..text)
end end
@ -1814,10 +1820,6 @@ function FLIGHTGROUP:onafterLanded(From, Event, To, airbase)
self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.TAXIINB) self.flightcontrol:SetFlightStatus(self, FLIGHTCONTROL.FlightStatus.TAXIINB)
end end
if airbase and self.isHelo then
self:Arrived()
end
end end
--- On after "LandedAt" event. --- On after "LandedAt" event.
@ -1993,7 +1995,7 @@ function FLIGHTGROUP:onbeforeUpdateRoute(From, Event, To, n)
allowed=false allowed=false
end end
if self:IsUncontrolled() then if allowed and self:IsUncontrolled() then
-- Not airborne yet. Try again in 5 sec. -- Not airborne yet. Try again in 5 sec.
self:T(self.lid.."Update route denied. Group is UNCONTROLLED ==> checking back in 5 sec") self:T(self.lid.."Update route denied. Group is UNCONTROLLED ==> checking back in 5 sec")
trepeat=-5 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: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) self:Wait(waittime)
elseif destbase then elseif destbase then
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:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTB!")
--self:RTB(destbase)
self:__RTB(-0.1, destbase) self:__RTB(-0.1, destbase)
end
elseif destzone then elseif destzone then
self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTZ!") self:T(self.lid.."Passed Final WP and No current and/or future missions/tasks/transports ==> RTZ!")
self:__RTZ(-0.1, destzone) 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) local c2=c0:GetIntermediateCoordinate(p0, 0.75):SetAltitude(self.altitudeCruise, true)
-- Altitude above ground for a glide slope of 3 degrees. -- Altitude above ground for a glide slope of 3 degrees.
local x1=self.isHelo and UTILS.NMToMeters(5.0) or UTILS.NMToMeters(10) local x1=self.isHelo and UTILS.NMToMeters(2.0) or UTILS.NMToMeters(10)
local x2=self.isHelo and UTILS.NMToMeters(2.5) or UTILS.NMToMeters(5) local x2=self.isHelo and UTILS.NMToMeters(1.0) or UTILS.NMToMeters(5)
local alpha=math.rad(3) local alpha=math.rad(3)
local h1=x1*math.tan(alpha) local h1=x1*math.tan(alpha)
local h2=x2*math.tan(alpha) local h2=x2*math.tan(alpha)
@ -2866,6 +2872,8 @@ function FLIGHTGROUP:onafterLandAt(From, Event, To, Coordinate, Duration)
-- Duration. -- Duration.
--Duration=Duration or 600 --Duration=Duration or 600
self:T(self.lid..string.format("Landing at Coordinate for %s seconds", tostring(Duration)))
Coordinate=Coordinate or self:GetCoordinate() Coordinate=Coordinate or self:GetCoordinate()
local DCStask=self.group:TaskLandAtVec2(Coordinate:GetVec2(), Duration) local DCStask=self.group:TaskLandAtVec2(Coordinate:GetVec2(), Duration)

View File

@ -1460,7 +1460,9 @@ end
-- @param #NAVYGROUP self -- @param #NAVYGROUP self
-- @return #boolean If true, a path was found. -- @return #boolean If true, a path was found.
function NAVYGROUP:_FindPathToNextWaypoint() 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* -- Pathfinding A*
local astar=ASTAR:New() local astar=ASTAR:New()

View File

@ -512,8 +512,6 @@ function OPSGROUP:New(group)
end end
end end
self.group:IsAir()
-- Set the template. -- Set the template.
self:_SetTemplate() self:_SetTemplate()
@ -1812,7 +1810,7 @@ function OPSGROUP:IsInZone(Zone)
if vec2 then if vec2 then
is=Zone:IsVec2InZone(vec2) is=Zone:IsVec2InZone(vec2)
else else
env.info(self.lid.."FF cannot get vec2") self:T3(self.lid.."WARNING: Cannot get vec2 at IsInZone()!")
end end
return is return is
end end
@ -2783,14 +2781,13 @@ end
--- Returns true if the DCS controller currently has a task. --- Returns true if the DCS controller currently has a task.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #number Delay Delay in seconds.
-- @return #boolean True or false if the controller has a task. Nil if no controller. -- @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 local hastask=nil
if self.controller then if self.controller then
hastask=self.controller:hasTask() hastask=self.controller:hasTask()
end 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 return hastask
end 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. -- 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 if self:GetTaskCurrent()==nil then
--env.info("FF adding current task to queue")
table.insert(self.taskqueue, Task) table.insert(self.taskqueue, Task)
end 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. -- 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 -- 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. -- 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:PushTask(TaskFinal)
self:SetTask(TaskFinal) --self:SetTask(TaskFinal)
elseif Task.type==OPSGROUP.TaskType.WAYPOINT then elseif Task.type==OPSGROUP.TaskType.WAYPOINT then
@ -3467,7 +3465,7 @@ function OPSGROUP:onafterTaskDone(From, Event, To, Task)
end end
if Task.description=="Task_Land_At" then if Task.description=="Task_Land_At" then
self:Wait(60, 100) self:Wait(20, 100)
else else
self:T(self.lid.."Task Done but NO mission found ==> _CheckGroupDone in 0 sec") self:T(self.lid.."Task Done but NO mission found ==> _CheckGroupDone in 0 sec")
self:_CheckGroupDone() self:_CheckGroupDone()
@ -5065,7 +5063,7 @@ end
function OPSGROUP:onbeforeElementSpawned(From, Event, To, Element) function OPSGROUP:onbeforeElementSpawned(From, Event, To, Element)
if Element and Element.status==OPSGROUP.ElementStatus.SPAWNED then 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 return false
end end
@ -5333,7 +5331,7 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
self:_InitWaypoints() self:_InitWaypoints()
-- Init Group. -- Init Group.
self:_InitGroup() self:_InitGroup(Template)
-- Reset events. -- Reset events.
--self:ResetEvents() --self:ResetEvents()
@ -5883,7 +5881,6 @@ function OPSGROUP:_CheckDelivered(CargoTransport)
elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then
-- This one is dead. -- This one is dead.
else else
--env.info(string.format())
done=false --Someone is not done! done=false --Someone is not done!
end end
@ -6416,7 +6413,7 @@ function OPSGROUP:onafterPickup(From, Event, To)
end end
-- Order group to land at an airbase. -- Order group to land at an airbase.
self:__LandAtAirbase(-0.5, airbasePickup) self:__LandAtAirbase(-0.1, airbasePickup)
elseif self.isHelo then elseif self.isHelo then
@ -6426,7 +6423,7 @@ function OPSGROUP:onafterPickup(From, Event, To)
-- Activate uncontrolled group. -- Activate uncontrolled group.
if self:IsParking() and self:IsUncontrolled() then if self:IsParking() and self:IsUncontrolled() then
self:StartUncontrolled(1) self:StartUncontrolled(0.5)
end end
-- If this is a helo and no ZONE_AIRBASE was given, we make the helo land in the pickup zone. -- 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") self:E(self.lid.."ERROR: Transportcarrier aircraft cannot land in Pickup zone! Specify a ZONE_AIRBASE as pickup zone")
end 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 elseif self:IsNavygroup() then
--- ---
@ -6793,14 +6800,18 @@ 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. -- 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 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. else
if self:IsFlightgroup() and self:IsLandedAt() then self:E(self.lid.."ERROR: Aircraft (cargo carrier) cannot land in Deploy zone! Specify a ZONE_AIRBASE as deploy zone")
local Task=self:GetTaskCurrent()
self:__TaskCancel(5, Task)
end 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 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: No current task but landed at?!")
end
end end
elseif self:IsArmygroup() then elseif self:IsArmygroup() then
@ -7179,9 +7190,22 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport)
-- Startup uncontrolled aircraft to allow it to go back. -- Startup uncontrolled aircraft to allow it to go back.
if self:IsFlightgroup() then 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() self:StartUncontrolled()
elseif self:IsLandedAt() then end
if self:IsLandedAt() then
local Task=self:GetTaskCurrent() local Task=self:GetTaskCurrent()
self:TaskCancel(Task) self:TaskCancel(Task)
end end
@ -7191,7 +7215,7 @@ function OPSGROUP:onafterDelivered(From, Event, To, CargoTransport)
end end
-- Check group done. -- 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) self:_CheckGroupDone(0.2)
-- No current transport any more. -- No current transport any more.

View File

@ -173,7 +173,7 @@ _OPSTRANSPORTID=0
--- Army Group version. --- Army Group version.
-- @field #string version -- @field #string version
OPSTRANSPORT.version="0.4.1" OPSTRANSPORT.version="0.4.2"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- 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 OpsGroupCargo Cargo OPSGROUP that was unloaded from a carrier.
-- @param Ops.OpsGroup#OPSGROUP OpsGroupCarrier Carrier OPSGROUP that unloaded the cargo. -- @param Ops.OpsGroup#OPSGROUP OpsGroupCarrier Carrier OPSGROUP that unloaded the cargo.
--- On after "Unloaded" event. --- On after "Unloaded" event.
-- @function [parent=#OPSTRANSPORT] OnAfterUnloaded -- @function [parent=#OPSTRANSPORT] OnAfterUnloaded
-- @param #OPSGROUP self -- @param #OPSGROUP self