From a939220d201ca751e1aa9313aa94c87fb731e5c9 Mon Sep 17 00:00:00 2001 From: svenvandevelde Date: Fri, 26 Feb 2016 19:44:27 +0100 Subject: [PATCH] Added functions for rescue mission. --- Moose/Base.lua | 2 +- Moose/Client.lua | 14 ++++++++---- Moose/Group.lua | 27 ++++++++++++++++++++-- Moose/Spawn.lua | 26 ++++++++++++++++++---- Moose/Unit.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 Moose/Unit.lua diff --git a/Moose/Base.lua b/Moose/Base.lua index 77724a7a1..520c951e3 100644 --- a/Moose/Base.lua +++ b/Moose/Base.lua @@ -7,7 +7,7 @@ Include.File( "Routines" ) BASE = { ClassName = "BASE", - TraceOn = false, + TraceOn = true, ClassID = 0, Events = {} } diff --git a/Moose/Client.lua b/Moose/Client.lua index 8b152620f..fc74435b1 100644 --- a/Moose/Client.lua +++ b/Moose/Client.lua @@ -65,7 +65,7 @@ end -- This function is modified to deal with a couple of bugs in DCS 1.5.3 -- @treturn Group function CLIENT:ClientGroup() -self:T() +--self:T() -- local ClientData = Group.getByName( self.ClientName ) -- if ClientData and ClientData:isExist() then @@ -77,9 +77,9 @@ self:T() local CoalitionsData = { AlivePlayersRed = coalition.getPlayers( coalition.side.RED ), AlivePlayersBlue = coalition.getPlayers( coalition.side.BLUE ) } for CoalitionId, CoalitionData in pairs( CoalitionsData ) do - self:T( { "CoalitionData:", CoalitionData } ) + --self:T( { "CoalitionData:", CoalitionData } ) for UnitId, UnitData in pairs( CoalitionData ) do - self:T( { "UnitData:", UnitData } ) + --self:T( { "UnitData:", UnitData } ) if UnitData and UnitData:isExist() then local ClientGroup = Group.getByName( self.ClientName ) @@ -173,7 +173,7 @@ end function CLIENT:GetClientGroupUnit() self:T() - ClientGroup = self:ClientGroup() + local ClientGroup = self:ClientGroup() if ClientGroup then if ClientGroup:isExist() then @@ -186,6 +186,12 @@ self:T() return nil end +function CLIENT:GetUnit() + self:T() + + return UNIT:New( self:GetClientGroupUnit() ) +end + --- Returns the Position of the @{CLIENT}. -- @treturn Position diff --git a/Moose/Group.lua b/Moose/Group.lua index 3506b79e0..48971a3ba 100644 --- a/Moose/Group.lua +++ b/Moose/Group.lua @@ -4,6 +4,7 @@ Include.File( "Routines" ) Include.File( "Base" ) Include.File( "Message" ) +Include.File( "Unit" ) GROUPS = {} @@ -13,9 +14,8 @@ GROUP = { } function GROUP:New( _Group ) -trace.f( self.ClassName, _Group:getName() ) - local self = BASE:Inherit( self, BASE:New() ) + self:T( _Group:getName() ) self._Group = _Group self.GroupName = _Group:getName() @@ -25,12 +25,25 @@ trace.f( self.ClassName, _Group:getName() ) end +function GROUP:NewFromName( GroupName ) + local self = BASE:Inherit( self, BASE:New() ) + self:T( GroupName ) + + self._Group = Group.getByName( GroupName ) + self.GroupName = self._Group:getName() + self.GroupID = self._Group:getID() + + return self +end + + function GROUP:GetName() self:T( self.GroupName ) return self.GroupName end + function GROUP:Destroy() self:T( self.GroupName ) @@ -41,6 +54,13 @@ function GROUP:Destroy() self._Group:destroy() end + +function GROUP:GetUnit( UnitNumber ) + self:T( self.GroupName ) + return UNIT:New( self._Group:getUnit( UnitNumber ) ) +end + + function GROUP:IsAir() self:T() @@ -50,6 +70,7 @@ self:T() return IsAirResult end + function GROUP:AllOnGround() self:T() @@ -106,6 +127,7 @@ trace.f( self.ClassName, { self.GroupName, Point, Duration } ) return self end + function GROUP:Embarking( Point, Duration, EmbarkingGroup ) trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup._Group } ) @@ -130,6 +152,7 @@ trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup._Grou return self end + function GROUP:EmbarkToTransport( Point, Radius ) trace.f( self.ClassName, { self.GroupName, Point, Radius } ) diff --git a/Moose/Spawn.lua b/Moose/Spawn.lua index 343d6614b..29ae2ea72 100644 --- a/Moose/Spawn.lua +++ b/Moose/Spawn.lua @@ -273,7 +273,7 @@ end -- Uses @{DATABASE} global object defined in MOOSE. -- @treturn SPAWN function SPAWN:Spawn( SpawnGroupName ) -trace.f( self.ClassName ) + self:T( { self.SpawnPrefix, SpawnGroupName } ) local SpawnTemplate = self:_Prepare( SpawnGroupName ) if self.SpawnStartPoint ~= 0 or self.SpawnEndPoint ~= 0 then SpawnTemplate = self:_RandomizeRoute( SpawnTemplate ) @@ -286,6 +286,24 @@ trace.f( self.ClassName ) end +--- Will SPAWN a Group with a specified index number whenever you want to do this. +-- Note that the configuration with the above functions will apply when calling this method: Maxima, Randomization of routes, Scheduler, ... +-- Uses @{DATABASE} global object defined in MOOSE. +-- @treturn SPAWN +function SPAWN:SpawnWithIndex( SpawnIndex ) + self:T( { self.SpawnPrefix, SpawnIndex } ) + local SpawnTemplate = self:_Prepare( self:SpawnGroupName( SpawnIndex ) ) + if self.SpawnStartPoint ~= 0 or self.SpawnEndPoint ~= 0 then + SpawnTemplate = self:_RandomizeRoute( SpawnTemplate ) + end + _Database:Spawn( SpawnTemplate ) + if self.SpawnRepeat then + _Database:SetStatusGroup( SpawnTemplate.name, "ReSpawn" ) + end + return self +end + + --- Will Re-SPAWN a Group based on a given GroupName. The GroupName must be a group that is already alive within the DCSRTE and should have a Group Template defined in the ME (with Late Activation flag on). -- Note that the configuration with the above functions will apply when calling this method: Maxima, Randomization of routes, Scheduler, ... -- @tparam string SpawnGroupName @@ -454,13 +472,13 @@ end -- @tparam number SpawnIndex is the number of the Group that is to be SPAWNed. -- @treturn string SpawnGroupName function SPAWN:SpawnGroupName( SpawnIndex ) -trace.f("Spawn", SpawnIndex ) + self:T( { self.SpawnPrefix, SpawnIndex } ) if SpawnIndex then - trace.i( self.ClassName, string.format( '%s#%03d', self.SpawnPrefix, SpawnIndex ) ) + self:T( string.format( '%s#%03d', self.SpawnPrefix, SpawnIndex ) ) return string.format( '%s#%03d', self.SpawnPrefix, SpawnIndex ) else - trace.i( self.ClassName, self.SpawnPrefix ) + self:T( self.SpawnPrefix ) return self.SpawnPrefix end diff --git a/Moose/Unit.lua b/Moose/Unit.lua new file mode 100644 index 000000000..eb5eb9713 --- /dev/null +++ b/Moose/Unit.lua @@ -0,0 +1,58 @@ +--- UNIT Classes +-- @classmod UNIT + +Include.File( "Routines" ) +Include.File( "Base" ) +Include.File( "Message" ) + +UNITS = {} + + +UNIT = { + ClassName="UNIT", + } + +function UNIT:New( _Unit ) + local self = BASE:Inherit( self, BASE:New() ) + self:T( _Unit:getName() ) + + self._Unit = _Unit + self.UnitName = _Unit:getName() + self.UnitID = _Unit:getID() + + return self +end + +function UNIT:GetCallSign() + self:T( self.UnitName ) + + return self._Unit:getCallsign() +end + +function UNIT:GetPositionVec3() + self:T( self.UnitName ) + + local UnitPos = self._Unit:getPosition().p + + self:T( UnitPos ) + return UnitPos +end + +function UNIT:OtherUnitInRadius( AwaitUnit, Radius ) + self:T( { self.UnitName, AwaitUnit.UnitName, Radius } ) + + local UnitPos = self:GetPositionVec3() + local AwaitUnitPos = AwaitUnit:GetPositionVec3() + + if (((UnitPos.x - AwaitUnitPos.x)^2 + (UnitPos.z - AwaitUnitPos.z)^2)^0.5 <= Radius) then + self:T( "true" ) + return true + else + self:T( "false" ) + return false + end + + self:T( "false" ) + return false +end +