mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Event Handling Optimization
-- Created a HandleEvent method -- Created an UnHandleEvent method
This commit is contained in:
parent
154f729788
commit
3db8062583
@ -347,6 +347,137 @@ do -- Event Handling
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-- Event handling function prototypes
|
||||
|
||||
--- Occurs whenever any unit in a mission fires a weapon. But not any machine gun or autocannon based weapon, those are handled by EVENT.ShootingStart.
|
||||
-- @function [parent=#BASE] OnEventShot
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs whenever an object is hit by a weapon.
|
||||
-- initiator : The unit object the fired the weapon
|
||||
-- weapon: Weapon object that hit the target
|
||||
-- target: The Object that was hit.
|
||||
-- @function [parent=#BASE] OnEventHit
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when an aircraft takes off from an airbase, farp, or ship.
|
||||
-- initiator : The unit that tookoff
|
||||
-- place: Object from where the AI took-off from. Can be an Airbase Object, FARP, or Ships
|
||||
-- @function [parent=#BASE] OnEventTakeoff
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when an aircraft lands at an airbase, farp or ship
|
||||
-- initiator : The unit that has landed
|
||||
-- place: Object that the unit landed on. Can be an Airbase Object, FARP, or Ships
|
||||
-- @function [parent=#BASE] OnEventLand
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any aircraft crashes into the ground and is completely destroyed.
|
||||
-- initiator : The unit that has crashed
|
||||
-- @function [parent=#BASE] OnEventCrash
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a pilot ejects from an aircraft
|
||||
-- initiator : The unit that has ejected
|
||||
-- @function [parent=#BASE] OnEventEjection
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when an aircraft connects with a tanker and begins taking on fuel.
|
||||
-- initiator : The unit that is receiving fuel.
|
||||
-- @function [parent=#BASE] OnEventRefueling
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when an object is completely destroyed.
|
||||
-- initiator : The unit that is was destroyed.
|
||||
-- @function [parent=#BASE] OnEvent
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when the pilot of an aircraft is killed. Can occur either if the player is alive and crashes or if a weapon kills the pilot without completely destroying the plane.
|
||||
-- initiator : The unit that the pilot has died in.
|
||||
-- @function [parent=#BASE] OnEventPilotDead
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a ground unit captures either an airbase or a farp.
|
||||
-- initiator : The unit that captured the base
|
||||
-- place: The airbase that was captured, can be a FARP or Airbase. When calling place:getCoalition() the faction will already be the new owning faction.
|
||||
-- @function [parent=#BASE] OnEventBaseCaptured
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a mission starts
|
||||
-- @function [parent=#BASE] OnEventMissionStart
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when a mission ends
|
||||
-- @function [parent=#BASE] OnEventMissionEnd
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when an aircraft is finished taking fuel.
|
||||
-- initiator : The unit that was receiving fuel.
|
||||
-- @function [parent=#BASE] OnEventRefuelingStop
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any object is spawned into the mission.
|
||||
-- initiator : The unit that was spawned
|
||||
-- @function [parent=#BASE] OnEventBirth
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any system fails on a human controlled aircraft.
|
||||
-- initiator : The unit that had the failure
|
||||
-- @function [parent=#BASE] OnEventHumanFailure
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any aircraft starts its engines.
|
||||
-- initiator : The unit that is starting its engines.
|
||||
-- @function [parent=#BASE] OnEventEngineStartup
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any aircraft shuts down its engines.
|
||||
-- initiator : The unit that is stopping its engines.
|
||||
-- @function [parent=#BASE] OnEventEngineShutdown
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any player assumes direct control of a unit.
|
||||
-- initiator : The unit that is being taken control of.
|
||||
-- @function [parent=#BASE] OnEventPlayerEnterUnit
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any player relieves control of a unit to the AI.
|
||||
-- initiator : The unit that the player left.
|
||||
-- @function [parent=#BASE] OnEventPlayerLeaveUnit
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any unit begins firing a weapon that has a high rate of fire. Most common with aircraft cannons (GAU-8), autocannons, and machine guns.
|
||||
-- initiator : The unit that is doing the shooing.
|
||||
-- target: The unit that is being targeted.
|
||||
-- @function [parent=#BASE] OnEventShootingStart
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
--- Occurs when any unit stops firing its weapon. Event will always correspond with a shooting start event.
|
||||
-- initiator : The unit that was doing the shooing.
|
||||
-- @function [parent=#BASE] OnEventShootingEnd
|
||||
-- @param #BASE self
|
||||
-- @param Core.Event#EVENTDATA EventData The EventData structure.
|
||||
|
||||
end
|
||||
|
||||
|
||||
@ -88,11 +88,11 @@ function DATABASE:New()
|
||||
|
||||
self:HandleEvent( EVENTS.Birth, self._EventOnBirth )
|
||||
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
||||
self.HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||
|
||||
-- Follow alive players and clients
|
||||
self.HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||
self.HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
||||
self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
||||
|
||||
self:_RegisterTemplates()
|
||||
self:_RegisterGroupsAndUnits()
|
||||
|
||||
@ -51,7 +51,7 @@ EVENTS = {
|
||||
Birth = world.event.S_EVENT_BIRTH,
|
||||
HumanFailure = world.event.S_EVENT_HUMAN_FAILURE,
|
||||
EngineStartup = world.event.S_EVENT_ENGINE_STARTUP,
|
||||
EngineShutDown = world.event.S_EVENT_ENGINE_SHUTDOWN,
|
||||
EngineShutdown = world.event.S_EVENT_ENGINE_SHUTDOWN,
|
||||
PlayerEnterUnit = world.event.S_EVENT_PLAYER_ENTER_UNIT,
|
||||
PlayerLeaveUnit = world.event.S_EVENT_PLAYER_LEAVE_UNIT,
|
||||
PlayerComment = world.event.S_EVENT_PLAYER_COMMENT,
|
||||
|
||||
@ -453,13 +453,13 @@ function SET_BASE:_FilterStart()
|
||||
end
|
||||
end
|
||||
|
||||
self.HandleEvent( EVENTS.Birth, self._EventOnBirth )
|
||||
self.HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
||||
self.HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.Birth, self._EventOnBirth )
|
||||
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
|
||||
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
|
||||
|
||||
-- Follow alive players and clients
|
||||
self.HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||
self.HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
||||
self:HandleEvent( EVENTS.PlayerEnterUnit, self._EventOnPlayerEnterUnit )
|
||||
self:HandleEvent( EVENTS.PlayerLeaveUnit, self._EventOnPlayerLeaveUnit )
|
||||
|
||||
|
||||
return self
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -33,4 +33,8 @@ function Tank2:OnEventDead( EventData )
|
||||
self:SmokeBlue()
|
||||
end
|
||||
|
||||
function Tank2:OnEventCrash(EventData)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,25 @@
|
||||
---
|
||||
-- Name: EVT-100 - OnEventShot Example
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 7 February 2017
|
||||
--
|
||||
-- # Situation:
|
||||
--
|
||||
-- A plane is flying in the air and shoots an missile to a ground target.
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. Observe the plane shooting the missile.
|
||||
-- 2. Observe when the plane shoots the missile, a dcs.log entry is written in the logging.
|
||||
-- 3. Check the contents of the fields of the S_EVENT_SHOT entry.
|
||||
|
||||
local Plane = UNIT:FindByName( "Plane" )
|
||||
|
||||
Plane:HandleEvent( EVENTS.Shot )
|
||||
|
||||
function Plane:OnEventShot( EventData )
|
||||
|
||||
Plane:MessageToAll( "I just fired a missile!", 15, "Alert!" )
|
||||
end
|
||||
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,32 @@
|
||||
---
|
||||
-- Name: EVT-101 - OnEventHit Example
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 7 February 2017
|
||||
--
|
||||
-- # Situation:
|
||||
--
|
||||
-- A plane is flying in the air and shoots an missile to a ground target.
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. Observe the plane shooting the missile.
|
||||
-- 2. Observe when the missile hits the target, a dcs.log entry is written in the logging.
|
||||
-- 3. Check the contents of the fields of the S_EVENT_HIT entry.
|
||||
|
||||
local Plane = UNIT:FindByName( "Plane" )
|
||||
|
||||
local Tank = UNIT:FindByName( "Tank" )
|
||||
|
||||
Plane:HandleEvent( EVENTS.Hit )
|
||||
Tank:HandleEvent( EVENTS.Hit )
|
||||
|
||||
function Plane:OnEventHit( EventData )
|
||||
|
||||
Plane:MessageToAll( "I just got hit!", 15, "Alert!" )
|
||||
end
|
||||
|
||||
function Tank:OnEventHit( EventData )
|
||||
Tank:MessageToAll( "I just got hit!", 15, "Alert!" )
|
||||
end
|
||||
|
||||
|
||||
Binary file not shown.
@ -0,0 +1,33 @@
|
||||
---
|
||||
-- Name: EVT-102 - OnEventTakeoff Example
|
||||
-- Author: FlightControl
|
||||
-- Date Created: 7 February 2017
|
||||
--
|
||||
-- # Situation:
|
||||
--
|
||||
-- A human plane and an AI plane are taking off from an airfield.
|
||||
--
|
||||
-- # Test cases:
|
||||
--
|
||||
-- 1. Take-Off the planes from the runway.
|
||||
-- 2. When the planes take-off, observe the message being sent.
|
||||
-- 3. Check the contents of the fields of the S_EVENT_TAKEOFF entry in the dcs.log file.
|
||||
|
||||
local PlaneAI = UNIT:FindByName( "PlaneAI" )
|
||||
|
||||
local PlaneHuman = UNIT:FindByName( "PlaneHuman" )
|
||||
|
||||
PlaneAI:HandleEvent( EVENTS.Takeoff )
|
||||
PlaneHuman:HandleEvent( EVENTS.Takeoff )
|
||||
|
||||
function PlaneAI:OnEventTakeoff( EventData )
|
||||
|
||||
PlaneHuman:MessageToAll( "AI Taking Off", 15, "Alert!" )
|
||||
end
|
||||
|
||||
function PlaneHuman:OnEventTakeoff( EventData )
|
||||
|
||||
PlaneHuman:MessageToAll( "Player " .. PlaneHuman:GetPlayerName() .. " is Taking Off", 15, "Alert!" )
|
||||
end
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user