Advertisement
Guest User

Mutant Gangland - Score location for Buildings

a guest
Oct 12th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. function harrold:scoreBuildingBasedOnProximity(_v)
  2.     local v = _v
  3.     local score = 0
  4.     local posX = nil
  5.     local posY = nil
  6.     --Game:updatePathfinding( )
  7.     for i,j in ipairs(building:_returnBuildingTable()) do
  8.         local bld = j
  9.  
  10.         --if j.point > 0 then --not our team
  11.         if bld.team ~= unit:_returnTurn() and unit:isLocEmpty(bld.x, bld.y) == nil and bld.x ~= v.x and bld.y ~= v.y then  
  12.              
  13.  
  14.            
  15.             local path, length = pather:getPath(v.x, v.y, bld.x, bld.y)
  16.             if path ~= nil then -- make sure there's a path to that building
  17.                 local bool = false
  18.                 for k, l in ipairs(unit:_returnTable() ) do
  19.                     if l.tp == 1 or l.tp == 2 and l.team == v.team then
  20.                         local distCheck = math.dist(l.x, l.y, bld.x, bld.y)
  21.                         if length < 2 then
  22.                             bool = true
  23.                         end
  24.                     end
  25.                 end
  26.  
  27.                 local moveScore = 0
  28.                 local modifier = 0
  29.                 if bool == true then
  30.                     modifier = 8
  31.                 end
  32.  
  33.                 moveScore = moveScore + (9 - bld._type*2) + (30 - length) - modifier -- more focus on buildings that create units
  34.                 if moveScore > score then
  35.                     posX = bld.x
  36.                     posY = bld.y
  37.                     score = moveScore
  38.                 end
  39.             else
  40.                 --print("VX: "..v.x.." | VY: "..v.y.." BX: "..bld.x.." BY: "..bld.y.."")
  41.                 --print("NIL NIL NIL IN SCORE BUILDING")
  42.             end
  43.  
  44.         end
  45.     end
  46.  
  47.     -- now we add our final positions to a list. This way, we'll make sure we didn't target the building before
  48.     v.goal_x = posX
  49.     v.goal_y = posY
  50.  
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement