From 4b60f776ce434757bfc0ca08809dec8759d55891 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Wed, 2 Aug 2017 12:41:35 +0200 Subject: [PATCH] Apply randomization at start for schedules. Apply randomization at start for schedules. --- Moose Development/Moose/AI/AI_A2A_Cap.lua | 10 +++------- .../Moose/AI/AI_A2A_Dispatcher.lua | 10 +++++++++- Moose Development/Moose/AI/AI_A2A_Gci.lua | 6 +++--- Moose Development/Moose/AI/AI_A2A_Patrol.lua | 20 ++++++++++++------- .../Moose/Core/ScheduleDispatcher.lua | 6 +++--- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Moose Development/Moose/AI/AI_A2A_Cap.lua b/Moose Development/Moose/AI/AI_A2A_Cap.lua index 1b365bc17..bd38bd29a 100644 --- a/Moose Development/Moose/AI/AI_A2A_Cap.lua +++ b/Moose Development/Moose/AI/AI_A2A_Cap.lua @@ -356,8 +356,8 @@ function AI_A2A_CAP.AttackRoute( AIGroup ) local _AI_A2A_CAP = AIGroup:GetState( AIGroup, "AI_A2A_CAP" ) -- AI.AI_Cap#AI_A2A_CAP _AI_A2A_CAP:__Engage( 0.5 ) - local Task = AIGroup:TaskOrbitCircle( 4000, 400 ) - AIGroup:SetTask( Task ) + --local Task = AIGroup:TaskOrbitCircle( 4000, 400 ) + --AIGroup:SetTask( Task ) end end @@ -434,10 +434,6 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit ) end end - --- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable... - self.Controllable:WayPointInitialize( EngageRoute ) - - if #AttackTasks == 0 then self:E("No targets found -> Going back to Patrolling") self:__Abort( 0.5 ) @@ -446,7 +442,7 @@ function AI_A2A_CAP:onafterEngage( AIGroup, From, Event, To, AttackSetUnit ) AIGroup:OptionROTPassiveDefense() AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, 1, "AI_A2A_CAP.AttackRoute" ) - AttackTasks[#AttackTasks+1] = AIGroup:TaskOrbitCircle( 4000, self.PatrolMinSpeed ) + --AttackTasks[#AttackTasks+1] = AIGroup:TaskOrbitCircle( AIGroup:GetHeight(), self.PatrolMinSpeed ) EngageRoute[1].task = AIGroup:TaskCombo( AttackTasks ) diff --git a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua index e164e3cd1..3d2d67dd1 100644 --- a/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua +++ b/Moose Development/Moose/AI/AI_A2A_Dispatcher.lua @@ -1482,10 +1482,18 @@ do -- AI_A2A_DISPATCHER Cap.CapLimit = CapLimit Cap.Scheduler = Cap.Scheduler or SCHEDULER:New( self ) local Scheduler = Cap.Scheduler -- Core.Scheduler#SCHEDULER + local ScheduleID = Cap.ScheduleID local Variance = ( Cap.HighInterval - Cap.LowInterval ) / 2 local Median = Cap.LowInterval + Variance local Randomization = Variance / Median - Scheduler:Schedule(self, self.SchedulerCAP, { SquadronName }, Median, Median, Randomization ) + + self:E({Randomization = Randomization}) + + if ScheduleID then + Scheduler:Stop( ScheduleID ) + end + + Cap.ScheduleID = Scheduler:Schedule( self, self.SchedulerCAP, { SquadronName }, Median, Median, Randomization ) else error( "This squadron does not exist:" .. SquadronName ) end diff --git a/Moose Development/Moose/AI/AI_A2A_Gci.lua b/Moose Development/Moose/AI/AI_A2A_Gci.lua index 2986be4fd..17107c514 100644 --- a/Moose Development/Moose/AI/AI_A2A_Gci.lua +++ b/Moose Development/Moose/AI/AI_A2A_Gci.lua @@ -319,8 +319,8 @@ function AI_A2A_GCI.InterceptRoute( AIGroup ) local _AI_A2A_GCI = AIGroup:GetState( AIGroup, "AI_A2A_GCI" ) -- AI.AI_Cap#AI_A2A_GCI _AI_A2A_GCI:__Engage( 0.5 ) - local Task = AIGroup:TaskOrbitCircle( 4000, 400 ) - AIGroup:SetTask( Task ) + --local Task = AIGroup:TaskOrbitCircle( 4000, 400 ) + --AIGroup:SetTask( Task ) end end @@ -418,7 +418,7 @@ function AI_A2A_GCI:onafterEngage( AIGroup, From, Event, To, AttackSetUnit ) AIGroup:OptionROTPassiveDefense() AttackTasks[#AttackTasks+1] = AIGroup:TaskFunction( 1, 1, "AI_A2A_GCI.InterceptRoute" ) - AttackTasks[#AttackTasks+1] = AIGroup:TaskOrbitCircle( 4000, self.EngageMinSpeed ) + --AttackTasks[#AttackTasks+1] = AIGroup:TaskOrbitCircle( AIGroup:GetHeight(), self.EngageMinSpeed ) EngageRoute[#EngageRoute].task = AIGroup:TaskCombo( AttackTasks ) --- Do a trick, link the NewEngageRoute function of the object to the AIControllable in a temporary variable ... diff --git a/Moose Development/Moose/AI/AI_A2A_Patrol.lua b/Moose Development/Moose/AI/AI_A2A_Patrol.lua index 12b59918f..47ca407a6 100644 --- a/Moose Development/Moose/AI/AI_A2A_Patrol.lua +++ b/Moose Development/Moose/AI/AI_A2A_Patrol.lua @@ -317,8 +317,13 @@ end -- Note that this method is required, as triggers the next route when patrolling for the Controllable. function AI_A2A_PATROL.PatrolRoute( AIGroup ) - local _AI_A2A_Patrol = AIGroup:GetState( AIGroup, "AI_A2A_PATROL" ) -- #AI_A2A_PATROL - _AI_A2A_Patrol:Route() + AIGroup:E( { "AI_A2A_PATROL.PatrolRoute:", AIGroup:GetName() } ) + + if AIGroup:IsAlive() then + local _AI_A2A_Patrol = AIGroup:GetState( AIGroup, "AI_A2A_PATROL" ) -- #AI_A2A_PATROL + _AI_A2A_Patrol:Route() + end + end @@ -347,7 +352,8 @@ function AI_A2A_PATROL:onafterRoute( AIGroup, From, Event, To ) local CurrentCoord = AIGroup:GetCoordinate() local ToTargetCoord = self.PatrolZone:GetRandomPointVec2() - ToTargetCoord:SetAlt(math.random( self.PatrolFloorAltitude,self.PatrolCeilingAltitude ) ) + self:E({self.PatrolFloorAltitude, self.PatrolCeilingAltitude}) + ToTargetCoord:SetAlt( math.random( self.PatrolFloorAltitude, self.PatrolCeilingAltitude ) ) self:SetTargetDistance( ToTargetCoord ) -- For RTB status check local ToTargetSpeed = math.random( self.PatrolMinSpeed, self.PatrolMaxSpeed ) @@ -364,9 +370,6 @@ function AI_A2A_PATROL:onafterRoute( AIGroup, From, Event, To ) PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint PatrolRoute[#PatrolRoute+1] = ToPatrolRoutePoint - --- Now we're going to do something special, we're going to call a function from a waypoint action at the AIControllable... - AIGroup:WayPointInitialize( PatrolRoute ) - local Tasks = {} Tasks[#Tasks+1] = AIGroup:TaskFunction( 1, 1, "AI_A2A_PATROL.PatrolRoute" ) @@ -375,8 +378,11 @@ function AI_A2A_PATROL:onafterRoute( AIGroup, From, Event, To ) --- Do a trick, link the NewPatrolRoute function of the PATROLGROUP object to the AIControllable in a temporary variable ... AIGroup:SetState( AIGroup, "AI_A2A_PATROL", self ) + AIGroup:OptionROEReturnFire() + AIGroup:OptionROTPassiveDefense() + --- NOW ROUTE THE GROUP! - AIGroup:WayPointExecute( 1, 2 ) + AIGroup:SetTask( AIGroup:TaskRoute( PatrolRoute ), 0.5 ) end end diff --git a/Moose Development/Moose/Core/ScheduleDispatcher.lua b/Moose Development/Moose/Core/ScheduleDispatcher.lua index 7ba478111..ca8f77150 100644 --- a/Moose Development/Moose/Core/ScheduleDispatcher.lua +++ b/Moose Development/Moose/Core/ScheduleDispatcher.lua @@ -79,8 +79,8 @@ function SCHEDULEDISPATCHER:AddSchedule( Scheduler, ScheduleFunction, ScheduleAr self.Schedule[Scheduler][self.CallID].Arguments = ScheduleArguments self.Schedule[Scheduler][self.CallID].StartTime = timer.getTime() + ( Start or 0 ) self.Schedule[Scheduler][self.CallID].Start = Start + .1 - self.Schedule[Scheduler][self.CallID].Repeat = Repeat - self.Schedule[Scheduler][self.CallID].Randomize = Randomize + self.Schedule[Scheduler][self.CallID].Repeat = Repeat or 0 + self.Schedule[Scheduler][self.CallID].Randomize = Randomize or 0 self.Schedule[Scheduler][self.CallID].Stop = Stop self:T3( self.Schedule[Scheduler][self.CallID] ) @@ -185,7 +185,7 @@ function SCHEDULEDISPATCHER:Start( Scheduler, CallID ) Schedule[CallID].ScheduleID = timer.scheduleFunction( Schedule[CallID].CallHandler, CallID, - timer.getTime() + Schedule[CallID].Start + timer.getTime() + Schedule[CallID].Start + math.random( - ( Schedule[CallID].Randomize * Schedule[CallID].Repeat / 2 ), ( Schedule[CallID].Randomize * Schedule[CallID].Repeat / 2 ) ) ) end else