mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Event functions replacement stable now ... (I think)...
This commit is contained in:
parent
66c7ebf786
commit
01c85670ec
@ -2,6 +2,7 @@ rem Generate Moose_Embedded.lua
|
||||
|
||||
copy /b ..\Moose\Routines.lua ^
|
||||
+ ..\Moose\Base.lua ^
|
||||
+ ..\Moose\Event.lua ^
|
||||
+ ..\Moose\Menu.lua ^
|
||||
+ ..\Moose\Group.lua ^
|
||||
+ ..\Moose\Unit.lua ^
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@ Include.File( "Task" )
|
||||
|
||||
--- The CLEANUP class.
|
||||
-- @type CLEANUP
|
||||
-- @extends Base#BASE
|
||||
CLEANUP = {
|
||||
ClassName = "CLEANUP",
|
||||
ZoneNames = {},
|
||||
@ -77,9 +78,8 @@ function CLEANUP:_DestroyUnit( CleanUpUnit, CleanUpUnitName )
|
||||
local CleanUpGroupUnits = CleanUpGroup:getUnits()
|
||||
if #CleanUpGroupUnits == 1 then
|
||||
local CleanUpGroupName = CleanUpGroup:getName()
|
||||
local Event = {["initiator"]=CleanUpUnit,["id"]=8}
|
||||
world.onEvent( Event )
|
||||
trigger.action.deactivateGroup( CleanUpGroup )
|
||||
--self:CreateEventCrash( timer.getTime(), CleanUpUnit )
|
||||
CleanUpGroup:destroy()
|
||||
self:T( { "Destroyed Group:", CleanUpGroupName } )
|
||||
else
|
||||
CleanUpUnit:destroy()
|
||||
@ -116,6 +116,8 @@ function CLEANUP:_OnEventBirth( Event )
|
||||
_EventDispatcher:OnEngineShutDownForUnit( Event.IniDCSUnitName, self._EventAddForCleanUp, self )
|
||||
_EventDispatcher:OnEngineStartUpForUnit( Event.IniDCSUnitName, self._EventAddForCleanUp, self )
|
||||
_EventDispatcher:OnHitForUnit( Event.IniDCSUnitName, self._EventAddForCleanUp, self )
|
||||
_EventDispatcher:OnPilotDeadForUnit( Event.IniDCSUnitName, self._EventCrash, self )
|
||||
_EventDispatcher:OnDeadForUnit( Event.IniDCSUnitName, self._EventCrash, self )
|
||||
_EventDispatcher:OnCrashForUnit( Event.IniDCSUnitName, self._EventCrash, self )
|
||||
_EventDispatcher:OnShotForUnit( Event.IniDCSUnitName, self._EventShot, self )
|
||||
|
||||
@ -135,9 +137,10 @@ end
|
||||
-- Crashed units go into a CleanUpList for removal.
|
||||
-- @param #CLEANUP self
|
||||
-- @param DCSTypes#Event event
|
||||
function CLEANUP:_EventCrash( event )
|
||||
self:F( { event } )
|
||||
function CLEANUP:_EventCrash( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
--TODO: This stuff is not working due to a DCS bug. Burning units cannot be destroyed.
|
||||
--MESSAGE:New( "Crash ", "Crash", 10, "Crash" ):ToAll()
|
||||
-- self:T("before getGroup")
|
||||
-- local _grp = Unit.getGroup(event.initiator)-- Identify the group that fired
|
||||
@ -151,6 +154,7 @@ function CLEANUP:_EventCrash( event )
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroup = Event.IniDCSGroup
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroupName = Event.IniDCSGroupName
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnitName = Event.IniDCSUnitName
|
||||
|
||||
end
|
||||
|
||||
--- Detects if a unit shoots a missile.
|
||||
@ -248,9 +252,11 @@ local CleanUpSurfaceTypeText = {
|
||||
--- At the defined time interval, CleanUp the Groups within the CleanUpList.
|
||||
-- @param #CLEANUP self
|
||||
function CLEANUP:_CleanUpScheduler()
|
||||
self:F( "CleanUp Scheduler" )
|
||||
self:F( { "CleanUp Scheduler" } )
|
||||
|
||||
local CleanUpCount = 0
|
||||
for CleanUpUnitName, UnitData in pairs( self.CleanUpList ) do
|
||||
CleanUpCount = CleanUpCount + 1
|
||||
|
||||
self:T( { CleanUpUnitName, UnitData } )
|
||||
local CleanUpUnit = Unit.getByName(UnitData.CleanUpUnitName)
|
||||
@ -312,5 +318,6 @@ function CLEANUP:_CleanUpScheduler()
|
||||
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||
end
|
||||
end
|
||||
self:T(CleanUpCount)
|
||||
end
|
||||
|
||||
|
||||
@ -24,13 +24,13 @@ DATABASE = {
|
||||
ClientsByID = {},
|
||||
}
|
||||
|
||||
DATABASECoalition =
|
||||
local _DATABASECoalition =
|
||||
{
|
||||
[1] = "Red",
|
||||
[2] = "Blue",
|
||||
}
|
||||
|
||||
DATABASECategory =
|
||||
local _DATABASECategory =
|
||||
{
|
||||
[Unit.Category.AIRPLANE] = "Plane",
|
||||
[Unit.Category.HELICOPTER] = "Helicopter",
|
||||
@ -111,15 +111,14 @@ function DATABASE:New()
|
||||
end --for coa_name, coa_data in pairs(mission.coalition) do
|
||||
|
||||
--self:AddEvent( world.event.S_EVENT_BIRTH, self.OnBirth )
|
||||
_EventDispatcher:OnDead( self.OnDeadOrCrash, self )
|
||||
_EventDispatcher:OnCrash( self.OnDeadOrCrash, self )
|
||||
_EventDispatcher:OnHit( self.OnHit, self )
|
||||
_EventDispatcher:OnDead( self._EventOnDeadOrCrash, self )
|
||||
_EventDispatcher:OnCrash( self._EventOnDeadOrCrash, self )
|
||||
_EventDispatcher:OnHit( self._EventOnHit, self )
|
||||
|
||||
self.SchedulerId = routines.scheduleFunction( DATABASE._FollowPlayers, { self }, 0, 5 )
|
||||
|
||||
self:ScoreMenu()
|
||||
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -220,8 +219,10 @@ end
|
||||
|
||||
|
||||
--- Track DCSRTE DEAD or CRASH events for the internal scoring.
|
||||
function DATABASE:OnDeadOrCrash( event )
|
||||
self:F( { event } )
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnDeadOrCrash( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local TargetUnit = nil
|
||||
local TargetGroup = nil
|
||||
@ -235,25 +236,21 @@ function DATABASE:OnDeadOrCrash( event )
|
||||
local TargetUnitCategory = nil
|
||||
local TargetUnitType = nil
|
||||
|
||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
||||
if Event.IniDCSUnit then
|
||||
|
||||
TargetUnit = event.initiator
|
||||
TargetGroup = Unit.getGroup( TargetUnit )
|
||||
TargetUnitDesc = TargetUnit:getDesc()
|
||||
|
||||
TargetUnitName = TargetUnit:getName()
|
||||
if TargetGroup and TargetGroup:isExist() then
|
||||
TargetGroupName = TargetGroup:getName()
|
||||
end
|
||||
TargetUnit = Event.IniDCSUnit
|
||||
TargetUnitName = Event.IniDCSUnitName
|
||||
TargetGroup = Event.IniDCSGroup
|
||||
TargetGroupName = Event.IniDCSGroupName
|
||||
TargetPlayerName = TargetUnit:getPlayerName()
|
||||
|
||||
TargetCoalition = TargetUnit:getCoalition()
|
||||
--TargetCategory = TargetUnit:getCategory()
|
||||
TargetCategory = TargetUnitDesc.category -- Workaround
|
||||
TargetCategory = TargetUnit:getDesc().category -- Workaround
|
||||
TargetType = TargetUnit:getTypeName()
|
||||
|
||||
TargetUnitCoalition = DATABASECoalition[TargetCoalition]
|
||||
TargetUnitCategory = DATABASECategory[TargetCategory]
|
||||
TargetUnitCoalition = _DATABASECoalition[TargetCoalition]
|
||||
TargetUnitCategory = _DATABASECategory[T1argetCategory]
|
||||
TargetUnitType = TargetType
|
||||
|
||||
self:T( { TargetUnitName, TargetGroupName, TargetPlayerName, TargetCoalition, TargetCategory, TargetType } )
|
||||
@ -268,8 +265,8 @@ function DATABASE:OnDeadOrCrash( event )
|
||||
local InitUnitType = PlayerData.UnitType
|
||||
local InitCoalition = PlayerData.UnitCoalition
|
||||
local InitCategory = PlayerData.UnitCategory
|
||||
local InitUnitCoalition = DATABASECoalition[InitCoalition]
|
||||
local InitUnitCategory = DATABASECategory[InitCategory]
|
||||
local InitUnitCoalition = _DATABASECoalition[InitCoalition]
|
||||
local InitUnitCategory = _DATABASECategory[InitCategory]
|
||||
|
||||
self:T( { InitUnitName, InitUnitType, InitUnitCoalition, InitCoalition, InitUnitCategory, InitCategory } )
|
||||
|
||||
@ -378,14 +375,14 @@ function DATABASE:_AddPlayerFromUnit( UnitData )
|
||||
if self.Players[PlayerName].UnitCoalition ~= UnitCoalition then
|
||||
self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + 50
|
||||
self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1
|
||||
MESSAGE:New( "Player '" .. PlayerName .. "' changed coalition from " .. DATABASECoalition[self.Players[PlayerName].UnitCoalition] .. " to " .. DATABASECoalition[UnitCoalition] ..
|
||||
MESSAGE:New( "Player '" .. PlayerName .. "' changed coalition from " .. _DATABASECoalition[self.Players[PlayerName].UnitCoalition] .. " to " .. _DATABASECoalition[UnitCoalition] ..
|
||||
"(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.",
|
||||
"",
|
||||
2,
|
||||
"/PENALTYCOALITION" .. PlayerName
|
||||
):ToAll()
|
||||
self:ScoreAdd( PlayerName, "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, DATABASECoalition[self.Players[PlayerName].UnitCoalition], DATABASECategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType,
|
||||
UnitName, DATABASECoalition[UnitCoalition], DATABASECategory[UnitCategory], UnitData:getTypeName() )
|
||||
self:ScoreAdd( PlayerName, "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, _DATABASECoalition[self.Players[PlayerName].UnitCoalition], _DATABASECategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType,
|
||||
UnitName, _DATABASECoalition[UnitCoalition], _DATABASECategory[UnitCategory], UnitData:getTypeName() )
|
||||
end
|
||||
end
|
||||
self.Players[PlayerName].UnitName = UnitName
|
||||
@ -466,11 +463,15 @@ end
|
||||
-- @section Events
|
||||
|
||||
|
||||
function DATABASE:OnHit( event )
|
||||
self:F( { event } )
|
||||
--- Handles the OnHit event for the scoring.
|
||||
-- @param #DATABASE self
|
||||
-- @param Event#EVENTDATA Event
|
||||
function DATABASE:_EventOnHit( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local InitUnit = nil
|
||||
local InitUnitName = ""
|
||||
local InitGroup = nil
|
||||
local InitGroupName = ""
|
||||
local InitPlayerName = "dummy"
|
||||
|
||||
@ -483,6 +484,7 @@ function DATABASE:OnHit( event )
|
||||
|
||||
local TargetUnit = nil
|
||||
local TargetUnitName = ""
|
||||
local TargetGroup = nil
|
||||
local TargetGroupName = ""
|
||||
local TargetPlayerName = ""
|
||||
|
||||
@ -493,57 +495,47 @@ function DATABASE:OnHit( event )
|
||||
local TargetUnitCategory = nil
|
||||
local TargetUnitType = nil
|
||||
|
||||
if event.initiator and event.initiator:getName() then
|
||||
if Event.IniDCSUnit then
|
||||
|
||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
||||
|
||||
InitUnit = event.initiator
|
||||
InitGroup = Unit.getGroup( InitUnit )
|
||||
InitUnitDesc = InitUnit:getDesc()
|
||||
|
||||
InitUnitName = InitUnit:getName()
|
||||
if InitGroup and InitGroup:isExist() then
|
||||
InitGroupName = InitGroup:getName()
|
||||
end
|
||||
InitUnit = Event.IniDCSUnit
|
||||
InitUnitName = Event.IniDCSUnitName
|
||||
InitGroup = Event.IniDCSGroup
|
||||
InitGroupName = Event.IniDCSGroupName
|
||||
InitPlayerName = InitUnit:getPlayerName()
|
||||
|
||||
InitCoalition = InitUnit:getCoalition()
|
||||
--TODO: Workaround Client DCS Bug
|
||||
--InitCategory = InitUnit:getCategory()
|
||||
InitCategory = InitUnitDesc.category -- Workaround
|
||||
InitCategory = InitUnit:getDesc().category
|
||||
InitType = InitUnit:getTypeName()
|
||||
|
||||
InitUnitCoalition = DATABASECoalition[InitCoalition]
|
||||
InitUnitCategory = DATABASECategory[InitCategory]
|
||||
InitUnitCoalition = _DATABASECoalition[InitCoalition]
|
||||
InitUnitCategory = _DATABASECategory[InitCategory]
|
||||
InitUnitType = InitType
|
||||
|
||||
self:T( { InitUnitName, InitGroupName, InitPlayerName, InitCoalition, InitCategory, InitType , InitUnitCoalition, InitUnitCategory, InitUnitType } )
|
||||
self:T( { InitUnitDesc } )
|
||||
end
|
||||
|
||||
|
||||
if event.target and Object.getCategory(event.target) == Object.Category.UNIT then
|
||||
if Event.TgtDCSUnit then
|
||||
|
||||
TargetUnit = event.target
|
||||
TargetGroup = Unit.getGroup( TargetUnit )
|
||||
TargetUnitDesc = TargetUnit:getDesc()
|
||||
|
||||
TargetUnitName = TargetUnit:getName()
|
||||
if TargetGroup and TargetGroup:isExist() then
|
||||
TargetGroupName = TargetGroup:getName()
|
||||
end
|
||||
TargetUnit = Event.TgtDCSUnit
|
||||
TargetUnitName = Event.TgtDCSUnitName
|
||||
TargetGroup = Event.TgtDCSGroup
|
||||
TargetGroupName = Event.TgtDCSGroupName
|
||||
TargetPlayerName = TargetUnit:getPlayerName()
|
||||
|
||||
TargetCoalition = TargetUnit:getCoalition()
|
||||
--TODO: Workaround Client DCS Bug
|
||||
--TargetCategory = TargetUnit:getCategory()
|
||||
TargetCategory = TargetUnitDesc.category -- Workaround
|
||||
TargetCategory = TargetUnit:getDesc().category
|
||||
TargetType = TargetUnit:getTypeName()
|
||||
|
||||
TargetUnitCoalition = DATABASECoalition[TargetCoalition]
|
||||
TargetUnitCategory = DATABASECategory[TargetCategory]
|
||||
TargetUnitCoalition = _DATABASECoalition[TargetCoalition]
|
||||
TargetUnitCategory = _DATABASECategory[TargetCategory]
|
||||
TargetUnitType = TargetType
|
||||
|
||||
self:T( { TargetUnitName, TargetGroupName, TargetPlayerName, TargetCoalition, TargetCategory, TargetType, TargetUnitCoalition, TargetUnitCategory, TargetUnitType } )
|
||||
self:T( { TargetUnitDesc } )
|
||||
end
|
||||
|
||||
if InitPlayerName ~= nil then -- It is a player that is hitting something
|
||||
@ -599,7 +591,6 @@ function DATABASE:OnHit( event )
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function DATABASE:ReportScoreAll()
|
||||
@ -616,8 +607,8 @@ env.info( "Hello World " )
|
||||
self:T( "Score Player: " .. PlayerName )
|
||||
|
||||
-- Some variables
|
||||
local InitUnitCoalition = DATABASECoalition[PlayerData.UnitCoalition]
|
||||
local InitUnitCategory = DATABASECategory[PlayerData.UnitCategory]
|
||||
local InitUnitCoalition = _DATABASECoalition[PlayerData.UnitCoalition]
|
||||
local InitUnitCategory = _DATABASECategory[PlayerData.UnitCategory]
|
||||
local InitUnitType = PlayerData.UnitType
|
||||
local InitUnitName = PlayerData.UnitName
|
||||
|
||||
@ -628,7 +619,7 @@ env.info( "Hello World " )
|
||||
|
||||
local ScoreMessageHits = ""
|
||||
|
||||
for CategoryID, CategoryName in pairs( DATABASECategory ) do
|
||||
for CategoryID, CategoryName in pairs( _DATABASECategory ) do
|
||||
self:T( CategoryName )
|
||||
if PlayerData.Hit[CategoryID] then
|
||||
local Score = 0
|
||||
@ -656,7 +647,7 @@ env.info( "Hello World " )
|
||||
end
|
||||
|
||||
local ScoreMessageKills = ""
|
||||
for CategoryID, CategoryName in pairs( DATABASECategory ) do
|
||||
for CategoryID, CategoryName in pairs( _DATABASECategory ) do
|
||||
self:T( "Kill scores exist for player " .. PlayerName )
|
||||
if PlayerData.Kill[CategoryID] then
|
||||
local Score = 0
|
||||
@ -729,8 +720,8 @@ env.info( "Hello World " )
|
||||
self:T( "Score Player: " .. PlayerName )
|
||||
|
||||
-- Some variables
|
||||
local InitUnitCoalition = DATABASECoalition[PlayerData.UnitCoalition]
|
||||
local InitUnitCategory = DATABASECategory[PlayerData.UnitCategory]
|
||||
local InitUnitCoalition = _DATABASECoalition[PlayerData.UnitCoalition]
|
||||
local InitUnitCategory = _DATABASECategory[PlayerData.UnitCategory]
|
||||
local InitUnitType = PlayerData.UnitType
|
||||
local InitUnitName = PlayerData.UnitName
|
||||
|
||||
@ -741,7 +732,7 @@ env.info( "Hello World " )
|
||||
|
||||
local ScoreMessageHits = ""
|
||||
|
||||
for CategoryID, CategoryName in pairs( DATABASECategory ) do
|
||||
for CategoryID, CategoryName in pairs( _DATABASECategory ) do
|
||||
self:T( CategoryName )
|
||||
if PlayerData.Hit[CategoryID] then
|
||||
local Score = 0
|
||||
@ -769,7 +760,7 @@ env.info( "Hello World " )
|
||||
end
|
||||
|
||||
local ScoreMessageKills = ""
|
||||
for CategoryID, CategoryName in pairs( DATABASECategory ) do
|
||||
for CategoryID, CategoryName in pairs( _DATABASECategory ) do
|
||||
self:T( "Kill scores exist for player " .. PlayerName )
|
||||
if PlayerData.Kill[CategoryID] then
|
||||
local Score = 0
|
||||
@ -879,11 +870,11 @@ function DATABASE:ScoreAdd( PlayerName, ScoreType, ScoreTimes, ScoreAmount, Play
|
||||
if PlayerUnit then
|
||||
if not PlayerUnitCategory then
|
||||
--PlayerUnitCategory = DATABASECategory[PlayerUnit:getCategory()]
|
||||
PlayerUnitCategory = DATABASECategory[PlayerUnit:getDesc().category]
|
||||
PlayerUnitCategory = _DATABASECategory[PlayerUnit:getDesc().category]
|
||||
end
|
||||
|
||||
if not PlayerUnitCoalition then
|
||||
PlayerUnitCoalition = DATABASECoalition[PlayerUnit:getCoalition()]
|
||||
PlayerUnitCoalition = _DATABASECoalition[PlayerUnit:getCoalition()]
|
||||
end
|
||||
|
||||
if not PlayerUnitType then
|
||||
@ -950,3 +941,4 @@ end
|
||||
_Database = DATABASE:New() -- Database#DATABASE
|
||||
_Database:ScoreOpen()
|
||||
|
||||
|
||||
|
||||
137
Moose/Event.lua
137
Moose/Event.lua
@ -13,7 +13,7 @@ EVENT = {
|
||||
ClassID = 0,
|
||||
}
|
||||
|
||||
local EVENTCODES = {
|
||||
local _EVENTCODES = {
|
||||
"S_EVENT_SHOT",
|
||||
"S_EVENT_HIT",
|
||||
"S_EVENT_TAKEOFF",
|
||||
@ -69,6 +69,13 @@ function EVENT:New()
|
||||
return self
|
||||
end
|
||||
|
||||
function EVENT:EventText( EventID )
|
||||
|
||||
local EventText = _EVENTCODES[EventID]
|
||||
|
||||
return EventText
|
||||
end
|
||||
|
||||
|
||||
--- Initializes the Events structure for the event
|
||||
-- @param #EVENT self
|
||||
@ -76,16 +83,13 @@ end
|
||||
-- @param #string EventClass
|
||||
-- @return #EVENT.Events
|
||||
function EVENT:Init( EventID, EventClass )
|
||||
self:F( { EventID, EventClass } )
|
||||
self:F3( { _EVENTCODES[EventID], EventClass } )
|
||||
if not self.Events[EventID] then
|
||||
self.Events[EventID] = {}
|
||||
end
|
||||
if not self.Events[EventID][EventClass] then
|
||||
self.Events[EventID][EventClass] = {}
|
||||
end
|
||||
if not self.Events[EventID][EventClass].IniUnit then
|
||||
self.Events[EventID][EventClass].IniUnit = {}
|
||||
end
|
||||
return self.Events[EventID][EventClass]
|
||||
end
|
||||
|
||||
@ -98,7 +102,7 @@ end
|
||||
-- @param #function OnEventFunction
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, OnEventFunction )
|
||||
self:F( EventTemplate )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
for EventUnitID, EventUnit in pairs( EventTemplate.units ) do
|
||||
OnEventFunction( self, EventUnit.name, EventFunction, EventSelf )
|
||||
@ -113,7 +117,7 @@ end
|
||||
-- @param EventID
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventGeneric( EventFunction, EventSelf, EventID )
|
||||
self:F( { EventID } )
|
||||
self:F2( { EventID } )
|
||||
|
||||
local Event = self:Init( EventID, EventSelf:GetClassNameAndID() )
|
||||
Event.EventFunction = EventFunction
|
||||
@ -130,9 +134,12 @@ end
|
||||
-- @param EventID
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, EventID )
|
||||
self:F( EventDCSUnitName )
|
||||
self:F2( EventDCSUnitName )
|
||||
|
||||
local Event = self:Init( EventID, EventSelf:GetClassNameAndID() )
|
||||
if not Event.IniUnit then
|
||||
Event.IniUnit = {}
|
||||
end
|
||||
Event.IniUnit[EventDCSUnitName] = {}
|
||||
Event.IniUnit[EventDCSUnitName].EventFunction = EventFunction
|
||||
Event.IniUnit[EventDCSUnitName].EventSelf = EventSelf
|
||||
@ -147,9 +154,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirthForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( { EventTemplate } )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnBirthForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnBirthForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_BIRTH event, and registers the unit born.
|
||||
@ -160,7 +169,9 @@ end
|
||||
function EVENT:OnBirth( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
return self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_BIRTH event.
|
||||
@ -172,7 +183,9 @@ end
|
||||
function EVENT:OnBirthForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnCrash event handler for a group
|
||||
@ -182,9 +195,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrashForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_CRASH event.
|
||||
@ -195,7 +210,9 @@ end
|
||||
function EVENT:OnCrash( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
return self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_CRASH event.
|
||||
@ -207,7 +224,9 @@ end
|
||||
function EVENT:OnCrashForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
@ -217,9 +236,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDeadForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_DEAD event.
|
||||
@ -230,7 +251,9 @@ end
|
||||
function EVENT:OnDead( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
return self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_DEAD )
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_DEAD )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
@ -243,7 +266,23 @@ end
|
||||
function EVENT:OnDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_DEAD )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_DEAD )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_PILOT_DEAD event.
|
||||
-- @param #EVENT self
|
||||
-- @param #string EventDCSUnitName
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param Base#BASE EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnPilotDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_PILOT_DEAD )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
@ -253,9 +292,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnLandForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnLandForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnLandForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_LAND event.
|
||||
@ -267,7 +308,9 @@ end
|
||||
function EVENT:OnLandForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_LAND )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_LAND )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
@ -277,9 +320,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnTakeOffForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnTakeOffForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnTakeOffForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_TAKEOFF event.
|
||||
@ -291,7 +336,9 @@ end
|
||||
function EVENT:OnTakeOffForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_TAKEOFF )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_TAKEOFF )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
@ -301,9 +348,11 @@ end
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEngineShutDownForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
return self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnEngineShutDownForUnit )
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnEngineShutDownForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_ENGINE_SHUTDOWN event.
|
||||
@ -315,7 +364,9 @@ end
|
||||
function EVENT:OnEngineShutDownForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_SHUTDOWN )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_SHUTDOWN )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_ENGINE_STARTUP event.
|
||||
@ -327,7 +378,9 @@ end
|
||||
function EVENT:OnEngineStartUpForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_STARTUP )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_STARTUP )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_SHOT event.
|
||||
@ -338,7 +391,9 @@ end
|
||||
function EVENT:OnShot( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
return self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_SHOT )
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_SHOT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_SHOT event for a unit.
|
||||
@ -350,7 +405,9 @@ end
|
||||
function EVENT:OnShotForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_SHOT )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_SHOT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_HIT event.
|
||||
@ -361,7 +418,9 @@ end
|
||||
function EVENT:OnHit( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
return self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_HIT event.
|
||||
@ -373,13 +432,15 @@ end
|
||||
function EVENT:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
return self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
function EVENT:onEvent( Event )
|
||||
self:F( { EVENTCODES[Event.id], Event } )
|
||||
self:F( { _EVENTCODES[Event.id], Event } )
|
||||
|
||||
if self and self.Events and self.Events[Event.id] then
|
||||
if Event.initiator and Event.initiator:getCategory() == Object.Category.UNIT then
|
||||
@ -405,15 +466,15 @@ function EVENT:onEvent( Event )
|
||||
if Event.weapon then
|
||||
Event.Weapon = Event.weapon
|
||||
Event.WeaponName = Event.Weapon:getTypeName()
|
||||
Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
|
||||
--Event.WeaponTgtDCSUnit = Event.Weapon:getTarget()
|
||||
end
|
||||
for ClassName, EventData in pairs( self.Events[Event.id] ) do
|
||||
if Event.IniDCSUnitName and EventData.IniUnit and EventData.IniUnit[Event.IniDCSUnitName] then
|
||||
self:T( { "Calling event function for class ", ClassName, " unit ", Event.IniDCSUnitName } )
|
||||
self:T2( { "Calling event function for class ", ClassName, " unit ", Event.IniDCSUnitName } )
|
||||
EventData.IniUnit[Event.IniDCSUnitName].EventFunction( EventData.IniUnit[Event.IniDCSUnitName].EventSelf, Event )
|
||||
else
|
||||
if Event.IniDCSUnit and not EventData.IniUnit then
|
||||
self:T( { "Calling event function for class ", ClassName } )
|
||||
self:T2( { "Calling event function for class ", ClassName } )
|
||||
EventData.EventFunction( EventData.EventSelf, Event )
|
||||
end
|
||||
end
|
||||
|
||||
@ -62,7 +62,7 @@ function SEAD:EventShot( Event )
|
||||
self:T( "Missile Launched = " .. SEADWeaponName )
|
||||
if SEADWeaponName == "KH-58" or SEADWeaponName == "KH-25MPU" or SEADWeaponName == "AGM-88" or SEADWeaponName == "KH-31A" or SEADWeaponName == "KH-31P" then -- Check if the missile is a SEAD
|
||||
local _evade = math.random (1,100) -- random number for chance of evading action
|
||||
local _targetMim = Event.WeaponTgtDCSUnit -- Identify target
|
||||
local _targetMim = Event.Weapon:getTarget() -- Identify target
|
||||
local _targetMimname = Unit.getName(_targetMim)
|
||||
local _targetMimgroup = Unit.getGroup(Weapon.getTarget(SEADWeapon))
|
||||
local _targetMimgroupName = _targetMimgroup:getName()
|
||||
|
||||
@ -471,7 +471,7 @@ function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
self.SpawnGroups[self.SpawnIndex].Spawned = true
|
||||
return self.SpawnGroups[self.SpawnIndex].Group
|
||||
else
|
||||
self:E( { self.SpawnTemplatePrefix, "No more Groups to Spawn:", SpawnIndex, self.SpawnMaxGroups } )
|
||||
--self:E( { self.SpawnTemplatePrefix, "No more Groups to Spawn:", SpawnIndex, self.SpawnMaxGroups } )
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
10
Test Missions/Moose_Test_CLEANUP/Moose_Test_CLEANUP.lua
Normal file
10
Test Missions/Moose_Test_CLEANUP/Moose_Test_CLEANUP.lua
Normal file
@ -0,0 +1,10 @@
|
||||
Include.File( 'Cleanup' )
|
||||
Include.File( 'Spawn' )
|
||||
Include.File( 'Event')
|
||||
|
||||
Clean = CLEANUP:New( 'CLEAN_BATUMI', 180 )
|
||||
|
||||
SpawnRU = SPAWN:New( 'RU Attack Heli Batumi'):Limit( 2, 20 ):SpawnScheduled( 2, 0.2 )
|
||||
|
||||
SpawnUS = SPAWN:New( 'US Attack Heli Batumi'):Limit( 2, 20 ):SpawnScheduled( 2, 0.2 )
|
||||
|
||||
BIN
Test Missions/Moose_Test_CLEANUP/Moose_Test_CLEANUP.miz
Normal file
BIN
Test Missions/Moose_Test_CLEANUP/Moose_Test_CLEANUP.miz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user