2011-06-19 20:29:38 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2021-06-02 15:49:19 -06:00
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2021-06-02 15:49:19 -06:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/World.h"
|
|
|
|
#include "modules/MapCache.h"
|
|
|
|
#include "modules/Gui.h"
|
2023-01-06 12:56:19 -07:00
|
|
|
#include "modules/Screen.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
#include "df/block_square_event_frozen_liquidst.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/construction.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
|
2011-08-01 19:48:59 -06:00
|
|
|
using MapExtras::MapCache;
|
2012-03-13 14:40:38 -06:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
using namespace DFHack;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2012-03-13 14:40:38 -06:00
|
|
|
|
2014-12-06 16:47:35 -07:00
|
|
|
DFHACK_PLUGIN("reveal");
|
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_active);
|
|
|
|
|
|
|
|
REQUIRE_GLOBAL(world);
|
2011-06-19 20:29:38 -06:00
|
|
|
|
2011-07-06 04:26:45 -06:00
|
|
|
/*
|
|
|
|
* Anything that might reveal Hell is unsafe.
|
|
|
|
*/
|
2012-01-19 21:36:34 -07:00
|
|
|
bool isSafe(df::coord c)
|
2011-07-06 04:26:45 -06:00
|
|
|
{
|
2012-03-13 14:40:38 -06:00
|
|
|
t_feature local_feature;
|
|
|
|
t_feature global_feature;
|
2011-07-06 04:26:45 -06:00
|
|
|
// get features of block
|
|
|
|
// error -> obviously not safe to manipulate
|
2012-01-19 21:36:34 -07:00
|
|
|
if(!Maps::ReadFeatures(c.x >> 4,c.y >> 4,c.z,&local_feature,&global_feature))
|
2011-07-06 04:26:45 -06:00
|
|
|
return false;
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2011-07-06 04:26:45 -06:00
|
|
|
// Adamantine tubes and temples lead to Hell
|
2012-01-21 17:31:15 -07:00
|
|
|
if (local_feature.type == feature_type::deep_special_tube || local_feature.type == feature_type::deep_surface_portal)
|
2011-07-06 04:26:45 -06:00
|
|
|
return false;
|
|
|
|
// And Hell *is* Hell.
|
2017-11-04 07:50:47 -06:00
|
|
|
if (global_feature.type == feature_type::underworld_from_layer)
|
2011-07-06 04:26:45 -06:00
|
|
|
return false;
|
|
|
|
// otherwise it's safe.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
struct hideblock
|
|
|
|
{
|
2012-01-19 21:36:34 -07:00
|
|
|
df::coord c;
|
2011-06-19 20:29:38 -06:00
|
|
|
uint8_t hiddens [16][16];
|
|
|
|
};
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
// the saved data. we keep map size to check if things still match
|
|
|
|
uint32_t x_max, y_max, z_max;
|
2012-03-13 14:40:38 -06:00
|
|
|
vector <hideblock> hidesaved;
|
2011-11-05 18:26:57 -06:00
|
|
|
bool nopause_state = false;
|
2011-07-06 04:26:45 -06:00
|
|
|
|
|
|
|
enum revealstate
|
|
|
|
{
|
|
|
|
NOT_REVEALED,
|
|
|
|
REVEALED,
|
2011-10-25 13:36:22 -06:00
|
|
|
SAFE_REVEALED,
|
|
|
|
DEMON_REVEALED
|
2011-07-06 04:26:45 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
revealstate revealed = NOT_REVEALED;
|
2011-06-24 21:35:29 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result reveal(color_ostream &out, vector<string> & params);
|
|
|
|
command_result unreveal(color_ostream &out, vector<string> & params);
|
|
|
|
command_result revtoggle(color_ostream &out, vector<string> & params);
|
|
|
|
command_result revflood(color_ostream &out, vector<string> & params);
|
|
|
|
command_result revforget(color_ostream &out, vector<string> & params);
|
|
|
|
command_result nopause(color_ostream &out, vector<string> & params);
|
2011-06-24 21:35:29 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, vector <PluginCommand> &commands)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
2022-07-29 18:12:15 -06:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"reveal",
|
|
|
|
"Reveal the map.",
|
|
|
|
reveal));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"unreveal",
|
|
|
|
"Revert a revealed map to its unrevealed state.",
|
|
|
|
unreveal));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"revtoggle",
|
|
|
|
"Switch betwen reveal and unreveal.",
|
|
|
|
revtoggle));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"revflood",
|
|
|
|
"Hide all, then reveal tiles reachable from the cursor.",
|
|
|
|
revflood));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"revforget",
|
|
|
|
"Forget the current reveal data.",
|
|
|
|
revforget));
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"nopause",
|
|
|
|
"Disable manual and automatic pausing.",
|
|
|
|
nopause));
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_onupdate ( color_ostream &out )
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
2011-11-05 18:26:57 -06:00
|
|
|
t_gamemodes gm;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::ReadGameMode(gm);
|
2012-06-16 04:42:56 -06:00
|
|
|
if(gm.g_mode == game_mode::DWARF)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
2011-11-05 18:26:57 -06:00
|
|
|
// if the map is revealed and we're in fortress mode, force the game to pause.
|
|
|
|
if(revealed == REVEALED)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
2012-10-06 03:46:20 -06:00
|
|
|
World::SetPauseState(true);
|
2011-06-26 18:13:01 -06:00
|
|
|
}
|
2011-11-05 18:26:57 -06:00
|
|
|
else if(nopause_state)
|
|
|
|
{
|
2012-10-06 03:46:20 -06:00
|
|
|
World::SetPauseState(false);
|
2011-11-05 18:26:57 -06:00
|
|
|
}
|
2011-06-26 18:13:01 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result nopause (color_ostream &out, vector <string> & parameters)
|
2011-11-05 18:26:57 -06:00
|
|
|
{
|
|
|
|
if (parameters.size() == 1 && (parameters[0] == "0" || parameters[0] == "1"))
|
|
|
|
{
|
|
|
|
if (parameters[0] == "0")
|
|
|
|
nopause_state = 0;
|
|
|
|
else
|
|
|
|
nopause_state = 1;
|
2013-09-30 03:19:51 -06:00
|
|
|
is_active = nopause_state || (revealed == REVEALED);
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("nopause %sactivated.\n", (nopause_state ? "" : "de"));
|
2011-11-05 18:26:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Disable pausing (doesn't affect pause forced by reveal).\nActivate with 'nopause 1', deactivate with 'nopause 0'.\nCurrent state: %d.\n", nopause_state);
|
2011-11-05 18:26:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
void revealAdventure(color_ostream &out)
|
2012-03-01 21:52:40 -07:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
|
|
|
|
{
|
|
|
|
df::map_block *block = world->map.map_blocks[i];
|
|
|
|
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
|
2014-07-21 12:26:34 -06:00
|
|
|
if (!isSafe(block->map_pos))
|
|
|
|
continue;
|
2012-03-13 14:40:38 -06:00
|
|
|
designations40d & designations = block->designation;
|
2012-03-01 21:52:40 -07:00
|
|
|
// for each tile in block
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
{
|
|
|
|
// set to revealed
|
|
|
|
designations[x][y].bits.hidden = 0;
|
|
|
|
// and visible
|
|
|
|
designations[x][y].bits.pile = 1;
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Local map revealed.\n");
|
2012-03-01 21:52:40 -07:00
|
|
|
}
|
2011-11-05 18:26:57 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result reveal(color_ostream &out, vector<string> & params)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2011-07-09 05:52:00 -06:00
|
|
|
bool no_hell = true;
|
2011-10-25 13:36:22 -06:00
|
|
|
bool pause = true;
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < params.size();i++)
|
2011-08-14 00:42:21 -06:00
|
|
|
{
|
|
|
|
if(params[i]=="hell")
|
|
|
|
no_hell = false;
|
|
|
|
else if(params[i] == "help" || params[i] == "?")
|
2013-10-30 14:58:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2011-08-14 00:42:21 -06:00
|
|
|
}
|
2023-01-06 12:56:19 -07:00
|
|
|
auto& con = out;
|
2011-07-09 05:52:00 -06:00
|
|
|
if(params.size() && params[0] == "hell")
|
2011-07-06 04:26:45 -06:00
|
|
|
{
|
2011-07-09 05:52:00 -06:00
|
|
|
no_hell = false;
|
2011-07-06 04:26:45 -06:00
|
|
|
}
|
2011-10-25 13:36:22 -06:00
|
|
|
if(params.size() && params[0] == "demon")
|
|
|
|
{
|
2023-01-06 12:56:19 -07:00
|
|
|
con.printerr("`reveal demon` is currently disabled to prevent a hang due to a bug in the base game\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
//no_hell = false;
|
|
|
|
//pause = false;
|
2011-10-25 13:36:22 -06:00
|
|
|
}
|
2011-07-06 04:26:45 -06:00
|
|
|
if(revealed != NOT_REVEALED)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
2011-07-15 07:55:01 -06:00
|
|
|
con.printerr("Map is already revealed or this is a different map.\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-07-06 04:26:45 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2012-03-01 21:52:40 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2012-03-01 21:52:40 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-26 18:13:01 -06:00
|
|
|
t_gamemodes gm;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::ReadGameMode(gm);
|
2012-06-16 04:42:56 -06:00
|
|
|
if(gm.g_mode == game_mode::ADVENTURE)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
revealAdventure(out);
|
2012-03-01 21:52:40 -07:00
|
|
|
return CR_OK;
|
2011-06-26 18:13:01 -06:00
|
|
|
}
|
2012-06-16 04:42:56 -06:00
|
|
|
if(gm.g_mode != game_mode::DWARF)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2012-03-01 21:52:40 -07:00
|
|
|
con.printerr("Only in fortress mode.\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_FAILURE;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::getSize(x_max,y_max,z_max);
|
2014-08-31 10:43:19 -06:00
|
|
|
hidesaved.reserve(world->map.map_blocks.size());
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2012-01-19 21:36:34 -07:00
|
|
|
df::map_block *block = world->map.map_blocks[i];
|
|
|
|
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
|
|
|
|
if (no_hell && !isSafe(block->map_pos))
|
|
|
|
continue;
|
|
|
|
hideblock hb;
|
|
|
|
hb.c = block->map_pos;
|
2012-03-13 14:40:38 -06:00
|
|
|
designations40d & designations = block->designation;
|
2012-01-19 21:36:34 -07:00
|
|
|
// for each tile in block
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2012-01-19 21:36:34 -07:00
|
|
|
// save hidden state of tile
|
|
|
|
hb.hiddens[x][y] = designations[x][y].bits.hidden;
|
|
|
|
// set to revealed
|
|
|
|
designations[x][y].bits.hidden = 0;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
2012-01-19 21:36:34 -07:00
|
|
|
hidesaved.push_back(hb);
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
2011-07-06 04:26:45 -06:00
|
|
|
if(no_hell)
|
|
|
|
{
|
|
|
|
revealed = SAFE_REVEALED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-25 13:36:22 -06:00
|
|
|
if(pause)
|
|
|
|
{
|
|
|
|
revealed = REVEALED;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::SetPauseState(true);
|
2011-10-25 13:36:22 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
revealed = DEMON_REVEALED;
|
2011-07-06 04:26:45 -06:00
|
|
|
}
|
2013-09-30 03:19:51 -06:00
|
|
|
is_active = nopause_state || (revealed == REVEALED);
|
2023-01-06 12:56:19 -07:00
|
|
|
bool graphics_mode = Screen::inGraphicsMode();
|
2023-01-06 13:34:59 -07:00
|
|
|
con.print("Map revealed.\n\n");
|
2023-01-06 12:56:19 -07:00
|
|
|
if (graphics_mode) {
|
|
|
|
con.print("Note that in graphics mode, tiles that are not adjacent to open\n"
|
|
|
|
"space will not render but can still be examined by hovering over\n"
|
|
|
|
"them with the mouse. Switching to text mode (in the game settings)\n"
|
2023-01-06 13:34:59 -07:00
|
|
|
"will allow the display the revealed tiles.\n\n");
|
2023-01-06 12:56:19 -07:00
|
|
|
}
|
2011-07-06 04:52:16 -06:00
|
|
|
if(!no_hell)
|
2023-01-06 13:34:59 -07:00
|
|
|
con.print("Unpausing can unleash the forces of hell, so it has been temporarily disabled.\n\n");
|
2011-07-15 07:55:01 -06:00
|
|
|
con.print("Run 'unreveal' to revert to previous state.\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result unreveal(color_ostream &out, vector<string> & params)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
auto & con = out;
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < params.size();i++)
|
2011-08-14 00:42:21 -06:00
|
|
|
{
|
|
|
|
if(params[i] == "help" || params[i] == "?")
|
2013-10-30 14:58:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2011-08-14 00:42:21 -06:00
|
|
|
}
|
2011-06-24 21:35:29 -06:00
|
|
|
if(!revealed)
|
|
|
|
{
|
2011-07-15 07:55:01 -06:00
|
|
|
con.printerr("There's nothing to revert!\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-19 20:44:17 -07:00
|
|
|
|
2012-03-01 21:52:40 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2012-03-01 21:52:40 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-26 18:13:01 -06:00
|
|
|
t_gamemodes gm;
|
2012-10-06 03:46:20 -06:00
|
|
|
World::ReadGameMode(gm);
|
2012-06-16 04:42:56 -06:00
|
|
|
if(gm.g_mode != game_mode::DWARF)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
2011-07-15 07:55:01 -06:00
|
|
|
con.printerr("Only in fortress mode.\n");
|
2011-06-26 18:13:01 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
// Sanity check: map size
|
|
|
|
uint32_t x_max_b, y_max_b, z_max_b;
|
2012-01-19 20:44:17 -07:00
|
|
|
Maps::getSize(x_max_b,y_max_b,z_max_b);
|
2011-06-24 21:35:29 -06:00
|
|
|
if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b)
|
|
|
|
{
|
2011-07-15 07:55:01 -06:00
|
|
|
con.printerr("The map is not of the same size...\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
for(size_t i = 0; i < hidesaved.size();i++)
|
|
|
|
{
|
|
|
|
hideblock & hb = hidesaved[i];
|
2012-04-11 02:01:27 -06:00
|
|
|
df::map_block * b = Maps::getTileBlock(hb.c.x,hb.c.y,hb.c.z);
|
2012-01-19 21:36:34 -07:00
|
|
|
for (uint32_t x = 0; x < 16;x++) for (uint32_t y = 0; y < 16;y++)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2012-01-19 21:36:34 -07:00
|
|
|
b->designation[x][y].bits.hidden = hb.hiddens[x][y];
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 21:35:29 -06:00
|
|
|
// give back memory.
|
|
|
|
hidesaved.clear();
|
2011-07-06 04:26:45 -06:00
|
|
|
revealed = NOT_REVEALED;
|
2013-09-30 03:19:51 -06:00
|
|
|
is_active = nopause_state || (revealed == REVEALED);
|
2011-07-15 07:55:01 -06:00
|
|
|
con.print("Map hidden!\n");
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result revtoggle (color_ostream &out, vector<string> & params)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < params.size();i++)
|
2011-08-14 00:42:21 -06:00
|
|
|
{
|
|
|
|
if(params[i] == "help" || params[i] == "?")
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Toggles between reveal and unreveal.\nCurrently it: ");
|
2011-08-14 00:42:21 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-24 21:35:29 -06:00
|
|
|
if(revealed)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return unreveal(out,params);
|
2011-06-24 21:35:29 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return reveal(out,params);
|
2011-06-24 21:35:29 -06:00
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
2011-08-01 19:48:59 -06:00
|
|
|
|
2021-06-02 15:49:19 -06:00
|
|
|
// Unhides map tiles according to visibility, starting from the given
|
|
|
|
// coordinates. This algorithm only processes adjacent hidden tiles, so it must
|
|
|
|
// start on a hidden tile and it will not reveal hidden sections separated by
|
|
|
|
// already-unhidden tiles.
|
|
|
|
static void unhideFlood_internal(MapCache *MCache, const DFCoord &xy)
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
|
|
|
typedef std::pair <DFCoord, bool> foo;
|
|
|
|
std::stack < foo > flood;
|
|
|
|
flood.push( foo(xy,false) );
|
|
|
|
|
|
|
|
while( !flood.empty() )
|
|
|
|
{
|
|
|
|
foo tile = flood.top();
|
|
|
|
DFCoord & current = tile.first;
|
|
|
|
bool & from_below = tile.second;
|
|
|
|
flood.pop();
|
|
|
|
|
|
|
|
if(!MCache->testCoord(current))
|
|
|
|
continue;
|
2012-01-19 13:11:52 -07:00
|
|
|
df::tile_designation des = MCache->designationAt(current);
|
2011-08-01 19:48:59 -06:00
|
|
|
if(!des.bits.hidden)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-07 13:23:33 -06:00
|
|
|
|
2018-06-09 14:19:52 -06:00
|
|
|
// we don't want constructions or ice to restrict vision (to avoid bug #1871)
|
|
|
|
// so use the base tile beneath it
|
2017-05-07 13:23:33 -06:00
|
|
|
df::tiletype tt = MCache->baseTiletypeAt(current);
|
|
|
|
|
2018-06-09 14:19:52 -06:00
|
|
|
// UNLESS the actual tile has more visibility than the base
|
|
|
|
// i.e. if it's a downward or up/down stairway
|
2017-05-07 13:23:33 -06:00
|
|
|
df::tiletype ctt = MCache->tiletypeAt(current);
|
|
|
|
switch (tileShape(ctt))
|
|
|
|
{
|
|
|
|
case tiletype_shape::STAIR_UPDOWN:
|
|
|
|
case tiletype_shape::STAIR_DOWN:
|
|
|
|
tt = ctt;
|
|
|
|
break;
|
2018-04-06 00:18:15 -06:00
|
|
|
default:
|
|
|
|
break;
|
2017-05-07 13:23:33 -06:00
|
|
|
}
|
|
|
|
|
2018-06-09 14:19:52 -06:00
|
|
|
bool below = false;
|
|
|
|
bool above = false;
|
|
|
|
bool sides = false;
|
|
|
|
bool unhide = true;
|
|
|
|
// By tile shape, determine behavior and action
|
2012-02-13 18:17:38 -07:00
|
|
|
switch (tileShape(tt))
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
2018-06-09 14:19:52 -06:00
|
|
|
// Walls
|
2012-02-13 18:17:38 -07:00
|
|
|
case tiletype_shape::WALL:
|
2018-06-09 14:19:52 -06:00
|
|
|
if (from_below)
|
|
|
|
unhide = false;
|
2012-02-13 18:17:38 -07:00
|
|
|
break;
|
2018-06-09 14:19:52 -06:00
|
|
|
// Open space
|
2018-04-06 00:18:15 -06:00
|
|
|
case tiletype_shape::NONE:
|
2012-02-13 18:17:38 -07:00
|
|
|
case tiletype_shape::EMPTY:
|
|
|
|
case tiletype_shape::RAMP_TOP:
|
|
|
|
case tiletype_shape::STAIR_UPDOWN:
|
|
|
|
case tiletype_shape::STAIR_DOWN:
|
|
|
|
case tiletype_shape::BROOK_TOP:
|
|
|
|
above = below = sides = true;
|
|
|
|
break;
|
2018-06-09 14:19:52 -06:00
|
|
|
// Floors
|
2012-02-13 18:17:38 -07:00
|
|
|
case tiletype_shape::FORTIFICATION:
|
|
|
|
case tiletype_shape::STAIR_UP:
|
|
|
|
case tiletype_shape::RAMP:
|
|
|
|
case tiletype_shape::FLOOR:
|
2014-07-21 12:18:29 -06:00
|
|
|
case tiletype_shape::BRANCH:
|
|
|
|
case tiletype_shape::TRUNK_BRANCH:
|
|
|
|
case tiletype_shape::TWIG:
|
2012-02-13 18:17:38 -07:00
|
|
|
case tiletype_shape::SAPLING:
|
|
|
|
case tiletype_shape::SHRUB:
|
|
|
|
case tiletype_shape::BOULDER:
|
|
|
|
case tiletype_shape::PEBBLES:
|
|
|
|
case tiletype_shape::BROOK_BED:
|
|
|
|
case tiletype_shape::ENDLESS_PIT:
|
2018-06-09 14:19:52 -06:00
|
|
|
if (from_below)
|
|
|
|
unhide = false;
|
|
|
|
else
|
|
|
|
above = sides = true;
|
2012-02-13 18:17:38 -07:00
|
|
|
break;
|
2011-08-01 19:48:59 -06:00
|
|
|
}
|
2018-06-09 14:19:52 -06:00
|
|
|
// Special case for trees - always reveal them as if they were floor tiles
|
2014-07-21 12:18:29 -06:00
|
|
|
if (tileMaterial(tt) == tiletype_material::PLANT || tileMaterial(tt) == tiletype_material::MUSHROOM)
|
|
|
|
{
|
2018-06-09 14:19:52 -06:00
|
|
|
if (from_below)
|
|
|
|
unhide = false;
|
|
|
|
else
|
|
|
|
above = sides = true;
|
2014-07-21 12:18:29 -06:00
|
|
|
}
|
2018-06-09 14:19:52 -06:00
|
|
|
if (unhide)
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
|
|
|
des.bits.hidden = false;
|
2018-06-09 14:19:52 -06:00
|
|
|
MCache->setDesignationAt(current, des);
|
2011-08-01 19:48:59 -06:00
|
|
|
}
|
2018-06-09 14:19:52 -06:00
|
|
|
if (sides)
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
2018-06-09 14:19:52 -06:00
|
|
|
// Scan adjacent tiles clockwise, starting toward east
|
|
|
|
flood.push(foo(DFCoord(current.x + 1, current.y , current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x + 1, current.y + 1, current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x , current.y + 1, current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x - 1, current.y + 1, current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x - 1, current.y , current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x - 1, current.y - 1, current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x , current.y - 1, current.z), false));
|
|
|
|
flood.push(foo(DFCoord(current.x + 1, current.y - 1, current.z), false));
|
2011-08-01 19:48:59 -06:00
|
|
|
}
|
2018-06-09 14:19:52 -06:00
|
|
|
if (above)
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
2018-06-09 14:19:52 -06:00
|
|
|
flood.push(foo(DFCoord(current.x, current.y, current.z + 1), true));
|
2011-08-01 19:48:59 -06:00
|
|
|
}
|
2018-06-09 14:19:52 -06:00
|
|
|
if (below)
|
2011-08-01 19:48:59 -06:00
|
|
|
{
|
2018-06-09 14:19:52 -06:00
|
|
|
flood.push(foo(DFCoord(current.x, current.y, current.z - 1), false));
|
2011-08-01 19:48:59 -06:00
|
|
|
}
|
|
|
|
}
|
2021-06-02 15:49:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lua entrypoint for unhideFlood_internal
|
|
|
|
static void unhideFlood(DFCoord pos)
|
|
|
|
{
|
|
|
|
MapCache MCache;
|
2021-06-05 15:45:09 -06:00
|
|
|
// no environment or bounds checking needed. if anything is invalid,
|
|
|
|
// unhideFlood_internal will just exit immeditately
|
2021-06-02 15:49:19 -06:00
|
|
|
unhideFlood_internal(&MCache, pos);
|
|
|
|
MCache.WriteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result revflood(color_ostream &out, vector<string> & params)
|
|
|
|
{
|
|
|
|
for(size_t i = 0; i < params.size();i++)
|
|
|
|
{
|
|
|
|
if(params[i] == "help" || params[i] == "?")
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
CoreSuspender suspend;
|
|
|
|
uint32_t x_max,y_max,z_max;
|
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
out.printerr("Map is not available!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
if(revealed != NOT_REVEALED)
|
|
|
|
{
|
|
|
|
out.printerr("This is only safe to use with non-revealed map.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
t_gamemodes gm;
|
|
|
|
World::ReadGameMode(gm);
|
|
|
|
if(!World::isFortressMode(gm.g_type) || gm.g_mode != game_mode::DWARF )
|
|
|
|
{
|
|
|
|
out.printerr("Only in proper dwarf mode.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
int32_t cx, cy, cz;
|
|
|
|
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");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
|
|
|
|
MapCache * MCache = new MapCache;
|
|
|
|
df::tiletype tt = MCache->tiletypeAt(xy);
|
|
|
|
if(isWallTerrain(tt))
|
|
|
|
{
|
|
|
|
out.printerr("Point the cursor at some empty space you want to be unhidden.\n");
|
|
|
|
delete MCache;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
// hide all tiles, flush cache
|
|
|
|
Maps::getSize(x_max,y_max,z_max);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < world->map.map_blocks.size(); i++)
|
|
|
|
{
|
|
|
|
df::map_block * b = world->map.map_blocks[i];
|
|
|
|
// change the hidden flag to 0
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
{
|
|
|
|
b->designation[x][y].bits.hidden = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MCache->trash();
|
|
|
|
|
|
|
|
unhideFlood_internal(MCache, xy);
|
2011-08-01 19:48:59 -06:00
|
|
|
MCache->WriteAll();
|
|
|
|
delete MCache;
|
2021-06-02 15:49:19 -06:00
|
|
|
|
2011-08-01 19:48:59 -06:00
|
|
|
return CR_OK;
|
2012-01-15 13:54:14 -07:00
|
|
|
}
|
2012-03-11 15:25:30 -06:00
|
|
|
|
2012-03-13 14:40:38 -06:00
|
|
|
command_result revforget(color_ostream &out, vector<string> & params)
|
2012-03-11 15:25:30 -06:00
|
|
|
{
|
|
|
|
auto & con = out;
|
|
|
|
for(size_t i = 0; i < params.size();i++)
|
|
|
|
{
|
|
|
|
if(params[i] == "help" || params[i] == "?")
|
2013-10-30 14:58:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2012-03-11 15:25:30 -06:00
|
|
|
}
|
|
|
|
if(!revealed)
|
|
|
|
{
|
|
|
|
con.printerr("There's nothing to forget!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
// give back memory.
|
|
|
|
hidesaved.clear();
|
|
|
|
revealed = NOT_REVEALED;
|
2013-09-30 03:19:51 -06:00
|
|
|
is_active = nopause_state || (revealed == REVEALED);
|
2012-03-11 15:25:30 -06:00
|
|
|
con.print("Reveal data forgotten!\n");
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2021-06-02 15:49:19 -06:00
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
DFHACK_LUA_FUNCTION(unhideFlood),
|
|
|
|
DFHACK_LUA_END
|
|
|
|
};
|