2011-06-19 20:29:38 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <dfhack/Core.h>
|
2011-06-22 00:14:21 -06:00
|
|
|
#include <dfhack/Console.h>
|
2011-06-19 20:29:38 -06:00
|
|
|
#include <dfhack/Export.h>
|
2011-06-24 21:35:29 -06:00
|
|
|
#include <dfhack/PluginManager.h>
|
2011-06-19 20:29:38 -06:00
|
|
|
#include <dfhack/modules/Maps.h>
|
|
|
|
#include <dfhack/modules/World.h>
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
using namespace DFHack;
|
2011-06-19 20:29:38 -06:00
|
|
|
|
2011-07-06 04:26:45 -06:00
|
|
|
/*
|
|
|
|
* Anything that might reveal Hell is unsafe.
|
|
|
|
*/
|
|
|
|
bool isSafe(uint32_t x, uint32_t y, uint32_t z, DFHack::Maps *Maps)
|
|
|
|
{
|
|
|
|
DFHack::t_feature *local_feature = NULL;
|
|
|
|
DFHack::t_feature *global_feature = NULL;
|
|
|
|
// get features of block
|
|
|
|
// error -> obviously not safe to manipulate
|
|
|
|
if(!Maps->ReadFeatures(x,y,z,&local_feature,&global_feature))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Adamantine tubes and temples lead to Hell
|
|
|
|
if (local_feature && local_feature->type != DFHack::feature_Other)
|
|
|
|
return false;
|
|
|
|
// And Hell *is* Hell.
|
|
|
|
if (global_feature && global_feature->type == DFHack::feature_Underworld)
|
|
|
|
return false;
|
|
|
|
// otherwise it's safe.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
struct hideblock
|
|
|
|
{
|
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
uint32_t z;
|
|
|
|
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;
|
|
|
|
std::vector <hideblock> hidesaved;
|
2011-07-06 04:26:45 -06:00
|
|
|
|
|
|
|
enum revealstate
|
|
|
|
{
|
|
|
|
NOT_REVEALED,
|
|
|
|
REVEALED,
|
|
|
|
SAFE_REVEALED
|
|
|
|
};
|
|
|
|
|
|
|
|
revealstate revealed = NOT_REVEALED;
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> & params);
|
|
|
|
DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string> & params);
|
2011-07-09 05:52:00 -06:00
|
|
|
DFhackCExport command_result revtoggle(DFHack::Core * c, std::vector<std::string> & params);
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "reveal";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2011-07-09 05:52:00 -06:00
|
|
|
commands.push_back(PluginCommand("reveal","Reveal the map. 'reveal hell' will also reveal hell.",reveal));
|
2011-06-24 21:35:29 -06:00
|
|
|
commands.push_back(PluginCommand("unreveal","Revert the map to its previous state.",unreveal));
|
2011-07-09 05:52:00 -06:00
|
|
|
commands.push_back(PluginCommand("revtoggle","Reveal/unreveal depending on state.",revtoggle));
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-26 18:13:01 -06:00
|
|
|
DFhackCExport command_result plugin_onupdate ( Core * c )
|
|
|
|
{
|
|
|
|
// if the map is revealed and we're in fortress mode, force the game to pause.
|
2011-07-06 04:26:45 -06:00
|
|
|
if(revealed == REVEALED)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
|
|
|
DFHack::World *World =c->getWorld();
|
|
|
|
t_gamemodes gm;
|
|
|
|
World->ReadGameMode(gm);
|
2011-07-06 03:13:36 -06:00
|
|
|
if(gm.g_mode == GAMEMODE_DWARF)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
|
|
|
World->SetPauseState(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2011-07-09 05:52:00 -06:00
|
|
|
bool no_hell = true;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if(revealed != NOT_REVEALED)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
|
|
|
dfout << "Map is already revealed or this is a different map." << std::endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-07-06 04:26:45 -06:00
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
c->Suspend();
|
|
|
|
DFHack::Maps *Maps =c->getMaps();
|
|
|
|
DFHack::World *World =c->getWorld();
|
2011-06-26 18:13:01 -06:00
|
|
|
t_gamemodes gm;
|
|
|
|
World->ReadGameMode(gm);
|
2011-07-06 03:13:36 -06:00
|
|
|
if(gm.g_mode != GAMEMODE_DWARF)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
|
|
|
dfout << "Only in fortress mode." << std::endl;
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
if(!Maps->Start())
|
|
|
|
{
|
2011-06-22 00:14:21 -06:00
|
|
|
dfout << "Can't init map." << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
c->Resume();
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_FAILURE;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
|
2011-07-06 04:26:45 -06:00
|
|
|
if(no_hell && !Maps->StartFeatures())
|
|
|
|
{
|
|
|
|
dfout << "Unable to read local features; can't reveal map safely" << std::endl;
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
Maps->getSize(x_max,y_max,z_max);
|
2011-06-24 21:35:29 -06:00
|
|
|
hidesaved.reserve(x_max * y_max * z_max);
|
2011-06-19 20:29:38 -06:00
|
|
|
for(uint32_t x = 0; x< x_max;x++)
|
|
|
|
{
|
|
|
|
for(uint32_t y = 0; y< y_max;y++)
|
|
|
|
{
|
|
|
|
for(uint32_t z = 0; z< z_max;z++)
|
|
|
|
{
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block *block = Maps->getBlock(x,y,z);
|
|
|
|
if(block)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2011-07-06 04:26:45 -06:00
|
|
|
// in 'no-hell'/'safe' mode, don't reveal blocks with hell and adamantine
|
|
|
|
if (no_hell && !isSafe(x, y, z, Maps))
|
|
|
|
continue;
|
2011-06-19 20:29:38 -06:00
|
|
|
hideblock hb;
|
|
|
|
hb.x = x;
|
|
|
|
hb.y = y;
|
|
|
|
hb.z = z;
|
2011-07-07 01:49:58 -06:00
|
|
|
DFHack::designations40d & designations = block->designation;
|
|
|
|
// for each tile in block
|
2011-06-19 20:29:38 -06:00
|
|
|
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
|
|
|
|
{
|
2011-07-07 01:49:58 -06:00
|
|
|
// save hidden state of tile
|
2011-06-19 20:29:38 -06:00
|
|
|
hb.hiddens[i][j] = designations[i][j].bits.hidden;
|
2011-07-07 01:49:58 -06:00
|
|
|
// set to revealed
|
2011-06-19 20:29:38 -06:00
|
|
|
designations[i][j].bits.hidden = 0;
|
|
|
|
}
|
|
|
|
hidesaved.push_back(hb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-06 04:26:45 -06:00
|
|
|
if(no_hell)
|
|
|
|
{
|
|
|
|
revealed = SAFE_REVEALED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
revealed = REVEALED;
|
|
|
|
World->SetPauseState(true);
|
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
c->Resume();
|
2011-06-26 18:13:01 -06:00
|
|
|
dfout << "Map revealed." << std::endl;
|
2011-07-06 04:52:16 -06:00
|
|
|
if(!no_hell)
|
2011-07-09 03:33:58 -06:00
|
|
|
dfout << "Unpausing can unleash the forces of hell, so it has been temporarily disabled." << std::endl;
|
2011-06-25 00:05:17 -06:00
|
|
|
dfout << "Run 'unreveal' to revert to previous state." << std::endl;
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string> & params)
|
|
|
|
{
|
|
|
|
DFHack::designations40d designations;
|
|
|
|
if(!revealed)
|
|
|
|
{
|
|
|
|
dfout << "There's nothing to revert!" << std::endl;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
c->Suspend();
|
2011-06-24 21:35:29 -06:00
|
|
|
DFHack::Maps *Maps =c->getMaps();
|
|
|
|
DFHack::World *World =c->getWorld();
|
2011-06-26 18:13:01 -06:00
|
|
|
t_gamemodes gm;
|
|
|
|
World->ReadGameMode(gm);
|
2011-07-06 03:13:36 -06:00
|
|
|
if(gm.g_mode != GAMEMODE_DWARF)
|
2011-06-26 18:13:01 -06:00
|
|
|
{
|
|
|
|
dfout << "Only in fortress mode." << std::endl;
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
Maps = c->getMaps();
|
2011-06-24 21:35:29 -06:00
|
|
|
if(!Maps->Start())
|
|
|
|
{
|
|
|
|
dfout << "Can't init map." << std::endl;
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sanity check: map size
|
|
|
|
uint32_t x_max_b, y_max_b, z_max_b;
|
|
|
|
Maps->getSize(x_max_b,y_max_b,z_max_b);
|
|
|
|
if(x_max != x_max_b || y_max != y_max_b || z_max != z_max_b)
|
|
|
|
{
|
|
|
|
dfout << "The map is not of the same size..." << std::endl;
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: add more sanity checks / MAP ID
|
|
|
|
|
2011-06-19 20:29:38 -06:00
|
|
|
for(size_t i = 0; i < hidesaved.size();i++)
|
|
|
|
{
|
|
|
|
hideblock & hb = hidesaved[i];
|
2011-07-07 01:49:58 -06:00
|
|
|
df_block * b = Maps->getBlock(hb.x,hb.y,hb.z);
|
2011-06-19 20:29:38 -06:00
|
|
|
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
|
|
|
|
{
|
2011-07-07 01:49:58 -06:00
|
|
|
b->designation[i][j].bits.hidden = hb.hiddens[i][j];
|
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;
|
2011-06-25 00:05:17 -06:00
|
|
|
dfout << "Map hidden!" << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
c->Resume();
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:52:00 -06:00
|
|
|
DFhackCExport command_result revtoggle (DFHack::Core * c, std::vector<std::string> & params)
|
2011-06-24 21:35:29 -06:00
|
|
|
{
|
|
|
|
if(revealed)
|
|
|
|
{
|
|
|
|
return unreveal(c,params);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return reveal(c,params);
|
|
|
|
}
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|