From ee78f4fbdfd36b282d1b27eaa5a65edf804b8032 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 13 Oct 2023 12:37:11 -0700 Subject: [PATCH] support searching for spheres on the religion selector --- docs/plugins/sort.rst | 4 +++- plugins/lua/sort/locationselector.lua | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/plugins/sort.rst b/docs/plugins/sort.rst index fd8d5102e..0ffe5118b 100644 --- a/docs/plugins/sort.rst +++ b/docs/plugins/sort.rst @@ -119,7 +119,9 @@ Location selection overlay -------------------------- When choosing the type of guildhall or temple to dedicate, you can search for -the relevant profession, religion, or deity by name. +the relevant profession, religion, or deity by name. For temples, you can also +search for the "spheres" associated with the deity or religion, such as +"wealth" or "lies". World overlay ------------- diff --git a/plugins/lua/sort/locationselector.lua b/plugins/lua/sort/locationselector.lua index 8a79a9d8f..d91c536ac 100644 --- a/plugins/lua/sort/locationselector.lua +++ b/plugins/lua/sort/locationselector.lua @@ -16,16 +16,38 @@ LocationSelectorOverlay.ATTRS{ frame={w=26, h=1}, } +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 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 dfhack.TranslateName(entity.name, true) + return ('%s %s'):format(dfhack.TranslateName(entity.name, true), stringify_spheres(spheres)) end local function get_profession_string(profession)