Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2427,15 +2427,20 @@ 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()``

Returns the currently loaded ``df.world_site`` or ``nil`` if no site is loaded.

* ``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:

Expand Down
8 changes: 4 additions & 4 deletions library/lua/gui/dwarfmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,20 +49,20 @@ 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)
end
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
Expand Down
2 changes: 1 addition & 1 deletion library/modules/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions plugins/createitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -403,9 +401,8 @@ command_result df_createitem (color_ostream &out, vector<string> &parameters) {
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())
Expand Down
Loading