Skip to content

Commit

Permalink
Merge pull request #1325 from c3r341/c3r341-global-necronomicon
Browse files Browse the repository at this point in the history
global necronomicon functionality
  • Loading branch information
myk002 authored Nov 28, 2024
2 parents 8a1e74a + d92a90e commit 00332f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Template for new versions:
- `idle-crafting`: also support making shell crafts for workshops with linked input stockpiles
- `gui/gm-editor`: automatic display of semantic values for language_name fields
- `fix/stuck-worship`: reduced console output by default. Added ``--verbose`` and ``--quiet`` options.
- `necronomicon`: new ``--world`` option to list all secret-containing items in the entire world

## Removed
- `modtools/force`: merged into `force`
Expand Down
12 changes: 8 additions & 4 deletions docs/necronomicon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ necronomicon
:summary: Find books that contain the secrets of life and death.
:tags: fort inspection items

Lists all books in the fortress that contain the secrets to life and death.
To find the books in fortress mode, go to the Written content submenu in
Objects (O). Slabs are not shown by default since dwarves cannot read secrets
from a slab in fort mode.
Lists all books in the fortress (or world) that contain the secrets to life and
death. To zoom to the books in fortress mode, go to the ``Artifacts`` tab in
`gui/sitemap` and click on their names. Slabs are not listed by default since
dwarves cannot read secrets from a slab in fort mode.

Usage
-----
Expand All @@ -23,3 +23,7 @@ Options
``-s``, ``--include-slabs``
Also list slabs that contain the secrets of life and death. Note that
dwarves cannot read the secrets from a slab in fort mode.

``-w``, ``--world``
Lists ALL secret-containing items across the entire world, not just your
fortress.
40 changes: 36 additions & 4 deletions necronomicon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ function get_book_interactions(item)
improvement._type == df.itemimprovement_writingst then
for _, content_id in ipairs(improvement.contents) do
local written_content = df.written_content.find(content_id)
title = written_content.title
if not written_content then goto continue end

title = written_content.title
for _, ref in ipairs (written_content.refs) do
if ref._type == df.general_ref_interactionst then
local interaction = df.interaction.find(ref.interaction_id)
table.insert(book_interactions, interaction)
end
end
::continue::
end
end
end
Expand Down Expand Up @@ -79,20 +81,50 @@ function necronomicon(include_slabs)
end
end

function necronomicon_world(include_slabs)
if include_slabs then
print("Slabs:")
print()
for _,rec in ipairs(df.global.world.artifacts.all) do
if df.item_slabst:is_instance(rec.item) and check_slab_secrets(rec.item) then
print(dfhack.df2console(dfhack.TranslateName(rec.name)))
end
end
print()
end
print("Books and Scrolls:")
print()
for _,rec in ipairs(df.global.world.artifacts.all) do
if df.item_bookst:is_instance(rec.item) or df.item_toolst:is_instance(rec.item) then
local title, interactions = get_book_interactions(rec.item)

if next(interactions) then
print(" " .. dfhack.df2console(title))
print_interactions(interactions)
print()
end
end
end
end

local help = false
local include_slabs = false
local include_slabs, scan_world = false, false
local args = argparse.processArgsGetopt({...}, {
{"s", "include-slabs", handler=function() include_slabs = true end},
{"w", "world", handler=function() scan_world = true end},
{"h", "help", handler=function() help = true end}
})

local cmd = args[1]

if help or cmd == "help" then
print(dfhack.script_help())
elseif cmd == nil or cmd == "" then
necronomicon(include_slabs)
elseif not cmd then
if scan_world then
necronomicon_world(include_slabs)
else
necronomicon(include_slabs)
end
else
print(('necronomicon: Invalid argument: "%s"'):format(cmd))
end

0 comments on commit 00332f5

Please sign in to comment.