General documentation and code fixes (#1650)

Documentation updates for correctness and clarity.
General code formatting updates.
Ajustment to POSITIONABLE:GetCoord to make use of existing POINT:UpdateFromVec3.
Added comments about clarifying the difference between POSITIONABLE:GetCoordinate() and POSITIONABLE:GetCoord() and to perhaps consider a renaming or merging the functions with an optional flag.
This commit is contained in:
TommyC81 2021-12-04 21:50:05 +04:00 committed by GitHub
parent b0818977cf
commit 6360b8c58f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 408 additions and 417 deletions

View File

@ -347,7 +347,6 @@ do -- COORDINATE
return self
end
--- Returns the coordinate from the latitude and longitude given in decimal degrees.
-- @param #COORDINATE self
-- @param #number latitude Latitude in decimal degrees.
@ -372,7 +371,6 @@ do -- COORDINATE
return _coord
end
--- Returns if the 2 coordinates are at the same 2D position.
-- @param #COORDINATE self
-- @param #COORDINATE Coordinate
@ -551,7 +549,7 @@ do -- COORDINATE
-- @param DCS#Distance Distance The Distance to be added in meters.
-- @param DCS#Angle Angle The Angle in degrees. Defaults to 0 if not specified (nil).
-- @param #boolean Keepalt If true, keep altitude of original coordinate. Default is that the new coordinate is created at the translated land height.
-- @param #boolean Overwrite If true, overwrite the original COORDINATE with the translated one. Otherwise, create a new COODINATE.
-- @param #boolean Overwrite If true, overwrite the original COORDINATE with the translated one. Otherwise, create a new COORDINATE.
-- @return #COORDINATE The new calculated COORDINATE.
function COORDINATE:Translate( Distance, Angle, Keepalt, Overwrite )
@ -3004,7 +3002,6 @@ do -- POINT_VEC3
return self
end
--- Create a new POINT_VEC3 object from Vec3 coordinates.
-- @param #POINT_VEC3 self
-- @param DCS#Vec3 Vec3 The Vec3 point.
@ -3017,8 +3014,6 @@ do -- POINT_VEC3
return self
end
--- Return the x coordinate of the POINT_VEC3.
-- @param #POINT_VEC3 self
-- @return #number The x coodinate.

View File

@ -152,7 +152,7 @@
--
-- * The first parameter *targetnames* defines the target or targets. This can be a single item or a Table with the name(s) of @{Wrapper.Unit} or @{Static} objects defined in the mission editor.
-- * The (optional) parameter *goodhitrange* specifies the radius in metres around the target within which a bomb/rocket hit is considered to be "good".
-- * If final (optional) parameter "*randommove*" can be enabled to create moving targets. If this parameter is set to true, the units of this bombing target will randomly move within the range zone.
-- * If final (optional) parameter *randommove* can be enabled to create moving targets. If this parameter is set to true, the units of this bombing target will randomly move within the range zone.
-- Note that there might be quirks since DCS units can get stuck in buildings etc. So it might be safer to manually define a route for the units in the mission editor if moving targets are desired.
--
-- ## Adding Groups
@ -903,10 +903,10 @@ end
--- Set player setting whether bomb impact points are smoked or not.
-- @param #RANGE self
-- @param #boolean switch If true nor nil default is to smoke impact points of bombs.
-- @param #boolean switch (Optional) If true, impact points of bombs will be smoked. Default is true.
-- @return #RANGE self
function RANGE:SetDefaultPlayerSmokeBomb(switch)
if switch==true or switch==nil then
if switch == nil or switch == true then
self.defaultsmokebomb=true
else
self.defaultsmokebomb=false
@ -1249,7 +1249,7 @@ end
-- @param #number boxlength (Optional) Length of the approach box in meters. Default is 3000 m.
-- @param #number boxwidth (Optional) Width of the approach box in meters. Default is 300 m.
-- @param #number heading (Optional) Approach heading in Degrees. Default is heading of the unit as defined in the mission editor.
-- @param #boolean inverseheading (Optional) Take inverse heading (heading --> heading - 180 Degrees). Default is false.
-- @param #boolean inverseheading (Optional) Use inverse heading (heading --> heading - 180 Degrees). Default is false.
-- @param #number goodpass (Optional) Number of hits for a "good" strafing pass. Default is 20.
-- @param #number foulline (Optional) Foul line distance. Hits from closer than this distance are not counted. Default 610 m = 2000 ft. Set to 0 for no foul line.
-- @return #RANGE self
@ -1284,8 +1284,8 @@ end
--- Add bombing target(s) to range.
-- @param #RANGE self
-- @param #table targetnames Single or multiple (Table) names of unit or static objects serving as bomb targets.
-- @param #number goodhitrange (Optional) Max distance from target unit (in meters) which is considered as a good hit. Default is 25 m.
-- @param #boolean randommove If true, unit will move randomly within the range. Default is false.
-- @param #number goodhitrange (Optional) Max hit distance from target unit in meters which is considered as a good hit. Default is 25 m.
-- @param #boolean randommove (Optional) If true, unit will move randomly within the range. Default is false.
-- @return #RANGE self
function RANGE:AddBombingTargets(targetnames, goodhitrange, randommove)
self:F({targetnames=targetnames, goodhitrange=goodhitrange, randommove=randommove})
@ -1323,8 +1323,8 @@ end
--- Add a unit or static object as bombing target.
-- @param #RANGE self
-- @param Wrapper.Positionable#POSITIONABLE unit Positionable (unit or static) of the strafe target.
-- @param #number goodhitrange Max distance from unit which is considered as a good hit.
-- @param #boolean randommove If true, unit will move randomly within the range. Default is false.
-- @param #number goodhitrange (Optional) Max hit distance from target unit in meters which is considered as a good hit. Default is 25 m.
-- @param #boolean randommove (Optional) If true, unit will move randomly within the range. Default is false.
-- @return #RANGE self
function RANGE:AddBombingTargetUnit(unit, goodhitrange, randommove)
self:F({unit=unit, goodhitrange=goodhitrange, randommove=randommove})
@ -1377,12 +1377,23 @@ function RANGE:AddBombingTargetUnit(unit, goodhitrange, randommove)
return self
end
--- Add a coordinate of a bombing target. This
--- Add a coordinate of a bombing target.
-- @param #RANGE self
-- @param Core.Point#COORDINATE coord The coordinate.
-- @param #string name Name of target.
-- @param #number goodhitrange Max distance from unit which is considered as a good hit.
-- @param #string name (Optional) Name of target. Default is "Bomb Target".
-- @param #number goodhitrange (Optional) Max hit distance from target unit in meters which is considered as a good hit. Default is 25 m.
-- @return #RANGE self
-- @usage
--
-- -- Setup a Range
-- RangeOne = RANGE:New( "Range One" )
-- -- Find the STATIC target object as setup in the ME
-- RangeOneBombTarget = STATIC:FindByName( "RangeOneBombTarget" ):
-- -- Add the coordinate of the STATIC target object as a bomb target (thus keeping the bomb function active, even if the STATIC target is destroyed)
-- RangeOne:AddBombingTargetCoordinate( RangeOneBombTarget:GetCoordinate(), "RangeOneBombTarget", 50)
-- -- Or, add the coordinate of the STATIC target object as a bomb target using default values (name will be "Bomb Target", goodhitrange will be 25 m)
-- RangeOne:AddBombingTargetCoordinate( RangeOneBombTarget:GetCoordinate() )
--
function RANGE:AddBombingTargetCoordinate(coord, name, goodhitrange)
local target={} --#RANGE.BombTarget
@ -1403,8 +1414,8 @@ end
--- Add all units of a group as bombing targets.
-- @param #RANGE self
-- @param Wrapper.Group#GROUP group Group of bombing targets.
-- @param #number goodhitrange Max distance from unit which is considered as a good hit.
-- @param #boolean randommove If true, unit will move randomly within the range. Default is false.
-- @param #number goodhitrange (Optional) Max hit distance from target unit in meters which is considered as a good hit. Default is 25 m.
-- @param #boolean randommove (Optional) If true, unit will move randomly within the range. Default is false.
-- @return #RANGE self
function RANGE:AddBombingTargetGroup(group, goodhitrange, randommove)
self:F({group=group, goodhitrange=goodhitrange, randommove=randommove})
@ -1423,10 +1434,10 @@ function RANGE:AddBombingTargetGroup(group, goodhitrange, randommove)
return self
end
--- Measures the foule line distance between two unit or static objects.
--- Returns the foul line distance between strafe pit target and a foul line distance marker object.
-- @param #RANGE self
-- @param #string namepit Name of the strafe pit target object.
-- @param #string namefoulline Name of the fould line distance marker object.
-- @param #string namefoulline Name of the foul line distance marker object.
-- @return #number Foul line distance in meters.
function RANGE:GetFoullineDistance(namepit, namefoulline)
self:F({namepit=namepit, namefoulline=namefoulline})
@ -1552,7 +1563,6 @@ function RANGE:OnEventBirth(EventData)
self:T3(self.id.."BIRTH: player = "..tostring(_playername))
if _unit and _playername then
local _uid=_unit:GetID()
local _group=_unit:GetGroup()
local _gid=_group:GetID()
@ -1589,8 +1599,8 @@ function RANGE:OnEventBirth(EventData)
self.timerCheckZone=TIMER:New(self._CheckInZone, self, EventData.IniUnitName):Start(1, 1)
self.planes[_uid] = true
end
end
end
--- Range event handler for event hit.
@ -1681,6 +1691,7 @@ function RANGE:OnEventHit(EventData)
end
end
end
end
--- Range event handler for event shot (when a unit releases a rocket or bomb (but not a fast firing gun).
@ -1741,7 +1752,6 @@ function RANGE:OnEventShot(EventData)
-- Only track if distance player to range is < 25 km. Also check that a player shot. No need to track AI weapons.
if _track and dPR<=self.BombtrackThreshold and _unit and _playername then
-- Player data.
local playerData=self.PlayerSettings[_playername] --#RANGE.PlayerData
@ -3008,7 +3018,7 @@ end
-- Helper Functions
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Get the number of shells a unit currently has.
--- Get the coordinate of a Bomb target.
-- @param #RANGE self
-- @param #RANGE.BombTarget target Bomb target data.
-- @return Core.Point#COORDINATE Target coordinate.

View File

@ -57,7 +57,6 @@ POSITIONABLE.__ = {}
--- @field #POSITIONABLE.__.Cargo
POSITIONABLE.__.Cargo = {}
--- A DCSPositionable
-- @type DCSPositionable
-- @field id_ The ID of the controllable in DCS
@ -75,16 +74,19 @@ end
--- Destroys the POSITIONABLE.
-- @param #POSITIONABLE self
-- @param #boolean GenerateEvent (Optional) true if you want to generate a crash or dead event for the unit.
-- @param #boolean GenerateEvent (Optional) If true, generates a crash or dead event for the unit. If false, no event generated. If nil, a remove event is generated.
-- @return #nil The DCS Unit is not existing or alive.
-- @usage
-- -- Air unit example: destroy the Helicopter and generate a S_EVENT_CRASH for each unit in the Helicopter group.
--
-- Air unit example: destroy the Helicopter and generate a S_EVENT_CRASH for each unit in the Helicopter group.
-- Helicopter = UNIT:FindByName( "Helicopter" )
-- Helicopter:Destroy( true )
--
-- @usage
-- -- Ground unit example: destroy the Tanks and generate a S_EVENT_DEAD for each unit in the Tanks group.
-- Tanks = UNIT:FindByName( "Tanks" )
-- Tanks:Destroy( true )
--
-- @usage
-- -- Ship unit example: destroy the Ship silently.
-- Ship = STATIC:FindByName( "Ship" )
@ -147,7 +149,7 @@ function POSITIONABLE:GetPosition()
return PositionablePosition
end
BASE:E( { "Cannot GetPositionVec3", Positionable = self, Alive = self:IsAlive() } )
BASE:E( { "Cannot GetPosition", Positionable = self, Alive = self:IsAlive() } )
return nil
end
@ -157,6 +159,7 @@ end
-- @return DCS#Vec3 X orientation, i.e. parallel to the direction of movement.
-- @return DCS#Vec3 Y orientation, i.e. vertical.
-- @return DCS#Vec3 Z orientation, i.e. perpendicular to the direction of movement.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetOrientation()
local position = self:GetPosition()
if position then
@ -170,6 +173,7 @@ end
--- Returns a {@DCS#Vec3} table of the objects current X orientation in 3D space, i.e. along the direction of movement.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 X orientation, i.e. parallel to the direction of movement.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetOrientationX()
local position = self:GetPosition()
if position then
@ -183,6 +187,7 @@ end
--- Returns a {@DCS#Vec3} table of the objects current Y orientation in 3D space, i.e. vertical orientation.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 Y orientation, i.e. vertical.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetOrientationY()
local position = self:GetPosition()
if position then
@ -196,6 +201,7 @@ end
--- Returns a {@DCS#Vec3} table of the objects current Z orientation in 3D space, i.e. perpendicular to direction of movement.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 Z orientation, i.e. perpendicular to movement.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetOrientationZ()
local position = self:GetPosition()
if position then
@ -228,7 +234,8 @@ end
--- Returns the @{DCS#Vec3} vector indicating the 3D vector of the POSITIONABLE within the mission.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 The 3D point vector of the POSITIONABLE or `nil` if it is not existing or alive.
-- @return DCS#Vec3 The 3D point vector of the POSITIONABLE.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVec3()
local DCSPositionable = self:GetDCSObject()
@ -251,7 +258,8 @@ end
--- Returns the @{DCS#Vec2} vector indicating the point in 2D of the POSITIONABLE within the mission.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec2 The 2D point vector of the POSITIONABLE or #nil if it is not existing or alive.
-- @return DCS#Vec2 The 2D point vector of the POSITIONABLE.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetVec2()
local DCSPositionable = self:GetDCSObject()
@ -327,8 +335,10 @@ function POSITIONABLE:GetPointVec3()
end
--- Returns a COORDINATE object indicating the point in 3D of the POSITIONABLE within the mission.
-- If the POSITIONABLE has a COORDINATE OBJECT set, it updates it. If not, it creates a new COORDINATE object.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return Core.Point#COORDINATE The COORDINATE of the POSITIONABLE.
-- TODO: Seems to have been introduced with Airboss. Should it be renamed to better reflect the difference to "GetCoordinate" (it is currently ambiguous)? Or perhaps just be a switch in the the GetCoordinate function; forceCoordinateUpate?
function POSITIONABLE:GetCoord()
-- Get DCS object.
@ -337,20 +347,14 @@ function POSITIONABLE:GetCoord()
if DCSPositionable then
-- Get the current position.
local Vec3 = self:GetVec3()
local PositionableVec3 = self:GetVec3()
if self.coordinate then
-- Update vector.
self.coordinate.x=Vec3.x
self.coordinate.y=Vec3.y
self.coordinate.z=Vec3.z
-- Update COORDINATE from 3D vector.
self.coordinate:UpdateFromVec3( PositionableVec3 )
else
-- New COORDINATE.
self.coordinate=COORDINATE:NewFromVec3(Vec3)
self.coordinate = COORDINATE:NewFromVec3( PositionableVec3 )
end
return self.coordinate
@ -377,7 +381,7 @@ function POSITIONABLE:GetCoordinate()
local coord = COORDINATE:NewFromVec3( PositionableVec3 )
-- Return a new coordiante object.
-- Return a new coordinate object.
return coord
end
@ -463,12 +467,11 @@ function POSITIONABLE:GetRandomVec3( Radius )
return nil
end
--- Get the bounding box of the underlying POSITIONABLE DCS Object.
-- @param #POSITIONABLE self
-- @return DCS#Box3 The bounding box of the POSITIONABLE.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetBoundingBox() --R2.1
function POSITIONABLE:GetBoundingBox()
self:F2()
local DCSPositionable = self:GetDCSObject()
@ -486,7 +489,6 @@ function POSITIONABLE:GetBoundingBox() --R2.1
return nil
end
--- Get the object size.
-- @param #POSITIONABLE self
-- @return DCS#Distance Max size of object in x, z or 0 if bounding box could not be obtained.
@ -511,7 +513,8 @@ end
--- Get the bounding radius of the underlying POSITIONABLE DCS Object.
-- @param #POSITIONABLE self
-- @param #number mindist (Optional) If bounding box is smaller than this value, mindist is returned.
-- @return DCS#Distance The bounding radius of the POSITIONABLE or #nil if the POSITIONABLE is not existing or alive.
-- @return DCS#Distance The bounding radius of the POSITIONABLE
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetBoundingRadius( mindist )
self:F2()
@ -574,7 +577,6 @@ function POSITIONABLE:IsAboveRunway()
return nil
end
function POSITIONABLE:GetSize()
local DCSObject = self:GetDCSObject()
@ -586,11 +588,10 @@ function POSITIONABLE:GetSize()
end
end
--- Returns the POSITIONABLE heading in degrees.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number The POSITIONABLE heading in degrees or `nil` if not existing or alive.
-- @return #number The POSITIONABLE heading in degrees.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetHeading()
local DCSPositionable = self:GetDCSObject()
@ -613,7 +614,6 @@ function POSITIONABLE:GetHeading()
end
self:E( { "Cannot GetHeading", Positionable = self, Alive = self:IsAlive() } )
return nil
end
@ -623,6 +623,7 @@ end
-- If the unit is a helicopter or a plane, then this method will return true, otherwise false.
-- @param #POSITIONABLE self
-- @return #boolean Air category evaluation result.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:IsAir()
self:F2()
@ -638,6 +639,7 @@ function POSITIONABLE:IsAir()
return IsAirResult
end
self:E( { "Cannot check IsAir", Positionable = self, Alive = self:IsAlive() } )
return nil
end
@ -645,6 +647,7 @@ end
-- If the unit is a ground vehicle or infantry, this method will return true, otherwise false.
-- @param #POSITIONABLE self
-- @return #boolean Ground category evaluation result.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:IsGround()
self:F2()
@ -660,13 +663,14 @@ function POSITIONABLE:IsGround()
return IsGroundResult
end
self:E( { "Cannot check IsGround", Positionable = self, Alive = self:IsAlive() } )
return nil
end
--- Returns if the unit is of ship category.
-- @param #POSITIONABLE self
-- @return #boolean Ship category evaluation result.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:IsShip()
self:F2()
@ -674,16 +678,18 @@ function POSITIONABLE:IsShip()
if DCSUnit then
local UnitDescriptor = DCSUnit:getDesc()
self:T3( { UnitDescriptor.category, Unit.Category.SHIP } )
local IsShip = ( UnitDescriptor.category == Unit.Category.SHIP )
local IsShipResult = (UnitDescriptor.category == Unit.Category.SHIP)
return IsShip
self:T3( IsShipResult )
return IsShipResult
end
self:E( { "Cannot check IsShip", Positionable = self, Alive = self:IsAlive() } )
return nil
end
--- Returns if the unit is a submarine.
-- @param #POSITIONABLE self
-- @return #boolean Submarines attributes result.
@ -701,10 +707,10 @@ function POSITIONABLE:IsSubmarine()
end
end
self:E( { "Cannot check IsSubmarine", Positionable = self, Alive = self:IsAlive() } )
return nil
end
--- Returns true if the POSITIONABLE is in the air.
-- Polymorphic, is overridden in GROUP and UNIT.
-- @param Wrapper.Positionable#POSITIONABLE self
@ -716,8 +722,7 @@ function POSITIONABLE:InAir()
return nil
end
--- Returns the a @{Velocity} object from the positionable.
--- Returns the a @{Velocity} object from the POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return Core.Velocity#VELOCITY Velocity The Velocity object.
-- @return #nil The POSITIONABLE is not existing or alive.
@ -736,8 +741,6 @@ function POSITIONABLE:GetVelocity()
return nil
end
--- Returns the POSITIONABLE velocity Vec3 vector.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 The velocity Vec3 vector
@ -760,7 +763,7 @@ end
--- Get relative velocity with respect to another POSITIONABLE.
-- @param #POSITIONABLE self
-- @param #POSITIONABLE positionable Other positionable.
-- @param #POSITIONABLE positionable Other POSITIONABLE.
-- @return #number Relative velocity in m/s.
function POSITIONABLE:GetRelativeVelocity( positionable )
self:F2( self.PositionableName )
@ -773,17 +776,16 @@ function POSITIONABLE:GetRelativeVelocity(positionable)
return UTILS.VecNorm( vtot )
end
--- Returns the POSITIONABLE height in meters.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Vec3 The height of the positionable.
-- @return DCS#Vec3 The height of the POSITIONABLE in meters.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetHeight() --R2.1
function POSITIONABLE:GetHeight()
self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject()
if DCSPositionable then
if DCSPositionable and DCSPositionable:isExist() then
local PositionablePosition = DCSPositionable:getPosition()
if PositionablePosition then
local PositionableHeight = PositionablePosition.p.y
@ -795,10 +797,9 @@ function POSITIONABLE:GetHeight() --R2.1
return nil
end
--- Returns the POSITIONABLE velocity in km/h.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number The velocity in km/h
-- @return #number The velocity in km/h.
function POSITIONABLE:GetVelocityKMH()
self:F2( self.PositionableName )
@ -841,9 +842,10 @@ function POSITIONABLE:GetVelocityKNOTS()
return UTILS.MpsToKnots( self:GetVelocityMPS() )
end
--- Returns the Angle of Attack of a positionable.
--- Returns the Angle of Attack of a POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number Angle of attack in degrees.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetAoA()
-- Get position of the unit.
@ -889,9 +891,10 @@ function POSITIONABLE:GetAoA()
return nil
end
--- Returns the unit's climb or descent angle.
--- Returns the climb or descent angle of the POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number Climb or descent angle in degrees. Or 0 if velocity vector norm is zero (or nil). Or nil, if the position of the POSITIONABLE returns nil.
-- @return #number Climb or descent angle in degrees. Or 0 if velocity vector norm is zero.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetClimbAngle()
-- Get position of the unit.
@ -912,14 +915,16 @@ function POSITIONABLE:GetClimbAngle()
else
return 0
end
end
return nil
end
--- Returns the pitch angle of a unit.
--- Returns the pitch angle of a POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number Pitch ange in degrees.
-- @return #number Pitch angle in degrees.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetPitch()
-- Get position of the unit.
@ -934,7 +939,8 @@ end
--- Returns the roll angle of a unit.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number Pitch ange in degrees.
-- @return #number Pitch angle in degrees.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetRoll()
-- Get position of the unit.
@ -942,34 +948,40 @@ function POSITIONABLE:GetRoll()
if unitpos then
--first, make a vector that is perpendicular to y and unitpos.x with cross product
-- First, make a vector that is perpendicular to y and unitpos.x with cross product
local cp = UTILS.VecCross( unitpos.x, { x = 0, y = 1, z = 0 } )
--now, get dot product of of this cross product with unitpos.z
-- Now, get dot product of of this cross product with unitpos.z
local dp = UTILS.VecDot( cp, unitpos.z )
--now get the magnitude of the roll (magnitude of the angle between two vectors is acos(vec1.vec2/|vec1||vec2|)
-- Now get the magnitude of the roll (magnitude of the angle between two vectors is acos(vec1.vec2/|vec1||vec2|)
local Roll = math.acos( dp / (UTILS.VecNorm( cp ) * UTILS.VecNorm( unitpos.z )) )
--now, have to get sign of roll.
-- by convention, making right roll positive
-- to get sign of roll, use the y component of unitpos.z. For right roll, y component is negative.
-- Now, have to get sign of roll. By convention, making right roll positive
-- To get sign of roll, use the y component of unitpos.z. For right roll, y component is negative.
if unitpos.z.y > 0 then -- left roll, flip the sign of the roll
Roll = -Roll
end
return math.deg( Roll )
end
end
--- Returns the yaw angle of a unit.
return nil
end
--- Returns the yaw angle of a POSITIONABLE.
-- @param Wrapper.Positionable#POSITIONABLE self
-- @return #number Yaw ange in degrees.
-- @return #number Yaw angle in degrees.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetYaw()
-- Get position of the unit.
local unitpos = self:GetPosition()
if unitpos then
-- get unit velocity
local unitvel = self:GetVelocityVec3()
@ -991,38 +1003,43 @@ function POSITIONABLE:GetYaw()
end
return Yaw
end
end
end
--- Returns the message text with the callsign embedded (if there is one).
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @return #string The message text
function POSITIONABLE:GetMessageText( Message, Name )
local DCSObject = self:GetDCSObject()
if DCSObject then
local Callsign = string.format( "%s", ( ( Name ~= "" and Name ) or self:GetCallsign() ~= "" and self:GetCallsign() ) or self:GetName() )
local MessageText = string.format("%s - %s", Callsign, Message )
return MessageText
end
return nil
end
--- Returns the message text with the callsign embedded (if there is one).
-- @param #POSITIONABLE self
-- @param #string Message The message text.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
-- @return #string The message text.
-- @return #nil The POSITIONABLE is not existing or alive.
function POSITIONABLE:GetMessageText( Message, Name )
local DCSObject = self:GetDCSObject()
if DCSObject then
local Callsign = string.format( "%s", ((Name ~= "" and Name) or self:GetCallsign() ~= "" and self:GetCallsign()) or self:GetName() )
local MessageText = string.format( "%s - %s", Callsign, Message )
return MessageText
end
return nil
end
--- Returns a message with the callsign embedded (if there is one).
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
-- @return Core.Message#MESSAGE
function POSITIONABLE:GetMessage( Message, Duration, Name ) --R2.1 changed callsign and name and using GetMessageText
function POSITIONABLE:GetMessage( Message, Duration, Name )
local DCSObject = self:GetDCSObject()
if DCSObject then
local MessageText = self:GetMessageText( Message, Name )
return MESSAGE:New( MessageText, Duration )
@ -1035,7 +1052,7 @@ end
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param Core.Message#MESSAGE MessageType MessageType The message type.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
-- @return Core.Message#MESSAGE
function POSITIONABLE:GetMessageType( Message, MessageType, Name ) -- R2.2 changed callsign and name and using GetMessageText
@ -1053,7 +1070,7 @@ end
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToAll( Message, Duration, Name )
self:F2( { Message, Duration } )
@ -1071,7 +1088,7 @@ end
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param DCS#coalition MessageCoalition The Coalition receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToCoalition( Message, Duration, MessageCoalition, Name )
self:F2( { Message, Duration } )
@ -1085,14 +1102,13 @@ function POSITIONABLE:MessageToCoalition( Message, Duration, MessageCoalition, N
return nil
end
--- Send a message to a coalition.
-- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message.
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param Core.Message#MESSAGE.Type MessageType The message type that determines the duration.
-- @param DCS#coalition MessageCoalition The Coalition receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageTypeToCoalition( Message, MessageType, MessageCoalition, Name )
self:F2( { Message, MessageType } )
@ -1106,13 +1122,12 @@ function POSITIONABLE:MessageTypeToCoalition( Message, MessageType, MessageCoali
return nil
end
--- Send a message to the red coalition.
-- The message will appear in the message area. The message will begin with the callsign of the group and the type of the first unit sending the message.
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToRed( Message, Duration, Name )
self:F2( { Message, Duration } )
@ -1129,7 +1144,7 @@ end
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToBlue( Message, Duration, Name )
self:F2( { Message, Duration } )
@ -1147,7 +1162,7 @@ end
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param Wrapper.Client#CLIENT Client The client object receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToClient( Message, Duration, Client, Name )
self:F2( { Message, Duration } )
@ -1165,7 +1180,7 @@ end
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param Wrapper.Group#GROUP MessageGroup The GROUP object receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToGroup( Message, Duration, MessageGroup, Name )
self:F2( { Message, Duration } )
@ -1178,11 +1193,15 @@ function POSITIONABLE:MessageToGroup( Message, Duration, MessageGroup, Name )
BASE:E( { "Message not sent to Group; Group is not alive...", Message = Message, MessageGroup = MessageGroup } )
end
else
BASE:E( { "Message not sent to Group; Positionable is not alive ...", Message = Message, Positionable = self, MessageGroup = MessageGroup } )
BASE:E( {
"Message not sent to Group; Positionable is not alive ...",
Message = Message,
Positionable = self,
MessageGroup = MessageGroup
} )
end
end
return nil
end
@ -1192,7 +1211,7 @@ end
-- @param #string Message The message text
-- @param Core.Message#MESSAGE.Type MessageType The message type that determines the duration.
-- @param Wrapper.Group#GROUP MessageGroup The GROUP object receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, the Name is the type of the POSITIONABLE.
function POSITIONABLE:MessageTypeToGroup( Message, MessageType, MessageGroup, Name )
self:F2( { Message, MessageType } )
@ -1212,18 +1231,16 @@ end
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param Core.Set#SET_GROUP MessageSetGroup The SET_GROUP collection receiving the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Name ) --R2.1
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:MessageToSetGroup( Message, Duration, MessageSetGroup, Name )
self:F2( { Message, Duration } )
local DCSObject = self:GetDCSObject()
if DCSObject then
if DCSObject:isExist() then
MessageSetGroup:ForEachGroupAlive(
function( MessageGroup )
MessageSetGroup:ForEachGroupAlive( function( MessageGroup )
self:GetMessage( Message, Duration, Name ):ToGroup( MessageGroup )
end
)
end )
end
end
@ -1235,7 +1252,7 @@ end
-- @param #POSITIONABLE self
-- @param #string Message The message text
-- @param DCS#Duration Duration The duration of the message.
-- @param #string Name (optional) The Name of the sender. If not provided, the Name is the type of the Positionable.
-- @param #string Name (Optional) The Name of the sender. If not provided, Name is set to the type of the POSITIONABLE.
function POSITIONABLE:Message( Message, Duration, Name )
self:F2( { Message, Duration } )
@ -1251,7 +1268,7 @@ end
-- Set parameters with the methods provided, then use RADIO:Broadcast() to actually broadcast the message
-- @param #POSITIONABLE self
-- @return Core.Radio#RADIO Radio
function POSITIONABLE:GetRadio() --R2.1
function POSITIONABLE:GetRadio()
self:F2( self )
return RADIO:New( self )
end
@ -1259,7 +1276,7 @@ end
--- Create a @{Core.Radio#BEACON}, to allow this POSITIONABLE to broadcast beacon signals
-- @param #POSITIONABLE self
-- @return Core.Radio#RADIO Radio
function POSITIONABLE:GetBeacon() --R2.1
function POSITIONABLE:GetBeacon()
self:F2( self )
return BEACON:New( self )
end
@ -1270,7 +1287,7 @@ end
-- @param #number LaserCode Laser code or random number in [1000, 9999].
-- @param #number Duration Duration of lasing in seconds.
-- @return Core.Spot#SPOT
function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
function POSITIONABLE:LaseUnit( Target, LaserCode, Duration )
self:F2()
LaserCode = LaserCode or math.random( 1000, 9999 )
@ -1278,7 +1295,7 @@ function POSITIONABLE:LaseUnit( Target, LaserCode, Duration ) --R2.1
local RecceDcsUnit = self:GetDCSObject()
local TargetVec3 = Target:GetVec3()
self:F("bulding spot")
self:F( "building spot" )
self.Spot = SPOT:New( self ) -- Core.Spot#SPOT
self.Spot:LaseOn( Target, LaserCode, Duration )
self.LaserCode = LaserCode
@ -1289,7 +1306,7 @@ end
--- Start Lasing a COORDINATE.
-- @param #POSITIONABLE self
-- @param Core.Point#COORDIUNATE Coordinate The coordinate where the lase is pointing at.
-- @param Core.Point#COORDINATE Coordinate The coordinate where the lase is pointing at.
-- @param #number LaserCode Laser code or random number in [1000, 9999].
-- @param #number Duration Duration of lasing in seconds.
-- @return Core.Spot#SPOT
@ -1308,7 +1325,7 @@ end
--- Stop Lasing a POSITIONABLE
-- @param #POSITIONABLE self
-- @return #POSITIONABLE
function POSITIONABLE:LaseOff() --R2.1
function POSITIONABLE:LaseOff()
self:F2()
if self.Spot then
@ -1322,7 +1339,7 @@ end
--- Check if the POSITIONABLE is lasing a target
-- @param #POSITIONABLE self
-- @return #boolean true if it is lasing a target
function POSITIONABLE:IsLasing() --R2.1
function POSITIONABLE:IsLasing()
self:F2()
local Lasing = false
@ -1337,7 +1354,7 @@ end
--- Get the Spot
-- @param #POSITIONABLE self
-- @return Core.Spot#SPOT The Spot
function POSITIONABLE:GetSpot() --R2.1
function POSITIONABLE:GetSpot()
return self.Spot
end
@ -1345,7 +1362,7 @@ end
--- Get the last assigned laser code
-- @param #POSITIONABLE self
-- @return #number The laser code
function POSITIONABLE:GetLaserCode() --R2.1
function POSITIONABLE:GetLaserCode()
return self.LaserCode
end
@ -1368,8 +1385,6 @@ do -- Cargo
return self.__.Cargo
end
--- Remove cargo.
-- @param #POSITIONABLE self
-- @param Core.Cargo#CARGO Cargo
@ -1468,8 +1483,8 @@ do -- Cargo
self:F( { Desc = Desc } )
local Weights = {
["C-17A"] = 35000, --77519 cannot be used, because it loads way too much apcs and infantry.,
["C-130"] = 22000 --The real value cannot be used, because it loads way too much apcs and infantry.,
["C-17A"] = 35000, -- 77519 cannot be used, because it loads way too many APCs and infantry.
["C-130"] = 22000 -- The real value cannot be used, because it loads way too many APCs and infantry.
}
self.__.CargoBayWeightLimit = Weights[Desc.typeName] or (Desc.massMax - (Desc.massEmpty + Desc.fuelMassMax))
@ -1485,7 +1500,7 @@ do -- Cargo
["Dry-cargo ship-2"] = 70000,
["Higgins_boat"] = 3700, -- Higgins Boat can load 3700 kg of general cargo or 36 men (source wikipedia).
["USS_Samuel_Chase"] = 25000, -- Let's say 25 tons for now. Wiki says 33 Higgins boats, which would be 264 tons (can't be right!) and/or 578 troops.
["LST_Mk2"] =2100000, -- Can carry 2100 tons according to wiki source!
["LST_Mk2"] = 2100000 -- Can carry 2100 tons according to wiki source!
}
self.__.CargoBayWeightLimit = (Weights[Desc.typeName] or 50000)
@ -1534,7 +1549,7 @@ do -- Cargo
["Ural-4320 APA-5D"] = 10,
["Ural-4320T"] = 14,
["ZBD04A"] = 7, -- new by kappa
["VAB_Mephisto"] = 8, -- new by Apple
["VAB_Mephisto"] = 8 -- new by Apple
}
local CargoBayWeightLimit = (Weights[Desc.typeName] or 0) * 95
@ -1586,9 +1601,9 @@ end
--- Smoke the POSITIONABLE.
-- @param #POSITIONABLE self
-- @param Utilities.Utils#SMOKECOLOR SmokeColor The color to smoke to positionable.
-- @param #number Range The range in meters to randomize the smoking around the positionable.
-- @param #number AddHeight The height in meters to add to the altitude of the positionable.
-- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color.
-- @param #number Range The range in meters to randomize the smoking around the POSITIONABLE.
-- @param #number AddHeight The height in meters to add to the altitude of the POSITIONABLE.
function POSITIONABLE:Smoke( SmokeColor, Range, AddHeight )
self:F2()
if Range then
@ -1638,7 +1653,6 @@ function POSITIONABLE:SmokeBlue()
trigger.action.smoke( self:GetVec3(), trigger.smokeColor.Blue )
end
--- Returns true if the unit is within a @{Zone}.
-- @param #POSITIONABLE self
-- @param Core.Zone#ZONE_BASE Zone The zone to test.

View File

@ -10,11 +10,8 @@
--
-- @module Wrapper.Static
-- @image Wrapper_Static.JPG
--- @type STATIC
-- @extends Wrapper.Positionable#POSITIONABLE
--- Wrapper class to handle Static objects.
--
-- Note that Statics are almost the same as Units, but they don't have a controller.
@ -40,13 +37,10 @@
--
-- * @{#STATIC.FindByName}(): Find a STATIC instance from the _DATABASE object using a DCS Static name.
--
-- IMPORTANT: ONE SHOULD NEVER SANATIZE these STATIC OBJECT REFERENCES! (make the STATIC object references nil).
-- IMPORTANT: ONE SHOULD NEVER SANITIZE these STATIC OBJECT REFERENCES! (make the STATIC object references nil).
--
-- @field #STATIC
STATIC = {
ClassName = "STATIC",
}
STATIC = { ClassName = "STATIC" }
--- Register a static object.
-- @param #STATIC self
@ -58,7 +52,6 @@ function STATIC:Register( StaticName )
return self
end
--- Finds a STATIC from the _DATABASE using a DCSStatic object.
-- @param #STATIC self
-- @param DCS#StaticObject DCSStatic An existing DCS Static object reference.
@ -97,8 +90,9 @@ end
--- Destroys the STATIC.
-- @param #STATIC self
-- @param #boolean GenerateEvent (Optional) true if you want to generate a crash or dead event for the static.
-- @param #boolean GenerateEvent (Optional) true to generate a crash or dead event, false to not generate any event. `nil` (default) creates a remove event.
-- @return #nil The DCS StaticObject is not existing or alive.
--
-- @usage
-- -- Air static example: destroy the static Helicopter and generate a S_EVENT_CRASH.
-- Helicopter = STATIC:FindByName( "Helicopter" )
@ -117,7 +111,7 @@ end
-- @usage
-- -- Destroy without event generation example.
-- Ship = STATIC:FindByName( "Boat" )
-- Ship:Destroy( false ) -- Don't generate an event upon destruction.
-- Ship:Destroy( false ) -- Don't generate any event upon destruction.
--
function STATIC:Destroy( GenerateEvent )
self:F2( self.ObjectName )
@ -148,7 +142,6 @@ function STATIC:Destroy( GenerateEvent )
return nil
end
--- Get DCS object of static of static.
-- @param #STATIC self
-- @return DCS static object
@ -180,7 +173,6 @@ function STATIC:GetUnits()
return nil
end
--- Get threat level of static.
-- @param #STATIC self
-- @return #number Threat level 1.
@ -211,7 +203,6 @@ function STATIC:SpawnAt(Coordinate, Heading, Delay)
return self
end
--- Respawn the @{Wrapper.Unit} at the same location with the same properties.
-- This is useful to respawn a cargo after it has been destroyed.
-- @param #STATIC self
@ -234,12 +225,11 @@ function STATIC:ReSpawn(CountryID, Delay)
return self
end
--- Respawn the @{Wrapper.Unit} at a defined Coordinate with an optional heading.
-- @param #STATIC self
-- @param Core.Point#COORDINATE Coordinate The coordinate where to spawn the new Static.
-- @param #number Heading (Optional) The heading of the static respawn in degrees. Default the current heading.
-- @param #number Delay (Optional) Delay in seconds before static is respawned. Default now.
-- @param #number Heading (Optional) The heading of the static respawn in degrees. Default is the current heading.
-- @param #number Delay (Optional) Delay in seconds before static is respawned. Default is now.
function STATIC:ReSpawnAt( Coordinate, Heading, Delay )
-- Heading=Heading or 0
@ -247,11 +237,9 @@ function STATIC:ReSpawnAt(Coordinate, Heading, Delay)
if Delay and Delay > 0 then
SCHEDULER:New( nil, self.ReSpawnAt, { self, Coordinate, Heading }, Delay )
else
local SpawnStatic = SPAWNSTATIC:NewFromStatic( self.StaticName, self:GetCountry() )
SpawnStatic:SpawnFromCoordinate( Coordinate, Heading, self.StaticName )
end
return self

View File

@ -168,9 +168,6 @@ function UNIT:GetDCSObject()
return nil
end
--- Respawn the @{Wrapper.Unit} using a (tweaked) template of the parent Group.
--
-- This function will:
@ -263,8 +260,6 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
_DATABASE:Spawn( SpawnGroupTemplate )
end
--- Returns if the unit is activated.
-- @param #UNIT self
-- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive.
@ -301,8 +296,6 @@ function UNIT:IsAlive()
return nil
end
--- Returns the Unit's callsign - the localized string.
-- @param #UNIT self
-- @return #string The Callsign of the Unit.
@ -961,7 +954,6 @@ end
-- @return #string Some text.
function UNIT:GetThreatLevel()
local ThreatLevel = 0
local ThreatText = ""
@ -987,7 +979,6 @@ function UNIT:GetThreatLevel()
"LR SAMs"
}
if Attributes["LR SAM"] then ThreatLevel = 10
elseif Attributes["MR SAM"] then ThreatLevel = 9
elseif Attributes["SR SAM"] and
@ -1023,7 +1014,6 @@ function UNIT:GetThreatLevel()
"Fighter"
}
if Attributes["Fighters"] then ThreatLevel = 10
elseif Attributes["Multirole fighters"] then ThreatLevel = 9
elseif Attributes["Battleplanes"] then ThreatLevel = 8
@ -1141,12 +1131,6 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
return nil
end
--- Returns if the unit is a friendly unit.
-- @param #UNIT self
-- @return #boolean IsFriendly evaluation result.