2015-04-30 15:22:06 +02:00
|
|
|
local this = {}
|
|
|
|
|
|
|
|
local function score(r, res)
|
|
|
|
assert(r)
|
|
|
|
res = res or "peasant"
|
|
|
|
local x, y, rn
|
|
|
|
local peas = r:get_resource(res)
|
|
|
|
for _, rn in pairs(r.adj) do
|
2015-07-04 23:42:41 +02:00
|
|
|
if rn and not rn.units() then
|
2015-04-30 15:22:06 +02:00
|
|
|
peas = peas + rn:get_resource(res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return peas
|
|
|
|
end
|
|
|
|
|
|
|
|
local function select(regions, limit)
|
|
|
|
local sel = {}
|
|
|
|
for r in regions do
|
2015-07-04 23:42:41 +02:00
|
|
|
if r.terrain~="ocean" and not r.units() then
|
2015-04-30 15:22:06 +02:00
|
|
|
s = score(r)
|
|
|
|
if s >= limit then
|
|
|
|
table.insert(sel, r)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return sel
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
score = score,
|
|
|
|
select = select
|
|
|
|
}
|