diff --git a/Moose Development/Moose/Core/Vector.lua b/Moose Development/Moose/Core/Vector.lua index 3ee2cc1e7..086cfd6c6 100644 --- a/Moose Development/Moose/Core/Vector.lua +++ b/Moose Development/Moose/Core/Vector.lua @@ -133,7 +133,7 @@ VECTOR = { --- VECTOR class version. -- @field #string version -VECTOR.version="0.0.2" +VECTOR.version="0.0.3" --- VECTOR private index. -- @field #VECTOR __index @@ -528,16 +528,25 @@ end --- Get MGRS coordinates of this vector. -- @param #VECTOR self --- @param #VECTOR Vector Vector from which the heading is requested. --- @return #number Latitude --- @return #number Longitude +-- @return #number Easting +-- @return #number Northing function VECTOR:GetMGRS() local lat, long=self:GetLatitudeLongitude() local mrgs=coord.LLtoMGRS(lat, long) + + -- Example table returned by coord.LLtoMGRS + --[[ + MGRS = { + UTMZone = string, + MGRSDigraph = string, + Easting = number, + Northing = number + } + ]] - return mrgs.Easing, mrgs.Northing + return mrgs.Easting, mrgs.Northing end --- Get the difference of the heading of this vector w. @@ -857,7 +866,7 @@ end -- * RUNWAY = 5 -- -- @param #VECTOR self --- @return #number Surface Type +-- @return #number Surface type function VECTOR:GetSurfaceType() local vec2=self:GetVec2() @@ -867,6 +876,32 @@ function VECTOR:GetSurfaceType() return s end + +--- Get the name of surface type at the vector. +-- +-- * LAND = 1 +-- * SHALLOW_WATER = 2 +-- * WATER = 3 +-- * ROAD = 4 +-- * RUNWAY = 5 +-- +-- @param #VECTOR self +-- @return #string Surface type name +function VECTOR:GetSurfaceTypeName() + + local vec2=self:GetVec2() + + local s=land.getSurfaceType(vec2) + + for name,id in land.SurfaceType() do + if id==s then + return name + end + end + + return "unknown" +end + --- Check if a given vector has line of sight with this vector. -- @param #VECTOR self -- @param #VECTOR Vec The other vector. @@ -1052,6 +1087,7 @@ function VECTOR:IlluminationBomb(Power) trigger.action.illuminationBomb(vec3, Power or 1000) + return self end --- Creates an explosion at a given point at the specified power. @@ -1085,14 +1121,28 @@ end --- Creates a arrow from this VECTOR to another vector on the F10 map. -- @param #VECTOR self -- @param #VECTOR Vector The vector defining the endpoint. --- @return #VECTOR self -function VECTOR:ArrowToAll(Vector) +-- @param #number Coalition Coalition Id: -1=All, 0=Neutral, 1=Red, 2=Blue. Default -1. +-- @param #table Color RGB color with alpha {r, g, b, alpha}. Default {1, 0, 0, 0.7}. +-- @param #table FillColor RGB color with alpha {r, g, b, alpha}. Default {1, 0, 0, 0.5}. +-- @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. +-- @return #number Marker ID. Can be used to remove the drawing. +function VECTOR:ArrowToAll(Vector, Coalition, Color, FillColor, LineType) local vec3Start=self:GetVec3() + local vec3End=Vector:GetVec3() - trigger.action.arrowToAll(coalition , id, vec3Start, vec3End, color, fillColor , lineType, readOnly, "") + local id=UTILS.GetMarkID() + + Coalition=Coalition or -1 + Color=Color or {1,0,0,0.7} + FillColor=FillColor or {1,0,0,0.5} + LineType=LineType or 1 + + local readOnly=false + + trigger.action.arrowToAll(Coalition , id, vec3Start, vec3End, Color, FillColor , LineType, readOnly, "") - return self + return id end ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Globals.lua b/Moose Development/Moose/Globals.lua index 771547060..5108254d1 100644 --- a/Moose Development/Moose/Globals.lua +++ b/Moose Development/Moose/Globals.lua @@ -20,6 +20,13 @@ _DATABASE:_RegisterCargos() _DATABASE:_RegisterZones() _DATABASE:_RegisterAirbases() +--- Function that writes to DCS log file +-- @param #string text Formatted text. +-- @param ... Format passed to string.format(). +function printf(text, ...) + env.info(string.format(text, ...)) +end + --- Check if os etc is available. BASE:I("Checking de-sanitization of os, io and lfs:") local __na = false diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 1c38db672..37b120863 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -1152,6 +1152,23 @@ function GROUP:GetVec3() return nil end +--- Returns the current {@Core.Vector#VECTOR} of the first Unit in the GROUP. +-- @param #GROUP self +-- @return Core.Vector#VECTOR Vector of the first Unit of the GROUP or nil if cannot be found. +function GROUP:GetVector() + + -- Get first unit. + local unit=self:GetUnit(1) + + if unit then + local vector=unit:GetVector() + return vector + end + + self:E("ERROR: Cannot get Vector of group "..tostring(self.GroupName)) + return nil +end + --- Returns the average Vec3 vector of the Units in the GROUP. -- @param #GROUP self -- @return DCS#Vec3 Current Vec3 of the GROUP or nil if cannot be found. diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index 038eefe56..13008b613 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -286,6 +286,27 @@ function POSITIONABLE:GetVec2() return nil end +--- Returns the @{Core.Vector#VECTOR} indicating the 3D position of the object on the map. +-- @param #POSITIONABLE self +-- @return Core.Vector#VECTOR The 3D vector. +function POSITIONABLE:GetVector() + + local DCSPositionable = self:GetDCSObject() + + if DCSPositionable then + + local Vec3 = DCSPositionable:getPoint() -- DCS#Vec3 + + local vector=VECTOR:NewFromVec(Vec3) + + return vector + end + + self:E( { "Cannot GetVec2", Positionable = self, Alive = self:IsAlive() } ) + + return nil +end + --- Returns a COORDINATE object indicating the point in 2D of the POSITIONABLE within the mission. -- @param #POSITIONABLE self -- @return Core.Point#COORDINATE The 3D point vector of the POSITIONABLE.