Merge branch 'master' into funkyfranky

This commit is contained in:
funkyfranky
2017-09-11 23:27:04 +02:00
15 changed files with 507 additions and 32 deletions

View File

@@ -90,6 +90,18 @@ do -- COORDINATE
-- * @{#COORDINATE.IlluminationBomb}(): To illuminate the point.
--
--
-- ## Markings
--
-- Place markers (text boxes with clarifications for briefings, target locations or any other reference point) on the map for all players, coalitions or specific groups:
--
-- * @{#COORDINATE.MarkToAll}(): Place a mark to all players.
-- * @{#COORDINATE.MarkToCoalition}(): Place a mark to a coalition.
-- * @{#COORDINATE.MarkToCoalitionRed}(): Place a mark to the red coalition.
-- * @{#COORDINATE.MarkToCoalitionBlue}(): Place a mark to the blue coalition.
-- * @{#COORDINATE.MarkToGroup}(): Place a mark to a group (needs to have a client in it or a CA group (CA group is bugged)).
-- * @{#COORDINATE.RemoveMark}(): Removes a mark from the map.
--
--
-- ## 3D calculation methods
--
-- Various calculation methods exist to use or manipulate 3D space. Find below a short description of each method:
@@ -289,9 +301,55 @@ do -- COORDINATE
end
--- Set the heading of the coordinate, if applicable.
-- @param #COORDINATE self
function COORDINATE:SetHeading( Heading )
self.Heading = Heading
end
--- Get the heading of the coordinate, if applicable.
-- @param #COORDINATE self
-- @return #number or nil
function COORDINATE:GetHeading()
return self.Heading
end
--- Set the velocity of the COORDINATE.
-- @param #COORDINATE self
-- @param #string Velocity Velocity in meters per second.
function COORDINATE:SetVelocity( Velocity )
self.Velocity = Velocity
end
--- Return the velocity of the COORDINATE.
-- @param #COORDINATE self
-- @return #number Velocity in meters per second.
function COORDINATE:GetVelocity()
local Velocity = self.Velocity
return Velocity or 0
end
--- Return velocity text of the COORDINATE.
-- @param #COORDINATE self
-- @return #string
function COORDINATE:GetMovingText( Settings )
local MovingText = ""
local Velocity = self:GetVelocity()
if Velocity == 0 then
MovingText = MovingText .. "stationary "
else
MovingText = MovingText .. "moving at " .. self:GetVelocityText( Settings ) .. " " .. self:GetHeadingText( Settings )
end
return MovingText
end
--- Return a direction vector Vec3 from COORDINATE to the COORDINATE.
@@ -347,6 +405,7 @@ do -- COORDINATE
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.
@@ -413,6 +472,39 @@ do -- COORDINATE
end
--- Return the velocity text of the COORDINATE.
-- @param #COORDINATE self
-- @return #string Velocity text.
function COORDINATE:GetVelocityText( Settings )
local Velocity = self:GetVelocity()
local Settings = Settings or _SETTINGS
if Velocity then
if Settings:IsMetric() then
return UTILS.MpsToKmph( Velocity ) .. " km/h"
else
return UTILS.MpsToKmph( Velocity ) / 1.852 .. " mph"
end
else
return ""
end
end
--- Return the heading text of the COORDINATE.
-- @param #COORDINATE self
-- @return #string Heading text.
function COORDINATE:GetHeadingText( Settings )
local Heading = self.Heading
local Settings = Settings or _SETTINGS
if Heading then
return Heading .. "°"
else
return ""
end
end
--- Provides a Bearing / Range string
-- @param #COORDINATE self
-- @param #number AngleRadians The angle in randians
@@ -650,6 +742,88 @@ do -- COORDINATE
self:F2( Azimuth )
self:Flare( FLARECOLOR.Red, Azimuth )
end
do -- Markings
--- Mark to All
-- @param #COORDINATE self
-- @param #string MarkText Free format text that shows the marking clarification.
-- @return #number The resulting Mark ID which is a number.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkID = TargetCoord:MarkToAll( "This is a target for all players" )
function COORDINATE:MarkToAll( MarkText )
local MarkID = UTILS.GetMarkID()
trigger.action.markToAll( MarkID, MarkText, self:GetVec3() )
return MarkID
end
--- Mark to Coalition
-- @param #COORDINATE self
-- @param #string MarkText Free format text that shows the marking clarification.
-- @param Coalition
-- @return #number The resulting Mark ID which is a number.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkID = TargetCoord:MarkToCoalition( "This is a target for the red coalition", coalition.side.RED )
function COORDINATE:MarkToCoalition( MarkText, Coalition )
local MarkID = UTILS.GetMarkID()
trigger.action.markToCoalition( MarkID, MarkText, self:GetVec3(), Coalition )
return MarkID
end
--- Mark to Red Coalition
-- @param #COORDINATE self
-- @param #string MarkText Free format text that shows the marking clarification.
-- @return #number The resulting Mark ID which is a number.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkID = TargetCoord:MarkToCoalitionRed( "This is a target for the red coalition" )
function COORDINATE:MarkToCoalitionRed( MarkText )
return self:MarkToCoalition( MarkText, coalition.side.RED )
end
--- Mark to Blue Coalition
-- @param #COORDINATE self
-- @param #string MarkText Free format text that shows the marking clarification.
-- @return #number The resulting Mark ID which is a number.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkID = TargetCoord:MarkToCoalitionBlue( "This is a target for the blue coalition" )
function COORDINATE:MarkToCoalitionBlue( MarkText )
return self:MarkToCoalition( MarkText, coalition.side.BLUE )
end
--- Mark to Group
-- @param #COORDINATE self
-- @param #string MarkText Free format text that shows the marking clarification.
-- @param Wrapper.Group#GROUP MarkGroup The @{Group} that receives the mark.
-- @return #number The resulting Mark ID which is a number.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkGroup = GROUP:FindByName( "AttackGroup" )
-- local MarkID = TargetCoord:MarkToGroup( "This is a target for the attack group", AttackGroup )
function COORDINATE:MarkToGroup( MarkText, MarkGroup )
local MarkID = UTILS.GetMarkID()
trigger.action.markToGroup( MarkID, MarkText, self:GetVec3(), MarkGroup:GetID() )
return MarkID
end
--- Remove a mark
-- @param #COORDINATE self
-- @param #number MarkID The ID of the mark to be removed.
-- @usage
-- local TargetCoord = TargetGroup:GetCoordinate()
-- local MarkGroup = GROUP:FindByName( "AttackGroup" )
-- local MarkID = TargetCoord:MarkToGroup( "This is a target for the attack group", AttackGroup )
-- <<< logic >>>
-- RemoveMark( MarkID ) -- The mark is now removed
function COORDINATE:RemoveMark( MarkID )
trigger.action.removeMark( MarkID )
end
end -- Markings
--- Returns if a Coordinate has Line of Sight (LOS) with the ToCoordinate.
-- @param #COORDINATE self

View File

@@ -1788,16 +1788,18 @@ end
function SET_UNIT:CalculateThreatLevelA2G()
local MaxThreatLevelA2G = 0
local MaxThreatText = ""
for UnitName, UnitData in pairs( self:GetSet() ) do
local ThreatUnit = UnitData -- Wrapper.Unit#UNIT
local ThreatLevelA2G = ThreatUnit:GetThreatLevel()
local ThreatLevelA2G, ThreatText = ThreatUnit:GetThreatLevel()
if ThreatLevelA2G > MaxThreatLevelA2G then
MaxThreatLevelA2G = ThreatLevelA2G
MaxThreatText = ThreatText
end
end
self:T3( MaxThreatLevelA2G )
return MaxThreatLevelA2G
self:F( { MaxThreatLevelA2G = MaxThreatLevelA2G, MaxThreatText = MaxThreatText } )
return MaxThreatLevelA2G, MaxThreatText
end

View File

@@ -1644,7 +1644,7 @@ do -- DETECTION_BASE
DetectedItem.Coordinate = Coordinate
DetectedItem.Coordinate:SetHeading( DetectedItemUnit:GetHeading() )
DetectedItem.Coordinate.y = DetectedItemUnit:GetAltitude()
DetectedItem.Coordinate.Speed = DetectedItemUnit:GetVelocityMPS()
DetectedItem.Coordinate:SetVelocity( DetectedItemUnit:GetVelocityMPS() )
end
end
end
@@ -1675,7 +1675,7 @@ do -- DETECTION_BASE
local DetectedSet = DetectedItem.Set
if DetectedItem then
DetectedItem.ThreatLevel = DetectedSet:CalculateThreatLevelA2G()
DetectedItem.ThreatLevel, DetectedItem.ThreatText = DetectedSet:CalculateThreatLevelA2G()
end
end
@@ -1691,10 +1691,10 @@ do -- DETECTION_BASE
local DetectedItem = self:GetDetectedItem( Index )
if DetectedItem then
return DetectedItem.ThreatLevel or 0
return DetectedItem.ThreatLevel or 0, DetectedItem.ThreatText or ""
end
return nil
return nil, ""
end
@@ -2423,9 +2423,9 @@ do -- DETECTION_AREAS
-- @param #DETECTION_BASE.DetectedItem DetectedItem
function DETECTION_AREAS:CalculateIntercept( DetectedItem )
local DetectedSpeed = DetectedItem.Coordinate.Speed
local DetectedHeading = DetectedItem.Coordinate.Heading
local DetectedCoord = DetectedItem.Coordinate
local DetectedSpeed = DetectedCoord:GetVelocity()
local DetectedHeading = DetectedCoord:GetHeading()
if self.Intercept then
local DetectedSet = DetectedItem.Set

View File

@@ -870,13 +870,11 @@ function TASK:MenuMarkToGroup( TaskGroup )
local Coordinate = self:GetInfo( "Coordinates" ) -- Core.Point#COORDINATE
local Briefing = self:GetTaskBriefing()
local GroupID = TaskGroup:GetID()
local Vec3 = Coordinate:GetVec3()
self:F( { Coordinate = Vec3, Briefing = Briefing, GroupID = GroupID } )
self:F( { Briefing = Briefing, Coordinate = Coordinate } )
trigger.action.markToGroup( 1, Briefing, Vec3, GroupID )
--trigger.action.markToAll( 1, Briefing, Vec3 )
Coordinate:MarkToGroup( Briefing, TaskGroup )
--Coordinate:MarkToAll( Briefing )
end
--- Report the task status.

View File

@@ -323,13 +323,18 @@ do -- TASK_A2G_SEAD
Mission:AddTask( self )
self:SetBriefing(
TaskBriefing or
"Execute a Suppression of Enemy Air Defenses.\n"
)
self:UpdateTaskInfo()
local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G()
local TargetUnit = TargetSetUnit:GetFirst()
local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE
self:SetBriefing(
TaskBriefing or
"Execute a Suppression of Enemy Air Defenses. " ..
ThreatText .. " targets to be expected. Target is " .. TargetCoord:GetMovingText() .. "."
)
return self
end
@@ -466,12 +471,17 @@ do -- TASK_A2G_BAI
Mission:AddTask( self )
self:UpdateTaskInfo()
local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G()
local TargetUnit = TargetSetUnit:GetFirst()
local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE
self:SetBriefing(
TaskBriefing or
"Execute a Battlefield Air Interdiction of a group of enemy targets.\n"
"Execute a Battlefield Air Interdiction of a group of enemy targets. " ..
ThreatText .. " targets to be expected. Target is " .. TargetCoord:GetMovingText() .. "."
)
self:UpdateTaskInfo()
return self
end
@@ -610,13 +620,20 @@ do -- TASK_A2G_CAS
Mission:AddTask( self )
self:UpdateTaskInfo()
local ThreatLevel, ThreatText = TargetSetUnit:CalculateThreatLevelA2G()
local TargetUnit = TargetSetUnit:GetFirst()
local TargetCoord = TargetUnit:GetCoordinate() -- Core.Point#COORDINATE
self:SetBriefing(
TaskBriefing or
"Execute a Close Air Support for a group of enemy targets.\n" ..
"Beware of friendlies at the vicinity!\n"
"Execute a Close Air Support for a group of enemy targets. " ..
"Beware of friendlies at the vicinity! " ..
ThreatText .. " targets to be expected. Target is " .. TargetCoord:GetMovingText() .. "."
)
self:UpdateTaskInfo()
return self
end
@@ -626,7 +643,9 @@ do -- TASK_A2G_CAS
local TargetCoordinate = self.Detection and self.Detection:GetDetectedItemCoordinate( self.DetectedItemIndex ) or self.TargetSetUnit:GetFirst():GetCoordinate()
self:SetInfo( "Coordinates", TargetCoordinate, 0 )
self:SetInfo( "Threat", "[" .. string.rep( "", self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G() ) .. "]", 11 )
local ThreatLevel = self.Detection and self.Detection:GetDetectedItemThreatLevel( self.DetectedItemIndex ) or self.TargetSetUnit:CalculateThreatLevelA2G()
self:SetInfo( "Threat", "[" .. string.rep( "", ThreatLevel ) .. "]", 11 )
if self.Detection then
local DetectedItemsCount = self.TargetSetUnit:Count()

View File

@@ -31,7 +31,9 @@ FLARECOLOR = trigger.flareColor -- #FLARECOLOR
--- Utilities static class.
-- @type UTILS
UTILS = {}
UTILS = {
_MarkID = 1
}
--- Function to infer instance of an object
--
@@ -395,3 +397,11 @@ function UTILS.spairs( t, order )
end
end
end
-- get a new mark ID for markings
function UTILS.GetMarkID()
UTILS._MarkID = UTILS._MarkID + 1
return UTILS._MarkID
end

View File

@@ -166,6 +166,7 @@ function POSITIONABLE:GetCoordinate()
local PositionableCoordinate = COORDINATE:NewFromVec3( PositionableVec3 )
PositionableCoordinate:SetHeading( self:GetHeading() )
PositionableCoordinate:SetVelocity( self:GetVelocityMPS() )
self:T2( PositionableCoordinate )
return PositionableCoordinate