← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

 

I had a eureka moment as well. Here is my code which is very fast (just some seconds.)

function get_valuable_fields()
   local fields = {}
   local map = wl.Game().map
   for x=0, map.width-1 do
      for y=0, map.height-1 do
         local f = map:get_field(x,y)
         if f:has_max_caps("small") then
            local radius = f:region(6)
            for idx, fg in ipairs(radius) do
               local index = fg.x * 1000 + fg.y
               fields[index] = fg
            end
         elseif f:has_max_caps("medium") then
            local radius = f:region(8)
            for idx, fg in ipairs(radius) do
               local index = fg.x * 1000 + fg.y
               fields[index] = fg
            end
         elseif f:has_max_caps("big") then
            local radius = f:region(12)
            for idx, fg in ipairs(radius) do
               local index = fg.x * 1000 + fg.y
               fields[index] = fg
            end
         end
      end
   end
   local result = {}
   for idx,f in pairs(fields) do
      table.insert(result, f)
   end
   return result
end


of course we could discuss about the size of the regions. I will go through the lua files of all military buildings to see what might be good values. 
-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.


References