the annotated colours when saving. Fixed by adding the ability to store arbitrary exit hooks to be executed on (unusual) shutdown; for now they're executed FIFO, but it should probably be LIFO with a stack. Anyway the only thing that uses this now is the range view annotator. Oh, and it only works if you're using libunix.cc.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8999 c06c8d41-db1a-0410-9941-cceddc491573
QX7GM3YZFUBCXTLQIKF27YOPKYR2655HYRWSNTDXXI6CTH4XEP7AC
IH5TVAZGKN7IQOTSOJ56WG5C3CMTG3AI63XT3XVNHC7DI4N2TSUAC
OIAQU4VDTZ3EHBNC7FZIOW2QEQLTDHZ7O46XW2YWM6JRVBC66UPQC
IQGGFC563RBS7GDOACKCLXK752EE5RC3T6G5L6H446SXTMSA7T2AC
SVY2PTCLXR3KNPQAWXVXTTGCC5DR334HOAKHYO3VDDRWM2BWMALAC
AVCMVFA3MKCXHO6H44UK5KJNIHTGQV7UA7GYXM26VI6TXXU5ZN6QC
YRY2TC3VHOYE47M23UJGUWDGF7H7WGU7WLWI4SUNM4EDNTGUPHGAC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
ZGZVOMRXLVC42FV67RBTLBOZWFYRL4UHL54A365BR76OUIYRWQXAC
IVVTHLTTLOP5TSULXJWUSSXHOKYWVU3OWKYVK45A7RIB6V34MYQAC
55PFDYPVE6JVGDYPCFUE4XS2523PVSV4CSIFRW6A2GGX4I6VWRWQC
FWVE7KM7BGEZUFQVM7H7UFGM3QMMPT7QHLNXSP62HG3SMBIPZBSQC
PI5BATR2SER3RFE76IUGHM2AGXVFOUM3PLU7WC2K2Q2BA5K2E73QC
SKWBAGSAB625IIN4UP3NCPRX2H3KCPC2LULHS2A7JVRLO3EUBJDAC
ON7HKKWM4CRYWNI5SZKKWI5Q5MVFOPC6QVKHXX3D66G7EOZEMGWAC
MSRJ3N4NX255RVISUOPTTTY2GG4JVVNNM76HWUZ2EKCYESNI6MLQC
F3STYUG6GEHXQX54YE6ZXXDJE3HWJ77SKHPL3F4GNKOQ43MEIRJQC
WEZLXS4OSKPX6ZFFZZKKEO4NKG2QC4AFANVC34IYNDAEDGWJJHLQC
#include "state.h"
class range_view_annotator : public crawl_exit_hook
{
public:
range_view_annotator(int range);
virtual ~range_view_annotator();
virtual void restore_state();
private:
bool do_anything;
FixedArray<int, ENV_SHOW_DIAMETER, ENV_SHOW_DIAMETER> orig_colours;
int orig_mon_colours[MAX_MONSTERS];
};
// last updated 12may2000 {dlb}
/* ***********************************************************************
* called from: acr - debug - effects - it_use3 - item_use - spells1 -
* spells2 - spells3 - spells4
* *********************************************************************** */
public:
range_view_annotator(int range) {
do_anything = (range >= 0);
if (range < 0)
return;
crawl_state.exit_hooks.erase(std::remove(crawl_state.exit_hooks.begin(),
crawl_state.exit_hooks.end(),
this),
crawl_state.exit_hooks.end());
}
// Restore grid colours.
coord_def c;
const coord_def offset(ENV_SHOW_OFFSET, ENV_SHOW_OFFSET);
for ( c.x = 0; c.x < ENV_SHOW_DIAMETER; ++c.x )
// Restore grid colours.
coord_def c;
const coord_def offset(ENV_SHOW_OFFSET, ENV_SHOW_OFFSET);
for ( c.x = 0; c.x < ENV_SHOW_DIAMETER; ++c.x )
{
for ( c.y = 0; c.y < ENV_SHOW_DIAMETER; ++c.y )
for ( c.y = 0; c.y < ENV_SHOW_DIAMETER; ++c.y )
{
const int old_colour = orig_colours(c);
if ( old_colour != -1 )
env.grid_colours(you.pos() + c - offset) = old_colour;
}
const int old_colour = orig_colours(c);
if ( old_colour != -1 )
env.grid_colours(you.pos() + c - offset) = old_colour;
// Restore monster colours.
for (int i = 0; i < MAX_MONSTERS; ++i)
if (orig_mon_colours[i] != -1)
menv[i].colour = orig_mon_colours[i];
// Restore monster colours.
for (int i = 0; i < MAX_MONSTERS; ++i)
if (orig_mon_colours[i] != -1)
menv[i].colour = orig_mon_colours[i];
// Repaint.
viewwindow(true, false);
}
private:
bool do_anything;
FixedArray<int, ENV_SHOW_DIAMETER, ENV_SHOW_DIAMETER> orig_colours;
int orig_mon_colours[MAX_MONSTERS];
};
do_anything = false;
}