Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
0ab4262
Add chronicle script to record fortress events
LoireLab Jul 19, 2025
3657eba
Merge pull request #1 from LoireLab/codex/-chronicle.lua
LoireLab Jul 19, 2025
2e675db
fix chronicle initialization and loading
LoireLab Jul 19, 2025
a508e66
Merge branch 'master' into 8pg7m7-codex/-chronicle.lua
LoireLab Jul 19, 2025
75c597b
Merge pull request #3 from LoireLab/8pg7m7-codex/-chronicle.lua
LoireLab Jul 19, 2025
8da32eb
Fix chronicle artifact log and hook handling
LoireLab Jul 19, 2025
b827167
Merge branch 'master' into cijxz4-codex/-chronicle.lua
LoireLab Jul 19, 2025
3e91375
Merge pull request #4 from LoireLab/cijxz4-codex/-chronicle.lua
LoireLab Jul 19, 2025
4ee1a21
fix chronicle artifact timestamp
LoireLab Jul 19, 2025
d912fc2
Merge pull request #6 from LoireLab/codex/fix-artifact_record.year_ti…
LoireLab Jul 19, 2025
5a4b43a
disable heavy scanning in chronicle
LoireLab Jul 19, 2025
7ae87b0
Merge pull request #7 from LoireLab/62ad62-codex
LoireLab Jul 19, 2025
bcbcc3d
Track artifacts and invasions
LoireLab Jul 19, 2025
c623822
Remove legacy scanning in chronicle
LoireLab Jul 19, 2025
1d72e2a
Merge pull request #8 from LoireLab/dhff81-codex
LoireLab Jul 19, 2025
dba3c1a
Refine holy-war mod with deity spheres
LoireLab Jul 19, 2025
5894d49
Merge pull request #9 from LoireLab/9hdvkm-codex
LoireLab Jul 19, 2025
66bc94e
Enhance chronicle output and item tracking
LoireLab Jul 19, 2025
a381a24
Merge pull request #10 from LoireLab/codex/investigate-chronicle-prin…
LoireLab Jul 19, 2025
55777ed
Ensure holy-war sets war on both sides
LoireLab Jul 19, 2025
0bc3aa2
Merge pull request #11 from LoireLab/codex/-holy-war
LoireLab Jul 19, 2025
f79f046
Refine chronicle output
LoireLab Jul 19, 2025
d5e8333
Merge pull request #12 from LoireLab/codex/fix-incomplete-utf-8-seque…
LoireLab Jul 19, 2025
5839e89
holy-war: display war reason
LoireLab Jul 19, 2025
5a1278e
Merge pull request #13 from LoireLab/uyevve-codex
LoireLab Jul 19, 2025
9a12910
Summarize non-artifact item creation
LoireLab Jul 19, 2025
d7b8668
Improve holy-war output
LoireLab Jul 19, 2025
fc848c8
Merge pull request #14 from LoireLab/3zaa1h-codex
LoireLab Jul 19, 2025
348aa13
Merge pull request #15 from LoireLab/90u9lr-codex/-holy-war
LoireLab Jul 19, 2025
1c8ab86
Need-aquire
LoireLab Jul 19, 2025
b541254
chronicle: capture artifact announcements
LoireLab Jul 19, 2025
c80fd0a
Merge pull request #16 from LoireLab/n6oxr7-codex
LoireLab Jul 19, 2025
27f92b8
Improve need-acquire.lua with documentation and cleanup
LoireLab Jul 19, 2025
e11daff
Merge pull request #17 from LoireLab/codex/-need-acquire.lua
LoireLab Jul 19, 2025
1271e42
chronicle: add export command
LoireLab Jul 19, 2025
aa7ec00
Merge pull request #19 from LoireLab/qgrtgu-codex
LoireLab Jul 19, 2025
a827df4
Sanitize chronicle output
LoireLab Jul 19, 2025
64184e2
Merge pull request #20 from LoireLab/tgeoam-codex
LoireLab Jul 19, 2025
aa46986
sanitize chronicle entries
LoireLab Jul 19, 2025
2a78abc
Merge branch 'master' into 7d9b1y-codex
LoireLab Jul 19, 2025
dd2afe3
Merge pull request #21 from LoireLab/7d9b1y-codex
LoireLab Jul 19, 2025
e187aed
Optimization of chronicle.lua
LoireLab Jul 19, 2025
c6cd65a
Refactor scripts and update docs
LoireLab Jul 19, 2025
f39879f
Merge pull request #22 from LoireLab/codex/-need-acquire,-holy-war,-c…
LoireLab Jul 19, 2025
bcd1d94
Chronicle.lua new events and text changes from notification style
LoireLab Jul 19, 2025
a811f4e
Ignore wildlife deaths in chronicle
LoireLab Jul 20, 2025
3c1113f
Merge pull request #23 from LoireLab/codex/-wildlife-chronicle
LoireLab Jul 20, 2025
5f3bea4
Add scrollable chronicle viewer
LoireLab Jul 20, 2025
a1754c3
Merge pull request #24 from LoireLab/codex/-chronicle
LoireLab Jul 20, 2025
18d804b
Preserve trimmed chronicle entries
LoireLab Jul 20, 2025
ce57986
Add multihaul script
LoireLab Jul 20, 2025
93f002f
Merge pull request #25 from LoireLab/fff979-codex/-chronicle
LoireLab Jul 20, 2025
0828c9f
Merge pull request #26 from LoireLab/codex/-haul
LoireLab Jul 20, 2025
dd177e3
Refine death messages with faction-specific text
LoireLab Jul 20, 2025
27e017f
Merge branch 'master' into arkt0w-codex
LoireLab Jul 20, 2025
9abc0cc
Merge pull request #27 from LoireLab/arkt0w-codex
LoireLab Jul 20, 2025
c61e2c1
Add config options and debugging to multihaul
LoireLab Jul 20, 2025
125b9b1
Merge pull request #28 from LoireLab/codex/-multihaul
LoireLab Jul 20, 2025
969dc3b
chronicle: unified notification capture pattern
LoireLab Jul 20, 2025
bb30c35
Add wheelbarrow-multi script
LoireLab Jul 20, 2025
120714f
Merge pull request #29 from LoireLab/xfayq7-codex
LoireLab Jul 20, 2025
4918c25
fix chronicle typos and update help
LoireLab Jul 20, 2025
f661b82
Merge pull request #30 from LoireLab/codex/-chroncile
LoireLab Jul 20, 2025
dbcfc0a
Delete wheelbarrow-multi.lua
LoireLab Jul 20, 2025
e1d73ab
Delete multihaul.lua
LoireLab Jul 20, 2025
ef86f40
Add stack-bodyparts script
LoireLab Jul 20, 2025
232ab56
Merge pull request #31 from LoireLab/cw2cix-codex
LoireLab Jul 20, 2025
c95408d
Revert "Add stack-bodyparts utility"
LoireLab Jul 20, 2025
6d8f5e3
chronicle.lua: fixed multiple notification logging
LoireLab Jul 20, 2025
3ee0432
chronicle.lua: more lines, separate lines for Bloodsuckers and Great …
LoireLab Jul 20, 2025
f5b19f3
chronicle.lua: ticks to detect events increased
LoireLab Jul 20, 2025
112be4e
Merge pull request #33 from LoireLab/revert-31-cw2cix-codex
LoireLab Jul 20, 2025
d44dcc3
Restored multihaul.lua
LoireLab Jul 20, 2025
996bec8
Fix multihaul unloading and limit by container size
LoireLab Jul 20, 2025
84ad664
Merge pull request #34 from LoireLab/codex/fix-unloading-issue-in-mul…
LoireLab Jul 20, 2025
989ae8d
multihaul.lua: reverted to item count since capacity is calculated by…
LoireLab Jul 20, 2025
2d23d4f
Debugging multihaul.lua
LoireLab Jul 20, 2025
e4f035f
Debug multihaul.lua: I got it called
LoireLab Jul 20, 2025
f1566b2
multihaul.lua: clean version with working multi gathering and not wor…
LoireLab Jul 20, 2025
5d1699e
multihaul.lua: fixed unneeded code copied from emptywheelbarrow
LoireLab Jul 21, 2025
0b31ff1
fix multihaul script
LoireLab Jul 21, 2025
c41e43a
Merge pull request #35 from LoireLab/codex/fix-nil-value-error-in-mul…
LoireLab Jul 21, 2025
fef261b
multihaul.lua: WORKING VERSION HURRAY
LoireLab Jul 21, 2025
37c55c5
Restrict multihaul to wheelbarrow jobs
LoireLab Jul 21, 2025
9ee5928
Merge pull request #36 from LoireLab/codex/-multihaul-wheelbarrow
LoireLab Jul 21, 2025
2572537
multihaul: restrict to identical items and verify wheelbarrow
LoireLab Jul 21, 2025
b84914f
Merge pull request #37 from LoireLab/codex/-wheelbarrow
LoireLab Jul 21, 2025
81f3db2
multihaul: fix wheelbarrow role
LoireLab Jul 21, 2025
cf05936
Merge pull request #38 from LoireLab/codex/-pushhaulvehicle
LoireLab Jul 21, 2025
58b3688
multihaul.lua: removed unnesessary checks and fixes
LoireLab Jul 21, 2025
cfb1e95
multihaul: filter items by stockpile settings
LoireLab Jul 21, 2025
7134d53
Merge pull request #39 from LoireLab/lxvsq8-codex
LoireLab Jul 21, 2025
986eeb5
multihaul: add matching modes
LoireLab Jul 21, 2025
f3e50c6
Merge pull request #40 from LoireLab/codex/-multihaul
LoireLab Jul 21, 2025
c2a4bd1
multihaul.lua: changed default mode and removed isItemAllowedInStockpile
LoireLab Jul 21, 2025
48cd99a
multihaul.lua: splited type and subtype modes
LoireLab Jul 21, 2025
8cbf4b3
refactor multihaul state and update docs
LoireLab Jul 21, 2025
46d0f57
Merge pull request #41 from LoireLab/673mq6-codex/-multihaul
LoireLab Jul 21, 2025
bfa99d6
Delete changelog.txt
LoireLab Jul 21, 2025
20dd70d
multihaul: docs updated
LoireLab Jul 21, 2025
640ca99
multihaul: help updated
LoireLab Jul 21, 2025
347d2a2
Delete gui/chronicle.lua
LoireLab Jul 21, 2025
b187046
Delete chronicle.lua
LoireLab Jul 21, 2025
acaa671
Delete holy-war.lua
LoireLab Jul 21, 2025
a9b48d1
Delete docs/need-acquire.rst
LoireLab Jul 21, 2025
2e45d27
Delete docs/wheelbarrow-multi.rst
LoireLab Jul 21, 2025
830de7a
Delete docs/chronicle.rst
LoireLab Jul 21, 2025
e1e3c65
Delete docs/holy-war.rst
LoireLab Jul 21, 2025
b96a5bf
Add files via upload
LoireLab Jul 21, 2025
a4845fd
Update changelog.txt
LoireLab Jul 21, 2025
e963afe
Delete need-acquire.lua
LoireLab Jul 21, 2025
4b0f187
Update multihaul.lua
LoireLab Jul 21, 2025
bb0d045
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 21, 2025
40cd433
multihaul.lua: protection for already in stockpile items and autobrea…
LoireLab Jul 21, 2025
64ac19e
Update multihaul.lua
LoireLab Jul 21, 2025
d31b536
Update multihaul.rst
LoireLab Jul 21, 2025
8ae5572
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 21, 2025
e94232c
multihaul: assign wheelbarrows to any job!
LoireLab Jul 22, 2025
3ccf8d0
multihaul: optimize wheelbarrow assignment
LoireLab Jul 22, 2025
80501dd
multihaul: optimization
LoireLab Jul 22, 2025
8f4c3e7
Update multihaul.rst
LoireLab Jul 22, 2025
ea5a859
multihaul wheelbarrow assign optimization
LoireLab Jul 22, 2025
759332c
Update multihaul.lua
LoireLab Jul 22, 2025
f2886ae
multihaul: fix grabbing wheelbarrows and minecart logic
LoireLab Jul 22, 2025
f21982f
multihaul: optimizing item search
LoireLab Jul 22, 2025
d8eded8
refactor multihaul item search
LoireLab Jul 22, 2025
ae59c6d
Merge pull request #45 from LoireLab/i8l5e4-codex/standardize-item-se…
LoireLab Jul 22, 2025
2b4f7b9
multihaul: added protection for returning wheelbarrow jobs
LoireLab Jul 23, 2025
a76460f
multihaul: removed magic number on wheelbarrow_search_radius_k
LoireLab Jul 23, 2025
bbead11
wheelbarrow_search_radius_k now is called correctly
LoireLab Jul 26, 2025
9410045
multihaul: clear lost wheelbarrow jobs when emptying
LoireLab Jul 26, 2025
c799c3f
Merge pull request #46 from LoireLab/0aur88-codex/implement-finish_jo…
LoireLab Jul 26, 2025
d910921
fix multihaul forward declaration
LoireLab Jul 26, 2025
3f31da2
Merge pull request #47 from LoireLab/x5agea-codex/fix-nil-value-error…
LoireLab Jul 26, 2025
6049eae
autowheelbarrow option now works correctly
LoireLab Jul 26, 2025
a334119
Removed breaking wheelbarrow.flags.in_job
LoireLab Jul 26, 2025
b976bdf
finish_jobs_without_wheelbarrow function expanded
LoireLab Jul 26, 2025
35f4800
Merge branch 'master' into multihaul
LoireLab Jul 26, 2025
f30d4b2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2025
84dcc48
Multihaul ignores Forbidden items
LoireLab Nov 21, 2025
43ab0bf
Update multihaul.rst
LoireLab Nov 21, 2025
680ce70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix chronicle artifact log and hook handling
  • Loading branch information
