From a79bc11834da7b9f30071ae01cf9c504bc0b38e5 Mon Sep 17 00:00:00 2001 From: FlightControl Date: Fri, 21 Apr 2017 06:58:28 +0200 Subject: [PATCH] Progress --- Moose Development/Moose/AI/AI_Designate.lua | 110 +++++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/Moose Development/Moose/AI/AI_Designate.lua b/Moose Development/Moose/AI/AI_Designate.lua index 35ed1639a..d892da22c 100644 --- a/Moose Development/Moose/AI/AI_Designate.lua +++ b/Moose Development/Moose/AI/AI_Designate.lua @@ -237,6 +237,9 @@ do -- AI_DESIGNATE self:SetLaserCodes( 1688 ) + self.LaserCodesUsed = {} + + self.Detection:__Start( 2 ) @@ -253,6 +256,8 @@ do -- AI_DESIGNATE self.LaserCodes = ( type( LaserCodes ) == "table" ) and LaserCodes or { LaserCodes } self:E(self.LaserCodes) + + self.LaserCodesUsed = {} return self end @@ -330,39 +335,35 @@ do -- AI_DESIGNATE DesignateMenu ) - if self.Spots[Index] then - - MENU_GROUP_COMMAND:New( - AttackGroup, - "Switch laser Off", - DetectedMenu, - self.MenuLaseOff, - self, - AttackGroup, - Index - ) - else - MENU_GROUP_COMMAND:New( - AttackGroup, - "Lase target 60 secs", - DetectedMenu, - self.MenuLaseOn, - self, - AttackGroup, - Index, - 60 - ) - MENU_GROUP_COMMAND:New( - AttackGroup, - "Lase target 120 secs", - DetectedMenu, - self.MenuLaseOn, - self, - AttackGroup, - Index, - 120 - ) - end + MENU_GROUP_COMMAND:New( + AttackGroup, + "Lase target 60 secs", + DetectedMenu, + self.MenuLaseOn, + self, + AttackGroup, + Index, + 60 + ) + MENU_GROUP_COMMAND:New( + AttackGroup, + "Lase target 120 secs", + DetectedMenu, + self.MenuLaseOn, + self, + AttackGroup, + Index, + 120 + ) + MENU_GROUP_COMMAND:New( + AttackGroup, + "Switch laser Off", + DetectedMenu, + self.MenuLaseOff, + self, + AttackGroup, + Index + ) MENU_GROUP_COMMAND:New( AttackGroup, @@ -425,32 +426,37 @@ do -- AI_DESIGNATE function AI_DESIGNATE:onafterLasing( From, Event, To, AttackGroup, Index, Duration ) local TargetSetUnit = self.Detection:GetDetectedSet( Index ) - + local Targets = false TargetSetUnit:ForEachUnit( --- @param Wrapper.Unit#UNIT SmokeUnit - function( SmokeUnit ) + function( TargetUnit ) self:E("In procedure") --if math.random( 1, ( 100 * TargetSetUnit:Count() ) / 100 ) <= 100 then - if SmokeUnit:IsAlive() then - local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( SmokeUnit:GetPointVec2() ) - if NearestRecceGroup then - for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do - local RecceUnit = UnitData -- Wrapper.Unit#UNIT - Targets = true - if RecceUnit:IsLasing() == false then - self.Spots[Index] = self.Spots[Index] or {} - local Spots = self.Spots[Index] - local LaserCode = self.LaserCodes[math.random(1, #self.LaserCodes)] - local Spot = RecceUnit:LaseUnit( SmokeUnit, LaserCode, Duration ) - Spots[RecceUnit] = Spot - RecceUnit:MessageToGroup( "Lasing " .. SmokeUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) - break - else + if TargetUnit:IsAlive() then + local Spot = self.Spots[TargetUnit] + if (not Spot) or ( Spot and Spot:IsLasing() == false ) then + local NearestRecceGroup = self.RecceSet:FindNearestGroupFromPointVec2( TargetUnit:GetPointVec2() ) + if NearestRecceGroup then + for UnitID, UnitData in pairs( NearestRecceGroup:GetUnits() or {} ) do + local RecceUnit = UnitData -- Wrapper.Unit#UNIT + Targets = true + if RecceUnit:IsLasing() == false then + local LaserCode = self.LaserCodes[math.random(1, #self.LaserCodes)] + local Spot = RecceUnit:LaseUnit( TargetUnit, LaserCode, Duration ) + self.Spots[TargetUnit] = Spot + RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) + break + end end end + else + local RecceUnit = Spot.Recce + RecceUnit:MessageToGroup( "Lasing " .. TargetUnit:GetTypeName() .. " for " .. Duration .. " seconds. Laser Code: " .. Spot.LaserCode, 15, AttackGroup ) end + else + self.Spots[TargetUnit] = nil end --end end @@ -473,7 +479,7 @@ do -- AI_DESIGNATE local TargetSetUnit = self.Detection:GetDetectedSet( Index ) - local Spots = self.Spots[Index] + local Spots = self.Spots for SpotID, SpotData in pairs( Spots ) do local Spot = SpotData -- Core.Spot#SPOT @@ -482,7 +488,7 @@ do -- AI_DESIGNATE end Spots = nil - self.Spots[Index] = nil + self.Spots = {} self:SetDesignateMenu() end