Merge pull request #3873 from myk002/myk_spheres

[sort] support searching for spheres on the religion selector
develop
Myk 2023-10-13 13:41:13 -07:00 committed by GitHub
commit f647e7e668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

@ -119,7 +119,9 @@ Location selection overlay
-------------------------- --------------------------
When choosing the type of guildhall or temple to dedicate, you can search for 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 World overlay
------------- -------------

@ -16,16 +16,38 @@ LocationSelectorOverlay.ATTRS{
frame={w=26, h=1}, 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) local function get_religion_string(religion_id, religion_type)
if religion_id == -1 then return end if religion_id == -1 then return end
local entity local entity
local spheres = {}
if religion_type == 0 then if religion_type == 0 then
entity = df.historical_figure.find(religion_id) entity = df.historical_figure.find(religion_id)
add_spheres(entity, spheres)
elseif religion_type == 1 then elseif religion_type == 1 then
entity = df.historical_entity.find(religion_id) 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 end
if not entity then return 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 end
local function get_profession_string(profession) local function get_profession_string(profession)