#SPAWN - performance tuning for event workaround

This commit is contained in:
Applevangelist
2024-09-03 16:47:17 +02:00
parent 6afb68390b
commit 8695953d5a
4 changed files with 378 additions and 339 deletions
+137 -98
View File
@@ -1226,7 +1226,7 @@ end
-- @param Core.Point#COORDINATE Coordinate The position to spawn from -- @param Core.Point#COORDINATE Coordinate The position to spawn from
-- @return #SPAWN self -- @return #SPAWN self
function SPAWN:InitPositionCoordinate(Coordinate) function SPAWN:InitPositionCoordinate(Coordinate)
self:T2( { self.SpawnTemplatePrefix, Coordinate:GetVec2()} ) --self:T2( { self.SpawnTemplatePrefix, Coordinate:GetVec2()} )
self:InitPositionVec2(Coordinate:GetVec2()) self:InitPositionVec2(Coordinate:GetVec2())
return self return self
end end
@@ -1236,10 +1236,10 @@ end
-- @param DCS#Vec2 Vec2 The position to spawn from -- @param DCS#Vec2 Vec2 The position to spawn from
-- @return #SPAWN self -- @return #SPAWN self
function SPAWN:InitPositionVec2(Vec2) function SPAWN:InitPositionVec2(Vec2)
self:T2( { self.SpawnTemplatePrefix, Vec2} ) --self:T2( { self.SpawnTemplatePrefix, Vec2} )
self.SpawnInitPosition = Vec2 self.SpawnInitPosition = Vec2
self.SpawnFromNewPosition = true self.SpawnFromNewPosition = true
self:T2("MaxGroups:"..self.SpawnMaxGroups) --self:T2("MaxGroups:"..self.SpawnMaxGroups)
for SpawnGroupID = 1, self.SpawnMaxGroups do for SpawnGroupID = 1, self.SpawnMaxGroups do
self:_SetInitialPosition( SpawnGroupID ) self:_SetInitialPosition( SpawnGroupID )
end end
@@ -1334,7 +1334,7 @@ function SPAWN:InitCleanUp( SpawnCleanUpInterval )
self.SpawnCleanUpTimeStamps = {} self.SpawnCleanUpTimeStamps = {}
local SpawnGroup, SpawnCursor = self:GetFirstAliveGroup() local SpawnGroup, SpawnCursor = self:GetFirstAliveGroup()
self:T2( { "CleanUp Scheduler:", SpawnGroup } ) --self:T2( { "CleanUp Scheduler:", SpawnGroup } )
self.CleanUpScheduler = SCHEDULER:New( self, self._SpawnCleanUpScheduler, {}, 1, SpawnCleanUpInterval, 0.2 ) self.CleanUpScheduler = SCHEDULER:New( self, self._SpawnCleanUpScheduler, {}, 1, SpawnCleanUpInterval, 0.2 )
return self return self
@@ -1367,7 +1367,7 @@ function SPAWN:InitArray( SpawnAngle, SpawnWidth, SpawnDeltaX, SpawnDeltaY )
local SpawnYIndex = 0 local SpawnYIndex = 0
for SpawnGroupID = 1, self.SpawnMaxGroups do for SpawnGroupID = 1, self.SpawnMaxGroups do
self:T2( { SpawnX, SpawnY, SpawnXIndex, SpawnYIndex } ) --self:T2( { SpawnX, SpawnY, SpawnXIndex, SpawnYIndex } )
self.SpawnGroups[SpawnGroupID].Visible = true self.SpawnGroups[SpawnGroupID].Visible = true
self.SpawnGroups[SpawnGroupID].Spawned = false self.SpawnGroups[SpawnGroupID].Spawned = false
@@ -1391,7 +1391,7 @@ function SPAWN:InitArray( SpawnAngle, SpawnWidth, SpawnDeltaX, SpawnDeltaY )
self.SpawnGroups[SpawnGroupID].Visible = true self.SpawnGroups[SpawnGroupID].Visible = true
self:HandleEvent( EVENTS.Birth, self._OnBirth ) self:HandleEvent( EVENTS.Birth, self._OnBirth )
--self:HandleEvent( EVENTS.Dead, self._OnDeadOrCrash ) self:HandleEvent( EVENTS.Dead, self._OnDeadOrCrash )
self:HandleEvent( EVENTS.Crash, self._OnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._OnDeadOrCrash )
self:HandleEvent( EVENTS.RemoveUnit, self._OnDeadOrCrash ) self:HandleEvent( EVENTS.RemoveUnit, self._OnDeadOrCrash )
self:HandleEvent( EVENTS.UnitLost, self._OnDeadOrCrash ) self:HandleEvent( EVENTS.UnitLost, self._OnDeadOrCrash )
@@ -1591,7 +1591,7 @@ end
-- @param #string SpawnIndex The index of the group to be spawned. -- @param #string SpawnIndex The index of the group to be spawned.
-- @return Wrapper.Group#GROUP The group that was spawned. You can use this group for further actions. -- @return Wrapper.Group#GROUP The group that was spawned. You can use this group for further actions.
function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth ) function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
--[[
local set = SET_GROUP:New():FilterAlive():FilterPrefixes({self.SpawnTemplatePrefix, self.SpawnAliasPrefix}):FilterOnce() local set = SET_GROUP:New():FilterAlive():FilterPrefixes({self.SpawnTemplatePrefix, self.SpawnAliasPrefix}):FilterOnce()
local aliveunits = 0 local aliveunits = 0
set:ForEachGroupAlive( set:ForEachGroupAlive(
@@ -1602,12 +1602,12 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
if aliveunits ~= self.AliveUnits then if aliveunits ~= self.AliveUnits then
self.AliveUnits = aliveunits self.AliveUnits = aliveunits
self:T2("***** self.AliveUnits accounting failure! Corrected! *****") --self:T2("***** self.AliveUnits accounting failure! Corrected! *****")
end end
set= nil set= nil
--]]
self:T2( { SpawnTemplatePrefix = self.SpawnTemplatePrefix, SpawnIndex = SpawnIndex, AliveUnits = self.AliveUnits, SpawnMaxGroups = self.SpawnMaxGroups } ) --self:T2( { SpawnTemplatePrefix = self.SpawnTemplatePrefix, SpawnIndex = SpawnIndex, AliveUnits = self.AliveUnits, SpawnMaxGroups = self.SpawnMaxGroups } )
if self:_GetSpawnIndex( SpawnIndex ) then if self:_GetSpawnIndex( SpawnIndex ) then
@@ -1622,12 +1622,12 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate local SpawnTemplate = self.SpawnGroups[self.SpawnIndex].SpawnTemplate
local SpawnZone = self.SpawnGroups[self.SpawnIndex].SpawnZone local SpawnZone = self.SpawnGroups[self.SpawnIndex].SpawnZone
self:T2( SpawnTemplate.name ) --self:T2( SpawnTemplate.name )
if SpawnTemplate then if SpawnTemplate then
local PointVec3 = POINT_VEC3:New( SpawnTemplate.route.points[1].x, SpawnTemplate.route.points[1].alt, SpawnTemplate.route.points[1].y ) local PointVec3 = POINT_VEC3:New( SpawnTemplate.route.points[1].x, SpawnTemplate.route.points[1].alt, SpawnTemplate.route.points[1].y )
self:T2( { "Current point of ", self.SpawnTemplatePrefix, PointVec3 } ) --self:T2( { "Current point of ", self.SpawnTemplatePrefix, PointVec3 } )
-- If RandomizePosition, then Randomize the formation in the zone band, keeping the template. -- If RandomizePosition, then Randomize the formation in the zone band, keeping the template.
if self.SpawnRandomizePosition then if self.SpawnRandomizePosition then
@@ -1639,7 +1639,7 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
for UnitID = 1, #SpawnTemplate.units do for UnitID = 1, #SpawnTemplate.units do
SpawnTemplate.units[UnitID].x = SpawnTemplate.units[UnitID].x + (RandomVec2.x - CurrentX) SpawnTemplate.units[UnitID].x = SpawnTemplate.units[UnitID].x + (RandomVec2.x - CurrentX)
SpawnTemplate.units[UnitID].y = SpawnTemplate.units[UnitID].y + (RandomVec2.y - CurrentY) SpawnTemplate.units[UnitID].y = SpawnTemplate.units[UnitID].y + (RandomVec2.y - CurrentY)
self:T2( 'SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
end end
end end
@@ -1660,13 +1660,13 @@ function SPAWN:SpawnWithIndex( SpawnIndex, NoBirth )
end end
end end
if (not inZone) then if (not inZone) then
self:T2("Could not place unit within zone and within radius!") --self:T2("Could not place unit within zone and within radius!")
RandomVec2 = SpawnZone:GetRandomVec2() RandomVec2 = SpawnZone:GetRandomVec2()
end end
end end
SpawnTemplate.units[UnitID].x = RandomVec2.x SpawnTemplate.units[UnitID].x = RandomVec2.x
SpawnTemplate.units[UnitID].y = RandomVec2.y SpawnTemplate.units[UnitID].y = RandomVec2.y
self:T2( 'SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
end end
end end
@@ -1887,6 +1887,7 @@ end
--- Spawns new groups at varying time intervals. --- Spawns new groups at varying time intervals.
-- This is useful if you want to have continuity within your missions of certain (AI) groups to be present (alive) within your missions. -- This is useful if you want to have continuity within your missions of certain (AI) groups to be present (alive) within your missions.
-- **WARNING** - Setting a very low SpawnTime heavily impacts your mission performance and CPU time, it is NOT useful to check the alive state of an object every split second! Be reasonable and stay at 15 seconds and above!
-- @param #SPAWN self -- @param #SPAWN self
-- @param #number SpawnTime The time interval defined in seconds between each new spawn of new groups. -- @param #number SpawnTime The time interval defined in seconds between each new spawn of new groups.
-- @param #number SpawnTimeVariation The variation to be applied on the defined time interval between each new spawn. -- @param #number SpawnTimeVariation The variation to be applied on the defined time interval between each new spawn.
@@ -1909,6 +1910,14 @@ function SPAWN:SpawnScheduled( SpawnTime, SpawnTimeVariation, WithDelay )
local SpawnTime = SpawnTime or 60 local SpawnTime = SpawnTime or 60
local SpawnTimeVariation = SpawnTimeVariation or 0.5 local SpawnTimeVariation = SpawnTimeVariation or 0.5
-- Noob catch
if SpawnTime < 15 then
self:E("****SPAWN SCHEDULED****\nWARNING - Setting a very low SpawnTime heavily impacts your mission performance and CPU time, it is NOT useful to check the alive state of an object every "..tostring(SpawnTime).." seconds.\nSetting to 15 second intervals.\n*****")
SpawnTime = 15
end
if SpawnTimeVariation > 1 or SpawnTimeVariation < 0 then SpawnTimeVariation = 0.5 end
if SpawnTime ~= nil and SpawnTimeVariation ~= nil then if SpawnTime ~= nil and SpawnTimeVariation ~= nil then
local InitialDelay = 0 local InitialDelay = 0
if WithDelay or self.DelayOnOff == true then if WithDelay or self.DelayOnOff == true then
@@ -2024,7 +2033,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Get position of airbase. -- Get position of airbase.
local PointVec3 = SpawnAirbase:GetCoordinate() local PointVec3 = SpawnAirbase:GetCoordinate()
self:T2( PointVec3 ) --self:T2( PointVec3 )
-- Set take off type. Default is hot. -- Set take off type. Default is hot.
Takeoff = Takeoff or SPAWN.Takeoff.Hot Takeoff = Takeoff or SPAWN.Takeoff.Hot
@@ -2053,7 +2062,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
--self:F( { GroupAlive = GroupAlive } ) --self:F( { GroupAlive = GroupAlive } )
-- Debug output -- Debug output
self:T2( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } ) --self:T2( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } )
-- Template group, unit and its attributes. -- Template group, unit and its attributes.
local TemplateGroup = GROUP:FindByName( self.SpawnTemplatePrefix ) local TemplateGroup = GROUP:FindByName( self.SpawnTemplatePrefix )
@@ -2102,7 +2111,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Check if we spawn on ground. -- Check if we spawn on ground.
local spawnonground = not (Takeoff == SPAWN.Takeoff.Air) local spawnonground = not (Takeoff == SPAWN.Takeoff.Air)
self:T2( { spawnonground = spawnonground, TOtype = Takeoff, TOair = Takeoff == SPAWN.Takeoff.Air } ) --self:T2( { spawnonground = spawnonground, TOtype = Takeoff, TOair = Takeoff == SPAWN.Takeoff.Air } )
-- Check where we actually spawn if we spawn on ground. -- Check where we actually spawn if we spawn on ground.
local spawnonship = false local spawnonship = false
@@ -2156,7 +2165,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Number of free parking spots at the airbase. -- Number of free parking spots at the airbase.
if spawnonship or spawnonfarp or spawnonrunway then if spawnonship or spawnonfarp or spawnonrunway then
-- These places work procedural and have some kind of build in queue ==> Less effort. -- These places work procedural and have some kind of build in queue ==> Less effort.
self:T2( string.format( "Group %s is spawned on farp/ship/runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s is spawned on farp/ship/runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
nfree = SpawnAirbase:GetFreeParkingSpotsNumber( termtype, true ) nfree = SpawnAirbase:GetFreeParkingSpotsNumber( termtype, true )
spots = SpawnAirbase:GetFreeParkingSpotsTable( termtype, true ) spots = SpawnAirbase:GetFreeParkingSpotsTable( termtype, true )
--[[ --[[
@@ -2169,18 +2178,18 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
if ishelo then if ishelo then
if termtype == nil then if termtype == nil then
-- Helo is spawned. Try exclusive helo spots first. -- Helo is spawned. Try exclusive helo spots first.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterOnly ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterOnly ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterOnly, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterOnly, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
if nfree < nunits then if nfree < nunits then
-- Not enough helo ports. Let's try also other terminal types. -- Not enough helo ports. Let's try also other terminal types.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterUsable ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterUsable ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterUsable, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterUsable, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
-- No terminal type specified. We try all spots except shelters. -- No terminal type specified. We try all spots except shelters.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), termtype ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), termtype ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
@@ -2189,23 +2198,23 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
if termtype == nil then if termtype == nil then
if isbomber or istransport or istanker or isawacs then if isbomber or istransport or istanker or isawacs then
-- First we fill the potentially bigger spots. -- First we fill the potentially bigger spots.
self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig ) ) --self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
if nfree < nunits then if nfree < nunits then
-- Now we try the smaller ones. -- Now we try the smaller ones.
self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenMedOrBig ) ) --self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenMedOrBig ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenMedOrBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenMedOrBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
self:T2( string.format( "Fighter group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.FighterAircraft ) ) --self:T2( string.format( "Fighter group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.FighterAircraft ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.FighterAircraft, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.FighterAircraft, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
-- Terminal type explicitly given. -- Terminal type explicitly given.
self:T2( string.format( "Plane group %s is at %s using terminal type %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), tostring( termtype ) ) ) --self:T2( string.format( "Plane group %s is at %s using terminal type %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), tostring( termtype ) ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
@@ -2215,12 +2224,12 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Debug: Get parking data. -- Debug: Get parking data.
--[[ --[[
local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype) local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype)
self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype))) --self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
for _,_spot in pairs(parkingdata) do for _,_spot in pairs(parkingdata) do
self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d", --self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy)) SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy))
end end
self:T2(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits)) --self:T2(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits))
]] ]]
-- Set this to true if not enough spots are available for emergency air start. -- Set this to true if not enough spots are available for emergency air start.
@@ -2315,7 +2324,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
SpawnTemplate.parked = true SpawnTemplate.parked = true
for UnitID = 1, nunits do for UnitID = 1, nunits do
self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
-- Template of the current unit. -- Template of the current unit.
local UnitTemplate = SpawnTemplate.units[UnitID] local UnitTemplate = SpawnTemplate.units[UnitID]
@@ -2333,7 +2342,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
-- Ships and FARPS seem to have a build in queue. -- Ships and FARPS seem to have a build in queue.
if spawnonship or spawnonfarp or spawnonrunway then if spawnonship or spawnonfarp or spawnonrunway then
self:T2( string.format( "Group %s spawning at farp, ship or runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s spawning at farp, ship or runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
-- Spawn on ship. We take only the position of the ship. -- Spawn on ship. We take only the position of the ship.
SpawnTemplate.units[UnitID].x = PointVec3.x -- TX SpawnTemplate.units[UnitID].x = PointVec3.x -- TX
@@ -2342,7 +2351,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
else else
self:T2( string.format( "Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID] ) ) --self:T2( string.format( "Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID] ) )
-- Get coordinates of parking spot. -- Get coordinates of parking spot.
SpawnTemplate.units[UnitID].x = parkingspots[UnitID].x SpawnTemplate.units[UnitID].x = parkingspots[UnitID].x
@@ -2354,7 +2363,7 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
else else
self:T2( string.format( "Group %s spawning in air at %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s spawning in air at %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
-- Spawn in air as requested initially. Original template orientation is perserved, altitude is already correctly set. -- Spawn in air as requested initially. Original template orientation is perserved, altitude is already correctly set.
SpawnTemplate.units[UnitID].x = TX SpawnTemplate.units[UnitID].x = TX
@@ -2371,9 +2380,9 @@ function SPAWN:SpawnAtAirbase( SpawnAirbase, Takeoff, TakeoffAltitude, TerminalT
end end
-- Debug output. -- Debug output.
self:T2( string.format( "Group %s unit number %d: Parking = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking ) ) ) --self:T2( string.format( "Group %s unit number %d: Parking = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking ) ) )
self:T2( string.format( "Group %s unit number %d: Parking ID = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking_id ) ) ) --self:T2( string.format( "Group %s unit number %d: Parking ID = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking_id ) ) )
self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
end end
end end
@@ -2451,10 +2460,10 @@ function SPAWN:SpawnAtParkingSpot( Airbase, Spots, Takeoff )
-- Get parking spot data. -- Get parking spot data.
local spot = Airbase:GetParkingSpotData( TerminalID ) local spot = Airbase:GetParkingSpotData( TerminalID )
self:T2( { spot = spot } ) --self:T2( { spot = spot } )
if spot and spot.Free then if spot and spot.Free then
self:T2( string.format( "Adding parking spot ID=%d TermType=%d", spot.TerminalID, spot.TerminalType ) ) --self:T2( string.format( "Adding parking spot ID=%d TermType=%d", spot.TerminalID, spot.TerminalType ) )
table.insert( Parkingdata, spot ) table.insert( Parkingdata, spot )
end end
@@ -2486,7 +2495,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- Get position of airbase. -- Get position of airbase.
local PointVec3 = SpawnAirbase:GetCoordinate() local PointVec3 = SpawnAirbase:GetCoordinate()
self:T2( PointVec3 ) --self:T2( PointVec3 )
-- Set take off type. Default is hot. -- Set take off type. Default is hot.
local Takeoff = SPAWN.Takeoff.Cold local Takeoff = SPAWN.Takeoff.Cold
@@ -2502,7 +2511,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
local GroupAlive = self:GetGroupFromIndex( SpawnIndex ) local GroupAlive = self:GetGroupFromIndex( SpawnIndex )
-- Debug output -- Debug output
self:T2( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } ) --self:T2( { "Current point of ", self.SpawnTemplatePrefix, SpawnAirbase } )
-- Template group, unit and its attributes. -- Template group, unit and its attributes.
local TemplateGroup = GROUP:FindByName( self.SpawnTemplatePrefix ) local TemplateGroup = GROUP:FindByName( self.SpawnTemplatePrefix )
@@ -2546,7 +2555,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- Check if we spawn on ground. -- Check if we spawn on ground.
local spawnonground = not (Takeoff == SPAWN.Takeoff.Air) local spawnonground = not (Takeoff == SPAWN.Takeoff.Air)
self:T2( { spawnonground = spawnonground, TOtype = Takeoff, TOair = Takeoff == SPAWN.Takeoff.Air } ) --self:T2( { spawnonground = spawnonground, TOtype = Takeoff, TOair = Takeoff == SPAWN.Takeoff.Air } )
-- Check where we actually spawn if we spawn on ground. -- Check where we actually spawn if we spawn on ground.
local spawnonship = false local spawnonship = false
@@ -2588,7 +2597,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- Number of free parking spots at the airbase. -- Number of free parking spots at the airbase.
if spawnonship or spawnonfarp or spawnonrunway then if spawnonship or spawnonfarp or spawnonrunway then
-- These places work procedural and have some kind of build in queue ==> Less effort. -- These places work procedural and have some kind of build in queue ==> Less effort.
self:T2( string.format( "Group %s is spawned on farp/ship/runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s is spawned on farp/ship/runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
nfree = SpawnAirbase:GetFreeParkingSpotsNumber( termtype, true ) nfree = SpawnAirbase:GetFreeParkingSpotsNumber( termtype, true )
spots = SpawnAirbase:GetFreeParkingSpotsTable( termtype, true ) spots = SpawnAirbase:GetFreeParkingSpotsTable( termtype, true )
--[[ --[[
@@ -2601,18 +2610,18 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
if ishelo then if ishelo then
if termtype == nil then if termtype == nil then
-- Helo is spawned. Try exclusive helo spots first. -- Helo is spawned. Try exclusive helo spots first.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterOnly ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterOnly ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterOnly, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterOnly, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
if nfree < nunits then if nfree < nunits then
-- Not enough helo ports. Let's try also other terminal types. -- Not enough helo ports. Let's try also other terminal types.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterUsable ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.HelicopterUsable ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterUsable, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.HelicopterUsable, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
-- No terminal type specified. We try all spots except shelters. -- No terminal type specified. We try all spots except shelters.
self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), termtype ) ) --self:T2( string.format( "Helo group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), termtype ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
@@ -2624,23 +2633,23 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- TODO: Some attributes are "Helicopters", "Bombers", "Transports", "Battleplanes". Need to check it out. -- TODO: Some attributes are "Helicopters", "Bombers", "Transports", "Battleplanes". Need to check it out.
if isbomber or istransport then if isbomber or istransport then
-- First we fill the potentially bigger spots. -- First we fill the potentially bigger spots.
self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig ) ) --self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenBig ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
if nfree < nunits then if nfree < nunits then
-- Now we try the smaller ones. -- Now we try the smaller ones.
self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenMedOrBig ) ) --self:T2( string.format( "Transport/bomber group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.OpenMedOrBig ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenMedOrBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.OpenMedOrBig, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
self:T2( string.format( "Fighter group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.FighterAircraft ) ) --self:T2( string.format( "Fighter group %s is at %s using terminal type %d.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), AIRBASE.TerminalType.FighterAircraft ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.FighterAircraft, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, AIRBASE.TerminalType.FighterAircraft, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
else else
-- Terminal type explicitly given. -- Terminal type explicitly given.
self:T2( string.format( "Plane group %s is at %s using terminal type %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), tostring( termtype ) ) ) --self:T2( string.format( "Plane group %s is at %s using terminal type %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), tostring( termtype ) ) )
spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata ) spots = SpawnAirbase:FindFreeParkingSpotForAircraft( TemplateGroup, termtype, scanradius, scanunits, scanstatics, scanscenery, verysafe, nunits, Parkingdata )
nfree = #spots nfree = #spots
end end
@@ -2650,12 +2659,12 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- Debug: Get parking data. -- Debug: Get parking data.
--[[ --[[
local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype) local parkingdata=SpawnAirbase:GetParkingSpotsTable(termtype)
self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype))) --self:T2(string.format("Parking at %s, terminal type %s:", SpawnAirbase:GetName(), tostring(termtype)))
for _,_spot in pairs(parkingdata) do for _,_spot in pairs(parkingdata) do
self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d", --self:T2(string.format("%s, Termin Index = %3d, Term Type = %03d, Free = %5s, TOAC = %5s, Term ID0 = %3d, Dist2Rwy = %4d",
SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy)) SpawnAirbase:GetName(), _spot.TerminalID, _spot.TerminalType,tostring(_spot.Free),tostring(_spot.TOAC),_spot.TerminalID0,_spot.DistToRwy))
end end
self:T2(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits)) --self:T2(string.format("%s at %s: free parking spots = %d - number of units = %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), nfree, nunits))
]] ]]
-- Set this to true if not enough spots are available for emergency air start. -- Set this to true if not enough spots are available for emergency air start.
@@ -2733,7 +2742,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
-- Ships and FARPS seem to have a build in queue. -- Ships and FARPS seem to have a build in queue.
if spawnonship or spawnonfarp or spawnonrunway then if spawnonship or spawnonfarp or spawnonrunway then
self:T2( string.format( "Group %s spawning at farp, ship or runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s spawning at farp, ship or runway %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
-- Spawn on ship. We take only the position of the ship. -- Spawn on ship. We take only the position of the ship.
SpawnTemplate.units[UnitID].x = PointVec3.x -- TX SpawnTemplate.units[UnitID].x = PointVec3.x -- TX
@@ -2742,7 +2751,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
else else
self:T2( string.format( "Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID] ) ) --self:T2( string.format( "Group %s spawning at airbase %s on parking spot id %d", self.SpawnTemplatePrefix, SpawnAirbase:GetName(), parkingindex[UnitID] ) )
-- Get coordinates of parking spot. -- Get coordinates of parking spot.
SpawnTemplate.units[UnitID].x = parkingspots[UnitID].x SpawnTemplate.units[UnitID].x = parkingspots[UnitID].x
@@ -2754,7 +2763,7 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
else else
self:T2( string.format( "Group %s spawning in air at %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) ) --self:T2( string.format( "Group %s spawning in air at %s.", self.SpawnTemplatePrefix, SpawnAirbase:GetName() ) )
-- Spawn in air as requested initially. Original template orientation is perserved, altitude is already correctly set. -- Spawn in air as requested initially. Original template orientation is perserved, altitude is already correctly set.
SpawnTemplate.units[UnitID].x = TX SpawnTemplate.units[UnitID].x = TX
@@ -2771,9 +2780,9 @@ function SPAWN:ParkAircraft( SpawnAirbase, TerminalType, Parkingdata, SpawnIndex
end end
-- Debug output. -- Debug output.
self:T2( string.format( "Group %s unit number %d: Parking = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking ) ) ) --self:T2( string.format( "Group %s unit number %d: Parking = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking ) ) )
self:T2( string.format( "Group %s unit number %d: Parking ID = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking_id ) ) ) --self:T2( string.format( "Group %s unit number %d: Parking ID = %s", self.SpawnTemplatePrefix, UnitID, tostring( UnitTemplate.parking_id ) ) )
self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
end end
end end
@@ -2871,7 +2880,7 @@ function SPAWN:SpawnFromVec3( Vec3, SpawnIndex )
--self:F( { self.SpawnTemplatePrefix, Vec3, SpawnIndex } ) --self:F( { self.SpawnTemplatePrefix, Vec3, SpawnIndex } )
local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 ) local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 )
self:T2( PointVec3 ) --self:T2( PointVec3 )
if SpawnIndex then if SpawnIndex then
else else
@@ -2884,7 +2893,7 @@ function SPAWN:SpawnFromVec3( Vec3, SpawnIndex )
if SpawnTemplate then if SpawnTemplate then
self:T2( { "Current point of ", self.SpawnTemplatePrefix, Vec3 } ) --self:T2( { "Current point of ", self.SpawnTemplatePrefix, Vec3 } )
local TemplateHeight = SpawnTemplate.route and SpawnTemplate.route.points[1].alt or nil local TemplateHeight = SpawnTemplate.route and SpawnTemplate.route.points[1].alt or nil
@@ -2909,7 +2918,7 @@ function SPAWN:SpawnFromVec3( Vec3, SpawnIndex )
if SpawnTemplate.CategoryID ~= Group.Category.SHIP then if SpawnTemplate.CategoryID ~= Group.Category.SHIP then
SpawnTemplate.units[UnitID].alt = Vec3.y or TemplateHeight SpawnTemplate.units[UnitID].alt = Vec3.y or TemplateHeight
end end
self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y ) --self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. SpawnTemplate.units[UnitID].x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. SpawnTemplate.units[UnitID].y )
end end
SpawnTemplate.route.points[1].x = Vec3.x SpawnTemplate.route.points[1].x = Vec3.x
SpawnTemplate.route.points[1].y = Vec3.z SpawnTemplate.route.points[1].y = Vec3.z
@@ -3168,10 +3177,10 @@ function SPAWN:SpawnGroupName( SpawnIndex )
if SpawnIndex then if SpawnIndex then
local SpawnName = string.format( '%s#%03d', SpawnPrefix, SpawnIndex ) local SpawnName = string.format( '%s#%03d', SpawnPrefix, SpawnIndex )
self:T2( SpawnName ) --self:T2( SpawnName )
return SpawnName return SpawnName
else else
self:T2( SpawnPrefix ) --self:T2( SpawnPrefix )
return SpawnPrefix return SpawnPrefix
end end
@@ -3499,7 +3508,7 @@ function SPAWN:_Prepare( SpawnTemplatePrefix, SpawnIndex ) -- R2.2
if SpawnInitKeepUnitIFF == false then if SpawnInitKeepUnitIFF == false then
UnitPrefix, Rest = string.match( SpawnTemplate.units[UnitID].name, "^([^#]+)#?" ):gsub( "^%s*(.-)%s*$", "%1" ) UnitPrefix, Rest = string.match( SpawnTemplate.units[UnitID].name, "^([^#]+)#?" ):gsub( "^%s*(.-)%s*$", "%1" )
SpawnTemplate.units[UnitID].name = string.format( '%s#%03d-%02d', UnitPrefix, SpawnIndex, UnitID ) SpawnTemplate.units[UnitID].name = string.format( '%s#%03d-%02d', UnitPrefix, SpawnIndex, UnitID )
self:T2( { UnitPrefix, Rest } ) --self:T2( { UnitPrefix, Rest } )
--else --else
--UnitPrefix=SpawnTemplate.units[UnitID].name --UnitPrefix=SpawnTemplate.units[UnitID].name
end end
@@ -3713,7 +3722,7 @@ function SPAWN:_RandomizeRoute( SpawnIndex )
SpawnTemplate.route.points[t].alt = nil SpawnTemplate.route.points[t].alt = nil
end end
self:T2( 'SpawnTemplate.route.points[' .. t .. '].x = ' .. SpawnTemplate.route.points[t].x .. ', SpawnTemplate.route.points[' .. t .. '].y = ' .. SpawnTemplate.route.points[t].y ) --self:T2( 'SpawnTemplate.route.points[' .. t .. '].x = ' .. SpawnTemplate.route.points[t].x .. ', SpawnTemplate.route.points[' .. t .. '].y = ' .. SpawnTemplate.route.points[t].y )
end end
end end
@@ -3756,15 +3765,15 @@ end
-- @param #number SpawnIndex -- @param #number SpawnIndex
-- @return #SPAWN self -- @return #SPAWN self
function SPAWN:_SetInitialPosition( SpawnIndex ) function SPAWN:_SetInitialPosition( SpawnIndex )
self:T2( { self.SpawnTemplatePrefix, SpawnIndex, self.SpawnRandomizeZones } ) --self:T2( { self.SpawnTemplatePrefix, SpawnIndex, self.SpawnRandomizeZones } )
if self.SpawnFromNewPosition then if self.SpawnFromNewPosition then
self:T2( "Preparing Spawn at Vec2 ", self.SpawnInitPosition ) --self:T2( "Preparing Spawn at Vec2 ", self.SpawnInitPosition )
local SpawnVec2 = self.SpawnInitPosition local SpawnVec2 = self.SpawnInitPosition
self:T2( { SpawnVec2 = SpawnVec2 } ) --self:T2( { SpawnVec2 = SpawnVec2 } )
local SpawnTemplate = self.SpawnGroups[SpawnIndex].SpawnTemplate local SpawnTemplate = self.SpawnGroups[SpawnIndex].SpawnTemplate
@@ -3774,11 +3783,11 @@ function SPAWN:_SetInitialPosition( SpawnIndex )
SpawnTemplate.route.points[1].x = SpawnTemplate.route.points[1].x or 0 SpawnTemplate.route.points[1].x = SpawnTemplate.route.points[1].x or 0
SpawnTemplate.route.points[1].y = SpawnTemplate.route.points[1].y or 0 SpawnTemplate.route.points[1].y = SpawnTemplate.route.points[1].y or 0
self:T2( { Route = SpawnTemplate.route } ) --self:T2( { Route = SpawnTemplate.route } )
for UnitID = 1, #SpawnTemplate.units do for UnitID = 1, #SpawnTemplate.units do
local UnitTemplate = SpawnTemplate.units[UnitID] local UnitTemplate = SpawnTemplate.units[UnitID]
self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y ) --self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y )
local SX = UnitTemplate.x local SX = UnitTemplate.x
local SY = UnitTemplate.y local SY = UnitTemplate.y
local BX = SpawnTemplate.route.points[1].x local BX = SpawnTemplate.route.points[1].x
@@ -3789,7 +3798,7 @@ function SPAWN:_SetInitialPosition( SpawnIndex )
UnitTemplate.y = TY UnitTemplate.y = TY
-- TODO: Manage altitude based on landheight... -- TODO: Manage altitude based on landheight...
-- SpawnTemplate.units[UnitID].alt = SpawnVec2: -- SpawnTemplate.units[UnitID].alt = SpawnVec2:
self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y ) --self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y )
end end
SpawnTemplate.route.points[1].x = SpawnVec2.x SpawnTemplate.route.points[1].x = SpawnVec2.x
@@ -3812,26 +3821,26 @@ function SPAWN:_RandomizeZones( SpawnIndex )
if self.SpawnRandomizeZones then if self.SpawnRandomizeZones then
local SpawnZone = nil -- Core.Zone#ZONE_BASE local SpawnZone = nil -- Core.Zone#ZONE_BASE
while not SpawnZone do while not SpawnZone do
self:T2( { SpawnZoneTableCount = #self.SpawnZoneTable, self.SpawnZoneTable } ) --self:T2( { SpawnZoneTableCount = #self.SpawnZoneTable, self.SpawnZoneTable } )
local ZoneID = math.random( #self.SpawnZoneTable ) local ZoneID = math.random( #self.SpawnZoneTable )
self:T2( ZoneID ) --self:T2( ZoneID )
SpawnZone = self.SpawnZoneTable[ZoneID]:GetZoneMaybe() SpawnZone = self.SpawnZoneTable[ZoneID]:GetZoneMaybe()
end end
self:T2( "Preparing Spawn in Zone", SpawnZone:GetName() ) --self:T2( "Preparing Spawn in Zone", SpawnZone:GetName() )
local SpawnVec2 = SpawnZone:GetRandomVec2() local SpawnVec2 = SpawnZone:GetRandomVec2()
self:T2( { SpawnVec2 = SpawnVec2 } ) --self:T2( { SpawnVec2 = SpawnVec2 } )
local SpawnTemplate = self.SpawnGroups[SpawnIndex].SpawnTemplate local SpawnTemplate = self.SpawnGroups[SpawnIndex].SpawnTemplate
self.SpawnGroups[SpawnIndex].SpawnZone = SpawnZone self.SpawnGroups[SpawnIndex].SpawnZone = SpawnZone
self:T2( { Route = SpawnTemplate.route } ) --self:T2( { Route = SpawnTemplate.route } )
for UnitID = 1, #SpawnTemplate.units do for UnitID = 1, #SpawnTemplate.units do
local UnitTemplate = SpawnTemplate.units[UnitID] local UnitTemplate = SpawnTemplate.units[UnitID]
self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y ) --self:T2( 'Before Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y )
local SX = UnitTemplate.x local SX = UnitTemplate.x
local SY = UnitTemplate.y local SY = UnitTemplate.y
local BX = SpawnTemplate.route.points[1].x local BX = SpawnTemplate.route.points[1].x
@@ -3842,7 +3851,7 @@ function SPAWN:_RandomizeZones( SpawnIndex )
UnitTemplate.y = TY UnitTemplate.y = TY
-- TODO: Manage altitude based on landheight... -- TODO: Manage altitude based on landheight...
-- SpawnTemplate.units[UnitID].alt = SpawnVec2: -- SpawnTemplate.units[UnitID].alt = SpawnVec2:
self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y ) --self:T2( 'After Translation SpawnTemplate.units[' .. UnitID .. '].x = ' .. UnitTemplate.x .. ', SpawnTemplate.units[' .. UnitID .. '].y = ' .. UnitTemplate.y )
end end
SpawnTemplate.x = SpawnVec2.x SpawnTemplate.x = SpawnVec2.x
SpawnTemplate.y = SpawnVec2.y SpawnTemplate.y = SpawnVec2.y
@@ -3897,11 +3906,11 @@ end
-- @param #number SpawnIndex Spawn index. -- @param #number SpawnIndex Spawn index.
-- @return #number self.SpawnIndex -- @return #number self.SpawnIndex
function SPAWN:_GetSpawnIndex( SpawnIndex ) function SPAWN:_GetSpawnIndex( SpawnIndex )
self:T2( { template=self.SpawnTemplatePrefix, SpawnIndex=SpawnIndex, SpawnMaxGroups=self.SpawnMaxGroups, SpawnMaxUnitsAlive=self.SpawnMaxUnitsAlive, AliveUnits=self.AliveUnits, TemplateUnits=#self.SpawnTemplate.units } ) --self:T2( { template=self.SpawnTemplatePrefix, SpawnIndex=SpawnIndex, SpawnMaxGroups=self.SpawnMaxGroups, SpawnMaxUnitsAlive=self.SpawnMaxUnitsAlive, AliveUnits=self.AliveUnits, TemplateUnits=#self.SpawnTemplate.units } )
if (self.SpawnMaxGroups == 0) or (SpawnIndex <= self.SpawnMaxGroups) then if (self.SpawnMaxGroups == 0) or (SpawnIndex <= self.SpawnMaxGroups) then
if (self.SpawnMaxUnitsAlive == 0) or (self.AliveUnits + #self.SpawnTemplate.units <= self.SpawnMaxUnitsAlive) or self.UnControlled == true then if (self.SpawnMaxUnitsAlive == 0) or (self.AliveUnits + #self.SpawnTemplate.units <= self.SpawnMaxUnitsAlive) or self.UnControlled == true then
self:T2( { SpawnCount = self.SpawnCount, SpawnIndex = SpawnIndex } ) --self:T2( { SpawnCount = self.SpawnCount, SpawnIndex = SpawnIndex } )
if SpawnIndex and SpawnIndex >= self.SpawnCount + 1 then if SpawnIndex and SpawnIndex >= self.SpawnCount + 1 then
self.SpawnCount = self.SpawnCount + 1 self.SpawnCount = self.SpawnCount + 1
SpawnIndex = self.SpawnCount SpawnIndex = self.SpawnCount
@@ -3932,22 +3941,51 @@ function SPAWN:_OnBirth( EventData )
if SpawnGroup then if SpawnGroup then
local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup ) local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup )
if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group!
self:T2( { "Birth Event:", EventPrefix, self.SpawnTemplatePrefix } ) --self:T2( { "Birth Event:", EventPrefix, self.SpawnTemplatePrefix } )
if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then
self.AliveUnits = self.AliveUnits + 1 self.AliveUnits = self.AliveUnits + 1
self:T2( "Alive Units: " .. self.AliveUnits ) --self:T2( "Alive Units: " .. self.AliveUnits )
end end
end end
end end
end end
---
-- @param #SPAWN self
-- @return #number count
function SPAWN:_CountAliveUnits()
local count = 0
if self.SpawnAliasPrefix then
if not self.SpawnAliasPrefixEscaped then self.SpawnAliasPrefixEscaped = string.gsub(self.SpawnAliasPrefix,"[%p%s]",".") end
local SpawnAliasPrefix = self.SpawnAliasPrefixEscaped
local agroups = GROUP:FindAllByMatching(SpawnAliasPrefix)
for _,_grp in pairs(agroups) do
local game = self:_GetPrefixFromGroupName(_grp.GroupName)
if game and game == self.SpawnAliasPrefix then
count = count + _grp:CountAliveUnits()
end
end
else
if not self.SpawnTemplatePrefixEscaped then self.SpawnTemplatePrefixEscaped = string.gsub(self.SpawnTemplatePrefix,"[%p%s]",".") end
local SpawnTemplatePrefix = self.SpawnTemplatePrefixEscaped
local groups = GROUP:FindAllByMatching(SpawnTemplatePrefix)
for _,_grp in pairs(groups) do
local game = self:_GetPrefixFromGroupName(_grp.GroupName)
if game and game == self.SpawnTemplatePrefix then
count = count + _grp:CountAliveUnits()
end
end
end
return count
end
--- ---
-- @param #SPAWN self -- @param #SPAWN self
-- @param Core.Event#EVENTDATA EventData -- @param Core.Event#EVENTDATA EventData
function SPAWN:_OnDeadOrCrash( EventData ) function SPAWN:_OnDeadOrCrash( EventData )
self:T2( "Dead or crash event ID "..tostring(EventData.id or 0)) --self:T2( "Dead or crash event ID "..tostring(EventData.id or 0))
self:T2( "Dead or crash event for "..tostring(EventData.IniUnitName or "none") ) --self:T2( "Dead or crash event for "..tostring(EventData.IniUnitName or "none") )
--if EventData.id == EVENTS.Dead then return end --if EventData.id == EVENTS.Dead then return end
@@ -3959,12 +3997,13 @@ function SPAWN:_OnDeadOrCrash( EventData )
local EventPrefix = self:_GetPrefixFromGroupName(unit.GroupName) local EventPrefix = self:_GetPrefixFromGroupName(unit.GroupName)
if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group!
self:T2( { "Dead event: " .. EventPrefix } ) --self:T2(string.format("EventPrefix = %s | SpawnAliasPrefix = %s | Old AliveUnits = %d",EventPrefix or "",self.SpawnAliasPrefix or "",self.AliveUnits or 0))
self:T2(string.format("EventPrefix = %s | SpawnAliasPrefix = %s | Old AliveUnits = %d",EventPrefix or "",self.SpawnAliasPrefix or "",self.AliveUnits or 0))
if EventPrefix == self.SpawnTemplatePrefix or ( self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix ) and self.AliveUnits > 0 then if EventPrefix == self.SpawnTemplatePrefix or ( self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix ) and self.AliveUnits > 0 then
self.AliveUnits = self.AliveUnits - 1 --self:I( { "Dead event: " .. EventPrefix } )
--self.AliveUnits = self.AliveUnits - 1
self.AliveUnits = self:_CountAliveUnits()
--self:I( "New Alive Units: " .. self.AliveUnits )
end end
self:T2( "New Alive Units: " .. self.AliveUnits )
end end
end end
end end
@@ -3980,9 +4019,9 @@ function SPAWN:_OnTakeOff( EventData )
if SpawnGroup then if SpawnGroup then
local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup ) local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup )
if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group!
self:T2( { "TakeOff event: " .. EventPrefix } ) --self:T2( { "TakeOff event: " .. EventPrefix } )
if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then
self:T2( "self.Landed = false" ) --self:T2( "self.Landed = false" )
SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", false ) SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", false )
end end
end end
@@ -4000,13 +4039,13 @@ function SPAWN:_OnLand( EventData )
if SpawnGroup then if SpawnGroup then
local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup ) local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup )
if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group!
self:T2( { "Land event: " .. EventPrefix } ) --self:T2( { "Land event: " .. EventPrefix } )
if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then
-- TODO: Check if this is the last unit of the group that lands. -- TODO: Check if this is the last unit of the group that lands.
SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", true ) SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", true )
if self.RepeatOnLanding then if self.RepeatOnLanding then
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup ) local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
self:T2( { "Landed:", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } ) --self:T2( { "Landed:", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
-- self:ReSpawn( SpawnGroupIndex ) -- self:ReSpawn( SpawnGroupIndex )
-- Delay respawn by three seconds due to DCS 2.5.4.26368 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076 -- Delay respawn by three seconds due to DCS 2.5.4.26368 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076
-- Bug was initially only for engine shutdown event but after ED "fixed" it, it now happens on landing events. -- Bug was initially only for engine shutdown event but after ED "fixed" it, it now happens on landing events.
@@ -4029,13 +4068,13 @@ function SPAWN:_OnEngineShutDown( EventData )
if SpawnGroup then if SpawnGroup then
local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup ) local EventPrefix = self:_GetPrefixFromGroup( SpawnGroup )
if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group! if EventPrefix then -- EventPrefix can be nil if no # is found, which means, no spawnable group!
self:T2( { "EngineShutdown event: " .. EventPrefix } ) --self:T2( { "EngineShutdown event: " .. EventPrefix } )
if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then if EventPrefix == self.SpawnTemplatePrefix or (self.SpawnAliasPrefix and EventPrefix == self.SpawnAliasPrefix) then
-- todo: test if on the runway -- todo: test if on the runway
local Landed = SpawnGroup:GetState( SpawnGroup, "Spawn_Landed" ) local Landed = SpawnGroup:GetState( SpawnGroup, "Spawn_Landed" )
if Landed and self.RepeatOnEngineShutDown then if Landed and self.RepeatOnEngineShutDown then
local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup ) local SpawnGroupIndex = self:GetSpawnIndexFromGroup( SpawnGroup )
self:T2( { "EngineShutDown: ", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } ) --self:T2( { "EngineShutDown: ", "ReSpawn:", SpawnGroup:GetName(), SpawnGroupIndex } )
-- self:ReSpawn( SpawnGroupIndex ) -- self:ReSpawn( SpawnGroupIndex )
-- Delay respawn by three seconds due to DCS 2.5.4 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076 -- Delay respawn by three seconds due to DCS 2.5.4 OB bug https://github.com/FlightControl-Master/MOOSE/issues/1076
SCHEDULER:New( nil, self.ReSpawn, { self, SpawnGroupIndex }, 3 ) SCHEDULER:New( nil, self.ReSpawn, { self, SpawnGroupIndex }, 3 )
@@ -4064,7 +4103,7 @@ function SPAWN:_SpawnCleanUpScheduler()
--self:F( { "CleanUp Scheduler:", self.SpawnTemplatePrefix } ) --self:F( { "CleanUp Scheduler:", self.SpawnTemplatePrefix } )
local SpawnGroup, SpawnCursor = self:GetFirstAliveGroup() local SpawnGroup, SpawnCursor = self:GetFirstAliveGroup()
self:T2( { "CleanUp Scheduler:", SpawnGroup, SpawnCursor } ) --self:T2( { "CleanUp Scheduler:", SpawnGroup, SpawnCursor } )
local IsHelo = false local IsHelo = false
@@ -4081,7 +4120,7 @@ function SPAWN:_SpawnCleanUpScheduler()
self.SpawnCleanUpTimeStamps[SpawnUnitName] = self.SpawnCleanUpTimeStamps[SpawnUnitName] or {} self.SpawnCleanUpTimeStamps[SpawnUnitName] = self.SpawnCleanUpTimeStamps[SpawnUnitName] or {}
local Stamp = self.SpawnCleanUpTimeStamps[SpawnUnitName] local Stamp = self.SpawnCleanUpTimeStamps[SpawnUnitName]
self:T2( { SpawnUnitName, Stamp } ) --self:T2( { SpawnUnitName, Stamp } )
if Stamp.Vec2 then if Stamp.Vec2 then
if (SpawnUnit:InAir() == false and SpawnUnit:GetVelocityKMH() < 1) or IsHelo then if (SpawnUnit:InAir() == false and SpawnUnit:GetVelocityKMH() < 1) or IsHelo then
@@ -4089,7 +4128,7 @@ function SPAWN:_SpawnCleanUpScheduler()
if (Stamp.Vec2.x == NewVec2.x and Stamp.Vec2.y == NewVec2.y) or (SpawnUnit:GetLife() <= 1) then if (Stamp.Vec2.x == NewVec2.x and Stamp.Vec2.y == NewVec2.y) or (SpawnUnit:GetLife() <= 1) then
-- If the plane is not moving or dead , and is on the ground, assign it with a timestamp... -- If the plane is not moving or dead , and is on the ground, assign it with a timestamp...
if Stamp.Time + self.SpawnCleanUpInterval < timer.getTime() then if Stamp.Time + self.SpawnCleanUpInterval < timer.getTime() then
self:T2( { "CleanUp Scheduler:", "ReSpawning:", SpawnGroup:GetName() } ) --self:T2( { "CleanUp Scheduler:", "ReSpawning:", SpawnGroup:GetName() } )
--self:ReSpawn( SpawnCursor ) --self:ReSpawn( SpawnCursor )
SCHEDULER:New( nil, self.ReSpawn, { self, SpawnCursor }, 3 ) SCHEDULER:New( nil, self.ReSpawn, { self, SpawnCursor }, 3 )
Stamp.Vec2 = nil Stamp.Vec2 = nil
@@ -4118,7 +4157,7 @@ function SPAWN:_SpawnCleanUpScheduler()
SpawnGroup, SpawnCursor = self:GetNextAliveGroup( SpawnCursor ) SpawnGroup, SpawnCursor = self:GetNextAliveGroup( SpawnCursor )
self:T2( { "CleanUp Scheduler:", SpawnGroup, SpawnCursor } ) --self:T2( { "CleanUp Scheduler:", SpawnGroup, SpawnCursor } )
end end
+89 -89
View File
@@ -144,7 +144,7 @@ ZONE_BASE = {
-- @return #ZONE_BASE self -- @return #ZONE_BASE self
function ZONE_BASE:New( ZoneName ) function ZONE_BASE:New( ZoneName )
local self = BASE:Inherit( self, FSM:New() ) local self = BASE:Inherit( self, FSM:New() )
self:F( ZoneName ) --self:F( ZoneName )
self.ZoneName = ZoneName self.ZoneName = ZoneName
@@ -157,7 +157,7 @@ end
-- @param #ZONE_BASE self -- @param #ZONE_BASE self
-- @return #string The name of the zone. -- @return #string The name of the zone.
function ZONE_BASE:GetName() function ZONE_BASE:GetName()
self:F2() --self:F2()
return self.ZoneName return self.ZoneName
end end
@@ -167,7 +167,7 @@ end
-- @param #string ZoneName The name of the zone. -- @param #string ZoneName The name of the zone.
-- @return #ZONE_BASE -- @return #ZONE_BASE
function ZONE_BASE:SetName( ZoneName ) function ZONE_BASE:SetName( ZoneName )
self:F2() --self:F2()
self.ZoneName = ZoneName self.ZoneName = ZoneName
end end
@@ -177,7 +177,7 @@ end
-- @param DCS#Vec2 Vec2 The Vec2 to test. -- @param DCS#Vec2 Vec2 The Vec2 to test.
-- @return #boolean true if the Vec2 is within the zone. -- @return #boolean true if the Vec2 is within the zone.
function ZONE_BASE:IsVec2InZone( Vec2 ) function ZONE_BASE:IsVec2InZone( Vec2 )
self:F2( Vec2 ) --self:F2( Vec2 )
return false return false
end end
@@ -232,13 +232,13 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return Core.Point#POINT_VEC2 The PointVec2 of the zone. -- @return Core.Point#POINT_VEC2 The PointVec2 of the zone.
function ZONE_BASE:GetPointVec2() function ZONE_BASE:GetPointVec2()
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
local Vec2 = self:GetVec2() local Vec2 = self:GetVec2()
local PointVec2 = POINT_VEC2:NewFromVec2( Vec2 ) local PointVec2 = POINT_VEC2:NewFromVec2( Vec2 )
self:T2( { PointVec2 } ) --self:T2( { PointVec2 } )
return PointVec2 return PointVec2
end end
@@ -248,7 +248,7 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return DCS#Vec3 The Vec3 of the zone. -- @return DCS#Vec3 The Vec3 of the zone.
function ZONE_BASE:GetVec3( Height ) function ZONE_BASE:GetVec3( Height )
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
Height = Height or 0 Height = Height or 0
@@ -256,7 +256,7 @@ function ZONE_BASE:GetVec3( Height )
local Vec3 = { x = Vec2.x, y = Height and Height or land.getHeight( self:GetVec2() ), z = Vec2.y } local Vec3 = { x = Vec2.x, y = Height and Height or land.getHeight( self:GetVec2() ), z = Vec2.y }
self:T2( { Vec3 } ) --self:T2( { Vec3 } )
return Vec3 return Vec3
end end
@@ -266,13 +266,13 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return Core.Point#POINT_VEC3 The PointVec3 of the zone. -- @return Core.Point#POINT_VEC3 The PointVec3 of the zone.
function ZONE_BASE:GetPointVec3( Height ) function ZONE_BASE:GetPointVec3( Height )
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
local Vec3 = self:GetVec3( Height ) local Vec3 = self:GetVec3( Height )
local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 ) local PointVec3 = POINT_VEC3:NewFromVec3( Vec3 )
self:T2( { PointVec3 } ) --self:T2( { PointVec3 } )
return PointVec3 return PointVec3
end end
@@ -282,7 +282,7 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return Core.Point#COORDINATE The Coordinate of the zone. -- @return Core.Point#COORDINATE The Coordinate of the zone.
function ZONE_BASE:GetCoordinate( Height ) --R2.1 function ZONE_BASE:GetCoordinate( Height ) --R2.1
self:F2(self.ZoneName) --self:F2(self.ZoneName)
local Vec3 = self:GetVec3( Height ) local Vec3 = self:GetVec3( Height )
@@ -363,7 +363,7 @@ end
--- Bound the zone boundaries with a tires. --- Bound the zone boundaries with a tires.
-- @param #ZONE_BASE self -- @param #ZONE_BASE self
function ZONE_BASE:BoundZone() function ZONE_BASE:BoundZone()
self:F2() --self:F2()
end end
--- Set draw coalition of zone. --- Set draw coalition of zone.
@@ -510,7 +510,7 @@ end
-- @param #ZONE_BASE self -- @param #ZONE_BASE self
-- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color. -- @param Utilities.Utils#SMOKECOLOR SmokeColor The smoke color.
function ZONE_BASE:SmokeZone( SmokeColor ) function ZONE_BASE:SmokeZone( SmokeColor )
self:F2( SmokeColor ) --self:F2( SmokeColor )
end end
@@ -519,7 +519,7 @@ end
-- @param #number ZoneProbability A value between 0 and 1. 0 = 0% and 1 = 100% probability. -- @param #number ZoneProbability A value between 0 and 1. 0 = 0% and 1 = 100% probability.
-- @return #ZONE_BASE self -- @return #ZONE_BASE self
function ZONE_BASE:SetZoneProbability( ZoneProbability ) function ZONE_BASE:SetZoneProbability( ZoneProbability )
self:F( { self:GetName(), ZoneProbability = ZoneProbability } ) --self:F( { self:GetName(), ZoneProbability = ZoneProbability } )
self.ZoneProbability = ZoneProbability or 1 self.ZoneProbability = ZoneProbability or 1
return self return self
@@ -529,7 +529,7 @@ end
-- @param #ZONE_BASE self -- @param #ZONE_BASE self
-- @return #number A value between 0 and 1. 0 = 0% and 1 = 100% probability. -- @return #number A value between 0 and 1. 0 = 0% and 1 = 100% probability.
function ZONE_BASE:GetZoneProbability() function ZONE_BASE:GetZoneProbability()
self:F2() --self:F2()
return self.ZoneProbability return self.ZoneProbability
end end
@@ -560,7 +560,7 @@ end
-- -- The result should be that Zone1 would be more probable selected than Zone2. -- -- The result should be that Zone1 would be more probable selected than Zone2.
-- --
function ZONE_BASE:GetZoneMaybe() function ZONE_BASE:GetZoneMaybe()
self:F2() --self:F2()
local Randomization = math.random() local Randomization = math.random()
if Randomization <= self.ZoneProbability then if Randomization <= self.ZoneProbability then
@@ -791,7 +791,7 @@ function ZONE_RADIUS:New( ZoneName, Vec2, Radius, DoNotRegisterZone )
-- Inherit ZONE_BASE. -- Inherit ZONE_BASE.
local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) -- #ZONE_RADIUS local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) -- #ZONE_RADIUS
self:F( { ZoneName, Vec2, Radius } ) --self:F( { ZoneName, Vec2, Radius } )
self.Radius = Radius self.Radius = Radius
self.Vec2 = Vec2 self.Vec2 = Vec2
@@ -947,7 +947,7 @@ end
-- @param #number AddOffSet (optional) The angle to be added for the smoking start position. -- @param #number AddOffSet (optional) The angle to be added for the smoking start position.
-- @return #ZONE_RADIUS self -- @return #ZONE_RADIUS self
function ZONE_RADIUS:SmokeZone( SmokeColor, Points, AddHeight, AngleOffset ) function ZONE_RADIUS:SmokeZone( SmokeColor, Points, AddHeight, AngleOffset )
self:F2( SmokeColor ) --self:F2( SmokeColor )
local Point = {} local Point = {}
local Vec2 = self:GetVec2() local Vec2 = self:GetVec2()
@@ -978,7 +978,7 @@ end
-- @param #number AddHeight (optional) The height to be added for the smoke. -- @param #number AddHeight (optional) The height to be added for the smoke.
-- @return #ZONE_RADIUS self -- @return #ZONE_RADIUS self
function ZONE_RADIUS:FlareZone( FlareColor, Points, Azimuth, AddHeight ) function ZONE_RADIUS:FlareZone( FlareColor, Points, Azimuth, AddHeight )
self:F2( { FlareColor, Azimuth } ) --self:F2( { FlareColor, Azimuth } )
local Point = {} local Point = {}
local Vec2 = self:GetVec2() local Vec2 = self:GetVec2()
@@ -1004,9 +1004,9 @@ end
-- @param #ZONE_RADIUS self -- @param #ZONE_RADIUS self
-- @return DCS#Distance The radius of the zone. -- @return DCS#Distance The radius of the zone.
function ZONE_RADIUS:GetRadius() function ZONE_RADIUS:GetRadius()
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
self:T2( { self.Radius } ) --self:T2( { self.Radius } )
return self.Radius return self.Radius
end end
@@ -1016,10 +1016,10 @@ end
-- @param DCS#Distance Radius The radius of the zone. -- @param DCS#Distance Radius The radius of the zone.
-- @return DCS#Distance The radius of the zone. -- @return DCS#Distance The radius of the zone.
function ZONE_RADIUS:SetRadius( Radius ) function ZONE_RADIUS:SetRadius( Radius )
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
self.Radius = Radius self.Radius = Radius
self:T2( { self.Radius } ) --self:T2( { self.Radius } )
return self.Radius return self.Radius
end end
@@ -1028,9 +1028,9 @@ end
-- @param #ZONE_RADIUS self -- @param #ZONE_RADIUS self
-- @return DCS#Vec2 The location of the zone. -- @return DCS#Vec2 The location of the zone.
function ZONE_RADIUS:GetVec2() function ZONE_RADIUS:GetVec2()
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
self:T2( { self.Vec2 } ) --self:T2( { self.Vec2 } )
return self.Vec2 return self.Vec2
end end
@@ -1040,11 +1040,11 @@ end
-- @param DCS#Vec2 Vec2 The new location of the zone. -- @param DCS#Vec2 Vec2 The new location of the zone.
-- @return DCS#Vec2 The new location of the zone. -- @return DCS#Vec2 The new location of the zone.
function ZONE_RADIUS:SetVec2( Vec2 ) function ZONE_RADIUS:SetVec2( Vec2 )
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
self.Vec2 = Vec2 self.Vec2 = Vec2
self:T2( { self.Vec2 } ) --self:T2( { self.Vec2 } )
return self.Vec2 return self.Vec2
end end
@@ -1054,14 +1054,14 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return DCS#Vec3 The point of the zone. -- @return DCS#Vec3 The point of the zone.
function ZONE_RADIUS:GetVec3( Height ) function ZONE_RADIUS:GetVec3( Height )
self:F2( { self.ZoneName, Height } ) --self:F2( { self.ZoneName, Height } )
Height = Height or 0 Height = Height or 0
local Vec2 = self:GetVec2() local Vec2 = self:GetVec2()
local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y } local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y }
self:T2( { Vec3 } ) --self:T2( { Vec3 } )
return Vec3 return Vec3
end end
@@ -1138,7 +1138,7 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories )
self.ScanData.Units[ZoneObject] = ZoneObject self.ScanData.Units[ZoneObject] = ZoneObject
self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } ) --self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
end end
end end
@@ -1149,7 +1149,7 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories )
self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {} self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {}
self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( tostring(SceneryName), ZoneObject) self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( tostring(SceneryName), ZoneObject)
table.insert(self.ScanData.SceneryTable,self.ScanData.Scenery[SceneryType][SceneryName] ) table.insert(self.ScanData.SceneryTable,self.ScanData.Scenery[SceneryType][SceneryName] )
self:T( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } ) --self:T( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } )
end end
end end
@@ -1409,7 +1409,7 @@ function ZONE_RADIUS:SearchZone( EvaluateFunction, ObjectCategories )
local ZoneCoord = self:GetCoordinate() local ZoneCoord = self:GetCoordinate()
local ZoneRadius = self:GetRadius() local ZoneRadius = self:GetRadius()
self:F({ZoneCoord = ZoneCoord, ZoneRadius = ZoneRadius, ZoneCoordLL = ZoneCoord:ToStringLLDMS()}) --self:F({ZoneCoord = ZoneCoord, ZoneRadius = ZoneRadius, ZoneCoordLL = ZoneCoord:ToStringLLDMS()})
local SphereSearch = { local SphereSearch = {
id = world.VolumeType.SPHERE, id = world.VolumeType.SPHERE,
@@ -1436,7 +1436,7 @@ end
-- @param DCS#Vec2 Vec2 The location to test. -- @param DCS#Vec2 Vec2 The location to test.
-- @return #boolean true if the location is within the zone. -- @return #boolean true if the location is within the zone.
function ZONE_RADIUS:IsVec2InZone( Vec2 ) function ZONE_RADIUS:IsVec2InZone( Vec2 )
self:F2( Vec2 ) --self:F2( Vec2 )
if not Vec2 then return false end if not Vec2 then return false end
@@ -1456,7 +1456,7 @@ end
-- @param DCS#Vec3 Vec3 The point to test. -- @param DCS#Vec3 Vec3 The point to test.
-- @return #boolean true if the point is within the zone. -- @return #boolean true if the point is within the zone.
function ZONE_RADIUS:IsVec3InZone( Vec3 ) function ZONE_RADIUS:IsVec3InZone( Vec3 )
self:F2( Vec3 ) --self:F2( Vec3 )
if not Vec3 then return false end if not Vec3 then return false end
local InZone = self:IsVec2InZone( { x = Vec3.x, y = Vec3.z } ) local InZone = self:IsVec2InZone( { x = Vec3.x, y = Vec3.z } )
@@ -1521,11 +1521,11 @@ end
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone. -- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
-- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone. -- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone.
function ZONE_RADIUS:GetRandomPointVec2( inner, outer ) function ZONE_RADIUS:GetRandomPointVec2( inner, outer )
self:F( self.ZoneName, inner, outer ) --self:F( self.ZoneName, inner, outer )
local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2( inner, outer ) ) local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2( inner, outer ) )
self:T3( { PointVec2 } ) --self:T3( { PointVec2 } )
return PointVec2 return PointVec2
end end
@@ -1536,11 +1536,11 @@ end
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone. -- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
-- @return DCS#Vec3 The random location within the zone. -- @return DCS#Vec3 The random location within the zone.
function ZONE_RADIUS:GetRandomVec3( inner, outer ) function ZONE_RADIUS:GetRandomVec3( inner, outer )
self:F( self.ZoneName, inner, outer ) --self:F( self.ZoneName, inner, outer )
local Vec2 = self:GetRandomVec2( inner, outer ) local Vec2 = self:GetRandomVec2( inner, outer )
self:T3( { x = Vec2.x, y = self.y, z = Vec2.y } ) --self:T3( { x = Vec2.x, y = self.y, z = Vec2.y } )
return { x = Vec2.x, y = self.y, z = Vec2.y } return { x = Vec2.x, y = self.y, z = Vec2.y }
end end
@@ -1552,11 +1552,11 @@ end
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone. -- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
-- @return Core.Point#POINT_VEC3 The @{Core.Point#POINT_VEC3} object reflecting the random 3D location within the zone. -- @return Core.Point#POINT_VEC3 The @{Core.Point#POINT_VEC3} object reflecting the random 3D location within the zone.
function ZONE_RADIUS:GetRandomPointVec3( inner, outer ) function ZONE_RADIUS:GetRandomPointVec3( inner, outer )
self:F( self.ZoneName, inner, outer ) --self:F( self.ZoneName, inner, outer )
local PointVec3 = POINT_VEC3:NewFromVec2( self:GetRandomVec2( inner, outer ) ) local PointVec3 = POINT_VEC3:NewFromVec2( self:GetRandomVec2( inner, outer ) )
self:T3( { PointVec3 } ) --self:T3( { PointVec3 } )
return PointVec3 return PointVec3
end end
@@ -1685,7 +1685,7 @@ function ZONE_RADIUS:GetRandomCoordinateWithoutBuildings(inner,outer,distance,ma
T1=timer.getTime() T1=timer.getTime()
self:T(string.format("Found a coordinate: %s | Iterations: %d | Time: %.3f",tostring(found),iterations,T1-T0)) --self:T(string.format("Found a coordinate: %s | Iterations: %d | Time: %.3f",tostring(found),iterations,T1-T0))
if found then return rcoord else return nil end if found then return rcoord else return nil end
@@ -1754,7 +1754,7 @@ function ZONE:New( ZoneName )
-- Create a new ZONE_RADIUS. -- Create a new ZONE_RADIUS.
local self=BASE:Inherit( self, ZONE_RADIUS:New(ZoneName, {x=Zone.point.x, y=Zone.point.z}, Zone.radius, true)) local self=BASE:Inherit( self, ZONE_RADIUS:New(ZoneName, {x=Zone.point.x, y=Zone.point.z}, Zone.radius, true))
self:F(ZoneName) --self:F(ZoneName)
-- Color of zone. -- Color of zone.
self.Color={1, 0, 0, 0.15} self.Color={1, 0, 0, 0.15}
@@ -1824,7 +1824,7 @@ function ZONE_UNIT:New( ZoneName, ZoneUNIT, Radius, Offset)
self.relative_to_unit = Offset.relative_to_unit or false self.relative_to_unit = Offset.relative_to_unit or false
end end
self:F( { ZoneName, ZoneUNIT:GetVec2(), Radius } ) --self:F( { ZoneName, ZoneUNIT:GetVec2(), Radius } )
self.ZoneUNIT = ZoneUNIT self.ZoneUNIT = ZoneUNIT
self.LastVec2 = ZoneUNIT:GetVec2() self.LastVec2 = ZoneUNIT:GetVec2()
@@ -1840,7 +1840,7 @@ end
-- @param #ZONE_UNIT self -- @param #ZONE_UNIT self
-- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Unit#UNIT}location and the offset, if any. -- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Unit#UNIT}location and the offset, if any.
function ZONE_UNIT:GetVec2() function ZONE_UNIT:GetVec2()
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
local ZoneVec2 = self.ZoneUNIT:GetVec2() local ZoneVec2 = self.ZoneUNIT:GetVec2()
if ZoneVec2 then if ZoneVec2 then
@@ -1873,7 +1873,7 @@ function ZONE_UNIT:GetVec2()
return self.LastVec2 return self.LastVec2
end end
self:T2( { ZoneVec2 } ) --self:T2( { ZoneVec2 } )
return nil return nil
end end
@@ -1882,7 +1882,7 @@ end
-- @param #ZONE_UNIT self -- @param #ZONE_UNIT self
-- @return DCS#Vec2 The random location within the zone. -- @return DCS#Vec2 The random location within the zone.
function ZONE_UNIT:GetRandomVec2() function ZONE_UNIT:GetRandomVec2()
self:F( self.ZoneName ) --self:F( self.ZoneName )
local RandomVec2 = {} local RandomVec2 = {}
--local Vec2 = self.ZoneUNIT:GetVec2() -- FF: This does not take care of the new offset feature! --local Vec2 = self.ZoneUNIT:GetVec2() -- FF: This does not take care of the new offset feature!
@@ -1896,7 +1896,7 @@ function ZONE_UNIT:GetRandomVec2()
RandomVec2.x = Vec2.x + math.cos( angle ) * math.random() * self:GetRadius(); RandomVec2.x = Vec2.x + math.cos( angle ) * math.random() * self:GetRadius();
RandomVec2.y = Vec2.y + math.sin( angle ) * math.random() * self:GetRadius(); RandomVec2.y = Vec2.y + math.sin( angle ) * math.random() * self:GetRadius();
self:T( { RandomVec2 } ) --self:T( { RandomVec2 } )
return RandomVec2 return RandomVec2
end end
@@ -1906,7 +1906,7 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located. -- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return DCS#Vec3 The point of the zone. -- @return DCS#Vec3 The point of the zone.
function ZONE_UNIT:GetVec3( Height ) function ZONE_UNIT:GetVec3( Height )
self:F2( self.ZoneName ) --self:F2( self.ZoneName )
Height = Height or 0 Height = Height or 0
@@ -1914,7 +1914,7 @@ function ZONE_UNIT:GetVec3( Height )
local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y } local Vec3 = { x = Vec2.x, y = land.getHeight( self:GetVec2() ) + Height, z = Vec2.y }
self:T2( { Vec3 } ) --self:T2( { Vec3 } )
return Vec3 return Vec3
end end
@@ -1940,7 +1940,7 @@ ZONE_GROUP = {
-- @return #ZONE_GROUP self -- @return #ZONE_GROUP self
function ZONE_GROUP:New( ZoneName, ZoneGROUP, Radius ) function ZONE_GROUP:New( ZoneName, ZoneGROUP, Radius )
local self = BASE:Inherit( self, ZONE_RADIUS:New( ZoneName, ZoneGROUP:GetVec2(), Radius, true ) ) local self = BASE:Inherit( self, ZONE_RADIUS:New( ZoneName, ZoneGROUP:GetVec2(), Radius, true ) )
self:F( { ZoneName, ZoneGROUP:GetVec2(), Radius } ) --self:F( { ZoneName, ZoneGROUP:GetVec2(), Radius } )
self._.ZoneGROUP = ZoneGROUP self._.ZoneGROUP = ZoneGROUP
self._.ZoneVec2Cache = self._.ZoneGROUP:GetVec2() self._.ZoneVec2Cache = self._.ZoneGROUP:GetVec2()
@@ -1956,7 +1956,7 @@ end
-- @param #ZONE_GROUP self -- @param #ZONE_GROUP self
-- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Group} location. -- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Group} location.
function ZONE_GROUP:GetVec2() function ZONE_GROUP:GetVec2()
self:F( self.ZoneName ) --self:F( self.ZoneName )
local ZoneVec2 = nil local ZoneVec2 = nil
@@ -1967,7 +1967,7 @@ function ZONE_GROUP:GetVec2()
ZoneVec2 = self._.ZoneVec2Cache ZoneVec2 = self._.ZoneVec2Cache
end end
self:T( { ZoneVec2 } ) --self:T( { ZoneVec2 } )
return ZoneVec2 return ZoneVec2
end end
@@ -1976,7 +1976,7 @@ end
-- @param #ZONE_GROUP self -- @param #ZONE_GROUP self
-- @return DCS#Vec2 The random location of the zone based on the @{Wrapper.Group} location. -- @return DCS#Vec2 The random location of the zone based on the @{Wrapper.Group} location.
function ZONE_GROUP:GetRandomVec2() function ZONE_GROUP:GetRandomVec2()
self:F( self.ZoneName ) --self:F( self.ZoneName )
local Point = {} local Point = {}
local Vec2 = self._.ZoneGROUP:GetVec2() local Vec2 = self._.ZoneGROUP:GetVec2()
@@ -1985,7 +1985,7 @@ function ZONE_GROUP:GetRandomVec2()
Point.x = Vec2.x + math.cos( angle ) * math.random() * self:GetRadius(); Point.x = Vec2.x + math.cos( angle ) * math.random() * self:GetRadius();
Point.y = Vec2.y + math.sin( angle ) * math.random() * self:GetRadius(); Point.y = Vec2.y + math.sin( angle ) * math.random() * self:GetRadius();
self:T( { Point } ) --self:T( { Point } )
return Point return Point
end end
@@ -1996,11 +1996,11 @@ end
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone. -- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
-- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone. -- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone.
function ZONE_GROUP:GetRandomPointVec2( inner, outer ) function ZONE_GROUP:GetRandomPointVec2( inner, outer )
self:F( self.ZoneName, inner, outer ) --self:F( self.ZoneName, inner, outer )
local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() ) local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() )
self:T3( { PointVec2 } ) --self:T3( { PointVec2 } )
return PointVec2 return PointVec2
end end
@@ -2183,7 +2183,7 @@ function ZONE_POLYGON_BASE:New( ZoneName, PointsArray )
-- Inherit ZONE_BASE. -- Inherit ZONE_BASE.
local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) )
self:F( { ZoneName, PointsArray } ) --self:F( { ZoneName, PointsArray } )
if PointsArray then if PointsArray then
@@ -2351,7 +2351,7 @@ end
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Group} location. -- @return DCS#Vec2 The location of the zone based on the @{Wrapper.Group} location.
function ZONE_POLYGON_BASE:GetVec2() function ZONE_POLYGON_BASE:GetVec2()
self:F( self.ZoneName ) --self:F( self.ZoneName )
local Bounds = self:GetBoundingSquare() local Bounds = self:GetBoundingSquare()
@@ -2434,9 +2434,9 @@ end
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @return #ZONE_POLYGON_BASE self -- @return #ZONE_POLYGON_BASE self
function ZONE_POLYGON_BASE:Flush() function ZONE_POLYGON_BASE:Flush()
self:F2() --self:F2()
self:F( { Polygon = self.ZoneName, Coordinates = self._.Polygon } ) --self:F( { Polygon = self.ZoneName, Coordinates = self._.Polygon } )
return self return self
end end
@@ -2455,7 +2455,7 @@ function ZONE_POLYGON_BASE:BoundZone( UnBound )
j = #self._.Polygon j = #self._.Polygon
while i <= #self._.Polygon do while i <= #self._.Polygon do
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } ) --self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x
local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y
@@ -2707,7 +2707,7 @@ end
-- @param #number Segments (Optional) Number of segments within boundary line. Default 10. -- @param #number Segments (Optional) Number of segments within boundary line. Default 10.
-- @return #ZONE_POLYGON_BASE self -- @return #ZONE_POLYGON_BASE self
function ZONE_POLYGON_BASE:SmokeZone( SmokeColor, Segments ) function ZONE_POLYGON_BASE:SmokeZone( SmokeColor, Segments )
self:F2( SmokeColor ) --self:F2( SmokeColor )
Segments=Segments or 10 Segments=Segments or 10
@@ -2715,7 +2715,7 @@ function ZONE_POLYGON_BASE:SmokeZone( SmokeColor, Segments )
local j=#self._.Polygon local j=#self._.Polygon
while i <= #self._.Polygon do while i <= #self._.Polygon do
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } ) --self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x
local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y
@@ -2740,7 +2740,7 @@ end
-- @param #number AddHeight (optional) The height to be added for the smoke. -- @param #number AddHeight (optional) The height to be added for the smoke.
-- @return #ZONE_POLYGON_BASE self -- @return #ZONE_POLYGON_BASE self
function ZONE_POLYGON_BASE:FlareZone( FlareColor, Segments, Azimuth, AddHeight ) function ZONE_POLYGON_BASE:FlareZone( FlareColor, Segments, Azimuth, AddHeight )
self:F2(FlareColor) --self:F2(FlareColor)
Segments=Segments or 10 Segments=Segments or 10
@@ -2750,7 +2750,7 @@ function ZONE_POLYGON_BASE:FlareZone( FlareColor, Segments, Azimuth, AddHeight )
local j=#self._.Polygon local j=#self._.Polygon
while i <= #self._.Polygon do while i <= #self._.Polygon do
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } ) --self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x
local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y
@@ -2773,7 +2773,7 @@ end
-- @param DCS#Vec2 Vec2 The location to test. -- @param DCS#Vec2 Vec2 The location to test.
-- @return #boolean true if the location is within the zone. -- @return #boolean true if the location is within the zone.
function ZONE_POLYGON_BASE:IsVec2InZone( Vec2 ) function ZONE_POLYGON_BASE:IsVec2InZone( Vec2 )
self:F2( Vec2 ) --self:F2( Vec2 )
if not Vec2 then return false end if not Vec2 then return false end
local Next local Next
local Prev local Prev
@@ -2783,18 +2783,18 @@ function ZONE_POLYGON_BASE:IsVec2InZone( Vec2 )
Prev = #self._.Polygon Prev = #self._.Polygon
while Next <= #self._.Polygon do while Next <= #self._.Polygon do
self:T( { Next, Prev, self._.Polygon[Next], self._.Polygon[Prev] } ) --self:T( { Next, Prev, self._.Polygon[Next], self._.Polygon[Prev] } )
if ( ( ( self._.Polygon[Next].y > Vec2.y ) ~= ( self._.Polygon[Prev].y > Vec2.y ) ) and if ( ( ( self._.Polygon[Next].y > Vec2.y ) ~= ( self._.Polygon[Prev].y > Vec2.y ) ) and
( Vec2.x < ( self._.Polygon[Prev].x - self._.Polygon[Next].x ) * ( Vec2.y - self._.Polygon[Next].y ) / ( self._.Polygon[Prev].y - self._.Polygon[Next].y ) + self._.Polygon[Next].x ) ( Vec2.x < ( self._.Polygon[Prev].x - self._.Polygon[Next].x ) * ( Vec2.y - self._.Polygon[Next].y ) / ( self._.Polygon[Prev].y - self._.Polygon[Next].y ) + self._.Polygon[Next].x )
) then ) then
InPolygon = not InPolygon InPolygon = not InPolygon
end end
self:T2( { InPolygon = InPolygon } ) --self:T2( { InPolygon = InPolygon } )
Prev = Next Prev = Next
Next = Next + 1 Next = Next + 1
end end
self:T( { InPolygon = InPolygon } ) --self:T( { InPolygon = InPolygon } )
return InPolygon return InPolygon
end end
@@ -2803,7 +2803,7 @@ end
-- @param DCS#Vec3 Vec3 The point to test. -- @param DCS#Vec3 Vec3 The point to test.
-- @return #boolean true if the point is within the zone. -- @return #boolean true if the point is within the zone.
function ZONE_POLYGON_BASE:IsVec3InZone( Vec3 ) function ZONE_POLYGON_BASE:IsVec3InZone( Vec3 )
self:F2( Vec3 ) --self:F2( Vec3 )
if not Vec3 then return false end if not Vec3 then return false end
@@ -2838,11 +2838,11 @@ end
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @return @{Core.Point#POINT_VEC2} -- @return @{Core.Point#POINT_VEC2}
function ZONE_POLYGON_BASE:GetRandomPointVec2() function ZONE_POLYGON_BASE:GetRandomPointVec2()
self:F2() --self:F2()
local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() ) local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() )
self:T2( PointVec2 ) --self:T2( PointVec2 )
return PointVec2 return PointVec2
end end
@@ -2851,11 +2851,11 @@ end
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @return @{Core.Point#POINT_VEC3} -- @return @{Core.Point#POINT_VEC3}
function ZONE_POLYGON_BASE:GetRandomPointVec3() function ZONE_POLYGON_BASE:GetRandomPointVec3()
self:F2() --self:F2()
local PointVec3 = POINT_VEC3:NewFromVec2( self:GetRandomVec2() ) local PointVec3 = POINT_VEC3:NewFromVec2( self:GetRandomVec2() )
self:T2( PointVec3 ) --self:T2( PointVec3 )
return PointVec3 return PointVec3
end end
@@ -2865,11 +2865,11 @@ end
-- @param #ZONE_POLYGON_BASE self -- @param #ZONE_POLYGON_BASE self
-- @return Core.Point#COORDINATE -- @return Core.Point#COORDINATE
function ZONE_POLYGON_BASE:GetRandomCoordinate() function ZONE_POLYGON_BASE:GetRandomCoordinate()
self:F2() --self:F2()
local Coordinate = COORDINATE:NewFromVec2( self:GetRandomVec2() ) local Coordinate = COORDINATE:NewFromVec2( self:GetRandomVec2() )
self:T2( Coordinate ) --self:T2( Coordinate )
return Coordinate return Coordinate
end end
@@ -2886,7 +2886,7 @@ function ZONE_POLYGON_BASE:GetBoundingSquare()
local y2 = self._.Polygon[1].y local y2 = self._.Polygon[1].y
for i = 2, #self._.Polygon do for i = 2, #self._.Polygon do
self:T2( { self._.Polygon[i], x1, y1, x2, y2 } ) --self:T2( { self._.Polygon[i], x1, y1, x2, y2 } )
x1 = ( x1 > self._.Polygon[i].x ) and self._.Polygon[i].x or x1 x1 = ( x1 > self._.Polygon[i].x ) and self._.Polygon[i].x or x1
x2 = ( x2 < self._.Polygon[i].x ) and self._.Polygon[i].x or x2 x2 = ( x2 < self._.Polygon[i].x ) and self._.Polygon[i].x or x2
y1 = ( y1 > self._.Polygon[i].y ) and self._.Polygon[i].y or y1 y1 = ( y1 > self._.Polygon[i].y ) and self._.Polygon[i].y or y1
@@ -2909,7 +2909,7 @@ function ZONE_POLYGON_BASE:GetBoundingVec2()
local y2 = self._.Polygon[1].y local y2 = self._.Polygon[1].y
for i = 2, #self._.Polygon do for i = 2, #self._.Polygon do
self:T2( { self._.Polygon[i], x1, y1, x2, y2 } ) --self:T2( { self._.Polygon[i], x1, y1, x2, y2 } )
x1 = ( x1 > self._.Polygon[i].x ) and self._.Polygon[i].x or x1 x1 = ( x1 > self._.Polygon[i].x ) and self._.Polygon[i].x or x1
x2 = ( x2 < self._.Polygon[i].x ) and self._.Polygon[i].x or x2 x2 = ( x2 < self._.Polygon[i].x ) and self._.Polygon[i].x or x2
y1 = ( y1 > self._.Polygon[i].y ) and self._.Polygon[i].y or y1 y1 = ( y1 > self._.Polygon[i].y ) and self._.Polygon[i].y or y1
@@ -2948,7 +2948,7 @@ function ZONE_POLYGON_BASE:Boundary(Coalition, Color, Radius, Alpha, Segments, C
Limit = #self._.Polygon Limit = #self._.Polygon
end end
while i <= #self._.Polygon do while i <= #self._.Polygon do
self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } ) --self:T( { i, j, self._.Polygon[i], self._.Polygon[j] } )
if j ~= Limit then if j ~= Limit then
local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x local DeltaX = self._.Polygon[j].x - self._.Polygon[i].x
local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y local DeltaY = self._.Polygon[j].y - self._.Polygon[i].y
@@ -3019,7 +3019,7 @@ function ZONE_POLYGON:New( ZoneName, ZoneGroup )
local GroupPoints = ZoneGroup:GetTaskRoute() local GroupPoints = ZoneGroup:GetTaskRoute()
local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( ZoneName, GroupPoints ) ) local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( ZoneName, GroupPoints ) )
self:F( { ZoneName, ZoneGroup, self._.Polygon } ) --self:F( { ZoneName, ZoneGroup, self._.Polygon } )
-- Zone objects are added to the _DATABASE and SET_ZONE objects. -- Zone objects are added to the _DATABASE and SET_ZONE objects.
_EVENTDISPATCHER:CreateEventNewZone( self ) _EVENTDISPATCHER:CreateEventNewZone( self )
@@ -3035,7 +3035,7 @@ end
function ZONE_POLYGON:NewFromPointsArray( ZoneName, PointsArray ) function ZONE_POLYGON:NewFromPointsArray( ZoneName, PointsArray )
local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( ZoneName, PointsArray ) ) local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( ZoneName, PointsArray ) )
self:F( { ZoneName, self._.Polygon } ) --self:F( { ZoneName, self._.Polygon } )
-- Zone objects are added to the _DATABASE and SET_ZONE objects. -- Zone objects are added to the _DATABASE and SET_ZONE objects.
_EVENTDISPATCHER:CreateEventNewZone( self ) _EVENTDISPATCHER:CreateEventNewZone( self )
@@ -3055,7 +3055,7 @@ function ZONE_POLYGON:NewFromGroupName( GroupName )
local GroupPoints = ZoneGroup:GetTaskRoute() local GroupPoints = ZoneGroup:GetTaskRoute()
local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( GroupName, GroupPoints ) ) local self = BASE:Inherit( self, ZONE_POLYGON_BASE:New( GroupName, GroupPoints ) )
self:F( { GroupName, ZoneGroup, self._.Polygon } ) --self:F( { GroupName, ZoneGroup, self._.Polygon } )
-- Zone objects are added to the _DATABASE and SET_ZONE objects. -- Zone objects are added to the _DATABASE and SET_ZONE objects.
_EVENTDISPATCHER:CreateEventNewZone( self ) _EVENTDISPATCHER:CreateEventNewZone( self )
@@ -3221,7 +3221,7 @@ function ZONE_POLYGON:Scan( ObjectCategories, UnitCategories )
self.ScanData.Units[ZoneObject] = ZoneObject self.ScanData.Units[ZoneObject] = ZoneObject
self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } ) --self:F2( { Name = ZoneObject:getName(), Coalition = CoalitionDCSUnit } )
end end
end end
@@ -3232,7 +3232,7 @@ function ZONE_POLYGON:Scan( ObjectCategories, UnitCategories )
self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {} self.ScanData.Scenery[SceneryType] = self.ScanData.Scenery[SceneryType] or {}
self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( SceneryName, ZoneObject ) self.ScanData.Scenery[SceneryType][SceneryName] = SCENERY:Register( SceneryName, ZoneObject )
table.insert(self.ScanData.SceneryTable,self.ScanData.Scenery[SceneryType][SceneryName]) table.insert(self.ScanData.SceneryTable,self.ScanData.Scenery[SceneryType][SceneryName])
self:T( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } ) --self:T( { SCENERY = self.ScanData.Scenery[SceneryType][SceneryName] } )
end end
end end
@@ -3573,7 +3573,7 @@ do -- ZONE_ELASTIC
function ZONE_ELASTIC:Update(Delay, Draw) function ZONE_ELASTIC:Update(Delay, Draw)
-- Debug info. -- Debug info.
self:T(string.format("Updating ZONE_ELASTIC %s", tostring(self.ZoneName))) --self:T(string.format("Updating ZONE_ELASTIC %s", tostring(self.ZoneName)))
-- Copy all points. -- Copy all points.
local points=UTILS.DeepCopy(self.points or {}) local points=UTILS.DeepCopy(self.points or {})
@@ -3987,7 +3987,7 @@ do -- ZONE_AIRBASE
-- @param #ZONE_AIRBASE self -- @param #ZONE_AIRBASE self
-- @return DCS#Vec2 The location of the zone based on the AIRBASE location. -- @return DCS#Vec2 The location of the zone based on the AIRBASE location.
function ZONE_AIRBASE:GetVec2() function ZONE_AIRBASE:GetVec2()
self:F( self.ZoneName ) --self:F( self.ZoneName )
local ZoneVec2 = nil local ZoneVec2 = nil
@@ -3998,7 +3998,7 @@ do -- ZONE_AIRBASE
ZoneVec2 = self._.ZoneVec2Cache ZoneVec2 = self._.ZoneVec2Cache
end end
self:T( { ZoneVec2 } ) --self:T( { ZoneVec2 } )
return ZoneVec2 return ZoneVec2
end end
@@ -4009,11 +4009,11 @@ do -- ZONE_AIRBASE
-- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone. -- @param #number outer (optional) Maximal distance from the outer edge of the zone. Default is the radius of the zone.
-- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone. -- @return Core.Point#POINT_VEC2 The @{Core.Point#POINT_VEC2} object reflecting the random 3D location within the zone.
function ZONE_AIRBASE:GetRandomPointVec2( inner, outer ) function ZONE_AIRBASE:GetRandomPointVec2( inner, outer )
self:F( self.ZoneName, inner, outer ) --self:F( self.ZoneName, inner, outer )
local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() ) local PointVec2 = POINT_VEC2:NewFromVec2( self:GetRandomVec2() )
self:T3( { PointVec2 } ) --self:T3( { PointVec2 } )
return PointVec2 return PointVec2
end end
+97 -97
View File
@@ -367,7 +367,7 @@ function GROUP:GetDCSObject()
return DCSGroup return DCSGroup
end end
self:T2(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.GroupName))) self:E(string.format("ERROR: Could not get DCS group object of group %s because DCS object could not be found!", tostring(self.GroupName)))
return nil return nil
end end
@@ -375,7 +375,7 @@ end
-- @param Wrapper.Positionable#POSITIONABLE self -- @param Wrapper.Positionable#POSITIONABLE self
-- @return DCS#Position The 3D position vectors of the POSITIONABLE or #nil if the groups not existing or alive. -- @return DCS#Position The 3D position vectors of the POSITIONABLE or #nil if the groups not existing or alive.
function GROUP:GetPositionVec3() -- Overridden from POSITIONABLE:GetPositionVec3() function GROUP:GetPositionVec3() -- Overridden from POSITIONABLE:GetPositionVec3()
self:F2( self.PositionableName ) --self:F2( self.PositionableName )
local DCSPositionable = self:GetDCSObject() local DCSPositionable = self:GetDCSObject()
@@ -383,7 +383,7 @@ function GROUP:GetPositionVec3() -- Overridden from POSITIONABLE:GetPositionVec3
local unit = DCSPositionable:getUnits()[1] local unit = DCSPositionable:getUnits()[1]
if unit then if unit then
local PositionablePosition = unit:getPosition().p local PositionablePosition = unit:getPosition().p
self:T3( PositionablePosition ) --self:T3( PositionablePosition )
return PositionablePosition return PositionablePosition
end end
end end
@@ -403,7 +403,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean `true` if the group is alive *and* active, `false` if the group is alive but inactive or `#nil` if the group does not exist anymore. -- @return #boolean `true` if the group is alive *and* active, `false` if the group is alive but inactive or `#nil` if the group does not exist anymore.
function GROUP:IsAlive() function GROUP:IsAlive()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() -- DCS#Group local DCSGroup = self:GetDCSObject() -- DCS#Group
@@ -412,7 +412,7 @@ function GROUP:IsAlive()
local DCSUnit = DCSGroup:getUnit(1) -- DCS#Unit local DCSUnit = DCSGroup:getUnit(1) -- DCS#Unit
if DCSUnit then if DCSUnit then
local GroupIsAlive = DCSUnit:isActive() local GroupIsAlive = DCSUnit:isActive()
self:T3( GroupIsAlive ) --self:T3( GroupIsAlive )
return GroupIsAlive return GroupIsAlive
end end
end end
@@ -425,7 +425,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean `true` if group is activated or `#nil` The group is not existing or alive. -- @return #boolean `true` if group is activated or `#nil` The group is not existing or alive.
function GROUP:IsActive() function GROUP:IsActive()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() -- DCS#Group local DCSGroup = self:GetDCSObject() -- DCS#Group
@@ -468,7 +468,7 @@ end
-- Ship:Destroy( false ) -- Don't generate an event upon destruction. -- Ship:Destroy( false ) -- Don't generate an event upon destruction.
-- --
function GROUP:Destroy( GenerateEvent, delay ) function GROUP:Destroy( GenerateEvent, delay )
self:F2( self.GroupName ) --self:F2( self.GroupName )
if delay and delay>0 then if delay and delay>0 then
self:ScheduleOnce(delay, GROUP.Destroy, self, GenerateEvent) self:ScheduleOnce(delay, GROUP.Destroy, self, GenerateEvent)
@@ -511,12 +511,12 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return DCS#Group.Category The category ID. -- @return DCS#Group.Category The category ID.
function GROUP:GetCategory() function GROUP:GetCategory()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T3( GroupCategory ) --self:T3( GroupCategory )
return GroupCategory return GroupCategory
end end
@@ -527,7 +527,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship, Train. -- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship, Train.
function GROUP:GetCategoryName() function GROUP:GetCategoryName()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -539,7 +539,7 @@ function GROUP:GetCategoryName()
[Group.Category.TRAIN] = "Train", [Group.Category.TRAIN] = "Train",
} }
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T3( GroupCategory ) --self:T3( GroupCategory )
return CategoryNames[GroupCategory] return CategoryNames[GroupCategory]
end end
@@ -570,12 +570,12 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return DCS#country.id The country identifier or nil if the DCS Group is not existing or alive. -- @return DCS#country.id The country identifier or nil if the DCS Group is not existing or alive.
function GROUP:GetCountry() function GROUP:GetCountry()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCountry = DCSGroup:getUnit(1):getCountry() local GroupCountry = DCSGroup:getUnit(1):getCountry()
self:T3( GroupCountry ) --self:T3( GroupCountry )
return GroupCountry return GroupCountry
end end
@@ -627,7 +627,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Speed in km/h. -- @return #number Speed in km/h.
function GROUP:GetSpeedMax() function GROUP:GetSpeedMax()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -660,7 +660,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Range in meters. -- @return #number Range in meters.
function GROUP:GetRange() function GROUP:GetRange()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -691,7 +691,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #table of Wrapper.Unit#UNIT objects, indexed by number. -- @return #table of Wrapper.Unit#UNIT objects, indexed by number.
function GROUP:GetUnits() function GROUP:GetUnits()
self:F2( { self.GroupName } ) --self:F2( { self.GroupName } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -708,7 +708,7 @@ function GROUP:GetUnits()
Units[#Units+1]=unit Units[#Units+1]=unit
end end
end end
self:T3( Units ) --self:T3( Units )
return Units return Units
end end
@@ -719,7 +719,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #list<Wrapper.Unit#UNIT> The list of player occupied @{Wrapper.Unit} objects of the @{Wrapper.Group}. -- @return #list<Wrapper.Unit#UNIT> The list of player occupied @{Wrapper.Unit} objects of the @{Wrapper.Group}.
function GROUP:GetPlayerUnits() function GROUP:GetPlayerUnits()
self:F2( { self.GroupName } ) --self:F2( { self.GroupName } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -731,7 +731,7 @@ function GROUP:GetPlayerUnits()
Units[#Units+1] = PlayerUnit Units[#Units+1] = PlayerUnit
end end
end end
self:T3( Units ) --self:T3( Units )
return Units return Units
end end
@@ -830,7 +830,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Number of alive units. If DCS group is nil, 0 is returned. -- @return #number Number of alive units. If DCS group is nil, 0 is returned.
function GROUP:CountAliveUnits() function GROUP:CountAliveUnits()
self:F3( { self.GroupName } ) --self:F3( { self.GroupName } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -852,7 +852,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return Wrapper.Unit#UNIT First unit alive. -- @return Wrapper.Unit#UNIT First unit alive.
function GROUP:GetFirstUnitAlive() function GROUP:GetFirstUnitAlive()
self:F3({self.GroupName}) --self:F3({self.GroupName})
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -872,7 +872,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return Wrapper.Unit#UNIT First unit or nil if it does not exist. -- @return Wrapper.Unit#UNIT First unit or nil if it does not exist.
function GROUP:GetFirstUnit() function GROUP:GetFirstUnit()
self:F3({self.GroupName}) --self:F3({self.GroupName})
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
@@ -887,7 +887,7 @@ end
-- @param Wrapper.Group#GROUP self -- @param Wrapper.Group#GROUP self
-- @return DCS#Vec3 The velocity Vec3 vector or `#nil` if the GROUP is not existing or alive. -- @return DCS#Vec3 The velocity Vec3 vector or `#nil` if the GROUP is not existing or alive.
function GROUP:GetVelocityVec3() function GROUP:GetVelocityVec3()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -921,7 +921,7 @@ end
-- @param #boolean FromGround Measure from the ground or from sea level (ASL). Provide **true** for measuring from the ground (AGL). **false** or **nil** if you measure from sea level. -- @param #boolean FromGround Measure from the ground or from sea level (ASL). Provide **true** for measuring from the ground (AGL). **false** or **nil** if you measure from sea level.
-- @return #number The altitude of the group or nil if is not existing or alive. -- @return #number The altitude of the group or nil if is not existing or alive.
function GROUP:GetAltitude(FromGround) function GROUP:GetAltitude(FromGround)
self:F2( self.GroupName ) --self:F2( self.GroupName )
return self:GetHeight(FromGround) return self:GetHeight(FromGround)
end end
@@ -930,7 +930,7 @@ end
-- @param #boolean FromGround Measure from the ground or from sea level (ASL). Provide **true** for measuring from the ground (AGL). **false** or **nil** if you measure from sea level. -- @param #boolean FromGround Measure from the ground or from sea level (ASL). Provide **true** for measuring from the ground (AGL). **false** or **nil** if you measure from sea level.
-- @return #number The height of the group or nil if is not existing or alive. -- @return #number The height of the group or nil if is not existing or alive.
function GROUP:GetHeight( FromGround ) function GROUP:GetHeight( FromGround )
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -966,12 +966,12 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number The DCS Group initial size. -- @return #number The DCS Group initial size.
function GROUP:GetInitialSize() function GROUP:GetInitialSize()
self:F3( { self.GroupName } ) --self:F3( { self.GroupName } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupInitialSize = DCSGroup:getInitialSize() local GroupInitialSize = DCSGroup:getInitialSize()
self:T3( GroupInitialSize ) --self:T3( GroupInitialSize )
return GroupInitialSize return GroupInitialSize
end end
@@ -983,12 +983,12 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #table The DCS Units. -- @return #table The DCS Units.
function GROUP:GetDCSUnits() function GROUP:GetDCSUnits()
self:F2( { self.GroupName } ) --self:F2( { self.GroupName } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local DCSUnits = DCSGroup:getUnits() local DCSUnits = DCSGroup:getUnits()
self:T3( DCSUnits ) --self:T3( DCSUnits )
return DCSUnits return DCSUnits
end end
@@ -1001,7 +1001,7 @@ end
-- @param #number delay Delay in seconds, before the group is activated. -- @param #number delay Delay in seconds, before the group is activated.
-- @return #GROUP self -- @return #GROUP self
function GROUP:Activate(delay) function GROUP:Activate(delay)
self:F2( { self.GroupName } ) --self:F2( { self.GroupName } )
if delay and delay>0 then if delay and delay>0 then
self:ScheduleOnce(delay, GROUP.Activate, self) self:ScheduleOnce(delay, GROUP.Activate, self)
else else
@@ -1015,13 +1015,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #string The type name of the group. -- @return #string The type name of the group.
function GROUP:GetTypeName() function GROUP:GetTypeName()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupTypeName = DCSGroup:getUnit(1):getTypeName() local GroupTypeName = DCSGroup:getUnit(1):getTypeName()
self:T3( GroupTypeName ) --self:T3( GroupTypeName )
return( GroupTypeName ) return( GroupTypeName )
end end
@@ -1032,13 +1032,13 @@ end
--@param #GROUP self --@param #GROUP self
--@return #string NatoReportingName or "Bogey" if unknown. --@return #string NatoReportingName or "Bogey" if unknown.
function GROUP:GetNatoReportingName() function GROUP:GetNatoReportingName()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupTypeName = DCSGroup:getUnit(1):getTypeName() local GroupTypeName = DCSGroup:getUnit(1):getTypeName()
self:T3( GroupTypeName ) --self:T3( GroupTypeName )
return UTILS.GetReportingName(GroupTypeName) return UTILS.GetReportingName(GroupTypeName)
end end
@@ -1050,13 +1050,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #string The player name of the group. -- @return #string The player name of the group.
function GROUP:GetPlayerName() function GROUP:GetPlayerName()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local PlayerName = DCSGroup:getUnit(1):getPlayerName() local PlayerName = DCSGroup:getUnit(1):getPlayerName()
self:T3( PlayerName ) --self:T3( PlayerName )
return( PlayerName ) return( PlayerName )
end end
@@ -1068,13 +1068,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #string The CallSign of the first DCS Unit of the DCS Group. -- @return #string The CallSign of the first DCS Unit of the DCS Group.
function GROUP:GetCallsign() function GROUP:GetCallsign()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCallSign = DCSGroup:getUnit(1):getCallsign() local GroupCallSign = DCSGroup:getUnit(1):getCallsign()
self:T3( GroupCallSign ) --self:T3( GroupCallSign )
return GroupCallSign return GroupCallSign
end end
@@ -1151,13 +1151,13 @@ end
-- @return Core.Point#POINT_VEC2 The 2D point vector of the first DCS Unit of the GROUP. -- @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. -- @return #nil The first UNIT is not existing or alive.
function GROUP:GetPointVec2() function GROUP:GetPointVec2()
self:F2(self.GroupName) --self:F2(self.GroupName)
local FirstUnit = self:GetUnit(1) local FirstUnit = self:GetUnit(1)
if FirstUnit then if FirstUnit then
local FirstUnitPointVec2 = FirstUnit:GetPointVec2() local FirstUnitPointVec2 = FirstUnit:GetPointVec2()
self:T3(FirstUnitPointVec2) --self:T3(FirstUnitPointVec2)
return FirstUnitPointVec2 return FirstUnitPointVec2
end end
@@ -1239,13 +1239,13 @@ end
-- @usage -- @usage
-- -- If Radius is ignored, returns the DCS#Vec3 of first UNIT of the GROUP -- -- If Radius is ignored, returns the DCS#Vec3 of first UNIT of the GROUP
function GROUP:GetRandomVec3(Radius) function GROUP:GetRandomVec3(Radius)
self:F2(self.GroupName) --self:F2(self.GroupName)
local FirstUnit = self:GetUnit(1) local FirstUnit = self:GetUnit(1)
if FirstUnit then if FirstUnit then
local FirstUnitRandomPointVec3 = FirstUnit:GetRandomVec3(Radius) local FirstUnitRandomPointVec3 = FirstUnit:GetRandomVec3(Radius)
self:T3(FirstUnitRandomPointVec3) --self:T3(FirstUnitRandomPointVec3)
return FirstUnitRandomPointVec3 return FirstUnitRandomPointVec3
end end
@@ -1258,9 +1258,9 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Mean heading of the GROUP in degrees or #nil The first UNIT is not existing or alive. -- @return #number Mean heading of the GROUP in degrees or #nil The first UNIT is not existing or alive.
function GROUP:GetHeading() function GROUP:GetHeading()
self:F2(self.GroupName) --self:F2(self.GroupName)
self:F2(self.GroupName) --self:F2(self.GroupName)
local GroupSize = self:GetSize() local GroupSize = self:GetSize()
local HeadingAccumulator = 0 local HeadingAccumulator = 0
@@ -1289,7 +1289,7 @@ end
-- @return #number The fuel state of the unit with the least amount of fuel. -- @return #number The fuel state of the unit with the least amount of fuel.
-- @return Wrapper.Unit#UNIT reference to #Unit object for further processing. -- @return Wrapper.Unit#UNIT reference to #Unit object for further processing.
function GROUP:GetFuelMin() function GROUP:GetFuelMin()
self:F3(self.ControllableName) --self:F3(self.ControllableName)
if not self:GetDCSObject() then if not self:GetDCSObject() then
BASE:E( { "Cannot GetFuel", Group = self, Alive = self:IsAlive() } ) BASE:E( { "Cannot GetFuel", Group = self, Alive = self:IsAlive() } )
@@ -1320,7 +1320,7 @@ end
-- @return #number The relative amount of fuel (from 0.0 to 1.0). -- @return #number The relative amount of fuel (from 0.0 to 1.0).
-- @return #nil The GROUP is not existing or alive. -- @return #nil The GROUP is not existing or alive.
function GROUP:GetFuelAvg() function GROUP:GetFuelAvg()
self:F( self.ControllableName ) --self:F( self.ControllableName )
local DCSControllable = self:GetDCSObject() local DCSControllable = self:GetDCSObject()
@@ -1330,7 +1330,7 @@ function GROUP:GetFuelAvg()
for UnitID, UnitData in pairs( self:GetUnits() ) do for UnitID, UnitData in pairs( self:GetUnits() ) do
local Unit = UnitData -- Wrapper.Unit#UNIT local Unit = UnitData -- Wrapper.Unit#UNIT
local UnitFuel = Unit:GetFuel() or 0 local UnitFuel = Unit:GetFuel() or 0
self:F( { Fuel = UnitFuel } ) --self:F( { Fuel = UnitFuel } )
TotalFuel = TotalFuel + UnitFuel TotalFuel = TotalFuel + UnitFuel
end end
local GroupFuel = TotalFuel / GroupSize local GroupFuel = TotalFuel / GroupSize
@@ -1360,7 +1360,7 @@ end
-- @return #number Number of missiles left. -- @return #number Number of missiles left.
-- @return #number Number of artillery shells left (with explosive mass, included in shells; shells can also be machine gun ammo) -- @return #number Number of artillery shells left (with explosive mass, included in shells; shells can also be machine gun ammo)
function GROUP:GetAmmunition() function GROUP:GetAmmunition()
self:F( self.ControllableName ) --self:F( self.ControllableName )
local DCSControllable = self:GetDCSObject() local DCSControllable = self:GetDCSObject()
@@ -1431,7 +1431,7 @@ end
-- @param Core.Zone#ZONE_BASE Zone The zone to test. -- @param Core.Zone#ZONE_BASE Zone The zone to test.
-- @return #boolean Returns true if the Group is completely within the @{Core.Zone#ZONE_BASE} -- @return #boolean Returns true if the Group is completely within the @{Core.Zone#ZONE_BASE}
function GROUP:IsCompletelyInZone( Zone ) function GROUP:IsCompletelyInZone( Zone )
self:F2( { self.GroupName, Zone } ) --self:F2( { self.GroupName, Zone } )
if not self:IsAlive() then return false end if not self:IsAlive() then return false end
@@ -1451,7 +1451,7 @@ end
-- @param Core.Zone#ZONE_BASE Zone The zone to test. -- @param Core.Zone#ZONE_BASE Zone The zone to test.
-- @return #boolean Returns true if the Group is partially within the @{Core.Zone#ZONE_BASE} -- @return #boolean Returns true if the Group is partially within the @{Core.Zone#ZONE_BASE}
function GROUP:IsPartlyInZone( Zone ) function GROUP:IsPartlyInZone( Zone )
self:F2( { self.GroupName, Zone } ) --self:F2( { self.GroupName, Zone } )
local IsOneUnitInZone = false local IsOneUnitInZone = false
local IsOneUnitOutsideZone = false local IsOneUnitOutsideZone = false
@@ -1487,7 +1487,7 @@ end
-- @param Core.Zone#ZONE_BASE Zone The zone to test. -- @param Core.Zone#ZONE_BASE Zone The zone to test.
-- @return #boolean Returns true if the Group is not within the @{Core.Zone#ZONE_BASE} -- @return #boolean Returns true if the Group is not within the @{Core.Zone#ZONE_BASE}
function GROUP:IsNotInZone( Zone ) function GROUP:IsNotInZone( Zone )
self:F2( { self.GroupName, Zone } ) --self:F2( { self.GroupName, Zone } )
if not self:IsAlive() then return true end if not self:IsAlive() then return true end
@@ -1523,7 +1523,7 @@ end
-- @param Core.Zone#ZONE_BASE Zone The zone to test. -- @param Core.Zone#ZONE_BASE Zone The zone to test.
-- @return #number The number of UNITs that are in the @{Core.Zone} -- @return #number The number of UNITs that are in the @{Core.Zone}
function GROUP:CountInZone( Zone ) function GROUP:CountInZone( Zone )
self:F2( {self.GroupName, Zone} ) --self:F2( {self.GroupName, Zone} )
local Count = 0 local Count = 0
if not self:IsAlive() then return Count end if not self:IsAlive() then return Count end
@@ -1543,13 +1543,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean Air category evaluation result. -- @return #boolean Air category evaluation result.
function GROUP:IsAir() function GROUP:IsAir()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local IsAirResult = DCSGroup:getCategory() == Group.Category.AIRPLANE or DCSGroup:getCategory() == Group.Category.HELICOPTER local IsAirResult = DCSGroup:getCategory() == Group.Category.AIRPLANE or DCSGroup:getCategory() == Group.Category.HELICOPTER
self:T3( IsAirResult ) --self:T3( IsAirResult )
return IsAirResult return IsAirResult
end end
@@ -1560,13 +1560,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if DCS Group contains Helicopters. -- @return #boolean true if DCS Group contains Helicopters.
function GROUP:IsHelicopter() function GROUP:IsHelicopter()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T2( GroupCategory ) --self:T2( GroupCategory )
return GroupCategory == Group.Category.HELICOPTER return GroupCategory == Group.Category.HELICOPTER
end end
@@ -1577,13 +1577,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if DCS Group contains AirPlanes. -- @return #boolean true if DCS Group contains AirPlanes.
function GROUP:IsAirPlane() function GROUP:IsAirPlane()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T2( GroupCategory ) --self:T2( GroupCategory )
return GroupCategory == Group.Category.AIRPLANE return GroupCategory == Group.Category.AIRPLANE
end end
@@ -1594,13 +1594,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if DCS Group contains Ground troops. -- @return #boolean true if DCS Group contains Ground troops.
function GROUP:IsGround() function GROUP:IsGround()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T2( GroupCategory ) --self:T2( GroupCategory )
return GroupCategory == Group.Category.GROUND return GroupCategory == Group.Category.GROUND
end end
@@ -1611,13 +1611,13 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean true if DCS Group contains Ships. -- @return #boolean true if DCS Group contains Ships.
function GROUP:IsShip() function GROUP:IsShip()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
if DCSGroup then if DCSGroup then
local GroupCategory = DCSGroup:getCategory() local GroupCategory = DCSGroup:getCategory()
self:T2( GroupCategory ) --self:T2( GroupCategory )
return GroupCategory == Group.Category.SHIP return GroupCategory == Group.Category.SHIP
end end
@@ -1629,7 +1629,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #boolean All units on the ground result. -- @return #boolean All units on the ground result.
function GROUP:AllOnGround() function GROUP:AllOnGround()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -1642,7 +1642,7 @@ function GROUP:AllOnGround()
end end
end end
self:T3( AllOnGroundResult ) --self:T3( AllOnGroundResult )
return AllOnGroundResult return AllOnGroundResult
end end
@@ -1697,7 +1697,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Maximum velocity found. -- @return #number Maximum velocity found.
function GROUP:GetMaxVelocity() function GROUP:GetMaxVelocity()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -1725,7 +1725,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Minimum height found. -- @return #number Minimum height found.
function GROUP:GetMinHeight() function GROUP:GetMinHeight()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -1753,7 +1753,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #number Maximum height found. -- @return #number Maximum height found.
function GROUP:GetMaxHeight() function GROUP:GetMaxHeight()
self:F2() --self:F2()
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -1895,7 +1895,7 @@ end
-- @param Core.Point#COORDINATE coordinate Coordinate where the group should be respawned. -- @param Core.Point#COORDINATE coordinate Coordinate where the group should be respawned.
-- @return #GROUP self -- @return #GROUP self
function GROUP:InitCoordinate(coordinate) function GROUP:InitCoordinate(coordinate)
self:F({coordinate=coordinate}) --self:F({coordinate=coordinate})
self.InitCoord=coordinate self.InitCoord=coordinate
return self return self
end end
@@ -1905,7 +1905,7 @@ end
-- @param #boolean switch If true (or nil), enables the radio comms. If false, disables the radio for the spawned group. -- @param #boolean switch If true (or nil), enables the radio comms. If false, disables the radio for the spawned group.
-- @return #GROUP self -- @return #GROUP self
function GROUP:InitRadioCommsOnOff(switch) function GROUP:InitRadioCommsOnOff(switch)
self:F({switch=switch}) --self:F({switch=switch})
if switch==true or switch==nil then if switch==true or switch==nil then
self.InitRespawnRadio=true self.InitRespawnRadio=true
else else
@@ -1919,7 +1919,7 @@ end
-- @param #number frequency The frequency in MHz. -- @param #number frequency The frequency in MHz.
-- @return #GROUP self -- @return #GROUP self
function GROUP:InitRadioFrequency(frequency) function GROUP:InitRadioFrequency(frequency)
self:F({frequency=frequency}) --self:F({frequency=frequency})
self.InitRespawnFreq=frequency self.InitRespawnFreq=frequency
@@ -1931,7 +1931,7 @@ end
-- @param #string modulation Either "FM" or "AM". If no value is given, modulation is set to AM. -- @param #string modulation Either "FM" or "AM". If no value is given, modulation is set to AM.
-- @return #GROUP self -- @return #GROUP self
function GROUP:InitRadioModulation(modulation) function GROUP:InitRadioModulation(modulation)
self:F({modulation=modulation}) --self:F({modulation=modulation})
if modulation and modulation:lower()=="fm" then if modulation and modulation:lower()=="fm" then
self.InitRespawnModu=radio.modulation.FM self.InitRespawnModu=radio.modulation.FM
else else
@@ -1945,7 +1945,7 @@ end
-- @param #string modex Tail number of the first unit. -- @param #string modex Tail number of the first unit.
-- @return #GROUP self -- @return #GROUP self
function GROUP:InitModex(modex) function GROUP:InitModex(modex)
self:F({modex=modex}) --self:F({modex=modex})
if modex then if modex then
self.InitRespawnModex=tonumber(modex) self.InitRespawnModex=tonumber(modex)
end end
@@ -2011,7 +2011,7 @@ function GROUP:Respawn( Template, Reset )
--Template.y = nil --Template.y = nil
-- Debug number of units. -- Debug number of units.
self:F( #Template.units ) --self:F( #Template.units )
-- Reset position etc? -- Reset position etc?
if Reset == true then if Reset == true then
@@ -2019,10 +2019,10 @@ function GROUP:Respawn( Template, Reset )
-- Loop over units in group. -- Loop over units in group.
for UnitID, UnitData in pairs( self:GetUnits() ) do for UnitID, UnitData in pairs( self:GetUnits() ) do
local GroupUnit = UnitData -- Wrapper.Unit#UNIT local GroupUnit = UnitData -- Wrapper.Unit#UNIT
self:F(GroupUnit:GetName()) --self:F(GroupUnit:GetName())
if GroupUnit:IsAlive() then if GroupUnit:IsAlive() then
self:I("FF Alive") --self:I("FF Alive")
-- Get unit position vector. -- Get unit position vector.
local GroupUnitVec3 = GroupUnit:GetVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
@@ -2062,7 +2062,7 @@ function GROUP:Respawn( Template, Reset )
Template.units[UnitID].psi = -Template.units[UnitID].heading Template.units[UnitID].psi = -Template.units[UnitID].heading
-- Debug. -- Debug.
self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) --self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } )
end end
end end
@@ -2071,7 +2071,7 @@ function GROUP:Respawn( Template, Reset )
-- Loop over template units. -- Loop over template units.
for UnitID, TemplateUnitData in pairs( Template.units ) do for UnitID, TemplateUnitData in pairs( Template.units ) do
self:F( "Reset" ) --self:F( "Reset" )
-- Position from template. -- Position from template.
local GroupUnitVec3 = { x = TemplateUnitData.x, y = TemplateUnitData.alt, z = TemplateUnitData.y } local GroupUnitVec3 = { x = TemplateUnitData.x, y = TemplateUnitData.alt, z = TemplateUnitData.y }
@@ -2105,7 +2105,7 @@ function GROUP:Respawn( Template, Reset )
Template.units[UnitID].heading = self.InitRespawnHeading and self.InitRespawnHeading or TemplateUnitData.heading Template.units[UnitID].heading = self.InitRespawnHeading and self.InitRespawnHeading or TemplateUnitData.heading
-- Debug. -- Debug.
self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } ) --self:F( { UnitID, Template.units[UnitID], Template.units[UnitID] } )
end end
else else
@@ -2156,7 +2156,7 @@ function GROUP:Respawn( Template, Reset )
-- Destroy old group. Dont trigger any dead/crash events since this is a respawn. -- Destroy old group. Dont trigger any dead/crash events since this is a respawn.
self:Destroy(false) self:Destroy(false)
self:T({Template=Template}) --self:T({Template=Template})
-- Spawn new group. -- Spawn new group.
_DATABASE:Spawn(Template) _DATABASE:Spawn(Template)
@@ -2177,7 +2177,7 @@ end
-- @param #boolean Uncontrolled (Optional) If true, spawn in uncontrolled state. -- @param #boolean Uncontrolled (Optional) If true, spawn in uncontrolled state.
-- @return Wrapper.Group#GROUP Group spawned at airbase or nil if group could not be spawned. -- @return Wrapper.Group#GROUP Group spawned at airbase or nil if group could not be spawned.
function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4 function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) -- R2.4
self:F2( { SpawnTemplate, Takeoff, Uncontrolled} ) --self:F2( { SpawnTemplate, Takeoff, Uncontrolled} )
if self and self:IsAlive() then if self and self:IsAlive() then
@@ -2185,7 +2185,7 @@ function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) --
local airbase=self:GetCoordinate():GetClosestAirbase() local airbase=self:GetCoordinate():GetClosestAirbase()
if airbase then if airbase then
self:F2("Closest airbase = "..airbase:GetName()) --self:F2("Closest airbase = "..airbase:GetName())
else else
self:E("ERROR: could not find closest airbase!") self:E("ERROR: could not find closest airbase!")
return nil return nil
@@ -2236,7 +2236,7 @@ function GROUP:RespawnAtCurrentAirbase(SpawnTemplate, Takeoff, Uncontrolled) --
local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase) local Parkingspot, TermialID, Distance=unit:GetCoordinate():GetClosestParkingSpot(airbase)
--Parkingspot:MarkToAll("parking spot") --Parkingspot:MarkToAll("parking spot")
self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID))) --self:T2(string.format("Closest parking spot distance = %s, terminal ID=%s", tostring(Distance), tostring(TermialID)))
-- Get unit coordinates for respawning position. -- Get unit coordinates for respawning position.
local uc=unit:GetCoordinate() local uc=unit:GetCoordinate()
@@ -2298,7 +2298,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #table The MissionTemplate -- @return #table The MissionTemplate
function GROUP:GetTaskMission() function GROUP:GetTaskMission()
self:F2( self.GroupName ) --self:F2( self.GroupName )
return UTILS.DeepCopy( _DATABASE.Templates.Groups[self.GroupName].Template ) return UTILS.DeepCopy( _DATABASE.Templates.Groups[self.GroupName].Template )
end end
@@ -2307,7 +2307,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #table The mission route defined by points. -- @return #table The mission route defined by points.
function GROUP:GetTaskRoute() function GROUP:GetTaskRoute()
self:F2( self.GroupName ) --self:F2( self.GroupName )
return UTILS.DeepCopy( _DATABASE.Templates.Groups[self.GroupName].Template.route.points ) return UTILS.DeepCopy( _DATABASE.Templates.Groups[self.GroupName].Template.route.points )
end end
@@ -2319,7 +2319,7 @@ end
-- @param #boolean Randomize Randomization of the route, when true. -- @param #boolean Randomize Randomization of the route, when true.
-- @param #number Radius When randomization is on, the randomization is within the radius. -- @param #number Radius When randomization is on, the randomization is within the radius.
function GROUP:CopyRoute( Begin, End, Randomize, Radius ) function GROUP:CopyRoute( Begin, End, Randomize, Radius )
self:F2( { Begin, End } ) --self:F2( { Begin, End } )
local Points = {} local Points = {}
@@ -2331,7 +2331,7 @@ function GROUP:CopyRoute( Begin, End, Randomize, Radius )
GroupName = self:GetName() GroupName = self:GetName()
end end
self:T3( { GroupName } ) --self:T3( { GroupName } )
local Template = _DATABASE.Templates.Groups[GroupName].Template local Template = _DATABASE.Templates.Groups[GroupName].Template
@@ -2377,7 +2377,7 @@ function GROUP:CalculateThreatLevelA2G()
end end
end end
self:T3( MaxThreatLevelA2G ) --self:T3( MaxThreatLevelA2G )
return MaxThreatLevelA2G return MaxThreatLevelA2G
end end
@@ -2404,7 +2404,7 @@ end
-- @param Wrapper.Group#GROUP self -- @param Wrapper.Group#GROUP self
-- @return #boolean true if in the first unit of the group is in the air or #nil if the GROUP is not existing or not alive. -- @return #boolean true if in the first unit of the group is in the air or #nil if the GROUP is not existing or not alive.
function GROUP:InAir() function GROUP:InAir()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -2412,7 +2412,7 @@ function GROUP:InAir()
local DCSUnit = DCSGroup:getUnit(1) local DCSUnit = DCSGroup:getUnit(1)
if DCSUnit then if DCSUnit then
local GroupInAir = DCSGroup:getUnit(1):inAir() local GroupInAir = DCSGroup:getUnit(1):inAir()
self:T3( GroupInAir ) --self:T3( GroupInAir )
return GroupInAir return GroupInAir
end end
end end
@@ -2425,7 +2425,7 @@ end
-- @param #boolean AllUnits (Optional) If true, check whether all units of the group are airborne. -- @param #boolean AllUnits (Optional) If true, check whether all units of the group are airborne.
-- @return #boolean True if at least one (optionally all) unit(s) is(are) airborne or false otherwise. Nil if no unit exists or is alive. -- @return #boolean True if at least one (optionally all) unit(s) is(are) airborne or false otherwise. Nil if no unit exists or is alive.
function GROUP:IsAirborne(AllUnits) function GROUP:IsAirborne(AllUnits)
self:F2( self.GroupName ) --self:F2( self.GroupName )
-- Get all units of the group. -- Get all units of the group.
local units=self:GetUnits() local units=self:GetUnits()
@@ -2636,7 +2636,7 @@ do -- Route methods
-- @param #number Speed (optional) The Speed, if no Speed is given, 80% of maximum Speed of the group is selected. -- @param #number Speed (optional) The Speed, if no Speed is given, 80% of maximum Speed of the group is selected.
-- @return #GROUP self -- @return #GROUP self
function GROUP:RouteRTB( RTBAirbase, Speed ) function GROUP:RouteRTB( RTBAirbase, Speed )
self:F( { RTBAirbase:GetName(), Speed } ) --self:F( { RTBAirbase:GetName(), Speed } )
local DCSGroup = self:GetDCSObject() local DCSGroup = self:GetDCSObject()
@@ -2662,7 +2662,7 @@ do -- Route methods
--local Points={PointFrom, PointAirbase, PointLanding} --local Points={PointFrom, PointAirbase, PointLanding}
-- Debug info. -- Debug info.
self:T3(Points) --self:T3(Points)
-- Get group template. -- Get group template.
local Template=self:GetTemplate() local Template=self:GetTemplate()
@@ -2758,7 +2758,7 @@ do -- Players
end end
if HasPlayers == true then if HasPlayers == true then
self:F2( PlayerNames ) --self:F2( PlayerNames )
return PlayerNames return PlayerNames
end end
@@ -2792,7 +2792,7 @@ end
-- @param #boolean switch If true, emission is enabled. If false, emission is disabled. -- @param #boolean switch If true, emission is enabled. If false, emission is disabled.
-- @return #GROUP self -- @return #GROUP self
function GROUP:EnableEmission(switch) function GROUP:EnableEmission(switch)
self:F2( self.GroupName ) --self:F2( self.GroupName )
local switch = switch or false local switch = switch or false
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -2819,7 +2819,7 @@ end
-- @param #boolean switch If true, Invisible is enabled. If false, Invisible is disabled. -- @param #boolean switch If true, Invisible is enabled. If false, Invisible is disabled.
-- @return #GROUP self -- @return #GROUP self
function GROUP:CommandSetInvisible(switch) function GROUP:CommandSetInvisible(switch)
self:F2( self.GroupName ) --self:F2( self.GroupName )
if switch==nil then if switch==nil then
switch=false switch=false
end end
@@ -2841,7 +2841,7 @@ end
-- @param #boolean switch If true, Immortal is enabled. If false, Immortal is disabled. -- @param #boolean switch If true, Immortal is enabled. If false, Immortal is disabled.
-- @return #GROUP self -- @return #GROUP self
function GROUP:CommandSetImmortal(switch) function GROUP:CommandSetImmortal(switch)
self:F2( self.GroupName ) --self:F2( self.GroupName )
if switch==nil then if switch==nil then
switch=false switch=false
end end
@@ -2854,7 +2854,7 @@ end
-- @param #GROUP self -- @param #GROUP self
-- @return #string Skill String of skill name. -- @return #string Skill String of skill name.
function GROUP:GetSkill() function GROUP:GetSkill()
self:F2( self.GroupName ) --self:F2( self.GroupName )
local unit = self:GetUnit(1) local unit = self:GetUnit(1)
local name = unit:GetName() local name = unit:GetName()
local skill = _DATABASE.Templates.Units[name].Template.skill or "Random" local skill = _DATABASE.Templates.Units[name].Template.skill or "Random"
+55 -55
View File
@@ -273,12 +273,12 @@ end
-- @param #number Heading The heading of the unit respawn. -- @param #number Heading The heading of the unit respawn.
function UNIT:ReSpawnAt( Coordinate, Heading ) function UNIT:ReSpawnAt( Coordinate, Heading )
self:T( self:Name() ) --self:T( self:Name() )
local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) ) local SpawnGroupTemplate = UTILS.DeepCopy( _DATABASE:GetGroupTemplateFromUnitName( self:Name() ) )
self:T( SpawnGroupTemplate ) --self:T( SpawnGroupTemplate )
local SpawnGroup = self:GetGroup() local SpawnGroup = self:GetGroup()
self:T( { SpawnGroup = SpawnGroup } ) --self:T( { SpawnGroup = SpawnGroup } )
if SpawnGroup then if SpawnGroup then
@@ -286,10 +286,10 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.x = Coordinate.x SpawnGroupTemplate.x = Coordinate.x
SpawnGroupTemplate.y = Coordinate.z SpawnGroupTemplate.y = Coordinate.z
self:F( #SpawnGroupTemplate.units ) --self:F( #SpawnGroupTemplate.units )
for UnitID, UnitData in pairs( SpawnGroup:GetUnits() or {} ) do for UnitID, UnitData in pairs( SpawnGroup:GetUnits() or {} ) do
local GroupUnit = UnitData -- #UNIT local GroupUnit = UnitData -- #UNIT
self:F( GroupUnit:GetName() ) --self:F( GroupUnit:GetName() )
if GroupUnit:IsAlive() then if GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
local GroupUnitHeading = GroupUnit:GetHeading() local GroupUnitHeading = GroupUnit:GetHeading()
@@ -297,23 +297,23 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x SpawnGroupTemplate.units[UnitID].x = GroupUnitVec3.x
SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z SpawnGroupTemplate.units[UnitID].y = GroupUnitVec3.z
SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading SpawnGroupTemplate.units[UnitID].heading = GroupUnitHeading
self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } ) --self:F( { UnitID, SpawnGroupTemplate.units[UnitID], SpawnGroupTemplate.units[UnitID] } )
end end
end end
end end
for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do for UnitTemplateID, UnitTemplateData in pairs( SpawnGroupTemplate.units ) do
self:T( { UnitTemplateData.name, self:Name() } ) --self:T( { UnitTemplateData.name, self:Name() } )
SpawnGroupTemplate.units[UnitTemplateID].unitId = nil SpawnGroupTemplate.units[UnitTemplateID].unitId = nil
if UnitTemplateData.name == self:Name() then if UnitTemplateData.name == self:Name() then
self:T("Adjusting") --self:T("Adjusting")
SpawnGroupTemplate.units[UnitTemplateID].alt = Coordinate.y SpawnGroupTemplate.units[UnitTemplateID].alt = Coordinate.y
SpawnGroupTemplate.units[UnitTemplateID].x = Coordinate.x SpawnGroupTemplate.units[UnitTemplateID].x = Coordinate.x
SpawnGroupTemplate.units[UnitTemplateID].y = Coordinate.z SpawnGroupTemplate.units[UnitTemplateID].y = Coordinate.z
SpawnGroupTemplate.units[UnitTemplateID].heading = Heading SpawnGroupTemplate.units[UnitTemplateID].heading = Heading
self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } ) --self:F( { UnitTemplateID, SpawnGroupTemplate.units[UnitTemplateID], SpawnGroupTemplate.units[UnitTemplateID] } )
else else
self:F( SpawnGroupTemplate.units[UnitTemplateID].name ) --self:F( SpawnGroupTemplate.units[UnitTemplateID].name )
local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT local GroupUnit = UNIT:FindByName( SpawnGroupTemplate.units[UnitTemplateID].name ) -- #UNIT
if GroupUnit and GroupUnit:IsAlive() then if GroupUnit and GroupUnit:IsAlive() then
local GroupUnitVec3 = GroupUnit:GetVec3() local GroupUnitVec3 = GroupUnit:GetVec3()
@@ -324,7 +324,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
UnitTemplateData.heading = GroupUnitHeading UnitTemplateData.heading = GroupUnitHeading
else else
if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then if SpawnGroupTemplate.units[UnitTemplateID].name ~= self:Name() then
self:T("nilling") --self:T("nilling")
SpawnGroupTemplate.units[UnitTemplateID].delete = true SpawnGroupTemplate.units[UnitTemplateID].delete = true
end end
end end
@@ -336,7 +336,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
while i <= #SpawnGroupTemplate.units do while i <= #SpawnGroupTemplate.units do
local UnitTemplateData = SpawnGroupTemplate.units[i] local UnitTemplateData = SpawnGroupTemplate.units[i]
self:T( UnitTemplateData.name ) --self:T( UnitTemplateData.name )
if UnitTemplateData.delete then if UnitTemplateData.delete then
table.remove( SpawnGroupTemplate.units, i ) table.remove( SpawnGroupTemplate.units, i )
@@ -347,7 +347,7 @@ function UNIT:ReSpawnAt( Coordinate, Heading )
SpawnGroupTemplate.groupId = nil SpawnGroupTemplate.groupId = nil
self:T( SpawnGroupTemplate ) --self:T( SpawnGroupTemplate )
_DATABASE:Spawn( SpawnGroupTemplate ) _DATABASE:Spawn( SpawnGroupTemplate )
end end
@@ -358,7 +358,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive. -- @return #boolean `true` if Unit is activated. `nil` The DCS Unit is not existing or alive.
function UNIT:IsActive() function UNIT:IsActive()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -395,7 +395,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean Returns `true` if Unit is alive and active, `false` if it exists but is not active and `nil` if the object does not exist or DCS `isExist` function returns false. -- @return #boolean Returns `true` if Unit is alive and active, `false` if it exists but is not active and `nil` if the object does not exist or DCS `isExist` function returns false.
function UNIT:IsAlive() function UNIT:IsAlive()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit local DCSUnit = self:GetDCSObject() -- DCS#Unit
@@ -418,7 +418,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string The Callsign of the Unit. -- @return #string The Callsign of the Unit.
function UNIT:GetCallsign() function UNIT:GetCallsign()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -430,7 +430,7 @@ function UNIT:GetCallsign()
return UnitCallSign return UnitCallSign
end end
self:F( self.ClassName .. " " .. self.UnitName .. " not found!" ) --self:F( self.ClassName .. " " .. self.UnitName .. " not found!" )
return nil return nil
end end
@@ -477,7 +477,7 @@ end
-- @return #string Player Name -- @return #string Player Name
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPlayerName() function UNIT:GetPlayerName()
self:F( self.UnitName ) --self:F( self.UnitName )
local DCSUnit = self:GetDCSObject() -- DCS#Unit local DCSUnit = self:GetDCSObject() -- DCS#Unit
@@ -551,7 +551,7 @@ end
-- @return #number The Unit number. -- @return #number The Unit number.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetNumber() function UNIT:GetNumber()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -568,7 +568,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Speed in km/h. -- @return #number Speed in km/h.
function UNIT:GetSpeedMax() function UNIT:GetSpeedMax()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local Desc = self:GetDesc() local Desc = self:GetDesc()
@@ -585,7 +585,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Range in meters. -- @return #number Range in meters.
function UNIT:GetRange() function UNIT:GetRange()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local Desc = self:GetDesc() local Desc = self:GetDesc()
@@ -607,7 +607,7 @@ end
-- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable"). -- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable").
-- @return #number Refueling system (if any): 0=boom, 1=probe. -- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsRefuelable() function UNIT:IsRefuelable()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local refuelable=self:HasAttribute("Refuelable") local refuelable=self:HasAttribute("Refuelable")
@@ -626,7 +626,7 @@ end
-- @return #boolean If true, unit is a tanker (checks for the attribute "Tankers"). -- @return #boolean If true, unit is a tanker (checks for the attribute "Tankers").
-- @return #number Refueling system (if any): 0=boom, 1=probe. -- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsTanker() function UNIT:IsTanker()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local tanker=self:HasAttribute("Tankers") local tanker=self:HasAttribute("Tankers")
@@ -725,7 +725,7 @@ end
-- @param Wrapper.Unit#UNIT self -- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist. -- @return Wrapper.Group#GROUP The Group of the Unit or `nil` if the unit does not exist.
function UNIT:GetGroup() function UNIT:GetGroup()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local UnitGroup = GROUP:FindByName(self.GroupName) local UnitGroup = GROUP:FindByName(self.GroupName)
if UnitGroup then if UnitGroup then
return UnitGroup return UnitGroup
@@ -749,13 +749,13 @@ end
-- @return #string The name of the DCS Unit. -- @return #string The name of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:GetPrefix() function UNIT:GetPrefix()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 ) local UnitPrefix = string.match( self.UnitName, ".*#" ):sub( 1, -2 )
self:T3( UnitPrefix ) --self:T3( UnitPrefix )
return UnitPrefix return UnitPrefix
end end
@@ -766,7 +766,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table! -- @return DCS#Unit.Ammo Table with ammuntion of the unit (or nil). This can be a complex table!
function UNIT:GetAmmo() function UNIT:GetAmmo()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
--local status, unitammo = pcall( --local status, unitammo = pcall(
@@ -958,7 +958,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return DCS#Unit.Sensors Table of sensors. -- @return DCS#Unit.Sensors Table of sensors.
function UNIT:GetSensors() function UNIT:GetSensors()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -977,7 +977,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors. -- @return #boolean returns true if the unit has specified types of sensors. This function is more preferable than Unit.getSensors() if you don't want to get information about all the unit's sensors, and just want to check if the unit has specified types of sensors.
function UNIT:HasSensors( ... ) function UNIT:HasSensors( ... )
self:F2( arg ) --self:F2( arg )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -993,7 +993,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean returns true if the unit is SEADable. -- @return #boolean returns true if the unit is SEADable.
function UNIT:HasSEAD() function UNIT:HasSEAD()
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1021,7 +1021,7 @@ end
-- @return #boolean Indicates if at least one of the unit's radar(s) is on. -- @return #boolean Indicates if at least one of the unit's radar(s) is on.
-- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target. -- @return DCS#Object The object of the radar's interest. Not nil only if at least one radar of the unit is tracking a target.
function UNIT:GetRadar() function UNIT:GetRadar()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1037,7 +1037,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The relative amount of fuel (from 0.0 to 1.0) or *nil* if the DCS Unit is not existing or alive. -- @return #number The relative amount of fuel (from 0.0 to 1.0) or *nil* if the DCS Unit is not existing or alive.
function UNIT:GetFuel() function UNIT:GetFuel()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1054,14 +1054,14 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}. -- @return #list<Wrapper.Unit#UNIT> A list of one @{Wrapper.Unit}.
function UNIT:GetUnits() function UNIT:GetUnits()
self:F3( { self.UnitName } ) --self:F3( { self.UnitName } )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
local Units = {} local Units = {}
if DCSUnit then if DCSUnit then
Units[1] = UNIT:Find( DCSUnit ) Units[1] = UNIT:Find( DCSUnit )
self:T3( Units ) -self:T3( Units )
return Units return Units
end end
@@ -1073,7 +1073,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's health value or -1 if unit does not exist any more. -- @return #number The Unit's health value or -1 if unit does not exist any more.
function UNIT:GetLife() function UNIT:GetLife()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1089,7 +1089,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's initial health value or 0 if unit does not exist any more. -- @return #number The Unit's initial health value or 0 if unit does not exist any more.
function UNIT:GetLife0() function UNIT:GetLife0()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1105,7 +1105,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more. -- @return #number The Unit's relative health value, i.e. a number in [0,1] or -1 if unit does not exist any more.
function UNIT:GetLifeRelative() function UNIT:GetLifeRelative()
self:F2(self.UnitName) --self:F2(self.UnitName)
if self and self:IsAlive() then if self and self:IsAlive() then
local life0=self:GetLife0() local life0=self:GetLife0()
@@ -1120,7 +1120,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more. -- @return #number The Unit's relative health value, i.e. a number in [0,1] or 1 if unit does not exist any more.
function UNIT:GetDamageRelative() function UNIT:GetDamageRelative()
self:F2(self.UnitName) --self:F2(self.UnitName)
if self and self:IsAlive() then if self and self:IsAlive() then
return 1-self:GetLifeRelative() return 1-self:GetLifeRelative()
@@ -1158,7 +1158,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #number Unit category from `getDesc().category`. -- @return #number Unit category from `getDesc().category`.
function UNIT:GetUnitCategory() function UNIT:GetUnitCategory()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
@@ -1172,7 +1172,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship -- @return #string Category name = Helicopter, Airplane, Ground Unit, Ship
function UNIT:GetCategoryName() function UNIT:GetCategoryName()
self:F3( self.UnitName ) --self:F3( self.UnitName )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
@@ -1184,7 +1184,7 @@ function UNIT:GetCategoryName()
[Unit.Category.STRUCTURE] = "Structure", [Unit.Category.STRUCTURE] = "Structure",
} }
local UnitCategory = DCSUnit:getDesc().category local UnitCategory = DCSUnit:getDesc().category
self:T3( UnitCategory ) --self:T3( UnitCategory )
return CategoryNames[UnitCategory] return CategoryNames[UnitCategory]
end end
@@ -1412,7 +1412,7 @@ end
-- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit. -- @return true If the other DCS Unit is within the radius of the 2D point of the DCS Unit.
-- @return #nil The DCS Unit is not existing or alive. -- @return #nil The DCS Unit is not existing or alive.
function UNIT:OtherUnitInRadius( AwaitUnit, Radius ) function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } ) --self:F2( { self.UnitName, AwaitUnit.UnitName, Radius } )
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
@@ -1421,10 +1421,10 @@ function UNIT:OtherUnitInRadius( AwaitUnit, Radius )
local AwaitUnitVec3 = AwaitUnit:GetVec3() local AwaitUnitVec3 = AwaitUnit:GetVec3()
if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then if (((UnitVec3.x - AwaitUnitVec3.x)^2 + (UnitVec3.z - AwaitUnitVec3.z)^2)^0.5 <= Radius) then
self:T3( "true" ) --self:T3( "true" )
return true return true
else else
self:T3( "false" ) --self:T3( "false" )
return false return false
end end
end end
@@ -1442,17 +1442,17 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean IsFriendly evaluation result. -- @return #boolean IsFriendly evaluation result.
function UNIT:IsFriendly( FriendlyCoalition ) function UNIT:IsFriendly( FriendlyCoalition )
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitCoalition = DCSUnit:getCoalition() local UnitCoalition = DCSUnit:getCoalition()
self:T3( { UnitCoalition, FriendlyCoalition } ) --self:T3( { UnitCoalition, FriendlyCoalition } )
local IsFriendlyResult = ( UnitCoalition == FriendlyCoalition ) local IsFriendlyResult = ( UnitCoalition == FriendlyCoalition )
self:F( IsFriendlyResult ) --self:F( IsFriendlyResult )
return IsFriendlyResult return IsFriendlyResult
end end
@@ -1464,17 +1464,17 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #boolean Ship category evaluation result. -- @return #boolean Ship category evaluation result.
function UNIT:IsShip() function UNIT:IsShip()
self:F2() --self:F2()
local DCSUnit = self:GetDCSObject() local DCSUnit = self:GetDCSObject()
if DCSUnit then if DCSUnit then
local UnitDescriptor = DCSUnit:getDesc() local UnitDescriptor = DCSUnit:getDesc()
self:T3( { UnitDescriptor.category, Unit.Category.SHIP } ) --self:T3( { UnitDescriptor.category, Unit.Category.SHIP } )
local IsShipResult = ( UnitDescriptor.category == Unit.Category.SHIP ) local IsShipResult = ( UnitDescriptor.category == Unit.Category.SHIP )
self:T3( IsShipResult ) --self:T3( IsShipResult )
return IsShipResult return IsShipResult
end end
@@ -1486,7 +1486,7 @@ end
-- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed. -- @param #boolean NoHeloCheck If true, no additonal checks for helos are performed.
-- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive. -- @return #boolean Return true if in the air or #nil if the UNIT is not existing or alive.
function UNIT:InAir(NoHeloCheck) function UNIT:InAir(NoHeloCheck)
self:F2( self.UnitName ) --self:F2( self.UnitName )
-- Get DCS unit object. -- Get DCS unit object.
local DCSUnit = self:GetDCSObject() --DCS#Unit local DCSUnit = self:GetDCSObject() --DCS#Unit
@@ -1513,7 +1513,7 @@ function UNIT:InAir(NoHeloCheck)
end end
end end
self:T3( UnitInAir ) --self:T3( UnitInAir )
return UnitInAir return UnitInAir
end end
@@ -1708,7 +1708,7 @@ end
-- @param #boolean switch If true, emission is enabled. If false, emission is disabled. -- @param #boolean switch If true, emission is enabled. If false, emission is disabled.
-- @return #UNIT self -- @return #UNIT self
function UNIT:EnableEmission(switch) function UNIT:EnableEmission(switch)
self:F2( self.UnitName ) --self:F2( self.UnitName )
local switch = switch or false local switch = switch or false
@@ -1727,7 +1727,7 @@ end
-- @param #UNIT self -- @param #UNIT self
-- @return #string Skill String of skill name. -- @return #string Skill String of skill name.
function UNIT:GetSkill() function UNIT:GetSkill()
self:F2( self.UnitName ) --self:F2( self.UnitName )
local name = self.UnitName local name = self.UnitName
local skill = "Random" local skill = "Random"
if _DATABASE.Templates.Units[name] and _DATABASE.Templates.Units[name].Template and _DATABASE.Templates.Units[name].Template.skill then if _DATABASE.Templates.Units[name] and _DATABASE.Templates.Units[name].Template and _DATABASE.Templates.Units[name].Template.skill then
@@ -1743,7 +1743,7 @@ end
-- @return #string VCN Voice Callsign Number or nil if not set/capable. -- @return #string VCN Voice Callsign Number or nil if not set/capable.
-- @return #string Lead If true, unit is Flight Lead, else false or nil. -- @return #string Lead If true, unit is Flight Lead, else false or nil.
function UNIT:GetSTN() function UNIT:GetSTN()
self:F2(self.UnitName) --self:F2(self.UnitName)
local STN = nil -- STN/TN local STN = nil -- STN/TN
local VCL = nil -- VoiceCallsignLabel local VCL = nil -- VoiceCallsignLabel
local VCN = nil -- VoiceCallsignNumber local VCN = nil -- VoiceCallsignNumber