From 13449cc9eedcb30eb964cb34421f155196c30762 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 08:48:57 +0200 Subject: [PATCH 1/9] Progress designing system settings --- Moose Development/Moose/Actions/Act_Route.lua | 25 +- Moose Development/Moose/Core/Point.lua | 1366 ++++++++--------- Moose Development/Moose/Core/Settings.lua | 228 +++ .../Moose/Functional/Detection.lua | 7 +- Moose Development/Moose/Moose.lua | 3 +- Moose Development/Moose/Tasking/Task.lua | 5 +- .../Moose/Tasking/Task_A2A_Dispatcher.lua | 8 +- Moose Mission Setup/Moose.files | 1 + Moose Mission Setup/Moose.lua | 3 +- 9 files changed, 924 insertions(+), 722 deletions(-) create mode 100644 Moose Development/Moose/Core/Settings.lua diff --git a/Moose Development/Moose/Actions/Act_Route.lua b/Moose Development/Moose/Actions/Act_Route.lua index 5a7b85d14..5e7f91381 100644 --- a/Moose Development/Moose/Actions/Act_Route.lua +++ b/Moose Development/Moose/Actions/Act_Route.lua @@ -154,29 +154,21 @@ do -- ACT_ROUTE --- Get the routing text to be displayed. -- The route mode determines the text displayed. -- @param #ACT_ROUTE self + -- @param Core.Point#COORDINATE FromCoordinate -- @return #string function ACT_ROUTE:GetRouteText( FromCoordinate ) local RouteText = "" - if self.Coordinate and self.RouteMode == "B" then - RouteText = "Route to " .. FromCoordinate:GetBRText( self.Coordinate ) .. " km." + + if self.Coordinate then + RouteText = "Route to " .. self.Coordinate:ToString( FromCoordinate ) end - if self.Coordinate and self.RouteMode == "C" then - RouteText = "Route to " .. self.Coordinate:ToString() - end - - if self.Zone and self.RouteMode == "B" then - local Coordinate = self.Zone:GetCoordinate() - RouteText = "Route to zone bearing " .. FromCoordinate:GetBRText( Coordinate ) .. " km." + if self.Zone then + RouteText = "Route to " .. self.Zone:GetCoordinate():ToString( FromCoordinate ) end - if self.Zone and self.RouteMode == "C" then - local Coordinate = self.Zone:GetCoordinate() - RouteText = "Route to zone at " .. Coordinate:ToString() - end - return RouteText end @@ -438,10 +430,7 @@ do -- ACT_ROUTE_ZONE -- @param #string To function ACT_ROUTE_ZONE:onafterReport( ProcessUnit, From, Event, To ) - local ZoneVec2 = self.Zone:GetVec2() - local ZoneCoordinate = COORDINATE:New( ZoneVec2.x, ZoneVec2.y ) - local TaskUnitVec2 = ProcessUnit:GetVec2() - local TaskUnitCoordinate = COORDINATE:New( TaskUnitVec2.x, TaskUnitVec2.y ) + local TaskUnitCoordinate = ProcessUnit:GetCoordinate() local RouteText = self:GetRouteText( TaskUnitCoordinate ) self:Message( RouteText ) end diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index f76caac96..75d44f6e1 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -53,6 +53,41 @@ -- -- @module Point + +--- @type COORDINATE +-- @extends Core.Base#BASE + +--- # COORDINATE class, extends @{Base#BASE} +-- +-- The COORDINATE class defines a 2D coordinate in the simulator. The height coordinate (if needed) will be the land height + an optional added height specified. +-- A COORDINATE can be expressed in LL or in MGRS. +-- +-- ## COORDINATE constructor +-- +-- A new COORDINATE instance can be created with: +-- +-- * @{Point#COORDINATE.New}(): a 2D point, taking an additional height parameter. +-- * @{Point#COORDINATE.NewFromVec2}(): a 2D point created from a @{DCSTypes#Vec2}. +-- +-- ## Manupulate the X, Altitude, Y coordinates of the 2D point +-- +-- A COORDINATE class works in 2D space, with an altitude setting. It contains internally an X, Altitude, Y coordinate. +-- Methods exist to manupulate these coordinates. +-- +-- The current X, Altitude, Y axis can be retrieved with the methods @{#COORDINATE.GetX}(), @{#COORDINATE.GetAlt}(), @{#COORDINATE.GetY}() respectively. +-- The methods @{#COORDINATE.SetX}(), @{#COORDINATE.SetAlt}(), @{#COORDINATE.SetY}() change the respective axis with a new value. +-- The current Lat(itude), Alt(itude), Lon(gitude) values can also be retrieved with the methods @{#COORDINATE.GetLat}(), @{#COORDINATE.GetAlt}(), @{#COORDINATE.GetLon}() respectively. +-- The current axis values can be changed by using the methods @{#COORDINATE.AddX}(), @{#COORDINATE.AddAlt}(), @{#COORDINATE.AddY}() +-- to add or substract a value from the current respective axis value. +-- Note that the Set and Add methods return the current COORDINATE object, so these manipulation methods can be chained... For example: +-- +-- local Vec2 = PointVec2:AddX( 100 ):AddY( 2000 ):GetVec2() +-- +-- @field #COORDINATE +COORDINATE = { + ClassName = "COORDINATE", +} + --- The POINT_VEC3 class -- @type POINT_VEC3 -- @field #number x The x coordinate in 3D space. @@ -63,9 +98,10 @@ -- @field #POINT_VEC3.RoutePointAltType RoutePointAltType -- @field #POINT_VEC3.RoutePointType RoutePointType -- @field #POINT_VEC3.RoutePointAction RoutePointAction --- @extends Core.Base#BASE +-- @extends Core.Point#COORDINATE ---- # POINT_VEC3 class, extends @{Base#BASE} + +--- # POINT_VEC3 class, extends @{Point#COORDINATE} -- -- POINT_VEC3 defines a 3D point in the simulator and with its methods, you can use or manipulate the point in 3D space. -- @@ -202,9 +238,10 @@ POINT_VEC3 = { --- @type POINT_VEC2 -- @field Dcs.DCSTypes#Distance x The x coordinate in meters. -- @field Dcs.DCSTypes#Distance y the y coordinate in meters. --- @extends Core.Point#POINT_VEC3 +-- @extends Core.Point#COORDINATE ---- # POINT_VEC2 class, extends @{Point#POINT_VEC3} + +--- # POINT_VEC2 class, extends @{Point#COORDINATE} -- -- The @{Point#POINT_VEC2} class defines a 2D point in the simulator. The height coordinate (if needed) will be the land height + an optional added height specified. -- @@ -235,48 +272,556 @@ POINT_VEC2 = { } ---- @type COORDINATE --- @field #number LL_Accuracy --- @field #boolean LL_DMS --- @field #number MGRS_Accuracy --- @field #string System --- @extends Core.Point#POINT_VEC2 ---- # COORDINATE class, extends @{Point#COORDINATE} --- --- The COORDINATE class defines a 2D coordinate in the simulator. The height coordinate (if needed) will be the land height + an optional added height specified. --- A COORDINATE can be expressed in LL or in MGRS. --- --- ## COORDINATE constructor --- --- A new COORDINATE instance can be created with: --- --- * @{Point#COORDINATE.New}(): a 2D point, taking an additional height parameter. --- * @{Point#COORDINATE.NewFromVec2}(): a 2D point created from a @{DCSTypes#Vec2}. --- --- ## Manupulate the X, Altitude, Y coordinates of the 2D point --- --- A COORDINATE class works in 2D space, with an altitude setting. It contains internally an X, Altitude, Y coordinate. --- Methods exist to manupulate these coordinates. --- --- The current X, Altitude, Y axis can be retrieved with the methods @{#COORDINATE.GetX}(), @{#COORDINATE.GetAlt}(), @{#COORDINATE.GetY}() respectively. --- The methods @{#COORDINATE.SetX}(), @{#COORDINATE.SetAlt}(), @{#COORDINATE.SetY}() change the respective axis with a new value. --- The current Lat(itude), Alt(itude), Lon(gitude) values can also be retrieved with the methods @{#COORDINATE.GetLat}(), @{#COORDINATE.GetAlt}(), @{#COORDINATE.GetLon}() respectively. --- The current axis values can be changed by using the methods @{#COORDINATE.AddX}(), @{#COORDINATE.AddAlt}(), @{#COORDINATE.AddY}() --- to add or substract a value from the current respective axis value. --- Note that the Set and Add methods return the current COORDINATE object, so these manipulation methods can be chained... For example: --- --- local Vec2 = PointVec2:AddX( 100 ):AddY( 2000 ):GetVec2() --- --- @field #COORDINATE -COORDINATE = { - ClassName = "COORDINATE", - LL_Accuracy = 2, - LL_DMS = true, - MGRS_Accuracy = 5, - System = "MGRS", -} +do -- COORDINATE + + --- COORDINATE constructor. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Distance x The x coordinate of the Vec3 point, pointing to the North. + -- @param Dcs.DCSTypes#Distance y The y coordinate of the Vec3 point, pointing to the Right. + -- @param Dcs.DCSTypes#Distance z The z coordinate of the Vec3 point, pointing to the Right. + -- @return Core.Point#COORDINATE + function COORDINATE:New( x, y, z ) + + local self = BASE:Inherit( self, BASE:New() ) -- #COORDINATE + self.x = x + self.y = y + self.z = z + + self:SetModeA2G() + + return self + end + + --- Create a new COORDINATE object from Vec2 coordinates. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Vec2 Vec2 The Vec2 point. + -- @param Dcs.DCSTypes#Distance LandHeightAdd (optional) The default height if required to be evaluated will be the land height of the x, y coordinate. You can specify an extra height to be added to the land height. + -- @return Core.Point#COORDINATE + function COORDINATE:NewFromVec2( Vec2, LandHeightAdd ) + + local LandHeight = land.getHeight( Vec2 ) + + LandHeightAdd = LandHeightAdd or 0 + LandHeight = LandHeight + LandHeightAdd + + local self = self:New( Vec2.x, LandHeight, Vec2.y ) -- #COORDINATE + + self:F2( self ) + + return self + + end + + --- Create a new COORDINATE object from Vec3 coordinates. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Vec3 Vec3 The Vec3 point. + -- @return Core.Point#COORDINATE + function COORDINATE:NewFromVec3( Vec3 ) + + local self = self:New( Vec3.x, Vec3.y, Vec3.z ) + + --local self = BASE:Inherit( self, POINT_VEC3:NewFromVec3( Vec3 ) ) -- Core.Point#COORDINATE + self:F2( self ) + + return self + end + + + --- Return the coordinates of the COORDINATE in Vec3 format. + -- @param #COORDINATE self + -- @return Dcs.DCSTypes#Vec3 The Vec3 format coordinate. + function COORDINATE:GetVec3() + return { x = self.x, y = self.y, z = self.z } + end + + + --- Return the coordinates of the COORDINATE in Vec2 format. + -- @param #COORDINATE self + -- @return Dcs.DCSTypes#Vec2 The Vec2 format coordinate. + function COORDINATE:GetVec2() + return { x = self.x, y = self.z } + end + + + function COORDINATE:SetHeading( Heading ) + self.Heading = Heading + end + + + --- Return a direction vector Vec3 from COORDINATE to the COORDINATE. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. + function COORDINATE:GetDirectionVec3( TargetCoordinate ) + return { x = TargetCoordinate.x - self.x, y = TargetCoordinate.y - self.y, z = TargetCoordinate.z - self.z } + end + + --- Get a correction in radians of the real magnetic north of the COORDINATE. + -- @param #COORDINATE self + -- @return #number CorrectionRadians The correction in radians. + function COORDINATE:GetNorthCorrectionRadians() + local TargetVec3 = self:GetVec3() + local lat, lon = coord.LOtoLL(TargetVec3) + local north_posit = coord.LLtoLO(lat + 1, lon) + return math.atan2( north_posit.z - TargetVec3.z, north_posit.x - TargetVec3.x ) + end + + + --- Return an angle in radians from the COORDINATE using a direction vector in Vec3 format. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. + -- @return #number DirectionRadians The angle in radians. + function COORDINATE:GetAngleRadians( DirectionVec3 ) + local DirectionRadians = math.atan2( DirectionVec3.z, DirectionVec3.x ) + --DirectionRadians = DirectionRadians + self:GetNorthCorrectionRadians() + if DirectionRadians < 0 then + DirectionRadians = DirectionRadians + 2 * math.pi -- put dir in range of 0 to 2*pi ( the full circle ) + end + return DirectionRadians + end + + --- Return an angle in degrees from the COORDINATE using a direction vector in Vec3 format. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. + -- @return #number DirectionRadians The angle in degrees. + function COORDINATE:GetAngleDegrees( DirectionVec3 ) + local AngleRadians = self:GetAngleRadians( DirectionVec3 ) + local Angle = UTILS.ToDegree( AngleRadians ) + return Angle + end + + + --- Return the 2D distance in meters between the target COORDINATE and the COORDINATE. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return Dcs.DCSTypes#Distance Distance The distance in meters. + function COORDINATE:Get2DDistance( TargetCoordinate ) + local TargetVec3 = TargetCoordinate:GetVec3() + local SourceVec3 = self:GetVec3() + return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 + end + + --- Return the 3D distance in meters between the target COORDINATE and the COORDINATE. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return Dcs.DCSTypes#Distance Distance The distance in meters. + function COORDINATE:Get3DDistance( TargetCoordinate ) + local TargetVec3 = TargetCoordinate:GetVec3() + local SourceVec3 = self:GetVec3() + return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.y - SourceVec3.y ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 + end + + --- Provides a Bearing / Range string + -- @param #COORDINATE self + -- @param #number AngleRadians The angle in randians + -- @param #number Distance The distance + -- @return #string The BR Text + function COORDINATE:GetBRText( AngleRadians, Distance, Settings ) + + local Settings = Settings or _SETTINGS + + AngleRadians = UTILS.Round( UTILS.ToDegree( AngleRadians ), 0 ) + if Settings:IsMetric() then + Distance = UTILS.Round( Distance / 1000, 2 ) + else + Distance = UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) + end + + local s = string.format( '%03d', AngleRadians ) .. ' for ' .. Distance + + s = s .. self:GetAltitudeText() -- When the POINT is a VEC2, there will be no altitude shown. + + return s + end + + + --- Return the altitude text of the COORDINATE. + -- @param #COORDINATE self + -- @return #string Altitude text. + function COORDINATE:GetAltitudeText( Settings ) + local Altitude = self.y + local Settings = Settings or _SETTINGS + if Altitude ~= 0 then + if Settings:IsMetric() then + return ' at ' .. UTILS.Round( self.y, -3 ) + else + return ' at ' .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) + end + end + end + + + --- Add a Distance in meters from the COORDINATE horizontal plane, with the given angle, and calculate the new COORDINATE. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Distance Distance The Distance to be added in meters. + -- @param Dcs.DCSTypes#Angle Angle The Angle in degrees. + -- @return #COORDINATE The new calculated COORDINATE. + function COORDINATE:Translate( Distance, Angle ) + local SX = self.x + local SZ = self.z + local Radians = Angle / 180 * math.pi + local TX = Distance * math.cos( Radians ) + SX + local TZ = Distance * math.sin( Radians ) + SZ + + return COORDINATE:New( TX, self.y, TZ ) + end + + + + --- Build an air type route point. + -- @param #COORDINATE self + -- @param #COORDINATE.RoutePointAltType AltType The altitude type. + -- @param #COORDINATE.RoutePointType Type The route point type. + -- @param #COORDINATE.RoutePointAction Action The route point action. + -- @param Dcs.DCSTypes#Speed Speed Airspeed in km/h. + -- @param #boolean SpeedLocked true means the speed is locked. + -- @return #table The route point. + function COORDINATE:RoutePointAir( AltType, Type, Action, Speed, SpeedLocked ) + self:F2( { AltType, Type, Action, Speed, SpeedLocked } ) + + local RoutePoint = {} + RoutePoint.x = self.x + RoutePoint.y = self.z + RoutePoint.alt = self.y + RoutePoint.alt_type = AltType + + RoutePoint.type = Type + RoutePoint.action = Action + + RoutePoint.speed = Speed / 3.6 + RoutePoint.speed_locked = true + + -- ["task"] = + -- { + -- ["id"] = "ComboTask", + -- ["params"] = + -- { + -- ["tasks"] = + -- { + -- }, -- end of ["tasks"] + -- }, -- end of ["params"] + -- }, -- end of ["task"] + + + RoutePoint.task = {} + RoutePoint.task.id = "ComboTask" + RoutePoint.task.params = {} + RoutePoint.task.params.tasks = {} + + + return RoutePoint + end + + --- Build an ground type route point. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Speed Speed Speed in km/h. + -- @param #COORDINATE.RoutePointAction Formation The route point Formation. + -- @return #table The route point. + function COORDINATE:RoutePointGround( Speed, Formation ) + self:F2( { Formation, Speed } ) + + local RoutePoint = {} + RoutePoint.x = self.x + RoutePoint.y = self.z + + RoutePoint.action = Formation or "" + + + RoutePoint.speed = Speed / 3.6 + RoutePoint.speed_locked = true + + -- ["task"] = + -- { + -- ["id"] = "ComboTask", + -- ["params"] = + -- { + -- ["tasks"] = + -- { + -- }, -- end of ["tasks"] + -- }, -- end of ["params"] + -- }, -- end of ["task"] + + + RoutePoint.task = {} + RoutePoint.task.id = "ComboTask" + RoutePoint.task.params = {} + RoutePoint.task.params.tasks = {} + + + return RoutePoint + end + + --- Creates an explosion at the point of a certain intensity. + -- @param #COORDINATE self + -- @param #number ExplosionIntensity + function COORDINATE:Explosion( ExplosionIntensity ) + self:F2( { ExplosionIntensity } ) + trigger.action.explosion( self:GetVec3(), ExplosionIntensity ) + end + + --- Creates an illumination bomb at the point. + -- @param #COORDINATE self + function COORDINATE:IlluminationBomb() + self:F2() + trigger.action.illuminationBomb( self:GetVec3() ) + end + + + --- Smokes the point in a color. + -- @param #COORDINATE self + -- @param Utilities.Utils#SMOKECOLOR SmokeColor + function COORDINATE:Smoke( SmokeColor ) + self:F2( { SmokeColor } ) + trigger.action.smoke( self:GetVec3(), SmokeColor ) + end + + --- Smoke the COORDINATE Green. + -- @param #COORDINATE self + function COORDINATE:SmokeGreen() + self:F2() + self:Smoke( SMOKECOLOR.Green ) + end + + --- Smoke the COORDINATE Red. + -- @param #COORDINATE self + function COORDINATE:SmokeRed() + self:F2() + self:Smoke( SMOKECOLOR.Red ) + end + + --- Smoke the COORDINATE White. + -- @param #COORDINATE self + function COORDINATE:SmokeWhite() + self:F2() + self:Smoke( SMOKECOLOR.White ) + end + + --- Smoke the COORDINATE Orange. + -- @param #COORDINATE self + function COORDINATE:SmokeOrange() + self:F2() + self:Smoke( SMOKECOLOR.Orange ) + end + + --- Smoke the COORDINATE Blue. + -- @param #COORDINATE self + function COORDINATE:SmokeBlue() + self:F2() + self:Smoke( SMOKECOLOR.Blue ) + end + + --- Flares the point in a color. + -- @param #COORDINATE self + -- @param Utilities.Utils#FLARECOLOR FlareColor + -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. + function COORDINATE:Flare( FlareColor, Azimuth ) + self:F2( { FlareColor } ) + trigger.action.signalFlare( self:GetVec3(), FlareColor, Azimuth and Azimuth or 0 ) + end + + --- Flare the COORDINATE White. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. + function COORDINATE:FlareWhite( Azimuth ) + self:F2( Azimuth ) + self:Flare( FLARECOLOR.White, Azimuth ) + end + + --- Flare the COORDINATE Yellow. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. + function COORDINATE:FlareYellow( Azimuth ) + self:F2( Azimuth ) + self:Flare( FLARECOLOR.Yellow, Azimuth ) + end + + --- Flare the COORDINATE Green. + -- @param #COORDINATE self + -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. + function COORDINATE:FlareGreen( Azimuth ) + self:F2( Azimuth ) + self:Flare( FLARECOLOR.Green, Azimuth ) + end + + --- Flare the COORDINATE Red. + -- @param #COORDINATE self + function COORDINATE:FlareRed( Azimuth ) + self:F2( Azimuth ) + self:Flare( FLARECOLOR.Red, Azimuth ) + end + + --- Returns if a Coordinate has Line of Sight (LOS) with the ToPointVec3. + -- @param #COORDINATE self + -- @param #COORDINATE ToCoordinate + -- @return #boolean true If the ToCoordinate has LOS with the Coordinate, otherwise false. + function COORDINATE:IsLOS( ToCoordinate ) + + -- Measurement of visibility should not be from the ground, so Adding a hypotethical 2 meters to each Coordinate. + local FromVec3 = self:GetVec3() + FromVec3.y = FromVec3.y + 2 + + local ToVec3 = ToCoordinate:GetVec3() + ToVec3.y = ToVec3.y + 2 + + local IsLOS = land.isVisible( FromVec3, ToVec3 ) + + return IsLOS + end + + + --- Set the mode to A2G + -- @param #COORDINATE self + -- @return #COORDINATE + function COORDINATE:SetModeA2G() + self.Mode = "A2G" + end + + --- Is the mode to A2G + -- @param #COORDINATE self + -- @return #boolean + function COORDINATE:IsModeA2G() + return self.Mode == "A2G" + end + + --- Set the mode to A2A + -- @param #COORDINATE self + -- @return #COORDINATE + function COORDINATE:SetModeA2A() + self.Mode = "A2A" + end + + --- Is the mode to A2A + -- @param #COORDINATE self + -- @return #boolean + function COORDINATE:IsModeA2A() + return self.Mode == "A2A" + end + + + --- Return a BR string from a COORDINATE to the COORDINATE. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return #string The BR text. + function COORDINATE:ToStringBR( FromCoordinate, Settings ) + local DirectionVec3 = self:GetDirectionVec3( FromCoordinate ) + local AngleRadians = self:GetAngleRadians( DirectionVec3 ) + local Distance = self:Get2DDistance( FromCoordinate ) + return "BR: " .. self:GetBRText( AngleRadians, Distance, Settings ) + end + + --- Return a BRAA string from a COORDINATE to the COORDINATE. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return #string The BR text. + function COORDINATE:ToStringBRAA( FromCoordinate, Settings ) + local DirectionVec3 = FromCoordinate:GetDirectionVec3( self ) + local AngleRadians = self:GetAngleRadians( DirectionVec3 ) + local Distance = FromCoordinate:Get2DDistance( self ) + local Altitude = self:GetAltitudeText() + return "BRAA: " .. self:GetBRText( AngleRadians, Distance, Settings ) + end + + --- Return a BULLS string from a COORDINATE to the BULLS of the coalition. + -- @param #COORDINATE self + -- @param Dcs.DCSCoalition#coalition.side Coalition The coalition. + -- @return #string The BR text. + function COORDINATE:ToStringBULLS( Coalition, Settings ) + local TargetCoordinate = COORDINATE:NewFromVec3( coalition.getMainRefPoint( Coalition ) ) + local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) + local AngleRadians = self:GetAngleRadians( DirectionVec3 ) + local Distance = self:Get2DDistance( TargetCoordinate ) + local Altitude = self:GetAltitudeText() + return "BULLS: " .. self:GetBRText( AngleRadians, Distance, Settings ) + end + + --- Return an aspect string from a COORDINATE to the Angle of the object. + -- @param #COORDINATE self + -- @param #COORDINATE TargetCoordinate The target COORDINATE. + -- @return #string The Aspect string, which is Hot, Cold or Flanking. + function COORDINATE:ToStringAspect( TargetCoordinate ) + local Heading = self.Heading + local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) + local Angle = self:GetAngleDegrees( DirectionVec3 ) + + if Heading then + local Aspect = Angle - Heading + if Aspect > -135 and Aspect <= -45 then + return "Flanking" + end + if Aspect > -45 and Aspect <= 45 then + return "Hot" + end + if Aspect > 45 and Aspect <= 135 then + return "Flanking" + end + if Aspect > 135 or Aspect <= -135 then + return "Cold" + end + end + return "" + end + + --- Provides a Lat Lon string + -- @param #COORDINATE self + -- @param Core.Settings#SETTINGS Settings (optional) Settings + -- @return #string The LL Text + function COORDINATE:ToStringLL( Settings ) --R2.1 Fixes issue #424. + + local LL_Accuracy = Settings and Settings.LL_Accuracy or _SETTINGS.LL_Accuracy + local LL_DMS = Settings and Settings.LL_DMS or _SETTINGS.LL_DMS + local lat, lon = coord.LOtoLL( self:GetVec3() ) + return "LL: " .. UTILS.tostringLL( lat, lon, LL_Accuracy, LL_DMS ) + end + + --- Provides a MGRS string + -- @param #COORDINATE self + -- @param Core.Settings#SETTINGS Settings (optional) Settings + -- @return #string The MGRS Text + function COORDINATE:ToStringMGRS( Settings ) --R2.1 Fixes issue #424. + + local MGRS_Accuracy = Settings and Settings.MGRS_Accuracy or _SETTINGS.MGRS_Accuracy + local lat, lon = coord.LOtoLL( self:GetVec3() ) + local MGRS = coord.LLtoMGRS( lat, lon ) + return "MGRS: " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy ) + end + + --- Provides a coordinate string of the point, based on a coordinate format system: + -- * Uses default settings in COORDINATE. + -- * Can be overridden if for a GROUP containing x clients, a menu was selected to override the default. + -- @param #COORDINATE self + -- @param #COORDINATE FromCoordinate + -- @param Core.Settings#SETTINGS Settings + -- @return #string The coordinate Text in the configured coordinate system. + function COORDINATE:ToString( FromCoordinate, Settings ) -- R2.2 + + local Settings = Settings or _SETTINGS + + if self:IsModeA2A() then + if Settings:IsA2A_BRA() then + return self:ToStringBRAA( FromCoordinate, Settings ) + end + + if Settings:IsA2A_BULLS() then + return self:ToStringBULLS( FromCoordinate, Settings ) + end + end + + if self:IsModeA2G() then + if Settings:IsA2G_LL() then + return self:ToStringLL( Settings ) + end + if Settings:IsA2G_MGRS() then + return self:ToStringMGRS( Settings ) + end + end + + return nil + + end + +end do -- POINT_VEC3 @@ -301,15 +846,11 @@ do -- POINT_VEC3 -- @param Dcs.DCSTypes#Distance x The x coordinate of the Vec3 point, pointing to the North. -- @param Dcs.DCSTypes#Distance y The y coordinate of the Vec3 point, pointing Upwards. -- @param Dcs.DCSTypes#Distance z The z coordinate of the Vec3 point, pointing to the Right. - -- @return Core.Point#POINT_VEC3 self + -- @return Core.Point#POINT_VEC3 function POINT_VEC3:New( x, y, z ) - local self = BASE:Inherit( self, BASE:New() ) - self.x = x - self.y = y - self.z = z - - self:SetMetric( true ) + local self = BASE:Inherit( self, COORDINATE:New( x, y, z ) ) -- Core.Point#POINT_VEC3 + self:F2( self ) return self end @@ -317,47 +858,30 @@ do -- POINT_VEC3 --- Create a new POINT_VEC3 object from Vec2 coordinates. -- @param #POINT_VEC3 self -- @param Dcs.DCSTypes#Vec2 Vec2 The Vec2 point. + -- @param Dcs.DCSTypes#Distance LandHeightAdd (optional) Add a landheight. -- @return Core.Point#POINT_VEC3 self function POINT_VEC3:NewFromVec2( Vec2, LandHeightAdd ) - local LandHeight = land.getHeight( Vec2 ) - - LandHeightAdd = LandHeightAdd or 0 - LandHeight = LandHeight + LandHeightAdd - - self = self:New( Vec2.x, LandHeight, Vec2.y ) - + local self = BASE:Inherit( self, COORDINATE:NewFromVec2( Vec2, LandHeightAdd ) ) -- Core.Point#POINT_VEC3 self:F2( self ) return self end + --- Create a new POINT_VEC3 object from Vec3 coordinates. -- @param #POINT_VEC3 self -- @param Dcs.DCSTypes#Vec3 Vec3 The Vec3 point. -- @return Core.Point#POINT_VEC3 self function POINT_VEC3:NewFromVec3( Vec3 ) - self = self:New( Vec3.x, Vec3.y, Vec3.z ) + local self = BASE:Inherit( self, COORDINATE:NewFromVec3( Vec3 ) ) -- Core.Point#POINT_VEC3 self:F2( self ) + return self end - --- Return the coordinates of the POINT_VEC3 in Vec3 format. - -- @param #POINT_VEC3 self - -- @return Dcs.DCSTypes#Vec3 The Vec3 coodinate. - function POINT_VEC3:GetVec3() - return { x = self.x, y = self.y, z = self.z } - end - - --- Return the coordinates of the POINT_VEC3 in Vec2 format. - -- @param #POINT_VEC3 self - -- @return Dcs.DCSTypes#Vec2 The Vec2 coodinate. - function POINT_VEC3:GetVec2() - return { x = self.x, y = self.z } - end - --- Return the x coordinate of the POINT_VEC3. -- @param #POINT_VEC3 self @@ -434,48 +958,6 @@ do -- POINT_VEC3 return self end - --- Return a random Vec2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Distance OuterRadius - -- @param Dcs.DCSTypes#Distance InnerRadius - -- @return Dcs.DCSTypes#Vec2 Vec2 - function POINT_VEC3:GetRandomVec2InRadius( OuterRadius, InnerRadius ) - self:F2( { OuterRadius, InnerRadius } ) - - local Theta = 2 * math.pi * math.random() - local Radials = math.random() + math.random() - if Radials > 1 then - Radials = 2 - Radials - end - - local RadialMultiplier - if InnerRadius and InnerRadius <= OuterRadius then - RadialMultiplier = ( OuterRadius - InnerRadius ) * Radials + InnerRadius - else - RadialMultiplier = OuterRadius * Radials - end - - local RandomVec2 - if OuterRadius > 0 then - RandomVec2 = { x = math.cos( Theta ) * RadialMultiplier + self:GetX(), y = math.sin( Theta ) * RadialMultiplier + self:GetZ() } - else - RandomVec2 = { x = self:GetX(), y = self:GetZ() } - end - - return RandomVec2 - end - - --- Return a random POINT_VEC2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Distance OuterRadius - -- @param Dcs.DCSTypes#Distance InnerRadius - -- @return #POINT_VEC2 - function POINT_VEC3:GetRandomPointVec2InRadius( OuterRadius, InnerRadius ) - self:F2( { OuterRadius, InnerRadius } ) - - return POINT_VEC2:NewFromVec2( self:GetRandomVec2InRadius( OuterRadius, InnerRadius ) ) - end - --- Return a random Vec3 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC3. -- @param #POINT_VEC3 self -- @param Dcs.DCSTypes#Distance OuterRadius @@ -500,335 +982,6 @@ do -- POINT_VEC3 return POINT_VEC3:NewFromVec3( self:GetRandomVec3InRadius( OuterRadius, InnerRadius ) ) end - - --- Return a direction vector Vec3 from POINT_VEC3 to the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3. - -- @return Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. - function POINT_VEC3:GetDirectionVec3( TargetPointVec3 ) - return { x = TargetPointVec3:GetX() - self:GetX(), y = TargetPointVec3:GetY() - self:GetY(), z = TargetPointVec3:GetZ() - self:GetZ() } - end - - --- Get a correction in radians of the real magnetic north of the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @return #number CorrectionRadians The correction in radians. - function POINT_VEC3:GetNorthCorrectionRadians() - local TargetVec3 = self:GetVec3() - local lat, lon = coord.LOtoLL(TargetVec3) - local north_posit = coord.LLtoLO(lat + 1, lon) - return math.atan2( north_posit.z - TargetVec3.z, north_posit.x - TargetVec3.x ) - end - - - --- Return an angle in radians from the POINT_VEC3 using a direction vector in Vec3 format. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. - -- @return #number DirectionRadians The angle in radians. - function POINT_VEC3:GetAngleRadians( DirectionVec3 ) - local DirectionRadians = math.atan2( DirectionVec3.z, DirectionVec3.x ) - --DirectionRadians = DirectionRadians + self:GetNorthCorrectionRadians() - if DirectionRadians < 0 then - DirectionRadians = DirectionRadians + 2 * math.pi -- put dir in range of 0 to 2*pi ( the full circle ) - end - return DirectionRadians - end - - --- Return an angle in degrees from the POINT_VEC3 using a direction vector in Vec3 format. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Vec3 DirectionVec3 The direction vector in Vec3 format. - -- @return #number DirectionRadians The angle in degrees. - function POINT_VEC3:GetAngleDegrees( DirectionVec3 ) - local AngleRadians = self:GetAngleRadians(DirectionVec3) - local Angle = UTILS.ToDegree( AngleRadians ) - return Angle - end - - - --- Return the 2D distance in meters between the target POINT_VEC3 and the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3. - -- @return Dcs.DCSTypes#Distance Distance The distance in meters. - function POINT_VEC3:Get2DDistance( TargetPointVec3 ) - local TargetVec3 = TargetPointVec3:GetVec3() - local SourceVec3 = self:GetVec3() - return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 - end - - --- Return the 3D distance in meters between the target POINT_VEC3 and the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param #POINT_VEC3 TargetPointVec3 The target POINT_VEC3. - -- @return Dcs.DCSTypes#Distance Distance The distance in meters. - function POINT_VEC3:Get3DDistance( TargetPointVec3 ) - local TargetVec3 = TargetPointVec3:GetVec3() - local SourceVec3 = self:GetVec3() - return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.y - SourceVec3.y ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 - end - - --- Provides a Bearing / Range string - -- @param #POINT_VEC3 self - -- @param #number AngleRadians The angle in randians - -- @param #number Distance The distance - -- @return #string The BR Text - function POINT_VEC3:GetBRText( AngleRadians, Distance ) - - AngleRadians = UTILS.Round( UTILS.ToDegree( AngleRadians ), 0 ) - if self:IsMetric() then - Distance = UTILS.Round( Distance / 1000, 2 ) - else - Distance = UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) - end - - local s = string.format( '%03d', AngleRadians ) .. ' for ' .. Distance - - s = s .. self:GetAltitudeText() -- When the POINT is a VEC2, there will be no altitude shown. - - return s - end - - - --- Return the altitude text of the POINT_VEC3. - -- @param #POINT_VEC3 self - -- @return #string Altitude text. - function POINT_VEC3:GetAltitudeText() - if self:IsMetric() then - return ' at ' .. UTILS.Round( self:GetY(), -3 ) - else - return ' at ' .. UTILS.Round( UTILS.MetersToFeet( self:GetY() ), 0 ) - end - end - - --- Sets the POINT_VEC3 metric or NM. - -- @param #POINT_VEC3 self - -- @param #boolean Metric true means metric, false means NM. - function POINT_VEC3:SetMetric( Metric ) - self.Metric = Metric - end - - --- Gets if the POINT_VEC3 is metric or NM. - -- @param #POINT_VEC3 self - -- @return #boolean Metric true means metric, false means NM. - function POINT_VEC3:IsMetric() - return self.Metric - end - - --- Add a Distance in meters from the POINT_VEC3 horizontal plane, with the given angle, and calculate the new POINT_VEC3. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Distance Distance The Distance to be added in meters. - -- @param Dcs.DCSTypes#Angle Angle The Angle in degrees. - -- @return #POINT_VEC3 The new calculated POINT_VEC3. - function POINT_VEC3:Translate( Distance, Angle ) - local SX = self:GetX() - local SZ = self:GetZ() - local Radians = Angle / 180 * math.pi - local TX = Distance * math.cos( Radians ) + SX - local TZ = Distance * math.sin( Radians ) + SZ - - return POINT_VEC3:New( TX, self:GetY(), TZ ) - end - - - - --- Build an air type route point. - -- @param #POINT_VEC3 self - -- @param #POINT_VEC3.RoutePointAltType AltType The altitude type. - -- @param #POINT_VEC3.RoutePointType Type The route point type. - -- @param #POINT_VEC3.RoutePointAction Action The route point action. - -- @param Dcs.DCSTypes#Speed Speed Airspeed in km/h. - -- @param #boolean SpeedLocked true means the speed is locked. - -- @return #table The route point. - function POINT_VEC3:RoutePointAir( AltType, Type, Action, Speed, SpeedLocked ) - self:F2( { AltType, Type, Action, Speed, SpeedLocked } ) - - local RoutePoint = {} - RoutePoint.x = self.x - RoutePoint.y = self.z - RoutePoint.alt = self.y - RoutePoint.alt_type = AltType - - RoutePoint.type = Type - RoutePoint.action = Action - - RoutePoint.speed = Speed / 3.6 - RoutePoint.speed_locked = true - - -- ["task"] = - -- { - -- ["id"] = "ComboTask", - -- ["params"] = - -- { - -- ["tasks"] = - -- { - -- }, -- end of ["tasks"] - -- }, -- end of ["params"] - -- }, -- end of ["task"] - - - RoutePoint.task = {} - RoutePoint.task.id = "ComboTask" - RoutePoint.task.params = {} - RoutePoint.task.params.tasks = {} - - - return RoutePoint - end - - --- Build an ground type route point. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Speed Speed Speed in km/h. - -- @param #POINT_VEC3.RoutePointAction Formation The route point Formation. - -- @return #table The route point. - function POINT_VEC3:RoutePointGround( Speed, Formation ) - self:F2( { Formation, Speed } ) - - local RoutePoint = {} - RoutePoint.x = self.x - RoutePoint.y = self.z - - RoutePoint.action = Formation or "" - - - RoutePoint.speed = Speed / 3.6 - RoutePoint.speed_locked = true - - -- ["task"] = - -- { - -- ["id"] = "ComboTask", - -- ["params"] = - -- { - -- ["tasks"] = - -- { - -- }, -- end of ["tasks"] - -- }, -- end of ["params"] - -- }, -- end of ["task"] - - - RoutePoint.task = {} - RoutePoint.task.id = "ComboTask" - RoutePoint.task.params = {} - RoutePoint.task.params.tasks = {} - - - return RoutePoint - end - - --- Creates an explosion at the point of a certain intensity. - -- @param #POINT_VEC3 self - -- @param #number ExplosionIntensity - function POINT_VEC3:Explosion( ExplosionIntensity ) - self:F2( { ExplosionIntensity } ) - trigger.action.explosion( self:GetVec3(), ExplosionIntensity ) - end - - --- Creates an illumination bomb at the point. - -- @param #POINT_VEC3 self - function POINT_VEC3:IlluminationBomb() - self:F2() - trigger.action.illuminationBomb( self:GetVec3() ) - end - - - --- Smokes the point in a color. - -- @param #POINT_VEC3 self - -- @param Utilities.Utils#SMOKECOLOR SmokeColor - function POINT_VEC3:Smoke( SmokeColor ) - self:F2( { SmokeColor } ) - trigger.action.smoke( self:GetVec3(), SmokeColor ) - end - - --- Smoke the POINT_VEC3 Green. - -- @param #POINT_VEC3 self - function POINT_VEC3:SmokeGreen() - self:F2() - self:Smoke( SMOKECOLOR.Green ) - end - - --- Smoke the POINT_VEC3 Red. - -- @param #POINT_VEC3 self - function POINT_VEC3:SmokeRed() - self:F2() - self:Smoke( SMOKECOLOR.Red ) - end - - --- Smoke the POINT_VEC3 White. - -- @param #POINT_VEC3 self - function POINT_VEC3:SmokeWhite() - self:F2() - self:Smoke( SMOKECOLOR.White ) - end - - --- Smoke the POINT_VEC3 Orange. - -- @param #POINT_VEC3 self - function POINT_VEC3:SmokeOrange() - self:F2() - self:Smoke( SMOKECOLOR.Orange ) - end - - --- Smoke the POINT_VEC3 Blue. - -- @param #POINT_VEC3 self - function POINT_VEC3:SmokeBlue() - self:F2() - self:Smoke( SMOKECOLOR.Blue ) - end - - --- Flares the point in a color. - -- @param #POINT_VEC3 self - -- @param Utilities.Utils#FLARECOLOR FlareColor - -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. - function POINT_VEC3:Flare( FlareColor, Azimuth ) - self:F2( { FlareColor } ) - trigger.action.signalFlare( self:GetVec3(), FlareColor, Azimuth and Azimuth or 0 ) - end - - --- Flare the POINT_VEC3 White. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. - function POINT_VEC3:FlareWhite( Azimuth ) - self:F2( Azimuth ) - self:Flare( FLARECOLOR.White, Azimuth ) - end - - --- Flare the POINT_VEC3 Yellow. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. - function POINT_VEC3:FlareYellow( Azimuth ) - self:F2( Azimuth ) - self:Flare( FLARECOLOR.Yellow, Azimuth ) - end - - --- Flare the POINT_VEC3 Green. - -- @param #POINT_VEC3 self - -- @param Dcs.DCSTypes#Azimuth (optional) Azimuth The azimuth of the flare direction. The default azimuth is 0. - function POINT_VEC3:FlareGreen( Azimuth ) - self:F2( Azimuth ) - self:Flare( FLARECOLOR.Green, Azimuth ) - end - - --- Flare the POINT_VEC3 Red. - -- @param #POINT_VEC3 self - function POINT_VEC3:FlareRed( Azimuth ) - self:F2( Azimuth ) - self:Flare( FLARECOLOR.Red, Azimuth ) - end - - --- Returns if a PointVec3 has Line of Sight (LOS) with the ToPointVec3. - -- @param #POINT_VEC3 self - -- @param #POINT_VEC3 ToPointVec3 - -- @return #boolean true If the ToPointVec3 has LOS with the PointVec3, otherwise false. - function POINT_VEC3:IsLOS( ToPointVec3 ) --R2.1 - - -- Measurement of visibility should not be from the ground, so Adding a hypotethical 2 meters to each PointVec3. - local FromVec3 = self:GetVec3() - FromVec3.y = FromVec3.y + 2 - - local ToVec3 = ToPointVec3:GetVec3() - ToVec3.y = ToVec3.y + 2 - - local IsLOS = land.isVisible( FromVec3, ToVec3 ) - - return IsLOS - end - - end do -- POINT_VEC2 @@ -848,7 +1001,7 @@ do -- POINT_VEC2 LandHeightAdd = LandHeightAdd or 0 LandHeight = LandHeight + LandHeightAdd - self = BASE:Inherit( self, POINT_VEC3:New( x, LandHeight, y ) ) + local self = BASE:Inherit( self, COORDINATE:New( x, LandHeight, y ) ) -- Core.Point#POINT_VEC2 self:F2( self ) return self @@ -865,7 +1018,7 @@ do -- POINT_VEC2 LandHeightAdd = LandHeightAdd or 0 LandHeight = LandHeight + LandHeightAdd - self = BASE:Inherit( self, POINT_VEC3:New( Vec2.x, LandHeight, Vec2.y ) ) + local self = BASE:Inherit( self, COORDINATE:New( Vec2.x, LandHeight, Vec2.y ) ) -- Core.Point#POINT_VEC2 self:F2( self ) return self @@ -879,7 +1032,7 @@ do -- POINT_VEC2 local self = BASE:Inherit( self, BASE:New() ) - self = BASE:Inherit( self, POINT_VEC3:New( Vec3.x, Vec3.y, Vec3.z ) ) + local self = BASE:Inherit( self, COORDINATE:New( Vec3.x, Vec3.y, Vec3.z ) ) -- Core.Point#POINT_VEC2 self:F2( self ) return self @@ -899,27 +1052,6 @@ do -- POINT_VEC2 return self.z end - --- Return the altitude (height) of the land at the POINT_VEC2. - -- @param #POINT_VEC2 self - -- @return #number The land altitude. - function POINT_VEC2:GetAlt() - return land.getHeight( { x = self.x, y = self.z } ) - end - - --- Return Return the Lat(itude) coordinate of the POINT_VEC2 (ie: (parent)POINT_VEC3.x). - -- @param #POINT_VEC2 self - -- @return #number The x coodinate. - function POINT_VEC2:GetLat() - return self.x - end - - --- Return the Lon(gitude) coordinate of the POINT_VEC2 (ie: (parent)POINT_VEC3.z). - -- @param #POINT_VEC2 self - -- @return #number The y coodinate. - function POINT_VEC2:GetLon() - return self.z - end - --- Set the x coordinate of the POINT_VEC2. -- @param #POINT_VEC2 self -- @param #number x The x coordinate. @@ -938,6 +1070,13 @@ do -- POINT_VEC2 return self end + --- Return Return the Lat(itude) coordinate of the POINT_VEC2 (ie: (parent)POINT_VEC3.x). + -- @param #POINT_VEC2 self + -- @return #number The x coodinate. + function POINT_VEC2:GetLat() + return self.x + end + --- Set the Lat(itude) coordinate of the POINT_VEC2 (ie: POINT_VEC3.x). -- @param #POINT_VEC2 self -- @param #number x The x coordinate. @@ -947,13 +1086,11 @@ do -- POINT_VEC2 return self end - --- Set the altitude of the POINT_VEC2. + --- Return the Lon(gitude) coordinate of the POINT_VEC2 (ie: (parent)POINT_VEC3.z). -- @param #POINT_VEC2 self - -- @param #number Altitude The land altitude. If nothing (nil) is given, then the current land altitude is set. - -- @return #POINT_VEC2 - function POINT_VEC2:SetAlt( Altitude ) - self.y = Altitude or land.getHeight( { x = self.x, y = self.z } ) - return self + -- @return #number The y coodinate. + function POINT_VEC2:GetLon() + return self.z end --- Set the Lon(gitude) coordinate of the POINT_VEC2 (ie: POINT_VEC3.z). @@ -965,6 +1102,22 @@ do -- POINT_VEC2 return self end + --- Return the altitude (height) of the land at the POINT_VEC2. + -- @param #POINT_VEC2 self + -- @return #number The land altitude. + function POINT_VEC2:GetAlt() + return self.y ~= 0 or land.getHeight( { x = self.x, y = self.z } ) + end + + --- Set the altitude of the POINT_VEC2. + -- @param #POINT_VEC2 self + -- @param #number Altitude The land altitude. If nothing (nil) is given, then the current land altitude is set. + -- @return #POINT_VEC2 + function POINT_VEC2:SetAlt( Altitude ) + self.y = Altitude or land.getHeight( { x = self.x, y = self.z } ) + return self + end + --- Add to the x coordinate of the POINT_VEC2. -- @param #POINT_VEC2 self -- @param #number x The x coordinate. @@ -992,8 +1145,50 @@ do -- POINT_VEC2 return self end + --- Return a random Vec2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC2. + -- @param #POINT_VEC2 self + -- @param Dcs.DCSTypes#Distance OuterRadius + -- @param Dcs.DCSTypes#Distance InnerRadius + -- @return Dcs.DCSTypes#Vec2 Vec2 + function POINT_VEC2:GetRandomVec2InRadius( OuterRadius, InnerRadius ) + self:F2( { OuterRadius, InnerRadius } ) + + local Theta = 2 * math.pi * math.random() + local Radials = math.random() + math.random() + if Radials > 1 then + Radials = 2 - Radials + end + + local RadialMultiplier + if InnerRadius and InnerRadius <= OuterRadius then + RadialMultiplier = ( OuterRadius - InnerRadius ) * Radials + InnerRadius + else + RadialMultiplier = OuterRadius * Radials + end + + local RandomVec2 + if OuterRadius > 0 then + RandomVec2 = { x = math.cos( Theta ) * RadialMultiplier + self:GetX(), y = math.sin( Theta ) * RadialMultiplier + self:GetZ() } + else + RandomVec2 = { x = self:GetX(), y = self:GetZ() } + end + + return RandomVec2 + end + + --- Return a random POINT_VEC2 within an Outer Radius and optionally NOT within an Inner Radius of the POINT_VEC2. + -- @param #POINT_VEC2 self + -- @param Dcs.DCSTypes#Distance OuterRadius + -- @param Dcs.DCSTypes#Distance InnerRadius + -- @return #POINT_VEC2 + function POINT_VEC2:GetRandomPointVec2InRadius( OuterRadius, InnerRadius ) + self:F2( { OuterRadius, InnerRadius } ) + + return POINT_VEC2:NewFromVec2( self:GetRandomVec2InRadius( OuterRadius, InnerRadius ) ) + end +-- TODO: Check this to replace --- Calculate the distance from a reference @{#POINT_VEC2}. -- @param #POINT_VEC2 self -- @param #POINT_VEC2 PointVec2Reference The reference @{#POINT_VEC2}. @@ -1007,6 +1202,8 @@ do -- POINT_VEC2 return Distance end +--TODO: check this to replace + --- Calculate the distance from a reference @{DCSTypes#Vec2}. -- @param #POINT_VEC2 self -- @param Dcs.DCSTypes#Vec2 Vec2Reference The reference @{DCSTypes#Vec2}. @@ -1038,225 +1235,4 @@ do -- POINT_VEC2 end -do -- COORDINATE - --- COORDINATE constructor. - -- @param #COORDINATE self - -- @param Dcs.DCSTypes#Distance x The x coordinate of the Vec3 point, pointing to the North. - -- @param Dcs.DCSTypes#Distance y The y coordinate of the Vec3 point, pointing to the Right. - -- @param Dcs.DCSTypes#Distance LandHeightAdd (optional) The default height if required to be evaluated will be the land height of the x, y coordinate. You can specify an extra height to be added to the land height. - -- @return Core.Point#COORDINATE - function COORDINATE:New( x, y, LandHeightAdd ) --R2.1 Fixes issue #424. - - self = BASE:Inherit( self, POINT_VEC2:New( x, y, LandHeightAdd ) ) -- Core.Point#COORDINATE - self:F2( self ) - - return self - end - - --- Create a new COORDINATE object from Vec2 coordinates. - -- @param #COORDINATE self - -- @param Dcs.DCSTypes#Vec2 Vec2 The Vec2 point. - -- @param Dcs.DCSTypes#Distance LandHeightAdd (optional) The default height if required to be evaluated will be the land height of the x, y coordinate. You can specify an extra height to be added to the land height. - -- @return Core.Point#COORDINATE self - function COORDINATE:NewFromVec2( Vec2, LandHeightAdd ) --R2.1 Fixes issue #424. - - self = BASE:Inherit( self, POINT_VEC2:NewFromVec2( Vec2, LandHeightAdd ) ) -- Core.Point#COORDINATE - self:F2( self ) - - return self - end - - --- Create a new COORDINATE object from Vec3 coordinates. - -- @param #COORDINATE self - -- @param Dcs.DCSTypes#Vec3 Vec3 The Vec3 point. - -- @return Core.Point#COORDINATE self - function COORDINATE:NewFromVec3( Vec3 ) --R2.1 Fixes issue #424. - - self = BASE:Inherit( self, POINT_VEC3:NewFromVec3( Vec3 ) ) -- Core.Point#COORDINATE - self:F2( self ) - - return self - end - - function COORDINATE:SetHeading( Heading ) - self.Heading = Heading - end - - - --- Return a BR string from a COORDINATE to the COORDINATE. - -- @param #COORDINATE self - -- @param #COORDINATE TargetCoordinate The target COORDINATE. - -- @return #string The BR text. - function COORDINATE:ToStringBR( TargetCoordinate ) - local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) - local AngleRadians = self:GetAngleRadians( DirectionVec3 ) - local Distance = self:Get2DDistance( TargetCoordinate ) - return "BR: " .. self:GetBRText( AngleRadians, Distance ) - end - - --- Return a BRAA string from a COORDINATE to the COORDINATE. - -- @param #COORDINATE self - -- @param #COORDINATE TargetCoordinate The target COORDINATE. - -- @return #string The BR text. - function COORDINATE:ToStringBRAA( TargetCoordinate ) - local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) - local AngleRadians = self:GetAngleRadians( DirectionVec3 ) - local Distance = self:Get2DDistance( TargetCoordinate ) - local Altitude = self:GetAltitudeText() - return "BRAA: " .. self:GetBRText( AngleRadians, Distance ) - end - - --- Return a BULLS string from a COORDINATE to the BULLS of the coalition. - -- @param #COORDINATE self - -- @param Dcs.DCSCoalition#coalition.side Coalition The coalition. - -- @return #string The BR text. - function COORDINATE:ToStringBULLS( Coalition ) - local TargetCoordinate = COORDINATE:NewFromVec3( coalition.getMainRefPoint( Coalition ) ) - local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) - local AngleRadians = self:GetAngleRadians( DirectionVec3 ) - local Distance = self:Get2DDistance( TargetCoordinate ) - local Altitude = self:GetAltitudeText() - return "BULLS: " .. self:GetBRText( AngleRadians, Distance ) - end - - --- Return an aspect string from a COORDINATE to the Angle of the object. - -- @param #COORDINATE self - -- @param #COORDINATE TargetCoordinate The target COORDINATE. - -- @return #string The Aspect string, which is Hot, Cold or Flanking. - function COORDINATE:ToStringAspect( TargetCoordinate ) - local Heading = self.Heading - local DirectionVec3 = self:GetDirectionVec3( TargetCoordinate ) - local Angle = self:GetAngleDegrees( DirectionVec3 ) - - if Heading then - local Aspect = Angle - Heading - if Aspect > -135 and Aspect <= -45 then - return "Flanking" - end - if Aspect > -45 and Aspect <= 45 then - return "Hot" - end - if Aspect > 45 and Aspect <= 135 then - return "Flanking" - end - if Aspect > 135 or Aspect <= -135 then - return "Cold" - end - end - return "" - end - - --- Provides a Lat Lon string - -- @param #COORDINATE self - -- @param #number LL_Accuracy The accurancy of significant numbers behind the comma... So Accurancy of 2 is 0.01. - -- @param #boolean LL_DMS true = Degrees, Minutes, Seconds; false = Degrees, Minutes - -- @return #string The LL Text - function COORDINATE:ToStringLL( LL_Accuracy, LL_DMS ) --R2.1 Fixes issue #424. - - LL_Accuracy = LL_Accuracy or self.LL_Accuracy - LL_DMS = LL_DMS or self.LL_DMS - local lat, lon = coord.LOtoLL( self:GetVec3() ) - return "LL: " .. UTILS.tostringLL( lat, lon, LL_Accuracy, LL_DMS ) - end - - --- Provides a MGRS string - -- @param #COORDINATE self - -- @param #number MGRS_Accuracy of the 5 digit code. - -- Precision depends on the Accuracy choosen: - -- * 0 = no digits - precision level 100 km - -- * 1 = 1 digits - precision level 10 km - -- * 2 = 2 digits - precision level 1 km - -- * 3 = 3 digits - precision level 100 m - -- * 4 = 4 digits - precision level 10 m. - -- @return #string The MGRS Text - function COORDINATE:ToStringMGRS( MGRS_Accuracy ) --R2.1 Fixes issue #424. - - MGRS_Accuracy = MGRS_Accuracy or self.MGRS_Accuracy - local lat, lon = coord.LOtoLL( self:GetVec3() ) - local MGRS = coord.LLtoMGRS( lat, lon ) - return "MGRS: " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy ) - end - - --- Provides a coordinate string of the point, based on a coordinate format system: - -- * Uses default settings in COORDINATE. - -- * Can be overridden if for a GROUP containing x clients, a menu was selected to override the default. - -- - -- @param #COORDINATE self - -- @return #string The coordinate Text in the configured coordinate system. - function COORDINATE:ToString() --R2.1 Fixes issue #424. - - local Coordinate = COORDINATE -- Core.Point#COORDINATE - - local CoordSystem = Coordinate.System - - if CoordSystem == "LL" then - return self:ToStringLL( Coordinate.LL_Accuracy, Coordinate.LL_DMS ) - end - - if CoordSystem == "MGRS" then - return self:ToStringMGRS( Coordinate.MGRS_Accuracy ) - end - - return nil - - end - - --- @param #COORDINATE self - -- @return #string The coordinate Text in the configured coordinate system. - function COORDINATE:CoordinateMenu( RootMenu ) --R2.1 Fixes issue #424. - - if self.SystemMenu then - self.SystemMenu:Remove() - self.SystemMenu = nil - end - - self.SystemMenu = MENU_MISSION:New( "System Settings" ) - local CoordinateMenu = MENU_MISSION:New( "Coordinates", self.SystemMenu ) - - local Coordinate = COORDINATE - - if Coordinate.System == "LL" then - MENU_MISSION_COMMAND:New( "Activate MGRS", CoordinateMenu, Coordinate.MenuSystem, Coordinate, "MGRS" ) - MENU_MISSION_COMMAND:New( "LL Accuracy 1", CoordinateMenu, Coordinate.MenuLL_Accuracy, Coordinate, 1 ) - MENU_MISSION_COMMAND:New( "LL Accuracy 2", CoordinateMenu, Coordinate.MenuLL_Accuracy, Coordinate, 2 ) - MENU_MISSION_COMMAND:New( "LL Accuracy 3", CoordinateMenu, Coordinate.MenuLL_Accuracy, Coordinate, 3 ) - MENU_MISSION_COMMAND:New( "LL Decimal On", CoordinateMenu, Coordinate.MenuLL_DMS, Coordinate, true ) - MENU_MISSION_COMMAND:New( "LL Decimal Off", CoordinateMenu, Coordinate.MenuLL_DMS, Coordinate, false ) - end - - if Coordinate.System == "MGRS" then - MENU_MISSION_COMMAND:New( "Activate LL", CoordinateMenu, Coordinate.MenuSystem, Coordinate, "LL" ) - MENU_MISSION_COMMAND:New( "MGRS Accuracy 1", CoordinateMenu, Coordinate.MenuMGRS_Accuracy, Coordinate, 1 ) - MENU_MISSION_COMMAND:New( "MGRS Accuracy 2", CoordinateMenu, Coordinate.MenuMGRS_Accuracy, Coordinate, 2 ) - MENU_MISSION_COMMAND:New( "MGRS Accuracy 3", CoordinateMenu, Coordinate.MenuMGRS_Accuracy, Coordinate, 3 ) - MENU_MISSION_COMMAND:New( "MGRS Accuracy 4", CoordinateMenu, Coordinate.MenuMGRS_Accuracy, Coordinate, 4 ) - MENU_MISSION_COMMAND:New( "MGRS Accuracy 5", CoordinateMenu, Coordinate.MenuMGRS_Accuracy, Coordinate, 5 ) - end - - end - - --- @param #COORDINATE self - function COORDINATE:MenuSystem( System ) --R2.1 Fixes issue #424. - self.System = System - self:CoordinateMenu() - end - - --- @param #COORDINATE self - function COORDINATE:MenuLL_Accuracy( LL_Accuracy ) --R2.1 Fixes issue #424. - self.LL_Accuracy = LL_Accuracy - self:CoordinateMenu() - end - - --- @param #COORDINATE self - function COORDINATE:MenuLL_DMS( LL_DMS ) --R2.1 Fixes issue #424. - self.LL_DMS = LL_DMS - self:CoordinateMenu() - end - --- @param #COORDINATE self - function COORDINATE:MenuMGRS_Accuracy( MGRS_Accuracy ) --R2.1 Fixes issue #424. - self.MGRS_Accuracy = MGRS_Accuracy - self:CoordinateMenu() - end - -end diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua new file mode 100644 index 000000000..3e71bdf47 --- /dev/null +++ b/Moose Development/Moose/Core/Settings.lua @@ -0,0 +1,228 @@ +--- **Core** - **SETTINGS** classe defines the format settings management for measurement. +-- +-- ![Banner Image](..\Presentations\SETTINGS\Dia1.JPG) +-- +-- ==== +-- +-- # Demo Missions +-- +-- ### [SETTINGS Demo Missions source code]() +-- +-- ### [SETTINGS Demo Missions, only for beta testers]() +-- +-- ### [ALL Demo Missions pack of the last release](https://github.com/FlightControl-Master/MOOSE_MISSIONS/releases) +-- +-- ==== +-- +-- # YouTube Channel +-- +-- ### [SETTINGS YouTube Channel]() +-- +-- === +-- +-- ### Authors: +-- +-- * FlightControl : Design & Programming +-- +-- ### Contributions: +-- +-- @module Settings + + +--- @type SETTINGS +-- @field #number LL_Accuracy +-- @field #boolean LL_DMS +-- @field #number MGRS_Accuracy +-- @field #string A2GSystem +-- @field #string A2ASystem +-- @extends Core.Base#BASE + +--- # SETTINGS class, extends @{Base#BASE} +-- +-- @field #SETTINGS +SETTINGS = { + ClassName = "SETTINGS", + LL_Accuracy = 2, + LL_DMS = true, + MGRS_Accuracy = 5, + A2GSystem = "MGRS", + A2ASystem = "BRA", + +} + + + +do -- SETTINGS + + --- SETTINGS constructor. + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:New() + + local self = BASE:Inherit( self, BASE:New() ) -- #SETTINGS + + self:SetMetric() -- Defaults + self:SetA2G_MGRS() -- Defaults + self:SetA2A_BRA() -- Defaults + + return self + end + + + --- Sets the SETTINGS metric. + -- @param #SETTINGS self + function SETTINGS:SetMetric() + self.Metric = true + end + + --- Gets if the SETTINGS is metric. + -- @param #SETTINGS self + -- @return #boolean true if metric. + function SETTINGS:IsMetric() + return self.Metric == true + end + + --- Sets the SETTINGS imperial. + -- @param #SETTINGS self + function SETTINGS:SetImperial() + self.Metric = false + end + + --- Gets if the SETTINGS is imperial. + -- @param #SETTINGS self + -- @return #boolean true if imperial. + function SETTINGS:IsImperial() + return self.Metric == false + end + + --- Sets A2G LL + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SetA2G_LL() + self.A2GSystem = "LL" + end + + --- Is LL + -- @param #SETTINGS self + -- @return #boolean true if LL + function SETTINGS:IsA2G_LL() + return self.A2GSystem == "LL" + end + + --- Sets A2G MGRS + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SetA2G_MGRS() + self.A2GSystem = "MGRS" + end + + --- Is MGRS + -- @param #SETTINGS self + -- @return #boolean true if MGRS + function SETTINGS:IsA2G_MGRS() + return self.A2GSystem == "MGRS" + end + + --- Sets A2A BRA + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SetA2A_BRA() + self.A2ASystem = "BRA" + end + + --- Is BRA + -- @param #SETTINGS self + -- @return #boolean true if BRA + function SETTINGS:IsA2A_BRA() + return self.A2ASystem == "BRA" + end + + --- Sets A2A BULLS + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SetA2A_BULLS() + self.A2ASystem = "BULLS" + end + + --- Is BULLS + -- @param #SETTINGS self + -- @return #boolean true if BULLS + function SETTINGS:IsA2A_BULLS() + return self.A2ASystem == "BULLS" + end + + --- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SettingsMenu( RootMenu ) + + if self.SystemMenu then + self.SystemMenu:Remove() + self.SystemMenu = nil + end + + self.SystemMenu = MENU_MISSION:New( "Coordinate Settings" ) + local A2GCoordinateMenu = MENU_MISSION:New( "A2G Coordinate System", self.SystemMenu ) + + if self:IsA2GLL() then + MENU_MISSION_COMMAND:New( "Activate MGRS", A2GCoordinateMenu, self.A2GMenuSystem, self, "MGRS" ) + MENU_MISSION_COMMAND:New( "LL Accuracy 1", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 1 ) + MENU_MISSION_COMMAND:New( "LL Accuracy 2", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 2 ) + MENU_MISSION_COMMAND:New( "LL Accuracy 3", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 3 ) + MENU_MISSION_COMMAND:New( "LL Decimal On", A2GCoordinateMenu, self.MenuLL_DMS, self, true ) + MENU_MISSION_COMMAND:New( "LL Decimal Off", A2GCoordinateMenu, self.MenuLL_DMS, self, false ) + end + + if self:IsA2GMGRS() then + MENU_MISSION_COMMAND:New( "Activate LL", A2GCoordinateMenu, self.A2GMenuSystem, self, "LL" ) + MENU_MISSION_COMMAND:New( "MGRS Accuracy 1", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 1 ) + MENU_MISSION_COMMAND:New( "MGRS Accuracy 2", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 2 ) + MENU_MISSION_COMMAND:New( "MGRS Accuracy 3", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 3 ) + MENU_MISSION_COMMAND:New( "MGRS Accuracy 4", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 4 ) + MENU_MISSION_COMMAND:New( "MGRS Accuracy 5", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 5 ) + end + + local A2ACoordinateMenu = MENU_MISSION:New( "A2A Coordinate System", self.SystemMenu ) + + if self:IsA2ABULLS() then + MENU_MISSION_COMMAND:New( "Activate BRA", A2GCoordinateMenu, self.A2AMenuSystem, self, "BRA" ) + end + + if self:IsA2ABRA() then + MENU_MISSION_COMMAND:New( "Activate BULLS", A2GCoordinateMenu, self.A2AMenuSystem, self, "BULLS" ) + end + + return self + end + + --- @param #SETTINGS self + function SETTINGS:A2GMenuSystem( A2GSystem ) + self.A2GSystem = A2GSystem + self:CoordinateMenu() + end + + --- @param #SETTINGS self + function SETTINGS:A2AMenuSystem( A2ASystem ) + self.A2ASystem = A2ASystem + self:CoordinateMenu() + end + + --- @param #SETTINGS self + function SETTINGS:MenuLL_Accuracy( LL_Accuracy ) + self.LL_Accuracy = LL_Accuracy + self:CoordinateMenu() + end + + --- @param #SETTINGS self + function SETTINGS:MenuLL_DMS( LL_DMS ) + self.LL_DMS = LL_DMS + self:CoordinateMenu() + end + --- @param #SETTINGS self + function SETTINGS:MenuMGRS_Accuracy( MGRS_Accuracy ) + self.MGRS_Accuracy = MGRS_Accuracy + self:CoordinateMenu() + end + +end + + diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index f75210006..6c92961e8 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1308,7 +1308,7 @@ do -- DETECTION_BASE --- Get the COORDINATE of a detection item using a given numeric index. -- @param #DETECTION_BASE self -- @param #number Index - -- @return Core.Point#COORDINATE Coordinate + -- @return Core.Point#COORDINATE function DETECTION_BASE:GetDetectedItemCoordinate( Index ) -- If the Zone is set, return the coordinate of the Zone. @@ -1317,14 +1317,15 @@ do -- DETECTION_BASE local DetectedZone = self:GetDetectedItemZone( Index ) if DetectedZone then - local Coordinate = DetectedZone:GetCoordinate() + local Coordinate = DetectedZone:GetPointVec2() Coordinate:SetHeading(FirstUnit:GetHeading()) + Coordinate:SetAlt( FirstUnit:GetAltitude() ) return Coordinate end -- If no Zone is set, return the coordinate of the first unit in the Set if FirstUnit then - local Coordinate = FirstUnit:GetCoordinate() + local Coordinate = FirstUnit:GetPointVec3() FirstUnit:SetHeading(FirstUnit:GetHeading()) return Coordinate end diff --git a/Moose Development/Moose/Moose.lua b/Moose Development/Moose/Moose.lua index 46fdaa17c..194951078 100644 --- a/Moose Development/Moose/Moose.lua +++ b/Moose Development/Moose/Moose.lua @@ -9,4 +9,5 @@ _SCHEDULEDISPATCHER = SCHEDULEDISPATCHER:New() -- Core.Timer#SCHEDULEDISPATCHER --- Declare the main database object, which is used internally by the MOOSE classes. _DATABASE = DATABASE:New() -- Database#DATABASE ---COORDINATE:CoordinateMenu() +_SETTINGS = SETTINGS:New() +_SETTINGS:SettingsMenu(nil) diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 5c95f5b8a..7b584a559 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -1403,9 +1403,10 @@ function TASK:ReportDetails( TaskGroup ) --R2.1 fixed report. Now nicely formatt elseif type(TaskInfo) == "table" then if TaskInfoID == "Coordinates" then local FromCoordinate = TaskGroup:GetUnit(1):GetCoordinate() + local ToCoordinate = TaskInfo -- Core.Point#COORDINATE Report:Add( TaskInfoIDText ) - Report:AddIndent( TaskInfo:ToStringBRAA( FromCoordinate ) .. ", " .. TaskInfo:ToStringAspect( FromCoordinate ) ) - Report:AddIndent( TaskInfo:ToStringBULLS( TaskGroup:GetCoalition() ) ) + Report:AddIndent( ToCoordinate:ToStringBRAA( FromCoordinate ) .. ", " .. TaskInfo:ToStringAspect( FromCoordinate ) ) + Report:AddIndent( ToCoordinate:ToStringBULLS( TaskGroup:GetCoalition() ) ) else end end diff --git a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua index 04d8c7664..6b1bba3eb 100644 --- a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua @@ -72,7 +72,7 @@ do -- TASK_A2A_DISPATCHER self.Mission = Mission self.Detection:FilterCategories( Unit.Category.AIRPLANE, Unit.Category.HELICOPTER ) - self.Detection:InitDetectRadar( true ) + --self.Detection:InitDetectRadar( true ) self.Detection:SetDetectionInterval( 30 ) self:AddTransition( "Started", "Assign", "Started" ) @@ -190,7 +190,11 @@ do -- TASK_A2A_DISPATCHER local DetectedItemsCount = DetectedSet:Count() local DetectedItemsTypes = DetectedSet:GetTypeNames() Task:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) - Task:SetInfo( "Coordinates", Detection:GetDetectedItemCoordinate( DetectedIndex ) ) + + local Coordinate = Detection:GetDetectedItemCoordinate( DetectedIndex ) + Coordinate:SetModeA2A() + + Task:SetInfo( "Coordinates", Coordinate ) Task:SetInfo( "Object", DetectedSet:GetFirst() ) Mission:AddTask( Task ) else diff --git a/Moose Mission Setup/Moose.files b/Moose Mission Setup/Moose.files index 6b2abfad1..55aba83d6 100644 --- a/Moose Mission Setup/Moose.files +++ b/Moose Mission Setup/Moose.files @@ -5,6 +5,7 @@ Core/Base.lua Core/Scheduler.lua Core/ScheduleDispatcher.lua Core/Event.lua +Core/Settings.lua Core/Menu.lua Core/Zone.lua Core/Database.lua diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 1010dac77..087866245 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170517_1856' ) +env.info( 'Moose Generation Timestamp: 20170520_0827' ) local base = _G @@ -27,6 +27,7 @@ __Moose.Include( 'Core/Base.lua' ) __Moose.Include( 'Core/Scheduler.lua' ) __Moose.Include( 'Core/ScheduleDispatcher.lua' ) __Moose.Include( 'Core/Event.lua' ) +__Moose.Include( 'Core/Settings.lua' ) __Moose.Include( 'Core/Menu.lua' ) __Moose.Include( 'Core/Zone.lua' ) __Moose.Include( 'Core/Database.lua' ) From 96fdf724008c8d76a9586be785a58496720049f7 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 13:32:21 +0200 Subject: [PATCH 2/9] Progress implementing teh SETTINGS class and coordinates per Controllable of the player --- Moose Development/Moose/Actions/Act_Route.lua | 21 +++++--- Moose Development/Moose/Core/Point.lua | 28 +++++----- Moose Development/Moose/Core/Zone.lua | 2 +- .../Moose/Functional/Designate.lua | 4 +- .../Moose/Functional/Detection.lua | 42 +++++++-------- Moose Development/Moose/Functional/Escort.lua | 2 +- Moose Development/Moose/Tasking/Task_A2A.lua | 23 ++++---- .../Moose/Tasking/Task_A2A_Dispatcher.lua | 12 +---- Moose Development/Moose/Tasking/Task_A2G.lua | 53 +++++++++++-------- Moose Development/Moose/Wrapper/Group.lua | 19 +++++++ 10 files changed, 119 insertions(+), 87 deletions(-) diff --git a/Moose Development/Moose/Actions/Act_Route.lua b/Moose Development/Moose/Actions/Act_Route.lua index 5e7f91381..91574be2d 100644 --- a/Moose Development/Moose/Actions/Act_Route.lua +++ b/Moose Development/Moose/Actions/Act_Route.lua @@ -154,19 +154,20 @@ do -- ACT_ROUTE --- Get the routing text to be displayed. -- The route mode determines the text displayed. -- @param #ACT_ROUTE self - -- @param Core.Point#COORDINATE FromCoordinate + -- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @return #string - function ACT_ROUTE:GetRouteText( FromCoordinate ) + function ACT_ROUTE:GetRouteText( Controllable ) local RouteText = "" - if self.Coordinate then - RouteText = "Route to " .. self.Coordinate:ToString( FromCoordinate ) + RouteText = "Route to " .. self.Coordinate:ToString( Controllable ) end if self.Zone then - RouteText = "Route to " .. self.Zone:GetCoordinate():ToString( FromCoordinate ) + local Coordinate = self.Zone:GetPointVec3( self.Altitude ) + Coordinate:SetHeading( self.Heading ) + RouteText = "Route to zone " .. Coordinate:ToString( Controllable ) end return RouteText @@ -395,8 +396,12 @@ do -- ACT_ROUTE_ZONE --- Set Zone -- @param #ACT_ROUTE_ZONE self -- @param Core.Zone#ZONE_BASE Zone The Zone object where to route to. - function ACT_ROUTE_ZONE:SetZone( Zone ) + -- @param #number Altitude + -- @param #number Heading + function ACT_ROUTE_ZONE:SetZone( Zone, Altitude, Heading ) -- R2.2 Added altitude and heading self.Zone = Zone + self.Altitude = Altitude + self.Heading = Heading end --- Get Zone @@ -429,9 +434,9 @@ do -- ACT_ROUTE_ZONE -- @param #string From -- @param #string To function ACT_ROUTE_ZONE:onafterReport( ProcessUnit, From, Event, To ) + self:E( { ProcessUnit = ProcessUnit } ) - local TaskUnitCoordinate = ProcessUnit:GetCoordinate() - local RouteText = self:GetRouteText( TaskUnitCoordinate ) + local RouteText = self:GetRouteText( ProcessUnit ) self:Message( RouteText ) end diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 75d44f6e1..d950c1bd7 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -241,6 +241,7 @@ POINT_VEC3 = { -- @extends Core.Point#COORDINATE + --- # POINT_VEC2 class, extends @{Point#COORDINATE} -- -- The @{Point#POINT_VEC2} class defines a 2D point in the simulator. The height coordinate (if needed) will be the land height + an optional added height specified. @@ -272,8 +273,6 @@ POINT_VEC2 = { } - - do -- COORDINATE --- COORDINATE constructor. @@ -449,6 +448,8 @@ do -- COORDINATE else return ' at ' .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) end + else + return "" end end @@ -720,7 +721,8 @@ do -- COORDINATE local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = FromCoordinate:Get2DDistance( self ) local Altitude = self:GetAltitudeText() - return "BRAA: " .. self:GetBRText( AngleRadians, Distance, Settings ) + local AspectText = self:ToStringAspect( FromCoordinate ) + return "BRAA: " .. self:GetBRText( AngleRadians, Distance, Settings ) .. ( AspectText and ", " .. AspectText or "" ) end --- Return a BULLS string from a COORDINATE to the BULLS of the coalition. @@ -791,24 +793,26 @@ do -- COORDINATE -- * Uses default settings in COORDINATE. -- * Can be overridden if for a GROUP containing x clients, a menu was selected to override the default. -- @param #COORDINATE self - -- @param #COORDINATE FromCoordinate + -- @param Wrapper.Controllable#CONTROLLABLE Controllable -- @param Core.Settings#SETTINGS Settings -- @return #string The coordinate Text in the configured coordinate system. - function COORDINATE:ToString( FromCoordinate, Settings ) -- R2.2 + function COORDINATE:ToString( Controllable, Settings ) -- R2.2 local Settings = Settings or _SETTINGS + + local IsAir = Controllable and Controllable:IsAir() or false - if self:IsModeA2A() then + if IsAir then + local Coordinate = Controllable:GetCoordinate() + Coordinate:SetModeA2A() if Settings:IsA2A_BRA() then - return self:ToStringBRAA( FromCoordinate, Settings ) + return self:ToStringBRAA( Coordinate, Settings ) end if Settings:IsA2A_BULLS() then - return self:ToStringBULLS( FromCoordinate, Settings ) + return self:ToStringBULLS( Coordinate, Settings ) end - end - - if self:IsModeA2G() then + else if Settings:IsA2G_LL() then return self:ToStringLL( Settings ) end @@ -816,7 +820,7 @@ do -- COORDINATE return self:ToStringMGRS( Settings ) end end - + return nil end diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 07d437913..7544c43bc 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -251,7 +251,7 @@ function ZONE_BASE:GetVec3( Height ) local Vec2 = self:GetVec2() - local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y } + local Vec3 = { x = Vec2.x, y = Height and Height or land.getHeight( self:GetVec2() ), z = Vec2.y } self:T2( { Vec3 } ) diff --git a/Moose Development/Moose/Functional/Designate.lua b/Moose Development/Moose/Functional/Designate.lua index 9dd5914f7..4a2543100 100644 --- a/Moose Development/Moose/Functional/Designate.lua +++ b/Moose Development/Moose/Functional/Designate.lua @@ -538,7 +538,7 @@ do -- DESIGNATE for Index, DetectedItemData in pairs( DetectedItems ) do - local Report = self.Detection:DetectedItemReportSummary( Index ) + local Report = self.Detection:DetectedItemReportSummary( Index, AttackGroup ) DetectedReport:Add(" - " .. Report) end @@ -639,7 +639,7 @@ do -- DESIGNATE for Index, DetectedItemData in pairs( DetectedItems ) do - local Report = self.Detection:DetectedItemMenu( Index ) + local Report = self.Detection:DetectedItemMenu( Index, AttackGroup ) if not self.Designating[Index] then local DetectedMenu = MENU_GROUP:New( AttackGroup, Report, DesignateMenu ) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 6c92961e8..c9659b1af 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -1359,7 +1359,7 @@ do -- DETECTION_BASE -- @param #DETECTION_BASE self -- @param Index -- @return #string - function DETECTION_BASE:DetectedItemMenu( Index ) + function DETECTION_BASE:DetectedItemMenu( Index, AttackGroup ) self:F( Index ) return nil end @@ -1369,7 +1369,7 @@ do -- DETECTION_BASE -- @param #DETECTION_BASE self -- @param Index -- @return #string - function DETECTION_BASE:DetectedItemReportSummary( Index ) + function DETECTION_BASE:DetectedItemReportSummary( Index, AttackGroup ) self:F( Index ) return nil end @@ -1377,7 +1377,7 @@ do -- DETECTION_BASE --- Report detailed of a detectedion result. -- @param #DETECTION_BASE self -- @return #string - function DETECTION_BASE:DetectedReportDetailed() + function DETECTION_BASE:DetectedReportDetailed( AttackGroup ) self:F() return nil end @@ -1574,7 +1574,7 @@ do -- DETECTION_UNITS -- @param #DETECTION_UNITS self -- @param Index -- @return #string - function DETECTION_UNITS:DetectedItemMenu( Index ) + function DETECTION_UNITS:DetectedItemMenu( Index, AttackGroup ) self:F( Index ) local DetectedItem = self:GetDetectedItem( Index ) @@ -1593,7 +1593,7 @@ do -- DETECTION_UNITS self:T(DetectedItemUnit) local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) ReportSummary = string.format( "%s - %s", @@ -1612,7 +1612,7 @@ do -- DETECTION_UNITS -- @param #DETECTION_UNITS self -- @param Index -- @return #string - function DETECTION_UNITS:DetectedItemReportSummary( Index ) + function DETECTION_UNITS:DetectedItemReportSummary( Index, AttackGroup ) self:F( { Index, self.DetectedItems } ) local DetectedItem = self:GetDetectedItem( Index ) @@ -1654,7 +1654,7 @@ do -- DETECTION_UNITS end local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) local ThreatLevelA2G = DetectedItemUnit:GetThreatLevel( DetectedItem ) @@ -1679,13 +1679,13 @@ do -- DETECTION_UNITS --- Report detailed of a detection result. -- @param #DETECTION_UNITS self -- @return #string - function DETECTION_UNITS:DetectedReportDetailed() + function DETECTION_UNITS:DetectedReportDetailed( AttackGroup ) self:F() local Report = REPORT:New( "Detected units:" ) for DetectedItemID, DetectedItem in pairs( self.DetectedItems ) do local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem - local ReportSummary = self:DetectedItemReportSummary( DetectedItemID ) + local ReportSummary = self:DetectedItemReportSummary( DetectedItemID, AttackGroup ) Report:Add( ReportSummary ) end @@ -1844,7 +1844,7 @@ do -- DETECTION_TYPES -- @param #DETECTION_TYPES self -- @param Index -- @return #string - function DETECTION_TYPES:DetectedItemMenu( DetectedTypeName ) + function DETECTION_TYPES:DetectedItemMenu( DetectedTypeName, AttackGroup ) self:F( DetectedTypeName ) local DetectedItem = self:GetDetectedItem( DetectedTypeName ) @@ -1857,7 +1857,7 @@ do -- DETECTION_TYPES local DetectedItemUnit = DetectedSet:GetFirst() local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) self:E( { DetectedItemID, DetectedItemCoordText } ) @@ -1877,7 +1877,7 @@ do -- DETECTION_TYPES -- @param #DETECTION_TYPES self -- @param Index -- @return #string - function DETECTION_TYPES:DetectedItemReportSummary( DetectedTypeName ) + function DETECTION_TYPES:DetectedItemReportSummary( DetectedTypeName, AttackGroup ) self:F( DetectedTypeName ) local DetectedItem = self:GetDetectedItem( DetectedTypeName ) @@ -1894,7 +1894,7 @@ do -- DETECTION_TYPES local DetectedItemUnit = DetectedSet:GetFirst() local DetectedItemCoordinate = DetectedItemUnit:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) local ReportSummary = string.format( "%s - %s - Threat:[%s](%2d) - %2d of %s", @@ -1914,13 +1914,13 @@ do -- DETECTION_TYPES --- Report detailed of a detection result. -- @param #DETECTION_TYPES self -- @return #string - function DETECTION_TYPES:DetectedReportDetailed() + function DETECTION_TYPES:DetectedReportDetailed( AttackGroup ) self:F() local Report = REPORT:New( "Detected types:" ) for DetectedItemTypeName, DetectedItem in pairs( self.DetectedItems ) do local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem - local ReportSummary = self:DetectedItemReportSummary( DetectedItemTypeName ) + local ReportSummary = self:DetectedItemReportSummary( DetectedItemTypeName, AttackGroup ) Report:Add( ReportSummary ) end @@ -2001,7 +2001,7 @@ do -- DETECTION_AREAS -- @param #DETECTION_AREAS self -- @param Index -- @return #string - function DETECTION_AREAS:DetectedItemMenu( Index ) + function DETECTION_AREAS:DetectedItemMenu( Index, AttackGroup ) self:F( Index ) local DetectedItem = self:GetDetectedItem( Index ) @@ -2013,7 +2013,7 @@ do -- DETECTION_AREAS local DetectedZone = self:GetDetectedItemZone( Index ) local DetectedItemCoordinate = DetectedZone:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) local ReportSummary = string.format( "%s - %s", @@ -2031,7 +2031,7 @@ do -- DETECTION_AREAS -- @param #DETECTION_AREAS self -- @param Index -- @return #string - function DETECTION_AREAS:DetectedItemReportSummary( Index ) + function DETECTION_AREAS:DetectedItemReportSummary( Index, AttackGroup ) self:F( Index ) local DetectedItem = self:GetDetectedItem( Index ) @@ -2043,7 +2043,7 @@ do -- DETECTION_AREAS local DetectedZone = self:GetDetectedItemZone( Index ) local DetectedItemCoordinate = DetectedZone:GetCoordinate() - local DetectedItemCoordText = DetectedItemCoordinate:ToString() + local DetectedItemCoordText = DetectedItemCoordinate:ToString( AttackGroup ) local ThreatLevelA2G = self:GetTreatLevelA2G( DetectedItem ) local DetectedItemsCount = DetectedSet:Count() @@ -2068,13 +2068,13 @@ do -- DETECTION_AREAS --- Report detailed of a detection result. -- @param #DETECTION_AREAS self -- @return #string - function DETECTION_AREAS:DetectedReportDetailed() --R2.1 Fixed missing report + function DETECTION_AREAS:DetectedReportDetailed( AttackGroup) --R2.1 Fixed missing report self:F() local Report = REPORT:New( "Detected areas:" ) for DetectedItemIndex, DetectedItem in pairs( self.DetectedItems ) do local DetectedItem = DetectedItem -- #DETECTION_BASE.DetectedItem - local ReportSummary = self:DetectedItemReportSummary( DetectedItemIndex ) + local ReportSummary = self:DetectedItemReportSummary( DetectedItemIndex, AttackGroup ) Report:Add( ReportSummary ) end diff --git a/Moose Development/Moose/Functional/Escort.lua b/Moose Development/Moose/Functional/Escort.lua index dc2d62c44..449218f84 100644 --- a/Moose Development/Moose/Functional/Escort.lua +++ b/Moose Development/Moose/Functional/Escort.lua @@ -1164,7 +1164,7 @@ function ESCORT:_ReportTargetsScheduler() self:E( { DetectedItemID, DetectedItem } ) -- Remove the sub menus of the Attack menu of the Escort for the EscortGroup. - local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItemID ) + local DetectedItemReportSummary = self.Detection:DetectedItemReportSummary( DetectedItemID, EscortGroupData ) if ClientEscortGroupName == EscortGroupName then diff --git a/Moose Development/Moose/Tasking/Task_A2A.lua b/Moose Development/Moose/Tasking/Task_A2A.lua index 070d62440..b69da792c 100644 --- a/Moose Development/Moose/Tasking/Task_A2A.lua +++ b/Moose Development/Moose/Tasking/Task_A2A.lua @@ -243,6 +243,8 @@ do -- TASK_A2A -- @param Wrapper.Unit#UNIT TaskUnit function TASK_A2A:SetTargetCoordinate( TargetCoordinate, TaskUnit ) + TargetCoordinate:SetModeA2A() + local ProcessUnit = self:GetUnitProcess( TaskUnit ) local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetPoint" ) -- Actions.Act_Route#ACT_ROUTE_POINT @@ -265,12 +267,12 @@ do -- TASK_A2A --- @param #TASK_A2A self -- @param Core.Zone#ZONE_BASE TargetZone The Zone object where the Target is located on the map. -- @param Wrapper.Unit#UNIT TaskUnit - function TASK_A2A:SetTargetZone( TargetZone, TaskUnit ) + function TASK_A2A:SetTargetZone( TargetZone, Altitude, Heading, TaskUnit ) local ProcessUnit = self:GetUnitProcess( TaskUnit ) local ActRouteTarget = ProcessUnit:GetProcess( "Engaging", "RouteToTargetZone" ) -- Actions.Act_Route#ACT_ROUTE_ZONE - ActRouteTarget:SetZone( TargetZone ) + ActRouteTarget:SetZone( TargetZone, Altitude, Heading ) end @@ -363,17 +365,20 @@ do -- TASK_INTERCEPT --TODO: Add BR, Altitude, type of planes... - local TargetCoord = TargetSetUnit:GetFirst():GetCoordinate() - local TargetPositionText = TargetCoord:ToString() - local TargetThreatLevel = TargetSetUnit:CalculateThreatLevelA2G() - self:SetBriefing( TaskBriefing or - "Intercept incoming intruders.\n" .. - "Last Known Coordinates: " .. TargetPositionText .. "\n" .. - "Threat Level: [" .. string.rep( "■", TargetThreatLevel ) .. "]" + "Intercept incoming intruders.\n" ) + local TargetCoordinate = TargetSetUnit:GetFirst():GetCoordinate() + TargetCoordinate:SetModeA2A() + self:SetInfo( "Coordinates", TargetCoordinate ) + + self:SetInfo( "ThreatLevel", "[" .. string.rep( "■", TargetSetUnit:CalculateThreatLevelA2G() ) .. "]" ) + local DetectedItemsCount = TargetSetUnit:Count() + local DetectedItemsTypes = TargetSetUnit:GetTypeNames() + self:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) + return self end diff --git a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua index 6b1bba3eb..4cacccd39 100644 --- a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua @@ -184,18 +184,8 @@ do -- TASK_A2A_DISPATCHER if Task then self.Tasks[DetectedID] = Task - Task:SetTargetZone( DetectedZone ) + Task:SetTargetZone( DetectedZone, DetectedSet:GetFirst():GetAltitude(), DetectedSet:GetFirst():GetHeading() ) Task:SetDispatcher( self ) - Task:SetInfo( "ThreatLevel", "[" .. string.rep( "■", DetectedSet:CalculateThreatLevelA2G() ) .. "]" ) - local DetectedItemsCount = DetectedSet:Count() - local DetectedItemsTypes = DetectedSet:GetTypeNames() - Task:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) - - local Coordinate = Detection:GetDetectedItemCoordinate( DetectedIndex ) - Coordinate:SetModeA2A() - - Task:SetInfo( "Coordinates", Coordinate ) - Task:SetInfo( "Object", DetectedSet:GetFirst() ) Mission:AddTask( Task ) else self:E("This should not happen") diff --git a/Moose Development/Moose/Tasking/Task_A2G.lua b/Moose Development/Moose/Tasking/Task_A2G.lua index 004fb85de..501186ea7 100644 --- a/Moose Development/Moose/Tasking/Task_A2G.lua +++ b/Moose Development/Moose/Tasking/Task_A2G.lua @@ -375,17 +375,20 @@ do -- TASK_SEAD Mission:AddTask( self ) - local TargetCoord = TargetSetUnit:GetFirst():GetCoordinate() - local TargetPositionText = TargetCoord:ToString() - local TargetThreatLevel = TargetSetUnit:CalculateThreatLevelA2G() - self:SetBriefing( TaskBriefing or - "Execute a Suppression of Enemy Air Defenses.\n" .. - "Initial Coordinates: " .. TargetPositionText .. "\n" .. - "Threat Level: [" .. string.rep( "■", TargetThreatLevel ) .. "]" + "Execute a Suppression of Enemy Air Defenses.\n" ) + local TargetCoordinate = TargetSetUnit:GetFirst():GetCoordinate() + TargetCoordinate:SetModeA2G() + self:SetInfo( "Coordinates", TargetCoordinate ) + + self:SetInfo( "ThreatLevel", "[" .. string.rep( "■", TargetSetUnit:CalculateThreatLevelA2G() ) .. "]" ) + local DetectedItemsCount = TargetSetUnit:Count() + local DetectedItemsTypes = TargetSetUnit:GetTypeNames() + self:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) + return self end @@ -415,17 +418,20 @@ do -- TASK_BAI Mission:AddTask( self ) - local TargetCoord = TargetSetUnit:GetFirst():GetCoordinate() - local TargetPositionText = TargetCoord:ToString() - local TargetThreatLevel = TargetSetUnit:CalculateThreatLevelA2G() - self:SetBriefing( TaskBriefing or - "Execute a Battlefield Air Interdiction of a group of enemy targets.\n" .. - "Initial Coordinates: " .. TargetPositionText .. "\n" .. - "Threat Level: [" .. string.rep( "■", TargetThreatLevel ) .. "]" + "Execute a Battlefield Air Interdiction of a group of enemy targets.\n" ) + local TargetCoordinate = TargetSetUnit:GetFirst():GetCoordinate() + TargetCoordinate:SetModeA2G() + self:SetInfo( "Coordinates", TargetCoordinate ) + + self:SetInfo( "ThreatLevel", "[" .. string.rep( "■", TargetSetUnit:CalculateThreatLevelA2G() ) .. "]" ) + local DetectedItemsCount = TargetSetUnit:Count() + local DetectedItemsTypes = TargetSetUnit:GetTypeNames() + self:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) + return self end @@ -455,18 +461,21 @@ do -- TASK_CAS Mission:AddTask( self ) - local TargetCoord = TargetSetUnit:GetFirst():GetCoordinate() - local TargetPositionText = TargetCoord:ToString() - local TargetThreatLevel = TargetSetUnit:CalculateThreatLevelA2G() - self:SetBriefing( TaskBriefing or "Execute a Close Air Support for a group of enemy targets.\n" .. - "Beware of friendlies at the vicinity!\n" .. - "Initial Coordinates: " .. TargetPositionText .. "\n" .. - "Threat Level: [" .. string.rep( "■", TargetThreatLevel ) .. "]" + "Beware of friendlies at the vicinity!\n" ) - + + local TargetCoordinate = TargetSetUnit:GetFirst():GetCoordinate() + TargetCoordinate:SetModeA2G() + self:SetInfo( "Coordinates", TargetCoordinate ) + + self:SetInfo( "ThreatLevel", "[" .. string.rep( "■", TargetSetUnit:CalculateThreatLevelA2G() ) .. "]" ) + local DetectedItemsCount = TargetSetUnit:Count() + local DetectedItemsTypes = TargetSetUnit:GetTypeNames() + self:SetInfo( "Targets", string.format( "%d of %s", DetectedItemsCount, DetectedItemsTypes ) ) + return self end diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 3be9bc187..3f48805c4 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -485,6 +485,25 @@ function GROUP:GetPointVec2() return nil end +--- Returns a COORDINATE object indicating the point of the first UNIT of the GROUP within the mission. +-- @param Wrapper.Group#GROUP self +-- @return Core.Point#COORDINATE The COORDINATE of the GROUP. +-- @return #nil The POSITIONABLE is not existing or alive. +function GROUP:GetCoordinate() + self:F2( self.PositionableName ) + + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitCoordinate = FirstUnit:GetCoordinate() + self:T3(FirstUnitCoordinate) + return FirstUnitCoordinate + end + + return nil +end + + --- Returns a random @{DCSTypes#Vec3} vector (point in 3D of the UNIT within the mission) within a range around the first UNIT of the GROUP. -- @param #GROUP self -- @param #number Radius From ece08e5e37c3aa1a1402659b9bfe6fe7db24857e Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 16:32:56 +0200 Subject: [PATCH 3/9] Got something working with these coordinates --- Moose Development/Moose/Actions/Act_Route.lua | 3 +-- Moose Development/Moose/Core/Point.lua | 4 ++- Moose Development/Moose/Core/Settings.lua | 25 ++++++++++--------- .../Moose/Tasking/CommandCenter.lua | 13 +++++----- .../Moose/Wrapper/Controllable.lua | 18 +++++++++++++ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Moose Development/Moose/Actions/Act_Route.lua b/Moose Development/Moose/Actions/Act_Route.lua index 91574be2d..953a526fe 100644 --- a/Moose Development/Moose/Actions/Act_Route.lua +++ b/Moose Development/Moose/Actions/Act_Route.lua @@ -346,8 +346,7 @@ do -- ACT_ROUTE_POINT -- @param #string To function ACT_ROUTE_POINT:onafterReport( ProcessUnit, From, Event, To ) - local TaskUnitCoordinate = ProcessUnit:GetCoordinate() - local RouteText = self:GetRouteText( TaskUnitCoordinate ) + local RouteText = self:GetRouteText( ProcessUnit ) self:Message( RouteText ) end diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index d950c1bd7..ccf65dd4b 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -797,10 +797,12 @@ do -- COORDINATE -- @param Core.Settings#SETTINGS Settings -- @return #string The coordinate Text in the configured coordinate system. function COORDINATE:ToString( Controllable, Settings ) -- R2.2 + + self:E( { Controllable = Controllable } ) local Settings = Settings or _SETTINGS - local IsAir = Controllable and Controllable:IsAir() or false + local IsAir = Controllable and Controllable:IsAirPlane() or false if IsAir then local Coordinate = Controllable:GetCoordinate() diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua index 3e71bdf47..c6066a17a 100644 --- a/Moose Development/Moose/Core/Settings.lua +++ b/Moose Development/Moose/Core/Settings.lua @@ -160,10 +160,11 @@ do -- SETTINGS self.SystemMenu = nil end - self.SystemMenu = MENU_MISSION:New( "Coordinate Settings" ) + self.SystemMenu = MENU_MISSION:New( "Settings" ) + local A2GCoordinateMenu = MENU_MISSION:New( "A2G Coordinate System", self.SystemMenu ) - if self:IsA2GLL() then + if self:IsA2G_LL() then MENU_MISSION_COMMAND:New( "Activate MGRS", A2GCoordinateMenu, self.A2GMenuSystem, self, "MGRS" ) MENU_MISSION_COMMAND:New( "LL Accuracy 1", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 1 ) MENU_MISSION_COMMAND:New( "LL Accuracy 2", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 2 ) @@ -172,7 +173,7 @@ do -- SETTINGS MENU_MISSION_COMMAND:New( "LL Decimal Off", A2GCoordinateMenu, self.MenuLL_DMS, self, false ) end - if self:IsA2GMGRS() then + if self:IsA2G_MGRS() then MENU_MISSION_COMMAND:New( "Activate LL", A2GCoordinateMenu, self.A2GMenuSystem, self, "LL" ) MENU_MISSION_COMMAND:New( "MGRS Accuracy 1", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 1 ) MENU_MISSION_COMMAND:New( "MGRS Accuracy 2", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 2 ) @@ -183,12 +184,12 @@ do -- SETTINGS local A2ACoordinateMenu = MENU_MISSION:New( "A2A Coordinate System", self.SystemMenu ) - if self:IsA2ABULLS() then - MENU_MISSION_COMMAND:New( "Activate BRA", A2GCoordinateMenu, self.A2AMenuSystem, self, "BRA" ) + if self:IsA2A_BULLS() then + MENU_MISSION_COMMAND:New( "Activate BRA", A2ACoordinateMenu, self.A2AMenuSystem, self, "BRA" ) end - if self:IsA2ABRA() then - MENU_MISSION_COMMAND:New( "Activate BULLS", A2GCoordinateMenu, self.A2AMenuSystem, self, "BULLS" ) + if self:IsA2A_BRA() then + MENU_MISSION_COMMAND:New( "Activate BULLS", A2ACoordinateMenu, self.A2AMenuSystem, self, "BULLS" ) end return self @@ -197,30 +198,30 @@ do -- SETTINGS --- @param #SETTINGS self function SETTINGS:A2GMenuSystem( A2GSystem ) self.A2GSystem = A2GSystem - self:CoordinateMenu() + self:SettingsMenu() end --- @param #SETTINGS self function SETTINGS:A2AMenuSystem( A2ASystem ) self.A2ASystem = A2ASystem - self:CoordinateMenu() + self:SettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_Accuracy( LL_Accuracy ) self.LL_Accuracy = LL_Accuracy - self:CoordinateMenu() + self:SettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_DMS( LL_DMS ) self.LL_DMS = LL_DMS - self:CoordinateMenu() + self:SettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuMGRS_Accuracy( MGRS_Accuracy ) self.MGRS_Accuracy = MGRS_Accuracy - self:CoordinateMenu() + self:SettingsMenu() end end diff --git a/Moose Development/Moose/Tasking/CommandCenter.lua b/Moose Development/Moose/Tasking/CommandCenter.lua index 93fd01162..a5a4fe6ed 100644 --- a/Moose Development/Moose/Tasking/CommandCenter.lua +++ b/Moose Development/Moose/Tasking/CommandCenter.lua @@ -116,13 +116,12 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName ) local MenuMissionsSummary = MENU_GROUP_COMMAND:New( EventGroup, "Missions Status Report", MenuReporting, self.ReportMissionsStatus, self, EventGroup ) local MenuMissionsDetails = MENU_GROUP_COMMAND:New( EventGroup, "Missions Players Report", MenuReporting, self.ReportMissionsPlayers, self, EventGroup ) self:ReportSummary( EventGroup ) - end - local PlayerUnit = EventData.IniUnit - for MissionID, Mission in pairs( self:GetMissions() ) do - local Mission = Mission -- Tasking.Mission#MISSION - local PlayerGroup = EventData.IniGroup -- The GROUP object should be filled! - Mission:JoinUnit( PlayerUnit, PlayerGroup ) - Mission:ReportDetails() + local PlayerUnit = EventData.IniUnit + for MissionID, Mission in pairs( self:GetMissions() ) do + local Mission = Mission -- Tasking.Mission#MISSION + local PlayerGroup = EventData.IniGroup -- The GROUP object should be filled! + Mission:JoinUnit( PlayerUnit, PlayerGroup ) + end end end diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 5b84dd5c9..1160ef81d 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -2217,4 +2217,22 @@ function CONTROLLABLE:WayPointExecute( WayPoint, WaitTime ) return self end +--- Returns if the Controllable contains AirPlanes. +-- @param #CONTROLLABLE self +-- @return #boolean true if Controllable contains AirPlanes. +function CONTROLLABLE:IsAirPlane() + self:F2() + + local DCSObject = self:GetDCSObject() + + if DCSObject then + local Category = DCSObject:getCategory() + self:T2( Category ) + return Category == Unit.Category.AIRPLANE + end + + return nil +end + + -- Message APIs \ No newline at end of file From 923ea597ec34e87e4567c666a1d5cc30a29f5c4a Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 16:41:45 +0200 Subject: [PATCH 4/9] Updates --- Moose Development/Moose/Core/Settings.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua index c6066a17a..e726bd510 100644 --- a/Moose Development/Moose/Core/Settings.lua +++ b/Moose Development/Moose/Core/Settings.lua @@ -123,6 +123,20 @@ do -- SETTINGS return self.A2GSystem == "MGRS" end + --- Sets A2G BRA + -- @param #SETTINGS self + -- @return #SETTINGS + function SETTINGS:SetA2G_BRA() + self.A2GSystem = "BRA" + end + + --- Is BRA + -- @param #SETTINGS self + -- @return #boolean true if BRA + function SETTINGS:IsA2G_BRA() + return self.A2GSystem == "BRA" + end + --- Sets A2A BRA -- @param #SETTINGS self -- @return #SETTINGS @@ -165,6 +179,7 @@ do -- SETTINGS local A2GCoordinateMenu = MENU_MISSION:New( "A2G Coordinate System", self.SystemMenu ) if self:IsA2G_LL() then + MENU_MISSION_COMMAND:New( "Activate BRA", A2GCoordinateMenu, self.A2GMenuSystem, self, "BRA" ) MENU_MISSION_COMMAND:New( "Activate MGRS", A2GCoordinateMenu, self.A2GMenuSystem, self, "MGRS" ) MENU_MISSION_COMMAND:New( "LL Accuracy 1", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 1 ) MENU_MISSION_COMMAND:New( "LL Accuracy 2", A2GCoordinateMenu, self.MenuLL_Accuracy, self, 2 ) @@ -174,6 +189,7 @@ do -- SETTINGS end if self:IsA2G_MGRS() then + MENU_MISSION_COMMAND:New( "Activate BRA", A2GCoordinateMenu, self.A2GMenuSystem, self, "BRA" ) MENU_MISSION_COMMAND:New( "Activate LL", A2GCoordinateMenu, self.A2GMenuSystem, self, "LL" ) MENU_MISSION_COMMAND:New( "MGRS Accuracy 1", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 1 ) MENU_MISSION_COMMAND:New( "MGRS Accuracy 2", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 2 ) @@ -182,6 +198,11 @@ do -- SETTINGS MENU_MISSION_COMMAND:New( "MGRS Accuracy 5", A2GCoordinateMenu, self.MenuMGRS_Accuracy, self, 5 ) end + if self:IsA2G_BRA() then + MENU_MISSION_COMMAND:New( "Activate MGRS", A2GCoordinateMenu, self.A2GMenuSystem, self, "MGRS" ) + MENU_MISSION_COMMAND:New( "Activate LL", A2GCoordinateMenu, self.A2GMenuSystem, self, "LL" ) + end + local A2ACoordinateMenu = MENU_MISSION:New( "A2A Coordinate System", self.SystemMenu ) if self:IsA2A_BULLS() then From 2b0fcd342679eea89b9bacca7e190d79128520af Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 22:04:44 +0200 Subject: [PATCH 5/9] Progress --- Moose Development/Moose/Actions/Act_Route.lua | 4 +-- Moose Development/Moose/Core/Point.lua | 11 ++++---- .../Moose/Functional/Detection.lua | 27 +++++++++++++++++-- .../Moose/Tasking/Task_A2A_Dispatcher.lua | 8 ++++-- .../Moose/Wrapper/Controllable.lua | 4 +-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Moose Development/Moose/Actions/Act_Route.lua b/Moose Development/Moose/Actions/Act_Route.lua index 953a526fe..a336dffea 100644 --- a/Moose Development/Moose/Actions/Act_Route.lua +++ b/Moose Development/Moose/Actions/Act_Route.lua @@ -161,13 +161,13 @@ do -- ACT_ROUTE local RouteText = "" if self.Coordinate then - RouteText = "Route to " .. self.Coordinate:ToString( Controllable ) + RouteText = self.Coordinate:ToString( Controllable ) end if self.Zone then local Coordinate = self.Zone:GetPointVec3( self.Altitude ) Coordinate:SetHeading( self.Heading ) - RouteText = "Route to zone " .. Coordinate:ToString( Controllable ) + RouteText = Coordinate:ToString( Controllable ) end return RouteText diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index ccf65dd4b..5fe8c6363 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -709,7 +709,7 @@ do -- COORDINATE local DirectionVec3 = self:GetDirectionVec3( FromCoordinate ) local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = self:Get2DDistance( FromCoordinate ) - return "BR: " .. self:GetBRText( AngleRadians, Distance, Settings ) + return "BR, " .. self:GetBRText( AngleRadians, Distance, Settings ) end --- Return a BRAA string from a COORDINATE to the COORDINATE. @@ -721,8 +721,7 @@ do -- COORDINATE local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = FromCoordinate:Get2DDistance( self ) local Altitude = self:GetAltitudeText() - local AspectText = self:ToStringAspect( FromCoordinate ) - return "BRAA: " .. self:GetBRText( AngleRadians, Distance, Settings ) .. ( AspectText and ", " .. AspectText or "" ) + return "BRA, " .. self:GetBRText( AngleRadians, Distance, Settings ) end --- Return a BULLS string from a COORDINATE to the BULLS of the coalition. @@ -735,7 +734,7 @@ do -- COORDINATE local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = self:Get2DDistance( TargetCoordinate ) local Altitude = self:GetAltitudeText() - return "BULLS: " .. self:GetBRText( AngleRadians, Distance, Settings ) + return "BULLS, " .. self:GetBRText( AngleRadians, Distance, Settings ) end --- Return an aspect string from a COORDINATE to the Angle of the object. @@ -774,7 +773,7 @@ do -- COORDINATE local LL_Accuracy = Settings and Settings.LL_Accuracy or _SETTINGS.LL_Accuracy local LL_DMS = Settings and Settings.LL_DMS or _SETTINGS.LL_DMS local lat, lon = coord.LOtoLL( self:GetVec3() ) - return "LL: " .. UTILS.tostringLL( lat, lon, LL_Accuracy, LL_DMS ) + return "LL, " .. UTILS.tostringLL( lat, lon, LL_Accuracy, LL_DMS ) end --- Provides a MGRS string @@ -786,7 +785,7 @@ do -- COORDINATE local MGRS_Accuracy = Settings and Settings.MGRS_Accuracy or _SETTINGS.MGRS_Accuracy local lat, lon = coord.LOtoLL( self:GetVec3() ) local MGRS = coord.LLtoMGRS( lat, lon ) - return "MGRS: " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy ) + return "MGRS, " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy ) end --- Provides a coordinate string of the point, based on a coordinate format system: diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index c9659b1af..6e7cb4df6 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -239,6 +239,11 @@ do -- DETECTION_BASE -- -- -- Start the Detection. -- Detection:Start() + -- + -- ## Detection of Friendlies Nearby + -- + -- Use the method @{Detection#DETECTION_BASE.SetFriendliesRange}() to set the range what will indicate when friendlies are nearby + -- a DetectedItem. The default range is 6000 meters. For air detections, it is advisory to use about 30.000 meters. -- -- ## DETECTION_BASE is a Finite State Machine -- @@ -329,6 +334,8 @@ do -- DETECTION_BASE Unit.Category.SHIP, Unit.Category.STRUCTURE } ) + + self:SetFriendlesRange( 6000 ) -- Create FSM transitions. @@ -879,6 +886,22 @@ do -- DETECTION_BASE end end + + do -- Friendlies Radius + + --- Set the radius in meters to validate if friendlies are nearby. + -- @param #DETECTION_BASE self + -- @param #number FriendliesRange Radius to use when checking if Friendlies are nearby. + -- @return #DETECTION_BASE self + function DETECTION_BASE:SetFriendlesRange( FriendliesRange ) --R2.2 Friendlies range + self:F2() + + self.FriendliesRange = FriendliesRange + + return self + end + + end do -- Accept / Reject detected units @@ -1071,7 +1094,7 @@ do -- DETECTION_BASE id = world.VolumeType.SPHERE, params = { point = DetectedUnit:GetVec3(), - radius = 6000, + radius = self.FriendliesRadius, } } @@ -1411,7 +1434,7 @@ end do -- DETECTION_UNITS - --- # 2) DETECTION_UNITS class, extends @{Detection#DETECTION_BASE} + --- # DETECTION_UNITS class, extends @{Detection#DETECTION_BASE} -- -- The DETECTION_UNITS class will detect units within the battle zone. -- It will build a DetectedItems list filled with DetectedItems. Each DetectedItem will contain a field Set, which contains a @{Set#SET_UNIT} containing ONE @{UNIT} object reference. diff --git a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua index 4cacccd39..82ed5f576 100644 --- a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua @@ -105,8 +105,9 @@ do -- TASK_A2A_DISPATCHER local DetectedZone = DetectedItem.Zone -- Put here the intercept logic.... + local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem ) - if true then + if not FriendliesNearBy == true then -- Here we're doing something advanced... We're copying the DetectedSet, but making a new Set only with SEADable Radar units in it. local TargetSetUnit = SET_UNIT:New() @@ -130,8 +131,11 @@ do -- TASK_A2A_DISPATCHER -- @return Tasking.Task#TASK function TASK_A2A_DISPATCHER:EvaluateRemoveTask( Mission, Task, DetectedItemID, DetectedItemChanged ) + if Task then - if Task:IsStatePlanned() and DetectedItemChanged == true then + local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItemID ) + + if Task:IsStatePlanned() and DetectedItemChanged == true and FriendliesNearBy then self:E( "Removing Tasking: " .. Task:GetTaskName() ) Mission:RemoveTask( Task ) self.Tasks[DetectedItemID] = nil diff --git a/Moose Development/Moose/Wrapper/Controllable.lua b/Moose Development/Moose/Wrapper/Controllable.lua index 1160ef81d..a1e05db0d 100644 --- a/Moose Development/Moose/Wrapper/Controllable.lua +++ b/Moose Development/Moose/Wrapper/Controllable.lua @@ -2226,8 +2226,8 @@ function CONTROLLABLE:IsAirPlane() local DCSObject = self:GetDCSObject() if DCSObject then - local Category = DCSObject:getCategory() - self:T2( Category ) + local Category = DCSObject:getDesc().category + self:T( Category ) return Category == Unit.Category.AIRPLANE end From 961658ee9acc6d8f6c1b70f22fcde17308fe0439 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Sat, 20 May 2017 22:07:36 +0200 Subject: [PATCH 6/9] Small Fix --- Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua index 82ed5f576..55528fc1c 100644 --- a/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua +++ b/Moose Development/Moose/Tasking/Task_A2A_Dispatcher.lua @@ -129,11 +129,11 @@ do -- TASK_A2A_DISPATCHER -- @param #boolean DetectedItemID -- @param #boolean DetectedItemChange -- @return Tasking.Task#TASK - function TASK_A2A_DISPATCHER:EvaluateRemoveTask( Mission, Task, DetectedItemID, DetectedItemChanged ) + function TASK_A2A_DISPATCHER:EvaluateRemoveTask( Mission, Task, DetectedItem, DetectedItemID, DetectedItemChanged ) if Task then - local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItemID ) + local FriendliesNearBy = self.Detection:IsFriendliesNearBy( DetectedItem ) if Task:IsStatePlanned() and DetectedItemChanged == true and FriendliesNearBy then self:E( "Removing Tasking: " .. Task:GetTaskName() ) @@ -177,7 +177,7 @@ do -- TASK_A2A_DISPATCHER local DetectedItemChanged = DetectedItem.Changed local Task = self.Tasks[DetectedID] - Task = self:EvaluateRemoveTask( Mission, Task, DetectedID, DetectedItemChanged ) -- Task will be removed if it is planned and changed. + Task = self:EvaluateRemoveTask( Mission, Task, DetectedItem, DetectedID, DetectedItemChanged ) -- Task will be removed if it is planned and changed. -- Evaluate INTERCEPT if not Task then From 314032ba3d0a9ce621d7e20b3ce34bd605117183 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 22 May 2017 09:54:07 +0200 Subject: [PATCH 7/9] Progress --- Moose Development/Moose/Core/Database.lua | 64 +++-- Moose Development/Moose/Core/Point.lua | 15 +- Moose Development/Moose/Core/Settings.lua | 241 +++++++++++++++--- .../Moose/Functional/Scoring.lua | 26 ++ Moose Development/Moose/Moose.lua | 4 +- .../Moose/Tasking/CommandCenter.lua | 2 + Moose Development/Moose/Tasking/Mission.lua | 2 - 7 files changed, 297 insertions(+), 57 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index c9f7ed174..049673c59 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -62,6 +62,7 @@ DATABASE = { COUNTRY_ID = {}, COUNTRY_NAME = {}, NavPoints = {}, + PLAYERSETTINGS = {}, } local _DATABASECoalition = @@ -107,27 +108,33 @@ function DATABASE:New() self:_RegisterGroupsAndUnits() self:_RegisterClients() self:_RegisterStatics() - self:_RegisterPlayers() + --self:_RegisterPlayers() self:_RegisterAirbases() self.UNITS_Position = 0 --- @param #DATABASE self local function CheckPlayers( self ) + + local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) } + for CoalitionId, CoalitionData in pairs( CoalitionsData ) do + self:T( { "CoalitionData:", CoalitionData } ) + for UnitId, UnitData in pairs( CoalitionData ) do + if UnitData and UnitData:isExist() then + + local UnitName = UnitData:getName() + local PlayerName = UnitData:getPlayerName() + local PlayerUnit = UNIT:Find( UnitData ) + self:T( { "UnitData:", UnitData, UnitName, PlayerName, PlayerUnit } ) - 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 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 ) + if PlayerName and PlayerName ~= "" 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 ) + local Settings = SETTINGS:Set( PlayerName ) + Settings:SetPlayerMenu( PlayerUnit ) + end end end end @@ -135,7 +142,7 @@ function DATABASE:New() end self:E( "Scheduling" ) - --local PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 2, 0.1 ) + PlayerCheckSchedule = SCHEDULER:New( nil, CheckPlayers, { self }, 1, 1 ) return self end @@ -667,7 +674,7 @@ function DATABASE:_EventOnBirth( Event ) self:AddGroup( Event.IniDCSGroupName ) end end - self:_EventOnPlayerEnterUnit( Event ) + --self:_EventOnPlayerEnterUnit( Event ) end end @@ -723,6 +730,8 @@ function DATABASE:_EventOnPlayerLeaveUnit( Event ) if Event.IniObjectCategory == 1 then local PlayerName = Event.IniUnit:GetPlayerName() if self.PLAYERS[PlayerName] then + local Settings = SETTINGS:Set( PlayerName ) + Settings:RemovePlayerMenu( Event.IniUnit ) self:DeletePlayer( PlayerName ) end end @@ -891,6 +900,29 @@ function DATABASE:OnEventDeleteCargo( EventData ) end +--- Gets the player settings +-- @param #DATABASE self +-- @param #string PlayerName +-- @return Core.Settings#SETTINGS +function DATABASE:GetPlayerSettings( PlayerName ) + self:E({PlayerName}) + return self.PLAYERSETTINGS[PlayerName] +end + + +--- Sets the player settings +-- @param #DATABASE self +-- @param #string PlayerName +-- @param Core.Settings#SETTINGS Settings +-- @return Core.Settings#SETTINGS +function DATABASE:SetPlayerSettings( PlayerName, Settings ) + self:E({PlayerName, Settings}) + self.PLAYERSETTINGS[PlayerName] = Settings +end + + + + --- @param #DATABASE self function DATABASE:_RegisterTemplates() self:F2() diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 5fe8c6363..0b0e76678 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -799,21 +799,28 @@ do -- COORDINATE self:E( { Controllable = Controllable } ) - local Settings = Settings or _SETTINGS + local Settings = Settings or ( Controllable and _DATABASE:GetPlayerSettings( Controllable:GetPlayerName() ) ) or _SETTINGS local IsAir = Controllable and Controllable:IsAirPlane() or false if IsAir then - local Coordinate = Controllable:GetCoordinate() - Coordinate:SetModeA2A() if Settings:IsA2A_BRA() then - return self:ToStringBRAA( Coordinate, Settings ) + local Coordinate = Controllable:GetCoordinate() + Coordinate:SetModeA2A() + return self:ToStringBRAA( Coordinate, Settings ) end if Settings:IsA2A_BULLS() then + local Coordinate = Controllable:GetCoordinate() + Coordinate:SetModeA2A() return self:ToStringBULLS( Coordinate, Settings ) end else + if Settings:IsA2G_BRA() then + local Coordinate = Controllable:GetCoordinate() + Coordinate:SetModeA2A() + return Controllable and self:ToStringBRAA( Coordinate, Settings ) or self:ToStringMGRS( Settings ) + end if Settings:IsA2G_LL() then return self:ToStringLL( Settings ) end diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua index e726bd510..73fb8b888 100644 --- a/Moose Development/Moose/Core/Settings.lua +++ b/Moose Development/Moose/Core/Settings.lua @@ -42,12 +42,6 @@ -- @field #SETTINGS SETTINGS = { ClassName = "SETTINGS", - LL_Accuracy = 2, - LL_DMS = true, - MGRS_Accuracy = 5, - A2GSystem = "MGRS", - A2ASystem = "BRA", - } @@ -57,17 +51,27 @@ do -- SETTINGS --- SETTINGS constructor. -- @param #SETTINGS self -- @return #SETTINGS - function SETTINGS:New() + function SETTINGS:Set( PlayerName ) - local self = BASE:Inherit( self, BASE:New() ) -- #SETTINGS - - self:SetMetric() -- Defaults - self:SetA2G_MGRS() -- Defaults - self:SetA2A_BRA() -- Defaults - - return self + if PlayerName == nil then + local self = BASE:Inherit( self, BASE:New() ) -- #SETTINGS + self:SetMetric() -- Defaults + self:SetA2G_MGRS() -- Defaults + self:SetA2A_BRA() -- Defaults + self:SetLL_Accuracy( 2 ) -- Defaults + self:SetLL_DMS( true ) -- Defaults + self:SetMGRS_Accuracy( 5 ) -- Defaults + return self + else + local Settings = _DATABASE:GetPlayerSettings( PlayerName ) + if not Settings then + Settings = BASE:Inherit( self, BASE:New() ) -- #SETTINGS + _DATABASE:SetPlayerSettings( PlayerName, Settings ) + end + return Settings + end end - + --- Sets the SETTINGS metric. -- @param #SETTINGS self @@ -95,6 +99,54 @@ do -- SETTINGS return self.Metric == false end + --- Sets the SETTINGS LL accuracy. + -- @param #SETTINGS self + -- @param #number LL_Accuracy + -- @return #SETTINGS + function SETTINGS:SetLL_Accuracy( LL_Accuracy ) + self.LL_Accuracy = LL_Accuracy + end + + --- Gets the SETTINGS LL accuracy. + -- @param #SETTINGS self + -- @return #number + function SETTINGS:GetLL_Accuracy() + return self.LL_Accuracy or _SETTINGS:GetLL_Accuracy() + end + + --- Sets the SETTINGS LL DMS. + -- @param #SETTINGS self + -- @param #number LL_DMS + -- @return #SETTINGS + function SETTINGS:SetLL_DMS( LL_DMS ) + self.LL_DMS = LL_DMS + end + + --- Gets the SETTINGS LL DMS. + -- @param #SETTINGS self + -- @return #number + function SETTINGS:GetLL_DMS() + return self.LL_DMS or _SETTINGS:GetLL_DMS() + end + + --- Sets the SETTINGS MGRS accuracy. + -- @param #SETTINGS self + -- @param #number MGRS_Accuracy + -- @return #SETTINGS + function SETTINGS:SetMGRS_Accuracy( MGRS_Accuracy ) + self.MGRS_Accuracy = MGRS_Accuracy + end + + --- Gets the SETTINGS MGRS accuracy. + -- @param #SETTINGS self + -- @return #number + function SETTINGS:GetMGRS_Accuracy() + return self.MGRS_Accuracy or _SETTINGS:GetMGRS_Accuracy() + end + + + + --- Sets A2G LL -- @param #SETTINGS self -- @return #SETTINGS @@ -106,7 +158,7 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if LL function SETTINGS:IsA2G_LL() - return self.A2GSystem == "LL" + return ( self.A2GSystem and self.A2GSystem == "LL" ) or ( not self.A2GSystem and _SETTINGS:IsA2G_LL() ) end --- Sets A2G MGRS @@ -120,7 +172,7 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if MGRS function SETTINGS:IsA2G_MGRS() - return self.A2GSystem == "MGRS" + return ( self.A2GSystem and self.A2GSystem == "MGRS" ) or ( not self.A2GSystem and _SETTINGS:IsA2G_MGRS() ) end --- Sets A2G BRA @@ -134,7 +186,8 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if BRA function SETTINGS:IsA2G_BRA() - return self.A2GSystem == "BRA" + self:E( { BRA = ( self.A2GSystem and self.A2GSystem == "BRA" ) or ( not self.A2GSystem and _SETTINGS:IsA2G_BRA() ) } ) + return ( self.A2GSystem and self.A2GSystem == "BRA" ) or ( not self.A2GSystem and _SETTINGS:IsA2G_BRA() ) end --- Sets A2A BRA @@ -148,7 +201,8 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if BRA function SETTINGS:IsA2A_BRA() - return self.A2ASystem == "BRA" + self:E( { BRA = ( self.A2ASystem and self.A2ASystem == "BRA" ) or ( not self.A2ASystem and _SETTINGS:IsA2A_BRA() ) } ) + return ( self.A2ASystem and self.A2ASystem == "BRA" ) or ( not self.A2ASystem and _SETTINGS:IsA2A_BRA() ) end --- Sets A2A BULLS @@ -162,21 +216,24 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if BULLS function SETTINGS:IsA2A_BULLS() - return self.A2ASystem == "BULLS" + return ( self.A2ASystem and self.A2ASystem == "BULLS" ) or ( not self.A2ASystem and _SETTINGS:IsA2A_BULLS() ) end --- @param #SETTINGS self -- @return #SETTINGS - function SETTINGS:SettingsMenu( RootMenu ) + function SETTINGS:SystemSettingsMenu( RootMenu, MenuText ) - if self.SystemMenu then - self.SystemMenu:Remove() - self.SystemMenu = nil - end + MenuText = MenuText or "System Settings" - self.SystemMenu = MENU_MISSION:New( "Settings" ) + self.SettingsMenu = MENU_MISSION:New( MenuText, RootMenu ) + + if self.DefaultMenu then + self.DefaultMenu:Remove() + self.DefaultMenu = nil + end + self.DefaultMenu = MENU_MISSION:New( "Default Settings", self.SettingsMenu ) - local A2GCoordinateMenu = MENU_MISSION:New( "A2G Coordinate System", self.SystemMenu ) + local A2GCoordinateMenu = MENU_MISSION:New( "A2G Coordinate System", self.DefaultMenu ) if self:IsA2G_LL() then MENU_MISSION_COMMAND:New( "Activate BRA", A2GCoordinateMenu, self.A2GMenuSystem, self, "BRA" ) @@ -203,7 +260,7 @@ do -- SETTINGS MENU_MISSION_COMMAND:New( "Activate LL", A2GCoordinateMenu, self.A2GMenuSystem, self, "LL" ) end - local A2ACoordinateMenu = MENU_MISSION:New( "A2A Coordinate System", self.SystemMenu ) + local A2ACoordinateMenu = MENU_MISSION:New( "A2A Coordinate System", self.DefaultMenu ) if self:IsA2A_BULLS() then MENU_MISSION_COMMAND:New( "Activate BRA", A2ACoordinateMenu, self.A2AMenuSystem, self, "BRA" ) @@ -216,33 +273,151 @@ do -- SETTINGS return self end + --- @param #SETTINGS self + -- @param RootMenu + -- @param Wrapper.Client#CLIENT PlayerUnit + -- @param #string MenuText + -- @return #SETTINGS + function SETTINGS:SetPlayerMenu( PlayerUnit ) + + local MenuText = "Player Settings" + self.MenuText = MenuText + + local SettingsMenu = _SETTINGS.SettingsMenu + + local PlayerGroup = PlayerUnit:GetGroup() + local PlayerName = PlayerUnit:GetPlayerName() + local PlayerNames = PlayerGroup:GetPlayerNames() + + local GroupMenu = MENU_GROUP:New( PlayerGroup, MenuText, SettingsMenu ) + local PlayerMenu = MENU_GROUP:New( PlayerGroup, 'Settings "' .. PlayerName .. '"', GroupMenu ) + + self.PlayerMenu = PlayerMenu + + local A2GCoordinateMenu = MENU_GROUP:New( PlayerGroup, "A2G Coordinate System", PlayerMenu ) + + if self:IsA2G_LL() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 1", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 2", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 3", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal On", A2GCoordinateMenu, self.GroupLL_DMSMenu, self, PlayerUnit, PlayerGroup, PlayerName, true ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal Off", A2GCoordinateMenu, self.GroupLL_DMSMenu, self, PlayerUnit, PlayerGroup, PlayerName, false ) + end + + if self:IsA2G_MGRS() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 1", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 2", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 3", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 4", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 4 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 5", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 5 ) + end + + if self:IsA2G_BRA() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) + end + + local A2ACoordinateMenu = MENU_GROUP:New( PlayerGroup, "A2A Coordinate System", PlayerMenu ) + + if self:IsA2A_BULLS() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2ACoordinateMenu, self.GroupA2AMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + end + + if self:IsA2A_BRA() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BULLS", A2ACoordinateMenu, self.GroupA2AMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BULLS" ) + end + + return self + end + + --- @param #SETTINGS self + -- @param RootMenu + -- @param Wrapper.Client#CLIENT PlayerUnit + -- @return #SETTINGS + function SETTINGS:RemovePlayerMenu( PlayerUnit ) + + if self.PlayerMenu then + self.PlayerMenu:Remove() + end + + return self + end + + --- @param #SETTINGS self function SETTINGS:A2GMenuSystem( A2GSystem ) self.A2GSystem = A2GSystem - self:SettingsMenu() + self:SystemSettingsMenu() end --- @param #SETTINGS self function SETTINGS:A2AMenuSystem( A2ASystem ) self.A2ASystem = A2ASystem - self:SettingsMenu() + self:SystemSettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_Accuracy( LL_Accuracy ) self.LL_Accuracy = LL_Accuracy - self:SettingsMenu() + self:SystemSettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_DMS( LL_DMS ) self.LL_DMS = LL_DMS - self:SettingsMenu() + self:SystemSettingsMenu() end --- @param #SETTINGS self function SETTINGS:MenuMGRS_Accuracy( MGRS_Accuracy ) self.MGRS_Accuracy = MGRS_Accuracy - self:SettingsMenu() + self:SystemSettingsMenu() + end + + do + --- @param #SETTINGS self + function SETTINGS:GroupA2GMenu( PlayerUnit, PlayerGroup, PlayerName, A2GSystem ) + BASE:E( {self, PlayerUnit:GetName(), A2GSystem} ) + self.A2GSystem = A2GSystem + MESSAGE:New( string.format("Settings: A2G format set to %s for player %s.", A2GSystem, PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end + + --- @param #SETTINGS self + function SETTINGS:GroupA2AMenu( PlayerUnit, PlayerGroup, PlayerName, A2ASystem ) + self.A2ASystem = A2ASystem + MESSAGE:New( string.format("Settings: A2A format set to %s for player %s.", A2ASystem, PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end + + --- @param #SETTINGS self + function SETTINGS:GroupLL_AccuracyMenu( PlayerUnit, PlayerGroup, PlayerName, LL_Accuracy ) + self.LL_Accuracy = LL_Accuracy + MESSAGE:New( string.format("Settings: A2G LL format accuracy set to %d for player %s.", LL_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end + + --- @param #SETTINGS self + function SETTINGS:GroupLL_DMSMenu( PlayerUnit, PlayerGroup, PlayerName, LL_DMS ) + self.LL_DMS = LL_DMS + MESSAGE:New( string.format("Settings: A2G LL format mode set to %s for player %s.", LL_DMS and "DMS" or "HMS", PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end + --- @param #SETTINGS self + function SETTINGS:GroupMGRS_AccuracyMenu( PlayerUnit, PlayerGroup, PlayerName, MGRS_Accuracy ) + self.MGRS_Accuracy = MGRS_Accuracy + MESSAGE:New( string.format("Settings: A2G MGRS format accuracy set to %d for player %s.", MGRS_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end + end end diff --git a/Moose Development/Moose/Functional/Scoring.lua b/Moose Development/Moose/Functional/Scoring.lua index 09dccc323..ba8745f2d 100644 --- a/Moose Development/Moose/Functional/Scoring.lua +++ b/Moose Development/Moose/Functional/Scoring.lua @@ -125,6 +125,32 @@ -- -- The above documents that 2 Scoring objects are created, ScoringFirstMission and ScoringSecondMission. -- +-- ### **IMPORTANT!!!* +-- In order to allow DCS world to write CSV files, you need to adapt a configuration file in your DCS world installation **on the server**. +-- For this, browse to the **missionscripting.lua** file in your DCS world installation folder. +-- For me, this installation folder is in _D:\\Program Files\\Eagle Dynamics\\DCS World\Scripts_. +-- +-- Edit a few code lines in the MissionScripting.lua file. Comment out the lines **os**, **io** and **lfs**: +-- +-- do +-- --sanitizeModule('os') +-- --sanitizeModule('io') +-- --sanitizeModule('lfs') +-- require = nil +-- loadlib = nil +-- end +-- +-- When these lines are not sanitized, functions become available to check the time, and to write files to your system at the above specified location. +-- Note that the MissionScripting.lua file provides a warning. So please beware of this warning as outlined by Eagle Dynamics! +-- +-- --Sanitize Mission Scripting environment +-- --This makes unavailable some unsecure functions. +-- --Mission downloaded from server to client may contain potentialy harmful lua code that may use these functions. +-- --You can remove the code below and make availble these functions at your own risk. +-- +-- The MOOSE designer cannot take any responsibility of any damage inflicted as a result of the de-sanitization. +-- That being said, I hope that the SCORING class provides you with a great add-on to score your squad mates achievements. +-- -- ## 1.9) Configure messages. -- -- When players hit or destroy targets, messages are sent. diff --git a/Moose Development/Moose/Moose.lua b/Moose Development/Moose/Moose.lua index 194951078..a78af6569 100644 --- a/Moose Development/Moose/Moose.lua +++ b/Moose Development/Moose/Moose.lua @@ -9,5 +9,5 @@ _SCHEDULEDISPATCHER = SCHEDULEDISPATCHER:New() -- Core.Timer#SCHEDULEDISPATCHER --- Declare the main database object, which is used internally by the MOOSE classes. _DATABASE = DATABASE:New() -- Database#DATABASE -_SETTINGS = SETTINGS:New() -_SETTINGS:SettingsMenu(nil) +_SETTINGS = SETTINGS:Set() +_SETTINGS:SystemSettingsMenu( nil ) diff --git a/Moose Development/Moose/Tasking/CommandCenter.lua b/Moose Development/Moose/Tasking/CommandCenter.lua index a5a4fe6ed..e774059fe 100644 --- a/Moose Development/Moose/Tasking/CommandCenter.lua +++ b/Moose Development/Moose/Tasking/CommandCenter.lua @@ -122,6 +122,8 @@ function COMMANDCENTER:New( CommandCenterPositionable, CommandCenterName ) local PlayerGroup = EventData.IniGroup -- The GROUP object should be filled! Mission:JoinUnit( PlayerUnit, PlayerGroup ) end + self:SetMenu() + _DATABASE:PlayerSettingsMenu( PlayerUnit ) end end diff --git a/Moose Development/Moose/Tasking/Mission.lua b/Moose Development/Moose/Tasking/Mission.lua index 9336ae32c..f54402750 100644 --- a/Moose Development/Moose/Tasking/Mission.lua +++ b/Moose Development/Moose/Tasking/Mission.lua @@ -265,8 +265,6 @@ function MISSION:JoinUnit( PlayerUnit, PlayerGroup ) end end - self:GetCommandCenter():SetMenu() - return PlayerUnitAdded end From 8ab12e5e9aef91084c9ca11242193d9a935b4fae Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 22 May 2017 10:59:19 +0200 Subject: [PATCH 8/9] Progress --- Moose Development/Moose/Core/Point.lua | 93 ++++++++++++++----- Moose Development/Moose/Core/Settings.lua | 105 +++++++++++++++------- Moose Development/Moose/Moose.lua | 2 +- 3 files changed, 147 insertions(+), 53 deletions(-) diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 0b0e76678..0695b16a0 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -412,29 +412,43 @@ do -- COORDINATE return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.y - SourceVec3.y ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5 end - --- Provides a Bearing / Range string + + --- Provides a bearing text in degrees. -- @param #COORDINATE self - -- @param #number AngleRadians The angle in randians - -- @param #number Distance The distance - -- @return #string The BR Text - function COORDINATE:GetBRText( AngleRadians, Distance, Settings ) + -- @param #number AngleRadians The angle in randians. + -- @param #number Precision The precision. + -- @param Core.Settings#SETTINGS Settings + -- @return #string The bearing text in degrees. + function COORDINATE:GetBearingText( AngleRadians, Precision, Settings ) - local Settings = Settings or _SETTINGS - - AngleRadians = UTILS.Round( UTILS.ToDegree( AngleRadians ), 0 ) - if Settings:IsMetric() then - Distance = UTILS.Round( Distance / 1000, 2 ) - else - Distance = UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) - end - - local s = string.format( '%03d', AngleRadians ) .. ' for ' .. Distance - - s = s .. self:GetAltitudeText() -- When the POINT is a VEC2, there will be no altitude shown. + local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS + local AngleDegrees = UTILS.Round( UTILS.ToDegree( AngleRadians ), Precision ) + + local s = string.format( '%03d°', AngleDegrees ) + return s end + --- Provides a distance text expressed in the units of measurement. + -- @param #COORDINATE self + -- @param #number Distance The distance in meters. + -- @param Core.Settings#SETTINGS Settings + -- @return #string The distance text expressed in the units of measurement. + function COORDINATE:GetDistanceText( Distance, Settings ) + + local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS + + local DistanceText + + if Settings:IsMetric() then + DistanceText = " for " .. UTILS.Round( Distance / 1000, 2 ) .. " km" + else + DistanceText = " for " .. UTILS.Round( UTILS.MetersToNM( Distance ), 2 ) .. " miles" + end + + return DistanceText + end --- Return the altitude text of the COORDINATE. -- @param #COORDINATE self @@ -444,9 +458,9 @@ do -- COORDINATE local Settings = Settings or _SETTINGS if Altitude ~= 0 then if Settings:IsMetric() then - return ' at ' .. UTILS.Round( self.y, -3 ) + return " at" .. UTILS.Round( self.y, -3 ) .. " meters" else - return ' at ' .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) + return " at " .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) .. " feet" end else return "" @@ -454,6 +468,45 @@ do -- COORDINATE end + --- Provides a Bearing / Range string + -- @param #COORDINATE self + -- @param #number AngleRadians The angle in randians + -- @param #number Distance The distance + -- @param Core.Settings#SETTINGS Settings + -- @return #string The BR Text + function COORDINATE:GetBRText( AngleRadians, Distance, Settings ) + + local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS + + local BearingText = self:GetBearingText( AngleRadians, 0, Settings ) + local DistanceText = self:GetDistanceText( Distance, Settings ) + + local BRText = BearingText .. DistanceText + + return BRText + end + + --- Provides a Bearing / Range / Altitude string + -- @param #COORDINATE self + -- @param #number AngleRadians The angle in randians + -- @param #number Distance The distance + -- @param Core.Settings#SETTINGS Settings + -- @return #string The BRA Text + function COORDINATE:GetBRAText( AngleRadians, Distance, Settings ) + + local Settings = Settings or _SETTINGS -- Core.Settings#SETTINGS + + local BearingText = self:GetBearingText( AngleRadians, 0, Settings ) + local DistanceText = self:GetDistanceText( Distance, Settings ) + local AltitudeText = self:GetAltitudeText( Settings ) + + local BRAText = BearingText .. DistanceText .. AltitudeText -- When the POINT is a VEC2, there will be no altitude shown. + + return BRAText + end + + + --- Add a Distance in meters from the COORDINATE horizontal plane, with the given angle, and calculate the new COORDINATE. -- @param #COORDINATE self -- @param Dcs.DCSTypes#Distance Distance The Distance to be added in meters. @@ -721,7 +774,7 @@ do -- COORDINATE local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = FromCoordinate:Get2DDistance( self ) local Altitude = self:GetAltitudeText() - return "BRA, " .. self:GetBRText( AngleRadians, Distance, Settings ) + return "BRA, " .. self:GetBRAText( AngleRadians, Distance, Settings ) end --- Return a BULLS string from a COORDINATE to the BULLS of the coalition. diff --git a/Moose Development/Moose/Core/Settings.lua b/Moose Development/Moose/Core/Settings.lua index 73fb8b888..b22fc6f17 100644 --- a/Moose Development/Moose/Core/Settings.lua +++ b/Moose Development/Moose/Core/Settings.lua @@ -83,7 +83,8 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if metric. function SETTINGS:IsMetric() - return self.Metric == true + self:E( {Metric = ( self.Metric ~= nil and self.Metric == true ) or ( self.Metric == nil and _SETTINGS:IsMetric() ) } ) + return ( self.Metric ~= nil and self.Metric == true ) or ( self.Metric == nil and _SETTINGS:IsMetric() ) end --- Sets the SETTINGS imperial. @@ -96,7 +97,8 @@ do -- SETTINGS -- @param #SETTINGS self -- @return #boolean true if imperial. function SETTINGS:IsImperial() - return self.Metric == false + self:E( {Metric = ( self.Metric ~= nil and self.Metric == false ) or ( self.Metric == nil and _SETTINGS:IsMetric() ) } ) + return ( self.Metric ~= nil and self.Metric == false ) or ( self.Metric == nil and _SETTINGS:IsMetric() ) end --- Sets the SETTINGS LL accuracy. @@ -221,11 +223,13 @@ do -- SETTINGS --- @param #SETTINGS self -- @return #SETTINGS - function SETTINGS:SystemSettingsMenu( RootMenu, MenuText ) + function SETTINGS:SetSystemMenu( RootMenu, MenuText ) MenuText = MenuText or "System Settings" - self.SettingsMenu = MENU_MISSION:New( MenuText, RootMenu ) + if not self.SettingsMenu then + self.SettingsMenu = MENU_MISSION:New( MenuText, RootMenu ) + end if self.DefaultMenu then self.DefaultMenu:Remove() @@ -270,6 +274,16 @@ do -- SETTINGS MENU_MISSION_COMMAND:New( "Activate BULLS", A2ACoordinateMenu, self.A2AMenuSystem, self, "BULLS" ) end + local MetricsMenu = MENU_MISSION:New( "Measures and Weights System", self.DefaultMenu ) + + if self:IsMetric() then + MENU_MISSION_COMMAND:New( "Activate Imperial", MetricsMenu, self.MenuMWSystem, self, false ) + end + + if self:IsImperial() then + MENU_MISSION_COMMAND:New( "Activate Metric", MetricsMenu, self.MenuMWSystem, self, true ) + end + return self end @@ -297,39 +311,49 @@ do -- SETTINGS local A2GCoordinateMenu = MENU_GROUP:New( PlayerGroup, "A2G Coordinate System", PlayerMenu ) if self:IsA2G_LL() then - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) - MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 1", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 2", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 3", A2GCoordinateMenu, self.GroupLL_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal On", A2GCoordinateMenu, self.GroupLL_DMSMenu, self, PlayerUnit, PlayerGroup, PlayerName, true ) - MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal Off", A2GCoordinateMenu, self.GroupLL_DMSMenu, self, PlayerUnit, PlayerGroup, PlayerName, false ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 1", A2GCoordinateMenu, self.MenuGroupLL_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 2", A2GCoordinateMenu, self.MenuGroupLL_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Accuracy 3", A2GCoordinateMenu, self.MenuGroupLL_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal On", A2GCoordinateMenu, self.MenuGroupLL_DMSSystem, self, PlayerUnit, PlayerGroup, PlayerName, true ) + MENU_GROUP_COMMAND:New( PlayerGroup, "LL Decimal Off", A2GCoordinateMenu, self.MenuGroupLL_DMSSystem, self, PlayerUnit, PlayerGroup, PlayerName, false ) end if self:IsA2G_MGRS() then - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) - MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 1", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 2", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 3", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 4", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 4 ) - MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 5", A2GCoordinateMenu, self.GroupMGRS_AccuracyMenu, self, PlayerUnit, PlayerGroup, PlayerName, 5 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 1", A2GCoordinateMenu, self.MenuGroupMGRS_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 1 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 2", A2GCoordinateMenu, self.MenuGroupMGRS_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 2 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 3", A2GCoordinateMenu, self.MenuGroupMGRS_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 3 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 4", A2GCoordinateMenu, self.MenuGroupMGRS_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 4 ) + MENU_GROUP_COMMAND:New( PlayerGroup, "MGRS Accuracy 5", A2GCoordinateMenu, self.MenuGroupMGRS_AccuracySystem, self, PlayerUnit, PlayerGroup, PlayerName, 5 ) end if self:IsA2G_BRA() then - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.GroupA2GMenu, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate MGRS", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "MGRS" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate LL", A2GCoordinateMenu, self.MenuGroupA2GSystem, self, PlayerUnit, PlayerGroup, PlayerName, "LL" ) end local A2ACoordinateMenu = MENU_GROUP:New( PlayerGroup, "A2A Coordinate System", PlayerMenu ) if self:IsA2A_BULLS() then - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2ACoordinateMenu, self.GroupA2AMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BRA", A2ACoordinateMenu, self.MenuGroupA2ASystem, self, PlayerUnit, PlayerGroup, PlayerName, "BRA" ) end if self:IsA2A_BRA() then - MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BULLS", A2ACoordinateMenu, self.GroupA2AMenu, self, PlayerUnit, PlayerGroup, PlayerName, "BULLS" ) + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate BULLS", A2ACoordinateMenu, self.MenuGroupA2ASystem, self, PlayerUnit, PlayerGroup, PlayerName, "BULLS" ) end + + local MetricsMenu = MENU_GROUP:New( PlayerGroup, "Measures and Weights System", PlayerMenu ) + + if self:IsMetric() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate Imperial", MetricsMenu, self.MenuGroupMWSystem, self, PlayerUnit, PlayerGroup, PlayerName, false ) + end + + if self:IsImperial() then + MENU_GROUP_COMMAND:New( PlayerGroup, "Activate Metric", MetricsMenu, self.MenuGroupMWSystem, self, PlayerUnit, PlayerGroup, PlayerName, true ) + end return self end @@ -351,35 +375,43 @@ do -- SETTINGS --- @param #SETTINGS self function SETTINGS:A2GMenuSystem( A2GSystem ) self.A2GSystem = A2GSystem - self:SystemSettingsMenu() + self:SetSystemMenu() end --- @param #SETTINGS self function SETTINGS:A2AMenuSystem( A2ASystem ) self.A2ASystem = A2ASystem - self:SystemSettingsMenu() + self:SetSystemMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_Accuracy( LL_Accuracy ) self.LL_Accuracy = LL_Accuracy - self:SystemSettingsMenu() + self:SetSystemMenu() end --- @param #SETTINGS self function SETTINGS:MenuLL_DMS( LL_DMS ) self.LL_DMS = LL_DMS - self:SystemSettingsMenu() + self:SetSystemMenu() end + --- @param #SETTINGS self function SETTINGS:MenuMGRS_Accuracy( MGRS_Accuracy ) self.MGRS_Accuracy = MGRS_Accuracy - self:SystemSettingsMenu() + self:SetSystemMenu() + end + + --- @param #SETTINGS self + function SETTINGS:MenuMWSystem( MW ) + self.Metric = MW + MESSAGE:New( string.format("Settings: Default measurement format set to %s for all players!.", MW and "Metric" or "Imperial" ), 5 ):ToAll() + self:SetSystemMenu() end do --- @param #SETTINGS self - function SETTINGS:GroupA2GMenu( PlayerUnit, PlayerGroup, PlayerName, A2GSystem ) + function SETTINGS:MenuGroupA2GSystem( PlayerUnit, PlayerGroup, PlayerName, A2GSystem ) BASE:E( {self, PlayerUnit:GetName(), A2GSystem} ) self.A2GSystem = A2GSystem MESSAGE:New( string.format("Settings: A2G format set to %s for player %s.", A2GSystem, PlayerName ), 5 ):ToGroup( PlayerGroup ) @@ -388,7 +420,7 @@ do -- SETTINGS end --- @param #SETTINGS self - function SETTINGS:GroupA2AMenu( PlayerUnit, PlayerGroup, PlayerName, A2ASystem ) + function SETTINGS:MenuGroupA2ASystem( PlayerUnit, PlayerGroup, PlayerName, A2ASystem ) self.A2ASystem = A2ASystem MESSAGE:New( string.format("Settings: A2A format set to %s for player %s.", A2ASystem, PlayerName ), 5 ):ToGroup( PlayerGroup ) self:RemovePlayerMenu(PlayerUnit) @@ -396,7 +428,7 @@ do -- SETTINGS end --- @param #SETTINGS self - function SETTINGS:GroupLL_AccuracyMenu( PlayerUnit, PlayerGroup, PlayerName, LL_Accuracy ) + function SETTINGS:MenuGroupLL_AccuracySystem( PlayerUnit, PlayerGroup, PlayerName, LL_Accuracy ) self.LL_Accuracy = LL_Accuracy MESSAGE:New( string.format("Settings: A2G LL format accuracy set to %d for player %s.", LL_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup ) self:RemovePlayerMenu(PlayerUnit) @@ -404,19 +436,28 @@ do -- SETTINGS end --- @param #SETTINGS self - function SETTINGS:GroupLL_DMSMenu( PlayerUnit, PlayerGroup, PlayerName, LL_DMS ) + function SETTINGS:MenuGroupLL_DMSSystem( PlayerUnit, PlayerGroup, PlayerName, LL_DMS ) self.LL_DMS = LL_DMS MESSAGE:New( string.format("Settings: A2G LL format mode set to %s for player %s.", LL_DMS and "DMS" or "HMS", PlayerName ), 5 ):ToGroup( PlayerGroup ) self:RemovePlayerMenu(PlayerUnit) self:SetPlayerMenu(PlayerUnit) end + --- @param #SETTINGS self - function SETTINGS:GroupMGRS_AccuracyMenu( PlayerUnit, PlayerGroup, PlayerName, MGRS_Accuracy ) + function SETTINGS:MenuGroupMGRS_AccuracySystem( PlayerUnit, PlayerGroup, PlayerName, MGRS_Accuracy ) self.MGRS_Accuracy = MGRS_Accuracy MESSAGE:New( string.format("Settings: A2G MGRS format accuracy set to %d for player %s.", MGRS_Accuracy, PlayerName ), 5 ):ToGroup( PlayerGroup ) self:RemovePlayerMenu(PlayerUnit) self:SetPlayerMenu(PlayerUnit) end + + --- @param #SETTINGS self + function SETTINGS:MenuGroupMWSystem( PlayerUnit, PlayerGroup, PlayerName, MW ) + self.Metrics = MW + MESSAGE:New( string.format("Settings: Measurement format set to %s for player %s.", MW and "Metric" or "Imperial", PlayerName ), 5 ):ToGroup( PlayerGroup ) + self:RemovePlayerMenu(PlayerUnit) + self:SetPlayerMenu(PlayerUnit) + end end diff --git a/Moose Development/Moose/Moose.lua b/Moose Development/Moose/Moose.lua index a78af6569..a7de46555 100644 --- a/Moose Development/Moose/Moose.lua +++ b/Moose Development/Moose/Moose.lua @@ -10,4 +10,4 @@ _SCHEDULEDISPATCHER = SCHEDULEDISPATCHER:New() -- Core.Timer#SCHEDULEDISPATCHER _DATABASE = DATABASE:New() -- Database#DATABASE _SETTINGS = SETTINGS:Set() -_SETTINGS:SystemSettingsMenu( nil ) +_SETTINGS:SetSystemMenu( nil ) From 599f31dfae45edd61445f512cddcaf6b59ec198b Mon Sep 17 00:00:00 2001 From: FlightControl Date: Mon, 22 May 2017 12:17:18 +0200 Subject: [PATCH 9/9] Final tests done, publishing --- Moose Development/Moose/Core/Database.lua | 6 ++++-- Moose Development/Moose/Core/Point.lua | 10 +++++----- Moose Development/Moose/Functional/Detection.lua | 6 +++--- Moose Development/Moose/Tasking/Task.lua | 2 +- Moose Development/Moose/Tasking/Task_A2G.lua | 2 +- Moose Development/Moose/Wrapper/Positionable.lua | 2 +- Moose Mission Setup/Moose.lua | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 049673c59..94a7f43b4 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -101,7 +101,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() @@ -118,7 +118,7 @@ function DATABASE:New() local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) } for CoalitionId, CoalitionData in pairs( CoalitionsData ) do - self:T( { "CoalitionData:", CoalitionData } ) + self:E( { "CoalitionData:", CoalitionData } ) for UnitId, UnitData in pairs( CoalitionData ) do if UnitData and UnitData:isExist() then @@ -715,6 +715,8 @@ function DATABASE:_EventOnPlayerEnterUnit( Event ) if not self.PLAYERS[PlayerName] then self:AddPlayer( Event.IniUnitName, PlayerName ) end + local Settings = SETTINGS:Set( PlayerName ) + Settings:SetPlayerMenu( Event.IniUnit ) end end end diff --git a/Moose Development/Moose/Core/Point.lua b/Moose Development/Moose/Core/Point.lua index 0695b16a0..9c6628980 100644 --- a/Moose Development/Moose/Core/Point.lua +++ b/Moose Development/Moose/Core/Point.lua @@ -458,7 +458,7 @@ do -- COORDINATE local Settings = Settings or _SETTINGS if Altitude ~= 0 then if Settings:IsMetric() then - return " at" .. UTILS.Round( self.y, -3 ) .. " meters" + return " at " .. UTILS.Round( self.y, -3 ) .. " meters" else return " at " .. UTILS.Round( UTILS.MetersToFeet( self.y ), -3 ) .. " feet" end @@ -759,7 +759,7 @@ do -- COORDINATE -- @param #COORDINATE TargetCoordinate The target COORDINATE. -- @return #string The BR text. function COORDINATE:ToStringBR( FromCoordinate, Settings ) - local DirectionVec3 = self:GetDirectionVec3( FromCoordinate ) + local DirectionVec3 = FromCoordinate:GetDirectionVec3( self ) local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = self:Get2DDistance( FromCoordinate ) return "BR, " .. self:GetBRText( AngleRadians, Distance, Settings ) @@ -769,7 +769,7 @@ do -- COORDINATE -- @param #COORDINATE self -- @param #COORDINATE TargetCoordinate The target COORDINATE. -- @return #string The BR text. - function COORDINATE:ToStringBRAA( FromCoordinate, Settings ) + function COORDINATE:ToStringBRA( FromCoordinate, Settings ) local DirectionVec3 = FromCoordinate:GetDirectionVec3( self ) local AngleRadians = self:GetAngleRadians( DirectionVec3 ) local Distance = FromCoordinate:Get2DDistance( self ) @@ -860,7 +860,7 @@ do -- COORDINATE if Settings:IsA2A_BRA() then local Coordinate = Controllable:GetCoordinate() Coordinate:SetModeA2A() - return self:ToStringBRAA( Coordinate, Settings ) + return self:ToStringBRA( Coordinate, Settings ) end if Settings:IsA2A_BULLS() then @@ -872,7 +872,7 @@ do -- COORDINATE if Settings:IsA2G_BRA() then local Coordinate = Controllable:GetCoordinate() Coordinate:SetModeA2A() - return Controllable and self:ToStringBRAA( Coordinate, Settings ) or self:ToStringMGRS( Settings ) + return Controllable and self:ToStringBR( Coordinate, Settings ) or self:ToStringMGRS( Settings ) end if Settings:IsA2G_LL() then return self:ToStringLL( Settings ) diff --git a/Moose Development/Moose/Functional/Detection.lua b/Moose Development/Moose/Functional/Detection.lua index 6e7cb4df6..05eb19aa0 100644 --- a/Moose Development/Moose/Functional/Detection.lua +++ b/Moose Development/Moose/Functional/Detection.lua @@ -335,7 +335,7 @@ do -- DETECTION_BASE Unit.Category.STRUCTURE } ) - self:SetFriendlesRange( 6000 ) + self:SetFriendliesRange( 6000 ) -- Create FSM transitions. @@ -893,7 +893,7 @@ do -- DETECTION_BASE -- @param #DETECTION_BASE self -- @param #number FriendliesRange Radius to use when checking if Friendlies are nearby. -- @return #DETECTION_BASE self - function DETECTION_BASE:SetFriendlesRange( FriendliesRange ) --R2.2 Friendlies range + function DETECTION_BASE:SetFriendliesRange( FriendliesRange ) --R2.2 Friendlies range self:F2() self.FriendliesRange = FriendliesRange @@ -1094,7 +1094,7 @@ do -- DETECTION_BASE id = world.VolumeType.SPHERE, params = { point = DetectedUnit:GetVec3(), - radius = self.FriendliesRadius, + radius = self.FriendliesRange, } } diff --git a/Moose Development/Moose/Tasking/Task.lua b/Moose Development/Moose/Tasking/Task.lua index 7b584a559..921919f50 100644 --- a/Moose Development/Moose/Tasking/Task.lua +++ b/Moose Development/Moose/Tasking/Task.lua @@ -1405,7 +1405,7 @@ function TASK:ReportDetails( TaskGroup ) --R2.1 fixed report. Now nicely formatt local FromCoordinate = TaskGroup:GetUnit(1):GetCoordinate() local ToCoordinate = TaskInfo -- Core.Point#COORDINATE Report:Add( TaskInfoIDText ) - Report:AddIndent( ToCoordinate:ToStringBRAA( FromCoordinate ) .. ", " .. TaskInfo:ToStringAspect( FromCoordinate ) ) + Report:AddIndent( ToCoordinate:ToStringBRA( FromCoordinate ) .. ", " .. TaskInfo:ToStringAspect( FromCoordinate ) ) Report:AddIndent( ToCoordinate:ToStringBULLS( TaskGroup:GetCoalition() ) ) else end diff --git a/Moose Development/Moose/Tasking/Task_A2G.lua b/Moose Development/Moose/Tasking/Task_A2G.lua index 501186ea7..56c43d091 100644 --- a/Moose Development/Moose/Tasking/Task_A2G.lua +++ b/Moose Development/Moose/Tasking/Task_A2G.lua @@ -174,7 +174,7 @@ do -- TASK_A2G local TargetUnit = Task.TargetSetUnit:GetFirst() -- Wrapper.Unit#UNIT if TargetUnit then local Coordinate = TargetUnit:GetCoordinate() - self:T( { TargetCoordinate = Coordinate, Coordinate:GetX(), Coordinate:GetAlt(), Coordinate:GetZ() } ) + self:T( { TargetCoordinate = Coordinate, Coordinate:GetX(), Coordinate:GetY(), Coordinate:GetZ() } ) Task:SetTargetCoordinate( TargetUnit:GetCoordinate(), TaskUnit ) end self:__RouteToTargetPoint( 0.1 ) diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index e33a9c392..85965c8d6 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -148,7 +148,7 @@ function POSITIONABLE:GetCoordinate() if DCSPositionable then local PositionableVec3 = self:GetPositionVec3() - local PositionableCoordinate = COORDINATE:NewFromVec3( PositionableVec3 ) + local PositionableCoordinate = POINT_VEC3:NewFromVec3( PositionableVec3 ) PositionableCoordinate:SetHeading( self:GetHeading() ) self:T2( PositionableCoordinate ) diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index 087866245..0e64ca6af 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170520_0827' ) +env.info( 'Moose Generation Timestamp: 20170522_1100' ) local base = _G