From 2b14162606354b5c24dac3bd55701c6d7bc2d3ef Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 4 Oct 2026 05:08:27 -0700 Subject: [PATCH 1/5] Fix `getAdventurer` in arena mode * Update World.cpp - Fix getAdventurer in arena * Update createitem.cpp - Simplify adventurer check * Update dwarfmode.lua - Fix adventure arena look cursor * Update Lua API.rst - Improve isAdventureMode doc * Update changelog.txt --- docs/changelog.txt | 4 ++++ docs/dev/Lua API.rst | 9 +++++++-- library/lua/gui/dwarfmode.lua | 8 ++++---- library/modules/World.cpp | 2 +- plugins/createitem.cpp | 5 +---- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 1e8961c7be..639bb4f02d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -60,10 +60,14 @@ Template for new versions: ## New Features ## Fixes +- ``World::getAdventurer``: properly detect adventurer in arena mode +- ``Units::getProfessionName``, ``Units::getCasteProfessionName``: now detects arena adventurer for default race name +- ``dwarfmode.lua``: properly handle adventure arena look cursor ## Misc Improvements ## Documentation +- ``dfhack.world.isAdventureMode``: doesn't include adventurer arena, advise checking gamemode ## API diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index ccc3c25e7d..337635171a 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2427,7 +2427,12 @@ World module * ``dfhack.world.isLegends([gametype])`` Without any arguments, returns *true* if the current gametype matches. - Optionally accepts a ``gametype`` id to match against. + Optionally accepts a ``gametype`` ID to match against. + + Be advised that ``isAdventureMode()`` does not detect adventure arena (controlling + arena unit). It may be desirable to test ``gamemode == df.game_mode.ADVENTURE`` + to allow for both, or ``gametype == df.game_type.ADVENTURE_ARENA`` to check for + just adventure arena, depending on your purpose. * ``dfhack.world.getCurrentSite()`` @@ -2435,7 +2440,7 @@ World module * ``dfhack.world.getAdventurer()`` - Returns the current adventurer unit (if in adventure mode). + Returns the current adventurer unit (if in adventure mode or adventure arena) else ``nil``. .. _lua-maps: diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index a0e50532e6..bfa6b33596 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -39,7 +39,7 @@ end ---@return df.coord|nil function getCursorPos() - if dfhack.world.isAdventureMode() then + if gamemode == df.game_mode.ADVENTURE then if a_look.open then return copyall(a_look.cursor) end @@ -49,7 +49,7 @@ function getCursorPos() end function setCursorPos(cursor) - if dfhack.world.isAdventureMode() then + if gamemode == df.game_mode.ADVENTURE then a_look.cursor = copyall(cursor) else df.global.cursor = copyall(cursor) @@ -57,12 +57,12 @@ function setCursorPos(cursor) end function clearCursorPos() - if dfhack.world.isAdventureMode() then + if gamemode == df.game_mode.ADVENTURE then if not a_look.open then return end local u = dfhack.world.getAdventurer() - if u and u.pos:isValid() then + if u and u.pos:isValid() then -- recenter on adventurer a_look.cursor = copyall(u.pos) end else diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 020e76127d..d4fd2e0682 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -208,7 +208,7 @@ bool World::isLegends(df::game_type t) } df::unit * World::getAdventurer() { - if (!isAdventureMode() || !world) + if (!world || !df::global::gamemode || *df::global::gamemode != game_mode::ADVENTURE) return NULL; return world->units.adv_unit; diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp index d813d8e44b..c2cb331b51 100644 --- a/plugins/createitem.cpp +++ b/plugins/createitem.cpp @@ -16,7 +16,6 @@ #include "df/building.h" #include "df/caste_raw.h" #include "df/creature_raw.h" -#include "df/game_type.h" #include "df/item.h" #include "df/plant_growth.h" #include "df/plant_raw.h" @@ -31,7 +30,6 @@ using namespace df::enums; DFHACK_PLUGIN("createitem"); REQUIRE_GLOBAL(world); -REQUIRE_GLOBAL(gametype); REQUIRE_GLOBAL(cur_year_tick); int dest_container = -1, dest_building = -1; @@ -403,9 +401,8 @@ command_result df_createitem (color_ostream &out, vector ¶meters) { auto unit = Gui::getSelectedUnit(out, true); if (!unit) { auto pos = Gui::getCursorPos(); - if (*gametype == game_type::ADVENTURE_ARENA || World::isAdventureMode()) + if (unit = World::getAdventurer()) { // Use the adventurer unit - unit = World::getAdventurer(); move_to_cursor = pos.isValid(); } else if (pos.isValid()) From 098b633c6438bdc6d14b0b63c94f2cbef3fe51bd Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 4 Oct 2026 12:33:55 -0700 Subject: [PATCH 2/5] Update createitem.cpp - Parentheses around assignment --- plugins/createitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp index c2cb331b51..703e6a4001 100644 --- a/plugins/createitem.cpp +++ b/plugins/createitem.cpp @@ -401,7 +401,7 @@ command_result df_createitem (color_ostream &out, vector ¶meters) { auto unit = Gui::getSelectedUnit(out, true); if (!unit) { auto pos = Gui::getCursorPos(); - if (unit = World::getAdventurer()) + if ( (unit = World::getAdventurer()) ) { // Use the adventurer unit move_to_cursor = pos.isValid(); } From c40c2088bbf7a05b66eb068d0b65b678f97b4f2d Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Mon, 5 Oct 2026 01:14:06 -0700 Subject: [PATCH 3/5] Prefix gamemode with df.global in Lua * Update Lua API.rst * Update dwarfmode.lua --- docs/dev/Lua API.rst | 4 ++-- library/lua/gui/dwarfmode.lua | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 337635171a..63cb40b810 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2430,8 +2430,8 @@ World module Optionally accepts a ``gametype`` ID to match against. Be advised that ``isAdventureMode()`` does not detect adventure arena (controlling - arena unit). It may be desirable to test ``gamemode == df.game_mode.ADVENTURE`` - to allow for both, or ``gametype == df.game_type.ADVENTURE_ARENA`` to check for + arena unit). It may be desirable to test ``df.global.gamemode == df.game_mode.ADVENTURE`` + to allow for both, or ``df.global.gametype == df.game_type.ADVENTURE_ARENA`` to check for just adventure arena, depending on your purpose. * ``dfhack.world.getCurrentSite()`` diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index bfa6b33596..cf330da949 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -39,7 +39,7 @@ end ---@return df.coord|nil function getCursorPos() - if gamemode == df.game_mode.ADVENTURE then + if df.global.gamemode == df.game_mode.ADVENTURE then if a_look.open then return copyall(a_look.cursor) end @@ -49,7 +49,7 @@ function getCursorPos() end function setCursorPos(cursor) - if gamemode == df.game_mode.ADVENTURE then + if df.global.gamemode == df.game_mode.ADVENTURE then a_look.cursor = copyall(cursor) else df.global.cursor = copyall(cursor) @@ -57,7 +57,7 @@ function setCursorPos(cursor) end function clearCursorPos() - if gamemode == df.game_mode.ADVENTURE then + if df.global.gamemode == df.game_mode.ADVENTURE then if not a_look.open then return end From a1a56a85ee4f698164b67ff80051e7fd1dcc1af3 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 6 Oct 2026 05:49:45 -0700 Subject: [PATCH 4/5] Update dwarfmode.lua - Make sure look is active before set --- library/lua/gui/dwarfmode.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index cf330da949..72807fed61 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -50,6 +50,9 @@ end function setCursorPos(cursor) if df.global.gamemode == df.game_mode.ADVENTURE then + if not a_look.open then + return + end a_look.cursor = copyall(cursor) else df.global.cursor = copyall(cursor) @@ -62,7 +65,7 @@ function clearCursorPos() return end local u = dfhack.world.getAdventurer() - if u and u.pos:isValid() then -- recenter on adventurer + if u and u.pos:isValid() then -- recenter cursor on adventurer a_look.cursor = copyall(u.pos) end else From 02ff813c76f82d8cd19883b41a051d4f4c5305af Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Tue, 6 Oct 2026 05:58:28 -0700 Subject: [PATCH 5/5] Update dwarfmode.lua - Use units.getPosition --- library/lua/gui/dwarfmode.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/lua/gui/dwarfmode.lua b/library/lua/gui/dwarfmode.lua index 72807fed61..f856e6281b 100644 --- a/library/lua/gui/dwarfmode.lua +++ b/library/lua/gui/dwarfmode.lua @@ -65,8 +65,9 @@ function clearCursorPos() return end local u = dfhack.world.getAdventurer() - if u and u.pos:isValid() then -- recenter cursor on adventurer - a_look.cursor = copyall(u.pos) + local pos = u and dfhack.units.getPosition(u) + if pos then -- recenter cursor on adventurer + a_look.cursor = copyall(pos) end else df.global.cursor = xyz2pos(nil)