diff --git a/Moose/Group.lua b/Moose/Group.lua index 2e2676743..a7d10f76a 100644 --- a/Moose/Group.lua +++ b/Moose/Group.lua @@ -767,8 +767,41 @@ function GROUP:TaskAttackUnit( AttackUnit ) params = { unitId = AttackUnit:GetID(), expend = AI.Task.WeaponExpend.TWO, groupAttack = true, - } - } + }, + }, + + self:T( { DCSTask } ) + return DCSTask +end + +--- Attack a Group. +-- @param #GROUP self +-- @param Group#GROUP AttackGroup The Group to be attacked. +-- @return DCSTask#Task The DCS task structure. +function GROUP:TaskAttackGroup( AttackGroup ) + self:F( { self.GroupName, AttackGroup } ) + +-- AttackGroup = { +-- id = 'AttackGroup', +-- params = { +-- groupId = Group.ID, +-- weaponType = number, +-- expend = enum AI.Task.WeaponExpend, +-- attackQty = number, +-- directionEnabled = boolean, +-- direction = Azimuth, +-- altitudeEnabled = boolean, +-- altitude = Distance, +-- attackQtyLimit = boolean, +-- } +-- } + + local DCSTask + DCSTask = { id = 'AttackGroup', + params = { groupId = AttackGroup:GetID(), + expend = AI.Task.WeaponExpend.TWO, + }, + }, self:T( { DCSTask } ) return DCSTask diff --git a/Moose/Menu.lua b/Moose/Menu.lua index f386e118d..e5bdfa778 100644 --- a/Moose/Menu.lua +++ b/Moose/Menu.lua @@ -245,3 +245,127 @@ function MENU_CLIENT_COMMAND:Remove() self.ParentMenu.Menus[self.MenuPath] = nil return nil end + + +--- The MENU_COALITION class +-- @type MENU_COALITION +-- @extends Menu#MENU +MENU_COALITION = { + ClassName = "MENU_COALITION" +} + +--- Creates a new coalition menu item +-- @param #MENU_COALITION self +-- @param DCSCoalition#coalition.side MenuCoalition The coalition owning the menu. +-- @param #string MenuText The text for the menu. +-- @param #table ParentMenu The parent menu. +-- @return #MENU_COALITION self +function MENU_COALITION:New( MenuCoalition, MenuText, ParentMenu ) + + -- Arrange meta tables + local MenuParentPath = {} + if ParentMenu ~= nil then + MenuParentPath = ParentMenu.MenuPath + end + + local self = BASE:Inherit( self, MENU:New( MenuText, MenuParentPath ) ) + self:F( { MenuCoalition, MenuText, ParentMenu } ) + + self.MenuCoalition = MenuCoalition + self.MenuParentPath = MenuParentPath + self.MenuText = MenuText + self.ParentMenu = ParentMenu + + self.Menus = {} + + self:T( { MenuParentPath, MenuText } ) + + self.MenuPath = missionCommands.addSubMenuForCoalition( self.MenuCoalition, MenuText, MenuParentPath ) + + self:T( { self.MenuPath } ) + + if ParentMenu and ParentMenu.Menus then + ParentMenu.Menus[self.MenuPath] = self + end + return self +end + +--- Removes the sub menus recursively of this MENU_COALITION. +-- @param #MENU_COALITION self +-- @return #MENU_COALITION self +function MENU_COALITION:RemoveSubMenus() + self:F( self.MenuPath ) + + for MenuID, Menu in pairs( self.Menus ) do + Menu:Remove() + end + +end + +--- Removes the sub menus recursively of this MENU_COALITION. +-- @param #MENU_COALITION self +-- @return #MENU_COALITION self +function MENU_COALITION:Remove() + self:F( self.MenuPath ) + + self:RemoveSubMenus() + missionCommands.removeItemForCoalition( self.MenuCoalition, self.MenuPath ) + self.ParentMenu.Menus[self.MenuPath] = nil + + return nil +end + + +--- The MENU_COALITION_COMMAND class +-- @type MENU_COALITION_COMMAND +-- @extends Menu#MENU +MENU_COALITION_COMMAND = { + ClassName = "MENU_COALITION_COMMAND" +} + +--- Creates a new radio command item for a group +-- @param #MENU_COALITION_COMMAND self +-- @param DCSCoalition#coalition.side MenuCoalition The coalition owning the menu. +-- @param MenuText The text for the menu. +-- @param ParentMenu The parent menu. +-- @param CommandMenuFunction A function that is called when the menu key is pressed. +-- @param CommandMenuArgument An argument for the function. +-- @return #MENU_COALITION_COMMAND self +function MENU_COALITION_COMMAND:New( MenuCoalition, MenuText, ParentMenu, CommandMenuFunction, CommandMenuArgument ) + + -- Arrange meta tables + + local MenuParentPath = {} + if ParentMenu ~= nil then + MenuParentPath = ParentMenu.MenuPath + end + + local self = BASE:Inherit( self, MENU:New( MenuText, MenuParentPath ) ) + + self.MenuCoalition = MenuCoalition + self.MenuParentPath = MenuParentPath + self.MenuText = MenuText + self.ParentMenu = ParentMenu + + self:T( { MenuParentPath, MenuText, CommandMenuFunction, CommandMenuArgument } ) + + self.MenuPath = missionCommands.addCommandForCoalition( self.MenuCoalition, MenuText, MenuParentPath, CommandMenuFunction, CommandMenuArgument ) + + self.CommandMenuFunction = CommandMenuFunction + self.CommandMenuArgument = CommandMenuArgument + + ParentMenu.Menus[self.MenuPath] = self + + return self +end + +--- Removes a radio command item for a coalition +-- @param #MENU_COALITION_COMMAND self +-- @return #MENU_COALITION_COMMAND self +function MENU_COALITION_COMMAND:Remove() + self:F( self.MenuPath ) + + missionCommands.removeItemForCoalition( self.MenuCoalition, self.MenuPath ) + self.ParentMenu.Menus[self.MenuPath] = nil + return nil +end diff --git a/Moose/TimeTrigger.lua b/Moose/TimeTrigger.lua index 4b3a9f9a2..345e576af 100644 --- a/Moose/TimeTrigger.lua +++ b/Moose/TimeTrigger.lua @@ -52,7 +52,7 @@ function TIMETRIGGER:New( TimeEventObject, TimeEventFunction, TimeEventFunctionA self.StartTime = timer.getTime() - self:T("Calling function" .. timer.getTime() + self.StartSeconds ) + self:T("Calling function " .. timer.getTime() + self.StartSeconds ) timer.scheduleFunction( self.Scheduler, self, timer.getTime() + self.StartSeconds + .01 ) @@ -62,8 +62,19 @@ end function TIMETRIGGER:Scheduler() self:F( self.TimeEventFunctionArguments ) + + local ErrorHandler = function( errmsg ) - local Result = self.TimeEventFunction( self.TimeEventObject, unpack( self.TimeEventFunctionArguments ) ) + env.info( "Error in TIMETRIGGER 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) + end if Result and Result == true then if not self.StopSeconds or ( self.StopSeconds and timer.getTime() <= self.StartTime + self.StopSeconds ) then