Event prefix can be nil, if the event occurs on a non-spawned group with no # tag.

This commit is contained in:
FlightControl
2017-05-05 13:37:04 +02:00
parent 96aa49d682
commit 625450ba12
@@ -1595,12 +1595,14 @@ 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!
self:T( { "Birth Event:", EventPrefix, self.SpawnTemplatePrefix } ) self:T( { "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:T( "Alive Units: " .. self.AliveUnits ) self:T( "Alive Units: " .. self.AliveUnits )
end end
end end
end
end end
@@ -1616,12 +1618,14 @@ function SPAWN:_OnDeadOrCrash( 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!
self:T( { "Dead event: " .. EventPrefix } ) self:T( { "Dead 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.AliveUnits = self.AliveUnits - 1 self.AliveUnits = self.AliveUnits - 1
self:T( "Alive Units: " .. self.AliveUnits ) self:T( "Alive Units: " .. self.AliveUnits )
end end
end end
end
end end
--- Will detect AIR Units taking off... When the event takes place, the spawned Group is registered as airborne... --- Will detect AIR Units taking off... When the event takes place, the spawned Group is registered as airborne...
@@ -1634,12 +1638,14 @@ function SPAWN:_OnTakeOff( EventData )
local SpawnGroup = EventData.IniGroup local SpawnGroup = EventData.IniGroup
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!
self:T( { "TakeOff event: " .. EventPrefix } ) self:T( { "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:T( "self.Landed = false" ) self:T( "self.Landed = false" )
SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", false ) SpawnGroup:SetState( SpawnGroup, "Spawn_Landed", false )
end end
end end
end
end end
--- Will detect AIR Units landing... When the event takes place, the spawned Group is registered as landed. --- Will detect AIR Units landing... When the event takes place, the spawned Group is registered as landed.
@@ -1652,6 +1658,7 @@ function SPAWN:_OnLand( EventData )
local SpawnGroup = EventData.IniGroup local SpawnGroup = EventData.IniGroup
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!
self:T( { "Land event: " .. EventPrefix } ) self:T( { "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.
@@ -1663,6 +1670,7 @@ function SPAWN:_OnLand( EventData )
end end
end end
end end
end
end end
--- Will detect AIR Units shutting down their engines ... --- Will detect AIR Units shutting down their engines ...
@@ -1676,6 +1684,7 @@ function SPAWN:_OnEngineShutDown( EventData )
local SpawnGroup = EventData.IniGroup local SpawnGroup = EventData.IniGroup
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!
self:T( { "EngineShutdown event: " .. EventPrefix } ) self:T( { "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
@@ -1687,6 +1696,7 @@ function SPAWN:_OnEngineShutDown( EventData )
end end
end end
end end
end
end end
--- This function is called automatically by the Spawning scheduler. --- This function is called automatically by the Spawning scheduler.