From 1e60111ce5ed626df8cdb7409629c7c053f15834 Mon Sep 17 00:00:00 2001 From: Grey-Echo Date: Mon, 27 Mar 2017 11:48:54 +0200 Subject: [PATCH] Add polymorphic methods GROUP:GetPointVec2(), GROUP:GetRandomVec3(Radius), GROUP:GetHeading() Also fix a Luadoc documentation issues in Wrapper.Group and Wrapper.Positionable --- Moose Development/Moose/Wrapper/Group.lua | 57 +++++++++++++++++ .../Moose/Wrapper/Positionable.lua | 2 + .../l10n/DEFAULT/Moose.lua | 61 ++++++++++++++++++- Moose Mission Setup/Moose.lua | 61 ++++++++++++++++++- 4 files changed, 179 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index 05f11a167..e2c5f9b45 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -442,6 +442,7 @@ function GROUP:GetVec2() end --- Returns the current Vec3 vector of the first DCS Unit in the GROUP. +-- @param #GROUP self -- @return Dcs.DCSTypes#Vec3 Current Vec3 of the first DCS Unit of the GROUP. function GROUP:GetVec3() self:F2( self.GroupName ) @@ -451,7 +452,63 @@ function GROUP:GetVec3() return GroupVec3 end +--- Returns a POINT_VEC2 object indicating the point in 2D of the first UNIT of the GROUP within the mission. +-- @param #GROUP self +-- @return Core.Point#POINT_VEC2 The 2D point vector of the first DCS Unit of the GROUP. +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetPointVec2() + self:F2(self.GroupName) + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitPointVec2 = FirstUnit:GetPointVec2() + self:T3(FirstUnitPointVec2) + return FirstUnitPointVec2 + end + + return nil +end + +--- Returns a random @{DCSTypes#Vec3} vector (point in 3D of the UNIT within the mission) within a range around the first UNIT of the GROUP. +-- @param #GROUP self +-- @param #number Radius +-- @return Dcs.DCSTypes#Vec3 The random 3D point vector around the first UNIT of the GROUP. +-- @return #nil The GROUP is invalid or empty +function GROUP:GetRandomVec3(Radius) + self:F2(self.GroupName) + + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitRandomPointVec3 = FirstUnit:GetRandomVec3(Radius) + self:T3(FirstUnitRandomPointVec3) + return FirstUnitRandomPointVec3 + end + + return nil +end + +--- Returns the mean heading of every UNIT in the GROUP in degrees +-- @param #GROUP self +-- @return #number mean heading of the GROUP +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetHeading() + self:F2(self.GroupName) + + local GroupSize = self:GetSize() + local HeadingAccumulator = 0 + + if GroupSize then + for i = 1, GroupSize do + HeadingAccumulator = HeadingAccumulator + self:GetUnit(i):GetHeading() + end + return math.floor(HeadingAccumulator / GroupSize) + end + + return nil + +end do -- Is Zone methods diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index e4cf24038..e20c0c7cc 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -135,6 +135,7 @@ end --- Returns a random @{DCSTypes#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission. -- @param Wrapper.Positionable#POSITIONABLE self +-- @param #number Radius -- @return Dcs.DCSTypes#Vec3 The 3D point vector of the POSITIONABLE. -- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetRandomVec3( Radius ) @@ -219,6 +220,7 @@ end --- Returns the POSITIONABLE heading in degrees. -- @param Wrapper.Positionable#POSITIONABLE self -- @return #number The POSTIONABLE heading +-- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetHeading() local DCSPositionable = self:GetDCSObject() diff --git a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua index fedaf29aa..d8de438d3 100644 --- a/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua +++ b/Moose Mission Setup/Moose Mission Update/l10n/DEFAULT/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170326_0853' ) +env.info( 'Moose Generation Timestamp: 20170327_1145' ) local base = _G Include = {} @@ -13541,6 +13541,7 @@ end --- Returns a random @{DCSTypes#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission. -- @param Wrapper.Positionable#POSITIONABLE self +-- @param #number Radius -- @return Dcs.DCSTypes#Vec3 The 3D point vector of the POSITIONABLE. -- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetRandomVec3( Radius ) @@ -13625,6 +13626,7 @@ end --- Returns the POSITIONABLE heading in degrees. -- @param Wrapper.Positionable#POSITIONABLE self -- @return #number The POSTIONABLE heading +-- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetHeading() local DCSPositionable = self:GetDCSObject() @@ -16514,6 +16516,7 @@ function GROUP:GetVec2() end --- Returns the current Vec3 vector of the first DCS Unit in the GROUP. +-- @param #GROUP self -- @return Dcs.DCSTypes#Vec3 Current Vec3 of the first DCS Unit of the GROUP. function GROUP:GetVec3() self:F2( self.GroupName ) @@ -16523,7 +16526,63 @@ function GROUP:GetVec3() return GroupVec3 end +--- Returns a POINT_VEC2 object indicating the point in 2D of the first UNIT of the GROUP within the mission. +-- @param #GROUP self +-- @return Core.Point#POINT_VEC2 The 2D point vector of the first DCS Unit of the GROUP. +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetPointVec2() + self:F2(self.GroupName) + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitPointVec2 = FirstUnit:GetPointVec2() + self:T3(FirstUnitPointVec2) + return FirstUnitPointVec2 + end + + return nil +end + +--- Returns a random @{DCSTypes#Vec3} vector (point in 3D of the UNIT within the mission) within a range around the first UNIT of the GROUP. +-- @param #GROUP self +-- @param #number Radius +-- @return Dcs.DCSTypes#Vec3 The random 3D point vector around the first UNIT of the GROUP. +-- @return #nil The GROUP is invalid or empty +function GROUP:GetRandomVec3(Radius) + self:F2(self.GroupName) + + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitRandomPointVec3 = FirstUnit:GetRandomVec3(Radius) + self:T3(FirstUnitRandomPointVec3) + return FirstUnitRandomPointVec3 + end + + return nil +end + +--- Returns the mean heading of every UNIT in the GROUP in degrees +-- @param #GROUP self +-- @return #number mean heading of the GROUP +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetHeading() + self:F2(self.GroupName) + + local GroupSize = self:GetSize() + local HeadingAccumulator = 0 + + if GroupSize then + for i = 1, GroupSize do + HeadingAccumulator = HeadingAccumulator + self:GetUnit(i):GetHeading() + end + return math.floor(HeadingAccumulator / GroupSize) + end + + return nil + +end do -- Is Zone methods diff --git a/Moose Mission Setup/Moose.lua b/Moose Mission Setup/Moose.lua index fedaf29aa..d8de438d3 100644 --- a/Moose Mission Setup/Moose.lua +++ b/Moose Mission Setup/Moose.lua @@ -1,5 +1,5 @@ env.info( '*** MOOSE STATIC INCLUDE START *** ' ) -env.info( 'Moose Generation Timestamp: 20170326_0853' ) +env.info( 'Moose Generation Timestamp: 20170327_1145' ) local base = _G Include = {} @@ -13541,6 +13541,7 @@ end --- Returns a random @{DCSTypes#Vec3} vector within a range, indicating the point in 3D of the POSITIONABLE within the mission. -- @param Wrapper.Positionable#POSITIONABLE self +-- @param #number Radius -- @return Dcs.DCSTypes#Vec3 The 3D point vector of the POSITIONABLE. -- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetRandomVec3( Radius ) @@ -13625,6 +13626,7 @@ end --- Returns the POSITIONABLE heading in degrees. -- @param Wrapper.Positionable#POSITIONABLE self -- @return #number The POSTIONABLE heading +-- @return #nil The POSITIONABLE is not existing or alive. function POSITIONABLE:GetHeading() local DCSPositionable = self:GetDCSObject() @@ -16514,6 +16516,7 @@ function GROUP:GetVec2() end --- Returns the current Vec3 vector of the first DCS Unit in the GROUP. +-- @param #GROUP self -- @return Dcs.DCSTypes#Vec3 Current Vec3 of the first DCS Unit of the GROUP. function GROUP:GetVec3() self:F2( self.GroupName ) @@ -16523,7 +16526,63 @@ function GROUP:GetVec3() return GroupVec3 end +--- Returns a POINT_VEC2 object indicating the point in 2D of the first UNIT of the GROUP within the mission. +-- @param #GROUP self +-- @return Core.Point#POINT_VEC2 The 2D point vector of the first DCS Unit of the GROUP. +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetPointVec2() + self:F2(self.GroupName) + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitPointVec2 = FirstUnit:GetPointVec2() + self:T3(FirstUnitPointVec2) + return FirstUnitPointVec2 + end + + return nil +end + +--- Returns a random @{DCSTypes#Vec3} vector (point in 3D of the UNIT within the mission) within a range around the first UNIT of the GROUP. +-- @param #GROUP self +-- @param #number Radius +-- @return Dcs.DCSTypes#Vec3 The random 3D point vector around the first UNIT of the GROUP. +-- @return #nil The GROUP is invalid or empty +function GROUP:GetRandomVec3(Radius) + self:F2(self.GroupName) + + local FirstUnit = self:GetUnit(1) + + if FirstUnit then + local FirstUnitRandomPointVec3 = FirstUnit:GetRandomVec3(Radius) + self:T3(FirstUnitRandomPointVec3) + return FirstUnitRandomPointVec3 + end + + return nil +end + +--- Returns the mean heading of every UNIT in the GROUP in degrees +-- @param #GROUP self +-- @return #number mean heading of the GROUP +-- @return #nil The first UNIT is not existing or alive. +function GROUP:GetHeading() + self:F2(self.GroupName) + + local GroupSize = self:GetSize() + local HeadingAccumulator = 0 + + if GroupSize then + for i = 1, GroupSize do + HeadingAccumulator = HeadingAccumulator + self:GetUnit(i):GetHeading() + end + return math.floor(HeadingAccumulator / GroupSize) + end + + return nil + +end do -- Is Zone methods