Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: Lua  |  size: 20.47 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ##########################################################################################
  2.     ## --Teleport Move & Teleport Move Field
  3.     ##########################################################################################
  4.        
  5.         --[[
  6.                 These intel types will only work IF the unit has them as a custom intel type..
  7.        
  8.         --]]
  9.        
  10.         --Teleport Move
  11.        
  12.         CreateTeleportMoveEnhancement = function(self, spec)
  13.                 if not spec or table.getsize(spec) == 0 then
  14.                         spec = self:GetDefaultTeleportMoveParams('single')
  15.                 end
  16.                 self:AddCustomUnitIntel('TeleportMove', spec)  
  17.         end,
  18.        
  19.         RemoveTeleportMoveEnhancement = function(self)
  20.                 self:RemoveCustomUnitIntel('TeleportMove')
  21.         end,
  22.        
  23.         Activate_TeleportMove = function(self, intelType)
  24.                 self:SetTeleportMoveStatus(true, intelType)
  25.     end,    
  26.    
  27.     Deactivate_TeleportMove = function(self,intelType)
  28.                 self:SetTeleportMoveStatus(false, intelType)
  29.     end,
  30.                
  31.         SetTeleportMoveStatus = function(self, enabled, intelType)
  32.         if enabled then
  33.                         self:SetUnitParam('CanTeleportMove', true)
  34.                         self:RemoveUnitThread('TeleportUnitToDestination')
  35.                         self:RemoveUnitThread('WaitForTeleportMoveReady')
  36.                         self:RemoveUnitThread('TeleportUnitsInRange')
  37.                         self:RemoveUnitThread('TeleportCoolDownTimer')
  38.                        
  39.                         if self:GetMotionStatus() == 'TopSpeed' then
  40.                                 self:TeleportToDestination()
  41.                         end
  42.         elseif not enabled then
  43.                         self:SetUnitParam('CanTeleportMove', false)
  44.                         self:RemoveUnitThread('WaitForTeleportMoveReady')
  45.                         self:RemoveUnitThread('TeleportUnitsInRange')
  46.                         self:RemoveUnitThread('TeleportCoolDownTimer')
  47.         end
  48.     end,
  49.        
  50.         GetTeleportMoveStatus = function(self)
  51.         return self:GetUnitParam('CanTeleportMove')
  52.     end,
  53.        
  54.         IsBeingTeleported = function(self)
  55.                 return self:GetUnitParam('IsBeingTeleported') or false
  56.         end,
  57.        
  58.         SetIsBeingTeleported = function(self, Param)
  59.                 if Param and not self:IsBeingTeleported() then
  60.                         self:SetUnitParam('IsBeingTeleported', true)
  61.                 elseif not Param and self:IsBeingTeleported() then
  62.                         self:SetUnitParam('IsBeingTeleported', false)
  63.                 end    
  64.         end,
  65.                        
  66.         TeleportToDestination = function(self)
  67.                 local MyPos = self:GetPosition()
  68.                 local Destination = self:GetNavigator():GetGoalPos()
  69.                 local ValidDestination = import('/lua/AI/aiutilities.lua').CheckUnitPathingEx(Destination, MyPos, self)
  70.                
  71.                 if ValidDestination then
  72.                         if not EntityCategoryContains(categories.CANNOTTELEPORT, self) then
  73.                                 self:ForkThread(self.InitializeTeleportToDestination)
  74.                         else
  75.                                 ShowMouseText(self, '--> Teleport Denied, Invalid Unit <--')
  76.                         end
  77.                 else
  78.                         ShowMouseText(self, '--> Teleport Denied, Invalid Destination <--')
  79.                 end
  80.         end,
  81.                
  82.         InitializeTeleportToDestination = function(self)
  83.                 local bp = self:GetBlueprint().Economy
  84.                 local MyCats = bp.Categories or {}
  85.                 local TeleportParams = self:GetCustomIntelParams('TeleportMove') or self:GetCustomIntelParams('TeleportMoveField') or {}
  86.                 local ExcludedCats = TeleportParams.ExcludeCats
  87.                 local IsUnitExcluded = false
  88.                
  89.                 --before we go further we need to check this..
  90.                
  91.                 for id, Cat in MyCats do
  92.                         if table.find(ExcludedCats, Cat) then
  93.                                 IsUnitExcluded = true
  94.                                 break
  95.                         end
  96.                 end
  97.                
  98.                 if IsUnitExcluded then
  99.                         ShowMouseText(self, '--> Teleport Denied, Unit Cannot Be Teleported <--' )
  100.                         return
  101.                 end
  102.                
  103.                 if self:HasThread('WaitForTeleportMoveReady') then
  104.                         self:RemoveUnitThread('WaitForTeleportMoveReady')
  105.                 end
  106.                
  107.                 --here we go...
  108.                 local CanTeleport = false
  109.                 local EnoughEnergy = false
  110.                 local InRange = false
  111.                 local CoolDownTime = TeleportParams.CoolDownTime or false
  112.                 local FreeEnergy = self:Get_Econ('FreeEnergy')
  113.                 local energyCost = self:GetUnitParam('TeleportEnergyCost') or bp.BuildCostEnergy or 0 * (self:GetUnitParam('TeleportEnergyMod') or bp.TeleportEnergyMod or 0.3)
  114.                 local MyPos = table.deepcopy(self:GetPosition())
  115.                 local Destination = self:GetNavigator():GetGoalPos()
  116.                 local CurrDistance = VDist3(MyPos, Destination)
  117.                 local MaxDistance = TeleportParams.MaxDistance or CurrDistance + 2
  118.                 local FreeTeleport = TeleportParams.FreeTeleport or false
  119.                 local ValidDestination = import('/lua/AI/aiutilities.lua').CheckUnitPathingEx(Destination, MyPos, self)
  120.                 local InAntiTeleportField = self:IsInField('AntiTeleportField')
  121.                 local DesNotInAntiTeleportField = self:CheckDestinationForAntiTeleport(Destination)
  122.                 local Orientation = table.deepcopy(self:GetOrientation())
  123.                 local CoolDownStatus = self:GetUnitParam('TeleportCoolDownStatus') or false
  124.                                
  125.                 if self:GetUnitParam('TeleportCoolDownProgress') != nil then
  126.                         if CoolDownTime then
  127.                                 if type(CoolDownTime) == 'number' and CoolDownTime > 0 then
  128.                                         if not self:HasThread('TeleportCoolDownTimer') and not CoolDownStatus then
  129.                                                 local CoolDownParams = { CoolDownTime = CoolDownTime }
  130.                                                 self:AddUnitThread('TeleportCoolDownTimer', CoolDownParams)
  131.                                         end
  132.                                        
  133.                                         if not CoolDownStatus then
  134.                                                 return
  135.                                         end
  136.                                 else
  137.                                         CoolDownStatus = true
  138.                                 end
  139.                         else
  140.                                 CoolDownStatus = true          
  141.                         end
  142.                 else
  143.                         self:SetUnitParam('TeleportCoolDownProgress', 0)
  144.                         CoolDownStatus = true
  145.                 end
  146.                
  147.                 if FreeTeleport then
  148.                         energyCost = 0
  149.                 end
  150.                                        
  151.                 if FreeEnergy >= energyCost then
  152.                         EnoughEnergy = true
  153.                 else
  154.                         ShowMouseText(self, '--> Teleport Denied, Energy Required ' .. energyCost .. ' <--')
  155.                 end
  156.                
  157.                 if CurrDistance <= MaxDistance then
  158.                         InRange = true
  159.                 else
  160.                         ShowMouseText(self, '--> Teleport Denied, Moving InTo TeleportRange <--')
  161.                 end
  162.                
  163.                 if InAntiTeleportField then
  164.                         ShowMouseText(self, '--> Teleport Denied, Scrambled <--')
  165.                 end
  166.                
  167.                 if not DesNotInAntiTeleportField then
  168.                         ShowMouseText(self, '--> Teleport Denied, Destination Scrambled <--')
  169.                 end
  170.                
  171.                 if MaxDistance == 0 then
  172.                         InRange = true
  173.                 end
  174.                
  175.                 if InRange and EnoughEnergy and ValidDestination and not InAntiTeleportField and DesNotInAntiTeleportField and CoolDownStatus then
  176.                         CanTeleport = true                     
  177.                 end
  178.                                
  179.                 if CanTeleport then
  180.                         if not self:HasThread('TeleportUnitToDestination') then
  181.                                 local Params = { energyCost = energyCost, Destination = Destination, CurrPos = MyPos, Orientation = Orientation, CoolDownTime = CoolDownTime, ExcludedCats = ExcludedCats }
  182.                                 self:AddUnitThread('TeleportUnitToDestination', Params)
  183.                         end
  184.                 else
  185.                         if not self:HasThread('WaitForTeleportMoveReady') then
  186.                                 local Params = { energyCost = energyCost, maxDistance = MaxDistance, CurrPos = MyPos, Orientation = Orientation, CoolDownTime = CoolDownTime, ExcludedCats = ExcludedCats }
  187.                                 --self:AddUnitThread('WaitForTeleportMoveReady', Params)
  188.                         end
  189.                 end
  190.         end,
  191.                
  192.         TeleportCoolDownTimer = function(self, Params)
  193.                 local CurrProgress = self:GetUnitParam('TeleportCoolDownProgress') or 0
  194.                 local CoolDownTime = Params.CoolDownTime or 0
  195.                
  196.                 if CoolDownTime == 0 then
  197.                         self:SetUnitParam('TeleportCoolDownStatus', true)
  198.                         if self:GetMotionStatus() != 'Stopped' then
  199.                                 self:TeleportToDestination()
  200.                         end
  201.                 else
  202.                         --the charge doesnt cost energy because the unit should already be using a consumption..
  203.                         while CurrProgress <= CoolDownTime do
  204.                                 CurrProgress = CurrProgress + 1
  205.                                 self:SetUnitParam('TeleportCoolDownProgress', CurrProgress)
  206.                                 WaitSeconds(1)
  207.                         end
  208.                        
  209.                         if CurrProgress >= CoolDownTime then
  210.                                 self:SetUnitParam('TeleportCoolDownStatus', true)
  211.                                 self:SetUnitParam('TeleportCoolDownProgress', 0)
  212.                                
  213.                                 if self:GetMotionStatus() != 'Stopped' then
  214.                                         self:TeleportToDestination()
  215.                                 end
  216.                         end
  217.                 end
  218.                
  219.                 self:RemoveUnitThread('TeleportCoolDownTimer')
  220.         end,
  221.        
  222.         TeleportUnitToDestination = function(self, Params)
  223.                 self:SetIsBeingTeleported(true)
  224.                 if self:UnitHasRallyPoint() then
  225.                         self:HideUnitRallyPointsWhenMoving()
  226.                 end
  227.                
  228.                 local aiBrain = self:GetAIBrain()
  229.                 aiBrain:TakeResource( 'ENERGY', Params.energyCost or 0 )
  230.                 WaitTicks(2)
  231.                 self:SetUnitHidden(true)
  232.  
  233.                 local Destination = Params.Destination
  234.                 local Orientation = Params.Orientation
  235.                 local TeleportParams = self:GetCustomIntelParams('TeleportMove') or self:GetCustomIntelParams('TeleportMoveField')
  236.                 local CoolDownTime = Params.CoolDownTime
  237.                
  238.                
  239.                 --Default Pods
  240.                 local HasPod = false
  241.                 local LeftPod = false
  242.                 local RightPod = false
  243.                
  244.                 if EntityCategoryContains(categories.PODSTAGINGPLATFORM, self) then
  245.                         if self.HasLeftPod then
  246.                                 LeftPod = self.LeftPod
  247.                                 HasPod = true
  248.                         end
  249.                        
  250.                         if self.HasRightPod then
  251.                                 RightPod = self.RightPod
  252.                                 HasPod = true
  253.                         end
  254.                 end
  255.                                        
  256.                 self:PlayTeleportMoveOutEffects()
  257.                 Warp(self, Destination, Orientation)
  258.                 self:SetUnitParam('TeleportCoolDownStatus', false)
  259.                
  260.                 if TeleportParams.HasField then
  261.                         if not self:HasThread('TeleportUnitsInRange') then
  262.                                 local UnitsInRangeParams = { Destination = Destination, Pos = Params.CurrPos, FreeTeleport = TeleportParams.FreeTeleport or false, Orientation = Params.Orientation, ExcludedCats = Params.ExcludedCats  }
  263.                                 self:AddUnitThread('TeleportUnitsInRange', UnitsInRangeParams)
  264.                         end
  265.                 end
  266.                
  267.                 if HasPod then                 
  268.                         if LeftPod then
  269.                                 IssueClearCommands( { LeftPod } )
  270.                                 LeftPod:SetUnitHidden(true)
  271.                                 Warp(LeftPod, Destination, Orientation)
  272.                         end
  273.                        
  274.                         if RightPod then
  275.                                 IssueClearCommands( { RightPod } )
  276.                                 RightPod:SetUnitHidden(true)
  277.                                 Warp(RightPod, Destination, Orientation)
  278.                         end
  279.                 end
  280.                
  281.                 WaitTicks(2)
  282.                 self:PlayTeleportMoveInEffects()
  283.                
  284.                 WaitSeconds(.3)
  285.                 self:GetNavigator():AbortMove()
  286.                
  287.                 self:SetUnitHidden(false)
  288.                 self:RemoveUnitThread('TeleportCoolDownTimer')
  289.                 self:DestroyMovementEffects()
  290.                 self:SetIsBeingTeleported(false)
  291.                
  292.                 if HasPod then                 
  293.                         if LeftPod then
  294.                                 LeftPod:SetUnitHidden(false)
  295.                         end
  296.                        
  297.                         if RightPod then
  298.                                 RightPod:SetUnitHidden(false)
  299.                         end
  300.                 end
  301.                
  302.                 if self:UnitHasRallyPoint() then
  303.                         self:ShowUnitRallyPointsWhenStopped()
  304.                 end
  305.                                
  306.                 if CoolDownTime then
  307.                         if type(CoolDownTime) == 'number' and CoolDownTime > 0 then
  308.                                 if not self:HasThread('TeleportCoolDownTimer') then
  309.                                         local CoolDownParams = { CoolDownTime = CoolDownTime }
  310.                                         self:AddUnitThread('TeleportCoolDownTimer', CoolDownParams)
  311.                                 end
  312.                         end
  313.                 end
  314.                
  315.                 self:RemoveUnitThread('TeleportUnitToDestination')
  316.                 self:RemoveUnitThread('WaitForTeleportMoveReady')
  317.         end,
  318.        
  319.         --we have this run all the time if we cant teleport, just in case the destination changes...
  320.         --saves doing alot of coding work with the orders...
  321.         --not currently used.
  322.         WaitForTeleportMoveReady = function(self, Params)
  323.                 local CanTeleport = false
  324.                 local Destination = self:GetNavigator():GetGoalPos()
  325.                
  326.                 while not self:IsDead() and not CanTeleport do
  327.                         local MyPos = self:GetPosition()
  328.                         Destination = self:GetNavigator():GetGoalPos()
  329.                         local CurrDistance = VDist3(MyPos, Destination)
  330.                         local MaxDistance = Params.maxDistance or CurrDistance + 2
  331.                         local FreeEnergy = self:Get_Econ('FreeEnergy')
  332.                         local ValidDestination = import('/lua/AI/aiutilities.lua').CheckUnitPathingEx(Destination, MyPos, self)
  333.                         local DesNotInAntiTeleportField = self:CheckDestinationForAntiTeleport(Destination)
  334.                         local InAntiTeleportField = self:IsInField('AntiTeleportField')
  335.                        
  336.                         if FreeEnergy >= Params.energyCost and CurrDistance <= MaxDistance and ValidDestination and not InAntiTeleportField and DesNotInAntiTeleportField then
  337.                                 CanTeleport = true
  338.                         end
  339.                                                
  340.                         WaitTicks(5)
  341.                 end
  342.        
  343.                 if CanTeleport then
  344.                         Params.Destination = Destination
  345.                         self:AddUnitThread('TeleportUnitToDestination', Params)
  346.                         self:RemoveUnitThread('WaitForTeleportMoveReady')
  347.                 end
  348.         end,
  349.        
  350.         CheckDestinationForAntiTeleport = function(self, Destination)
  351.                 local ValidDestination = true
  352.                 for num, brain in ArmyBrains do
  353.                         if brain:GetArmyIndex() != self:GetArmy() then
  354.                                 local units = brain:GetIntelTypeUnits('AntiTeleportField')
  355.                                 for id, unit in units do
  356.                                         if unit and not unit:IsDead() or not unit:BeenDestroyed() and IsEnemy(self:GetArmy(), unit:GetArmy()) then
  357.                                                 if unit:HasCustomIntelType('AntiTeleportField') and unit:IsIntelEnabled('AntiTeleportField') then
  358.                                                                                
  359.                                                         local AntiTeleportParams = unit:GetCustomIntelParams('AntiTeleportField')
  360.                                                         local AntiTeleRadius = AntiTeleportParams.Radius
  361.                                                         local UnitPos = unit:GetPosition()
  362.                                                         local GenDistToDest = VDist2(Destination[1], Destination[3], UnitPos[1], UnitPos[3])
  363.                                                                                                                                                
  364.                                                         if GenDistToDest < AntiTeleRadius  then
  365.                                                                 ValidDestination = false
  366.                                                                 break
  367.                                                         end
  368.                                                 end
  369.                                
  370.                                         end
  371.                                 end
  372.                                
  373.                                 if not ValidDestination then break end
  374.                         end
  375.                 end
  376.                
  377.                 return ValidDestination
  378.         end,
  379.        
  380.         GetDefaultTeleportMoveParams = function(self, Type)
  381.                 local spec = {}
  382.                 local Type = Type or 'single'
  383.                
  384.                 if Type != 'field' then
  385.                         spec = {
  386.                                 MaintenanceConsumptionPerSecondEnergy = 75,
  387.                                 WatchPower = true,
  388.                                 AddToggles = true,
  389.                                 Toggles = { RULEETC_TeleportMoveToggle = { StartEnabled = false } },
  390.                                 EnabledOnTransport = false,
  391.                                
  392.                                 MaxDistance = 20,
  393.                                 MinDistance = 5,
  394.                                 FreeTeleport = true,
  395.                                 CoolDownTime = 15,
  396.                                
  397.                                 ExcludeCats = {'POD', 'HOLOGRAM', 'STRUCTURE', 'WALL', 'IMMOBILE' },
  398.                                 ExcludeUnitIds = {},
  399.                         }
  400.                 else
  401.                         spec = {
  402.                                 MaintenanceConsumptionPerSecondEnergy = 10,
  403.                                 WatchPower = true,
  404.                                 AddToggles = true,
  405.                                 Toggles = { RULEETC_TeleportMoveFieldToggle = { StartEnabled = false } },
  406.                                 EnabledOnTransport = false,
  407.                                
  408.                                 MaxDistance = 200,
  409.                                 MinDistance = 5,
  410.                                 FreeTeleport = true,
  411.                                 CoolDownTime = 5,
  412.                                
  413.                                 HasField = true,
  414.                                 Radius = 20,
  415.                                 FieldEffects = 'AlliedUnits',
  416.                                 IncludeGenerator = false,
  417.                                
  418.                                 ExcludeCats = {'POD', 'HOLOGRAM', 'STRUCTURE', 'WALL', 'IMMOBILE'},
  419.                                 ExcludeUnitIds = {},
  420.                         }
  421.                 end
  422.                
  423.                 return spec
  424.         end,
  425.        
  426.         --id love to shoot off a projectile with trail from the unit before it telports.. to the destination..
  427.         --that would be a cool effect.. however im not to sure how to make that happen... (yet)
  428.         PlayTeleportMoveOutEffects = function(self)
  429.                 local army = self:GetArmy()
  430.                                
  431.                 explosion.CreateFlash( self, -1, explosion.GetAverageBoundingXZRadius(self), army )
  432.                 self:PlayUnitSound('GateOut')
  433.         end,
  434.        
  435.         PlayTeleportMoveInEffects = function(self)             
  436.                 local TeleportInEffects = {
  437.                         '/effects/emitters/generic_teleportin_01_emit.bp',
  438.                         '/effects/emitters/generic_teleportin_02_emit.bp',
  439.                         '/effects/emitters/generic_teleportin_03_emit.bp',
  440.                 }
  441.                
  442.                 local bp = self:GetBlueprint()
  443.                 local army = self:GetArmy()
  444.                 local UnitRadius = explosion.GetAverageBoundingXZRadius(self)
  445.                
  446.                 --explosion.CreateFlash( self, -1, UnitRadius, army )
  447.         for k, v in TeleportInEffects do
  448.             emit = CreateEmitterAtEntity(self,army,v):ScaleEmitter((UnitRadius or 1) * 2):OffsetEmitter(0, (bp.Physics.MeshExtentsY or 1) / 2, 0)
  449.         end
  450.                
  451.                 self:PlayUnitSound('GateIn')
  452.         end,
  453.        
  454.         --Teleport Move Field
  455.                
  456.         CreateTeleportMoveFieldEnhancement = function(self, spec)
  457.                 if not spec or table.getsize(spec) == 0 then
  458.                         spec = self:GetDefaultTeleportMoveParams('field')
  459.                 end
  460.                 self:AddCustomUnitIntel('TeleportMoveField', spec)     
  461.         end,
  462.        
  463.         RemoveTeleportMoveFieldEnhancement = function(self)
  464.                 self:RemoveCustomUnitIntel('TeleportMoveField')
  465.         end,
  466.                
  467.         TeleportUnitsInRange = function(self, Params)
  468.                 local FieldUnits = GetIntelFieldUnits(self, 'TeleportMoveField')
  469.                 if table.getsize(FieldUnits) > 0 then
  470.                         for id, unit in FieldUnits do
  471.                                 if not table.equal(unit, self) then
  472.                                         local Destination = unit:CalculateTeleportPosition(Params.Pos, Params.Destination)
  473.                                         local TeleParams = { Destination = Destination, FreeTeleport = Params.FreeTeleport, Orientation = Params.Orientation, ExcludedCats = Params.ExcludedCats }
  474.                                         unit:AddUnitThread('TeleportUnitToDestinationInField', TeleParams)
  475.                                 end
  476.                         end
  477.                 end
  478.        
  479.                 self:RemoveUnitThread('TeleportUnitsInRange')
  480.         end,
  481.        
  482.         TeleportUnitToDestinationInField = function(self, Params)
  483.                
  484.                 local bp = self:GetBlueprint().Economy
  485.                 local MyCats = bp.Categories or {}
  486.                 local ExcludedCats = Params.ExcludeCats
  487.                 local FreeEnergy = self:Get_Econ('FreeEnergy')
  488.                 local energyCost = self:GetUnitParam('TeleportEnergyCost') or bp.BuildCostEnergy or 0 * (self:GetUnitParam('TeleportEnergyMod') or bp.TeleportEnergyMod or 0.3)
  489.                 local Destination = Params.Destination
  490.                 local MyPos = self:GetPosition()
  491.                 local CanTeleport = false
  492.                 local EnoughEnergy = false
  493.                 local ValidUnit = false
  494.                 local ValidDestination = import('/lua/AI/aiutilities.lua').CheckUnitPathingEx(Destination, MyPos, self)
  495.                 local DesNotInAntiTeleportField = self:CheckDestinationForAntiTeleport(Destination)
  496.                 local InAntiTeleportField = self:IsInField('AntiTeleportField')
  497.                 local TeleportIntelEnabled = false
  498.                 local Orientation = Params.Orientation
  499.                 local IsUnitExcluded = false
  500.                
  501.                 --before we go further we need to check this..
  502.                 for id, Cat in MyCats do
  503.                         if table.find(ExcludedCats, Cat) then
  504.                                 IsUnitExcluded = true
  505.                                 break
  506.                         end
  507.                 end
  508.                
  509.                 if IsUnitExcluded then
  510.                         return
  511.                 end
  512.                
  513.                 --here we go
  514.                 if Params.FreeTeleport then
  515.                         energyCost = 0
  516.                 end
  517.                
  518.                 if FreeEnergy >= energyCost then
  519.                         EnoughEnergy = true
  520.                 end
  521.                
  522.                 --put this in blueprints add the category to all structures, walls, immobile, pods,
  523.                 if not EntityCategoryContains(categories.CANNOTTELEPORT, self) then
  524.                         ValidUnit = true
  525.                 end
  526.                
  527.                 if self:HasCustomIntelType('TeleportMove') and self:IsIntelEnabled('TeleportMove') then
  528.                         TeleportIntelEnabled = true
  529.                 end
  530.                
  531.                 if self:HasCustomIntelType('TeleportMoveField') and self:IsIntelEnabled('TeleportMoveField') then
  532.                         TeleportIntelEnabled = true
  533.                 end
  534.                
  535.                 if EnoughEnergy and ValidUnit and ValidDestination and not InAntiTeleportField and DesNotInAntiTeleportField and not TeleportIntelEnabled then
  536.                         CanTeleport = true
  537.                 end
  538.                
  539.                 if CanTeleport then
  540.                         self:SetIsBeingTeleported(true)
  541.                         if self:UnitHasRallyPoint() then
  542.                                 self:HideUnitRallyPointsWhenMoving()
  543.                         end
  544.                         WaitTicks(Random(3, 25))
  545.                         local aiBrain = self:GetAIBrain()
  546.                         aiBrain:TakeResource( 'ENERGY', energyCost or 0 )
  547.                         WaitTicks(2)
  548.                         self:SetUnitHidden(true)
  549.                        
  550.                         self:PlayTeleportMoveOutEffects()
  551.                         Warp(self, Destination, Orientation)
  552.                                                
  553.                         WaitTicks(2)
  554.                         self:PlayTeleportMoveInEffects()
  555.                        
  556.                         WaitSeconds(.3)
  557.                         self:GetNavigator():AbortMove()
  558.                         self:DestroyMovementEffects()
  559.                         self:SetUnitHidden(false)
  560.                         self:SetIsBeingTeleported(false)
  561.                        
  562.                         if self:UnitHasRallyPoint() then
  563.                                 self:ShowUnitRallyPointsWhenStopped()
  564.                         end
  565.                        
  566.                         self:RemoveUnitThread('TeleportUnitToDestinationInField')
  567.                 else
  568.                         self:RemoveUnitThread('TeleportUnitToDestinationInField')
  569.                 end
  570.         end,
  571.        
  572.         CalculateTeleportPosition = function(self, Pos, Destination)
  573.                 local MyPosX, MyPosY, MyPosZ = unpack(self:GetPosition())
  574.                 local PosX, PosY, PosZ = unpack(Pos)
  575.  
  576.                 local DifX = PosX - MyPosX
  577.                 local DifY = PosY - MyPosY
  578.                 local DifZ = PosZ - MyPosZ
  579.                                
  580.                 local DesX, DesY, DesZ = unpack(Destination)
  581.                 DesX = DesX - DifX
  582.                 DesY = DesY - DifY
  583.                 DesZ = DesZ - DifZ
  584.                                                
  585.                 return Vector(DesX, DesY, DesZ)
  586.         end,
  587.                
  588.         ##########################################################################################
  589.     ## --Anti Teleport Field
  590.     ##########################################################################################
  591.        
  592.         CreateAntiTeleportFieldEnhancement = function(self, spec)
  593.                 if not spec or table.getsize(spec) == 0 then
  594.                         spec = self:GetDefaultAntiTeleportParams()
  595.                 end
  596.                 self:AddCustomUnitIntel('AntiTeleportField', spec)     
  597.         end,
  598.        
  599.         RemoveAntiTeleportFieldEnhancement = function(self)
  600.                 self:RemoveCustomUnitIntel('AntiTeleportField')
  601.         end,
  602.        
  603.         SetUnitInAntiTeleportField = function(self, generator, param)
  604.                 if param then
  605.                        
  606.                 elseif not param then
  607.                        
  608.                 end
  609.         end,
  610.        
  611.         SetAntiTeleportFieldStatus = function(self, Param, intelType)
  612.                 if Param and not self:GetUnitParam('AntiTeleportFieldEnabled') then
  613.                         self:SetUnitParam('AntiTeleportFieldEnabled', true)
  614.                         local MyBrain = self:GetAIBrain()
  615.                         MyBrain:SetAntiTeleportUnit(self, true)
  616.                 elseif not Param and self:GetUnitParam('AntiTeleportFieldEnabled') then
  617.                         self:SetUnitParam('AntiTeleportFieldEnabled', nil)
  618.                         local MyBrain = self:GetAIBrain()
  619.                         MyBrain:SetAntiTeleportUnit(self, false)
  620.                 end    
  621.         end,
  622.        
  623.         GetDefaultAntiTeleportParams = function(self)
  624.                 spec = {
  625.                         MaintenanceConsumptionPerSecondEnergy = 10,
  626.                         WatchPower = true,
  627.                         AddToggles = true,
  628.                         Toggles = { RULEETC_AntiTeleportFieldToggle = { StartEnabled = true } },
  629.                         EnabledOnTransport = false,
  630.                                                                
  631.                         HasField = true,
  632.                         Radius = 20,
  633.                         FieldEffects = 'EnemyUnits',
  634.                                
  635.                         ExcludeCats = {},
  636.                         ExcludeUnitIds = {},
  637.                 }
  638.                
  639.                 return spec
  640.         end,