2009-09-13 18:02:46 -06:00
|
|
|
// This is a reveal program. It reveals the map.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2010-05-23 15:06:10 -06:00
|
|
|
#include <map>
|
2009-09-13 18:02:46 -06:00
|
|
|
using namespace std;
|
|
|
|
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2011-07-05 17:32:43 -06:00
|
|
|
#include <dfhack/extra/MapExtras.h>
|
|
|
|
#include <xgetopt.h>
|
2010-09-03 23:43:39 -06:00
|
|
|
#include <dfhack/modules/Gui.h>
|
2010-04-17 14:08:16 -06:00
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
typedef std::vector<DFHack::t_feature*> FeatureListPointer;
|
|
|
|
typedef std::map<DFHack::DFCoord, FeatureListPointer> FeatureMap;
|
|
|
|
|
2010-09-20 16:44:41 -06:00
|
|
|
#ifdef LINUX_BUILD
|
|
|
|
#include <unistd.h>
|
|
|
|
void waitmsec (int delay)
|
|
|
|
{
|
|
|
|
usleep(delay);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#include <windows.h>
|
|
|
|
void waitmsec (int delay)
|
|
|
|
{
|
|
|
|
Sleep(delay);
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-17 00:36:38 -06:00
|
|
|
#include <dfhack/extra/termutil.h>
|
2010-09-20 16:44:41 -06:00
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
/*
|
|
|
|
* Anything that might reveal Hell is unsafe.
|
|
|
|
*/
|
|
|
|
bool isSafe(uint32_t x, uint32_t y, uint32_t z, DFHack::Maps *Maps,
|
|
|
|
MapExtras::MapCache &cache, FeatureMap localFeatures)
|
|
|
|
{
|
|
|
|
DFHack::t_feature *blockFeatureLocal = NULL;
|
|
|
|
|
|
|
|
DFHack::DFCoord blockCoord(x, y);
|
|
|
|
MapExtras::Block *b = cache.BlockAt(DFHack::DFCoord(x, y, z));
|
|
|
|
|
|
|
|
uint16_t index = b->raw.local_feature;
|
|
|
|
FeatureMap::const_iterator it = localFeatures.find(blockCoord);
|
|
|
|
if (it != localFeatures.end())
|
|
|
|
{
|
|
|
|
FeatureListPointer features = it->second;
|
|
|
|
|
|
|
|
if (index != -1 && index < features.size())
|
|
|
|
{
|
|
|
|
blockFeatureLocal = features[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blockFeatureLocal == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Adamantine tubes and temples lead to Hell, and Hell *is* Hell.
|
|
|
|
if (blockFeatureLocal->type != DFHack::feature_Other)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-17 14:08:16 -06:00
|
|
|
struct hideblock
|
|
|
|
{
|
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
uint32_t z;
|
|
|
|
uint8_t hiddens [16][16];
|
|
|
|
};
|
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
int main (int argc, char *argv[])
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-07-05 17:32:43 -06:00
|
|
|
bool doSafe = false;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
xgetopt opt(argc, argv, "s");
|
|
|
|
opt.opterr = 0;
|
|
|
|
|
|
|
|
while ((c = opt()) != -1)
|
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
doSafe = true;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
switch (opt.optopt)
|
|
|
|
{
|
|
|
|
// For when we take arguments
|
|
|
|
default:
|
|
|
|
if (isprint(opt.optopt))
|
|
|
|
std::cerr << "Unknown option -" << opt.optopt << "!"
|
|
|
|
<< std::endl;
|
|
|
|
else
|
|
|
|
std::cerr << "Unknown option character " << (int) opt.optopt << "!"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// Um.....
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-14 22:10:47 -06:00
|
|
|
bool temporary_terminal = TemporaryTerminal();
|
2009-09-13 18:02:46 -06:00
|
|
|
uint32_t x_max,y_max,z_max;
|
2010-03-25 14:37:09 -06:00
|
|
|
DFHack::designations40d designations;
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context *DF;
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
2009-09-13 18:02:46 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::Maps *Maps =DF->getMaps();
|
2011-03-18 04:38:37 -06:00
|
|
|
DFHack::World *World =DF->getWorld();
|
2011-07-05 17:32:43 -06:00
|
|
|
|
2010-09-03 23:43:39 -06:00
|
|
|
// walk the map, save the hide bits, reveal.
|
|
|
|
cout << "Pausing..." << endl;
|
|
|
|
|
|
|
|
// horrible hack to make sure the pause is really set
|
2010-09-08 19:36:11 -06:00
|
|
|
// preblem here is that we could be 'arriving' at the wrong time and DF could be in the middle of a frame.
|
|
|
|
// that could mean that revealing, even with suspending DF's thread, would mean unleashing hell *in the same frame*
|
|
|
|
// this here hack sets the pause state, resumes DF, waits a second for it to enter the pause (I know, BS value.) and suspends.
|
2011-03-18 04:38:37 -06:00
|
|
|
World->SetPauseState(true);
|
2010-09-03 23:43:39 -06:00
|
|
|
DF->Resume();
|
2010-09-20 16:44:41 -06:00
|
|
|
waitmsec(1000);
|
2010-09-03 23:43:39 -06:00
|
|
|
DF->Suspend();
|
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
cout << "Revealing, please wait..." << endl;
|
|
|
|
|
2010-03-26 06:01:46 -06:00
|
|
|
// init the map
|
2010-04-04 16:48:19 -06:00
|
|
|
if(!Maps->Start())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
|
|
|
cerr << "Can't init map." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
|
|
|
return 1;
|
|
|
|
}
|
2010-09-03 23:43:39 -06:00
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
MapExtras::MapCache cache(Maps);
|
|
|
|
FeatureMap localFeatures;
|
|
|
|
|
|
|
|
if(doSafe && !Maps->ReadLocalFeatures(localFeatures))
|
|
|
|
{
|
|
|
|
std::cerr << "Unable to read local features; can't reveal map "
|
|
|
|
<< "safely" << std::endl;
|
|
|
|
if(temporary_terminal)
|
|
|
|
cin.ignore();
|
|
|
|
return 1;
|
|
|
|
}
|
2010-09-03 23:43:39 -06:00
|
|
|
|
2010-04-04 16:48:19 -06:00
|
|
|
Maps->getSize(x_max,y_max,z_max);
|
2010-04-17 14:08:16 -06:00
|
|
|
vector <hideblock> hidesaved;
|
2010-09-03 23:43:39 -06:00
|
|
|
|
2011-07-05 17:32:43 -06:00
|
|
|
// We go from the top z-level down, stopping as soon as we encounter
|
|
|
|
// something that might lead to Hell, so the player can unpause without
|
|
|
|
// spawning demons.
|
|
|
|
bool quit = false;
|
|
|
|
for(uint32_t z = z_max - 1; z > 0 && !quit;z--)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-07-05 17:32:43 -06:00
|
|
|
for(uint32_t y = 0; y < y_max;y++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-07-05 17:32:43 -06:00
|
|
|
for(uint32_t x = 0; x < x_max;x++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-04-04 16:48:19 -06:00
|
|
|
if(Maps->isValidBlock(x,y,z))
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2011-07-05 17:32:43 -06:00
|
|
|
if (doSafe && !isSafe(x, y, z, Maps, cache, localFeatures))
|
|
|
|
quit = true;
|
|
|
|
|
2010-04-17 14:08:16 -06:00
|
|
|
hideblock hb;
|
|
|
|
hb.x = x;
|
|
|
|
hb.y = y;
|
|
|
|
hb.z = z;
|
2009-09-13 18:02:46 -06:00
|
|
|
// read block designations
|
2010-04-04 16:48:19 -06:00
|
|
|
Maps->ReadDesignations(x,y,z, &designations);
|
2009-09-13 18:02:46 -06:00
|
|
|
// change the hidden flag to 0
|
2010-03-25 14:37:09 -06:00
|
|
|
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-04-17 14:08:16 -06:00
|
|
|
hb.hiddens[i][j] = designations[i][j].bits.hidden;
|
2010-03-25 14:37:09 -06:00
|
|
|
designations[i][j].bits.hidden = 0;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2010-04-17 14:08:16 -06:00
|
|
|
hidesaved.push_back(hb);
|
2009-09-13 18:02:46 -06:00
|
|
|
// write the designations back
|
2010-04-04 16:48:19 -06:00
|
|
|
Maps->WriteDesignations(x,y,z, &designations);
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-17 14:08:16 -06:00
|
|
|
// FIXME: force game pause here!
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Detach();
|
2010-09-03 23:43:39 -06:00
|
|
|
cout << "Map revealed. The game has been paused for you." << endl;
|
2011-07-05 17:32:43 -06:00
|
|
|
if (doSafe)
|
|
|
|
cout << "Unpausing *WON'T* reveal hell." << endl << endl;
|
|
|
|
else
|
|
|
|
cout << "Unpausing can unleash the forces of hell!" << endl << endl;
|
2010-09-03 23:43:39 -06:00
|
|
|
cout << "Press any key to unreveal." << endl;
|
2011-03-30 06:27:47 -06:00
|
|
|
cout << "Close to keep the map revealed !!FOREVER!!" << endl;
|
2010-04-17 14:08:16 -06:00
|
|
|
cin.ignore();
|
|
|
|
cout << "Unrevealing... please wait." << endl;
|
|
|
|
// FIXME: do some consistency checks here!
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Attach();
|
|
|
|
Maps = DF->getMaps();
|
2010-04-19 06:14:37 -06:00
|
|
|
Maps->Start();
|
2011-03-01 15:18:55 -07:00
|
|
|
for(size_t i = 0; i < hidesaved.size();i++)
|
2010-04-17 14:08:16 -06:00
|
|
|
{
|
|
|
|
hideblock & hb = hidesaved[i];
|
|
|
|
Maps->ReadDesignations(hb.x,hb.y,hb.z, &designations);
|
|
|
|
for (uint32_t i = 0; i < 16;i++) for (uint32_t j = 0; j < 16;j++)
|
|
|
|
{
|
|
|
|
designations[i][j].bits.hidden = hb.hiddens[i][j];
|
|
|
|
}
|
|
|
|
Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations);
|
|
|
|
}
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
|
|
|
{
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
return 0;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|