mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Rework of SPAWN
- Visible Array - Internal table in SPAWN GROUP functions - Route - RouteToZone - CopyRoute SPAWN functions - SpawnFromUnit - SpawnInZone Replaced SpawnFromCarrier overall
This commit is contained in:
177
Moose/Group.lua
177
Moose/Group.lua
@@ -13,13 +13,14 @@ GROUP = {
|
||||
ClassName="GROUP",
|
||||
}
|
||||
|
||||
function GROUP:New( _Group )
|
||||
function GROUP:New( DCSGroup )
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:T( _Group:getName() )
|
||||
self:T( DCSGroup:getName() )
|
||||
|
||||
self._Group = _Group
|
||||
self.GroupName = _Group:getName()
|
||||
self.GroupID = _Group:getID()
|
||||
self.DCSGroup = DCSGroup
|
||||
self.GroupName = DCSGroup:getName()
|
||||
self.GroupID = DCSGroup:getID()
|
||||
self.Controller = DCSGroup:getController()
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -29,13 +30,29 @@ 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()
|
||||
self.DCSGroup = Group.getByName( GroupName )
|
||||
self.GroupName = self.DCSGroup:getName()
|
||||
self.GroupID = self.DCSGroup:getID()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GROUP:GetDCSGroup()
|
||||
self:T( { self.GroupName } )
|
||||
return self.DCSGroup
|
||||
end
|
||||
|
||||
function GROUP:GetDCSUnit( UnitNumber )
|
||||
self:T( { self.GroupName, UnitNumber } )
|
||||
return self.DCSGroup:getUnit( UnitNumber )
|
||||
|
||||
end
|
||||
|
||||
function GROUP:Activate()
|
||||
self:T( { self.GroupName } )
|
||||
trigger.action.activateGroup( self:GetDCSGroup() )
|
||||
return self:GetDCSGroup()
|
||||
end
|
||||
|
||||
function GROUP:GetName()
|
||||
self:T( self.GroupName )
|
||||
@@ -43,40 +60,59 @@ function GROUP:GetName()
|
||||
return self.GroupName
|
||||
end
|
||||
|
||||
function GROUP:GetPoint()
|
||||
self:T( self.GroupName )
|
||||
|
||||
local GroupPoint = self:GetUnit(1):GetPoint()
|
||||
self:T( GroupPoint )
|
||||
return GroupPoint
|
||||
end
|
||||
|
||||
|
||||
function GROUP:Destroy()
|
||||
self:T( self.GroupName )
|
||||
|
||||
for Index, UnitData in pairs( self._Group:getUnits() ) do
|
||||
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
|
||||
self:CreateEventCrash( timer.getTime(), UnitData )
|
||||
end
|
||||
|
||||
self._Group:destroy()
|
||||
self.DCSGroup:destroy()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function GROUP:GetUnit( UnitNumber )
|
||||
self:T( self.GroupName )
|
||||
return UNIT:New( self._Group:getUnit( UnitNumber ) )
|
||||
self:T( { self.GroupName, UnitNumber } )
|
||||
return UNIT:New( self.DCSGroup:getUnit( UnitNumber ) )
|
||||
end
|
||||
|
||||
|
||||
function GROUP:IsAir()
|
||||
self:T()
|
||||
|
||||
local IsAirResult = self._Group:getCategory() == Group.Category.AIRPLANE or self._Group:getCategory() == Group.Category.HELICOPTER
|
||||
local IsAirResult = self.DCSGroup:getCategory() == Group.Category.AIRPLANE or self.DCSGroup:getCategory() == Group.Category.HELICOPTER
|
||||
|
||||
self:T( IsAirResult )
|
||||
return IsAirResult
|
||||
end
|
||||
|
||||
function GROUP:IsAlive()
|
||||
self:T()
|
||||
|
||||
local IsAliveResult = self.DCSGroup and self.DCSGroup:isExist()
|
||||
|
||||
self:T( IsAliveResult )
|
||||
return IsAliveResult
|
||||
end
|
||||
|
||||
|
||||
function GROUP:AllOnGround()
|
||||
self:T()
|
||||
|
||||
local AllOnGroundResult = true
|
||||
|
||||
for Index, UnitData in pairs( self._Group:getUnits() ) do
|
||||
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
|
||||
if UnitData:inAir() then
|
||||
AllOnGroundResult = false
|
||||
end
|
||||
@@ -92,7 +128,7 @@ self:T()
|
||||
|
||||
local MaxVelocity = 0
|
||||
|
||||
for Index, UnitData in pairs( self._Group:getUnits() ) do
|
||||
for Index, UnitData in pairs( self.DCSGroup:getUnits() ) do
|
||||
|
||||
local Velocity = UnitData:getVelocity()
|
||||
local VelocityTotal = math.abs( Velocity.x ) + math.abs( Velocity.y ) + math.abs( Velocity.z )
|
||||
@@ -129,13 +165,13 @@ end
|
||||
|
||||
|
||||
function GROUP:Embarking( Point, Duration, EmbarkingGroup )
|
||||
trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup._Group } )
|
||||
trace.f( self.ClassName, { self.GroupName, Point, Duration, EmbarkingGroup.DCSGroup } )
|
||||
|
||||
local Controller = self:_GetController()
|
||||
|
||||
trace.i( self.ClassName, EmbarkingGroup.GroupID )
|
||||
trace.i( self.ClassName, EmbarkingGroup._Group:getID() )
|
||||
trace.i( self.ClassName, EmbarkingGroup._Group.id )
|
||||
trace.i( self.ClassName, EmbarkingGroup.DCSGroup:getID() )
|
||||
trace.i( self.ClassName, EmbarkingGroup.DCSGroup.id )
|
||||
|
||||
Controller:pushTask( { id = 'Embarking',
|
||||
params = { x = Point.x,
|
||||
@@ -169,9 +205,112 @@ trace.f( self.ClassName, { self.GroupName, Point, Radius } )
|
||||
return self
|
||||
end
|
||||
|
||||
function GROUP:Route( GoPoints )
|
||||
self:T( GoPoints )
|
||||
|
||||
local Points = routines.utils.deepCopy( GoPoints )
|
||||
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
|
||||
|
||||
--self.Controller.setTask( self.Controller, MissionTask )
|
||||
|
||||
routines.scheduleFunction( self.Controller.setTask, { self.Controller, MissionTask}, timer.getTime() + 1 )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GROUP:RouteToZone( Zone, Randomize, Speed, Formation )
|
||||
self:T( Zone )
|
||||
|
||||
local GroupPoint = self:GetPoint()
|
||||
|
||||
local PointFrom = {}
|
||||
PointFrom.x = GroupPoint.x
|
||||
PointFrom.y = GroupPoint.y
|
||||
PointFrom.type = "Turning Point"
|
||||
PointFrom.action = "Cone"
|
||||
PointFrom.speed = 20 / 1.6
|
||||
|
||||
|
||||
local PointTo = {}
|
||||
local ZonePoint
|
||||
|
||||
if Randomize then
|
||||
ZonePoint = Zone:GetRandomPoint()
|
||||
else
|
||||
ZonePoint = Zone:GetPoint()
|
||||
end
|
||||
|
||||
PointTo.x = ZonePoint.x
|
||||
PointTo.y = ZonePoint.y
|
||||
PointTo.type = "Turning Point"
|
||||
|
||||
if Formation then
|
||||
PointTo.action = Formation
|
||||
else
|
||||
PointTo.action = "Cone"
|
||||
end
|
||||
|
||||
if Speed then
|
||||
PointTo.speed = Speed
|
||||
else
|
||||
PointTo.speed = 20 / 1.6
|
||||
end
|
||||
|
||||
local Points = { PointFrom, PointTo }
|
||||
|
||||
self:T( Points )
|
||||
|
||||
self:Route( Points )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function GROUP:CopyRoute( Begin, End, Randomize, Radius )
|
||||
self:T( { Begin, End } )
|
||||
|
||||
local Points = {}
|
||||
|
||||
-- Could be a Spawned Group
|
||||
local GroupName = string.match( self:GetName(), ".*#" )
|
||||
if GroupName then
|
||||
GroupName = GroupName:sub( 1, -2 )
|
||||
else
|
||||
GroupName = self:GetName()
|
||||
end
|
||||
|
||||
self:T( { GroupName } )
|
||||
|
||||
local Template = _Database.Groups[GroupName].Template
|
||||
|
||||
if Template then
|
||||
if not Begin then
|
||||
Begin = 0
|
||||
end
|
||||
if not End then
|
||||
End = 0
|
||||
end
|
||||
|
||||
for TPointID = Begin + 1, #Template.route.points - End do
|
||||
if Template.route.points[TPointID] then
|
||||
Points[#Points+1] = routines.utils.deepCopy( Template.route.points[TPointID] )
|
||||
if Randomize then
|
||||
if not Radius then
|
||||
Radius = 500
|
||||
end
|
||||
Points[#Points].x = Points[#Points].x + math.random( Radius * -1, Radius )
|
||||
Points[#Points].y = Points[#Points].y + math.random( Radius * -1, Radius )
|
||||
end
|
||||
end
|
||||
end
|
||||
return Points
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
function GROUP:_GetController()
|
||||
|
||||
return self._Group:getController()
|
||||
return self.DCSGroup:getController()
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user