diff --git a/Moose/DestroyBaseTask.lua b/Moose/DestroyBaseTask.lua index 997e959a1..4ac7a245a 100644 --- a/Moose/DestroyBaseTask.lua +++ b/Moose/DestroyBaseTask.lua @@ -20,51 +20,52 @@ DESTROYBASETASK = { -- @tparam ?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}. -- @treturn DESTROYBASETASK function DESTROYBASETASK:New( DestroyGroupType, DestroyUnitType, DestroyGroupPrefixes, DestroyPercentage ) -trace.f(self.ClassName) - - -- Inheritance - local Child = BASE:Inherit( self, TASK:New() ) + local self = BASE:Inherit( self, TASK:New() ) + self:T() - Child.Name = 'Destroy' - Child.Destroyed = 0 - Child.DestroyGroupPrefixes = DestroyGroupPrefixes - Child.DestroyGroupType = DestroyGroupType - Child.DestroyUnitType = DestroyUnitType - Child.TaskBriefing = "Task: Destroy " .. DestroyGroupType .. "." - Child.Stages = { STAGEBRIEF:New(), STAGESTART:New(), STAGEGROUPSDESTROYED:New(), STAGEDONE:New() } - Child.SetStage( Child, 1 ) + self.Name = 'Destroy' + self.Destroyed = 0 + self.DestroyGroupPrefixes = DestroyGroupPrefixes + self.DestroyGroupType = DestroyGroupType + self.DestroyUnitType = DestroyUnitType + self.TaskBriefing = "Task: Destroy " .. DestroyGroupType .. "." + self.Stages = { STAGEBRIEF:New(), STAGESTART:New(), STAGEGROUPSDESTROYED:New(), STAGEDONE:New() } + self.SetStage( self, 1 ) - --Child.AddEvent( Child, world.event.S_EVENT_DEAD, Child.EventDead ) + --self.AddEvent( self, world.event.S_EVENT_DEAD, self.EventDead ) - --env.info( 'New Table Child = ' .. tostring(Child) ) + --env.info( 'New Table self = ' .. tostring(self) ) --env.info( 'New Table self = ' .. tostring(self) ) - return Child + 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 ) -trace.f( self.ClassName, { 'EventDead', event } ) + self:T( { 'EventDead', event } ) if event.initiator then - local DestroyGroup = Unit.getGroup( event.initiator ) - local DestroyGroupName = DestroyGroup:getName() 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 local UnitsDestroyed = 0 - trace.i( self.ClassName, DestroyGroupName ) - trace.i( self.ClassName, DestroyUnitName ) + self:T( DestroyGroupName ) + self:T( DestroyUnitName ) for DestroyGroupPrefixID, DestroyGroupPrefix in pairs( self.DestroyGroupPrefixes ) do - trace.i( self.ClassName, DestroyGroupPrefix ) + self:T( DestroyGroupPrefix ) if string.find( DestroyGroupName, DestroyGroupPrefix, 1, true ) then - trace.i( self.ClassName, BASE:Inherited(self).ClassName ) + self:T( BASE:Inherited(self).ClassName ) UnitsDestroyed = self:ReportGoalProgress( DestroyGroup, DestroyUnit ) - trace.i( self.ClassName, UnitsDestroyed ) + self:T( UnitsDestroyed ) end end - trace.i( self.ClassName, { UnitsDestroyed } ) + self:T( { UnitsDestroyed } ) self:IncreaseGoalCount( UnitsDestroyed, self.GoalVerb ) end end @@ -73,7 +74,7 @@ end -- @param DestroyGroup Group structure describing the group to be evaluated. -- @param DestroyUnit Unit structure describing the Unit to be evaluated. function DESTROYBASETASK:ReportGoalProgress( DestroyGroup, DestroyUnit ) -trace.f(self.ClassName) +self:T() return 0 end diff --git a/Moose/Sead.lua b/Moose/Sead.lua index e9b2a31f3..c068491d7 100644 --- a/Moose/Sead.lua +++ b/Moose/Sead.lua @@ -30,51 +30,48 @@ SEAD = { -- -- Defends the Russian SA installations from SEAD attacks. -- SEAD_RU_SAM_Defenses = SEAD:New( { 'RU SA-6 Kub', 'RU SA-6 Defenses', 'RU MI-26 Troops', 'RU Attack Gori' } ) function SEAD:New( SEADGroupPrefixes ) -trace.f(self.ClassName, SEADGroupPrefixes ) - - -- Arrange meta tables - local Child = BASE:Inherit( self, BASE:New() ) + local self = BASE:Inherit( self, BASE:New() ) + self:T( SEADGroupPrefixes ) if type( SEADGroupPrefixes ) == 'table' then for SEADGroupPrefixID, SEADGroupPrefix in pairs( SEADGroupPrefixes ) do - Child.SEADGroupPrefixes[SEADGroupPrefix] = SEADGroupPrefix + self.SEADGroupPrefixes[SEADGroupPrefix] = SEADGroupPrefix end else - Child.SEADGroupNames[SEADGroupPrefixes] = SEADGroupPrefixes + self.SEADGroupNames[SEADGroupPrefixes] = SEADGroupPrefixes end - Child.AddEvent( Child, world.event.S_EVENT_SHOT, Child.EventShot ) - Child.EnableEvents( Child ) + self.AddEvent( self, world.event.S_EVENT_SHOT, self.EventShot ) + self.EnableEvents( self ) - return Child + 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 ) -trace.f( self.ClassName, { event } ) +self:T( { 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 + local SEADUnit = event.initiator + local SEADUnitName = SEADUnit:getName() + local SEADWeapon = event.weapon -- Identify the weapon fired + local SEADWeaponName = SEADWeapon:getTypeName() -- return weapon type + --trigger.action.outText( string.format("Alerte, depart missile " ..string.format(SEADWeaponName)), 20) --debug message -- Start of the 2nd loop - trace.i( self.ClassName, "Missile Launched = " .. _SEADmissileName ) - if _SEADmissileName == "KH-58" or _SEADmissileName == "KH-25MPU" or _SEADmissileName == "AGM-88" or _SEADmissileName == "KH-31A" or _SEADmissileName == "KH-31P" then -- Check if the missile is a SEAD + 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(_SEADmissile) -- Identify target + local _targetMim = Weapon.getTarget(SEADWeapon) -- Identify target local _targetMimname = Unit.getName(_targetMim) - local _targetMimgroup = Unit.getGroup(Weapon.getTarget(_SEADmissile)) + local _targetMimgroup = Unit.getGroup(Weapon.getTarget(SEADWeapon)) local _targetMimgroupName = _targetMimgroup:getName() local _targetMimcont= _targetMimgroup:getController() local _targetskill = _Database.Units[_targetMimname].Template.skill - trace.i( self.ClassName, self.SEADGroupPrefixes ) - trace.i( self.ClassName, _targetMimgroupName ) + self:T( self.SEADGroupPrefixes ) + self:T( _targetMimgroupName ) local SEADGroupFound = false for SEADGroupPrefixID, SEADGroupPrefix in pairs( self.SEADGroupPrefixes ) do if string.find( _targetMimgroupName, SEADGroupPrefix, 1, true ) then SEADGroupFound = true - trace.i( self.ClassName, 'Group Found' ) + self:T( 'Group Found' ) break end end @@ -83,13 +80,13 @@ trace.f( self.ClassName, { event } ) local Skills = { "Average", "Good", "High", "Excellent" } _targetskill = Skills[ math.random(1,4) ] end - trace.i( self.ClassName, _targetskill ) -- debug message for skill check + self:T( _targetskill ) -- debug message for skill check if self.TargetSkill[_targetskill] then if (_evade > self.TargetSkill[_targetskill].Evade) then - trace.i( self.ClassName, string.format("Evading, target skill " ..string.format(_targetskill)) ) --debug message - local _targetMim = Weapon.getTarget(_SEADmissile) + self:T( string.format("Evading, target skill " ..string.format(_targetskill)) ) --debug message + local _targetMim = Weapon.getTarget(SEADWeapon) local _targetMimname = Unit.getName(_targetMim) - local _targetMimgroup = Unit.getGroup(Weapon.getTarget(_SEADmissile)) + local _targetMimgroup = Unit.getGroup(Weapon.getTarget(SEADWeapon)) local _targetMimcont= _targetMimgroup:getController() routines.groupRandomDistSelf(_targetMimgroup,300,'Rank',250,20) -- move randomly local SuppressedGroups1 = {} -- unit suppressed radar off for a random time