mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
#ZONE - Trigger added OnAfterZoneEmpty and OnAfterObjectDead
This commit is contained in:
parent
31d0410284
commit
32f0bb33c3
@ -605,10 +605,13 @@ function ZONE_BASE:Trigger(Objects)
|
|||||||
self:AddTransition("TriggerStopped","TriggerStart","TriggerRunning")
|
self:AddTransition("TriggerStopped","TriggerStart","TriggerRunning")
|
||||||
self:AddTransition("*","EnteredZone","*")
|
self:AddTransition("*","EnteredZone","*")
|
||||||
self:AddTransition("*","LeftZone","*")
|
self:AddTransition("*","LeftZone","*")
|
||||||
|
self:AddTransition("*","ZoneEmpty","*")
|
||||||
|
self:AddTransition("*","ObjectDead","*")
|
||||||
self:AddTransition("*","TriggerRunCheck","*")
|
self:AddTransition("*","TriggerRunCheck","*")
|
||||||
self:AddTransition("*","TriggerStop","TriggerStopped")
|
self:AddTransition("*","TriggerStop","TriggerStopped")
|
||||||
self:TriggerStart()
|
self:TriggerStart()
|
||||||
self.checkobjects = Objects
|
self.checkobjects = Objects
|
||||||
|
self.ObjectsInZone = false
|
||||||
if UTILS.IsInstanceOf(Objects,"SET_BASE") then
|
if UTILS.IsInstanceOf(Objects,"SET_BASE") then
|
||||||
self.objectset = Objects.Set
|
self.objectset = Objects.Set
|
||||||
else
|
else
|
||||||
@ -646,6 +649,22 @@ function ZONE_BASE:Trigger(Objects)
|
|||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
-- @param #string To To state.
|
-- @param #string To To state.
|
||||||
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable leaving the zone.
|
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable leaving the zone.
|
||||||
|
|
||||||
|
--- On After "ObjectDead" event. An observed object has left the zone.
|
||||||
|
-- @function [parent=#ZONE_BASE] OnAfterObjectDead
|
||||||
|
-- @param #ZONE_BASE self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param Wrapper.Controllable#CONTROLLABLE Controllable The controllable which died. Might be nil.
|
||||||
|
|
||||||
|
--- On After "ZoneEmpty" event. All observed objects have left the zone or are dead.
|
||||||
|
-- @function [parent=#ZONE_BASE] OnAfterZoneEmpty
|
||||||
|
-- @param #ZONE_BASE self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- (Internal) Check the assigned objects for being in/out of the zone
|
--- (Internal) Check the assigned objects for being in/out of the zone
|
||||||
@ -659,9 +678,13 @@ function ZONE_BASE:_TriggerCheck(fromstart)
|
|||||||
-- just earmark everyone in/out
|
-- just earmark everyone in/out
|
||||||
for _,_object in pairs(objectset) do
|
for _,_object in pairs(objectset) do
|
||||||
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
|
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
|
||||||
if not obj.TriggerInZone then obj.TriggerInZone = {} end
|
if not obj.TriggerInZone then
|
||||||
|
obj.TriggerInZone = {}
|
||||||
|
obj.TriggerZoneDeadNotification = false
|
||||||
|
end
|
||||||
if obj and obj:IsAlive() and self:IsCoordinateInZone(obj:GetCoordinate()) then
|
if obj and obj:IsAlive() and self:IsCoordinateInZone(obj:GetCoordinate()) then
|
||||||
obj.TriggerInZone[self.ZoneName] = true
|
obj.TriggerInZone[self.ZoneName] = true
|
||||||
|
self.ObjectsInZone = true
|
||||||
else
|
else
|
||||||
obj.TriggerInZone[self.ZoneName] = false
|
obj.TriggerInZone[self.ZoneName] = false
|
||||||
end
|
end
|
||||||
@ -669,6 +692,7 @@ function ZONE_BASE:_TriggerCheck(fromstart)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Check for changes
|
-- Check for changes
|
||||||
|
local objcount = 0
|
||||||
for _,_object in pairs(objectset) do
|
for _,_object in pairs(objectset) do
|
||||||
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
|
local obj = _object -- Wrapper.Controllable#CONTROLLABLE
|
||||||
if obj and obj:IsAlive() then
|
if obj and obj:IsAlive() then
|
||||||
@ -683,11 +707,20 @@ function ZONE_BASE:_TriggerCheck(fromstart)
|
|||||||
-- is obj in zone?
|
-- is obj in zone?
|
||||||
local inzone = self:IsCoordinateInZone(obj:GetCoordinate())
|
local inzone = self:IsCoordinateInZone(obj:GetCoordinate())
|
||||||
--self:I("Object "..obj:GetName().." is in zone: "..tostring(inzone))
|
--self:I("Object "..obj:GetName().." is in zone: "..tostring(inzone))
|
||||||
|
if inzone and obj.TriggerInZone[self.ZoneName] then
|
||||||
|
-- just count
|
||||||
|
objcount = objcount + 1
|
||||||
|
self.ObjectsInZone = true
|
||||||
|
obj.TriggerZoneDeadNotification = false
|
||||||
|
end
|
||||||
if inzone and not obj.TriggerInZone[self.ZoneName] then
|
if inzone and not obj.TriggerInZone[self.ZoneName] then
|
||||||
-- wasn't in zone before
|
-- wasn't in zone before
|
||||||
--self:I("Newly entered")
|
--self:I("Newly entered")
|
||||||
self:__EnteredZone(0.5,obj)
|
self:__EnteredZone(0.5,obj)
|
||||||
obj.TriggerInZone[self.ZoneName] = true
|
obj.TriggerInZone[self.ZoneName] = true
|
||||||
|
objcount = objcount + 1
|
||||||
|
self.ObjectsInZone = true
|
||||||
|
obj.TriggerZoneDeadNotification = false
|
||||||
elseif (not inzone) and obj.TriggerInZone[self.ZoneName] then
|
elseif (not inzone) and obj.TriggerInZone[self.ZoneName] then
|
||||||
-- has left the zone
|
-- has left the zone
|
||||||
--self:I("Newly left")
|
--self:I("Newly left")
|
||||||
@ -696,8 +729,21 @@ function ZONE_BASE:_TriggerCheck(fromstart)
|
|||||||
else
|
else
|
||||||
--self:I("Not left or not entered, or something went wrong!")
|
--self:I("Not left or not entered, or something went wrong!")
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
-- object dead
|
||||||
|
if not obj.TriggerZoneDeadNotification == true then
|
||||||
|
obj.TriggerInZone = nil
|
||||||
|
self:__ObjectDead(0.5,obj)
|
||||||
|
obj.TriggerZoneDeadNotification = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- zone empty?
|
||||||
|
if objcount == 0 and self.ObjectsInZone == true then
|
||||||
|
-- zone was not but is now empty
|
||||||
|
self.ObjectsInZone = false
|
||||||
|
self:__ZoneEmpty(0.5)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2816,7 +2816,7 @@ do -- Event Handling
|
|||||||
|
|
||||||
self:EventDispatcher():Reset( self )
|
self:EventDispatcher():Reset( self )
|
||||||
|
|
||||||
for UnitID, UnitData in pairs( self:GetUnits() ) do
|
for UnitID, UnitData in pairs( self:GetUnits() or {}) do
|
||||||
UnitData:ResetEvents()
|
UnitData:ResetEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user