From 76af3fb101749c425a99c88ff97cbc13ef6961f2 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Mon, 9 Oct 2023 04:13:42 -0700 Subject: [PATCH 01/12] don't click too quickly for embark tutorial --- changelog.txt | 1 + hide-tutorials.lua | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changelog.txt b/changelog.txt index d03ae453cc..e830ab0c49 100644 --- a/changelog.txt +++ b/changelog.txt @@ -37,6 +37,7 @@ Template for new versions: ## Fixes - `suspendmanager`: fix errors when constructing near the map edge - `gui/sandbox`: fix scrollbar moving double distance on click +- `hide-tutorials`: fix the embark tutorial prompt sometimes not being skipped ## Misc Improvements diff --git a/hide-tutorials.lua b/hide-tutorials.lua index ef855539e4..5ad2c112a7 100644 --- a/hide-tutorials.lua +++ b/hide-tutorials.lua @@ -22,8 +22,9 @@ local function close_help() help.open = false end -function skip_tutorial_prompt(scr) +function skip_tutorial_prompt() if not help.open then return end + local scr = dfhack.gui.getDFViewscreen(true) local mouse_y = 23 if help.context == df.help_context_type.EMBARK_TUTORIAL_CHOICE then help.context = df.help_context_type.EMBARK_MESSAGE @@ -55,7 +56,7 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc) if df.viewscreen_new_regionst:is_instance(scr) then close_help() elseif df.viewscreen_choose_start_sitest:is_instance(scr) then - skip_tutorial_prompt(scr) + dfhack.timeout(1, 'frames', skip_tutorial_prompt) end elseif sc == SC_MAP_LOADED and df.global.gamemode == df.game_mode.DWARF then hide_all_popups() From 7a20d0eb990d9488b25d1df450802d42a9369a18 Mon Sep 17 00:00:00 2001 From: Quinn Cypher Date: Tue, 10 Oct 2023 02:05:46 -0400 Subject: [PATCH 02/12] Initial update + docs --- burial.lua | 51 ++++++++++++++++++++++++++++--------------------- docs/burial.rst | 22 ++++++++++++--------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/burial.lua b/burial.lua index 3f75c50b46..144b1a2136 100644 --- a/burial.lua +++ b/burial.lua @@ -1,27 +1,34 @@ --- allows burial in unowned coffins --- by Putnam https://gist.github.com/Putnam3145/e7031588f4d9b24b9dda ---[====[ +-- Allows burial in unowned coffins. +-- Based on Putnam's work (https://gist.github.com/Putnam3145/e7031588f4d9b24b9dda) +local argparse = require('argparse') +local utils = require('utils') -burial -====== -Sets all unowned coffins to allow burial. ``burial -pets`` also allows burial -of pets. +local args = argparse.processArgs({...}, utils.invert{'d', 'p'}) -]====] - -local utils=require('utils') - -local validArgs = utils.invert({ - 'pets' -}) - -local args = utils.processArgs({...}, validArgs) - -for k,v in ipairs(df.global.world.buildings.other.COFFIN) do --as:df.building_coffinst - if v.owner_id==-1 then - v.burial_mode.allow_burial=true - if not args.pets then - v.burial_mode.no_pets=true +for i, c in pairs(df.global.world.buildings.other.COFFIN) do + -- Check for existing tomb + for i, z in pairs(c.relations) do + if z.type == df.civzone_type.Tomb then + goto skip end end + + dfhack.buildings.constructBuilding { + type = df.building_type.Civzone, + subtype = df.civzone_type.Tomb, + pos = xyz2pos(c.x1, c.y1, c.z), + abstract = true, + fields = { + is_active = 8, + zone_settings = { + tomb = { + no_pets = args.d and not args.p, + no_citizens = args.p and not args.d, + }, + }, + }, + } + + ::skip:: end + diff --git a/docs/burial.rst b/docs/burial.rst index 19e58b9b87..db7601e526 100644 --- a/docs/burial.rst +++ b/docs/burial.rst @@ -2,20 +2,24 @@ burial ====== .. dfhack-tool:: - :summary: Configures all unowned coffins to allow burial. - :tags: unavailable fort productivity buildings + :summary: Allows burial in unowned coffins. + :tags: fort productivity buildings + +Creates a 1x1 tomb zone for each built coffin that doesn't already have one. Usage ----- -:: + ``burial [-d] [-p]`` - burial [--pets] +Created tombs allow both dwarves and pets by default. By specifying ``-d`` or +``-p``, they can be restricted to dwarves or pets, respectively. -if the ``--pets`` option is passed, coffins will also allow burial of pets. +Options +------- -Examples --------- +``-d`` + Create dwarf-only tombs +``-p`` + Create pet-only tombs -``burial --pets`` - Configures all unowned coffins to allow burial, including pets. From 6b5e442fd17c28738020de309cbc24533784161f Mon Sep 17 00:00:00 2001 From: Quinn Cypher Date: Tue, 10 Oct 2023 02:23:43 -0400 Subject: [PATCH 03/12] Added burial update to changelog --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index d03ae453cc..798530521d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,6 +28,7 @@ Template for new versions: ## New Tools - `add-recipe`: (reinstated) add reactions to your civ (e.g. for high boots if your civ didn't start with the ability to make high boots) +- `burial`: (reinstated) allows burial in unowned coffins (now creates tomb zones for all built coffins) ## New Features - `drain-aquifer`: gained ability to drain just above or below a certain z-level From 0b1dbac90d84554f6854927baef8e6dd32341dd5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:21:50 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- burial.lua | 3 +-- docs/burial.rst | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/burial.lua b/burial.lua index 144b1a2136..2b49f9a1ab 100644 --- a/burial.lua +++ b/burial.lua @@ -12,7 +12,7 @@ for i, c in pairs(df.global.world.buildings.other.COFFIN) do goto skip end end - + dfhack.buildings.constructBuilding { type = df.building_type.Civzone, subtype = df.civzone_type.Tomb, @@ -31,4 +31,3 @@ for i, c in pairs(df.global.world.buildings.other.COFFIN) do ::skip:: end - diff --git a/docs/burial.rst b/docs/burial.rst index db7601e526..befd16ba1a 100644 --- a/docs/burial.rst +++ b/docs/burial.rst @@ -22,4 +22,3 @@ Options Create dwarf-only tombs ``-p`` Create pet-only tombs - From 973537cebf9999ce1326b2f41fa4b6a49167381d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Wed, 11 Oct 2023 17:51:30 -0700 Subject: [PATCH 05/12] make hide-tutorials more robust sometimes frames go by so quickly that the mouse click isn't detected on the first or second try --- hide-tutorials.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hide-tutorials.lua b/hide-tutorials.lua index 5ad2c112a7..2ca950e3bf 100644 --- a/hide-tutorials.lua +++ b/hide-tutorials.lua @@ -37,6 +37,10 @@ function skip_tutorial_prompt() df.global.gps.mouse_y = mouse_y gui.simulateInput(scr, '_MOUSE_L') end + if help.open then + -- retry later + help.context = df.help_context_type.EMBARK_TUTORIAL_CHOICE + end end local function hide_all_popups() @@ -56,7 +60,10 @@ dfhack.onStateChange[GLOBAL_KEY] = function(sc) if df.viewscreen_new_regionst:is_instance(scr) then close_help() elseif df.viewscreen_choose_start_sitest:is_instance(scr) then - dfhack.timeout(1, 'frames', skip_tutorial_prompt) + skip_tutorial_prompt() + dfhack.timeout(10, 'frames', skip_tutorial_prompt) + dfhack.timeout(100, 'frames', skip_tutorial_prompt) + dfhack.timeout(1000, 'frames', skip_tutorial_prompt) end elseif sc == SC_MAP_LOADED and df.global.gamemode == df.game_mode.DWARF then hide_all_popups() From 218cae668a6762cb59fc571e528e9a3484dbbae8 Mon Sep 17 00:00:00 2001 From: Quinn Cypher Date: Thu, 12 Oct 2023 14:43:02 -0400 Subject: [PATCH 06/12] Now using quickfort, added zlevel option --- burial.lua | 47 ++++++++++++++++++++++++++--------------------- docs/burial.rst | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/burial.lua b/burial.lua index 2b49f9a1ab..ea1924c422 100644 --- a/burial.lua +++ b/burial.lua @@ -1,33 +1,38 @@ -- Allows burial in unowned coffins. -- Based on Putnam's work (https://gist.github.com/Putnam3145/e7031588f4d9b24b9dda) local argparse = require('argparse') -local utils = require('utils') +local quickfort = reqscript('quickfort') -local args = argparse.processArgs({...}, utils.invert{'d', 'p'}) +local cur_zlevel, citizens, pets = false, true, true +argparse.processArgsGetopt({...}, { + {'z', 'cur-zlevel', handler=function() cur_zlevel = true end}, + {'c', 'citizens-only', handler=function() pets = false end}, + {'p', 'pets-only', handler=function() citizens = false end}, +}) +local tomb_blueprint = { + mode = 'zone', + pos = nil, + -- Don't pass properties with default values to avoid 'unhandled property' warning + data = ('T{%s %s}'):format(citizens and '' or 'citizens=false', pets and 'pets=true' or ''), +} -for i, c in pairs(df.global.world.buildings.other.COFFIN) do - -- Check for existing tomb - for i, z in pairs(c.relations) do - if z.type == df.civzone_type.Tomb then +local tomb_count = 0 +for _, coffin in pairs(df.global.world.buildings.other.COFFIN) do + + if cur_zlevel and not (coffin.z == df.global.window_z) then + goto skip + end + for _, zone in pairs(coffin.relations) do + if zone.type == df.civzone_type.Tomb then goto skip end end - dfhack.buildings.constructBuilding { - type = df.building_type.Civzone, - subtype = df.civzone_type.Tomb, - pos = xyz2pos(c.x1, c.y1, c.z), - abstract = true, - fields = { - is_active = 8, - zone_settings = { - tomb = { - no_pets = args.d and not args.p, - no_citizens = args.p and not args.d, - }, - }, - }, - } + tomb_blueprint.pos = xyz2pos(coffin.x1, coffin.y1, coffin.z) + quickfort.apply_blueprint(tomb_blueprint) + tomb_count = tomb_count + 1 ::skip:: end + +print(('Created %s tombs.'):format(tomb_count)) diff --git a/docs/burial.rst b/docs/burial.rst index befd16ba1a..abc85b6264 100644 --- a/docs/burial.rst +++ b/docs/burial.rst @@ -3,22 +3,42 @@ burial .. dfhack-tool:: :summary: Allows burial in unowned coffins. - :tags: fort productivity buildings + :tags: fort | productivity | buildings -Creates a 1x1 tomb zone for each built coffin that doesn't already have one. +Creates a 1x1 tomb zone for each built coffin that isn't already in a tomb. Usage ----- - ``burial [-d] [-p]`` + ``burial []`` -Created tombs allow both dwarves and pets by default. By specifying ``-d`` or -``-p``, they can be restricted to dwarves or pets, respectively. +Examples +-------- + +``burial`` + Create a tomb for every coffin on the map with automatic burial enabled. + +``burial -z`` + Create tombs only on the current zlevel. + +``burial -c`` + Create tombs designated for automatic burial of citizens only. + +``burial -p`` + Create tombs designated for automatic burial of pets only. + +``burial -cp`` + Create tombs with automatic burial disabled for both citizens and pets, + requiring manual assignment of deceased units to each tomb. Options ------- -``-d`` - Create dwarf-only tombs -``-p`` - Create pet-only tombs +``-z``, ``--cur-zlevel`` + Only create tombs on the current zlevel. + +``-c``, ``--citizens-only`` + Only automatically bury citizens. + +``-p``, ``--pets-only`` + Only automatically bury pets. From e83bb778ee9907d0bf289142cd4955c034ce00d6 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 13 Oct 2023 02:27:55 -0700 Subject: [PATCH 07/12] include the insane for reachability purposes --- unforbid.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unforbid.lua b/unforbid.lua index 1daf1e41e1..38667602c1 100644 --- a/unforbid.lua +++ b/unforbid.lua @@ -5,7 +5,7 @@ local argparse = require('argparse') local function unforbid_all(include_unreachable, quiet) if not quiet then print('Unforbidding all items...') end - local citizens = dfhack.units.getCitizens() + local citizens = dfhack.units.getCitizens(true) local count = 0 for _, item in pairs(df.global.world.items.all) do if item.flags.forbid then From 1c67dcd56955c4ee12d6492d0c38774d1797dadf Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 13 Oct 2023 02:28:43 -0700 Subject: [PATCH 08/12] include the insane for reachability purposes --- forbid.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forbid.lua b/forbid.lua index cfb62a1e98..b0be9536f9 100644 --- a/forbid.lua +++ b/forbid.lua @@ -70,7 +70,7 @@ end if positionals[1] == "unreachable" then print("Forbidding all unreachable items on the map...") - local citizens = dfhack.units.getCitizens() + local citizens = dfhack.units.getCitizens(true) local count = 0 for _, item in pairs(df.global.world.items.all) do From 3d4854e1b21b60ad8b0957f6de7cc27fbdbd12ee Mon Sep 17 00:00:00 2001 From: Quinn Cypher Date: Fri, 13 Oct 2023 11:21:52 -0400 Subject: [PATCH 09/12] Apply suggestions from code review Co-authored-by: Myk --- burial.lua | 2 +- docs/burial.rst | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/burial.lua b/burial.lua index ea1924c422..caf01e0064 100644 --- a/burial.lua +++ b/burial.lua @@ -35,4 +35,4 @@ for _, coffin in pairs(df.global.world.buildings.other.COFFIN) do ::skip:: end -print(('Created %s tombs.'):format(tomb_count)) +print(('Created %s tomb(s).'):format(tomb_count)) diff --git a/docs/burial.rst b/docs/burial.rst index abc85b6264..506d1a8715 100644 --- a/docs/burial.rst +++ b/docs/burial.rst @@ -2,8 +2,8 @@ burial ====== .. dfhack-tool:: - :summary: Allows burial in unowned coffins. - :tags: fort | productivity | buildings + :summary: Create tomb zones for unzoned coffins. + :tags: fort productivity buildings Creates a 1x1 tomb zone for each built coffin that isn't already in a tomb. From 923f10d98d69efc2a59fcadab591d4bdf71e0031 Mon Sep 17 00:00:00 2001 From: Quinn Cypher Date: Fri, 13 Oct 2023 12:00:53 -0400 Subject: [PATCH 10/12] New burial options --- changelog.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 798530521d..398cfb8747 100644 --- a/changelog.txt +++ b/changelog.txt @@ -28,9 +28,10 @@ Template for new versions: ## New Tools - `add-recipe`: (reinstated) add reactions to your civ (e.g. for high boots if your civ didn't start with the ability to make high boots) -- `burial`: (reinstated) allows burial in unowned coffins (now creates tomb zones for all built coffins) +- `burial`: (reinstated) create tomb zones for unzoned coffins ## New Features +- `burial`: new options to configure automatic burial and limit scope to the current z-level - `drain-aquifer`: gained ability to drain just above or below a certain z-level - `drain-aquifer`: new option to drain all layers except for the first N aquifer layers, in case you want some aquifer layers but not too many - `gui/control-panel`: ``drain-aquifer --top 2`` added as an autostart option From 04f561cdad149dfd8e67204520a453e1233cbf18 Mon Sep 17 00:00:00 2001 From: Rose Date: Fri, 13 Oct 2023 23:19:54 -0700 Subject: [PATCH 11/12] Updated transform-unit.lua to try to select the currently selected unit if none is provided. It still can crash the game, however. --- modtools/transform-unit.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/modtools/transform-unit.lua b/modtools/transform-unit.lua index 3d559d5ab3..8833420ee3 100644 --- a/modtools/transform-unit.lua +++ b/modtools/transform-unit.lua @@ -66,9 +66,17 @@ if args.clear then return end -if not args.unit then - error 'Specify a unit.' +local unit +if args.unit then + unit = df.unit.find(tonumber(args.unit)) +else + unit = dfhack.gui.getSelectedUnit(true) +end +if not unit then + error 'Select or specify a valid unit' + return end +local unit_id = unit.id if not args.duration then args.duration = 'forever' @@ -78,11 +86,10 @@ local raceIndex local race local caste if args.untransform then - local unit = df.unit.find(tonumber(args.unit)) - raceIndex = normalRace[args.unit].race + raceIndex = normalRace[unit_id].race race = df.creature_raw.find(raceIndex) - caste = normalRace[args.unit].caste - normalRace[args.unit] = nil + caste = normalRace[unit_id].caste + normalRace[unit_id] = nil else if not args.race or not args.caste then error 'Specficy a target form.' @@ -113,13 +120,12 @@ else end end -local unit = df.unit.find(tonumber(args.unit)) local oldRace = unit.enemy.normal_race local oldCaste = unit.enemy.normal_caste if args.setPrevRace then - normalRace[args.unit] = {} - normalRace[args.unit].race = oldRace - normalRace[args.unit].caste = oldCaste + normalRace[unit_id] = {} + normalRace[unit_id].race = oldRace + normalRace[unit_id].caste = oldCaste end transform(unit,raceIndex,caste,args.setPrevRace) From 22238c9707be9335dd18e92505dcf393d6267baa Mon Sep 17 00:00:00 2001 From: Myk Date: Sat, 14 Oct 2023 12:28:50 -0700 Subject: [PATCH 12/12] Update burial.lua --- burial.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/burial.lua b/burial.lua index caf01e0064..3bc7f1072c 100644 --- a/burial.lua +++ b/burial.lua @@ -19,7 +19,7 @@ local tomb_blueprint = { local tomb_count = 0 for _, coffin in pairs(df.global.world.buildings.other.COFFIN) do - if cur_zlevel and not (coffin.z == df.global.window_z) then + if cur_zlevel and coffin.z ~= df.global.window_z then goto skip end for _, zone in pairs(coffin.relations) do