mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Merge branch 'Events-Dispatcher2'
This commit is contained in:
commit
1acf66f74d
35
Dcs/DCSworld.lua
Normal file
35
Dcs/DCSworld.lua
Normal file
@ -0,0 +1,35 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- @module DCSWorld
|
||||
|
||||
--- @type world
|
||||
-- @field #world.event event
|
||||
|
||||
|
||||
--- @type world.event
|
||||
-- @field S_EVENT_INVALID
|
||||
-- @field S_EVENT_SHOT
|
||||
-- @field S_EVENT_HIT
|
||||
-- @field S_EVENT_TAKEOFF
|
||||
-- @field S_EVENT_LAND
|
||||
-- @field S_EVENT_CRASH
|
||||
-- @field S_EVENT_EJECTION
|
||||
-- @field S_EVENT_REFUELING
|
||||
-- @field S_EVENT_DEAD
|
||||
-- @field S_EVENT_PILOT_DEAD
|
||||
-- @field S_EVENT_BASE_CAPTURED
|
||||
-- @field S_EVENT_MISSION_START
|
||||
-- @field S_EVENT_MISSION_END
|
||||
-- @field S_EVENT_TOOK_CONTROL
|
||||
-- @field S_EVENT_REFUELING_STOP
|
||||
-- @field S_EVENT_BIRTH
|
||||
-- @field S_EVENT_HUMAN_FAILURE
|
||||
-- @field S_EVENT_ENGINE_STARTUP
|
||||
-- @field S_EVENT_ENGINE_SHUTDOWN
|
||||
-- @field S_EVENT_PLAYER_ENTER_UNIT
|
||||
-- @field S_EVENT_PLAYER_LEAVE_UNIT
|
||||
-- @field S_EVENT_PLAYER_COMMENT
|
||||
-- @field S_EVENT_SHOOTING_START
|
||||
-- @field S_EVENT_SHOOTING_END
|
||||
-- @field S_EVENT_MAX
|
||||
|
||||
world = {} --#world
|
||||
@ -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
@ -46,6 +46,8 @@ FORMATION = {
|
||||
Cone = "Cone"
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- The base constructor. This is the top top class of all classed defined within the MOOSE.
|
||||
-- Any new class needs to be derived from this class for proper inheritance.
|
||||
-- @param #BASE self
|
||||
@ -140,6 +142,18 @@ function BASE:AddEvent( Event, EventFunction )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Returns the event dispatcher
|
||||
-- @param #BASE self
|
||||
-- @return Event#EVENT
|
||||
function BASE:Event()
|
||||
|
||||
return _EVENTDISPATCHER
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Enable the event listeners for the class.
|
||||
-- @param #BASE self
|
||||
-- @return #BASE
|
||||
@ -253,8 +267,8 @@ end
|
||||
-- @param #BASE self
|
||||
-- @param DCSTypes#Event event
|
||||
function BASE:onEvent(event)
|
||||
--self:F( { BaseEventCodes[event.id], event } )
|
||||
|
||||
--env.info( 'onEvent Table self = ' .. tostring(self) )
|
||||
if self then
|
||||
for EventID, EventObject in pairs( self.Events ) do
|
||||
if EventObject.EventEnabled then
|
||||
@ -269,8 +283,8 @@ function BASE:onEvent(event)
|
||||
if event.target and event.target:isExist() then
|
||||
event.TgtUnitName = event.target:getName()
|
||||
end
|
||||
self:T( { BaseEventCodes[event.id], event } )
|
||||
EventObject.EventFunction( self, event )
|
||||
--self:T( { BaseEventCodes[event.id], event } )
|
||||
--EventObject.EventFunction( self, event )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -10,6 +10,7 @@ Include.File( "Task" )
|
||||
|
||||
--- The CLEANUP class.
|
||||
-- @type CLEANUP
|
||||
-- @extends Base#BASE
|
||||
CLEANUP = {
|
||||
ClassName = "CLEANUP",
|
||||
ZoneNames = {},
|
||||
@ -40,15 +41,8 @@ function CLEANUP:New( ZoneNames, TimeInterval ) local self = BASE:Inherit( self,
|
||||
self.TimeInterval = TimeInterval
|
||||
end
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_ENGINE_SHUTDOWN, self._EventAddForCleanUp )
|
||||
self:AddEvent( world.event.S_EVENT_ENGINE_STARTUP, self._EventAddForCleanUp )
|
||||
self:AddEvent( world.event.S_EVENT_HIT, self._EventAddForCleanUp ) -- , self._EventHitCleanUp )
|
||||
self:AddEvent( world.event.S_EVENT_CRASH, self._EventCrash ) -- , self._EventHitCleanUp )
|
||||
--self:AddEvent( world.event.S_EVENT_DEAD, self._EventCrash )
|
||||
self:AddEvent( world.event.S_EVENT_SHOT, self._EventShot )
|
||||
_EVENTDISPATCHER:OnBirth( self._OnEventBirth, self )
|
||||
|
||||
self:EnableEvents()
|
||||
|
||||
self.CleanUpScheduler = routines.scheduleFunction( self._CleanUpScheduler, { self }, timer.getTime() + 1, TimeInterval )
|
||||
|
||||
return self
|
||||
@ -84,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()
|
||||
@ -111,13 +104,43 @@ function CLEANUP:_DestroyMissile( MissileObject )
|
||||
end
|
||||
end
|
||||
|
||||
function CLEANUP:_OnEventBirth( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
self.CleanUpList[Event.IniDCSUnitName] = {}
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnit = Event.IniDCSUnit
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroup = Event.IniDCSGroup
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpGroupName = Event.IniDCSGroupName
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnitName = Event.IniDCSUnitName
|
||||
|
||||
_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 )
|
||||
|
||||
--self:AddEvent( world.event.S_EVENT_ENGINE_SHUTDOWN, self._EventAddForCleanUp )
|
||||
--self:AddEvent( world.event.S_EVENT_ENGINE_STARTUP, self._EventAddForCleanUp )
|
||||
-- self:AddEvent( world.event.S_EVENT_HIT, self._EventAddForCleanUp ) -- , self._EventHitCleanUp )
|
||||
-- self:AddEvent( world.event.S_EVENT_CRASH, self._EventCrash ) -- , self._EventHitCleanUp )
|
||||
-- --self:AddEvent( world.event.S_EVENT_DEAD, self._EventCrash )
|
||||
-- self:AddEvent( world.event.S_EVENT_SHOT, self._EventShot )
|
||||
--
|
||||
-- self:EnableEvents()
|
||||
|
||||
|
||||
end
|
||||
|
||||
--- Detects if a crash event occurs.
|
||||
-- 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
|
||||
@ -126,44 +149,28 @@ function CLEANUP:_EventCrash( event )
|
||||
-- self:T("after deactivateGroup")
|
||||
-- event.initiator:destroy()
|
||||
|
||||
local CleanUpUnit = event.initiator -- the Unit
|
||||
local CleanUpUnitName = CleanUpUnit:getName() -- return the name of the Unit
|
||||
local CleanUpGroup = Unit.getGroup(CleanUpUnit)-- Identify the Group
|
||||
local CleanUpGroupName = ""
|
||||
if CleanUpGroup and CleanUpGroup:isExist() then
|
||||
CleanUpGroupName = CleanUpGroup:getName() -- return the name of the Group
|
||||
end
|
||||
|
||||
self.CleanUpList[CleanUpUnitName] = {}
|
||||
self.CleanUpList[CleanUpUnitName].CleanUpUnit = CleanUpUnit
|
||||
self.CleanUpList[CleanUpUnitName].CleanUpGroup = CleanUpGroup
|
||||
self.CleanUpList[CleanUpUnitName].CleanUpGroupName = CleanUpGroupName
|
||||
self.CleanUpList[CleanUpUnitName].CleanUpUnitName = CleanUpUnitName
|
||||
self.CleanUpList[Event.IniDCSUnitName] = {}
|
||||
self.CleanUpList[Event.IniDCSUnitName].CleanUpUnit = Event.IniDCSUnit
|
||||
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.
|
||||
-- If this occurs within one of the zones, then the weapon used must be destroyed.
|
||||
-- @param #CLEANUP self
|
||||
-- @param DCSTypes#Event event
|
||||
function CLEANUP:_EventShot( event )
|
||||
self:F( { event } )
|
||||
function CLEANUP:_EventShot( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local _grp = Unit.getGroup(event.initiator)-- Identify the group that fired
|
||||
local _groupname = _grp:getName() -- return the name of the group
|
||||
local _unittable = {event.initiator:getName()} -- return the name of the units in the group
|
||||
local _SEADmissile = event.weapon -- Identify the weapon fired
|
||||
--local _SEADmissileName = _SEADmissile:getTypeName() -- return weapon type
|
||||
--trigger.action.outText( string.format("Alerte, depart missile " ..string.format(_SEADmissileName)), 20) --debug message
|
||||
-- Start of the 2nd loop
|
||||
--self:T( "Missile Launched = " .. _SEADmissileName )
|
||||
|
||||
-- Test if the missile was fired within one of the CLEANUP.ZoneNames.
|
||||
local CurrentLandingZoneID = 0
|
||||
CurrentLandingZoneID = routines.IsUnitInZones( event.initiator, self.ZoneNames )
|
||||
CurrentLandingZoneID = routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames )
|
||||
if ( CurrentLandingZoneID ) then
|
||||
-- Okay, the missile was fired within the CLEANUP.ZoneNames, destroy the fired weapon.
|
||||
--_SEADmissile:destroy()
|
||||
routines.scheduleFunction( CLEANUP._DestroyMissile, {self, _SEADmissile}, timer.getTime() + 0.1)
|
||||
routines.scheduleFunction( CLEANUP._DestroyMissile, { self, Event.Weapon }, timer.getTime() + 0.1)
|
||||
end
|
||||
end
|
||||
|
||||
@ -171,38 +178,28 @@ end
|
||||
--- Detects if the Unit has an S_EVENT_HIT within the given ZoneNames. If this is the case, destroy the unit.
|
||||
-- @param #CLEANUP self
|
||||
-- @param DCSTypes#Event event
|
||||
function CLEANUP:_EventHitCleanUp( event )
|
||||
self:F( { event } )
|
||||
function CLEANUP:_EventHitCleanUp( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local CleanUpUnit = event.initiator -- the Unit
|
||||
if CleanUpUnit and CleanUpUnit:isExist() and Object.getCategory(CleanUpUnit) == Object.Category.UNIT then
|
||||
local CleanUpUnitName = event.initiator:getName() -- return the name of the Unit
|
||||
|
||||
if routines.IsUnitInZones( CleanUpUnit, self.ZoneNames ) ~= nil then
|
||||
self:T( "Life: " .. CleanUpUnitName .. ' = ' .. CleanUpUnit:getLife() .. "/" .. CleanUpUnit:getLife0() )
|
||||
if CleanUpUnit:getLife() < CleanUpUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. CleanUpUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, {self, CleanUpUnit}, timer.getTime() + 0.1)
|
||||
if Event.IniDCSUnit then
|
||||
if routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames ) ~= nil then
|
||||
self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniDCSUnit:getLife(), "/", Event.IniDCSUnit:getLife0() } )
|
||||
if Event.IniDCSUnit:getLife() < Event.IniDCSUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.IniDCSUnit }, timer.getTime() + 0.1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local CleanUpTgtUnit = event.target -- the target Unit
|
||||
if CleanUpTgtUnit and CleanUpTgtUnit:isExist() and Object.getCategory(CleanUpTgtUnit) == Object.Category.UNIT then
|
||||
local CleanUpTgtUnitName = event.target:getName() -- return the name of the target Unit
|
||||
local CleanUpTgtGroup = Unit.getGroup(event.target)-- Identify the target Group
|
||||
local CleanUpTgtGroupName = CleanUpTgtGroup:getName() -- return the name of the target Group
|
||||
|
||||
|
||||
if routines.IsUnitInZones( CleanUpTgtUnit, self.ZoneNames ) ~= nil then
|
||||
self:T( "Life: " .. CleanUpTgtUnitName .. ' = ' .. CleanUpTgtUnit:getLife() .. "/" .. CleanUpTgtUnit:getLife0() )
|
||||
if CleanUpTgtUnit:getLife() < CleanUpTgtUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. CleanUpTgtUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, {self, CleanUpTgtUnit}, timer.getTime() + 0.1)
|
||||
if Event.TgtDCSUnit then
|
||||
if routines.IsUnitInZones( Event.TgtDCSUnit, self.ZoneNames ) ~= nil then
|
||||
self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtDCSUnit:getLife(), "/", Event.TgtDCSUnit:getLife0() } )
|
||||
if Event.TgtDCSUnit:getLife() < Event.TgtDCSUnit:getLife0() then
|
||||
self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName )
|
||||
routines.scheduleFunction( CLEANUP._DestroyUnit, { self, Event.TgtDCSUnit }, timer.getTime() + 0.1 )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Add the @{DCSUnit#Unit} to the CleanUpList for CleanUp.
|
||||
@ -224,24 +221,20 @@ end
|
||||
--- Detects if the Unit has an S_EVENT_ENGINE_SHUTDOWN or an S_EVENT_HIT within the given ZoneNames. If this is the case, add the Group to the CLEANUP List.
|
||||
-- @param #CLEANUP self
|
||||
-- @param DCSTypes#Event event
|
||||
function CLEANUP:_EventAddForCleanUp( event )
|
||||
function CLEANUP:_EventAddForCleanUp( Event )
|
||||
|
||||
local CleanUpUnit = event.initiator -- the Unit
|
||||
if CleanUpUnit and Object.getCategory(CleanUpUnit) == Object.Category.UNIT then
|
||||
local CleanUpUnitName = CleanUpUnit:getName() -- return the name of the Unit
|
||||
if self.CleanUpList[CleanUpUnitName] == nil then
|
||||
if routines.IsUnitInZones( CleanUpUnit, self.ZoneNames ) ~= nil then
|
||||
self:_AddForCleanUp( CleanUpUnit, CleanUpUnitName )
|
||||
if Event.IniDCSUnit then
|
||||
if self.CleanUpList[Event.IniDCSUnitName] == nil then
|
||||
if routines.IsUnitInZones( Event.IniDCSUnit, self.ZoneNames ) ~= nil then
|
||||
self:_AddForCleanUp( Event.IniDCSUnit, Event.IniDCSUnitName )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local CleanUpTgtUnit = event.target -- the target Unit
|
||||
if CleanUpTgtUnit and Object.getCategory(CleanUpTgtUnit) == Object.Category.UNIT then
|
||||
local CleanUpTgtUnitName = CleanUpTgtUnit:getName() -- return the name of the target Unit
|
||||
if self.CleanUpList[CleanUpTgtUnitName] == nil then
|
||||
if routines.IsUnitInZones( CleanUpTgtUnit, self.ZoneNames ) ~= nil then
|
||||
self:_AddForCleanUp( CleanUpTgtUnit, CleanUpTgtUnitName )
|
||||
if Event.TgtDCSUnit then
|
||||
if self.CleanUpList[Event.TgtDCSUnitName] == nil then
|
||||
if routines.IsUnitInZones( Event.TgtDCSUnit, self.ZoneNames ) ~= nil then
|
||||
self:_AddForCleanUp( Event.TgtDCSUnit, Event.TgtDCSUnitName )
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -259,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)
|
||||
@ -323,5 +318,6 @@ function CLEANUP:_CleanUpScheduler()
|
||||
self.CleanUpList[CleanUpUnitName] = nil -- Not anymore in the DCSRTE
|
||||
end
|
||||
end
|
||||
self:T(CleanUpCount)
|
||||
end
|
||||
|
||||
|
||||
1488
Moose/Database.lua
1488
Moose/Database.lua
File diff suppressed because it is too large
Load Diff
@ -16,10 +16,11 @@ DESTROYBASETASK = {
|
||||
}
|
||||
|
||||
--- Creates a new DESTROYBASETASK.
|
||||
-- @param string DestroyGroupType Text describing the group to be destroyed. f.e. "Radar Installations", "Ships", "Vehicles", "Command Centers".
|
||||
-- @param string DestroyUnitType Text describing the unit types to be destroyed. f.e. "SA-6", "Row Boats", "Tanks", "Tents".
|
||||
-- @param table{string,...} DestroyGroupPrefixes Table of Prefixes of the Groups to be destroyed before task is completed.
|
||||
-- @param ?number DestroyPercentage defines the %-tage that needs to be destroyed to achieve mission success. eg. If in the Group there are 10 units, then a value of 75 would require 8 units to be destroyed from the Group to complete the @{TASK}.
|
||||
-- @param #DESTROYBASETASK self
|
||||
-- @param #string DestroyGroupType Text describing the group to be destroyed. f.e. "Radar Installations", "Ships", "Vehicles", "Command Centers".
|
||||
-- @param #string DestroyUnitType Text describing the unit types to be destroyed. f.e. "SA-6", "Row Boats", "Tanks", "Tents".
|
||||
-- @param #list<#string> DestroyGroupPrefixes Table of Prefixes of the Groups to be destroyed before task is completed.
|
||||
-- @param #number DestroyPercentage defines the %-tage that needs to be destroyed to achieve mission success. eg. If in the Group there are 10 units, then a value of 75 would require 8 units to be destroyed from the Group to complete the @{TASK}.
|
||||
-- @return DESTROYBASETASK
|
||||
function DESTROYBASETASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupPrefixes, DestroyPercentage )
|
||||
local self = BASE:Inherit( self, TASK:New() )
|
||||
@ -30,34 +31,31 @@ function DESTROYBASETASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupPre
|
||||
self.DestroyGroupPrefixes = DestroyGroupPrefixes
|
||||
self.DestroyGroupType = DestroyGroupType
|
||||
self.DestroyUnitType = DestroyUnitType
|
||||
if DestroyPercentage then
|
||||
self.DestroyPercentage = DestroyPercentage
|
||||
end
|
||||
self.TaskBriefing = "Task: Destroy " .. DestroyGroupType .. "."
|
||||
self.Stages = { STAGEBRIEF:New(), STAGESTART:New(), STAGEGROUPSDESTROYED:New(), STAGEDONE:New() }
|
||||
self.SetStage( self, 1 )
|
||||
|
||||
--self.AddEvent( self, world.event.S_EVENT_DEAD, self.EventDead )
|
||||
|
||||
--env.info( 'New Table self = ' .. tostring(self) )
|
||||
--env.info( 'New Table self = ' .. tostring(self) )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Handle the S_EVENT_DEAD events to validate the destruction of units for the task monitoring.
|
||||
-- @param event Event structure of DCS world.
|
||||
function DESTROYBASETASK:EventDead( event )
|
||||
self:F( { 'EventDead', event } )
|
||||
-- @param #DESTROYBASETASK self
|
||||
-- @param Event#EVENTDATA Event structure of MOOSE.
|
||||
function DESTROYBASETASK:EventDead( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
||||
local DestroyUnit = event.initiator
|
||||
local DestroyUnitName = DestroyUnit:getName()
|
||||
local DestroyGroup = Unit.getGroup( DestroyUnit )
|
||||
local DestroyGroupName = ""
|
||||
if DestroyGroup and DestroyGroup:isExist() then
|
||||
local DestroyGroupName = DestroyGroup:getName()
|
||||
end
|
||||
if Event.IniDCSUnit then
|
||||
local DestroyUnit = Event.IniDCSUnit
|
||||
local DestroyUnitName = Event.IniDCSUnitName
|
||||
local DestroyGroup = Event.IniDCSGroup
|
||||
local DestroyGroupName = Event.IniDCSGroupName
|
||||
|
||||
--TODO: I need to fix here if 2 groups in the mission have a similar name with GroupPrefix equal, then i should differentiate for which group the goal was reached!
|
||||
--I may need to test if for the goalverb that group goal was reached or something. Need to think about it a bit more ...
|
||||
local UnitsDestroyed = 0
|
||||
self:T( DestroyGroupName )
|
||||
self:T( DestroyUnitName )
|
||||
for DestroyGroupPrefixID, DestroyGroupPrefix in pairs( self.DestroyGroupPrefixes ) do
|
||||
self:T( DestroyGroupPrefix )
|
||||
if string.find( DestroyGroupName, DestroyGroupPrefix, 1, true ) then
|
||||
@ -70,6 +68,7 @@ function DESTROYBASETASK:EventDead( event )
|
||||
self:T( { UnitsDestroyed } )
|
||||
self:IncreaseGoalCount( UnitsDestroyed, self.GoalVerb )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Validate task completeness of DESTROYBASETASK.
|
||||
|
||||
@ -11,10 +11,11 @@ DESTROYGROUPSTASK = {
|
||||
}
|
||||
|
||||
--- Creates a new DESTROYGROUPSTASK.
|
||||
-- @param string DestroyGroupType String describing the group to be destroyed.
|
||||
-- @param string DestroyUnitType String describing the unit to be destroyed.
|
||||
-- @param table{string,...} DestroyGroupNames Table of string containing the name of the groups to be destroyed before task is completed.
|
||||
-- @param ?number DestroyPercentage defines the %-tage that needs to be destroyed to achieve mission success. eg. If in the Group there are 10 units, then a value of 75 would require 8 units to be destroyed from the Group to complete the @{TASK}.
|
||||
-- @param #DESTROYGROUPSTASK self
|
||||
-- @param #string DestroyGroupType String describing the group to be destroyed.
|
||||
-- @param #string DestroyUnitType String describing the unit to be destroyed.
|
||||
-- @param #list<#string> DestroyGroupNames Table of string containing the name of the groups to be destroyed before task is completed.
|
||||
-- @param #number DestroyPercentage defines the %-tage that needs to be destroyed to achieve mission success. eg. If in the Group there are 10 units, then a value of 75 would require 8 units to be destroyed from the Group to complete the @{TASK}.
|
||||
---@return DESTROYGROUPSTASK
|
||||
function DESTROYGROUPSTASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupNames, DestroyPercentage )
|
||||
local self = BASE:Inherit( self, DESTROYBASETASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupNames, DestroyPercentage ) )
|
||||
@ -23,34 +24,34 @@ function DESTROYGROUPSTASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupN
|
||||
self.Name = 'Destroy Groups'
|
||||
self.GoalVerb = "Destroy " .. DestroyGroupType
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self.EventDead )
|
||||
self:AddEvent( world.event.S_EVENT_CRASH, self.EventDead )
|
||||
--Child.AddEvent( Child, world.event.S_EVENT_PILOT_DEAD, Child.EventDead )
|
||||
_EVENTDISPATCHER:OnDead( self.EventDead , self )
|
||||
_EVENTDISPATCHER:OnCrash( self.EventDead , self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Report Goal Progress.
|
||||
-- @param Group DestroyGroup Group structure describing the group to be evaluated.
|
||||
-- @param Unit DestroyUnit Unit structure describing the Unit to be evaluated.
|
||||
-- @param #DESTROYGROUPSTASK self
|
||||
-- @param DCSGroup#Group DestroyGroup Group structure describing the group to be evaluated.
|
||||
-- @param DCSUnit#Unit DestroyUnit Unit structure describing the Unit to be evaluated.
|
||||
-- @return #number The DestroyCount reflecting the amount of units destroyed within the group.
|
||||
function DESTROYGROUPSTASK:ReportGoalProgress( DestroyGroup, DestroyUnit )
|
||||
self:F( { DestroyGroup, DestroyUnit } )
|
||||
self:T( DestroyGroup:getSize() )
|
||||
self:F( { DestroyGroup, DestroyUnit, self.DestroyPercentage } )
|
||||
|
||||
local DestroyGroupSize = DestroyGroup:getSize() - 1 -- When a DEAD event occurs, the getSize is still one larger than the destroyed unit.
|
||||
local DestroyGroupInitialSize = DestroyGroup:getInitialSize()
|
||||
self:T( { DestroyGroupSize, DestroyGroupInitialSize - ( DestroyGroupInitialSize * self.DestroyPercentage / 100 ) } )
|
||||
|
||||
local DestroyCount = 0
|
||||
if DestroyGroup then
|
||||
if ( ( DestroyGroup:getInitialSize() * self.DestroyPercentage ) / 100 ) - DestroyGroup:getSize() <= 0 then
|
||||
if DestroyGroupSize <= DestroyGroupInitialSize - ( DestroyGroupInitialSize * self.DestroyPercentage / 100 ) then
|
||||
DestroyCount = 1
|
||||
--[[ else
|
||||
if DestroyGroup:getSize() == 1 then
|
||||
if DestroyUnit and DestroyUnit:getLife() <= 1.0 then
|
||||
DestroyCount = 1
|
||||
end
|
||||
end
|
||||
]] end
|
||||
end
|
||||
else
|
||||
DestroyCount = 1
|
||||
end
|
||||
|
||||
self:T( DestroyCount )
|
||||
|
||||
return DestroyCount
|
||||
end
|
||||
|
||||
@ -18,8 +18,8 @@ function DESTROYRADARSTASK:New( DestroyGroupNames )
|
||||
self:F()
|
||||
|
||||
self.Name = 'Destroy Radars'
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self.EventDead )
|
||||
|
||||
_EVENTDISPATCHER:OnDead( self.EventDead , self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -29,7 +29,7 @@ function DESTROYUNITTYPESTASK:New( DestroyGroupType, DestroyUnitType, DestroyGro
|
||||
self.Name = 'Destroy Unit Types'
|
||||
self.GoalVerb = "Destroy " .. DestroyGroupType
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self.EventDead )
|
||||
_EVENTDISPATCHER:OnDead( self.EventDead , self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
489
Moose/Event.lua
Normal file
489
Moose/Event.lua
Normal file
@ -0,0 +1,489 @@
|
||||
--- The EVENT class models an efficient event handling process between other classes and its units, weapons.
|
||||
-- @module Event
|
||||
-- @author FlightControl
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Base" )
|
||||
|
||||
--- The EVENT structure
|
||||
-- @type EVENT
|
||||
-- @field #EVENT.Events Events
|
||||
EVENT = {
|
||||
ClassName = "EVENT",
|
||||
ClassID = 0,
|
||||
}
|
||||
|
||||
local _EVENTCODES = {
|
||||
"S_EVENT_SHOT",
|
||||
"S_EVENT_HIT",
|
||||
"S_EVENT_TAKEOFF",
|
||||
"S_EVENT_LAND",
|
||||
"S_EVENT_CRASH",
|
||||
"S_EVENT_EJECTION",
|
||||
"S_EVENT_REFUELING",
|
||||
"S_EVENT_DEAD",
|
||||
"S_EVENT_PILOT_DEAD",
|
||||
"S_EVENT_BASE_CAPTURED",
|
||||
"S_EVENT_MISSION_START",
|
||||
"S_EVENT_MISSION_END",
|
||||
"S_EVENT_TOOK_CONTROL",
|
||||
"S_EVENT_REFUELING_STOP",
|
||||
"S_EVENT_BIRTH",
|
||||
"S_EVENT_HUMAN_FAILURE",
|
||||
"S_EVENT_ENGINE_STARTUP",
|
||||
"S_EVENT_ENGINE_SHUTDOWN",
|
||||
"S_EVENT_PLAYER_ENTER_UNIT",
|
||||
"S_EVENT_PLAYER_LEAVE_UNIT",
|
||||
"S_EVENT_PLAYER_COMMENT",
|
||||
"S_EVENT_SHOOTING_START",
|
||||
"S_EVENT_SHOOTING_END",
|
||||
"S_EVENT_MAX",
|
||||
}
|
||||
|
||||
--- The Event structure
|
||||
-- @type EVENTDATA
|
||||
-- @field id
|
||||
-- @field initiator
|
||||
-- @field target
|
||||
-- @field weapon
|
||||
-- @field IniDCSUnit
|
||||
-- @field IniDCSUnitName
|
||||
-- @field IniDCSGroup
|
||||
-- @field IniDCSGroupName
|
||||
-- @field TgtDCSUnit
|
||||
-- @field TgtDCSUnitName
|
||||
-- @field TgtDCSGroup
|
||||
-- @field TgtDCSGroupName
|
||||
-- @field Weapon
|
||||
-- @field WeaponName
|
||||
-- @field WeaponTgtDCSUnit
|
||||
|
||||
--- The Events structure
|
||||
-- @type EVENT.Events
|
||||
-- @field #number IniUnit
|
||||
|
||||
function EVENT:New()
|
||||
local self = BASE:Inherit( self, BASE:New() )
|
||||
self:F()
|
||||
self.EventHandler = world.addEventHandler( self )
|
||||
return self
|
||||
end
|
||||
|
||||
function EVENT:EventText( EventID )
|
||||
|
||||
local EventText = _EVENTCODES[EventID]
|
||||
|
||||
return EventText
|
||||
end
|
||||
|
||||
|
||||
--- Initializes the Events structure for the event
|
||||
-- @param #EVENT self
|
||||
-- @param DCSWorld#world.event EventID
|
||||
-- @param #string EventClass
|
||||
-- @return #EVENT.Events
|
||||
function EVENT:Init( 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
|
||||
return self.Events[EventID][EventClass]
|
||||
end
|
||||
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param #table EventTemplate
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @param #function OnEventFunction
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, OnEventFunction )
|
||||
self:F2( EventTemplate.name )
|
||||
|
||||
for EventUnitID, EventUnit in pairs( EventTemplate.units ) do
|
||||
OnEventFunction( self, EventUnit.name, EventFunction, EventSelf )
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_X event independent from a unit or a weapon.
|
||||
-- @param #EVENT self
|
||||
-- @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.
|
||||
-- @param EventID
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventGeneric( EventFunction, EventSelf, EventID )
|
||||
self:F2( { EventID } )
|
||||
|
||||
local Event = self:Init( EventID, EventSelf:GetClassNameAndID() )
|
||||
Event.EventFunction = EventFunction
|
||||
Event.EventSelf = EventSelf
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set a new listener for an S_EVENT_X 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.
|
||||
-- @param EventID
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, EventID )
|
||||
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
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Create an OnBirth event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param Group#GROUP EventGroup
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirthForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
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.
|
||||
-- @param #EVENT self
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirth( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_BIRTH event.
|
||||
-- @param #EVENT self
|
||||
-- @param #string EventDCSUnitName The id of the unit for the event to be handled.
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnBirthForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_BIRTH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnCrash event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param Group#GROUP EventGroup
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrashForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnCrashForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_CRASH event.
|
||||
-- @param #EVENT self
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnCrash( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_CRASH 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:OnCrashForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_CRASH )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param Group#GROUP EventGroup
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDeadForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnDeadForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_DEAD event.
|
||||
-- @param #EVENT self
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param Base#BASE EventSelf
|
||||
-- @return #EVENT
|
||||
function EVENT:OnDead( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_DEAD )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Set a new listener for an S_EVENT_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:OnDeadForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
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
|
||||
-- @param #EVENT self
|
||||
-- @param #table EventTemplate
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnLandForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnLandForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_LAND 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:OnLandForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_LAND )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param #table EventTemplate
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnTakeOffForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnTakeOffForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_TAKEOFF 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:OnTakeOffForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_TAKEOFF )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Create an OnDead event handler for a group
|
||||
-- @param #EVENT self
|
||||
-- @param #table EventTemplate
|
||||
-- @param #function EventFunction The function to be called when the event occurs for the unit.
|
||||
-- @param EventSelf The self instance of the class for which the event is.
|
||||
-- @return #EVENT
|
||||
function EVENT:OnEngineShutDownForTemplate( EventTemplate, EventFunction, EventSelf )
|
||||
self:F( EventTemplate.name )
|
||||
|
||||
self:OnEventForTemplate( EventTemplate, EventFunction, EventSelf, self.OnEngineShutDownForUnit )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_ENGINE_SHUTDOWN 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:OnEngineShutDownForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
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.
|
||||
-- @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:OnEngineStartUpForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_ENGINE_STARTUP )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_SHOT event.
|
||||
-- @param #EVENT self
|
||||
-- @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:OnShot( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
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.
|
||||
-- @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:OnShotForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_SHOT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_HIT event.
|
||||
-- @param #EVENT self
|
||||
-- @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:OnHit( EventFunction, EventSelf )
|
||||
self:F()
|
||||
|
||||
self:OnEventGeneric( EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Set a new listener for an S_EVENT_HIT 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:OnHitForUnit( EventDCSUnitName, EventFunction, EventSelf )
|
||||
self:F( EventDCSUnitName )
|
||||
|
||||
self:OnEventForUnit( EventDCSUnitName, EventFunction, EventSelf, world.event.S_EVENT_HIT )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
function EVENT:onEvent( 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
|
||||
Event.IniDCSUnit = Event.initiator
|
||||
Event.IniDCSGroup = Event.IniDCSUnit:getGroup()
|
||||
Event.IniDCSUnitName = Event.IniDCSUnit:getName()
|
||||
Event.IniDCSGroupName = ""
|
||||
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
|
||||
Event.IniDCSGroupName = Event.IniDCSGroup:getName()
|
||||
end
|
||||
end
|
||||
if Event.target then
|
||||
if Event.target and Event.target:getCategory() == Object.Category.UNIT then
|
||||
Event.TgtDCSUnit = Event.target
|
||||
Event.TgtDCSGroup = Event.TgtDCSUnit:getGroup()
|
||||
Event.TgtDCSUnitName = Event.TgtDCSUnit:getName()
|
||||
Event.TgtDCSGroupName = ""
|
||||
if Event.TgtDCSGroup and Event.TgtDCSGroup:isExist() then
|
||||
Event.TgtDCSGroupName = Event.TgtDCSGroup:getName()
|
||||
end
|
||||
end
|
||||
end
|
||||
if Event.weapon then
|
||||
Event.Weapon = Event.weapon
|
||||
Event.WeaponName = Event.Weapon:getTypeName()
|
||||
--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: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:T2( { "Calling event function for class ", ClassName } )
|
||||
EventData.EventFunction( EventData.EventSelf, Event )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Declare the event dispatcher based on the EVENT class
|
||||
_EVENTDISPATCHER = EVENT:New() -- #EVENT
|
||||
|
||||
@ -35,11 +35,11 @@ function MOVEMENT:New( MovePrefixes, MoveMaximum )
|
||||
self.AliveUnits = 0 -- Contains the counter how many units are currently alive
|
||||
self.MoveUnits = {} -- Reflects if the Moving for this MovePrefixes is going to be scheduled or not.
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_BIRTH, self.OnBirth )
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self.OnDeadOrCrash )
|
||||
self:AddEvent( world.event.S_EVENT_CRASH, self.OnDeadOrCrash )
|
||||
_EVENTDISPATCHER:OnBirth( self.OnBirth, self )
|
||||
|
||||
self:EnableEvents()
|
||||
-- self:AddEvent( world.event.S_EVENT_BIRTH, self.OnBirth )
|
||||
--
|
||||
-- self:EnableEvents()
|
||||
|
||||
self:ScheduleStart()
|
||||
|
||||
@ -61,43 +61,39 @@ end
|
||||
|
||||
--- Captures the birth events when new Units were spawned.
|
||||
-- @todo This method should become obsolete. The new @{DATABASE} class will handle the collection administration.
|
||||
function MOVEMENT:OnBirth( event )
|
||||
self:F( { event } )
|
||||
function MOVEMENT:OnBirth( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
if timer.getTime0() < timer.getAbsTime() then -- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
||||
local MovementUnit = event.initiator
|
||||
local MovementUnitName = MovementUnit:getName()
|
||||
self:T( "Birth object : " .. MovementUnitName )
|
||||
local MovementGroup = MovementUnit:getGroup()
|
||||
if MovementGroup and MovementGroup:isExist() then
|
||||
local MovementGroupName = MovementGroup:getName()
|
||||
if Event.IniDCSUnit then
|
||||
self:T( "Birth object : " .. Event.IniDCSUnitName )
|
||||
if Event.IniDCSGroup and Event.IniDCSGroup:isExist() then
|
||||
for MovePrefixID, MovePrefix in pairs( self.MovePrefixes ) do
|
||||
if string.find( MovementUnitName, MovePrefix, 1, true ) then
|
||||
if string.find( Event.IniDCSUnitName, MovePrefix, 1, true ) then
|
||||
self.AliveUnits = self.AliveUnits + 1
|
||||
self.MoveUnits[MovementUnitName] = MovementGroupName
|
||||
self.MoveUnits[Event.IniDCSUnitName] = Event.IniDCSGroupName
|
||||
self:T( self.AliveUnits )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
_EVENTDISPATCHER:OnCrashForUnit( Event.IniDCSUnitName, self.OnDeadOrCrash, self )
|
||||
_EVENTDISPATCHER:OnDeadForUnit( Event.IniDCSUnitName, self.OnDeadOrCrash, self )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Captures the Dead or Crash events when Units crash or are destroyed.
|
||||
-- @todo This method should become obsolete. The new @{DATABASE} class will handle the collection administration.
|
||||
function MOVEMENT:OnDeadOrCrash( event )
|
||||
self:F( { event } )
|
||||
function MOVEMENT:OnDeadOrCrash( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
if event.initiator and Object.getCategory(event.initiator) == Object.Category.UNIT then
|
||||
local MovementUnit = event.initiator
|
||||
local MovementUnitName = MovementUnit:getName()
|
||||
self:T( "Dead object : " .. MovementUnitName )
|
||||
if Event.IniDCSUnit then
|
||||
self:T( "Dead object : " .. Event.IniDCSUnitName )
|
||||
for MovePrefixID, MovePrefix in pairs( self.MovePrefixes ) do
|
||||
if string.find( MovementUnitName, MovePrefix, 1, true ) then
|
||||
if string.find( Event.IniDCSUnitName, MovePrefix, 1, true ) then
|
||||
self.AliveUnits = self.AliveUnits - 1
|
||||
self.MoveUnits[MovementUnitName] = nil
|
||||
self.MoveUnits[Event.IniDCSUnitName] = nil
|
||||
self:T( self.AliveUnits )
|
||||
end
|
||||
end
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
-- @author (co) Flightcontrol (Modified and enriched with functionality)
|
||||
|
||||
Include.File( "Routines" )
|
||||
Include.File( "Event" )
|
||||
Include.File( "Base" )
|
||||
Include.File( "Mission" )
|
||||
Include.File( "Client" )
|
||||
@ -42,27 +43,26 @@ function SEAD:New( SEADGroupPrefixes )
|
||||
else
|
||||
self.SEADGroupNames[SEADGroupPrefixes] = SEADGroupPrefixes
|
||||
end
|
||||
self:AddEvent( world.event.S_EVENT_SHOT, self.EventShot )
|
||||
self:EnableEvents()
|
||||
_EVENTDISPATCHER:OnShot( self.EventShot, self )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
--- Detects if an SA site was shot with an anti radiation missile. In this case, take evasive actions based on the skill level set within the ME.
|
||||
-- @see SEAD
|
||||
function SEAD:EventShot( event )
|
||||
self:F( { event } )
|
||||
function SEAD:EventShot( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local SEADUnit = event.initiator
|
||||
local SEADUnitName = SEADUnit:getName()
|
||||
local SEADWeapon = event.weapon -- Identify the weapon fired
|
||||
local SEADWeaponName = SEADWeapon:getTypeName() -- return weapon type
|
||||
local SEADUnit = Event.IniDCSUnit
|
||||
local SEADUnitName = Event.IniDCSUnitName
|
||||
local SEADWeapon = Event.Weapon -- Identify the weapon fired
|
||||
local SEADWeaponName = Event.WeaponName -- return weapon type
|
||||
--trigger.action.outText( string.format("Alerte, depart missile " ..string.format(SEADWeaponName)), 20) --debug message
|
||||
-- Start of the 2nd loop
|
||||
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 = Weapon.getTarget(SEADWeapon) -- 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()
|
||||
|
||||
@ -75,6 +75,7 @@ Include.File( "Base" )
|
||||
Include.File( "Database" )
|
||||
Include.File( "Group" )
|
||||
Include.File( "Zone" )
|
||||
Include.File( "Event" )
|
||||
|
||||
--- SPAWN Class
|
||||
-- @type SPAWN
|
||||
@ -121,12 +122,6 @@ function SPAWN:New( SpawnTemplatePrefix )
|
||||
else
|
||||
error( "SPAWN:New: There is no group declared in the mission editor with SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" )
|
||||
end
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_BIRTH, self._OnBirth )
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self._OnDeadOrCrash )
|
||||
self:AddEvent( world.event.S_EVENT_CRASH, self._OnDeadOrCrash )
|
||||
|
||||
self:EnableEvents()
|
||||
|
||||
return self
|
||||
end
|
||||
@ -165,12 +160,6 @@ function SPAWN:NewWithAlias( SpawnTemplatePrefix, SpawnAliasPrefix )
|
||||
error( "SPAWN:New: There is no group declared in the mission editor with SpawnTemplatePrefix = '" .. SpawnTemplatePrefix .. "'" )
|
||||
end
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_BIRTH, self._OnBirth )
|
||||
self:AddEvent( world.event.S_EVENT_DEAD, self._OnDeadOrCrash )
|
||||
self:AddEvent( world.event.S_EVENT_CRASH, self._OnDeadOrCrash )
|
||||
|
||||
self:EnableEvents()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -282,17 +271,12 @@ end
|
||||
-- -- Re-SPAWN the Group(s) after each landing and Engine Shut-Down automatically.
|
||||
-- SpawnRU_SU34 = SPAWN:New( 'TF1 RU Su-34 Krymsk@AI - Attack Ships' ):Schedule( 2, 3, 1800, 0.4 ):SpawnUncontrolled():RandomizeRoute( 1, 1, 3000 ):RepeatOnEngineShutDown()
|
||||
function SPAWN:Repeat()
|
||||
self:F( { self.SpawnTemplatePrefix } )
|
||||
self:F( { self.SpawnTemplatePrefix, self.SpawnIndex } )
|
||||
|
||||
self.SpawnRepeat = true
|
||||
self.RepeatOnEngineShutDown = false
|
||||
self.RepeatOnLanding = true
|
||||
|
||||
self:AddEvent( world.event.S_EVENT_LAND, self._OnLand )
|
||||
self:AddEvent( world.event.S_EVENT_TAKEOFF, self._OnTakeOff )
|
||||
self:AddEvent( world.event.S_EVENT_ENGINE_SHUTDOWN, self._OnEngineShutDown )
|
||||
self:EnableEvents()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -385,6 +369,21 @@ function SPAWN:Array( SpawnAngle, SpawnWidth, SpawnDeltaX, SpawnDeltaY )
|
||||
self.SpawnGroups[SpawnGroupID].SpawnTemplate.visible = true
|
||||
|
||||
self.SpawnGroups[SpawnGroupID].Visible = true
|
||||
|
||||
_EVENTDISPATCHER:OnBirthForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnBirth, self )
|
||||
_EVENTDISPATCHER:OnCrashForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnDeadOrCrash, self )
|
||||
_EVENTDISPATCHER:OnDeadForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnDeadOrCrash, self )
|
||||
|
||||
if self.SpawnRepeat then
|
||||
_EVENTDISPATCHER:OnTakeOffForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnTakeOff, self )
|
||||
end
|
||||
if self.RepeatOnLanding then
|
||||
_EVENTDISPATCHER:OnLandForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnLand, self )
|
||||
end
|
||||
if self.RepeatOnEngineShutDown then
|
||||
_EVENTDISPATCHER:OnEngineShutDownForTemplate( self.SpawnGroups[SpawnGroupID].SpawnTemplate, self._OnEngineShutDown, self )
|
||||
end
|
||||
|
||||
self.SpawnGroups[SpawnGroupID].Group = _Database:Spawn( self.SpawnGroups[SpawnGroupID].SpawnTemplate )
|
||||
|
||||
SpawnX = SpawnXIndex * SpawnDeltaX
|
||||
@ -419,13 +418,13 @@ function SPAWN:ReSpawn( SpawnIndex )
|
||||
end
|
||||
|
||||
-- TODO: This logic makes DCS crash and i don't know why (yet).
|
||||
-- local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
|
||||
-- if SpawnGroup then
|
||||
-- local SpawnDCSGroup = SpawnGroup:GetDCSGroup()
|
||||
-- if SpawnDCSGroup then
|
||||
-- SpawnGroup:Destroy()
|
||||
-- end
|
||||
-- end
|
||||
local SpawnGroup = self:GetGroupFromIndex( SpawnIndex )
|
||||
if SpawnGroup then
|
||||
local SpawnDCSGroup = SpawnGroup:GetDCSGroup()
|
||||
if SpawnDCSGroup then
|
||||
SpawnGroup:Destroy()
|
||||
end
|
||||
end
|
||||
|
||||
return self:SpawnWithIndex( SpawnIndex )
|
||||
end
|
||||
@ -443,6 +442,20 @@ function SPAWN:SpawnWithIndex( SpawnIndex )
|
||||
self.SpawnGroups[self.SpawnIndex].Group:Activate()
|
||||
else
|
||||
self:T( self.SpawnGroups[self.SpawnIndex].SpawnTemplate )
|
||||
_EVENTDISPATCHER:OnBirthForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnBirth, self )
|
||||
_EVENTDISPATCHER:OnCrashForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnDeadOrCrash, self )
|
||||
_EVENTDISPATCHER:OnDeadForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnDeadOrCrash, self )
|
||||
|
||||
if self.SpawnRepeat then
|
||||
_EVENTDISPATCHER:OnTakeOffForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnTakeOff, self )
|
||||
end
|
||||
if self.RepeatOnLanding then
|
||||
_EVENTDISPATCHER:OnLandForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnLand, self )
|
||||
end
|
||||
if self.RepeatOnEngineShutDown then
|
||||
_EVENTDISPATCHER:OnEngineShutDownForTemplate( self.SpawnGroups[self.SpawnIndex].SpawnTemplate, self._OnEngineShutDown, self )
|
||||
end
|
||||
|
||||
self.SpawnGroups[self.SpawnIndex].Group = _Database:Spawn( self.SpawnGroups[self.SpawnIndex].SpawnTemplate )
|
||||
|
||||
-- If there is a SpawnFunction hook defined, call it.
|
||||
@ -458,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
|
||||
|
||||
@ -91,7 +91,7 @@ end
|
||||
--- Get progress of a TASK.
|
||||
-- @return string GoalsText
|
||||
function TASK:GetGoalProgress()
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
local GoalsText = ""
|
||||
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
|
||||
@ -115,7 +115,7 @@ end
|
||||
-- @param MISSION Mission Group structure describing the Mission.
|
||||
-- @param CLIENT Client Group structure describing the Client.
|
||||
function TASK:ShowGoalProgress( Mission, Client )
|
||||
self:F()
|
||||
self:F2()
|
||||
|
||||
local GoalsText = ""
|
||||
for GoalVerb, GoalVerbData in pairs( self.GoalTasks ) do
|
||||
@ -137,14 +137,14 @@ end
|
||||
|
||||
--- Sets a TASK to status Done.
|
||||
function TASK:Done()
|
||||
self:F()
|
||||
self:F2()
|
||||
self.TaskDone = true
|
||||
end
|
||||
|
||||
--- Returns if a TASK is done.
|
||||
-- @return bool
|
||||
function TASK:IsDone()
|
||||
self:F( self.TaskDone )
|
||||
self:F2( self.TaskDone )
|
||||
return self.TaskDone
|
||||
end
|
||||
|
||||
@ -157,12 +157,12 @@ end
|
||||
--- Returns if a TASk has failed.
|
||||
-- @return bool
|
||||
function TASK:IsFailed()
|
||||
self:F( self.TaskFailed )
|
||||
self:F2( self.TaskFailed )
|
||||
return self.TaskFailed
|
||||
end
|
||||
|
||||
function TASK:Reset( Mission, Client )
|
||||
self:F()
|
||||
self:F2()
|
||||
self.ExecuteStage = _TransportExecuteStage.NONE
|
||||
end
|
||||
|
||||
@ -173,13 +173,15 @@ function TASK:GetGoals()
|
||||
end
|
||||
|
||||
--- Returns if a TASK has Goal(s).
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK.
|
||||
-- @param #TASK self
|
||||
-- @param #string GoalVerb is the name of the Goal of the TASK.
|
||||
-- @return bool
|
||||
function TASK:Goal( GoalVerb )
|
||||
self:F()
|
||||
self:F2( { GoalVerb } )
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
self:T2( {self.GoalTasks[GoalVerb] } )
|
||||
if self.GoalTasks[GoalVerb] and self.GoalTasks[GoalVerb].GoalTotal > 0 then
|
||||
return true
|
||||
else
|
||||
@ -191,7 +193,7 @@ end
|
||||
-- @param number GoalTotal is the number of times the GoalVerb needs to be achieved.
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
function TASK:SetGoalTotal( GoalTotal, GoalVerb )
|
||||
self:F( { GoalTotal, GoalVerb } )
|
||||
self:F2( { GoalTotal, GoalVerb } )
|
||||
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
@ -206,7 +208,7 @@ end
|
||||
--- Gets the total of Goals to be achieved within the TASK of the GoalVerb.
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
function TASK:GetGoalTotal( GoalVerb )
|
||||
self:F()
|
||||
self:F2( { GoalVerb } )
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
@ -222,7 +224,7 @@ end
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
-- @return TASK
|
||||
function TASK:SetGoalCount( GoalCount, GoalVerb )
|
||||
self:F()
|
||||
self:F2()
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
@ -237,7 +239,7 @@ end
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
-- @return TASK
|
||||
function TASK:IncreaseGoalCount( GoalCountIncrease, GoalVerb )
|
||||
self:F()
|
||||
self:F2( { GoalCountIncrease, GoalVerb } )
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
@ -251,7 +253,7 @@ end
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
-- @return TASK
|
||||
function TASK:GetGoalCount( GoalVerb )
|
||||
self:F()
|
||||
self:F2()
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
@ -266,7 +268,7 @@ end
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
-- @return TASK
|
||||
function TASK:GetGoalPercentage( GoalVerb )
|
||||
self:F()
|
||||
self:F2()
|
||||
if not GoalVerb then
|
||||
GoalVerb = self.GoalVerb
|
||||
end
|
||||
@ -279,15 +281,16 @@ end
|
||||
|
||||
--- Returns if all the Goals of the TASK were achieved.
|
||||
-- @return bool
|
||||
function TASK:IsGoalReached( )
|
||||
function TASK:IsGoalReached()
|
||||
self:F2()
|
||||
|
||||
local GoalReached = true
|
||||
|
||||
for GoalVerb, Goals in pairs( self.GoalTasks ) do
|
||||
self:T( { "GoalVerb", GoalVerb } )
|
||||
self:T2( { "GoalVerb", GoalVerb } )
|
||||
if self:Goal( GoalVerb ) then
|
||||
local GoalToDo = self:GetGoalTotal( GoalVerb ) - self:GetGoalCount( GoalVerb )
|
||||
self:T( "GoalToDo = " .. GoalToDo )
|
||||
self:T2( "GoalToDo = " .. GoalToDo )
|
||||
if GoalToDo <= 0 then
|
||||
else
|
||||
GoalReached = false
|
||||
@ -298,7 +301,7 @@ function TASK:IsGoalReached( )
|
||||
end
|
||||
end
|
||||
|
||||
self:T( GoalReached )
|
||||
self:T( { GoalReached, self.GoalTasks } )
|
||||
return GoalReached
|
||||
end
|
||||
|
||||
@ -307,7 +310,7 @@ end
|
||||
-- @param string GoalTask is a text describing the Goal of the TASK to be achieved.
|
||||
-- @param number GoalIncrease is a number by which the Goal achievement is increasing.
|
||||
function TASK:AddGoalCompletion( GoalVerb, GoalTask, GoalIncrease )
|
||||
self:F( { GoalVerb, GoalTask, GoalIncrease } )
|
||||
self:F2( { GoalVerb, GoalTask, GoalIncrease } )
|
||||
|
||||
if self:Goal( GoalVerb ) then
|
||||
self.GoalTasks[GoalVerb].Goals[#self.GoalTasks[GoalVerb].Goals+1] = GoalTask
|
||||
@ -320,7 +323,7 @@ end
|
||||
-- @param ?string GoalVerb is the name of the Goal of the TASK. If the GoalVerb is not given, then the default TASK Goals will be used.
|
||||
-- @return string Goals
|
||||
function TASK:GetGoalCompletion( GoalVerb )
|
||||
self:F( { GoalVerb } )
|
||||
self:F2( { GoalVerb } )
|
||||
|
||||
if self:Goal( GoalVerb ) then
|
||||
local Goals = ""
|
||||
|
||||
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.
BIN
Test Missions/Moose_Test_DESTROY/MOOSE_Test_DESTROY.miz
Normal file
BIN
Test Missions/Moose_Test_DESTROY/MOOSE_Test_DESTROY.miz
Normal file
Binary file not shown.
41
Test Missions/Moose_Test_DESTROY/Moose_Test_DESTROY.lua
Normal file
41
Test Missions/Moose_Test_DESTROY/Moose_Test_DESTROY.lua
Normal file
@ -0,0 +1,41 @@
|
||||
-- MOOSE include files.
|
||||
Include.File( "Mission" )
|
||||
Include.File( "Client" )
|
||||
Include.File( "DestroyGroupsTask" )
|
||||
Include.File( "DestroyRadarsTask" )
|
||||
Include.File( "DestroyUnitTypesTask" )
|
||||
Include.File( "Group" )
|
||||
Include.File( "Unit" )
|
||||
Include.File( "Zone" )
|
||||
Include.File( "Event" )
|
||||
|
||||
do
|
||||
local Mission = MISSION:New( 'Destroy Gound', 'Ground', 'Briefing', 'CCCP' )
|
||||
|
||||
Mission:AddClient( CLIENT:New( 'Client Plane', "Just wait and observe the SU-25T destoying targets. Your mission goal should increase..." ) )
|
||||
|
||||
local DESTROYGROUPSTASK = DESTROYGROUPSTASK:New( 'Ground Vehicle', 'Ground Vehicles', { 'DESTROY Test 1' }, 100 ) -- 75% of a patriot battery needs to be destroyed to achieve mission success...
|
||||
DESTROYGROUPSTASK:SetGoalTotal( 1 )
|
||||
Mission:AddTask( DESTROYGROUPSTASK, 1 )
|
||||
|
||||
MISSIONSCHEDULER.AddMission( Mission )
|
||||
end
|
||||
|
||||
|
||||
do
|
||||
local Mission = MISSION:New( 'Destroy Helicopters', 'Helicopters', 'Briefing', 'CCCP' )
|
||||
|
||||
Mission:AddClient( CLIENT:New( 'Client Plane', "Just wait and observe the SU-25T destoying the helicopters. The helicopter mission goal should increase once all are destroyed ..." ) )
|
||||
|
||||
local DESTROYGROUPSTASK = DESTROYGROUPSTASK:New( 'Helicopter', 'Helicopters', { 'DESTROY Test 2' }, 50 )
|
||||
DESTROYGROUPSTASK:SetGoalTotal( 2 )
|
||||
Mission:AddTask( DESTROYGROUPSTASK, 1 )
|
||||
|
||||
MISSIONSCHEDULER.AddMission( Mission )
|
||||
end
|
||||
|
||||
-- MISSION SCHEDULER STARTUP
|
||||
MISSIONSCHEDULER.Start()
|
||||
MISSIONSCHEDULER.ReportMenu()
|
||||
MISSIONSCHEDULER.ReportMissionsFlash( 30 )
|
||||
MISSIONSCHEDULER.ReportMissionsHide()
|
||||
BIN
Test Missions/Moose_Test_SEAD/MOOSE_Test_SEAD.miz
Normal file
BIN
Test Missions/Moose_Test_SEAD/MOOSE_Test_SEAD.miz
Normal file
Binary file not shown.
11
Test Missions/Moose_Test_SEAD/Moose_Test_SEAD.lua
Normal file
11
Test Missions/Moose_Test_SEAD/Moose_Test_SEAD.lua
Normal file
@ -0,0 +1,11 @@
|
||||
Include.File( "Sead" )
|
||||
|
||||
|
||||
-- CCCP SEAD Defenses
|
||||
SEAD_RU_SAM_Defenses = SEAD
|
||||
:New(
|
||||
{ 'SAM Test'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ Spawn_Vehicle_Limited_Scheduled_RandomizeRoute = SPAWN:New( "Spawn Vehicle Limit
|
||||
-- Tests the CleanUp functionality.
|
||||
-- Limited spawning of groups, scheduled every 10 seconds, who are engaging into combat. Some helicopters may crash land on the ground.
|
||||
-- Observe when helicopters land but are not dead and are out of the danger zone, that they get removed after a while (+/- 180 seconds) and ReSpawn.
|
||||
Spawn_Helicopter_Scheduled_CleanUp = SPAWN:New( "Spawn Helicopter Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):CleanUp( 180 ):SpawnScheduled( 10, 0 )
|
||||
Spawn_Helicopter_Scheduled_CleanUp = SPAWN:New( "Spawn Helicopter Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):CleanUp( 60 ):SpawnScheduled( 10, 0 )
|
||||
Spawn_Vehicle_Scheduled_CleanUp = SPAWN:New( "Spawn Vehicle Scheduled CleanUp" ):Limit( 3, 100 ):RandomizeRoute( 1, 1, 1000 ):SpawnScheduled( 10, 0 )
|
||||
|
||||
-- Maykop
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user