--nef_20230307 do -- DEMO -- SOH local function min_path(...) min_path = assert(game.min_path,'minpath not loaded.'); return min_path(...) end 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 ftext (...) ftext = featured.ftext; return ftext (...) 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 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 wrap, type = coroutine.wrap, tolua.type local path_demo = { -- destination and city added by demo() -- boolean (Tile):has_extra (string (rule_name)) edger = function (_ENV, distance, tile, neighbour) if false then elseif neighbour:has_extra('railroad') then return 10 elseif neighbour:has_extra('road') then return 12 end end; -- City (Tile):city () terminator = function (_ENV, distance, tile) city = tile:city (); return (tile == destination or not destination and city) and distance end; } -- Tile (City).tile function demo(city1,city2,mc) city1 = get_link_bb(city1); city2 = get_link_bb(city2) assert(type(city1) == 'City','Arg. 1 must be a city' ) mc = type(mc) == 'number' and mc > 0 and mc or 1 local _ENV, path, iterate = path_demo destination = type(city2) == 'City' and city2.tile for i = 1, mc do local co = wrap(min_path) repeat city = nil; path, iterate = co (_ENV, city1.tile) if mc == i and (destination or city) then report(nil, (path and 'Path length = '..path or 'No path').. ' from city ' ..ftext(city1).. ' to ' ..colored_link(city2 or city) .. '' ) end until destination or not path end if destination and path then do report(destination, colored_link(destination)..' ('..path..')'); end for destination, path in iterate(destination) do report(destination, colored_link(destination)..' ('..path..')'); end end end -- EOT end ------------ end DEMO