From 2157f8e8cd161577e33fa33829cb7927324b1d1a Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 26 Sep 2022 23:34:00 +0200 Subject: [PATCH 1/5] Airboss Take animation for determining the wire --- .gitignore | 1 + Moose Development/Moose/.vscode/settings.json | 12 ++++++-- Moose Development/Moose/Ops/Airboss.lua | 30 ++++++++++++++++--- Moose Development/Moose/Wrapper/Unit.lua | 18 +++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index fe5b6b4f8..634be4279 100644 --- a/.gitignore +++ b/.gitignore @@ -228,3 +228,4 @@ MooseCodeWS.code-workspace .gitignore .gitignore /.gitignore +Moose Development/Moose/.vscode/settings.json diff --git a/Moose Development/Moose/.vscode/settings.json b/Moose Development/Moose/.vscode/settings.json index 13211d027..f25704250 100644 --- a/Moose Development/Moose/.vscode/settings.json +++ b/Moose Development/Moose/.vscode/settings.json @@ -1,7 +1,8 @@ { "Lua.workspace.preloadFileSize": 1000, "Lua.diagnostics.disable": [ - "undefined-doc-name" + "undefined-doc-name", + "need-check-nil" ], "Lua.diagnostics.globals": [ "BASE", @@ -9,9 +10,14 @@ "__Moose", "trigger", "coord", - "missionCommands" + "missionCommands", + "world" ], "Lua.completion.displayContext": 5, "Lua.runtime.version": "Lua 5.1", - "Lua.completion.callSnippet": "Both" + "Lua.completion.callSnippet": "Both", + "Lua.workspace.library": [ + "${3rd}/lfs/library" + ], + "Lua.workspace.checkThirdParty": false } \ No newline at end of file diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index 1bd4c98da..85ec855b7 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1809,7 +1809,7 @@ AIRBOSS.version = "1.2.1" function AIRBOSS:New( carriername, alias ) -- Inherit everthing from FSM class. - local self = BASE:Inherit( self, FSM:New() ) -- #AIRBOSS + self = BASE:Inherit( self, FSM:New() ) -- #AIRBOSS -- Debug. self:F2( { carriername = carriername, alias = alias } ) @@ -8222,7 +8222,7 @@ function AIRBOSS:OnEventLand( EventData ) local dist = coord:Get2DDistance( self:GetCoordinate() ) -- Get wire - local wire = self:_GetWire( coord, 0 ) + local wire = self:_GetWirePos( coord, 0 ) -- Aircraft type. local _type = EventData.IniUnit:GetTypeName() @@ -10058,12 +10058,34 @@ function AIRBOSS:_GetSternCoord() return self.sterncoord end +--- Get wire from +-- @param #AIRBOSS self +-- @param Core.Point#COORDINATE Lcoord Landing position. +-- @return #number Trapped wire (1-4) or 99 if no wire was trapped. +function AIRBOSS:_GetWire() + + local wireArgs={} + wireArgs[1]=141 + wireArgs[2]=142 + wireArgs[3]=143 + wireArgs[4]=144 + + for wire,drawArg in pairs(wireArgs) do + local value=self.carrier:GetDrawArgumentValue(drawArg) + if math.abs(value)>0.001 then + return wire + end + end + + return 99 +end + --- Get wire from landing position. -- @param #AIRBOSS self -- @param Core.Point#COORDINATE Lcoord Landing position. -- @param #number dc Distance correction. Shift the landing coord back if dc>0 and forward if dc<0. -- @return #number Trapped wire (1-4) or 99 if no wire was trapped. -function AIRBOSS:_GetWire( Lcoord, dc ) +function AIRBOSS:_GetWirePos( Lcoord, dc ) -- Final bearing (true). local FB = self:GetFinalBearing() @@ -10181,7 +10203,7 @@ function AIRBOSS:_Trapped( playerData ) end -- Get wire. - local wire = self:_GetWire( coord, dcorr ) + local wire = self:_GetWirePos( coord, dcorr ) -- Debug. local text = string.format( "Player %s _Trapped: v=%.1f km/h, s-dcorr=%.1f m ==> wire=%d (dcorr=%d)", playerData.name, v, s - dcorr, wire, dcorr ) diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 6195f03e5..06617bafb 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -963,6 +963,24 @@ function UNIT:GetDamageRelative() return 1 end +--- Returns the current value for an animation argument on the external model of the given object. +-- Each model animation has an id tied to with different values representing different states of the model. +-- Animation arguments can be figured out by opening the respective 3d model in the modelviewer. +-- @param #UNIT self +-- @param #number AnimationArgument Number corresponding to the animated part of the unit. +-- @return #number Value of the animation argument [-1, 1]. If draw argument value is invalid for the unit in question a value of 0 will be returned. +function UNIT:GetDrawArgumentValue(AnimationArgument) + + local DCSUnit = self:GetDCSObject() + + if DCSUnit then + local value = DCSUnit:getDrawArgumentValue(AnimationArgument or 0) + return value + end + + return 0 +end + --- Returns the category of the #UNIT from descriptor. Returns one of -- -- * Unit.Category.AIRPLANE From 819912cfd3e5a7ed58e904811f4b6ffbf929ca8c Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 28 Jan 2023 15:39:42 +0100 Subject: [PATCH 2/5] Database - Polygon drawings are adde as polygon zones to DB --- Moose Development/Moose/Core/Database.lua | 63 ++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index afa1d6a64..2bd712f72 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -370,11 +370,70 @@ do -- Zones -- Add zone to DB. self:AddZone( ZoneName, Zone_Polygon ) end + end + + -- Drawings as zones + if env.mission.drawings and env.mission.drawings.layers then + + -- Loop over layers. + for layerID, layerData in pairs(env.mission.drawings.layers or {}) do + + -- Loop over objects in layers. + for objectID, objectData in pairs(layerData.objects or {}) do + + -- Check for polygon which has at least 4 points (we would need 3 but the origin seems to be there twice) + if objectData.polygonMode=="free" and objectData.points and #objectData.points>=4 then + + -- Name of the zone. + local ZoneName=objectData.name or "Unknown Drawing" + + -- Reference point. All other points need to be translated by this. + local vec2={x=objectData.mapX, y=objectData.mapY} + + -- Debug stuff. + --local vec3={x=objectData.mapX, y=0, z=objectData.mapY} + --local coord=COORDINATE:NewFromVec2(vec2):MarkToAll("MapX, MapY") + --trigger.action.markToAll(id, "mapXY", vec3) + -- Copy points array. + local points=UTILS.DeepCopy(objectData.points) + + -- Translate points. + for i,_point in pairs(points) do + local point=_point --DCS#Vec2 + points[i]=UTILS.Vec2Add(point, vec2) + end + + -- Remove last point. + table.remove(points, #points) + + -- Debug output + self:I(string.format("Register ZONE: %s (Polygon drawing with %d verticies)", ZoneName, #points)) + + -- Create new polygon zone. + local Zone=ZONE_POLYGON:NewFromPointsArray(ZoneName, points) + + -- Set color. + Zone:SetColor({1, 0, 0}, 0.15) + + -- Store in DB. + self.ZONENAMES[ZoneName] = ZoneName + + -- Add zone. + self:AddZone(ZoneName, Zone) + + end + + end + + end + + end + + end - - + end -- zone do -- Zone_Goal From 6adef473400b85ecf0ffa7f84e9da8a5b495c075 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 7 Feb 2023 22:47:55 +0100 Subject: [PATCH 3/5] PATHLINE Added new class PATHLINE --- Moose Development/Moose/Core/Database.lua | 75 +++++++++- Moose Development/Moose/Core/Pathline.lua | 163 ++++++++++++++++++++++ Moose Development/Moose/Modules.lua | 1 + Moose Setup/Moose.files | 1 + 4 files changed, 234 insertions(+), 6 deletions(-) create mode 100644 Moose Development/Moose/Core/Pathline.lua diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 2bd712f72..8cfad8cd2 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -88,6 +88,7 @@ DATABASE = { WAREHOUSES = {}, FLIGHTGROUPS = {}, FLIGHTCONTROLS = {}, + PATHLINES = {}, } local _DATABASECoalition = @@ -244,7 +245,7 @@ function DATABASE:FindAirbase( AirbaseName ) end -do -- Zones +do -- Zones and Pathlines --- Finds a @{Core.Zone} based on the zone name. -- @param #DATABASE self @@ -266,8 +267,7 @@ do -- Zones self.ZONES[ZoneName] = Zone end end - - + --- Deletes a @{Core.Zone} from the DATABASE based on the zone name. -- @param #DATABASE self -- @param #string ZoneName The name of the zone. @@ -277,6 +277,39 @@ do -- Zones end + --- Adds a @{Core.Pathline} based on its name in the DATABASE. + -- @param #DATABASE self + -- @param #string PathlineName The name of the pathline + -- @param Core.Pathline#PATHLINE Pathline The pathline. + function DATABASE:AddPathline( PathlineName, Pathline ) + + if not self.PATHLINES[PathlineName] then + self.PATHLINES[PathlineName]=Pathline + end + end + + --- Finds a @{Core.Pathline} by its name. + -- @param #DATABASE self + -- @param #string PathlineName The name of the Pathline. + -- @return Core.Pathline#PATHLINE The found PATHLINE. + function DATABASE:FindPathline( PathlineName ) + + local pathline = self.PATHLINES[PathlineName] + + return pathline + end + + + --- Deletes a @{Core.Pathline} from the DATABASE based on its name. + -- @param #DATABASE self + -- @param #string PathlineName The name of the PATHLINE. + function DATABASE:DeletePathline( PathlineName ) + + self.PATHLINES[PathlineName]=nil + + return self + end + --- Private method that registers new ZONE_BASE derived objects within the DATABASE Object. -- @param #DATABASE self -- @return #DATABASE self @@ -383,7 +416,7 @@ do -- Zones for objectID, objectData in pairs(layerData.objects or {}) do -- Check for polygon which has at least 4 points (we would need 3 but the origin seems to be there twice) - if objectData.polygonMode=="free" and objectData.points and #objectData.points>=4 then + if objectData.polygonMode and objectData.polygonMode=="free" and objectData.points and #objectData.points>=4 then -- Name of the zone. local ZoneName=objectData.name or "Unknown Drawing" @@ -409,7 +442,7 @@ do -- Zones table.remove(points, #points) -- Debug output - self:I(string.format("Register ZONE: %s (Polygon drawing with %d verticies)", ZoneName, #points)) + self:I(string.format("Register ZONE: %s (Polygon drawing with %d vertices)", ZoneName, #points)) -- Create new polygon zone. local Zone=ZONE_POLYGON:NewFromPointsArray(ZoneName, points) @@ -421,8 +454,38 @@ do -- Zones self.ZONENAMES[ZoneName] = ZoneName -- Add zone. - self:AddZone(ZoneName, Zone) + self:AddZone(ZoneName, Zone) + elseif objectData.lineMode and objectData.lineMode=="segments" and objectData.points and #objectData.points>=2 then + + -- Name of the zone. + local Name=objectData.name or "Unknown Line Drawing" + + -- Reference point. All other points need to be translated by this. + local vec2={x=objectData.mapX, y=objectData.mapY} + + -- Copy points array. + local points=UTILS.DeepCopy(objectData.points) + + -- Translate points. + for i,_point in pairs(points) do + local point=_point --DCS#Vec2 + points[i]=UTILS.Vec2Add(point, vec2) + end + + + -- Debug output + self:I(string.format("Register PATHLINE: %s (Line drawing with %d points)", Name, #points)) + + -- Create new polygon zone. + local Pathline=PATHLINE:NewFromVec2Array(Name, points) + + -- Set color. + --Zone:SetColor({1, 0, 0}, 0.15) + + -- Add zone. + self:AddPathline(Name,Pathline) + end end diff --git a/Moose Development/Moose/Core/Pathline.lua b/Moose Development/Moose/Core/Pathline.lua new file mode 100644 index 000000000..058933107 --- /dev/null +++ b/Moose Development/Moose/Core/Pathline.lua @@ -0,0 +1,163 @@ +--- **Core** - Path from A to B. +-- +-- **Main Features:** +-- +-- * Path from A to B +-- * Arbitrary number of segments +-- * Automatically from lines drawtool +-- +-- === +-- +-- ### Author: **funkyfranky** +-- +-- === +-- @module Core.Pathline +-- @image CORE_Pathline.png + + +--- PATHLINE class. +-- @type PATHLINE +-- @field #string ClassName Name of the class. +-- @field #string lid Class id string for output to DCS log file. +-- @field #string name Name of the path line. +-- @field #table points List of 3D points defining the path. +-- @extends Core.Base#BASE + +--- *When nothing goes right... Go left!* +-- +-- === +-- +-- # The PATHLINE Concept +-- +-- List of points defining a path from A to B. +-- +-- Line drawings created in the mission editor are automatically registered as pathlines and stored in the MOOSE database. +-- They can be accessed with the @{#PATHLINE.FindByName) function. +-- +-- +-- @field #PATHLINE +PATHLINE = { + ClassName = "PATHLINE", + lid = nil, + points = {}, +} + + +--- PATHLINE class version. +-- @field #string version +PATHLINE.version="0.0.1" + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- TODO list +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +-- TODO: A lot... + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Constructor +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Create a new PATHLINE object. Points need to be added later. +-- @param #PATHLINE self +-- @param #string Name Name of the path. +-- @return #PATHLINE self +function PATHLINE:New(Name) + + -- Inherit everything from INTEL class. + local self=BASE:Inherit(self, BASE:New()) --#PATHLINE + + self.name=Name or "Unknown Path" + + self.lid=string.format("PATHLINE %s | ", Name) + + return self +end + +--- Create a new PATHLINE object from a given list of 2D points. +-- @param #PATHLINE self +-- @param #string Name Name of the pathline. +-- @param #table Vec2Array List of DCS#Vec2 points. +-- @return #PATHLINE self +function PATHLINE:NewFromVec2Array(Name, Vec2Array) + + local self=PATHLINE:New(Name) + + for i=1,#Vec2Array do + self:AddPointFromVec2(Vec2Array[i]) + end + + return self +end + +--- Create a new PATHLINE object from a given list of 3D points. +-- @param #PATHLINE self +-- @param #string Name Name of the pathline. +-- @param #table Vec3Array List of DCS#Vec3 points. +-- @return #PATHLINE self +function PATHLINE:NewFromVec3Array(Name, Vec3Array) + + local self=PATHLINE:New(Name) + + for i=1,#Vec3Array do + self:AddPointFromVec3(Vec3Array[i]) + end + + return self +end + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- User functions +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Find a pathline in the database. +-- @param #PATHLINE self +-- @param #string Name The name of the pathline. +-- @return #PATHLINE self +function PATHLINE:FindByName(Name) + local pathline = _DATABASE:FindPathline(Name) + return pathline +end + +--- Add a 2D point to the path. The third dimension is determined from the land height. +-- @param #PATHLINE self +-- @param DCS#Vec2 Vec2 The 2D vector (x,y) to add. +-- @return #PATHLINE self +function PATHLINE:AddPointFromVec2(Vec2) + + if Vec2 then + + local Vec3={x=Vec2.x, y=land.getHeight(Vec2), z=Vec2.y} + + self:AddPointFromVec3(Vec3) + + end + + return self +end + +--- Add a 3D point to the path. +-- @param #PATHLINE self +-- @param DCS#Vec3 Vec3 The §D vector (x,y) to add. +-- @return #PATHLINE self +function PATHLINE:AddPointFromVec3(Vec3) + + if Vec3 then + + table.insert(self.points, Vec3) + + end + + return self +end + +--- Get 3D points of pathline. +-- @param #PATHLINE self +-- @return List of DCS#Vec3 points. +function PATHLINE:GetPoints3D() + return self.points +end + + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/Moose Development/Moose/Modules.lua b/Moose Development/Moose/Modules.lua index c0ed4dd90..eda4bd2b2 100644 --- a/Moose Development/Moose/Modules.lua +++ b/Moose Development/Moose/Modules.lua @@ -33,6 +33,7 @@ __Moose.Include( 'Scripts/Moose/Core/Goal.lua' ) __Moose.Include( 'Scripts/Moose/Core/Spot.lua' ) __Moose.Include( 'Scripts/Moose/Core/MarkerOps_Base.lua' ) __Moose.Include( 'Scripts/Moose/Core/TextAndSound.lua' ) +__Moose.Include( 'Scripts/Moose/Core/Pathline.lua' ) __Moose.Include( 'Scripts/Moose/Wrapper/Object.lua' ) __Moose.Include( 'Scripts/Moose/Wrapper/Identifiable.lua' ) diff --git a/Moose Setup/Moose.files b/Moose Setup/Moose.files index 9531ed658..dbc0c37e1 100644 --- a/Moose Setup/Moose.files +++ b/Moose Setup/Moose.files @@ -34,6 +34,7 @@ Core/MarkerOps_Base.lua Core/Astar.lua Core/Condition.lua Core/TextAndSound.lua +Core/Pathline.lua Wrapper/Object.lua Wrapper/Identifiable.lua From f02b7036a95d39cda901affed624d1768948c16e Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 8 Feb 2023 12:37:18 +0100 Subject: [PATCH 4/5] PATHLINE --- Moose Development/Moose/Core/Database.lua | 2 +- Moose Development/Moose/Core/Pathline.lua | 176 ++++++++++++++++++++-- Moose Development/Moose/DCS.lua | 28 ++-- 3 files changed, 186 insertions(+), 20 deletions(-) diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 8cfad8cd2..a95504bb1 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -456,7 +456,7 @@ do -- Zones and Pathlines -- Add zone. self:AddZone(ZoneName, Zone) - elseif objectData.lineMode and objectData.lineMode=="segments" and objectData.points and #objectData.points>=2 then + elseif objectData.lineMode and (objectData.lineMode=="segments" or objectData.lineMode=="segment" or objectData.lineMode=="free") and objectData.points and #objectData.points>=2 then -- Name of the zone. local Name=objectData.name or "Unknown Line Drawing" diff --git a/Moose Development/Moose/Core/Pathline.lua b/Moose Development/Moose/Core/Pathline.lua index 058933107..5364bc505 100644 --- a/Moose Development/Moose/Core/Pathline.lua +++ b/Moose Development/Moose/Core/Pathline.lua @@ -42,6 +42,15 @@ PATHLINE = { points = {}, } +--- Point of line. +-- @type PATHLINE.Point +-- @field DCS#Vec3 vec3 3D position. +-- @field DCS#Vec2 vec2 2D position. +-- @field #number surfaceType Surface type. +-- @field #number landHeight Land height in meters. +-- @field #number depth Water depth in meters. +-- @field #number markerID Marker ID. + --- PATHLINE class version. -- @field #string version @@ -118,43 +127,192 @@ function PATHLINE:FindByName(Name) return pathline end ---- Add a 2D point to the path. The third dimension is determined from the land height. + + +--- Add a point to the path from a given 2D position. The third dimension is determined from the land height. -- @param #PATHLINE self -- @param DCS#Vec2 Vec2 The 2D vector (x,y) to add. -- @return #PATHLINE self function PATHLINE:AddPointFromVec2(Vec2) if Vec2 then - - local Vec3={x=Vec2.x, y=land.getHeight(Vec2), z=Vec2.y} - self:AddPointFromVec3(Vec3) + local point=self:_CreatePoint(Vec2) + + table.insert(self.points, point) end return self end ---- Add a 3D point to the path. +--- Add a point to the path from a given 3D position. -- @param #PATHLINE self --- @param DCS#Vec3 Vec3 The §D vector (x,y) to add. +-- @param DCS#Vec3 Vec3 The 3D vector (x,y) to add. -- @return #PATHLINE self function PATHLINE:AddPointFromVec3(Vec3) if Vec3 then + + local point=self:_CreatePoint(Vec3) - table.insert(self.points, Vec3) + table.insert(self.points, point) end return self end +--- Get name of pathline. +-- @param #PATHLINE self +-- @return #string Name of the pathline. +function PATHLINE:GetName() + return self.name +end + +--- Get number of points. +-- @param #PATHLINE self +-- @return #number Number of points. +function PATHLINE:GetNumberOfPoints() + local N=#self.points + return N +end + +--- Get points of pathline. Not that points are tables, that contain more information as just the 2D or 3D position but also the surface type etc. +-- @param #PATHLINE self +-- @return <#PATHLINE.Point> List of points. +function PATHLINE:GetPoints() + return self.points +end + --- Get 3D points of pathline. -- @param #PATHLINE self -- @return List of DCS#Vec3 points. -function PATHLINE:GetPoints3D() - return self.points +function PATHLINE:GetPoints3D() + + local vecs={} + + for _,_point in pairs(self.points) do + local point=_point --#PATHLINE.Point + table.insert(vecs, point.vec3) + end + + return vecs +end + +--- Get 2D points of pathline. +-- @param #PATHLINE self +-- @return List of DCS#Vec2 points. +function PATHLINE:GetPoints2D() + + local vecs={} + + for _,_point in pairs(self.points) do + local point=_point --#PATHLINE.Point + table.insert(vecs, point.vec2) + end + + return vecs +end + +--- Get COORDINATES of pathline. Note that COORDINATE objects are created when calling this function. That does involve deep copy calls and can have an impact on performance if done too often. +-- @param #PATHLINE self +-- @return List of COORDINATES points. +function PATHLINE:GetCoordinats() + + local vecs={} + + for _,_point in pairs(self.points) do + local point=_point --#PATHLINE.Point + local coord=COORDINATE:NewFromVec3(point.vec3) + end + + return vecs +end + +--- Get the n-th point. +-- @param #PATHLINE self +-- @param #number n The n-th point. +-- @return #number Number of points. +function PATHLINE:GetPoint3D(n) + + local N=self:GetNumberOfPoints() + + local vec3=nil + if n and n>=1 and n<=N then + + vec3=self.point[n] + else + self:E(self.lid..string.format("ERROR: No point in pathline for N=%s", tostring(n))) + end + + return vec3 +end + + + + +--- Mark points on F10 map. +-- @param #PATHLINE self +-- @param #boolean Switch If `true` or nil, set marks. If `false`, remove marks. +-- @return List of DCS#Vec3 points. +function PATHLINE:MarkPoints(Switch) + for i,_point in pairs(self.points) do + local point=_point --#PATHLINE.Point + if Switch==false then + + if point.markerID then + UTILS.RemoveMark(point.markerID, Delay) + end + + else + + if point.markerID then + UTILS.RemoveMark(point.markerID) + end + + point.markerID=UTILS.GetMarkID() + + local text=string.format("Pathline %s: Point #%d\nSurface Type=%d\nHeight=%.1f m\nDepth=%.1f m", self.name, i, point.surfaceType, point.landHeight, point.depth) + + trigger.action.markToAll(point.markerID, text, point.vec3, "") + + end + end +end + + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Private functions +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + +--- Get 3D points of pathline. +-- @param #PATHLINE self +-- @param DCS#Vec3 Vec Position vector. Can also be a DCS#Vec2 in which case the altitude at landheight is taken. +-- @return #PATHLINE.Point +function PATHLINE:_CreatePoint(Vec) + + local point={} --#PATHLINE.Point + + if Vec.z then + -- Given vec is 3D + point.vec3=UTILS.DeepCopy(Vec) + point.vec2={x=Vec.x, y=Vec.z} + else + -- Given vec is 2D + point.vec2=UTILS.DeepCopy(Vec) + point.vec3={x=Vec.x, y=land.getHeight(Vec), z=Vec.y} + end + + -- Get surface type. + point.surfaceType=land.getSurfaceType(point.vec2) + + -- Get land height and depth. + point.landHeight, point.depth=land.getSurfaceHeightWithSeabed(point.vec2) + + point.markerID=nil + + return point end diff --git a/Moose Development/Moose/DCS.lua b/Moose Development/Moose/DCS.lua index 4db719cdb..602d9a608 100644 --- a/Moose Development/Moose/DCS.lua +++ b/Moose Development/Moose/DCS.lua @@ -193,21 +193,29 @@ do -- land --- [Type of surface enumerator](https://wiki.hoggitworld.com/view/DCS_singleton_land) -- @type land.SurfaceType - -- @field LAND - -- @field SHALLOW_WATER - -- @field WATER - -- @field ROAD - -- @field RUNWAY + -- @field LAND Land=1 + -- @field SHALLOW_WATER Shallow water=2 + -- @field WATER Water=3 + -- @field ROAD Road=4 + -- @field RUNWAY Runway=5 - --- Returns altitude MSL of the point. + --- Returns the distance from sea level (y-axis) of a given vec2 point. -- @function [parent=#land] getHeight - -- @param #Vec2 point point on the ground. - -- @return #Distance + -- @param #Vec2 point Point on the ground. + -- @return #number Height in meters. + + --- Returns the surface height and depth of a point. Useful for checking if the path is deep enough to support a given ship. + -- Both values are positive. When checked over water at sea level the first value is always zero. + -- When checked over water at altitude, for example the reservoir of the Inguri Dam, the first value is the corresponding altitude the water level is at. + -- @function [parent=#land] getSurfaceHeightWithSeabed + -- @param #Vec2 point Position where to check. + -- @return #number Height in meters. + -- @return #number Depth in meters. - --- returns surface type at the given point. + --- Returns surface type at the given point. -- @function [parent=#land] getSurfaceType -- @param #Vec2 point Point on the land. - -- @return #land.SurfaceType + -- @return #number Enumerator value from `land.SurfaceType` (LAND=1, SHALLOW_WATER=2, WATER=3, ROAD=4, RUNWAY=5) --- [DCS Singleton land](https://wiki.hoggitworld.com/view/DCS_singleton_land) land = {} --#land From e4c8ca34edfd0ac08a9f2d000324db16e49a0189 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 8 Feb 2023 16:11:47 +0100 Subject: [PATCH 5/5] Update Pathline.lua --- Moose Development/Moose/Core/Pathline.lua | 52 ++++++++++++++++++----- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/Moose Development/Moose/Core/Pathline.lua b/Moose Development/Moose/Core/Pathline.lua index 5364bc505..090da3931 100644 --- a/Moose Development/Moose/Core/Pathline.lua +++ b/Moose Development/Moose/Core/Pathline.lua @@ -3,7 +3,7 @@ -- **Main Features:** -- -- * Path from A to B --- * Arbitrary number of segments +-- * Arbitrary number of points -- * Automatically from lines drawtool -- -- === @@ -230,26 +230,56 @@ function PATHLINE:GetCoordinats() return vecs end ---- Get the n-th point. +--- Get the n-th point of the pathline. -- @param #PATHLINE self --- @param #number n The n-th point. --- @return #number Number of points. -function PATHLINE:GetPoint3D(n) +-- @param #number n The index of the point. Default is the first point. +-- @return #PATHLINE.Point Point. +function PATHLINE:GetPointFromIndex(n) local N=self:GetNumberOfPoints() + + n=n or 1 - local vec3=nil - if n and n>=1 and n<=N then - - vec3=self.point[n] + local point=nil --#PATHLINE.Point + + if n>=1 and n<=N then + point=self.point[n] else self:E(self.lid..string.format("ERROR: No point in pathline for N=%s", tostring(n))) end - - return vec3 + + return point end +--- Get the 3D position of the n-th point. +-- @param #PATHLINE self +-- @param #number n The n-th point. +-- @return DCS#VEC3 Position in 3D. +function PATHLINE:GetPoint3DFromIndex(n) + local point=self:GetPointFromIndex(n) + + if point then + return point.vec3 + end + + return nil +end + +--- Get the 2D position of the n-th point. +-- @param #PATHLINE self +-- @param #number n The n-th point. +-- @return DCS#VEC2 Position in 3D. +function PATHLINE:GetPoint2DFromIndex(n) + + local point=self:GetPointFromIndex(n) + + if point then + return point.vec2 + end + + return nil +end --- Mark points on F10 map.