Updated improved version ...

-- Fixed error in HIT processing. HIT events are only for the Target,
when set on UNIT or GROUP level!
This commit is contained in:
FlightControl
2017-04-11 07:01:44 +02:00
parent 785a297a69
commit c8cf0e2cc5
2 changed files with 54 additions and 20 deletions

View File

@@ -274,116 +274,139 @@ EVENTS = {
local _EVENTMETA = { local _EVENTMETA = {
[world.event.S_EVENT_SHOT] = { [world.event.S_EVENT_SHOT] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventShot", Event = "OnEventShot",
Text = "S_EVENT_SHOT" Text = "S_EVENT_SHOT"
}, },
[world.event.S_EVENT_HIT] = { [world.event.S_EVENT_HIT] = {
Order = 1, Order = 1,
Side = "T",
Event = "OnEventHit", Event = "OnEventHit",
Text = "S_EVENT_HIT" Text = "S_EVENT_HIT"
}, },
[world.event.S_EVENT_TAKEOFF] = { [world.event.S_EVENT_TAKEOFF] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventTakeoff", Event = "OnEventTakeoff",
Text = "S_EVENT_TAKEOFF" Text = "S_EVENT_TAKEOFF"
}, },
[world.event.S_EVENT_LAND] = { [world.event.S_EVENT_LAND] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventLand", Event = "OnEventLand",
Text = "S_EVENT_LAND" Text = "S_EVENT_LAND"
}, },
[world.event.S_EVENT_CRASH] = { [world.event.S_EVENT_CRASH] = {
Order = -1, Order = -1,
Side = "I",
Event = "OnEventCrash", Event = "OnEventCrash",
Text = "S_EVENT_CRASH" Text = "S_EVENT_CRASH"
}, },
[world.event.S_EVENT_EJECTION] = { [world.event.S_EVENT_EJECTION] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventEjection", Event = "OnEventEjection",
Text = "S_EVENT_EJECTION" Text = "S_EVENT_EJECTION"
}, },
[world.event.S_EVENT_REFUELING] = { [world.event.S_EVENT_REFUELING] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventRefueling", Event = "OnEventRefueling",
Text = "S_EVENT_REFUELING" Text = "S_EVENT_REFUELING"
}, },
[world.event.S_EVENT_DEAD] = { [world.event.S_EVENT_DEAD] = {
Order = -1, Order = -1,
Side = "I",
Event = "OnEventDead", Event = "OnEventDead",
Text = "S_EVENT_DEAD" Text = "S_EVENT_DEAD"
}, },
[world.event.S_EVENT_PILOT_DEAD] = { [world.event.S_EVENT_PILOT_DEAD] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventPilotDead", Event = "OnEventPilotDead",
Text = "S_EVENT_PILOT_DEAD" Text = "S_EVENT_PILOT_DEAD"
}, },
[world.event.S_EVENT_BASE_CAPTURED] = { [world.event.S_EVENT_BASE_CAPTURED] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventBaseCaptured", Event = "OnEventBaseCaptured",
Text = "S_EVENT_BASE_CAPTURED" Text = "S_EVENT_BASE_CAPTURED"
}, },
[world.event.S_EVENT_MISSION_START] = { [world.event.S_EVENT_MISSION_START] = {
Order = 1, Order = 1,
Side = "N",
Event = "OnEventMissionStart", Event = "OnEventMissionStart",
Text = "S_EVENT_MISSION_START" Text = "S_EVENT_MISSION_START"
}, },
[world.event.S_EVENT_MISSION_END] = { [world.event.S_EVENT_MISSION_END] = {
Order = 1, Order = 1,
Side = "N",
Event = "OnEventMissionEnd", Event = "OnEventMissionEnd",
Text = "S_EVENT_MISSION_END" Text = "S_EVENT_MISSION_END"
}, },
[world.event.S_EVENT_TOOK_CONTROL] = { [world.event.S_EVENT_TOOK_CONTROL] = {
Order = 1, Order = 1,
Side = "N",
Event = "OnEventTookControl", Event = "OnEventTookControl",
Text = "S_EVENT_TOOK_CONTROL" Text = "S_EVENT_TOOK_CONTROL"
}, },
[world.event.S_EVENT_REFUELING_STOP] = { [world.event.S_EVENT_REFUELING_STOP] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventRefuelingStop", Event = "OnEventRefuelingStop",
Text = "S_EVENT_REFUELING_STOP" Text = "S_EVENT_REFUELING_STOP"
}, },
[world.event.S_EVENT_BIRTH] = { [world.event.S_EVENT_BIRTH] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventBirth", Event = "OnEventBirth",
Text = "S_EVENT_BIRTH" Text = "S_EVENT_BIRTH"
}, },
[world.event.S_EVENT_HUMAN_FAILURE] = { [world.event.S_EVENT_HUMAN_FAILURE] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventHumanFailure", Event = "OnEventHumanFailure",
Text = "S_EVENT_HUMAN_FAILURE" Text = "S_EVENT_HUMAN_FAILURE"
}, },
[world.event.S_EVENT_ENGINE_STARTUP] = { [world.event.S_EVENT_ENGINE_STARTUP] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventEngineStartup", Event = "OnEventEngineStartup",
Text = "S_EVENT_ENGINE_STARTUP" Text = "S_EVENT_ENGINE_STARTUP"
}, },
[world.event.S_EVENT_ENGINE_SHUTDOWN] = { [world.event.S_EVENT_ENGINE_SHUTDOWN] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventEngineShutdown", Event = "OnEventEngineShutdown",
Text = "S_EVENT_ENGINE_SHUTDOWN" Text = "S_EVENT_ENGINE_SHUTDOWN"
}, },
[world.event.S_EVENT_PLAYER_ENTER_UNIT] = { [world.event.S_EVENT_PLAYER_ENTER_UNIT] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventPlayerEnterUnit", Event = "OnEventPlayerEnterUnit",
Text = "S_EVENT_PLAYER_ENTER_UNIT" Text = "S_EVENT_PLAYER_ENTER_UNIT"
}, },
[world.event.S_EVENT_PLAYER_LEAVE_UNIT] = { [world.event.S_EVENT_PLAYER_LEAVE_UNIT] = {
Order = -1, Order = -1,
Side = "I",
Event = "OnEventPlayerLeaveUnit", Event = "OnEventPlayerLeaveUnit",
Text = "S_EVENT_PLAYER_LEAVE_UNIT" Text = "S_EVENT_PLAYER_LEAVE_UNIT"
}, },
[world.event.S_EVENT_PLAYER_COMMENT] = { [world.event.S_EVENT_PLAYER_COMMENT] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventPlayerComment", Event = "OnEventPlayerComment",
Text = "S_EVENT_PLAYER_COMMENT" Text = "S_EVENT_PLAYER_COMMENT"
}, },
[world.event.S_EVENT_SHOOTING_START] = { [world.event.S_EVENT_SHOOTING_START] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventShootingStart", Event = "OnEventShootingStart",
Text = "S_EVENT_SHOOTING_START" Text = "S_EVENT_SHOOTING_START"
}, },
[world.event.S_EVENT_SHOOTING_END] = { [world.event.S_EVENT_SHOOTING_END] = {
Order = 1, Order = 1,
Side = "I",
Event = "OnEventShootingEnd", Event = "OnEventShootingEnd",
Text = "S_EVENT_SHOOTING_END" Text = "S_EVENT_SHOOTING_END"
}, },
@@ -674,10 +697,11 @@ function EVENT:onEvent( Event )
return errmsg return errmsg
end end
self:E( _EVENTMETA[Event.id].Text, Event )
local EventMeta = _EVENTMETA[Event.id]
self:E( EventMeta.Text, Event )
if self and self.Events and self.Events[Event.id] then if self and self.Events and self.Events[Event.id] then
if Event.initiator then if Event.initiator then
@@ -782,12 +806,11 @@ function EVENT:onEvent( Event )
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget() --Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
end end
local PriorityOrder = _EVENTMETA[Event.id].Order
local PriorityBegin = PriorityOrder == -1 and 5 or 1 local PriorityBegin = PriorityOrder == -1 and 5 or 1
local PriorityEnd = PriorityOrder == -1 and 1 or 5 local PriorityEnd = PriorityOrder == -1 and 1 or 5
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:E( { _EVENTMETA[Event.id].Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } ) self:E( { EventMeta.Text, Event, Event.IniDCSUnitName, Event.TgtDCSUnitName, PriorityOrder } )
end end
for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do for EventPriority = PriorityBegin, PriorityEnd, PriorityOrder do
@@ -803,12 +826,16 @@ function EVENT:onEvent( Event )
Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName ) Event.TgtGroup = GROUP:FindByName( Event.TgtDCSGroupName )
-- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT. -- If the EventData is for a UNIT, the call directly the EventClass EventFunction for that UNIT.
if ( Event.IniDCSUnitName and EventData.EventUnit ) or if EventData.EventUnit then
( Event.TgtDCSUnitName and EventData.EventUnit ) then
local UnitName = EventClass:GetName() -- So now the EventClass must be a UNIT class!!! We check if it is still "Alive".
if UnitName then if EventClass:IsAlive() then
if UnitName == Event.IniDCSUnitName or UnitName == Event.TgtDCSUnitName then
local UnitName = EventClass:GetName()
if ( EventMeta.Side == "I" and UnitName == Event.IniDCSUnitName ) or
( EventMeta.Side == "T" and UnitName == Event.TgtDCSUnitName ) then
-- First test if a EventFunction is Set, otherwise search for the default function -- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then if EventData.EventFunction then
@@ -824,12 +851,12 @@ function EVENT:onEvent( Event )
else else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object. -- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ] local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function. -- Now call the default event function.
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } ) self:E( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end end
local Result, Value = xpcall( local Result, Value = xpcall(
@@ -840,17 +867,23 @@ function EVENT:onEvent( Event )
end end
end end
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveForUnit( EventClass, Event.id ) self:RemoveForUnit( EventClass, Event.id )
end end
else else
-- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP. -- If the EventData is for a GROUP, the call directly the EventClass EventFunction for the UNIT in that GROUP.
if ( Event.IniDCSUnitName and Event.IniDCSGroupName and Event.IniGroupName and EventData.EventGroup ) or if EventData.EventGroup then
( Event.TgtDCSUnitName and Event.TgtDCSGroupName and Event.TgtGroupName and EventData.EventGroup ) then
-- So now the EventClass must be a GROUP class!!! We check if it is still "Alive".
if EventClass:IsAlive() then if EventClass:IsAlive() then
-- We can get the name of the EventClass, which is now always a GROUP object.
local GroupName = EventClass:GetName() local GroupName = EventClass:GetName()
if GroupName == Event.IniDCSGroupName or GroupName == Event.TgtDCSGroupName then
if ( EventMeta.Side == "I" and GroupName == Event.IniDCSGroupName ) or
( EventMeta.Side == "T" and GroupName == Event.TgtDCSGroupName ) then
-- First test if a EventFunction is Set, otherwise search for the default function -- First test if a EventFunction is Set, otherwise search for the default function
if EventData.EventFunction then if EventData.EventFunction then
@@ -866,12 +899,12 @@ function EVENT:onEvent( Event )
else else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object. -- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ] local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function. -- Now call the default event function.
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } ) self:E( { "Calling " .. EventMeta.Event .. " for GROUP ", EventClass:GetClassNameAndID(), EventPriority } )
end end
local Result, Value = xpcall( local Result, Value = xpcall(
@@ -882,6 +915,7 @@ function EVENT:onEvent( Event )
end end
end end
else else
-- The EventClass is not alive anymore, we remove it from the EventHandlers...
self:RemoveForGroup( EventClass, Event.id ) self:RemoveForGroup( EventClass, Event.id )
end end
else else
@@ -904,12 +938,12 @@ function EVENT:onEvent( Event )
else else
-- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object. -- There is no EventFunction defined, so try to find if a default OnEvent function is defined on the object.
local EventFunction = EventClass[ _EVENTMETA[Event.id].Event ] local EventFunction = EventClass[ EventMeta.Event ]
if EventFunction and type( EventFunction ) == "function" then if EventFunction and type( EventFunction ) == "function" then
-- Now call the default event function. -- Now call the default event function.
if Event.IniObjectCategory ~= 3 then if Event.IniObjectCategory ~= 3 then
self:E( { "Calling " .. _EVENTMETA[Event.id].Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } ) self:E( { "Calling " .. EventMeta.Event .. " for Class ", EventClass:GetClassNameAndID(), EventPriority } )
end end
local Result, Value = xpcall( local Result, Value = xpcall(
@@ -927,7 +961,7 @@ function EVENT:onEvent( Event )
end end
end end
else else
self:E( { _EVENTMETA[Event.id].Text, Event } ) self:E( { EventMeta.Text, Event } )
end end
Event = nil Event = nil

View File

@@ -1,5 +1,5 @@
env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' ) env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )
env.info( 'Moose Generation Timestamp: 20170410_0953' ) env.info( 'Moose Generation Timestamp: 20170411_0630' )
local base = _G local base = _G