summaryrefslogtreecommitdiff
path: root/plugins/reveal.cpp
diff options
context:
space:
mode:
authorPetr Mrázek2011-06-25 05:35:29 +0200
committerPetr Mrázek2011-06-25 05:35:29 +0200
commit6fd7d42f0093ec5d057f35cd0a652c9ad254fc30 (patch)
tree7638dbc5d1bd03d1fb21d3dd22511b22b16b9b20 /plugins/reveal.cpp
parent0bb097296a8e980c0f3282716d1887923294307d (diff)
downloaddfhack-6fd7d42f0093ec5d057f35cd0a652c9ad254fc30.tar.gz
dfhack-6fd7d42f0093ec5d057f35cd0a652c9ad254fc30.tar.bz2
dfhack-6fd7d42f0093ec5d057f35cd0a652c9ad254fc30.tar.xz
Plugin manager, reworked kittens and reveal.
Diffstat (limited to 'plugins/reveal.cpp')
-rw-r--r--plugins/reveal.cpp110
1 files changed, 92 insertions, 18 deletions
diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp
index 1734bfb0..cd5ddd5c 100644
--- a/plugins/reveal.cpp
+++ b/plugins/reveal.cpp
@@ -5,13 +5,11 @@
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
+#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/World.h>
-DFhackCExport const char * plugin_name ( void )
-{
- return "reveal";
-}
+using namespace DFHack;
struct hideblock
{
@@ -21,27 +19,58 @@ struct hideblock
uint8_t hiddens [16][16];
};
-DFhackCExport int plugin_run (DFHack::Core * c)
+// 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;
+bool revealed = false;
+
+DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> & params);
+DFhackCExport command_result unreveal(DFHack::Core * c, std::vector<std::string> & params);
+DFhackCExport command_result revealtoggle(DFHack::Core * c, std::vector<std::string> & params);
+//DFhackCExport command_result revealclear(DFHack::Core * c, std::vector<std::string> & params);
+
+DFhackCExport const char * plugin_name ( void )
+{
+ return "reveal";
+}
+
+DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
+{
+ commands.clear();
+ commands.push_back(PluginCommand("reveal","Reveal the map.",reveal));
+ commands.push_back(PluginCommand("unreveal","Revert the map to its previous state.",unreveal));
+ commands.push_back(PluginCommand("revealtoggle","Reveal/unreveal depending on state.",revealtoggle));
+ //commands.push_back(PluginCommand("revealclear","Reset the reveal tool.",revealclear));
+ return CR_OK;
+}
+
+DFhackCExport command_result plugin_shutdown ( Core * c )
+{
+ return CR_OK;
+}
+
+DFhackCExport command_result reveal(DFHack::Core * c, std::vector<std::string> & params)
{
+ DFHack::designations40d designations;
+ if(revealed)
+ {
+ dfout << "Map is already revealed or this is a different map." << std::endl;
+ return CR_FAILURE;
+ }
c->Suspend();
DFHack::Maps *Maps =c->getMaps();
DFHack::World *World =c->getWorld();
-
// init the map
if(!Maps->Start())
{
dfout << "Can't init map." << std::endl;
c->Resume();
- return 1;
+ return CR_FAILURE;
}
dfout << "Revealing, please wait..." << std::endl;
-
- uint32_t x_max, y_max, z_max;
- DFHack::designations40d designations;
Maps->getSize(x_max,y_max,z_max);
- std::vector <hideblock> hidesaved;
-
+ hidesaved.reserve(x_max * y_max * z_max);
for(uint32_t x = 0; x< x_max;x++)
{
for(uint32_t y = 0; y< y_max;y++)
@@ -70,17 +99,47 @@ DFhackCExport int plugin_run (DFHack::Core * c)
}
}
World->SetPauseState(true);
+ revealed = true;
c->Resume();
dfout << "Map revealed. The game has been paused for you." << std::endl;
dfout << "Unpausing can unleash the forces of hell!" << std::endl;
dfout << "Saving will make this state permanent. Don't do it." << std::endl << std::endl;
- dfout << "Press any key to unreveal." << std::endl;
- std::cin.ignore();
- dfout << "Unrevealing... please wait." << std::endl;
- // FIXME: do some consistency checks here!
+ dfout << "Run 'reveal' again to revert to previous state." << std::endl;
+ 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;
+ }
c->Suspend();
+ DFHack::Maps *Maps =c->getMaps();
+ DFHack::World *World =c->getWorld();
Maps = c->getMaps();
- Maps->Start();
+ 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
+
+ dfout << "Unrevealing... please wait." << std::endl;
for(size_t i = 0; i < hidesaved.size();i++)
{
hideblock & hb = hidesaved[i];
@@ -91,6 +150,21 @@ DFhackCExport int plugin_run (DFHack::Core * c)
}
Maps->WriteDesignations(hb.x,hb.y,hb.z, &designations);
}
+ // give back memory.
+ hidesaved.clear();
+ revealed = false;
c->Resume();
- return 0;
+ return CR_OK;
+}
+
+DFhackCExport command_result revealtoggle (DFHack::Core * c, std::vector<std::string> & params)
+{
+ if(revealed)
+ {
+ return unreveal(c,params);
+ }
+ else
+ {
+ return reveal(c,params);
+ }
}