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.
I had a eureka moment as well. Here is my code which is very fast (just some seconds.)
function get_valuable_ fields( ) caps("small" ) then
local index = fg.x * 1000 + fg.y
fields[ index] = fg caps("medium" ) then
local index = fg.x * 1000 + fg.y
fields[ index] = fg caps("big" ) then
local index = fg.x * 1000 + fg.y
fields[ index] = fg insert( result, f)
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_
local radius = f:region(6)
for idx, fg in ipairs(radius) do
end
elseif f:has_max_
local radius = f:region(8)
for idx, fg in ipairs(radius) do
end
elseif f:has_max_
local radius = f:region(12)
for idx, fg in ipairs(radius) do
end
end
end
end
local result = {}
for idx,f in pairs(fields) do
table.
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.