From c5587304f7d2cc811d29b5418c28eaa97a94263d Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 27 Apr 2017 10:12:48 +0200 Subject: [PATCH 1/8] Trace every event. Some stuff is fishy on MP --- Moose Development/Moose/Core/Event.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index 8bbaeade6..8c2dbb2f4 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -748,6 +748,8 @@ function EVENT:onEvent( Event ) local EventMeta = _EVENTMETA[Event.id] + + self:E( { EventMeta.Text, Event } ) if self and self.Events and self.Events[Event.id] then @@ -863,7 +865,7 @@ function EVENT:onEvent( Event ) local PriorityBegin = PriorityOrder == -1 and 5 or 1 local PriorityEnd = PriorityOrder == -1 and 1 or 5 - if Event.IniObjectCategory ~= 3 then + if Event.IniObjectCategory ~= Object.Category.STATIC then self:E( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } ) end From 5a2594853c61dac6025702bb517ad05f242a9580 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 27 Apr 2017 10:22:29 +0200 Subject: [PATCH 2/8] Remove static event trace of tires --- Moose Development/Moose/Core/Event.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index 8c2dbb2f4..f16df7b81 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -876,8 +876,10 @@ function EVENT:onEvent( Event ) -- Okay, we got the event from DCS. Now loop the SORTED self.EventSorted[] table for the received Event.id, and for each EventData registered, check if a function needs to be called. for EventClass, EventData in pairs( self.Events[Event.id][EventPriority] ) do - self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } ) - + if Event.IniObjectCategory ~= Object.Category.STATIC then + self:E( { "Evaluating: ", EventClass:GetClassNameAndID() } ) + end + Event.IniGroup = GROUP:FindByName( Event.IniDCSGroupName ) Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName ) From 26033a4172ca153cf4491d360a5c328bc98875c2 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 27 Apr 2017 12:11:09 +0200 Subject: [PATCH 3/8] Check players --- Moose Development/Moose/Core/Database.lua | 34 +++++++++++++++++++++-- Moose Development/Moose/Core/Event.lua | 17 ++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index eebce2873..2ce9d7928 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -51,6 +51,7 @@ DATABASE = { ClientsByID = {}, }, UNITS = {}, + UNITS_Index = {}, STATICS = {}, GROUPS = {}, PLAYERS = {}, @@ -99,7 +100,7 @@ function DATABASE:New() self:HandleEvent( EVENTS.DeleteCargo ) -- Follow alive players and clients - self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit ) +-- self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit ) self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit ) self:_RegisterTemplates() @@ -108,6 +109,33 @@ function DATABASE:New() self:_RegisterStatics() self:_RegisterPlayers() self:_RegisterAirbases() + + self.UNITS_Position = 0 + + --- @param Wrapper.Unit#UNIT PlayerUnit + local function CheckPlayers( self ) + + local UNITS_Count = #self.UNITS_Index + if UNITS_Count > 0 then + self.UNITS_Position = ( ( self.UNITS_Position <= UNITS_Count ) and self.UNITS_Position + 1 ) or 1 + local PlayerUnit = self.UNITS[self.UNITS_Index[self.UNITS_Position]] + if PlayerUnit then + local UnitName = PlayerUnit:GetName() + local PlayerName = PlayerUnit:GetPlayerName() + self:E( { UNITS_Count, self.UNITS_Position, UnitName, PlayerName } ) + if PlayerName and PlayerName ~= "" then + if not self.PLAYERS[PlayerName] or self.PLAYERS[PlayerName] ~= PlayerUnit then + self:E( { "Add player for unit:", UnitName, PlayerName } ) + self:AddPlayer( UnitName, PlayerName ) + _EVENTDISPATCHER:CreateEventPlayerEnterUnit( PlayerUnit ) + end + end + end + end + end + + self:E( "Scheduling" ) + local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.05 ) return self end @@ -130,6 +158,8 @@ function DATABASE:AddUnit( DCSUnitName ) if not self.UNITS[DCSUnitName] then local UnitRegister = UNIT:Register( DCSUnitName ) self.UNITS[DCSUnitName] = UNIT:Register( DCSUnitName ) + + table.insert( self.UNITS_Index, DCSUnitName ) end return self.UNITS[DCSUnitName] @@ -140,7 +170,7 @@ end -- @param #DATABASE self function DATABASE:DeleteUnit( DCSUnitName ) - --self.UNITS[DCSUnitName] = nil + self.UNITS[DCSUnitName] = nil end --- Adds a Static based on the Static Name in the DATABASE. diff --git a/Moose Development/Moose/Core/Event.lua b/Moose Development/Moose/Core/Event.lua index f16df7b81..f37e590df 100644 --- a/Moose Development/Moose/Core/Event.lua +++ b/Moose Development/Moose/Core/Event.lua @@ -730,6 +730,21 @@ do -- Event Creation world.onEvent( Event ) end + --- Creation of a S_EVENT_PLAYER_ENTER_UNIT Event. + -- @param #EVENT self + -- @param Wrapper.Unit#UNIT PlayerUnit. + function EVENT:CreateEventPlayerEnterUnit( PlayerUnit ) + self:F( { PlayerUnit } ) + + local Event = { + id = EVENTS.PlayerEnterUnit, + time = timer.getTime(), + initiator = PlayerUnit:GetDCSObject() + } + + world.onEvent( Event ) + end + end --- @param #EVENT self @@ -749,8 +764,6 @@ function EVENT:onEvent( Event ) local EventMeta = _EVENTMETA[Event.id] - self:E( { EventMeta.Text, Event } ) - if self and self.Events and self.Events[Event.id] then if Event.initiator then From 0eb9d1917b410a0f9a8b403934093a3f835c4fd6 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 4 May 2017 10:19:34 +0200 Subject: [PATCH 4/8] Updates --- Moose Development/Moose/Core/Database.lua | 12 ++++++------ Moose Development/Moose/Core/Menu.lua | 8 ++++---- Moose Development/Moose/Tasking/DetectionManager.lua | 1 + Moose Development/Moose/Tasking/Mission.lua | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 2ce9d7928..e3da3142d 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -112,7 +112,7 @@ function DATABASE:New() self.UNITS_Position = 0 - --- @param Wrapper.Unit#UNIT PlayerUnit + --- @param #DATABASE self local function CheckPlayers( self ) local UNITS_Count = #self.UNITS_Index @@ -122,12 +122,12 @@ function DATABASE:New() if PlayerUnit then local UnitName = PlayerUnit:GetName() local PlayerName = PlayerUnit:GetPlayerName() - self:E( { UNITS_Count, self.UNITS_Position, UnitName, PlayerName } ) + --self:E( { UNITS_Count, self.UNITS_Position, UnitName, PlayerName } ) if PlayerName and PlayerName ~= "" then - if not self.PLAYERS[PlayerName] or self.PLAYERS[PlayerName] ~= PlayerUnit then + if self.PLAYERS[PlayerName] == nil or self.PLAYERS[PlayerName] ~= UnitName then self:E( { "Add player for unit:", UnitName, PlayerName } ) self:AddPlayer( UnitName, PlayerName ) - _EVENTDISPATCHER:CreateEventPlayerEnterUnit( PlayerUnit ) + --_EVENTDISPATCHER:CreateEventPlayerEnterUnit( PlayerUnit ) end end end @@ -135,7 +135,7 @@ function DATABASE:New() end self:E( "Scheduling" ) - local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.05 ) + local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.1 ) return self end @@ -311,7 +311,7 @@ function DATABASE:AddPlayer( UnitName, PlayerName ) if PlayerName then self:E( { "Add player for unit:", UnitName, PlayerName } ) - self.PLAYERS[PlayerName] = self:FindUnit( UnitName ) + self.PLAYERS[PlayerName] = UnitName self.PLAYERSJOINED[PlayerName] = PlayerName end end diff --git a/Moose Development/Moose/Core/Menu.lua b/Moose Development/Moose/Core/Menu.lua index 7a6049091..2188db052 100644 --- a/Moose Development/Moose/Core/Menu.lua +++ b/Moose Development/Moose/Core/Menu.lua @@ -780,9 +780,9 @@ do self = MenuGroup._Menus[Path] else self = BASE:Inherit( self, MENU_BASE:New( MenuText, ParentMenu ) ) - if MenuGroup:IsAlive() then + --if MenuGroup:IsAlive() then MenuGroup._Menus[Path] = self - end + --end self.MenuGroup = MenuGroup self.Path = Path @@ -886,9 +886,9 @@ do else self = BASE:Inherit( self, MENU_COMMAND_BASE:New( MenuText, ParentMenu, CommandMenuFunction, arg ) ) - if MenuGroup:IsAlive() then + --if MenuGroup:IsAlive() then MenuGroup._Menus[Path] = self - end + --end self.Path = Path self.MenuGroup = MenuGroup diff --git a/Moose Development/Moose/Tasking/DetectionManager.lua b/Moose Development/Moose/Tasking/DetectionManager.lua index 7601701a0..7283d50d9 100644 --- a/Moose Development/Moose/Tasking/DetectionManager.lua +++ b/Moose Development/Moose/Tasking/DetectionManager.lua @@ -76,6 +76,7 @@ do -- DETECTION MANAGER self:SetReportInterval( 30 ) self:SetReportDisplayTime( 25 ) + self:E( { Detection = Detection } ) Detection:__Start( 1 ) return self diff --git a/Moose Development/Moose/Tasking/Mission.lua b/Moose Development/Moose/Tasking/Mission.lua index dfc45aaab..00451544a 100644 --- a/Moose Development/Moose/Tasking/Mission.lua +++ b/Moose Development/Moose/Tasking/Mission.lua @@ -549,7 +549,7 @@ function MISSION:GetTasksRemaining() local TasksRemaining = 0 for TaskID, Task in pairs( self:GetTasks() ) do local Task = Task -- Tasking.Task#TASK - if Task:IsStateSuccess() or Task:IsStateFAILED() then + if Task:IsStateSuccess() or Task:IsStateFailed() then else TasksRemaining = TasksRemaining + 1 end From 2519fcde48acc09bd6337caba328e7bfba805865 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 4 May 2017 12:25:50 +0200 Subject: [PATCH 5/8] No loop logic --- Moose Development/Moose/Core/Database.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index e3da3142d..c9f7ed174 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -135,7 +135,7 @@ function DATABASE:New() end self:E( "Scheduling" ) - local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.1 ) + --local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.1 ) return self end From b4107b14f8629e56b38bf5164cfb6c4db8bab87c Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 4 May 2017 13:33:13 +0200 Subject: [PATCH 6/8] Eliminate trace details --- Moose Development/Moose/Core/Menu.lua | 4 ++-- Moose Development/Moose/Core/Zone.lua | 4 ++-- Moose Development/Moose/Functional/Detection.lua | 6 +++--- Moose Development/Moose/Wrapper/Unit.lua | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Moose Development/Moose/Core/Menu.lua b/Moose Development/Moose/Core/Menu.lua index 2188db052..1b15cbe06 100644 --- a/Moose Development/Moose/Core/Menu.lua +++ b/Moose Development/Moose/Core/Menu.lua @@ -839,7 +839,7 @@ do self.ParentMenu.MenuCount = self.ParentMenu.MenuCount - 1 if self.ParentMenu.MenuCount == 0 then if self.MenuRemoveParent == true then - self:T( "Removing Parent Menu " ) + self:T2( "Removing Parent Menu " ) self.ParentMenu:Remove() end end @@ -927,7 +927,7 @@ do self.ParentMenu.MenuCount = self.ParentMenu.MenuCount - 1 if self.ParentMenu.MenuCount == 0 then if self.MenuRemoveParent == true then - self:T( "Removing Parent Menu " ) + self:T2( "Removing Parent Menu " ) self.ParentMenu:Remove() end end diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 998bd07fa..5f41cf733 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -731,7 +731,7 @@ end -- @param #ZONE_UNIT self -- @return Dcs.DCSTypes#Vec2 The location of the zone based on the @{Unit#UNIT}location. function ZONE_UNIT:GetVec2() - self:F( self.ZoneName ) + self:F2( self.ZoneName ) local ZoneVec2 = self.ZoneUNIT:GetVec2() if ZoneVec2 then @@ -741,7 +741,7 @@ function ZONE_UNIT:GetVec2() return self.LastVec2 end - self:T( { ZoneVec2 } ) + self:T2( { ZoneVec2 } ) return nil end diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index d302fe481..f6eb2dc97 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -567,7 +567,7 @@ do -- DETECTION_BASE self.DetectDLINK ) - self:T( { TargetIsDetected = TargetIsDetected, TargetIsVisible = TargetIsVisible, TargetLastTime = TargetLastTime, TargetKnowType = TargetKnowType, TargetKnowDistance = TargetKnowDistance, TargetLastPos = TargetLastPos, TargetLastVelocity = TargetLastVelocity } ) + self:T2( { TargetIsDetected = TargetIsDetected, TargetIsVisible = TargetIsVisible, TargetLastTime = TargetLastTime, TargetKnowType = TargetKnowType, TargetKnowDistance = TargetKnowDistance, TargetLastPos = TargetLastPos, TargetLastVelocity = TargetLastVelocity } ) local DetectionAccepted = true @@ -585,7 +585,7 @@ do -- DETECTION_BASE local DetectedUnitCategory = DetectedObject:getDesc().category - self:T( { "Detected Target:", DetectionGroupName, DetectedObjectName, Distance, DetectedUnitCategory } ) + self:T2( { "Detected Target:", DetectionGroupName, DetectedObjectName, Distance, DetectedUnitCategory } ) -- Calculate Acceptance @@ -1154,7 +1154,7 @@ do -- DETECTION_BASE -- @param #string ObjectName -- @return #DETECTION_BASE.DetectedObject function DETECTION_BASE:GetDetectedObject( ObjectName ) - self:F( ObjectName ) + self:F2( ObjectName ) if ObjectName then local DetectedObject = self.DetectedObjects[ObjectName] diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 0107839b5..c99c2a7a4 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -724,7 +724,7 @@ function UNIT:IsInZone( Zone ) if self:IsAlive() then local IsInZone = Zone:IsVec3InZone( self:GetVec3() ) - self:T( { IsInZone } ) + self:T2( { IsInZone } ) return IsInZone end From a499c04fa4513e5c16c2653af74b6659329839a5 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 4 May 2017 14:05:57 +0200 Subject: [PATCH 7/8] Fix crash --- Moose Development/Moose/Core/Fsm.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Moose Development/Moose/Core/Fsm.lua b/Moose Development/Moose/Core/Fsm.lua index 8af98362f..d2333ffdc 100644 --- a/Moose Development/Moose/Core/Fsm.lua +++ b/Moose Development/Moose/Core/Fsm.lua @@ -1014,6 +1014,8 @@ do -- FSM_PROCESS Process.fsm:Remove() Process.fsm = nil end + + self._Processes = nil return self end From 5bb91646d78bc05985acbc7c41a57d0699e863b8 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Thu, 4 May 2017 14:23:10 +0200 Subject: [PATCH 8/8] Updates --- Moose Development/Moose/Core/Menu.lua | 4 ++-- Moose Development/Moose/Tasking/Task.lua | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Core/Menu.lua b/Moose Development/Moose/Core/Menu.lua index 1b15cbe06..c38f763d4 100644 --- a/Moose Development/Moose/Core/Menu.lua +++ b/Moose Development/Moose/Core/Menu.lua @@ -91,7 +91,7 @@ do -- MENU_BASE -- @param #boolean RemoveParent If true, the parent menu is automatically removed when this menu is the last child menu of that parent @{Menu}. -- @return #MENU_BASE function MENU_BASE:SetRemoveParent( RemoveParent ) - self:F( { RemoveParent } ) + self:F2( { RemoveParent } ) self.MenuRemoveParent = RemoveParent return self end @@ -902,7 +902,7 @@ do if self.ParentMenu and self.ParentMenu.Menus then self.ParentMenu.Menus[MenuText] = self self.ParentMenu.MenuCount = self.ParentMenu.MenuCount + 1 - self:F( { ParentMenu.Menus, MenuText } ) + self:F2( { ParentMenu.Menus, MenuText } ) end end diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 70d97867d..78fea4073 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -724,7 +724,12 @@ end -- @param #TASK self function TASK:MenuTaskAbort( TaskGroup ) - self:Abort() + for PlayerUnitName, PlayerUnit in pairs( TaskGroup:GetUnits() ) do + self:AbortUnit( PlayerUnit ) + end + + self:GetMission():GetCommandCenter():GetPositionable():MessageToSetGroup( "Abort", 15, self.SetGroup ) + end