Skip to content

Commit

Permalink
Merge pull request DFHack#3040 from myk002/myk_revflood
Browse files Browse the repository at this point in the history
[reveal] anchor revflood at a unit's position
  • Loading branch information
myk002 authored Mar 19, 2023
2 parents 490ffe1 + 4a3363d commit b03a35b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
9 changes: 5 additions & 4 deletions docs/plugins/reveal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ reveal
:summary: Switch between reveal and unreveal.

.. dfhack-command:: revflood
:summary: Hide everything, then reveal tiles with a path to the cursor.
:summary: Hide everything, then reveal tiles with a path to a unit.

.. dfhack-command:: nopause
:summary: Disable pausing.
Expand All @@ -44,9 +44,10 @@ Usage
where (for example) you abandoned with the fort revealed and no longer need
the saved map data when you load a new fort.
``revflood``
Hide everything, then reveal tiles with a path to the cursor. This allows
reparing maps that you accidentally saved while they were revealed. Note
that tiles behind constructed walls are also revealed as a workaround for
Hide everything, then reveal tiles with a path to the keyboard cursor (if
enabled) or the selected unit (if a unit is selected) or else a random citizen.
This allows reparing maps that you accidentally saved while they were revealed.
Note that tiles behind constructed walls are also revealed as a workaround for
:bug:`1871`.
``nopause 1|0``
Disables pausing (both manual and automatic) with the exception of the pause
Expand Down
30 changes: 21 additions & 9 deletions plugins/reveal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "modules/World.h"
#include "modules/MapCache.h"
#include "modules/Gui.h"
#include "modules/Units.h"
#include "modules/Screen.h"

#include "df/block_square_event_frozen_liquidst.h"
Expand Down Expand Up @@ -502,21 +503,32 @@ command_result revflood(color_ostream &out, vector<string> & params)
out.printerr("Only in proper dwarf mode.\n");
return CR_FAILURE;
}
int32_t cx, cy, cz;
df::coord pos;
Maps::getSize(x_max,y_max,z_max);

Gui::getCursorCoords(cx,cy,cz);
if(cx == -30000)
{
out.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n");
Gui::getCursorCoords(pos);
if (!pos.isValid()) {
df::unit *unit = Gui::getSelectedUnit(out, true);
if (unit)
pos = Units::getPosition(unit);
}

if (!pos.isValid()) {
vector<df::unit *> citizens;
Units::getCitizens(citizens);
if (citizens.size())
pos = Units::getPosition(citizens[0]);
}

if(!pos.isValid()) {
out.printerr("Please select a unit or place the keyboard cursor at some empty space you want to be unhidden.\n");
return CR_FAILURE;
}
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
MapCache * MCache = new MapCache;
df::tiletype tt = MCache->tiletypeAt(xy);
df::tiletype tt = MCache->tiletypeAt(pos);
if(isWallTerrain(tt))
{
out.printerr("Point the cursor at some empty space you want to be unhidden.\n");
out.printerr("Please select a unit or place the keyboard cursor at some empty space you want to be unhidden.\n");
delete MCache;
return CR_FAILURE;
}
Expand All @@ -534,7 +546,7 @@ command_result revflood(color_ostream &out, vector<string> & params)
}
MCache->trash();

unhideFlood_internal(MCache, xy);
unhideFlood_internal(MCache, pos);
MCache->WriteAll();
delete MCache;

Expand Down

0 comments on commit b03a35b

Please sign in to comment.