From 7f122cd15d4e6289a61c75914ac1e464c3c87b7c Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 14 Jun 2024 03:01:15 +0300 Subject: [PATCH 1/6] Fix adv-fix-sleepers to work on v51 --- adv-fix-sleepers.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/adv-fix-sleepers.lua b/adv-fix-sleepers.lua index e92a01e0e7..83131abeb1 100644 --- a/adv-fix-sleepers.lua +++ b/adv-fix-sleepers.lua @@ -17,7 +17,8 @@ Usage:: --======================== -- Author: ArrowThunder on bay12 & reddit --- Version: 1.1 +-- Fixed for v51 by Crystalwarrior +-- Version: 1.2 --======================= -- get the list of all the active units currently loaded @@ -28,10 +29,10 @@ local num_fixed = 0 -- this is the number of army controllers fixed, not units -- I've found that often, multiple sleepers share a bugged army controller for k, unit in pairs(active_units) do if unit then - local army_controller = df.army_controller.find(unit.enemy.army_controller_id) - if army_controller and army_controller.type == 4 then -- sleeping code is possible - if army_controller.unk_64.t4.unk_2.not_sleeping == false then - army_controller.unk_64.t4.unk_2.not_sleeping = true -- fix bug + local army_controller = unit.enemy.army_controller + if army_controller and army_controller.goal == df.army_controller_goal_type.CAMP then -- sleeping code is possible + if not army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER then + army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER = true -- fix bug num_fixed = num_fixed + 1 end end From 60055d06b59fe644294f9b7d0cea1c9c225377f3 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 14 Jun 2024 03:14:41 +0300 Subject: [PATCH 2/6] Changelog entry, documentation, renaming to fix/sleepers --- adv-fix-sleepers.lua | 46 ------------------------------------------- changelog.txt | 1 + docs/fix/sleepers.rst | 18 +++++++++++++++++ fix/sleepers.lua | 21 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 46 deletions(-) delete mode 100644 adv-fix-sleepers.lua create mode 100644 docs/fix/sleepers.rst create mode 100644 fix/sleepers.lua diff --git a/adv-fix-sleepers.lua b/adv-fix-sleepers.lua deleted file mode 100644 index 83131abeb1..0000000000 --- a/adv-fix-sleepers.lua +++ /dev/null @@ -1,46 +0,0 @@ ---Fixes all local bugged sleepers in adventure mode. ---[====[ - -adv-fix-sleepers -================ -Fixes :bug:`6798`. This bug is characterized by sleeping units who refuse to -awaken in adventure mode regardless of talking to them, hitting them, or waiting -so long you die of thirst. If you come accross one or more bugged sleepers in -adventure mode, simply run the script and all nearby sleepers will be cured. - -Usage:: - - adv-fix-sleepers - - -]====] - ---======================== --- Author: ArrowThunder on bay12 & reddit --- Fixed for v51 by Crystalwarrior --- Version: 1.2 ---======================= - --- get the list of all the active units currently loaded -local active_units = df.global.world.units.active -- get all active units - --- check every active unit for the bug -local num_fixed = 0 -- this is the number of army controllers fixed, not units - -- I've found that often, multiple sleepers share a bugged army controller -for k, unit in pairs(active_units) do - if unit then - local army_controller = unit.enemy.army_controller - if army_controller and army_controller.goal == df.army_controller_goal_type.CAMP then -- sleeping code is possible - if not army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER then - army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER = true -- fix bug - num_fixed = num_fixed + 1 - end - end - end -end - -if num_fixed == 0 then - print ("No sleepers with the fixable bug were found, sorry.") -else - print ("Fixed " .. num_fixed .. " bugged army_controller(s).") -end diff --git a/changelog.txt b/changelog.txt index 40cbd9e6fa..504c6f88e6 100644 --- a/changelog.txt +++ b/changelog.txt @@ -35,6 +35,7 @@ Template for new versions: - `gui/tiletypes`: interface for modifying map tiles and tile properties - `fix/population-cap`: fixes the situation where you continue to get migrant waves even when you are above your configured population cap - `fix/occupancy`: fixes issues where you can't build somewhere because the game tells you an item/unit/building is in the way but there's nothing there +- `fix/sleepers`: (reinstated) fixes sleeping units belonging to a camp that never wake up. ## New Features - `buildingplan`: dimension tooltip is now displayed for constructions and buildings that are designated over an area diff --git a/docs/fix/sleepers.rst b/docs/fix/sleepers.rst new file mode 100644 index 0000000000..1b3a0bc6ae --- /dev/null +++ b/docs/fix/sleepers.rst @@ -0,0 +1,18 @@ +fix/sleepers +============ + +.. dfhack-tool:: + :summary: Fixes sleeping units belonging to a camp that never wake up. + :tags: adventure bugfix + +Fixes :bug:`6798`. This bug is characterized by sleeping units who refuse to +awaken in adventure mode regardless of talking to them, hitting them, or waiting +so long you die of thirst. If you come accross one or more bugged sleepers in +adventure mode, simply run the script and all nearby sleepers will be cured. + +Usage +----- + +:: + + fix/sleepers diff --git a/fix/sleepers.lua b/fix/sleepers.lua new file mode 100644 index 0000000000..2f6b4bf101 --- /dev/null +++ b/fix/sleepers.lua @@ -0,0 +1,21 @@ +-- Number of fixed army controller(s) that may be shared by multiple units +local num_fixed = 0 + +-- Loop through all the active units currently loaded +for k, unit in pairs(df.global.world.units.active) do + local army_controller = unit.enemy.army_controller + -- Only Campers have been observed to sleep + if army_controller and army_controller.goal == df.army_controller_goal_type.CAMP then + if not army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER then + -- Intruder alert! Bloodthirsty adventurer is in the camp! + army_controller.data.goal_camp.camp_flag.ALARM_INTRUDER = true + num_fixed = num_fixed + 1 + end + end +end + +if num_fixed == 0 then + print ("No sleepers with the fixable bug were found, sorry.") +else + print ("Fixed " .. num_fixed .. " bugged army_controller(s).") +end From e9118d278272794d42500bd0e9a826c1b0bc37aa Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sat, 22 Jun 2024 16:14:48 +0300 Subject: [PATCH 3/6] remove old doc --- docs/adv-fix-sleepers.rst | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 docs/adv-fix-sleepers.rst diff --git a/docs/adv-fix-sleepers.rst b/docs/adv-fix-sleepers.rst deleted file mode 100644 index 111a743f43..0000000000 --- a/docs/adv-fix-sleepers.rst +++ /dev/null @@ -1,18 +0,0 @@ -adv-fix-sleepers -================ - -.. dfhack-tool:: - :summary: Fix units who refuse to awaken in adventure mode. - :tags: unavailable - -Use this tool if you encounter sleeping units who refuse to awaken regardless of -talking to them, hitting them, or waiting so long you die of thirst -(:bug:`6798`). If you come across one or more bugged sleepers in adventure -mode, simply run the script and all nearby sleepers will be cured. - -Usage ------ - -:: - - adv-fix-sleepers From ce35f368014eb3c4a69a5b8f92aa19f008c1f16d Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Tue, 25 Jun 2024 03:15:02 +0300 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Myk --- fix/sleepers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fix/sleepers.lua b/fix/sleepers.lua index 2f6b4bf101..1b7ed75fa8 100644 --- a/fix/sleepers.lua +++ b/fix/sleepers.lua @@ -2,7 +2,7 @@ local num_fixed = 0 -- Loop through all the active units currently loaded -for k, unit in pairs(df.global.world.units.active) do +for _, unit in ipairs(df.global.world.units.active) do local army_controller = unit.enemy.army_controller -- Only Campers have been observed to sleep if army_controller and army_controller.goal == df.army_controller_goal_type.CAMP then @@ -17,5 +17,5 @@ end if num_fixed == 0 then print ("No sleepers with the fixable bug were found, sorry.") else - print ("Fixed " .. num_fixed .. " bugged army_controller(s).") + print ("Fixed " .. num_fixed .. " group(s) of sleeping units.") end From 76dc7d0158e233fcd4ee9e3812fc54ef51535e7a Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Tue, 25 Jun 2024 03:16:53 +0300 Subject: [PATCH 5/6] adv-fix-sleepers added to removed section --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 504c6f88e6..cf5ae9f4fe 100644 --- a/changelog.txt +++ b/changelog.txt @@ -75,6 +75,7 @@ Template for new versions: - `max-wave`: merged into `pop-control` - `devel/find-offsets`, `devel/find-twbt`, `devel/prepare-save`: remove development scripts that are no longer useful - `fix/item-occupancy`, `fix/tile-occupancy`: merged into `fix/occupancy` +- `adv-fix-sleepers`: renamed into fix/sleepers # 50.13-r2 From e8d92dd9a9f4909d3d622aaa65b95f680ef4b7eb Mon Sep 17 00:00:00 2001 From: Myk Date: Mon, 24 Jun 2024 17:36:00 -0700 Subject: [PATCH 6/6] link to named script --- changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index cf5ae9f4fe..3b4efe153f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -75,7 +75,7 @@ Template for new versions: - `max-wave`: merged into `pop-control` - `devel/find-offsets`, `devel/find-twbt`, `devel/prepare-save`: remove development scripts that are no longer useful - `fix/item-occupancy`, `fix/tile-occupancy`: merged into `fix/occupancy` -- `adv-fix-sleepers`: renamed into fix/sleepers +- `adv-fix-sleepers`: renamed to `fix/sleepers` # 50.13-r2