Added functions for rescue mission.

This commit is contained in:
svenvandevelde 2016-02-26 19:44:27 +01:00
parent c7d3e44a57
commit a939220d20
5 changed files with 116 additions and 11 deletions

View File

@ -7,7 +7,7 @@ Include.File( "Routines" )
BASE = {
ClassName = "BASE",
TraceOn = false,
TraceOn = true,
ClassID = 0,
Events = {}
}

View File

@ -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

View File

@ -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 } )

View File

@ -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

58
Moose/Unit.lua Normal file
View File

@ -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