LoireLab committed Jul 19, 2025
commit 8da32eb333cb1feb85c02a534daab68f4806ab77
144 changes: 144 additions & 0 deletions chronicle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
-- Chronicles fortress events (deaths, artifacts, invasions)
--@module = true
--@enable = true

local eventful = require('plugins.eventful')
local utils = require('utils')

local GLOBAL_KEY = 'chronicle'

local function get_default_state()
return {
entries = {},
last_artifact_id = -1,
known_invasions = {},
}
end

state = state or get_default_state()

local function persist_state()
dfhack.persistent.saveSiteData(GLOBAL_KEY, state)
end

local function format_date(year, ticks)
local julian_day = math.floor(ticks / 1200) + 1
local month = math.floor(julian_day / 28) + 1
local day = julian_day % 28
return string.format('%03d-%02d-%02d', year, month, day)
end

local function add_entry(text)
table.insert(state.entries, text)
persist_state()
end

local function on_unit_death(unit_id)
local unit = df.unit.find(unit_id)
if not unit then return end
local name = dfhack.units.getReadableName(unit)
local date = format_date(df.global.cur_year, df.global.cur_year_tick)
add_entry(string.format('Death of %s on %s', name, date))
end

local function check_artifacts()
local last_id = state.last_artifact_id
for _, rec in ipairs(df.global.world.artifacts.all) do
if rec.id > last_id then
local name = dfhack.translation.translateName(rec.name)
-- artifact_record stores the creation tick in `year_tick`
local date = format_date(rec.year, rec.year_tick or 0)
add_entry(string.format('Artifact "%s" created on %s', name, date))
last_id = rec.id
end
end
state.last_artifact_id = last_id
end

