--[[nef_20221122 NEAREST This utility can be used to quickly identify all cities that are candidates to become the 'owner' of units that belonged to the indicated city if it was disbanded. Special reporting is used to facilitate opening the city DB`s. The argument is the city that could be disbanded. (Userdata or featured text link) Module requires the FEATURED_TEXT, PARSER and SUPPORT_extended. ]] do -- NEAREST -- SOH local featured = setmetatable({},{ -- FEATURED_TEXT __index = function(t,k) local ft = assert(log.featured, 'Featured text not loaded') return assert(ft[k], 'Featured '..k..' not loaded.' ) end;}) local function color (...) color = featured.color; return color (...) end local function link (...) link = featured.link; return link (...) end local function bbcode(...) bbcode = featured.bbcode; return bbcode (...) end local SP = setmetatable({},{ -- SUPPORT_basic __index = function(t,k) local SP = assert(game.SP, 'Support package not loaded') return assert(SP[k], 'Support '..k..' not loaded.') end;}) local function user (...) user = SP.user; return user (...) end local function background(...) background = SP.background; return background (...) end local function colored_link(...) colored_link = SP.colored_link; return colored_link(...) end -- SUPPORT_extended local function get_link_bb(...) get_link_bb = SP.get_link_bb; return get_link_bb (...) end -- STX local report = function(tile,...) if chat then chat.msg(...) log.normal(...) else notify.event(user(),tile,E.BROADCAST_REPORT,...) end end local report2 = function(tile,...) if chat then chat.msg(...) log.normal(...) else notify.event(user(),tile,E.TECH_LOST,...) end end -- Tile (Tile):square_iterate (number (chebyshev radius) ) -- number (Player):num_cities () function nearest(city); city = get_link_bb(city) if tolua.type(city) ~= 'City' then return report(nil, 'Argument not a city reference') end; local player, city_tile = city.owner, city.tile if player:num_cities() == 1 then report(city_tile, colored_link(city,'No other cities')) else report(city_tile, color(link(city,'Nearest cities to '..(city.name)),nil,background(city))) local distance = 0 repeat distance = distance + 1 for tile in city_tile:square_iterate (distance) do local city = tile:city() if tile ~= city_tile and city and city.owner == player then report2(tile,colored_link(city) ); distance = -1 end end until distance < 0 end end --ETX end -------- end NEAREST