From bfb11b6f79026607543f811c20dae7c6644c26ec Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 23 Mar 2019 10:45:14 +0100 Subject: [PATCH 1/3] Updates on goal logic --- Moose Development/Moose/Tasking/Mission.lua | 15 ++++++++------- Moose Development/Moose/Tasking/Task.lua | 17 +++++++++++++++++ .../Moose/Tasking/Task_Capture_Zone.lua | 4 ++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/Tasking/Mission.lua b/Moose Development/Moose/Tasking/Mission.lua index 2d6ac4660..f057c9648 100644 --- a/Moose Development/Moose/Tasking/Mission.lua +++ b/Moose Development/Moose/Tasking/Mission.lua @@ -968,18 +968,19 @@ function MISSION:ReportPlayersProgress( ReportGroup ) -- Determine how many tasks are remaining. for TaskID, Task in pairs( self:GetTasks() ) do local Task = Task -- Tasking.Task#TASK - local TaskGoalTotal = Task:GetGoalTotal() or 0 local TaskName = Task:GetName() + local Goal = Task:GetGoal() PlayerList[TaskName] = PlayerList[TaskName] or {} - if TaskGoalTotal ~= 0 then - local PlayerNames = self:GetPlayerNames() - for PlayerName, PlayerData in pairs( PlayerNames ) do - PlayerList[TaskName][PlayerName] = string.format( 'Player (%s): Task "%s": %d%%', PlayerName, TaskName, Task:GetPlayerProgress( PlayerName ) * 100 / TaskGoalTotal ) + if Goal then + local TotalContributions = Goal:GetTotalContributions() + local PlayerContributions = Goal:GetPlayerContributions() + self:F( { TotalContributions = TotalContributions, PlayerContributions = PlayerContributions } ) + for PlayerName, PlayerContribution in pairs( PlayerContributions ) do + PlayerList[TaskName][PlayerName] = string.format( 'Player (%s): Task "%s": %d%%', PlayerName, TaskName, PlayerContributions[PlayerName] * 100 / TotalContributions ) end else PlayerList[TaskName]["_"] = string.format( 'Player (---): Task "%s": %d%%', TaskName, 0 ) - end - + end end for TaskName, TaskData in pairs( PlayerList ) do diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 797de7d61..68c8a4803 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -1709,6 +1709,23 @@ end do -- Links + --- Set goal of a task + -- @param #TASK self + -- @param Core.Goal#GOAL Goal + -- @return #TASK + function TASK:SetGoal( Goal ) + self.Goal = Goal + end + + + --- Get goal of a task + -- @param #TASK self + -- @return Core.Goal#GOAL The Goal + function TASK:GetGoal() + return self.Goal + end + + --- Set dispatcher of a task -- @param #TASK self -- @param Tasking.DetectionManager#DETECTION_MANAGER Dispatcher diff --git a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua index e39e8b2c9..9ab0f35c7 100644 --- a/Moose Development/Moose/Tasking/Task_Capture_Zone.lua +++ b/Moose Development/Moose/Tasking/Task_Capture_Zone.lua @@ -213,7 +213,7 @@ do -- TASK_CAPTURE_ZONE self:UpdateTaskInfo( true ) - self:SetGoalTotal( 1 ) + self:SetGoal( self.ZoneGoal.Goal ) return self end @@ -232,7 +232,7 @@ do -- TASK_CAPTURE_ZONE self.TaskInfo:AddText( "Zone Coalition", self.ZoneGoal:GetCoalitionName(), 11, "MOD", Persist ) local SetUnit = self.ZoneGoal.Zone:GetScannedSetUnit() local ThreatLevel, ThreatText = SetUnit:CalculateThreatLevelA2G() - self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 20, "MSOD", Persist ) + self.TaskInfo:AddThreat( ThreatText, ThreatLevel, 20, "MOD", Persist ) end From bd290ffdab937b857087d02cd737843f12240af9 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 23 Mar 2019 11:24:04 +0100 Subject: [PATCH 2/3] Fixing hit problem in multi player for database when hitting static objects. --- 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 1a3d7c7e5..5a07d5f5a 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -1330,7 +1330,7 @@ end -- What is he hitting? if Event.TgtCategory then - if Event.IniCoalition then -- A coalition object was hit, probably a static. + if Event.WeaponCoalition then -- A coalition object was hit, probably a static. -- A target got hit self.HITS[Event.TgtUnitName] = self.HITS[Event.TgtUnitName] or {} local Hit = self.HITS[Event.TgtUnitName] From 59974ea33eeff34b9c9b6994ac8fdc98e5be0470 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Wed, 27 Mar 2019 19:18:12 +0100 Subject: [PATCH 3/3] New Zone Detection module. --- .../Moose/Core/Zone_Detection.lua | 203 ++++++++++++++++++ .../Moose/Functional/Detection.lua | 15 ++ Moose Development/Moose/Modules.lua | 1 + 3 files changed, 219 insertions(+) create mode 100644 Moose Development/Moose/Core/Zone_Detection.lua diff --git a/Moose Development/Moose/Core/Zone_Detection.lua b/Moose Development/Moose/Core/Zone_Detection.lua new file mode 100644 index 000000000..96a508c0e --- /dev/null +++ b/Moose Development/Moose/Core/Zone_Detection.lua @@ -0,0 +1,203 @@ + +--- The ZONE_DETECTION class, defined by a zone name, a detection object and a radius. +-- @type ZONE_DETECTION +-- @field DCS#Vec2 Vec2 The current location of the zone. +-- @field DCS#Distance Radius The radius of the zone. +-- @extends #ZONE_BASE + +--- The ZONE_DETECTION class defined by a zone name, a location and a radius. +-- This class implements the inherited functions from Core.Zone#ZONE_BASE taking into account the own zone format and properties. +-- +-- ## ZONE_DETECTION constructor +-- +-- * @{#ZONE_DETECTION.New}(): Constructor. +-- +-- @field #ZONE_DETECTION +ZONE_DETECTION = { + ClassName="ZONE_DETECTION", + } + +--- Constructor of @{#ZONE_DETECTION}, taking the zone name, the zone location and a radius. +-- @param #ZONE_DETECTION self +-- @param #string ZoneName Name of the zone. +-- @param Functional.Detection#DETECTION_BASE Detection The detection object defining the locations of the central detections. +-- @param DCS#Distance Radius The radius around the detections defining the combined zone. +-- @return #ZONE_DETECTION self +function ZONE_DETECTION:New( ZoneName, Detection, Radius ) + local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) -- #ZONE_DETECTION + self:F( { ZoneName, Detection, Radius } ) + + self.Detection = Detection + self.Radius = Radius + + return self +end + +--- Bounds the zone with tires. +-- @param #ZONE_DETECTION self +-- @param #number Points (optional) The amount of points in the circle. Default 360. +-- @param DCS#country.id CountryID The country id of the tire objects, e.g. country.id.USA for blue or country.id.RUSSIA for red. +-- @param #boolean UnBound (Optional) If true the tyres will be destroyed. +-- @return #ZONE_DETECTION self +function ZONE_DETECTION:BoundZone( Points, CountryID, UnBound ) + + local Point = {} + local Vec2 = self:GetVec2() + + Points = Points and Points or 360 + + local Angle + local RadialBase = math.pi*2 + + -- + for Angle = 0, 360, (360 / Points ) do + local Radial = Angle * RadialBase / 360 + Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius() + Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius() + + local CountryName = _DATABASE.COUNTRY_NAME[CountryID] + + local Tire = { + ["country"] = CountryName, + ["category"] = "Fortifications", + ["canCargo"] = false, + ["shape_name"] = "H-tyre_B_WF", + ["type"] = "Black_Tyre_WF", + --["unitId"] = Angle + 10000, + ["y"] = Point.y, + ["x"] = Point.x, + ["name"] = string.format( "%s-Tire #%0d", self:GetName(), Angle ), + ["heading"] = 0, + } -- end of ["group"] + + local Group = coalition.addStaticObject( CountryID, Tire ) + if UnBound and UnBound == true then + Group:destroy() + end + end + + return self +end + + +--- Smokes the zone boundaries in a color. +-- @param #ZONE_DETECTION self +-- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color. +-- @param #number Points (optional) The amount of points in the circle. +-- @param #number AddHeight (optional) The height to be added for the smoke. +-- @param #number AddOffSet (optional) The angle to be added for the smoking start position. +-- @return #ZONE_DETECTION self +function ZONE_DETECTION:SmokeZone( SmokeColor, Points, AddHeight, AngleOffset ) + self:F2( SmokeColor ) + + local Point = {} + local Vec2 = self:GetVec2() + + AddHeight = AddHeight or 0 + AngleOffset = AngleOffset or 0 + + Points = Points and Points or 360 + + local Angle + local RadialBase = math.pi*2 + + for Angle = 0, 360, 360 / Points do + local Radial = ( Angle + AngleOffset ) * RadialBase / 360 + Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius() + Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius() + POINT_VEC2:New( Point.x, Point.y, AddHeight ):Smoke( SmokeColor ) + end + + return self +end + + +--- Flares the zone boundaries in a color. +-- @param #ZONE_DETECTION self +-- @param Utilities.Utils#FLARECOLOR FlareColor The flare color. +-- @param #number Points (optional) The amount of points in the circle. +-- @param DCS#Azimuth Azimuth (optional) Azimuth The azimuth of the flare. +-- @param #number AddHeight (optional) The height to be added for the smoke. +-- @return #ZONE_DETECTION self +function ZONE_DETECTION:FlareZone( FlareColor, Points, Azimuth, AddHeight ) + self:F2( { FlareColor, Azimuth } ) + + local Point = {} + local Vec2 = self:GetVec2() + + AddHeight = AddHeight or 0 + + Points = Points and Points or 360 + + local Angle + local RadialBase = math.pi*2 + + for Angle = 0, 360, 360 / Points do + local Radial = Angle * RadialBase / 360 + Point.x = Vec2.x + math.cos( Radial ) * self:GetRadius() + Point.y = Vec2.y + math.sin( Radial ) * self:GetRadius() + POINT_VEC2:New( Point.x, Point.y, AddHeight ):Flare( FlareColor, Azimuth ) + end + + return self +end + +--- Returns the radius around the detected locations defining the combine zone. +-- @param #ZONE_DETECTION self +-- @return DCS#Distance The radius. +function ZONE_DETECTION:GetRadius() + self:F2( self.ZoneName ) + + self:T2( { self.Radius } ) + + return self.Radius +end + +--- Sets the radius around the detected locations defining the combine zone. +-- @param #ZONE_DETECTION self +-- @param DCS#Distance Radius The radius. +-- @return #ZONE_DETECTION self +function ZONE_DETECTION:SetRadius( Radius ) + self:F2( self.ZoneName ) + + self.Radius = Radius + self:T2( { self.Radius } ) + + return self.Radius +end + + + +--- Returns if a location is within the zone. +-- @param #ZONE_DETECTION self +-- @param DCS#Vec2 Vec2 The location to test. +-- @return #boolean true if the location is within the zone. +function ZONE_DETECTION:IsVec2InZone( Vec2 ) + self:F2( Vec2 ) + + local Coordinates = self.Detection:GetDetectedItemCoordinates() -- This returns a list of coordinates that define the (central) locations of the detections. + + for CoordinateID, Coordinate in pairs( Coordinates ) do + local ZoneVec2 = Coordinate:GetVec2() + if ZoneVec2 then + if (( Vec2.x - ZoneVec2.x )^2 + ( Vec2.y - ZoneVec2.y ) ^2 ) ^ 0.5 <= self:GetRadius() then + return true + end + end + end + + return false +end + +--- Returns if a point is within the zone. +-- @param #ZONE_DETECTION self +-- @param DCS#Vec3 Vec3 The point to test. +-- @return #boolean true if the point is within the zone. +function ZONE_DETECTION:IsVec3InZone( Vec3 ) + self:F2( Vec3 ) + + local InZone = self:IsVec2InZone( { x = Vec3.x, y = Vec3.z } ) + + return InZone +end + diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 99f98848b..c3d0c21a3 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1826,6 +1826,21 @@ do -- DETECTION_BASE return nil end + --- Get a list of the detected item coordinates. + -- @param #DETECTION_BASE self + -- @param #DETECTION_BASE.DetectedItem DetectedItem The DetectedItem to set the coordinate at. + -- @return Core.Point#COORDINATE + function DETECTION_BASE:GetDetectedItemCoordinates() + + local Coordinates = {} + + for DetectedItemID, DetectedItem in pairs( self:GetDetectedItems() ) do + Coordinates[DetectedItem] = self:GetDetectedItemCoordinate( DetectedItem ) + end + + return Coordinates + end + --- Set the detected item threatlevel. -- @param #DETECTION_BASE self -- @param #DETECTION_BASE.DetectedItem The DetectedItem to calculate the threatlevel for. diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index 162e605fd..8a86a02f9 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -11,6 +11,7 @@ __Moose.Include( 'Scripts/Moose/Core/Event.lua' ) __Moose.Include( 'Scripts/Moose/Core/Settings.lua' ) __Moose.Include( 'Scripts/Moose/Core/Menu.lua' ) __Moose.Include( 'Scripts/Moose/Core/Zone.lua' ) +__Moose.Include( 'Scripts/Moose/Core/Zone_Detection.lua' ) __Moose.Include( 'Scripts/Moose/Core/Database.lua' ) __Moose.Include( 'Scripts/Moose/Core/Set.lua' ) __Moose.Include( 'Scripts/Moose/Core/Point.lua' )