--[[nef_20221122 HOME This utility can be used for two purposes: A. When provided with a unit, it will identify the home city. B. When provided with a city, it will list all owned units. The list will provide featured text 'hot links' to those units not in the city. In both cases the argument can be userdata or featured text. Requires FEATURED_TEXT, PARSER, SUPPORT_extended. ]] do -- HOME -- 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 ftext (...) ftext = featured.ftext; return ftext (...) 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 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 function home(object,option) object = get_link_bb(object) if tolua.type(object) == 'Tile' then if object:num_units() == 1 then local f,s,k = object:units_iterate(); object = f(s,k) else object = nil end end local Type = tolua.type(object) if false then elseif object and object.owner and object.owner ~= user() then report(object.tile,'Foreign city or unit.' ) elseif Type == 'Unit' then local homecity = object:get_homecity() if homecity then report (homecity.tile,colored_link(homecity)) else report (object.tile,colored_link(object,'Unit unhomed.')) end elseif Type == 'City' then local tile = object.tile local function p_report(...); p_report = report; p_report(nil, bbcode ("b","Owned units")); p_report(...) end for unit in object.owner:units_iterate() do if unit:get_homecity () == object then p_report (unit.tile, (unit.tile == tile and ftext or colored_link)(unit)) end end; if p_report ~= report then report(nil, "No owned units") end else report(nil, 'Select a unit or city.') end end --ETX end -------- end HOME