diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index 5292d227b..1ff4af8b3 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -33,9 +33,45 @@ local language_name_types = { [df.language_name_type.SymbolFood] = 'Inn Tavern', [df.language_name_type.Temple] = 'Temple', [df.language_name_type.Hospital] = 'Hospital', - [df.language_name_type.Guildhall] = 'Guildhall' + [df.language_name_type.Guildhall] = 'Guildhall', + [df.language_name_type.Library] = 'Library' } +local function add_spheres(hf, spheres) + if not hf then return end + for _, sphere in ipairs(hf.info.spheres.spheres) do + spheres[sphere] = true + end +end + +local function stringify_spheres(spheres) + local strs = {} + for sphere in pairs(spheres) do + table.insert(strs, df.sphere_type[sphere]) + end + return table.concat(strs, ' ') +end + +local function get_religion_string(religion_id, religion_type) + if religion_id == -1 then return '' end + if religion_type == -1 then return 'Temple' end + local entity + local spheres = {} + if religion_type == 0 then + entity = df.historical_figure.find(religion_id) + add_spheres(entity, spheres) + elseif religion_type == 1 then + entity = df.historical_entity.find(religion_id) + if entity then + for _, deity in ipairs(entity.relations.deities) do + add_spheres(df.historical_figure.find(deity), spheres) + end + end + end + if not entity then return end + return ('%s %s'):format(dfhack.TranslateName(entity.name, true), stringify_spheres(spheres)) +end + local function get_default_zone_name(zone_type) return zone_names[zone_type] or '' end @@ -61,6 +97,7 @@ local function get_zone_search_key(zone) table.insert(result, df.civzone_type[zone.type]); else -- zone is a special location and we need to get its type from world data local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') + if success and building.name then table.insert(result, language_name_types[building.name.type] or '') if building.name.has_name then @@ -77,6 +114,33 @@ local function get_zone_search_key(zone) return table.concat(result, ' ') end +local function get_location_search_key(zone) + local site = df.global.world.world_data.active_site[0] + local result = {} + + -- get language_name and type (we dont need user-given zone name because it does not appear on this page) + local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') + if success and building.name then + table.insert(result, language_name_types[building.name.type] or '') + if building.name.has_name then + table.insert(result, dfhack.TranslateName(building.name, true)) + end + + -- for temples and guildhalls, get assigned organization + if language_name_types[building.name.type] == 'Temple' then + table.insert(result, get_religion_string(building.deity_data.Deity or building.deity_data.Religion, building.deity_type)) + elseif language_name_types[building.name.type] == 'Guildhall' then + -- Broke this up into two locals because table.insert doesn't like it all being inside the second argument for some reason + local profession = df.profession[building.contents.profession] + local dwarfified_profession = profession:gsub('[Mm][Aa][Nn]', 'dwarf') -- Craftsman becomes Craftsdwarf, etc + table.insert(result, dwarfified_profession) + end + + end + + return table.concat(result, ' ') +end + -- ---------------------- -- PlacesOverlay -- @@ -106,6 +170,7 @@ function PlacesOverlay:init() } self:register_handler('ZONES', buildings.list[df.buildings_mode_type.ZONES], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_zone_search_key})) + self:register_handler('LOCATIONS', buildings.list[df.buildings_mode_type.LOCATIONS], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_location_search_key})) end function PlacesOverlay:get_key() @@ -114,6 +179,8 @@ function PlacesOverlay:get_key() -- Not there right now so it doesn't render a search bar on unsupported Places subpages if buildings.mode == df.buildings_mode_type.ZONES then return 'ZONES' + elseif buildings.mode == df.buildings_mode_type.LOCATIONS then + return 'LOCATIONS' end end end