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..63cb40b810 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 ``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()`` @@ -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..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 dfhack.world.isAdventureMode() 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 dfhack.world.isAdventureMode() then + if df.global.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 df.global.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..703e6a4001 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())