Advertisement
Guest User

Mutant Gangland - Select unit to attack

a guest
Oct 12th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. function harrold:_selectEnemyToEngage(_v)
  2.     local v = _v
  3.    
  4.     local score = 0
  5.     local scoutScore = 0
  6.     local posX, posY = nil, nil
  7.     local targetID = nil
  8.     for i,j in ipairs(unit:_returnTable()) do
  9.         local un = j
  10.         if j.team ~= unit:_returnTurn() then
  11.             local bool, threat, bid = self:isEnemyNearOneOfOurBuildings(j)
  12.  
  13.             local moveScore = 0
  14.             local path, length = pather:getPath(v.x, v.y, un.x, un.y)
  15.             local bunitScore = self:scoreUnit(v)
  16.             local targUnScore = self:scoreUnit(un)
  17.             if path ~= nil then
  18.                 local modifier = 0
  19.                 if bool == true then
  20.                     local extraMode = 0
  21.                     if bid ~= nil then
  22.                         local bld = building:_returnBuildingTable()[bid]
  23.                         -- get my own distance to the
  24.                         local distCheck = math.dist(v.x, v.y, bld.x, bld.y)
  25.                         if distCheck < v.range then
  26.                             extraMode = 18 - distCheck*2
  27.                         end
  28.                         if length < 4 then
  29.                             extraMode = extraMode + 500
  30.                         end
  31.                     end
  32.                     if threat == 1 then
  33.                         if j.tp == 1 or j.tp == 2 then
  34.                             modifier = 225 + extraMode
  35.                         else
  36.                             modifier = 125 + extraMode
  37.                         end
  38.                     else
  39.                         modifier = 20
  40.                     end
  41.                 end
  42.                 local freeSpotModifier = 0
  43.                 local mcX, mcY = self:findFreeSpot(j.x, j.y, v.attack_range)
  44.                 if mcX ~= nil and mcy ~= nil then
  45.                     freeSpotModifier = - 200
  46.                 else
  47.                     freeSpotModifier = 40
  48.                 end
  49.                 moveScore = moveScore + (30 - length) + modifier + (20 ) + freeSpotModifier
  50.                 if moveScore > score then
  51.                     posX, posY = un.x, un.y
  52.                     score = moveScore
  53.                     targetID = i
  54.                 end
  55.             else
  56.                 --print("NIL FUCKERE")
  57.             end
  58.         end
  59.     end
  60.  
  61.     v.goal_x = posX
  62.     v.goal_y = posY
  63.     v.rival = i
  64.     if v.goal_x == nil and v.goal_y == nil then
  65.         --print("FIND FREE LOCATION")
  66.         v.goal_x, v.goal_y = self:_findFreeLocation(v)
  67.     end
  68.        
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement