mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS and SCHEDULER
This commit is contained in:
parent
1a53f58540
commit
f67cf99477
@ -873,7 +873,7 @@ do -- Scheduling
|
||||
-- @param #number Start Specifies the amount of seconds that will be waited before the scheduling is started, and the event function is called.
|
||||
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
|
||||
-- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
||||
-- @return #number The ScheduleID of the planned schedule.
|
||||
-- @return #string The Schedule ID of the planned schedule.
|
||||
function BASE:ScheduleOnce( Start, SchedulerFunction, ... )
|
||||
self:F2( { Start } )
|
||||
self:T3( { ... } )
|
||||
@ -887,6 +887,8 @@ do -- Scheduling
|
||||
self.Scheduler = SCHEDULER:New( self )
|
||||
end
|
||||
|
||||
-- FF this was wrong!
|
||||
--[[
|
||||
local ScheduleID = _SCHEDULEDISPATCHER:AddSchedule(
|
||||
self,
|
||||
SchedulerFunction,
|
||||
@ -896,6 +898,10 @@ do -- Scheduling
|
||||
nil,
|
||||
nil
|
||||
)
|
||||
]]
|
||||
|
||||
-- NOTE: MasterObject (first parameter) needs to be nil or it will be the first argument passed to the SchedulerFunction!
|
||||
local ScheduleID = self.Scheduler:Schedule(nil, SchedulerFunction, {...}, Start, nil, nil, nil)
|
||||
|
||||
self._.Schedules[#self._.Schedules+1] = ScheduleID
|
||||
|
||||
@ -910,7 +916,7 @@ do -- Scheduling
|
||||
-- @param #number Stop Specifies the amount of seconds when the scheduler will be stopped.
|
||||
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
|
||||
-- @param #table ... Optional arguments that can be given as part of scheduler. The arguments need to be given as a table { param1, param 2, ... }.
|
||||
-- @return #number The ScheduleID of the planned schedule.
|
||||
-- @return #string The Schedule ID of the planned schedule.
|
||||
function BASE:ScheduleRepeat( Start, Repeat, RandomizeFactor, Stop, SchedulerFunction, ... )
|
||||
self:F2( { Start } )
|
||||
self:T3( { ... } )
|
||||
@ -924,6 +930,7 @@ do -- Scheduling
|
||||
self.Scheduler = SCHEDULER:New( self )
|
||||
end
|
||||
|
||||
-- NOTE: MasterObject (first parameter) should(!) be nil as it will be the first argument passed to the SchedulerFunction!
|
||||
local ScheduleID = self.Scheduler:Schedule(
|
||||
self,
|
||||
SchedulerFunction,
|
||||
@ -942,13 +949,13 @@ do -- Scheduling
|
||||
|
||||
--- Stops the Schedule.
|
||||
-- @param #BASE self
|
||||
-- @param #function SchedulerFunction The event function to be called when a timer event occurs. The event function needs to accept the parameters specified in SchedulerArguments.
|
||||
function BASE:ScheduleStop( SchedulerFunction )
|
||||
|
||||
-- @param #string SchedulerID (Optional) Scheduler ID to be stopped. If nil, all pending schedules are stopped.
|
||||
function BASE:ScheduleStop( SchedulerID )
|
||||
self:F3( { "ScheduleStop:" } )
|
||||
|
||||
if self.Scheduler then
|
||||
_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] )
|
||||
--_SCHEDULEDISPATCHER:Stop( self.Scheduler, self._.Schedules[SchedulerFunction] )
|
||||
_SCHEDULEDISPATCHER:Stop(self.Scheduler, SchedulerID)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1431,7 +1431,7 @@ do -- FSM_SET
|
||||
-- @param #FSM_SET self
|
||||
-- @return Core.Set#SET_BASE
|
||||
function FSM_SET:Get()
|
||||
return self.Controllable
|
||||
return self.Set
|
||||
end
|
||||
|
||||
function FSM_SET:_call_handler( step, trigger, params, EventName )
|
||||
|
||||
@ -317,7 +317,7 @@ end
|
||||
--- Stop dispatcher.
|
||||
-- @param #SCHEDULEDISPATCHER self
|
||||
-- @param Core.Scheduler#SCHEDULER Scheduler Scheduler object.
|
||||
-- @param #table CallID Call ID.
|
||||
-- @param #string CallID (Optional) Scheduler Call ID. If nil, all pending schedules are stopped recursively.
|
||||
function SCHEDULEDISPATCHER:Stop( Scheduler, CallID )
|
||||
self:F2( { Stop = CallID, Scheduler = Scheduler } )
|
||||
|
||||
|
||||
@ -238,7 +238,7 @@ end
|
||||
-- @param #number Stop Time interval in seconds after which the scheduler will be stoppe.
|
||||
-- @param #number TraceLevel Trace level [0,3]. Default 3.
|
||||
-- @param Core.Fsm#FSM Fsm Finite state model.
|
||||
-- @return #table The ScheduleID of the planned schedule.
|
||||
-- @return #string The Schedule ID of the planned schedule.
|
||||
function SCHEDULER:Schedule( MasterObject, SchedulerFunction, SchedulerArguments, Start, Repeat, RandomizeFactor, Stop, TraceLevel, Fsm )
|
||||
self:F2( { Start, Repeat, RandomizeFactor, Stop } )
|
||||
self:T3( { SchedulerArguments } )
|
||||
@ -273,7 +273,7 @@ end
|
||||
|
||||
--- (Re-)Starts the schedules or a specific schedule if a valid ScheduleID is provided.
|
||||
-- @param #SCHEDULER self
|
||||
-- @param #string ScheduleID (Optional) The ScheduleID of the planned (repeating) schedule.
|
||||
-- @param #string ScheduleID (Optional) The Schedule ID of the planned (repeating) schedule.
|
||||
function SCHEDULER:Start( ScheduleID )
|
||||
self:F3( { ScheduleID } )
|
||||
self:T(string.format("Starting scheduler ID=%s", tostring(ScheduleID)))
|
||||
|
||||
@ -3989,9 +3989,21 @@ function WAREHOUSE:onafterAddAsset(From, Event, To, group, ngroups, forceattribu
|
||||
-- Destroy group if it is alive.
|
||||
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.
|
||||
-- TODO: It would be nice, however, to have the remove event.
|
||||
group:Destroy() --(false)
|
||||
|
||||
local opsgroup=_DATABASE:GetOpsGroup(group:GetName())
|
||||
if opsgroup then
|
||||
opsgroup:Despawn(0)
|
||||
opsgroup:__Stop(-0.01)
|
||||
else
|
||||
-- Setting parameter to false, i.e. creating NO dead or remove unit event, seems to not confuse the dispatcher logic.
|
||||
-- TODO: It would be nice, however, to have the remove event.
|
||||
group:Destroy() --(false)
|
||||
end
|
||||
else
|
||||
local opsgroup=_DATABASE:GetOpsGroup(group:GetName())
|
||||
if opsgroup then
|
||||
opsgroup:Stop()
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
@ -8766,7 +8778,7 @@ end
|
||||
-- @param #number duration Message display duration in seconds. Default 20 sec. If duration is zero, no message is displayed.
|
||||
function WAREHOUSE:_DebugMessage(text, duration)
|
||||
duration=duration or 20
|
||||
if duration>0 then
|
||||
if self.Debug and duration>0 then
|
||||
MESSAGE:New(text, duration):ToAllIf(self.Debug)
|
||||
end
|
||||
self:T(self.lid..text)
|
||||
|
||||
@ -1178,7 +1178,7 @@ function ARMYGROUP:_InitGroup(Template)
|
||||
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
|
||||
|
||||
-- Set default formation from first waypoint.
|
||||
self.optionDefault.Formation=self:GetWaypoint(1).action
|
||||
self.optionDefault.Formation=template.route.points[1].action --self:GetWaypoint(1).action
|
||||
|
||||
-- Default TACAN off.
|
||||
self:SetDefaultTACAN(nil, nil, nil, nil, true)
|
||||
|
||||
@ -1970,6 +1970,7 @@ function FLIGHTGROUP:onafterArrived(From, Event, To)
|
||||
|
||||
else
|
||||
-- Depawn after 5 min. Important to trigger dead events before DCS despawns on its own without any notification.
|
||||
self:T(self.lid..string.format("Despawning group in 5 minutes after arrival!"))
|
||||
self:Despawn(5*60)
|
||||
end
|
||||
end
|
||||
|
||||
@ -546,7 +546,7 @@ function OPSGROUP:New(group)
|
||||
-- From State --> Event --> To State
|
||||
self:AddTransition("InUtero", "Spawned", "Spawned") -- The whole group was spawned.
|
||||
self:AddTransition("*", "Respawn", "InUtero") -- Respawn group.
|
||||
self:AddTransition("*", "Dead", "Dead") -- The whole group is dead.
|
||||
self:AddTransition("*", "Dead", "InUtero") -- The whole group is dead and goes back to mummy.
|
||||
self:AddTransition("*", "InUtero", "InUtero") -- Deactivated group goes back to mummy.
|
||||
self:AddTransition("*", "Stop", "Stopped") -- Stop FSM.
|
||||
|
||||
@ -1326,8 +1326,10 @@ end
|
||||
function OPSGROUP:Despawn(Delay, NoEventRemoveUnit)
|
||||
|
||||
if Delay and Delay>0 then
|
||||
self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit)
|
||||
self.scheduleIDDespawn=self:ScheduleOnce(Delay, OPSGROUP.Despawn, self, 0, NoEventRemoveUnit)
|
||||
else
|
||||
|
||||
self:I(self.lid..string.format("Despawning Group!"))
|
||||
|
||||
local DCSGroup=self:GetDCSGroup()
|
||||
|
||||
@ -1422,8 +1424,8 @@ end
|
||||
function OPSGROUP:Activate(delay)
|
||||
|
||||
if delay and delay>0 then
|
||||
self:T2(self.lid..string.format("Activating late activated group in %d seconds", delay))
|
||||
self:ScheduleOnce(delay, OPSGROUP.Activate, self)
|
||||
self:T2(self.lid..string.format("Activating late activated group in %d seconds", delay))
|
||||
self:ScheduleOnce(delay, OPSGROUP.Activate, self)
|
||||
else
|
||||
|
||||
if self:IsAlive()==false then
|
||||
@ -1750,16 +1752,11 @@ function OPSGROUP:IsSpawned()
|
||||
return is
|
||||
end
|
||||
|
||||
--- Check if group is dead.
|
||||
--- Check if group is dead. Could be destroyed or despawned. FSM state of dead group is `InUtero` though.
|
||||
-- @param #OPSGROUP self
|
||||
-- @return #boolean If true, all units/elements of the group are dead.
|
||||
function OPSGROUP:IsDead()
|
||||
if self.isDead then
|
||||
return true
|
||||
else
|
||||
local is=self:Is("Dead")
|
||||
return is
|
||||
end
|
||||
return self.isDead
|
||||
end
|
||||
|
||||
--- Check if group was destroyed.
|
||||
@ -4960,6 +4957,16 @@ function OPSGROUP:_Respawn(Delay, Template, Reset)
|
||||
return self
|
||||
end
|
||||
|
||||
--- On after "InUtero" event.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
-- @param #string To To state.
|
||||
function OPSGROUP:onafterInUtero(From, Event, To)
|
||||
self:T(self.lid..string.format("Group inutero at t=%.3f", timer.getTime()))
|
||||
--TODO: set element status to inutero
|
||||
end
|
||||
|
||||
--- On after "Destroyed" event.
|
||||
-- @param #OPSGROUP self
|
||||
-- @param #string From From state.
|
||||
@ -5031,8 +5038,7 @@ function OPSGROUP:onafterDead(From, Event, To)
|
||||
|
||||
-- No current cargo transport.
|
||||
self.cargoTransport=nil
|
||||
|
||||
|
||||
|
||||
-- Stop in a sec.
|
||||
--self:__Stop(-5)
|
||||
end
|
||||
@ -5083,6 +5089,9 @@ function OPSGROUP:onafterStop(From, Event, To)
|
||||
|
||||
-- Stop FSM scheduler.
|
||||
self.CallScheduler:Clear()
|
||||
if self.Scheduler then
|
||||
self.Scheduler:Clear()
|
||||
end
|
||||
|
||||
if self:IsAlive() and not (self:IsDead() or self:IsStopped()) then
|
||||
local life, life0=self:GetLifePoints()
|
||||
|
||||
@ -338,8 +338,7 @@ end
|
||||
-- If the first @{Wrapper.Unit} of the group is inactive, it will return false.
|
||||
--
|
||||
-- @param #GROUP self
|
||||
-- @return #boolean true if the group is alive and active.
|
||||
-- @return #boolean false if the group is alive but inactive or #nil if the group does not exist anymore.
|
||||
-- @return #boolean `true` if the group is alive *and* active, `false` if the group is alive but inactive or `#nil` if the group does not exist anymore.
|
||||
function GROUP:IsAlive()
|
||||
self:F2( self.GroupName )
|
||||
|
||||
@ -361,7 +360,7 @@ end
|
||||
|
||||
--- Returns if the group is activated.
|
||||
-- @param #GROUP self
|
||||
-- @return #boolean true if group is activated or #nil The group is not existing or alive.
|
||||
-- @return #boolean `true` if group is activated or `#nil` The group is not existing or alive.
|
||||
function GROUP:IsActive()
|
||||
self:F2( self.GroupName )
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user