From 1949d69fa084616ef38efe015a2f285062506f46 Mon Sep 17 00:00:00 2001 From: Sven Van de Velde Date: Sat, 7 May 2016 06:59:15 +0200 Subject: [PATCH] Updated Anapa --- Moose/Group.lua | 19 ++++++++++++- Moose/MissileTrainer.lua | 10 +++---- Moose/{TimeTrigger.lua => Scheduler.lua} | 36 +++++++++++++----------- 3 files changed, 43 insertions(+), 22 deletions(-) rename Moose/{TimeTrigger.lua => Scheduler.lua} (67%) diff --git a/Moose/Group.lua b/Moose/Group.lua index a7d10f76a..e93f50b69 100644 --- a/Moose/Group.lua +++ b/Moose/Group.lua @@ -92,6 +92,18 @@ function GROUP:NewFromDCSUnit( DCSUnit ) return self end +--- Returns the name of the Group. +-- @param #GROUP self +-- @return #string GroupName +function GROUP:GetName() + + local GroupName = self.DCSGroup:getName() + + return GroupName +end + + + --- Retrieve the group mission and allow to place function hooks within the mission waypoint plan. -- Use the method @{Group#GROUP:WayPointFunction} to define the hook functions for specific waypoints. -- Use the method @{Group@GROUP:WayPointExecute) to start the execution of the new mission plan. @@ -128,7 +140,12 @@ function GROUP:TaskFunction( WayPoint, WayPointIndex, FunctionString, FunctionAr local DCSScript = {} DCSScript[#DCSScript+1] = "local MissionGroup = GROUP.FindGroup( ... ) " - DCSScript[#DCSScript+1] = FunctionString .. "( MissionGroup, " .. table.concat( FunctionArguments, "," ) .. ")" + + if FunctionArguments.n > 0 then + DCSScript[#DCSScript+1] = FunctionString .. "( MissionGroup, " .. table.concat( FunctionArguments, "," ) .. ")" + else + DCSScript[#DCSScript+1] = FunctionString .. "( MissionGroup )" + end DCSTask = self:TaskWrappedAction( self:CommandDoScript( diff --git a/Moose/MissileTrainer.lua b/Moose/MissileTrainer.lua index cc2c15aa9..e805103b4 100644 --- a/Moose/MissileTrainer.lua +++ b/Moose/MissileTrainer.lua @@ -3,7 +3,7 @@ -- @author FlightControl Include.File( "Client" ) -Include.File( "TimeTrigger" ) +Include.File( "Scheduler" ) --- The MISSILETRAINER class -- @type MISSILETRAINER @@ -13,7 +13,7 @@ MISSILETRAINER = { } --- Creates the main object which is handling missile tracking. --- When a missile is fired a TIMETRIGGER is set off that follows the missile. When near a certain a client player, the missile will be destroyed. +-- When a missile is fired a SCHEDULER is set off that follows the missile. When near a certain a client player, the missile will be destroyed. -- @param #MISSILETRAINER -- @param #number Distance The distance in meters when a tracked missile needs to be destroyed when close to a player. -- @return #MISSILETRAINER @@ -21,8 +21,8 @@ function MISSILETRAINER:New( Distance ) local self = BASE:Inherit( self, BASE:New() ) self:F( Distance ) - self.TimeTriggers = {} - self.TimeTriggerID = 0 + self.Schedulers = {} + self.SchedulerID = 0 self.Distance = Distance @@ -52,7 +52,7 @@ function MISSILETRAINER:_EventShot( Event ) self:T( TrainerTargetSkill ) if TrainerTargetSkill == "Client" or TrainerTargetSkill == "Player" then - self.TimeTriggers[#self.TimeTriggers+1] = TIMETRIGGER:New( self, self._FollowMissile, { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit }, 0.5, 0.05, 0 ) + self.Schedulers[#self.Schedulers+1] = SCHEDULER:New( self, self._FollowMissile, { TrainerSourceDCSUnit, TrainerWeapon, TrainerTargetDCSUnit }, 0.5, 0.05, 0 ) end end diff --git a/Moose/TimeTrigger.lua b/Moose/Scheduler.lua similarity index 67% rename from Moose/TimeTrigger.lua rename to Moose/Scheduler.lua index 345e576af..3134e2626 100644 --- a/Moose/TimeTrigger.lua +++ b/Moose/Scheduler.lua @@ -1,5 +1,5 @@ --- Models time events calling event handing functions. --- @module TimeTrigger +-- @module Scheduler -- @author FlightControl Include.File( "Routines" ) @@ -8,24 +8,24 @@ Include.File( "Cargo" ) Include.File( "Message" ) ---- The TIMETRIGGER class --- @type TIMETRIGGER +--- The SCHEDULER class +-- @type SCHEDULER -- @extends Base#BASE -TIMETRIGGER = { - ClassName = "TIMETRIGGER", +SCHEDULER = { + ClassName = "SCHEDULER", } ---- TIMETRIGGER constructor. --- @param #TIMETRIGGER self +--- SCHEDULER constructor. +-- @param #SCHEDULER self -- @param #function TimeEventFunction -- @param #table TimeEventFunctionArguments -- @param #number StartSeconds -- @param #number RepeatSecondsInterval -- @param #number RandomizationFactor -- @param #number StopSeconds --- @return #TIMETRIGGER -function TIMETRIGGER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds ) +-- @return #SCHEDULER +function SCHEDULER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds ) local self = BASE:Inherit( self, BASE:New() ) self:F( { TimeEventObject, TimeEventFunction, TimeEventFunctionArguments, StartSeconds, RepeatSecondsInterval, RandomizationFactor, StopSeconds } ) @@ -60,23 +60,27 @@ function TIMETRIGGER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionA return self end -function TIMETRIGGER:Scheduler() +function SCHEDULER:Scheduler() self:F( self.TimeEventFunctionArguments ) local ErrorHandler = function( errmsg ) - env.info( "Error in TIMETRIGGER function:" .. errmsg ) + env.info( "Error in SCHEDULER function:" .. errmsg ) env.info( debug.traceback() ) return errmsg end - local err, Result = xpcall( function() self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments, 1, table.maxn( self.TimeEventFunctionArguments ) ) ) end, ErrorHandler ) - if not err then - --env.info('routines.scheduleFunction, error in scheduled function: ' .. errmsg) + local Status, Result + if self.TimeEventObject then + Status, Result = xpcall( function() return self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) + else + Status, Result = xpcall( function() return self.TimeEventFunction( unpack( self.TimeEventFunctionArguments ) ) end, ErrorHandler ) end - - if Result and Result == true then + + self:T( { Status, Result } ) + + if Status and Status == true and Result and Result == true then if not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) then timer.scheduleFunction( self.Scheduler,