mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-19 05:36:02 +00:00
Update RAT.lua
- RATMANAGER
This commit is contained in:
@@ -5873,7 +5873,7 @@ function RATMANAGER:New(ntot)
|
|||||||
self.ntot=ntot or 1
|
self.ntot=ntot or 1
|
||||||
|
|
||||||
-- Debug info
|
-- Debug info
|
||||||
self:E(RATMANAGER.id..string.format("Creating manager for %d groups.", ntot))
|
self:I(RATMANAGER.id..string.format("Creating manager for %d groups", ntot))
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -5915,7 +5915,9 @@ end
|
|||||||
function RATMANAGER:Start(delay)
|
function RATMANAGER:Start(delay)
|
||||||
|
|
||||||
-- Time delay.
|
-- Time delay.
|
||||||
local delay=delay or 5
|
delay=delay or 5
|
||||||
|
|
||||||
|
if delay and delay>0 then
|
||||||
|
|
||||||
-- Info text.
|
-- Info text.
|
||||||
local text=string.format(RATMANAGER.id.."RAT manager will be started in %d seconds.\n", delay)
|
local text=string.format(RATMANAGER.id.."RAT manager will be started in %d seconds.\n", delay)
|
||||||
@@ -5926,16 +5928,10 @@ function RATMANAGER:Start(delay)
|
|||||||
text=text..string.format("Number of constantly alive groups %d", self.ntot)
|
text=text..string.format("Number of constantly alive groups %d", self.ntot)
|
||||||
self:E(text)
|
self:E(text)
|
||||||
|
|
||||||
-- Start scheduler.
|
-- Delayed call
|
||||||
SCHEDULER:New(nil, self._Start, {self}, delay)
|
self:ScheduleOnce(delay, RATMANAGER.Start, self, 0)
|
||||||
|
|
||||||
return self
|
else
|
||||||
end
|
|
||||||
|
|
||||||
--- Instantly starts the RAT manager and spawns the initial random number RAT groups for each RAT object.
|
|
||||||
-- @param #RATMANAGER self
|
|
||||||
-- @return #RATMANAGER RATMANAGER self object.
|
|
||||||
function RATMANAGER:_Start()
|
|
||||||
|
|
||||||
-- Ensure that ntot is at least sum of min RAT groups.
|
-- Ensure that ntot is at least sum of min RAT groups.
|
||||||
local n=0
|
local n=0
|
||||||
@@ -5952,16 +5948,19 @@ function RATMANAGER:_Start()
|
|||||||
for i=1,self.nrat do
|
for i=1,self.nrat do
|
||||||
for j=1,N[i] do
|
for j=1,N[i] do
|
||||||
time=time+self.dTspawn
|
time=time+self.dTspawn
|
||||||
SCHEDULER:New(nil, RAT._SpawnWithRoute, {self.rat[i]}, time)
|
--SCHEDULER:New(nil, RAT._SpawnWithRoute, {self.rat[i]}, time)
|
||||||
|
self:ScheduleOnce(time, RAT._SpawnWithRoute, self.rat[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Start activation scheduler for uncontrolled aircraft.
|
-- Start activation scheduler for uncontrolled aircraft.
|
||||||
for i=1,self.nrat do
|
for i=1,self.nrat do
|
||||||
if self.rat[i].uncontrolled and self.rat[i].activate_uncontrolled then
|
local rat=self.rat[i] --#RAT
|
||||||
|
if rat.uncontrolled and rat.activate_uncontrolled then
|
||||||
-- Start activating stuff but not before the latest spawn has happend.
|
-- Start activating stuff but not before the latest spawn has happend.
|
||||||
local Tactivate=math.max(time+1, self.rat[i].activate_delay)
|
local Tactivate=math.max(time+1, rat.activate_delay)
|
||||||
SCHEDULER:New(self.rat[i], self.rat[i]._ActivateUncontrolled, {self.rat[i]}, Tactivate, self.rat[i].activate_delta, self.rat[i].activate_frand)
|
--SCHEDULER:New(self.rat[i], self.rat[i]._ActivateUncontrolled, {self.rat[i]}, Tactivate, self.rat[i].activate_delta, self.rat[i].activate_frand)
|
||||||
|
self:ScheduleRepeat(Tactivate,rat.activate_delta, rat.activate_frand, nil,rat._ActivateUncontrolled, rat)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -5973,30 +5972,41 @@ function RATMANAGER:_Start()
|
|||||||
|
|
||||||
-- Info
|
-- Info
|
||||||
local text=string.format(RATMANAGER.id.."Starting RAT manager with scheduler ID %s in %d seconds. Repeat interval %d seconds.", self.managerid, TstartManager, self.Tcheck)
|
local text=string.format(RATMANAGER.id.."Starting RAT manager with scheduler ID %s in %d seconds. Repeat interval %d seconds.", self.managerid, TstartManager, self.Tcheck)
|
||||||
self:E(text)
|
self:I(text)
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Stops the RAT manager.
|
--- Stops the RAT manager.
|
||||||
-- @param #RATMANAGER self
|
-- @param #RATMANAGER self
|
||||||
-- @param #number delay Delay in seconds before the manager is stopped. Default is 1 second.
|
-- @param #number delay Delay in seconds before the manager is stopped. Default is 1 second.
|
||||||
-- @return #RATMANAGER RATMANAGER self object.
|
-- @return #RATMANAGER RATMANAGER self object.
|
||||||
function RATMANAGER:Stop(delay)
|
function RATMANAGER:Stop(delay)
|
||||||
delay=delay or 1
|
delay=delay or 1
|
||||||
self:E(string.format(RATMANAGER.id.."Manager will be stopped in %d seconds.", delay))
|
|
||||||
SCHEDULER:New(nil, self._Stop, {self}, delay)
|
|
||||||
|
if delay and delay>0 then
|
||||||
|
|
||||||
|
self:I(RATMANAGER.id..string.format("Manager will be stopped in %d seconds.", delay))
|
||||||
|
|
||||||
|
self:ScheduleOnce(delay, RATMANAGER.Stop, self, 0)
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
self:I(RATMANAGER.id..string.format("Stopping manager with scheduler ID %s", self.managerid))
|
||||||
|
|
||||||
|
self.manager:Stop(self.managerid)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Instantly stops the RAT manager by terminating its scheduler.
|
|
||||||
-- @param #RATMANAGER self
|
|
||||||
-- @return #RATMANAGER RATMANAGER self object.
|
|
||||||
function RATMANAGER:_Stop()
|
|
||||||
self:E(string.format(RATMANAGER.id.."Stopping manager with scheduler ID %s.", self.managerid))
|
|
||||||
self.manager:Stop(self.managerid)
|
|
||||||
return self
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Sets the time interval between checks of alive RAT groups. Default is 60 seconds.
|
--- Sets the time interval between checks of alive RAT groups. Default is 60 seconds.
|
||||||
-- @param #RATMANAGER self
|
-- @param #RATMANAGER self
|
||||||
@@ -6025,8 +6035,7 @@ function RATMANAGER:_Manage()
|
|||||||
local ntot=self:_Count()
|
local ntot=self:_Count()
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
local text=string.format("Number of alive groups %d. New groups to be spawned %d.", ntot, self.ntot-ntot)
|
self:T(RATMANAGER.id..string.format("Number of alive groups %d. New groups to be spawned %d.", ntot, self.ntot-ntot))
|
||||||
self:T(RATMANAGER.id..text)
|
|
||||||
|
|
||||||
-- Get number of necessary spawns.
|
-- Get number of necessary spawns.
|
||||||
local N=self:_RollDice(self.nrat, self.ntot, self.min, self.alive)
|
local N=self:_RollDice(self.nrat, self.ntot, self.min, self.alive)
|
||||||
@@ -6037,7 +6046,8 @@ function RATMANAGER:_Manage()
|
|||||||
for j=1,N[i] do
|
for j=1,N[i] do
|
||||||
time=time+self.dTspawn
|
time=time+self.dTspawn
|
||||||
self.planned[i]=self.planned[i]+1
|
self.planned[i]=self.planned[i]+1
|
||||||
SCHEDULER:New(nil, RATMANAGER._Spawn, {self, i}, time)
|
--SCHEDULER:New(nil, RATMANAGER._Spawn, {self, i}, time)
|
||||||
|
self:ScheduleOnce(time, RATMANAGER._Spawn, self, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user