diff --git a/chronicle.lua b/chronicle.lua index c247180ed..eb91cc8e6 100644 --- a/chronicle.lua +++ b/chronicle.lua @@ -1,4 +1,4 @@ --- Chronicles fortress events: unit deaths, artifact creation, and invasions +-- Chronicles fortress events: unit deaths, item creation, and invasions --@module = true --@enable = true @@ -43,18 +43,22 @@ end local function on_item_created(item_id) local item = df.item.find(item_id) - if not item or not item.flags.artifact then return end + if not item then return end - local gref = dfhack.items.getGeneralRef(item, df.general_ref_type.IS_ARTIFACT) - local rec = gref and df.artifact_record.find(gref.artifact_id) or nil - if not rec then return end + local date = format_date(df.global.cur_year, df.global.cur_year_tick) - local name = dfhack.translation.translateName(rec.name) - local date = format_date(rec.year, rec.season_tick or 0) - if rec.id > state.last_artifact_id then - state.last_artifact_id = rec.id + if item.flags.artifact then + local gref = dfhack.items.getGeneralRef(item, df.general_ref_type.IS_ARTIFACT) + local rec = gref and df.artifact_record.find(gref.artifact_id) or nil + local name = rec and dfhack.translation.translateName(rec.name) or 'unknown artifact' + if rec and rec.id > state.last_artifact_id then + state.last_artifact_id = rec.id + end + add_entry(string.format('Artifact "%s" created on %s', name, date)) + else + local desc = dfhack.items.getDescription(item, 0, true) + add_entry(string.format('Item "%s" created on %s', desc, date)) end - add_entry(string.format('Artifact "%s" created on %s', name, date)) end local function on_invasion(invasion_id) @@ -134,8 +138,12 @@ elseif cmd == 'clear' then state.entries = {} persist_state() elseif cmd == 'print' then - for _, entry in ipairs(state.entries) do - print(entry) + if #state.entries == 0 then + print('Chronicle is empty.') + else + for _, entry in ipairs(state.entries) do + print(entry) + end end else print(dfhack.script_help()) diff --git a/docs/chronicle.rst b/docs/chronicle.rst index e573d967b..0c4c5b7c1 100644 --- a/docs/chronicle.rst +++ b/docs/chronicle.rst @@ -2,11 +2,12 @@ chronicle ========= .. dfhack-tool:: - :summary: Record fortress events like deaths, artifacts, and invasions. + :summary: Record fortress events like deaths, item creation, and invasions. :tags: fort gameplay This tool automatically records notable events in a chronicle that is stored -with your save. Unit deaths, artifact creation, and invasions are recorded. +with your save. Unit deaths, all item creation events, and invasions are +recorded. Usage ----- @@ -23,6 +24,6 @@ Usage ``chronicle disable`` Stop recording events. ``chronicle print`` - Print all recorded events. + Print all recorded events. Prints a notice if the chronicle is empty. ``chronicle clear`` Delete the chronicle.