mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'develop' into FF/Ops
This commit is contained in:
commit
5b37e7b249
@ -368,7 +368,7 @@ function MESSAGE:ToCoalition( CoalitionSide, Settings )
|
||||
if CoalitionSide then
|
||||
if self.MessageDuration ~= 0 then
|
||||
self:T( self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ) .. " / " .. self.MessageDuration )
|
||||
trigger.action.outTextForCoalition( CoalitionSide, self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ), self.MessageDuration, self.ClearScreen )
|
||||
trigger.action.outTextForCoalition( CoalitionSide, self.MessageCategory .. self.MessageText:gsub( "\n$", "" ):gsub( "\n$", "" ), self.MessageDuration, self.ClearScreen )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -25,7 +25,8 @@
|
||||
|
||||
do -- COORDINATE
|
||||
|
||||
--- @type COORDINATE
|
||||
---
|
||||
-- @type COORDINATE
|
||||
-- @field #string ClassName Name of the class
|
||||
-- @field #number x Component of the 3D vector.
|
||||
-- @field #number y Component of the 3D vector.
|
||||
@ -2551,7 +2552,7 @@ do -- COORDINATE
|
||||
|
||||
Offset=Offset or 2
|
||||
|
||||
-- Measurement of visibility should not be from the ground, so Adding a hypotethical 2 meters to each Coordinate.
|
||||
-- Measurement of visibility should not be from the ground, so Adding a hypothetical 2 meters to each Coordinate.
|
||||
local FromVec3 = self:GetVec3()
|
||||
FromVec3.y = FromVec3.y + Offset
|
||||
|
||||
@ -3101,6 +3102,49 @@ do -- COORDINATE
|
||||
return "MGRS " .. UTILS.tostringMGRS( MGRS, MGRS_Accuracy )
|
||||
end
|
||||
|
||||
--- Provides a COORDINATE from an MGRS String
|
||||
-- @param #COORDINATE self
|
||||
-- @param #string MGRSString MGRS String, e.g. "MGRS 37T DK 12345 12345"
|
||||
-- @return #COORDINATE self
|
||||
function COORDINATE:NewFromMGRSString( MGRSString )
|
||||
local myparts = UTILS.Split(MGRSString," ")
|
||||
local northing = tostring(myparts[5]) or ""
|
||||
local easting = tostring(myparts[4]) or ""
|
||||
if string.len(easting) < 5 then easting = easting..string.rep("0",5-string.len(easting)) end
|
||||
if string.len(northing) < 5 then northing = northing..string.rep("0",5-string.len(northing)) end
|
||||
local MGRS = {
|
||||
UTMZone = myparts[2],
|
||||
MGRSDigraph = myparts[3],
|
||||
Easting = easting,
|
||||
Northing = northing,
|
||||
}
|
||||
local lat, lon = coord.MGRStoLL(MGRS)
|
||||
local point = coord.LLtoLO(lat, lon, 0)
|
||||
local coord = COORDINATE:NewFromVec2({x=point.x,y=point.z})
|
||||
return coord
|
||||
end
|
||||
|
||||
--- Provides a COORDINATE from an MGRS Coordinate
|
||||
-- @param #COORDINATE self
|
||||
-- @param #string UTMZone UTM Zone, e.g. "37T"
|
||||
-- @param #string MGRSDigraph Digraph, e.g. "DK"
|
||||
-- @param #string Easting Meters easting - string in order to allow for leading zeros, e.g. "01234". Should be 5 digits.
|
||||
-- @param #string Northing Meters northing - string in order to allow for leading zeros, e.g. "12340". Should be 5 digits.
|
||||
-- @return #COORDINATE self
|
||||
function COORDINATE:NewFromMGRS( UTMZone, MGRSDigraph, Easting, Northing )
|
||||
if string.len(Easting) < 5 then Easting = Easting..string.rep("0",5-string.len(Easting) )end
|
||||
if string.len(Northing) < 5 then Northing = Northing..string.rep("0",5-string.len(Northing) )end
|
||||
local MGRS = {
|
||||
UTMZone = UTMZone,
|
||||
MGRSDigraph = MGRSDigraph,
|
||||
Easting = Easting,
|
||||
Northing = Northing,
|
||||
}
|
||||
local lat, lon = coord.MGRStoLL(MGRS)
|
||||
local point = coord.LLtoLO(lat, lon, 0)
|
||||
local coord = COORDINATE:NewFromVec2({x=point.x,y=point.z})
|
||||
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.
|
||||
@ -3613,7 +3657,7 @@ end
|
||||
|
||||
do -- POINT_VEC2
|
||||
|
||||
--- @type POINT_VEC2
|
||||
-- @type POINT_VEC2
|
||||
-- @field DCS#Distance x The x coordinate in meters.
|
||||
-- @field DCS#Distance y the y coordinate in meters.
|
||||
-- @extends Core.Point#COORDINATE
|
||||
|
||||
@ -419,7 +419,11 @@ do -- SET_BASE
|
||||
-- @param #SET_BASE self
|
||||
-- @return Core.Base#BASE
|
||||
function SET_BASE:GetRandom()
|
||||
local tablemax = table.maxn(self.Index)
|
||||
local tablemax = 0
|
||||
for _,_ind in pairs(self.Index) do
|
||||
tablemax = tablemax + 1
|
||||
end
|
||||
--local tablemax = table.maxn(self.Index)
|
||||
local RandomItem = self.Set[self.Index[math.random(1,tablemax)]]
|
||||
self:T3( { RandomItem } )
|
||||
return RandomItem
|
||||
@ -561,10 +565,12 @@ do -- SET_BASE
|
||||
return self
|
||||
end
|
||||
|
||||
--- Iterate the SET_BASE while identifying the nearest object from a @{Core.Point#POINT_VEC2}.
|
||||
--- Iterate the SET_BASE while identifying the nearest object in the set from a @{Core.Point#POINT_VEC2}.
|
||||
-- @param #SET_BASE self
|
||||
-- @param Core.Point#POINT_VEC2 PointVec2 A @{Core.Point#POINT_VEC2} object from where to evaluate the closest object in the set.
|
||||
-- @param Core.Point#POINT_VEC2 PointVec2 A @{Core.Point#COORDINATE} or @{Core.Point#POINT_VEC2} object (but **not** a simple DCS#Vec2!) from where to evaluate the closest object in the set.
|
||||
-- @return Core.Base#BASE The closest object.
|
||||
-- @usage
|
||||
-- myset:FindNearestObjectFromPointVec2( ZONE:New("Test Zone"):GetCoordinate() )
|
||||
function SET_BASE:FindNearestObjectFromPointVec2( PointVec2 )
|
||||
self:F2( PointVec2 )
|
||||
|
||||
@ -2848,59 +2854,50 @@ do -- SET_UNIT
|
||||
-- @return Core.Point#COORDINATE The center coordinate of all the units in the set, including heading in degrees and speed in mps in case of moving units.
|
||||
function SET_UNIT:GetCoordinate()
|
||||
|
||||
local function GetSetVec3(units)
|
||||
-- Init.
|
||||
local x=0
|
||||
local y=0
|
||||
local z=0
|
||||
local n=0
|
||||
-- Loop over all units.
|
||||
for _,unit in pairs(units) do
|
||||
local vec3=nil --DCS#Vec3
|
||||
if unit and unit:IsAlive() then
|
||||
vec3 = unit:GetVec3()
|
||||
end
|
||||
if vec3 then
|
||||
-- Sum up posits.
|
||||
x=x+vec3.x
|
||||
y=y+vec3.y
|
||||
z=z+vec3.z
|
||||
-- Increase counter.
|
||||
n=n+1
|
||||
end
|
||||
end
|
||||
if n>0 then
|
||||
-- Average.
|
||||
local Vec3={x=x/n, y=y/n, z=z/n} --DCS#Vec3
|
||||
return Vec3
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local Coordinate = nil
|
||||
local unit = self:GetRandom()
|
||||
if self:Count() == 1 and unit then
|
||||
return unit:GetCoordinate()
|
||||
end
|
||||
if unit then
|
||||
local Coordinate = unit:GetCoordinate()
|
||||
--self:F({Coordinate:GetVec3()})
|
||||
|
||||
|
||||
local x1 = Coordinate.x
|
||||
local x2 = Coordinate.x
|
||||
local y1 = Coordinate.y
|
||||
local y2 = Coordinate.y
|
||||
local z1 = Coordinate.z
|
||||
local z2 = Coordinate.z
|
||||
local MaxVelocity = 0
|
||||
local AvgHeading = nil
|
||||
local MovingCount = 0
|
||||
|
||||
for UnitName, UnitData in pairs( self:GetAliveSet() ) do
|
||||
|
||||
local Unit = UnitData -- Wrapper.Unit#UNIT
|
||||
local Coordinate = Unit:GetCoordinate()
|
||||
|
||||
x1 = (Coordinate.x < x1) and Coordinate.x or x1
|
||||
x2 = (Coordinate.x > x2) and Coordinate.x or x2
|
||||
y1 = (Coordinate.y < y1) and Coordinate.y or y1
|
||||
y2 = (Coordinate.y > y2) and Coordinate.y or y2
|
||||
z1 = (Coordinate.y < z1) and Coordinate.z or z1
|
||||
z2 = (Coordinate.y > z2) and Coordinate.z or z2
|
||||
|
||||
local Velocity = Coordinate:GetVelocity()
|
||||
if Velocity ~= 0 then
|
||||
MaxVelocity = (MaxVelocity < Velocity) and Velocity or MaxVelocity
|
||||
local Heading = Coordinate:GetHeading()
|
||||
AvgHeading = AvgHeading and (AvgHeading + Heading) or Heading
|
||||
MovingCount = MovingCount + 1
|
||||
end
|
||||
local Vec3 = GetSetVec3(self.Set)
|
||||
if Vec3 then
|
||||
Coordinate = COORDINATE:NewFromVec3(Vec3)
|
||||
end
|
||||
|
||||
AvgHeading = AvgHeading and (AvgHeading / MovingCount)
|
||||
|
||||
Coordinate.x = (x2 - x1) / 2 + x1
|
||||
Coordinate.y = (y2 - y1) / 2 + y1
|
||||
Coordinate.z = (z2 - z1) / 2 + z1
|
||||
Coordinate:SetHeading( AvgHeading )
|
||||
Coordinate:SetVelocity( MaxVelocity )
|
||||
|
||||
self:F( { Coordinate = Coordinate } )
|
||||
if Coordinate then
|
||||
local heading = self:GetHeading() or 0
|
||||
local velocity = self:GetVelocity() or 0
|
||||
Coordinate:SetHeading( heading )
|
||||
Coordinate:SetVelocity( velocity )
|
||||
self:I(UTILS.PrintTableToLog(Coordinate))
|
||||
end
|
||||
|
||||
return Coordinate
|
||||
|
||||
end
|
||||
|
||||
--- Get the maximum velocity of the SET_UNIT.
|
||||
|
||||
@ -1108,6 +1108,22 @@ function SPAWN:InitRandomizeCallsign()
|
||||
return self
|
||||
end
|
||||
|
||||
--- [BLUE AIR only!] This method sets a specific callsign for a spawned group. Use for a group with one unit only!
|
||||
-- @param #SPAWN self
|
||||
-- @param #number ID ID of the callsign enumerator, e.g. CALLSIGN.Tanker.Texaco - - resulting in e.g. Texaco-2-1
|
||||
-- @param #string Name Name of this callsign as it cannot be determined from the ID because of the dependency on the task type of the plane, and the plane type. E.g. "Texaco"
|
||||
-- @param #number Minor Minor number, i.e. the unit number within the group, e.g 2 - resulting in e.g. Texaco-2-1
|
||||
-- @param #number Major Major number, i.e. the group number of this name, e.g. 1 - resulting in e.g. Texaco-2-1
|
||||
-- @return #SPAWN self
|
||||
function SPAWN:InitCallSign(ID,Name,Minor,Major)
|
||||
self.SpawnInitCallSign = true
|
||||
self.SpawnInitCallSignID = ID or 1
|
||||
self.SpawnInitCallSignMinor = Minor or 1
|
||||
self.SpawnInitCallSignMajor = Major or 1
|
||||
self.SpawnInitCallSignName = string.lower(Name) or "enfield"
|
||||
return self
|
||||
end
|
||||
|
||||
--- This method sets a spawn position for the group that is different from the location of the template.
|
||||
-- @param #SPAWN self
|
||||
-- @param Core.Point#COORDINATE Coordinate The position to spawn from
|
||||
@ -3331,10 +3347,23 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) -- R2.2
|
||||
end
|
||||
end
|
||||
|
||||
if self.SpawnInitCallSign then
|
||||
for UnitID = 1, #SpawnTemplate.units do
|
||||
local Callsign = SpawnTemplate.units[UnitID].callsign
|
||||
if Callsign and type( Callsign ) ~= "number" then
|
||||
SpawnTemplate.units[UnitID].callsign[1] = self.SpawnInitCallSignID
|
||||
SpawnTemplate.units[UnitID].callsign[2] = self.SpawnInitCallSignMinor
|
||||
SpawnTemplate.units[UnitID].callsign[3] = self.SpawnInitCallSignMajor
|
||||
SpawnTemplate.units[UnitID].callsign["name"] = string.format("%s%d%d",self.SpawnInitCallSignName,self.SpawnInitCallSignMinor,self.SpawnInitCallSignMajor)
|
||||
--UTILS.PrintTableToLog(SpawnTemplate.units[UnitID].callsign,1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for UnitID = 1, #SpawnTemplate.units do
|
||||
local Callsign = SpawnTemplate.units[UnitID].callsign
|
||||
if Callsign then
|
||||
if type( Callsign ) ~= "number" then -- blue callsign
|
||||
if type( Callsign ) ~= "number" and not self.SpawnInitCallSign then -- blue callsign
|
||||
-- UTILS.PrintTableToLog(Callsign,1)
|
||||
Callsign[2] = ((SpawnIndex - 1) % 10) + 1
|
||||
local CallsignName = SpawnTemplate.units[UnitID].callsign["name"] -- #string
|
||||
@ -3342,7 +3371,7 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) -- R2.2
|
||||
local CallsignLen = CallsignName:len()
|
||||
SpawnTemplate.units[UnitID].callsign[2] = UnitID
|
||||
SpawnTemplate.units[UnitID].callsign["name"] = CallsignName:sub( 1, CallsignLen ) .. SpawnTemplate.units[UnitID].callsign[2] .. SpawnTemplate.units[UnitID].callsign[3]
|
||||
else
|
||||
elseif type( Callsign ) == "number" then
|
||||
SpawnTemplate.units[UnitID].callsign = Callsign + SpawnIndex
|
||||
end
|
||||
end
|
||||
@ -3377,11 +3406,11 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) -- R2.2
|
||||
end
|
||||
end
|
||||
-- VoiceCallsignNumber
|
||||
if SpawnTemplate.units[UnitID].AddPropAircraft.VoiceCallsignNumber then
|
||||
if SpawnTemplate.units[UnitID].AddPropAircraft.VoiceCallsignNumber and type( Callsign ) ~= "number" then
|
||||
SpawnTemplate.units[UnitID].AddPropAircraft.VoiceCallsignNumber = SpawnTemplate.units[UnitID].callsign[2] .. SpawnTemplate.units[UnitID].callsign[3]
|
||||
end
|
||||
-- VoiceCallsignLabel
|
||||
if SpawnTemplate.units[UnitID].AddPropAircraft.VoiceCallsignLabel then
|
||||
if SpawnTemplate.units[UnitID].AddPropAircraft.VoiceCallsignLabel and type( Callsign ) ~= "number" then
|
||||
local CallsignName = SpawnTemplate.units[UnitID].callsign["name"] -- #string
|
||||
CallsignName = string.match(CallsignName,"^(%a+)") -- 2.8 - only the part w/o numbers
|
||||
local label = "NY" -- Navy One exception
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
-- * Create moving zones around a unit.
|
||||
-- * Create moving zones around a group.
|
||||
-- * Provide the zone behavior. Some zones are static, while others are moveable.
|
||||
-- * Enquiry if a coordinate is within a zone.
|
||||
-- * Enquire if a coordinate is within a zone.
|
||||
-- * Smoke zones.
|
||||
-- * Set a zone probability to control zone selection.
|
||||
-- * Get zone coordinates.
|
||||
@ -2001,240 +2001,19 @@ function ZONE_GROUP:GetRandomPointVec2( inner, outer )
|
||||
end
|
||||
|
||||
|
||||
--- ZONE_OVAL created from a center point, major axis, minor axis, and angle.
|
||||
-- Ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @type ZONE_OVAL
|
||||
-- @extends Core.Zone#ZONE_BASE
|
||||
|
||||
--- ## ZONE_OVAL class, extends @{#ZONE_BASE}
|
||||
--
|
||||
-- The ZONE_OVAL class is defined by a center point, major axis, minor axis, and angle.
|
||||
-- This class implements the inherited functions from @{#ZONE_BASE} taking into account the own zone format and properties.
|
||||
--
|
||||
-- @field #ZONE_OVAL
|
||||
ZONE_OVAL = {
|
||||
ClassName = "OVAL",
|
||||
ZoneName="",
|
||||
MajorAxis = nil,
|
||||
MinorAxis = nil,
|
||||
Angle = 0,
|
||||
DrawPoly = nil -- let's just use a ZONE_POLYGON to draw the ZONE_OVAL on the map
|
||||
}
|
||||
|
||||
--- Creates a new ZONE_OVAL from a center point, major axis, minor axis, and angle.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #table vec2 The center point of the oval
|
||||
-- @param #number major_axis The major axis of the oval
|
||||
-- @param #number minor_axis The minor axis of the oval
|
||||
-- @param #number angle The angle of the oval
|
||||
-- @return #ZONE_OVAL The new oval
|
||||
function ZONE_OVAL:New(name, vec2, major_axis, minor_axis, angle)
|
||||
self = BASE:Inherit(self, ZONE_BASE:New())
|
||||
self.ZoneName = name
|
||||
self.CenterVec2 = vec2
|
||||
self.MajorAxis = major_axis
|
||||
self.MinorAxis = minor_axis
|
||||
self.Angle = angle or 0
|
||||
|
||||
_DATABASE:AddZone(name, self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Constructor to create a ZONE_OVAL instance, taking the name of a drawing made with the draw tool in the Mission Editor.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #string DrawingName The name of the drawing in the Mission Editor
|
||||
-- @return #ZONE_OVAL self
|
||||
function ZONE_OVAL:NewFromDrawing(DrawingName)
|
||||
self = BASE:Inherit(self, ZONE_BASE:New(DrawingName))
|
||||
for _, layer in pairs(env.mission.drawings.layers) do
|
||||
for _, object in pairs(layer["objects"]) do
|
||||
if string.find(object["name"], DrawingName, 1, true) then
|
||||
if object["polygonMode"] == "oval" then
|
||||
self.CenterVec2 = { x = object["mapX"], y = object["mapY"] }
|
||||
self.MajorAxis = object["r1"]
|
||||
self.MinorAxis = object["r2"]
|
||||
self.Angle = object["angle"]
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
_DATABASE:AddZone(DrawingName, self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the major axis of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The major axis of the oval
|
||||
function ZONE_OVAL:GetMajorAxis()
|
||||
return self.MajorAxis
|
||||
end
|
||||
|
||||
--- Gets the minor axis of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The minor axis of the oval
|
||||
function ZONE_OVAL:GetMinorAxis()
|
||||
return self.MinorAxis
|
||||
end
|
||||
|
||||
--- Gets the angle of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The angle of the oval
|
||||
function ZONE_OVAL:GetAngle()
|
||||
return self.Angle
|
||||
end
|
||||
|
||||
--- Returns a the center point of the oval
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The center Vec2
|
||||
function ZONE_OVAL:GetVec2()
|
||||
return self.CenterVec2
|
||||
end
|
||||
|
||||
--- Checks if a point is contained within the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #table point The point to check
|
||||
-- @return #bool True if the point is contained, false otherwise
|
||||
function ZONE_OVAL:IsVec2InZone(vec2)
|
||||
local cos, sin = math.cos, math.sin
|
||||
local dx = vec2.x - self.CenterVec2.x
|
||||
local dy = vec2.y - self.CenterVec2.y
|
||||
local rx = dx * cos(self.Angle) + dy * sin(self.Angle)
|
||||
local ry = -dx * sin(self.Angle) + dy * cos(self.Angle)
|
||||
return rx * rx / (self.MajorAxis * self.MajorAxis) + ry * ry / (self.MinorAxis * self.MinorAxis) <= 1
|
||||
end
|
||||
|
||||
--- Calculates the bounding box of the oval. The bounding box is the smallest rectangle that contains the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The bounding box of the oval
|
||||
function ZONE_OVAL:GetBoundingSquare()
|
||||
local min_x = self.CenterVec2.x - self.MajorAxis
|
||||
local min_y = self.CenterVec2.y - self.MinorAxis
|
||||
local max_x = self.CenterVec2.x + self.MajorAxis
|
||||
local max_y = self.CenterVec2.y + self.MinorAxis
|
||||
|
||||
return {
|
||||
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
|
||||
}
|
||||
end
|
||||
|
||||
--- Find points on the edge of the oval
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #number num_points How many points should be found. More = smoother shape
|
||||
-- @return #table Points on he edge
|
||||
function ZONE_OVAL:PointsOnEdge(num_points)
|
||||
num_points = num_points or 40
|
||||
local points = {}
|
||||
local dtheta = 2 * math.pi / num_points
|
||||
|
||||
for i = 0, num_points - 1 do
|
||||
local theta = i * dtheta
|
||||
local x = self.CenterVec2.x + self.MajorAxis * math.cos(theta) * math.cos(self.Angle) - self.MinorAxis * math.sin(theta) * math.sin(self.Angle)
|
||||
local y = self.CenterVec2.y + self.MajorAxis * math.cos(theta) * math.sin(self.Angle) + self.MinorAxis * math.sin(theta) * math.cos(self.Angle)
|
||||
table.insert(points, {x = x, y = y})
|
||||
end
|
||||
|
||||
return points
|
||||
end
|
||||
|
||||
--- Returns a random Vec2 within the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The random Vec2
|
||||
function ZONE_OVAL:GetRandomVec2()
|
||||
local theta = math.rad(self.Angle)
|
||||
|
||||
local random_point = math.sqrt(math.random()) --> uniformly
|
||||
--local random_point = math.random() --> more clumped around center
|
||||
local phi = math.random() * 2 * math.pi
|
||||
local x_c = random_point * math.cos(phi)
|
||||
local y_c = random_point * math.sin(phi)
|
||||
local x_e = x_c * self.MajorAxis
|
||||
local y_e = y_c * self.MinorAxis
|
||||
local rx = (x_e * math.cos(theta) - y_e * math.sin(theta)) + self.CenterVec2.x
|
||||
local ry = (x_e * math.sin(theta) + y_e * math.cos(theta)) + self.CenterVec2.y
|
||||
|
||||
return {x=rx, y=ry}
|
||||
end
|
||||
|
||||
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
|
||||
function ZONE_OVAL:GetRandomPointVec2()
|
||||
return POINT_VEC2:NewFromVec2(self:GetRandomVec2())
|
||||
end
|
||||
|
||||
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
|
||||
function ZONE_OVAL:GetRandomPointVec3()
|
||||
return POINT_VEC2:NewFromVec3(self:GetRandomVec2())
|
||||
end
|
||||
|
||||
--- Draw the zone on the F10 map.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #number Coalition Coalition: All=-1, Neutral=0, Red=1, Blue=2. Default -1=All.
|
||||
-- @param #table Color RGB color table {r, g, b}, e.g. {1,0,0} for red.
|
||||
-- @param #number Alpha Transparency [0,1]. Default 1.
|
||||
-- @param #table FillColor RGB color table {r, g, b}, e.g. {1,0,0} for red. Default is same as `Color` value. -- doesn't seem to work
|
||||
-- @param #number FillAlpha Transparency [0,1]. Default 0.15. -- doesn't seem to work
|
||||
-- @param #number LineType Line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 1=Solid.
|
||||
-- @param #boolean ReadOnly (Optional) Mark is readonly and cannot be removed by users. Default false.
|
||||
-- @return #ZONE_OVAL self
|
||||
function ZONE_OVAL:DrawZone(Coalition, Color, Alpha, FillColor, FillAlpha, LineType)
|
||||
Coalition = Coalition or self:GetDrawCoalition()
|
||||
|
||||
-- Set draw coalition.
|
||||
self:SetDrawCoalition(Coalition)
|
||||
|
||||
Color = Color or self:GetColorRGB()
|
||||
Alpha = Alpha or 1
|
||||
|
||||
-- Set color.
|
||||
self:SetColor(Color, Alpha)
|
||||
|
||||
FillColor = FillColor or self:GetFillColorRGB()
|
||||
if not FillColor then
|
||||
UTILS.DeepCopy(Color)
|
||||
end
|
||||
FillAlpha = FillAlpha or self:GetFillColorAlpha()
|
||||
if not FillAlpha then
|
||||
FillAlpha = 0.15
|
||||
end
|
||||
|
||||
LineType = LineType or 1
|
||||
|
||||
-- Set fill color -----------> has fill color worked in recent versions of DCS?
|
||||
-- doing something like
|
||||
--
|
||||
-- trigger.action.markupToAll(7, -1, 501, p.Coords[1]:GetVec3(), p.Coords[2]:GetVec3(),p.Coords[3]:GetVec3(),p.Coords[4]:GetVec3(),{1,0,0, 1}, {1,0,0, 1}, 4, false, Text or "")
|
||||
--
|
||||
-- doesn't seem to fill in the shape for an n-sided polygon
|
||||
self:SetFillColor(FillColor, FillAlpha)
|
||||
|
||||
self.DrawPoly = ZONE_POLYGON:NewFromPointsArray(self.ZoneName, self:PointsOnEdge(80))
|
||||
self.DrawPoly:DrawZone(Coalition, Color, Alpha, FillColor, FillAlpha, LineType)
|
||||
end
|
||||
|
||||
--- Remove drawing from F10 map
|
||||
-- @param #ZONE_OVAL self
|
||||
function ZONE_OVAL:UndrawZone()
|
||||
if self.DrawPoly then
|
||||
self.DrawPoly:UndrawZone()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- Ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Triangle.lua
|
||||
--- This triangle "zone" is not really to be used on its own, it only serves as building blocks for
|
||||
--- ZONE_POLYGON to accurately find a point inside a polygon; as well as getting the correct surface area of
|
||||
--- a polygon.
|
||||
-- @type _ZONE_TRIANGLE
|
||||
-- @extends #BASE
|
||||
-- @extends Core.Zone#ZONE_BASE
|
||||
|
||||
--- ## _ZONE_TRIANGLE class, extends @{#ZONE_BASE}
|
||||
--
|
||||
-- _ZONE_TRIANGLE class is a helper class for ZONE_POLYGON
|
||||
-- This class implements the inherited functions from @{#ZONE_BASE} taking into account the own zone format and properties.
|
||||
--
|
||||
-- @field #_ZONE_TRIANGLE
|
||||
_ZONE_TRIANGLE = {
|
||||
ClassName="ZONE_TRIANGLE",
|
||||
Points={},
|
||||
@ -2243,7 +2022,12 @@ _ZONE_TRIANGLE = {
|
||||
SurfaceArea=0,
|
||||
DrawIDs={}
|
||||
}
|
||||
|
||||
---
|
||||
-- @param #_ZONE_TRIANGLE self
|
||||
-- @param DCS#Vec p1
|
||||
-- @param DCS#Vec p2
|
||||
-- @param DCS#Vec p3
|
||||
-- @return #_ZONE_TRIANGLE self
|
||||
function _ZONE_TRIANGLE:New(p1, p2, p3)
|
||||
local self = BASE:Inherit(self, ZONE_BASE:New())
|
||||
self.Points = {p1, p2, p3}
|
||||
@ -2262,6 +2046,7 @@ function _ZONE_TRIANGLE:New(p1, p2, p3)
|
||||
end
|
||||
|
||||
--- Checks if a point is contained within the triangle.
|
||||
-- @param #_ZONE_TRIANGLE self
|
||||
-- @param #table pt The point to check
|
||||
-- @param #table points (optional) The points of the triangle, or 3 other points if you're just using the TRIANGLE class without an object of it
|
||||
-- @return #bool True if the point is contained, false otherwise
|
||||
@ -2283,6 +2068,7 @@ function _ZONE_TRIANGLE:ContainsPoint(pt, points)
|
||||
end
|
||||
|
||||
--- Returns a random Vec2 within the triangle.
|
||||
-- @param #_ZONE_TRIANGLE self
|
||||
-- @param #table points The points of the triangle, or 3 other points if you're just using the TRIANGLE class without an object of it
|
||||
-- @return #table The random Vec2
|
||||
function _ZONE_TRIANGLE:GetRandomVec2(points)
|
||||
@ -2298,6 +2084,8 @@ function _ZONE_TRIANGLE:GetRandomVec2(points)
|
||||
end
|
||||
|
||||
--- Draw the triangle
|
||||
-- @param #_ZONE_TRIANGLE self
|
||||
-- @return #table of draw IDs
|
||||
function _ZONE_TRIANGLE:Draw(Coalition, Color, Alpha, FillColor, FillAlpha, LineType, ReadOnly)
|
||||
Coalition=Coalition or -1
|
||||
|
||||
@ -2380,19 +2168,20 @@ function ZONE_POLYGON_BASE:New( ZoneName, PointsArray )
|
||||
self._.Polygon[i].y = PointsArray[i].y
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- triangulate the polygon so we can work with it
|
||||
self._Triangles = self:_Triangulate()
|
||||
-- set the polygon's surface area
|
||||
self.SurfaceArea = self:_CalculateSurfaceArea()
|
||||
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Triangulates the polygon.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Polygon.lua
|
||||
-- @return #table The #_TRIANGLE list that make up
|
||||
-- @param #ZONE_POLYGON_BASE self
|
||||
-- @return #table The #_ZONE_TRIANGLE list that makes up the polygon
|
||||
function ZONE_POLYGON_BASE:_Triangulate()
|
||||
local points = self._.Polygon
|
||||
local triangles = {}
|
||||
@ -2521,6 +2310,7 @@ end
|
||||
|
||||
--- Calculates the surface area of the polygon. The surface area is the sum of the areas of the triangles that make up the polygon.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Polygon.lua
|
||||
-- @param #ZONE_POLYGON_BASE self
|
||||
-- @return #number The surface area of the polygon
|
||||
function ZONE_POLYGON_BASE:_CalculateSurfaceArea()
|
||||
local area = 0
|
||||
@ -3090,9 +2880,13 @@ function ZONE_POLYGON_BASE:Boundary(Coalition, Color, Radius, Alpha, Segments, C
|
||||
return self
|
||||
end
|
||||
|
||||
do -- Zone_Polygon
|
||||
|
||||
|
||||
---
|
||||
-- @type ZONE_POLYGON
|
||||
-- @extends #ZONE_POLYGON_BASE
|
||||
-- @extends #ZONE_BASE
|
||||
|
||||
|
||||
--- The ZONE_POLYGON class defined by a sequence of @{Wrapper.Group#GROUP} waypoints within the Mission Editor, forming a polygon, OR by drawings made with the Draw tool
|
||||
@ -3124,8 +2918,7 @@ end
|
||||
--
|
||||
-- This class has been updated to use a accurate way of generating random points inside the polygon without having to use trial and error guesses.
|
||||
-- You can also get the surface area of the polygon now, handy if you want measure which coalition has the largest captured area, for example.
|
||||
|
||||
|
||||
--
|
||||
-- @field #ZONE_POLYGON
|
||||
ZONE_POLYGON = {
|
||||
ClassName="ZONE_POLYGON",
|
||||
@ -3590,9 +3383,11 @@ function ZONE_POLYGON:IsNoneInZone()
|
||||
return self:CountScannedCoalitions() == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
do -- ZONE_ELASTIC
|
||||
|
||||
---
|
||||
-- @type ZONE_ELASTIC
|
||||
-- @field #table points Points in 2D.
|
||||
-- @field #table setGroups Set of GROUPs.
|
||||
@ -3791,8 +3586,238 @@ do -- ZONE_ELASTIC
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- ZONE_OVAL created from a center point, major axis, minor axis, and angle.
|
||||
-- Ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @type ZONE_OVAL
|
||||
-- @extends Core.Zone#ZONE_BASE
|
||||
|
||||
--- ## ZONE_OVAL class, extends @{#ZONE_BASE}
|
||||
--
|
||||
-- The ZONE_OVAL class is defined by a center point, major axis, minor axis, and angle.
|
||||
-- This class implements the inherited functions from @{#ZONE_BASE} taking into account the own zone format and properties.
|
||||
--
|
||||
-- @field #ZONE_OVAL
|
||||
ZONE_OVAL = {
|
||||
ClassName = "OVAL",
|
||||
ZoneName="",
|
||||
MajorAxis = nil,
|
||||
MinorAxis = nil,
|
||||
Angle = 0,
|
||||
DrawPoly = nil -- let's just use a ZONE_POLYGON to draw the ZONE_OVAL on the map
|
||||
}
|
||||
|
||||
--- Creates a new ZONE_OVAL from a center point, major axis, minor axis, and angle.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #table vec2 The center point of the oval
|
||||
-- @param #number major_axis The major axis of the oval
|
||||
-- @param #number minor_axis The minor axis of the oval
|
||||
-- @param #number angle The angle of the oval
|
||||
-- @return #ZONE_OVAL The new oval
|
||||
function ZONE_OVAL:New(name, vec2, major_axis, minor_axis, angle)
|
||||
self = BASE:Inherit(self, ZONE_BASE:New())
|
||||
self.ZoneName = name
|
||||
self.CenterVec2 = vec2
|
||||
self.MajorAxis = major_axis
|
||||
self.MinorAxis = minor_axis
|
||||
self.Angle = angle or 0
|
||||
|
||||
_DATABASE:AddZone(name, self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Constructor to create a ZONE_OVAL instance, taking the name of a drawing made with the draw tool in the Mission Editor.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #string DrawingName The name of the drawing in the Mission Editor
|
||||
-- @return #ZONE_OVAL self
|
||||
function ZONE_OVAL:NewFromDrawing(DrawingName)
|
||||
self = BASE:Inherit(self, ZONE_BASE:New(DrawingName))
|
||||
for _, layer in pairs(env.mission.drawings.layers) do
|
||||
for _, object in pairs(layer["objects"]) do
|
||||
if string.find(object["name"], DrawingName, 1, true) then
|
||||
if object["polygonMode"] == "oval" then
|
||||
self.CenterVec2 = { x = object["mapX"], y = object["mapY"] }
|
||||
self.MajorAxis = object["r1"]
|
||||
self.MinorAxis = object["r2"]
|
||||
self.Angle = object["angle"]
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
_DATABASE:AddZone(DrawingName, self)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Gets the major axis of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The major axis of the oval
|
||||
function ZONE_OVAL:GetMajorAxis()
|
||||
return self.MajorAxis
|
||||
end
|
||||
|
||||
--- Gets the minor axis of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The minor axis of the oval
|
||||
function ZONE_OVAL:GetMinorAxis()
|
||||
return self.MinorAxis
|
||||
end
|
||||
|
||||
--- Gets the angle of the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #number The angle of the oval
|
||||
function ZONE_OVAL:GetAngle()
|
||||
return self.Angle
|
||||
end
|
||||
|
||||
--- Returns a the center point of the oval
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The center Vec2
|
||||
function ZONE_OVAL:GetVec2()
|
||||
return self.CenterVec2
|
||||
end
|
||||
|
||||
--- Checks if a point is contained within the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #table point The point to check
|
||||
-- @return #bool True if the point is contained, false otherwise
|
||||
function ZONE_OVAL:IsVec2InZone(vec2)
|
||||
local cos, sin = math.cos, math.sin
|
||||
local dx = vec2.x - self.CenterVec2.x
|
||||
local dy = vec2.y - self.CenterVec2.y
|
||||
local rx = dx * cos(self.Angle) + dy * sin(self.Angle)
|
||||
local ry = -dx * sin(self.Angle) + dy * cos(self.Angle)
|
||||
return rx * rx / (self.MajorAxis * self.MajorAxis) + ry * ry / (self.MinorAxis * self.MinorAxis) <= 1
|
||||
end
|
||||
|
||||
--- Calculates the bounding box of the oval. The bounding box is the smallest rectangle that contains the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The bounding box of the oval
|
||||
function ZONE_OVAL:GetBoundingSquare()
|
||||
local min_x = self.CenterVec2.x - self.MajorAxis
|
||||
local min_y = self.CenterVec2.y - self.MinorAxis
|
||||
local max_x = self.CenterVec2.x + self.MajorAxis
|
||||
local max_y = self.CenterVec2.y + self.MinorAxis
|
||||
|
||||
return {
|
||||
{x=min_x, y=min_x}, {x=max_x, y=min_y}, {x=max_x, y=max_y}, {x=min_x, y=max_y}
|
||||
}
|
||||
end
|
||||
|
||||
--- Find points on the edge of the oval
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #number num_points How many points should be found. More = smoother shape
|
||||
-- @return #table Points on he edge
|
||||
function ZONE_OVAL:PointsOnEdge(num_points)
|
||||
num_points = num_points or 40
|
||||
local points = {}
|
||||
local dtheta = 2 * math.pi / num_points
|
||||
|
||||
for i = 0, num_points - 1 do
|
||||
local theta = i * dtheta
|
||||
local x = self.CenterVec2.x + self.MajorAxis * math.cos(theta) * math.cos(self.Angle) - self.MinorAxis * math.sin(theta) * math.sin(self.Angle)
|
||||
local y = self.CenterVec2.y + self.MajorAxis * math.cos(theta) * math.sin(self.Angle) + self.MinorAxis * math.sin(theta) * math.cos(self.Angle)
|
||||
table.insert(points, {x = x, y = y})
|
||||
end
|
||||
|
||||
return points
|
||||
end
|
||||
|
||||
--- Returns a random Vec2 within the oval.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return #table The random Vec2
|
||||
function ZONE_OVAL:GetRandomVec2()
|
||||
local theta = math.rad(self.Angle)
|
||||
|
||||
local random_point = math.sqrt(math.random()) --> uniformly
|
||||
--local random_point = math.random() --> more clumped around center
|
||||
local phi = math.random() * 2 * math.pi
|
||||
local x_c = random_point * math.cos(phi)
|
||||
local y_c = random_point * math.sin(phi)
|
||||
local x_e = x_c * self.MajorAxis
|
||||
local y_e = y_c * self.MinorAxis
|
||||
local rx = (x_e * math.cos(theta) - y_e * math.sin(theta)) + self.CenterVec2.x
|
||||
local ry = (x_e * math.sin(theta) + y_e * math.cos(theta)) + self.CenterVec2.y
|
||||
|
||||
return {x=rx, y=ry}
|
||||
end
|
||||
|
||||
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
|
||||
function ZONE_OVAL:GetRandomPointVec2()
|
||||
return POINT_VEC2:NewFromVec2(self:GetRandomVec2())
|
||||
end
|
||||
|
||||
--- Define a random @{Core.Point#POINT_VEC2} within the zone.
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @return Core.Point#POINT_VEC2 The PointVec2 coordinates.
|
||||
function ZONE_OVAL:GetRandomPointVec3()
|
||||
return POINT_VEC2:NewFromVec3(self:GetRandomVec2())
|
||||
end
|
||||
|
||||
--- Draw the zone on the F10 map.
|
||||
--- ported from https://github.com/nielsvaes/CCMOOSE/blob/master/Moose%20Development/Moose/Shapes/Oval.lua
|
||||
-- @param #ZONE_OVAL self
|
||||
-- @param #number Coalition Coalition: All=-1, Neutral=0, Red=1, Blue=2. Default -1=All.
|
||||
-- @param #table Color RGB color table {r, g, b}, e.g. {1,0,0} for red.
|
||||
-- @param #number Alpha Transparency [0,1]. Default 1.
|
||||
-- @param #table FillColor RGB color table {r, g, b}, e.g. {1,0,0} for red. Default is same as `Color` value. -- doesn't seem to work
|
||||
-- @param #number FillAlpha Transparency [0,1]. Default 0.15. -- doesn't seem to work
|
||||
-- @param #number LineType Line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 1=Solid.
|
||||
-- @param #boolean ReadOnly (Optional) Mark is readonly and cannot be removed by users. Default false.
|
||||
-- @return #ZONE_OVAL self
|
||||
function ZONE_OVAL:DrawZone(Coalition, Color, Alpha, FillColor, FillAlpha, LineType)
|
||||
Coalition = Coalition or self:GetDrawCoalition()
|
||||
|
||||
-- Set draw coalition.
|
||||
self:SetDrawCoalition(Coalition)
|
||||
|
||||
Color = Color or self:GetColorRGB()
|
||||
Alpha = Alpha or 1
|
||||
|
||||
-- Set color.
|
||||
self:SetColor(Color, Alpha)
|
||||
|
||||
FillColor = FillColor or self:GetFillColorRGB()
|
||||
if not FillColor then
|
||||
UTILS.DeepCopy(Color)
|
||||
end
|
||||
FillAlpha = FillAlpha or self:GetFillColorAlpha()
|
||||
if not FillAlpha then
|
||||
FillAlpha = 0.15
|
||||
end
|
||||
|
||||
LineType = LineType or 1
|
||||
|
||||
-- Set fill color -----------> has fill color worked in recent versions of DCS?
|
||||
-- doing something like
|
||||
--
|
||||
-- trigger.action.markupToAll(7, -1, 501, p.Coords[1]:GetVec3(), p.Coords[2]:GetVec3(),p.Coords[3]:GetVec3(),p.Coords[4]:GetVec3(),{1,0,0, 1}, {1,0,0, 1}, 4, false, Text or "")
|
||||
--
|
||||
-- doesn't seem to fill in the shape for an n-sided polygon
|
||||
self:SetFillColor(FillColor, FillAlpha)
|
||||
|
||||
self.DrawPoly = ZONE_POLYGON:NewFromPointsArray(self.ZoneName, self:PointsOnEdge(80))
|
||||
self.DrawPoly:DrawZone(Coalition, Color, Alpha, FillColor, FillAlpha, LineType)
|
||||
end
|
||||
|
||||
--- Remove drawing from F10 map
|
||||
-- @param #ZONE_OVAL self
|
||||
function ZONE_OVAL:UndrawZone()
|
||||
if self.DrawPoly then
|
||||
self.DrawPoly:UndrawZone()
|
||||
end
|
||||
end
|
||||
|
||||
do -- ZONE_AIRBASE
|
||||
|
||||
---
|
||||
-- @type ZONE_AIRBASE
|
||||
-- @field #boolean isShip If `true`, airbase is a ship.
|
||||
-- @field #boolean isHelipad If `true`, airbase is a helipad.
|
||||
|
||||
@ -39,7 +39,8 @@
|
||||
|
||||
do -- DETECTION_BASE
|
||||
|
||||
--- @type DETECTION_BASE
|
||||
---
|
||||
-- @type DETECTION_BASE
|
||||
-- @field Core.Set#SET_GROUP DetectionSetGroup The @{Core.Set} of GROUPs in the Forward Air Controller role.
|
||||
-- @field DCS#Distance DetectionRange The range till which targets are accepted to be detected.
|
||||
-- @field #DETECTION_BASE.DetectedObjects DetectedObjects The list of detected objects.
|
||||
@ -91,6 +92,11 @@ do -- DETECTION_BASE
|
||||
--
|
||||
-- DetectionObject:FilterCategories( { Unit.Category.AIRPLANE, Unit.Category.HELICOPTER } )
|
||||
--
|
||||
--
|
||||
-- ## Radar Blur - use to make the radar less exact, e.g. for WWII scenarios
|
||||
--
|
||||
-- * @{DETECTION_BASE.SetRadarBlur}(): Set the radar blur to be used.
|
||||
--
|
||||
-- ## **DETECTION_ derived classes** group the detected units into a **DetectedItems[]** list
|
||||
--
|
||||
-- DETECTION_BASE derived classes build a list called DetectedItems[], which is essentially a first later
|
||||
@ -269,10 +275,12 @@ do -- DETECTION_BASE
|
||||
DetectedItemsByIndex = {},
|
||||
}
|
||||
|
||||
--- @type DETECTION_BASE.DetectedObjects
|
||||
---
|
||||
-- @type DETECTION_BASE.DetectedObjects
|
||||
-- @list <#DETECTION_BASE.DetectedObject>
|
||||
|
||||
--- @type DETECTION_BASE.DetectedObject
|
||||
---
|
||||
-- @type DETECTION_BASE.DetectedObject
|
||||
-- @field #string Name
|
||||
-- @field #boolean IsVisible
|
||||
-- @field #boolean KnowType
|
||||
@ -284,7 +292,8 @@ do -- DETECTION_BASE
|
||||
-- @field #boolean LastPos
|
||||
-- @field #number LastVelocity
|
||||
|
||||
--- @type DETECTION_BASE.DetectedItems
|
||||
---
|
||||
-- @type DETECTION_BASE.DetectedItems
|
||||
-- @list <#DETECTION_BASE.DetectedItem>
|
||||
|
||||
--- Detected item data structure.
|
||||
@ -522,7 +531,7 @@ do -- DETECTION_BASE
|
||||
|
||||
do -- State Transition Handling
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
@ -530,7 +539,7 @@ do -- DETECTION_BASE
|
||||
self:__Detect( 1 )
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
@ -570,7 +579,7 @@ do -- DETECTION_BASE
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #number The amount of alive recce.
|
||||
function DETECTION_BASE:CountAliveRecce()
|
||||
|
||||
@ -578,7 +587,7 @@ do -- DETECTION_BASE
|
||||
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE self
|
||||
function DETECTION_BASE:ForEachAliveRecce( IteratorFunction, ... )
|
||||
self:F2( arg )
|
||||
|
||||
@ -587,7 +596,7 @@ do -- DETECTION_BASE
|
||||
return self
|
||||
end
|
||||
|
||||
--- @param #DETECTION_BASE self
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #string From The From State string.
|
||||
-- @param #string Event The Event string.
|
||||
-- @param #string To The To State string.
|
||||
@ -712,6 +721,31 @@ do -- DETECTION_BASE
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate radar blur probability
|
||||
|
||||
if self.RadarBlur then
|
||||
MESSAGE:New("Radar Blur",10):ToLogIf(self.debug):ToAllIf(self.verbose)
|
||||
local minheight = self.RadarBlurMinHeight or 250 -- meters
|
||||
local thresheight = self.RadarBlurThresHeight or 90 -- 10% chance to find a low flying group
|
||||
local thresblur = self.RadarBlurThresBlur or 85 -- 25% chance to escape the radar overall
|
||||
local dist = math.floor(Distance)
|
||||
if dist <= self.RadarBlurClosing then
|
||||
thresheight = (((dist*dist)/self.RadarBlurClosingSquare)*thresheight)
|
||||
thresblur = (((dist*dist)/self.RadarBlurClosingSquare)*thresblur)
|
||||
end
|
||||
local fheight = math.floor(math.random(1,10000)/100)
|
||||
local fblur = math.floor(math.random(1,10000)/100)
|
||||
local unit = UNIT:FindByName(DetectedObjectName)
|
||||
if unit and unit:IsAlive() then
|
||||
local AGL = unit:GetAltitude(true)
|
||||
MESSAGE:New("Unit "..DetectedObjectName.." is at "..math.floor(AGL).."m. Distance "..math.floor(Distance).."km.",10):ToLogIf(self.debug):ToAllIf(self.verbose)
|
||||
MESSAGE:New(string.format("fheight = %d/%d | fblur = %d/%d",fheight,thresheight,fblur,thresblur),10):ToLogIf(self.debug):ToAllIf(self.verbose)
|
||||
if fblur > thresblur then DetectionAccepted = false end
|
||||
if AGL <= minheight and fheight < thresheight then DetectionAccepted = false end
|
||||
MESSAGE:New("Detection Accepted = "..tostring(DetectionAccepted),10):ToLogIf(self.debug):ToAllIf(self.verbose)
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate additional probabilities
|
||||
|
||||
if not self.DetectedObjects[DetectedObjectName] and TargetIsVisible and self.DistanceProbability then
|
||||
@ -1012,6 +1046,23 @@ do -- DETECTION_BASE
|
||||
|
||||
end
|
||||
|
||||
--- Method to make the radar detection less accurate, e.g. for WWII scenarios.
|
||||
-- @param #DETECTION_BASE self
|
||||
-- @param #number minheight Minimum flight height to be detected, in meters AGL (above ground)
|
||||
-- @param #number thresheight Threshold to escape the radar if flying below minheight, defaults to 90 (90% escape chance)
|
||||
-- @param #number thresblur Threshold to be detected by the radar overall, defaults to 85 (85% chance to be found)
|
||||
-- @param #number closing Closing-in in km - the limit of km from which on it becomes increasingly difficult to escape radar detection if flying towards the radar position. Should be about 1/3 of the radar detection radius in kilometers, defaults to 20.
|
||||
-- @return #DETECTION_BASE self
|
||||
function DETECTION_BASE:SetRadarBlur(minheight,thresheight,thresblur,closing)
|
||||
self.RadarBlur = true
|
||||
self.RadarBlurMinHeight = minheight or 250 -- meters
|
||||
self.RadarBlurThresHeight = thresheight or 90 -- 10% chance to find a low flying group
|
||||
self.RadarBlurThresBlur = thresblur or 85 -- 25% chance to escape the radar overall
|
||||
self.RadarBlurClosing = closing or 20 -- 20km
|
||||
self.RadarBlurClosingSquare = self.RadarBlurClosing * self.RadarBlurClosing
|
||||
return self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
do
|
||||
@ -1354,7 +1405,7 @@ do -- DETECTION_BASE
|
||||
}
|
||||
}
|
||||
|
||||
--- @param DCS#Unit FoundDCSUnit
|
||||
-- @param DCS#Unit FoundDCSUnit
|
||||
-- @param Wrapper.Group#GROUP ReportGroup
|
||||
-- @param Core.Set#SET_GROUP ReportSetGroup
|
||||
local FindNearByFriendlies = function( FoundDCSUnit, ReportGroupData )
|
||||
@ -1419,7 +1470,7 @@ do -- DETECTION_BASE
|
||||
DetectedItem.PlayersNearBy = nil
|
||||
|
||||
_DATABASE:ForEachPlayer(
|
||||
--- @param Wrapper.Unit#UNIT PlayerUnit
|
||||
-- @param Wrapper.Unit#UNIT PlayerUnit
|
||||
function( PlayerUnitName )
|
||||
local PlayerUnit = UNIT:FindByName( PlayerUnitName )
|
||||
|
||||
@ -1976,7 +2027,8 @@ end
|
||||
|
||||
do -- DETECTION_UNITS
|
||||
|
||||
--- @type DETECTION_UNITS
|
||||
---
|
||||
-- @type DETECTION_UNITS
|
||||
-- @field DCS#Distance DetectionRange The range till which targets are detected.
|
||||
-- @extends Functional.Detection#DETECTION_BASE
|
||||
|
||||
@ -2232,7 +2284,8 @@ end
|
||||
|
||||
do -- DETECTION_TYPES
|
||||
|
||||
--- @type DETECTION_TYPES
|
||||
---
|
||||
-- @type DETECTION_TYPES
|
||||
-- @extends Functional.Detection#DETECTION_BASE
|
||||
|
||||
--- Will detect units within the battle zone.
|
||||
@ -2435,7 +2488,8 @@ end
|
||||
|
||||
do -- DETECTION_AREAS
|
||||
|
||||
--- @type DETECTION_AREAS
|
||||
---
|
||||
-- @type DETECTION_AREAS
|
||||
-- @field DCS#Distance DetectionZoneRange The range till which targets are grouped upon the first detected target.
|
||||
-- @field #DETECTION_BASE.DetectedItems DetectedItems A list of areas containing the set of @{Wrapper.Unit}s, @{Core.Zone}s, the center @{Wrapper.Unit} within the zone, and ID of each area that was detected within a DetectionZoneRange.
|
||||
-- @extends Functional.Detection#DETECTION_BASE
|
||||
@ -2961,7 +3015,7 @@ do -- DETECTION_AREAS
|
||||
|
||||
-- DetectedSet:Flush( self )
|
||||
|
||||
DetectedSet:ForEachUnit( --- @param Wrapper.Unit#UNIT DetectedUnit
|
||||
DetectedSet:ForEachUnit( -- @param Wrapper.Unit#UNIT DetectedUnit
|
||||
function( DetectedUnit )
|
||||
if DetectedUnit:IsAlive() then
|
||||
-- self:T( "Detected Set #" .. DetectedItem.ID .. ":" .. DetectedUnit:GetName() )
|
||||
|
||||
@ -1207,18 +1207,18 @@ end
|
||||
-- @return #RANGE self
|
||||
function RANGE:SetSRS(PathToSRS, Port, Coalition, Frequency, Modulation, Volume, PathToGoogleKey)
|
||||
|
||||
if PathToSRS then
|
||||
if PathToSRS or MSRS.path then
|
||||
|
||||
self.useSRS=true
|
||||
|
||||
self.controlmsrs=MSRS:New(PathToSRS, Frequency or 256, Modulation or radio.modulation.AM, Volume or 1.0)
|
||||
self.controlmsrs:SetPort(Port)
|
||||
self.controlmsrs=MSRS:New(PathToSRS or MSRS.path, Frequency or 256, Modulation or radio.modulation.AM, Volume or 1.0)
|
||||
self.controlmsrs:SetPort(Port or MSRS.port)
|
||||
self.controlmsrs:SetCoalition(Coalition or coalition.side.BLUE)
|
||||
self.controlmsrs:SetLabel("RANGEC")
|
||||
self.controlsrsQ = MSRSQUEUE:New("CONTROL")
|
||||
|
||||
self.instructmsrs=MSRS:New(PathToSRS, Frequency or 305, Modulation or radio.modulation.AM, Volume or 1.0)
|
||||
self.instructmsrs:SetPort(Port)
|
||||
self.instructmsrs=MSRS:New(PathToSRS or MSRS.path, Frequency or 305, Modulation or radio.modulation.AM, Volume or 1.0)
|
||||
self.instructmsrs:SetPort(Port or MSRS.port)
|
||||
self.instructmsrs:SetCoalition(Coalition or coalition.side.BLUE)
|
||||
self.instructmsrs:SetLabel("RANGEI")
|
||||
self.instructsrsQ = MSRSQUEUE:New("INSTRUCT")
|
||||
@ -2187,7 +2187,7 @@ function RANGE:onafterExitRange( From, Event, To, player )
|
||||
|
||||
local text = "You left the bombing range zone. "
|
||||
|
||||
local r=math.random(2)
|
||||
local r=math.random(5)
|
||||
|
||||
if r==1 then
|
||||
text=text.."Have a nice day!"
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
-- @module Ops.CTLD
|
||||
-- @image OPS_CTLD.jpg
|
||||
|
||||
-- Last Update November 2023
|
||||
-- Last Update December 2023
|
||||
|
||||
do
|
||||
|
||||
@ -1228,7 +1228,7 @@ CTLD.UnitTypeCapabilities = {
|
||||
|
||||
--- CTLD class version.
|
||||
-- @field #string version
|
||||
CTLD.version="1.0.43"
|
||||
CTLD.version="1.0.44"
|
||||
|
||||
--- Instantiate a new CTLD.
|
||||
-- @param #CTLD self
|
||||
@ -2561,6 +2561,40 @@ function CTLD:_ListCratesNearby( _group, _unit)
|
||||
return self
|
||||
end
|
||||
|
||||
-- (Internal) Function to find and Remove nearby crates.
|
||||
-- @param #CTLD self
|
||||
-- @param Wrapper.Group#GROUP Group
|
||||
-- @param Wrapper.Unit#UNIT Unit
|
||||
-- @return #CTLD self
|
||||
function CTLD:_RemoveCratesNearby( _group, _unit)
|
||||
self:T(self.lid .. " _RemoveCratesNearby")
|
||||
local finddist = self.CrateDistance or 35
|
||||
local crates,number = self:_FindCratesNearby(_group,_unit, finddist,true) -- #table
|
||||
if number > 0 then
|
||||
local text = REPORT:New("Removing Crates Found Nearby:")
|
||||
text:Add("------------------------------------------------------------")
|
||||
for _,_entry in pairs (crates) do
|
||||
local entry = _entry -- #CTLD_CARGO
|
||||
local name = entry:GetName() --#string
|
||||
local dropped = entry:WasDropped()
|
||||
if dropped then
|
||||
text:Add(string.format("Crate for %s, %dkg removed",name, entry.PerCrateMass))
|
||||
else
|
||||
text:Add(string.format("Crate for %s, %dkg removed",name, entry.PerCrateMass))
|
||||
end
|
||||
entry:GetPositionable():Destroy(false)
|
||||
end
|
||||
if text:GetCount() == 1 then
|
||||
text:Add(" N O N E")
|
||||
end
|
||||
text:Add("------------------------------------------------------------")
|
||||
self:_SendMessage(text:Text(), 30, true, _group)
|
||||
else
|
||||
self:_SendMessage(string.format("No (loadable) crates within %d meters!",finddist), 10, false, _group)
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- (Internal) Return distance in meters between two coordinates.
|
||||
-- @param #CTLD self
|
||||
-- @param Core.Point#COORDINATE _point1 Coordinate one
|
||||
@ -2976,6 +3010,35 @@ function CTLD:IsHercules(Unit)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--- (Internal) Function to set troops positions of a template to a nice circle
|
||||
-- @param #CTLD self
|
||||
-- @param Core.Point#COORDINATE Coordinate Start coordinate to use
|
||||
-- @param #number Radius Radius to be used
|
||||
-- @param #number Heading Heading starting with
|
||||
-- @param #string Template The group template name
|
||||
-- @return #table Positions The positions table
|
||||
function CTLD:_GetUnitPositions(Coordinate,Radius,Heading,Template)
|
||||
local Positions = {}
|
||||
local template = _DATABASE:GetGroupTemplate(Template)
|
||||
UTILS.PrintTableToLog(template)
|
||||
local numbertroops = #template.units
|
||||
local newcenter = Coordinate:Translate(Radius,((Heading+270)%360))
|
||||
for i=1,360,math.floor(360/numbertroops) do
|
||||
local phead = ((Heading+270+i)%360)
|
||||
local post = newcenter:Translate(Radius,phead)
|
||||
local pos1 = post:GetVec2()
|
||||
local p1t = {
|
||||
x = pos1.x,
|
||||
y = pos1.y,
|
||||
heading = phead,
|
||||
}
|
||||
table.insert(Positions,p1t)
|
||||
end
|
||||
UTILS.PrintTableToLog(Positions)
|
||||
return Positions
|
||||
end
|
||||
|
||||
--- (Internal) Function to unload troops from heli.
|
||||
-- @param #CTLD self
|
||||
-- @param Wrapper.Group#GROUP Group
|
||||
@ -3027,14 +3090,29 @@ function CTLD:_UnloadTroops(Group, Unit)
|
||||
zoneradius = Unit:GetVelocityMPS() or 100
|
||||
end
|
||||
local zone = ZONE_GROUP:New(string.format("Unload zone-%s",unitname),Group,zoneradius*factor)
|
||||
local randomcoord = zone:GetRandomCoordinate(10,30*factor):GetVec2()
|
||||
local randomcoord = zone:GetRandomCoordinate(10,30*factor) --:GetVec2()
|
||||
local heading = Group:GetHeading() or 0
|
||||
-- Spawn troops left from us, closer when hovering, further off when landed
|
||||
if hoverunload or grounded then
|
||||
randomcoord = Group:GetCoordinate()
|
||||
-- slightly left from us
|
||||
local Angle = (heading+270)%360
|
||||
local offset = hoverunload and 1.5 or 5
|
||||
randomcoord:Translate(offset,Angle,nil,true)
|
||||
end
|
||||
local tempcount = 0
|
||||
for _,_template in pairs(temptable) do
|
||||
self.TroopCounter = self.TroopCounter + 1
|
||||
tempcount = tempcount+1
|
||||
local alias = string.format("%s-%d", _template, math.random(1,100000))
|
||||
local rad = 2.5+tempcount
|
||||
local Positions = self:_GetUnitPositions(randomcoord,rad,heading,_template)
|
||||
self.DroppedTroops[self.TroopCounter] = SPAWN:NewWithAlias(_template,alias)
|
||||
:InitRandomizeUnits(true,20,2)
|
||||
--:InitRandomizeUnits(true,20,2)
|
||||
--:InitHeading(heading)
|
||||
:InitDelayOff()
|
||||
:SpawnFromVec2(randomcoord)
|
||||
:InitSetUnitAbsolutePositions(Positions)
|
||||
:SpawnFromVec2(randomcoord:GetVec2())
|
||||
self:__TroopsDeployed(1, Group, Unit, self.DroppedTroops[self.TroopCounter],type)
|
||||
end -- template loop
|
||||
cargo:SetWasDropped(true)
|
||||
@ -3637,6 +3715,7 @@ function CTLD:_RefreshF10Menus()
|
||||
local loadmenu = MENU_GROUP_COMMAND:New(_group,"Load crates",topcrates, self._LoadCratesNearby, self, _group, _unit)
|
||||
local cratesmenu = MENU_GROUP:New(_group,"Get Crates",topcrates)
|
||||
local packmenu = MENU_GROUP_COMMAND:New(_group, "Pack crates", topcrates, self._PackCratesNearby, self, _group, _unit)
|
||||
local removecratesmenu = MENU_GROUP:New(_group, "Remove crates", topcrates)
|
||||
|
||||
if self.usesubcats then
|
||||
local subcatmenus = {}
|
||||
@ -3672,6 +3751,7 @@ function CTLD:_RefreshF10Menus()
|
||||
end
|
||||
end
|
||||
listmenu = MENU_GROUP_COMMAND:New(_group,"List crates nearby",topcrates, self._ListCratesNearby, self, _group, _unit)
|
||||
removecrates = MENU_GROUP_COMMAND:New(_group,"Remove crates nearby",removecratesmenu, self._RemoveCratesNearby, self, _group, _unit)
|
||||
local unloadmenu = MENU_GROUP_COMMAND:New(_group,"Drop crates",topcrates, self._UnloadCrates, self, _group, _unit)
|
||||
if not self.nobuildmenu then
|
||||
local buildmenu = MENU_GROUP_COMMAND:New(_group,"Build crates",topcrates, self._BuildCrates, self, _group, _unit)
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
-- @field #table filterCategoryGroup Filter for group categories.
|
||||
-- @field Core.Set#SET_ZONE acceptzoneset Set of accept zones. If defined, only contacts in these zones are considered.
|
||||
-- @field Core.Set#SET_ZONE rejectzoneset Set of reject zones. Contacts in these zones are not considered, even if they are in accept zones.
|
||||
-- @field Core.Set#SET_ZONE conflictzoneset Set of conflict zones. Contacts in these zones are considered, even if they are not in accept zones or if they are in reject zones.
|
||||
-- @field #table Contacts Table of detected items.
|
||||
-- @field #table ContactsLost Table of lost detected items.
|
||||
-- @field #table ContactsUnknown Table of new detected items.
|
||||
@ -159,13 +160,12 @@ INTEL.Ctype={
|
||||
|
||||
--- INTEL class version.
|
||||
-- @field #string version
|
||||
INTEL.version="0.3.5"
|
||||
INTEL.version="0.3.6"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- TODO: Make forget times user input. Currently these are hard coded.
|
||||
-- TODO: Add min cluster size. Only create new clusters if they have a certain group size.
|
||||
-- TODO: process detected set asynchroniously for better performance.
|
||||
-- DONE: Add statics.
|
||||
@ -266,6 +266,7 @@ function INTEL:New(DetectionSet, Coalition, Alias)
|
||||
self:SetForgetTime()
|
||||
self:SetAcceptZones()
|
||||
self:SetRejectZones()
|
||||
self:SetConflictZones()
|
||||
|
||||
------------------------
|
||||
--- Pseudo Functions ---
|
||||
@ -416,7 +417,7 @@ function INTEL:RemoveAcceptZone(AcceptZone)
|
||||
end
|
||||
|
||||
--- Set reject zones. Contacts detected in this/these zone(s) are rejected and not reported by the detection.
|
||||
-- Note that reject zones overrule accept zones, i.e. if a unit is inside and accept zone and inside a reject zone, it is rejected.
|
||||
-- Note that reject zones overrule accept zones, i.e. if a unit is inside an accept zone and inside a reject zone, it is rejected.
|
||||
-- @param #INTEL self
|
||||
-- @param Core.Set#SET_ZONE RejectZoneSet Set of reject zone(s).
|
||||
-- @return #INTEL self
|
||||
@ -426,7 +427,7 @@ function INTEL:SetRejectZones(RejectZoneSet)
|
||||
end
|
||||
|
||||
--- Add a reject zone. Contacts detected in this zone are rejected and not reported by the detection.
|
||||
-- Note that reject zones overrule accept zones, i.e. if a unit is inside and accept zone and inside a reject zone, it is rejected.
|
||||
-- Note that reject zones overrule accept zones, i.e. if a unit is inside an accept zone and inside a reject zone, it is rejected.
|
||||
-- @param #INTEL self
|
||||
-- @param Core.Zone#ZONE RejectZone Add a zone to the reject zone set.
|
||||
-- @return #INTEL self
|
||||
@ -444,6 +445,36 @@ function INTEL:RemoveRejectZone(RejectZone)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set conflict zones. Contacts detected in this/these zone(s) are reported by the detection.
|
||||
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
|
||||
-- @param #INTEL self
|
||||
-- @param Core.Set#SET_ZONE ConflictZoneSet Set of conflict zone(s).
|
||||
-- @return #INTEL self
|
||||
function INTEL:SetConflictZones(ConflictZoneSet)
|
||||
self.conflictzoneset=ConflictZoneSet or SET_ZONE:New()
|
||||
return self
|
||||
end
|
||||
|
||||
--- Add a conflict zone. Contacts detected in this zone are conflicted and not reported by the detection.
|
||||
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
|
||||
-- @param #INTEL self
|
||||
-- @param Core.Zone#ZONE ConflictZone Add a zone to the conflict zone set.
|
||||
-- @return #INTEL self
|
||||
function INTEL:AddConflictZone(ConflictZone)
|
||||
self.conflictzoneset:AddZone(ConflictZone)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Remove a conflict zone from the conflict zone set.
|
||||
-- Note that conflict zones overrule all other zones, i.e. if a unit is outside of an accept zone and inside a reject zone, it is still reported if inside a conflict zone.
|
||||
-- @param #INTEL self
|
||||
-- @param Core.Zone#ZONE ConflictZone Remove a zone from the conflict zone set.
|
||||
-- @return #INTEL self
|
||||
function INTEL:RemoveConflictZone(ConflictZone)
|
||||
self.conflictzoneset:Remove(ConflictZone:GetName(), true)
|
||||
return self
|
||||
end
|
||||
|
||||
--- **OBSOLETE, will be removed in next version!** Set forget contacts time interval.
|
||||
-- Previously known contacts that are not detected any more, are "lost" after this time.
|
||||
-- This avoids fast oscillations between a contact being detected and undetected.
|
||||
@ -481,6 +512,33 @@ function INTEL:SetFilterCategory(Categories)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Method to make the radar detection less accurate, e.g. for WWII scenarios.
|
||||
-- @param #INTEL self
|
||||
-- @param #number minheight Minimum flight height to be detected, in meters AGL (above ground)
|
||||
-- @param #number thresheight Threshold to escape the radar if flying below minheight, defaults to 90 (90% escape chance)
|
||||
-- @param #number thresblur Threshold to be detected by the radar overall, defaults to 85 (85% chance to be found)
|
||||
-- @param #number closing Closing-in in km - the limit of km from which on it becomes increasingly difficult to escape radar detection if flying towards the radar position. Should be about 1/3 of the radar detection radius in kilometers, defaults to 20.
|
||||
-- @return #INTEL self
|
||||
function INTEL:SetRadarBlur(minheight,thresheight,thresblur,closing)
|
||||
self.RadarBlur = true
|
||||
self.RadarBlurMinHeight = minheight or 250 -- meters
|
||||
self.RadarBlurThresHeight = thresheight or 90 -- 10% chance to find a low flying group
|
||||
self.RadarBlurThresBlur = thresblur or 85 -- 25% chance to escape the radar overall
|
||||
self.RadarBlurClosing = closing or 20 -- 20km
|
||||
self.RadarBlurClosingSquare = self.RadarBlurClosing * self.RadarBlurClosing
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set the accept range in kilometers from each of the recce. Only object closer than this range will be detected.
|
||||
-- @param #INTEL self
|
||||
-- @param #number Range Range in kilometers
|
||||
-- @return #INTEL self
|
||||
function INTEL:SetAcceptRange(Range)
|
||||
self.RadarAcceptRange = true
|
||||
self.RadarAcceptRangeKilometers = Range or 75
|
||||
return self
|
||||
end
|
||||
|
||||
--- Filter group categories. Valid categories are:
|
||||
--
|
||||
-- * Group.Category.AIRPLANE
|
||||
@ -781,6 +839,18 @@ function INTEL:UpdateIntel()
|
||||
for unitname,_unit in pairs(DetectedUnits) do
|
||||
local unit=_unit --Wrapper.Unit#UNIT
|
||||
|
||||
local inconflictzone=false
|
||||
-- Check if unit is in any of the conflict zones.
|
||||
if self.conflictzoneset:Count()>0 then
|
||||
for _,_zone in pairs(self.conflictzoneset.Set) do
|
||||
local zone=_zone --Core.Zone#ZONE
|
||||
if unit:IsInZone(zone) then
|
||||
inconflictzone=true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if unit is in any of the accept zones.
|
||||
if self.acceptzoneset:Count()>0 then
|
||||
local inzone=false
|
||||
@ -793,7 +863,7 @@ function INTEL:UpdateIntel()
|
||||
end
|
||||
|
||||
-- Unit is not in accept zone ==> remove!
|
||||
if not inzone then
|
||||
if (not inzone) and (not inconflictzone) then
|
||||
table.insert(remove, unitname)
|
||||
end
|
||||
end
|
||||
@ -810,7 +880,7 @@ function INTEL:UpdateIntel()
|
||||
end
|
||||
|
||||
-- Unit is inside a reject zone ==> remove!
|
||||
if inzone then
|
||||
if inzone and (not inconflictzone) then
|
||||
table.insert(remove, unitname)
|
||||
end
|
||||
end
|
||||
@ -1037,7 +1107,7 @@ function INTEL:CreateDetectedItems(DetectedGroups, DetectedStatics, RecceDetecti
|
||||
end
|
||||
|
||||
--- (Internal) Return the detected target groups of the controllable as a @{SET_GROUP}.
|
||||
-- The optional parametes specify the detection methods that can be applied.
|
||||
-- The optional parameters specify the detection methods that can be applied.
|
||||
-- If no detection method is given, the detection will use all the available methods by default.
|
||||
-- @param #INTEL self
|
||||
-- @param Wrapper.Unit#UNIT Unit The unit detecting.
|
||||
@ -1053,6 +1123,7 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
|
||||
|
||||
-- Get detected DCS units.
|
||||
local reccename = Unit:GetName()
|
||||
|
||||
local detectedtargets=Unit:GetDetectedTargets(DetectVisual, DetectOptical, DetectRadar, DetectIRST, DetectRWR, DetectDLINK)
|
||||
|
||||
for DetectionObjectID, Detection in pairs(detectedtargets or {}) do
|
||||
@ -1073,9 +1144,45 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
|
||||
local unit=UNIT:FindByName(name)
|
||||
|
||||
if unit and unit:IsAlive() then
|
||||
local DetectionAccepted = true
|
||||
|
||||
if self.RadarAcceptRange then
|
||||
local reccecoord = Unit:GetCoordinate()
|
||||
local coord = unit:GetCoordinate()
|
||||
local dist = math.floor(coord:Get2DDistance(reccecoord)/1000) -- km
|
||||
if dist > self.RadarAcceptRangeKilometers then DetectionAccepted = false end
|
||||
end
|
||||
|
||||
if self.RadarBlur then
|
||||
local reccecoord = Unit:GetCoordinate()
|
||||
local coord = unit:GetCoordinate()
|
||||
local dist = math.floor(coord:Get2DDistance(reccecoord)/1000) -- km
|
||||
local AGL = unit:GetAltitude(true)
|
||||
local minheight = self.RadarBlurMinHeight or 250 -- meters
|
||||
local thresheight = self.RadarBlurThresHeight or 90 -- 10% chance to find a low flying group
|
||||
local thresblur = self.RadarBlurThresBlur or 85 -- 25% chance to escape the radar overall
|
||||
--local dist = math.floor(Distance)
|
||||
if dist <= self.RadarBlurClosing then
|
||||
thresheight = (((dist*dist)/self.RadarBlurClosingSquare)*thresheight)
|
||||
thresblur = (((dist*dist)/self.RadarBlurClosingSquare)*thresblur)
|
||||
end
|
||||
local fheight = math.floor(math.random(1,10000)/100)
|
||||
local fblur = math.floor(math.random(1,10000)/100)
|
||||
if fblur > thresblur then DetectionAccepted = false end
|
||||
if AGL <= minheight and fheight < thresheight then DetectionAccepted = false end
|
||||
if self.debug or self.verbose > 1 then
|
||||
MESSAGE:New("Radar Blur",10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
|
||||
MESSAGE:New("Unit "..name.." is at "..math.floor(AGL).."m. Distance "..math.floor(dist).."km.",10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
|
||||
MESSAGE:New(string.format("fheight = %d/%d | fblur = %d/%d",fheight,thresheight,fblur,thresblur),10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
|
||||
MESSAGE:New("Detection Accepted = "..tostring(DetectionAccepted),10):ToLogIf(self.debug):ToAllIf(self.verbose>1)
|
||||
end
|
||||
end
|
||||
|
||||
if DetectionAccepted then
|
||||
DetectedUnits[name]=unit
|
||||
RecceDetecting[name]=reccename
|
||||
self:T(string.format("Unit %s detect by %s", name, reccename))
|
||||
end
|
||||
else
|
||||
if self.detectStatics then
|
||||
local static=STATIC:FindByName(name, false)
|
||||
@ -1093,7 +1200,6 @@ function INTEL:GetDetectedUnits(Unit, DetectedUnits, RecceDetecting, DetectVisua
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@ -3477,7 +3477,6 @@ function OPSGROUP:RemoveWaypoint(wpindex)
|
||||
self:_PassedFinalWaypoint(false, "Removed PASSED temporary waypoint")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@ -5805,6 +5804,27 @@ function OPSGROUP:onafterMissionDone(From, Event, To, Mission)
|
||||
end
|
||||
end
|
||||
|
||||
if self.legion and self.legionReturn==false and self.waypoints and #self.waypoints==1 then
|
||||
---
|
||||
-- This is the case where a group was send on a mission (which is over now), has no addional
|
||||
-- waypoints or tasks and should NOT return to its legion.
|
||||
-- We create a new waypoint at the current position and let it hold here.
|
||||
---
|
||||
|
||||
local Coordinate=self:GetCoordinate()
|
||||
|
||||
if self.isArmygroup then
|
||||
ARMYGROUP.AddWaypoint(self, Coordinate, 0, nil, nil, false)
|
||||
elseif self.isNavygroup then
|
||||
NAVYGROUP.AddWaypoint(self,Coordinate, 0, nil, nil, false)
|
||||
end
|
||||
|
||||
-- Remove original waypoint.
|
||||
self:RemoveWaypoint(1)
|
||||
|
||||
self:_PassedFinalWaypoint(true, "Passed final waypoint as group is done with mission but should NOT return to its legion")
|
||||
end
|
||||
|
||||
-- Check if group is done.
|
||||
self:_CheckGroupDone(delay)
|
||||
|
||||
|
||||
@ -97,7 +97,7 @@ OPSZONE.ZoneType={
|
||||
|
||||
--- OPSZONE class version.
|
||||
-- @field #string version
|
||||
OPSZONE.version="0.6.0"
|
||||
OPSZONE.version="0.6.1"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- ToDo list
|
||||
@ -1277,7 +1277,7 @@ function OPSZONE:EvaluateZone()
|
||||
|
||||
if Nblu>0 then
|
||||
|
||||
if not self:IsAttacked() then
|
||||
if not self:IsAttacked() and self.Tnut>=self.threatlevelCapture then
|
||||
self:Attacked(coalition.side.BLUE)
|
||||
end
|
||||
|
||||
@ -1329,7 +1329,7 @@ function OPSZONE:EvaluateZone()
|
||||
|
||||
if Nred>0 then
|
||||
|
||||
if not self:IsAttacked() then
|
||||
if not self:IsAttacked() and self.Tnut>=self.threatlevelCapture then
|
||||
-- Red is attacking blue zone.
|
||||
self:Attacked(coalition.side.RED)
|
||||
end
|
||||
|
||||
@ -79,6 +79,7 @@
|
||||
-- @field Utilities.FiFo#FIFO TargetCache
|
||||
-- @field #boolean smokeownposition
|
||||
-- @field #table SmokeOwn
|
||||
-- @field #boolean smokeaveragetargetpos
|
||||
-- @extends Core.Fsm#FSM
|
||||
|
||||
---
|
||||
@ -104,7 +105,7 @@ PLAYERRECCE = {
|
||||
ClassName = "PLAYERRECCE",
|
||||
verbose = true,
|
||||
lid = nil,
|
||||
version = "0.0.22",
|
||||
version = "0.1.23",
|
||||
ViewZone = {},
|
||||
ViewZoneVisual = {},
|
||||
ViewZoneLaser = {},
|
||||
@ -130,8 +131,9 @@ PLAYERRECCE = {
|
||||
ReferencePoint = nil,
|
||||
TForget = 600,
|
||||
TargetCache = nil,
|
||||
smokeownposition = true,
|
||||
smokeownposition = false,
|
||||
SmokeOwn = {},
|
||||
smokeaveragetargetpos = false,
|
||||
}
|
||||
|
||||
---
|
||||
@ -1109,9 +1111,8 @@ function PLAYERRECCE:_SmokeTargets(client,group,playername)
|
||||
self:T(self.lid.."_SmokeTargets")
|
||||
local cameraset = self:_GetTargetSet(client,true) -- Core.Set#SET_UNIT
|
||||
local visualset = self:_GetTargetSet(client,false) -- Core.Set#SET_UNIT
|
||||
cameraset:AddSet(visualset)
|
||||
|
||||
if cameraset:CountAlive() > 0 then
|
||||
if cameraset:CountAlive() > 0 or visualset:CountAlive() > 0 then
|
||||
self:__TargetsSmoked(-1,client,playername,cameraset)
|
||||
else
|
||||
return self
|
||||
@ -1126,29 +1127,31 @@ function PLAYERRECCE:_SmokeTargets(client,group,playername)
|
||||
-- laser targer gets extra smoke
|
||||
if laser and laser.Target and laser.Target:IsAlive() then
|
||||
laser.Target:GetCoordinate():Smoke(lasersmoke)
|
||||
if cameraset:IsInSet(laser.Target) then
|
||||
cameraset:Remove(laser.Target:GetName(),true)
|
||||
end
|
||||
end
|
||||
|
||||
local coordinate = nil
|
||||
local setthreat = 0
|
||||
-- smoke everything else
|
||||
if cameraset:CountAlive() > 1 then
|
||||
local coordinate = cameraset:GetCoordinate()
|
||||
local setthreat = cameraset:CalculateThreatLevelA2G()
|
||||
end
|
||||
|
||||
if coordinate then
|
||||
local coord = visualset:GetCoordinate()
|
||||
if coord and self.smokeaveragetargetpos then
|
||||
coord:SetAtLandheight()
|
||||
coord:Smoke(medsmoke)
|
||||
else
|
||||
-- smoke everything
|
||||
for _,_unit in pairs(visualset.Set) do
|
||||
local unit = _unit --Wrapper.Unit#UNIT
|
||||
if unit and unit:IsAlive() then
|
||||
local coord = unit:GetCoordinate()
|
||||
local threat = unit:GetThreatLevel()
|
||||
if coord then
|
||||
local color = lowsmoke
|
||||
if setthreat > 7 then
|
||||
if threat > 7 then
|
||||
color = highsmoke
|
||||
elseif threat > 2 then
|
||||
color = medsmoke
|
||||
elseif setthreat > 2 then
|
||||
color = lowsmoke
|
||||
end
|
||||
coordinate:Smoke(color)
|
||||
coord:Smoke(color)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.SmokeOwn[playername] then
|
||||
local cc = client:GetVec2()
|
||||
-- don't smoke mid-air
|
||||
@ -1189,15 +1192,15 @@ function PLAYERRECCE:_FlareTargets(client,group,playername)
|
||||
-- smoke everything else
|
||||
for _,_unit in pairs(cameraset.Set) do
|
||||
local unit = _unit --Wrapper.Unit#UNIT
|
||||
if unit then
|
||||
if unit and unit:IsAlive() then
|
||||
local coord = unit:GetCoordinate()
|
||||
local threat = unit:GetThreatLevel()
|
||||
if coord then
|
||||
local color = lowsmoke
|
||||
if threat > 7 then
|
||||
color = medsmoke
|
||||
color = highsmoke
|
||||
elseif threat > 2 then
|
||||
color = lowsmoke
|
||||
color = medsmoke
|
||||
end
|
||||
coord:Flare(color)
|
||||
end
|
||||
@ -1546,7 +1549,7 @@ end
|
||||
-- @param #PLAYERRECCE self
|
||||
-- @return #PLAYERRECCE self
|
||||
function PLAYERRECCE:EnableSmokeOwnPosition()
|
||||
self:T(self.lid.."ENableSmokeOwnPosition")
|
||||
self:T(self.lid.."EnableSmokeOwnPosition")
|
||||
self.smokeownposition = true
|
||||
return self
|
||||
end
|
||||
@ -1560,6 +1563,24 @@ function PLAYERRECCE:DisableSmokeOwnPosition()
|
||||
return self
|
||||
end
|
||||
|
||||
--- [User] Enable smoking of average target positions, instead of all targets visible. Loses smoke per threatlevel -- each is med threat. Default is - smoke all positions.
|
||||
-- @param #PLAYERRECCE self
|
||||
-- @return #PLAYERRECCE self
|
||||
function PLAYERRECCE:EnableSmokeAverageTargetPosition()
|
||||
self:T(self.lid.."ENableSmokeOwnPosition")
|
||||
self.smokeaveragetargetpos = true
|
||||
return self
|
||||
end
|
||||
|
||||
--- [User] Disable smoking of average target positions, instead of all targets visible. Default is - smoke all positions.
|
||||
-- @param #PLAYERRECCE self
|
||||
-- @return #PLAYERRECCE
|
||||
function PLAYERRECCE:DisableSmokeAverageTargetPosition()
|
||||
self:T(self.lid.."DisableSmokeAverageTargetPosition")
|
||||
self.smokeaveragetargetpos = false
|
||||
return self
|
||||
end
|
||||
|
||||
--- [Internal] Get text for text-to-speech.
|
||||
-- Numbers are spaced out, e.g. "Heading 180" becomes "Heading 1 8 0 ".
|
||||
-- @param #PLAYERRECCE self
|
||||
|
||||
@ -159,4 +159,24 @@ do -- UserSound
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Play the usersound to the given @{Wrapper.Client}.
|
||||
-- @param #USERSOUND self
|
||||
-- @param Wrapper.Client#CLIENT The @{Wrapper.Client} to play the usersound to.
|
||||
-- @param #number Delay (Optional) Delay in seconds, before the sound is played. Default 0.
|
||||
-- @return #USERSOUND The usersound instance.
|
||||
-- @usage
|
||||
-- local BlueVictory = USERSOUND:New( "BlueVictory.ogg" )
|
||||
-- local PlayerUnit = CLIENT:FindByPlayerName("Karl Heinz")-- Search for the active client with playername "Karl Heinz", a human player.
|
||||
-- BlueVictory:ToClient( PlayerUnit ) -- Play the victory sound to the player unit.
|
||||
--
|
||||
function USERSOUND:ToClient( Client, Delay )
|
||||
Delay=Delay or 0
|
||||
if Delay>0 then
|
||||
SCHEDULER:New(nil, USERSOUND.ToClient,{self, Client}, Delay)
|
||||
else
|
||||
trigger.action.outSoundForUnit( Client:GetID(), self.UserSoundFileName )
|
||||
end
|
||||
return self
|
||||
end
|
||||
end
|
||||
@ -443,22 +443,35 @@ end
|
||||
|
||||
--- Print a table to log in a nice format
|
||||
-- @param #table table The table to print
|
||||
-- @param #number indent Number of idents
|
||||
-- @param #number indent Number of indents
|
||||
-- @return #string text Text created on the fly of the log output
|
||||
function UTILS.PrintTableToLog(table, indent)
|
||||
local text = "\n"
|
||||
if not table then
|
||||
env.warning("No table passed!")
|
||||
return
|
||||
return nil
|
||||
end
|
||||
if not indent then indent = 0 end
|
||||
for k, v in pairs(table) do
|
||||
if string.find(k," ") then k='"'..k..'"'end
|
||||
if type(v) == "table" then
|
||||
env.info(string.rep(" ", indent) .. tostring(k) .. " = {")
|
||||
UTILS.PrintTableToLog(v, indent + 1)
|
||||
env.info(string.rep(" ", indent) .. "}")
|
||||
text = text ..string.rep(" ", indent) .. tostring(k) .. " = {\n"
|
||||
text = text .. tostring(UTILS.PrintTableToLog(v, indent + 1)).."\n"
|
||||
env.info(string.rep(" ", indent) .. "},")
|
||||
text = text .. string.rep(" ", indent) .. "},\n"
|
||||
else
|
||||
env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(v))
|
||||
local value
|
||||
if tostring(v) == "true" or tostring(v) == "false" or tonumber(v) ~= nil then
|
||||
value=v
|
||||
else
|
||||
value = '"'..tostring(v)..'"'
|
||||
end
|
||||
env.info(string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n")
|
||||
text = text .. string.rep(" ", indent) .. tostring(k) .. " = " .. tostring(value)..",\n"
|
||||
end
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
--- Returns table in a easy readable string representation.
|
||||
|
||||
@ -1159,6 +1159,7 @@ function GROUP:GetAverageCoordinate()
|
||||
local coord = COORDINATE:NewFromVec3(vec3)
|
||||
local Heading = self:GetHeading()
|
||||
coord.Heading = Heading
|
||||
return coord
|
||||
else
|
||||
BASE:E( { "Cannot GetAverageCoordinate", Group = self, Alive = self:IsAlive() } )
|
||||
return nil
|
||||
|
||||
@ -5,6 +5,7 @@ Utilities/Profiler.lua
|
||||
Utilities/Templates.lua
|
||||
Utilities/STTS.lua
|
||||
Utilities/FiFo.lua
|
||||
Utilities/Socket.lua
|
||||
|
||||
Core/Base.lua
|
||||
Core/Beacon.lua
|
||||
@ -32,6 +33,8 @@ Core/TextAndSound.lua
|
||||
Core/Condition.lua
|
||||
Core/Pathline.lua
|
||||
Core/ClientMenu.lua
|
||||
Core/Astar.lua
|
||||
Core/MarkerOps_Base.lua
|
||||
|
||||
Wrapper/Object.lua
|
||||
Wrapper/Identifiable.lua
|
||||
@ -79,6 +82,7 @@ Functional/Shorad.lua
|
||||
Functional/Autolase.lua
|
||||
Functional/AICSAR.lua
|
||||
Functional/AmmoTruck.lua
|
||||
Functional/ZoneGoalCargo.lua
|
||||
|
||||
Ops/Airboss.lua
|
||||
Ops/RecoveryTanker.lua
|
||||
@ -107,6 +111,10 @@ Ops/FlightControl.lua
|
||||
Ops/PlayerTask.lua
|
||||
Ops/PlayerRecce.lua
|
||||
Ops/EasyGCICAP.lua
|
||||
Ops/OpsZone.lua
|
||||
Ops/ArmyGroup.lua
|
||||
Ops/OpsTransport.lua
|
||||
Ops/Target.lua
|
||||
|
||||
AI/AI_Balancer.lua
|
||||
AI/AI_Air.lua
|
||||
|
||||
13
docs/beginner/demo-missions.md
Normal file
13
docs/beginner/demo-missions.md
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
parent: Beginner
|
||||
nav_order: 04
|
||||
---
|
||||
|
||||
# Demo missions
|
||||
{: .no_toc }
|
||||
|
||||
1. Table of contents
|
||||
{:toc}
|
||||
|
||||
{: .warning }
|
||||
> THIS DOCUMENT IS STILL WORK IN PROGRESS!
|
||||
@ -4,6 +4,171 @@ nav_order: 03
|
||||
---
|
||||
|
||||
# Create your own Hello world
|
||||
{: .no_toc }
|
||||
|
||||
{: .warning }
|
||||
> THIS DOCUMENT IS STILL WORK IN PROGRESS!
|
||||
1. Table of contents
|
||||
{:toc}
|
||||
|
||||
This page will lead you step by step through the process of creating a mission
|
||||
with MOOSE. This time we include a simple mission script, which sends only
|
||||
a "Hello world" message to all players. But the steps are the same to add
|
||||
another mission script, which will do whatever class(es) you want to use.
|
||||
|
||||
## Create Mission script
|
||||
|
||||
At first we will create the mission script. It is a simple text file and can be
|
||||
changed with a lot of different tools. Theoretically even the Microsoft Notepad
|
||||
editor can be used. But it lacks a lot of features, which helps you to avoid
|
||||
errors.
|
||||
|
||||
For this guide we suggest you to download, install and use [Notepad++]{:target="_blank"}.
|
||||
|
||||
{: .important }
|
||||
> Windows hides filename extensions by default. So when you create a text file
|
||||
> and name it `hello-world.lua` it's name is `hello-world.lua.txt` in reality.
|
||||
> You must activate the display of the file name extension.
|
||||
> Open a `File Explorer`, switch to menu `View` and find the option
|
||||
> `File name extensions` in the section `Show/hide`. Activate it.
|
||||
|
||||
- Open a File Explorer.
|
||||
- Go to the subfolder `Missions` of your [Saved Games folder]{:target="_blank"}.
|
||||
- Create a new text file and name it `hello-world.lua`.
|
||||
- Add the following content and save the file:
|
||||
|
||||
`MESSAGE:New( "Hello World! This messages is printed by MOOSE", 35, "INFO" ):ToAll()`
|
||||
|
||||
## Get Moose
|
||||
|
||||
To download Moose click on the following link:
|
||||
|
||||
- [Moose_.lua from develop branch]{:target="_blank"}
|
||||
|
||||
Press `Ctrl + S` to save the file on your hard disk next to your mission script.
|
||||
|
||||
## Create the mission
|
||||
|
||||
- Start DCS.
|
||||
- In the main menu choose `MISSION EDITOR`.
|
||||
- Click on `create new mission`.
|
||||
- In the dialog `NEW MISSION SETTINGS`:
|
||||
- Choose map `Caucasus`.
|
||||
- In the drop box upper left choose `Modern` as coalition preset.
|
||||
- Click on `OK`.
|
||||
- The mission editor will load with a fresh new and empty mission.
|
||||
- Click on `File` in the menu bar and `SAVE` or Press `Ctrl + S`.
|
||||
- Open `My Missions` and save the file with the name `hello-world.miz`.
|
||||
|
||||
## Add Moose to the mission
|
||||
|
||||
- On the left side activate `TRIGGERS`:
|
||||
|
||||

|
||||
|
||||
- On the right side the `TRIGGERS` dialog opens with a lot of options.
|
||||
- Click on `NEW`, choose `4 MISSION START` as **TYPE**.
|
||||
- Give it the `Load MOOSE` as **NAME**.
|
||||
- Leave the **EVENT** option set to `NO EVENT`.
|
||||
- Optional: Choose a color for easy recognition (e.g. yellow).
|
||||
|
||||

|
||||
|
||||
- In the middle part the `CONDITIONS` will be shown.
|
||||
For this trigger we do not configure any conditions.
|
||||
|
||||

|
||||
|
||||
{: .important }
|
||||
> The trigger type `4 MISSION START` does not support `CONDITIONS`. <br />
|
||||
> So `CONDITIONS` must left blank when using it. <br />
|
||||
> **If you add a condition the trigger will never be executed!**
|
||||
|
||||

|
||||
|
||||
- On the right side `ACTIONS` is shown.
|
||||
- We need to click on `NEW`.
|
||||
- Choose **ACTION** `Do SCRIPT FILE` and ignore all other actions.
|
||||
- Click **OPEN** and navigate to the downloaded `Moose_.lua` file.
|
||||
- The result should look like this:
|
||||
|
||||

|
||||
|
||||
## Add the mission script
|
||||
|
||||
- Click on `NEW`, choose `1 ONCE` as **TYPE**.
|
||||
- Give it the `Load Mission Script` as **NAME**.
|
||||
- Leave the **EVENT** option set to `NO EVENT`.
|
||||
- Optional: Choose a color for easy recognition (e.g. green).
|
||||
- The result should look like this:
|
||||
|
||||

|
||||
|
||||
- Switch to the middle part, the `CONDITIONS` section. <br />
|
||||
For this trigger we add one condition:
|
||||
|
||||

|
||||
|
||||
- The combination of `1 ONCE` with `TIME MORE(1)` will ensure, that the mission
|
||||
script is executed 1 second after the mission is started.
|
||||
|
||||
- On the right side under `ACTIONS` you need to add the script:
|
||||
- Click on `NEW`.
|
||||
- Choose **ACTION** `Do SCRIPT FILE`.
|
||||
- Click **OPEN** and navigate to the created `hello-world.lua` file.
|
||||
|
||||
{: .important }
|
||||
> Most important is the fact, that the mission script (`hello-world.lua`)
|
||||
> is executed **after** `Moose_.lua`, because the mission script needs the
|
||||
> classes defined in `Moose_.lua`. And they are only available when `Moose_.lua`
|
||||
> is executed before the mission script.
|
||||
|
||||
## Test the mission
|
||||
|
||||
- Save the mission again.
|
||||
- Click on the green **Fly mission** cirlce on the left tool side bar.
|
||||
- It is an empty mission, so skip `BRIEFING` with `START` and then `FLY`.
|
||||
- You spawn as a spectator. After some seconds you will see this message in
|
||||
the upper right corner:
|
||||
|
||||

|
||||
|
||||
This is the same result as already seen in the last chapter, but this time you
|
||||
have create everything on your own.
|
||||
|
||||
{: .note }
|
||||
> You can use this mission as a template for your own missions. So you don't
|
||||
> need to do alle these steps again and again.
|
||||
|
||||
## Update mission script
|
||||
|
||||
- Open the `hello-world.lua` with Notepad++ again.
|
||||
- Change the text a little bit, like `Hello Dude! ...` and save the file.
|
||||
- Run the mission again.
|
||||
- The text will not be changed in the mission. Why?
|
||||
The mission editor copies the script into the mission file when you add it.
|
||||
Ever change on the script file on your hard disk is not recognized by mission editor.
|
||||
You have to add the file after each change again.
|
||||
|
||||
- On the left side of the `TRIGGERS` dialog click on `Load Mission Script`.
|
||||
- On the right side under `ACTIONS` you need to add the script again:
|
||||
- Click **OPEN** and navigate to the created `hello-world.lua` file.
|
||||
- Save the mission and test it again.
|
||||
- Now the new text should be shown.
|
||||
|
||||
## Update Moose
|
||||
|
||||
Moose is constantly being developed so that new functionallity is added or
|
||||
existing errors are corrected. Also from time to time changes of the DCS
|
||||
scripting engine comes with a new DCS version. It may therefore be useful or
|
||||
necessary to update Moose.
|
||||
|
||||
- To update Moose download it again and add it again in the same way you did
|
||||
with the mission script in the last step.
|
||||
|
||||
## Next step
|
||||
|
||||
Let's move on to the [demo missions].
|
||||
|
||||
[Notepad++]: https://notepad-plus-plus.org/downloads/
|
||||
[Saved Games folder]: tipps-and-tricks.md#find-the-saved-games-folder
|
||||
[Moose_.lua from develop branch]: https://raw.githubusercontent.com/FlightControl-Master/MOOSE_INCLUDE/develop/Moose_Include_Static/Moose_.lua
|
||||
[demo missions]: demo-missions.md
|
||||
|
||||
BIN
docs/images/beginner/dcs-triggers-once-conditions-conf.png
Normal file
BIN
docs/images/beginner/dcs-triggers-once-conditions-conf.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Loading…
x
Reference in New Issue
Block a user