local function check_invasions()
for _, inv in ipairs(df.global.plotinfo.invasions.list) do
if inv.flags.active and not state.known_invasions[inv.id] then
state.known_invasions[inv.id] = true
local date = format_date(df.global.cur_year, df.global.cur_year_tick)
add_entry(string.format('Invasion started on %s', date))
end
end
end

local function event_loop()
if not state.enabled then return end
check_artifacts()
check_invasions()
dfhack.timeout(1200, 'ticks', event_loop)
end

local function do_enable()
state.enabled = true
eventful.onUnitDeath[GLOBAL_KEY] = on_unit_death
persist_state()
event_loop()
end

local function do_disable()
state.enabled = false
eventful.onUnitDeath[GLOBAL_KEY] = nil
persist_state()
end

local function load_state()
state = get_default_state()
utils.assign(state, dfhack.persistent.getSiteData(GLOBAL_KEY, state))
end

-- State change hook

dfhack.onStateChange[GLOBAL_KEY] = function(sc)
if sc == SC_MAP_UNLOADED then
eventful.onUnitDeath[GLOBAL_KEY] = nil
state.enabled = false
return
end
if sc ~= SC_MAP_LOADED or not dfhack.world.isFortressMode() then
return
end

load_state()
if state.enabled then
do_enable()
end
end

