diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 1ef4a3473..ceb9b3f55 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -109,7 +109,8 @@ function NAVYGROUP:New(GroupName) self:AddTransition("*", "Cruise", "Cruising") -- Hold position. self:AddTransition("*", "TurnIntoWind", "IntoWind") -- Command the group to turn into the wind. - self:AddTransition("*", "TurnIntoWindOver", "Cruising") -- Turn into wind is over. + self:AddTransition("IntoWind", "TurnIntoWindStop", "IntoWind") -- Stop a turn into wind. + self:AddTransition("IntoWind", "TurnIntoWindOver", "Cruising") -- Turn into wind is over. self:AddTransition("*", "TurningStarted", "*") -- Group started turning. self:AddTransition("*", "TurningStopped", "*") -- Group stopped turning. @@ -144,14 +145,6 @@ function NAVYGROUP:New(GroupName) -- Initialize the group. self:_InitGroup() - -- Debug trace. - if false then - self.Debug=true - BASE:TraceOnOff(true) - BASE:TraceClass(self.ClassName) - BASE:TraceLevel(1) - end - -- Handle events: self:HandleEvent(EVENTS.Birth, self.OnEventBirth) self:HandleEvent(EVENTS.Dead, self.OnEventDead) @@ -272,7 +265,7 @@ function NAVYGROUP:AddTaskAttackGroup(TargetGroup, WeaponExpend, WeaponType, Clo return task end ---- Add aircraft recovery time window and recovery case. +--- Create a turn into wind window. Note that this is not executed as it not added to the queue. -- @param #NAVYGROUP self -- @param #string starttime Start time, e.g. "8:00" for eight o'clock. Default now. -- @param #string stoptime Stop time, e.g. "9:00" for nine o'clock. Default 90 minutes after start time. @@ -280,7 +273,7 @@ end -- @param #boolean uturn If true (or nil), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint. -- @param #number offset Offset angle in degrees, e.g. to account for an angled runway. Default 0 deg. -- @return #NAVYGROUP.IntoWind Recovery window. -function NAVYGROUP:CreateTurnIntoWind(starttime, stoptime, speed, uturn, offset) +function NAVYGROUP:_CreateTurnIntoWind(starttime, stoptime, speed, uturn, offset) -- Absolute mission time in seconds. local Tnow=timer.getAbsTime() @@ -335,17 +328,17 @@ function NAVYGROUP:CreateTurnIntoWind(starttime, stoptime, speed, uturn, offset) return recovery end ---- Add aircraft recovery time window and recovery case. +--- Add a time window, where the groups steams into the wind. -- @param #NAVYGROUP self -- @param #string starttime Start time, e.g. "8:00" for eight o'clock. Default now. -- @param #string stoptime Stop time, e.g. "9:00" for nine o'clock. Default 90 minutes after start time. -- @param #number speed Speed in knots during turn into wind leg. --- @param #boolean uturn If true (or nil), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint. +-- @param #boolean uturn If `true` (or `nil`), carrier wil perform a U-turn and go back to where it came from before resuming its route to the next waypoint. If false, it will go directly to the next waypoint. -- @param #number offset Offset angle in degrees, e.g. to account for an angled runway. Default 0 deg. --- @return #NAVYGROUP.IntoWind Recovery window. +-- @return #NAVYGROUP.IntoWind Turn into window data table. function NAVYGROUP:AddTurnIntoWind(starttime, stoptime, speed, uturn, offset) - local recovery=self:CreateTurnIntoWind(starttime, stoptime, speed, uturn, offset) + local recovery=self:_CreateTurnIntoWind(starttime, stoptime, speed, uturn, offset) --TODO: check if window is overlapping with an other and if extend the window. @@ -355,6 +348,29 @@ function NAVYGROUP:AddTurnIntoWind(starttime, stoptime, speed, uturn, offset) return recovery end +--- Remove steam into wind window from queue. If the window is currently active, it is stopped first. +-- @param #NAVYGROUP self +-- @param #NAVYGROUP.IntoWind IntoWindData Turn into window data table. +-- @return #NAVYGROUP self +function NAVYGROUP:RemoveTurnIntoWind(IntoWindData) + + -- Check if this is a window currently open. + if self.intowind and self.intowind.id==IntoWindData.Id then + self:TurnIntoWindStop() + return + end + + for i,_tiw in pairs(self.Qintowind) do + local tiw=_tiw --#NAVYGROUP.IntoWind + if tiw.Id==IntoWindData.Id then + table.remove(self.Qintowind, i) + break + end + end + + return self +end + --- Check if the group is currently holding its positon. -- @param #NAVYGROUP self @@ -757,14 +773,35 @@ function NAVYGROUP:onafterTurnIntoWind(From, Event, To, IntoWind) end +--- On before "TurnIntoWindStop" event. +-- @param #NAVYGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +function NAVYGROUP:onbeforeTurnIntoWindStop(From, Event, To) + + if self.intowind then + return true + else + return false + end + +end + +--- On after "TurnIntoWindStop" event. +-- @param #NAVYGROUP self +-- @param #string From From state. +-- @param #string Event Event. +-- @param #string To To state. +function NAVYGROUP:onafterTurnIntoWindStop(From, Event, To) + self:TurnIntoWindOver() +end + --- On after "TurnIntoWindOver" event. -- @param #NAVYGROUP self -- @param #string From From state. -- @param #string Event Event. -- @param #string To To state. --- @param #number Duration Duration in seconds. --- @param #number Speed Speed in knots. --- @param #boolean Uturn Return to the place we came from. function NAVYGROUP:onafterTurnIntoWindOver(From, Event, To) -- Debug message. diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 733cdd056..d0e7e5e78 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3440,21 +3440,25 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) opsgroup.speed=wpnext.speed end + + -- Debug message. + local text=string.format("Group passing waypoint uid=%d", uid) + opsgroup:T(opsgroup.lid..text) - -- Check if the group is still pathfinding. - if opsgroup.ispathfinding and not waypoint.astar then - opsgroup.ispathfinding=false - end - - -- Check special waypoints. + -- Trigger PassingWaypoint event. if waypoint.astar then - + + -- Remove Astar waypoint. opsgroup:RemoveWaypointByID(uid) + -- Cruise. + opsgroup:Cruise() + elseif waypoint.detour then + -- Remove detour waypoint. opsgroup:RemoveWaypointByID(uid) - + -- Trigger event. opsgroup:DetourReached() @@ -3466,14 +3470,12 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) opsgroup:E("ERROR: waypoint.detour should be 0 or 1") end - end - - -- Debug message. - local text=string.format("Group passing waypoint uid=%d", uid) - opsgroup:T(opsgroup.lid..text) - - -- Trigger PassingWaypoint event. - if not (waypoint.astar or waypoint.detour) then + else + + -- Check if the group is still pathfinding. + if opsgroup.ispathfinding then + opsgroup.ispathfinding=false + end -- Increase passing counter. waypoint.npassed=waypoint.npassed+1