if dfhack.isMapLoaded() and dfhack.world.isFortressMode() then
load_state()
if state.enabled then
do_enable()
end
end

if dfhack_flags.module then return end

if not dfhack.world.isFortressMode() or not dfhack.isMapLoaded() then
qerror('chronicle requires a loaded fortress map')
end

load_state()

local args = {...}
local cmd = args[1] or 'print'

if cmd == 'enable' then
do_enable()
elseif cmd == 'disable' then
do_disable()
elseif cmd == 'clear' then
state.entries = {}
persist_state()
elseif cmd == 'print' then
for _, entry in ipairs(state.entries) do
print(entry)
end
else
print(dfhack.script_help())
end

persist_state()
29 changes: 29 additions & 0 deletions docs/chronicle.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
chronicle
=========

.. dfhack-tool::
:summary: Record fortress events like deaths, artifacts, and invasions.
:tags: fort gameplay

This tool automatically records notable events in a chronicle that is stored
with your save. The chronicle contains entries for unit deaths, newly created
artifacts, and the start of invasions.

Usage
-----

::

chronicle enable
chronicle disable
chronicle print
chronicle clear

``chronicle enable``
Start recording events in the current fortress.
``chronicle disable``
Stop recording events.
``chronicle print``
Print all recorded events.
``chronicle clear``
Delete the chronicle.