Port tubefill tool.

develop
Petr Mrázek 2011-08-02 16:25:10 +02:00
parent e04dd8f101
commit ff4d545ae7
2 changed files with 43 additions and 42 deletions

@ -142,3 +142,4 @@ DFHACK_PLUGIN(notes notes.cpp)
DFHACK_PLUGIN(mode mode.cpp) DFHACK_PLUGIN(mode mode.cpp)
#DFHACK_PLUGIN(tiles tiles.cpp) #DFHACK_PLUGIN(tiles tiles.cpp)
DFHACK_PLUGIN(liquids liquids.cpp) DFHACK_PLUGIN(liquids liquids.cpp)
DFHACK_PLUGIN(tubefill tubefill.cpp)

@ -1,20 +1,41 @@
// Adamantine tube filler. It fills the hollow ones. // Adamantine tube filler. It fills the hollow ones.
#include <stdint.h>
#include <iostream> #include <iostream>
#include <vector>
#include <map> #include <map>
#include <stddef.h> #include <vector>
#include <assert.h> #include <dfhack/Core.h>
#include <string.h> #include <dfhack/Console.h>
using namespace std; #include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <dfhack/modules/Maps.h>
#include <dfhack/modules/World.h>
#include <dfhack/extra/MapExtras.h>
#include <dfhack/modules/Gui.h>
using MapExtras::MapCache;
using namespace DFHack;
DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params);
DFhackCExport const char * plugin_name ( void )
{
return "tubefill";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("tubefill","Fill in all the adamantine tubes again.",tubefill));
return CR_OK;
}
#include <DFHack.h> DFhackCExport command_result plugin_shutdown ( Core * c )
#include <dfhack/DFTileTypes.h> {
#include <dfhack/extra/termutil.h> return CR_OK;
}
int main (void) DFhackCExport command_result tubefill(DFHack::Core * c, std::vector<std::string> & params)
{ {
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::tiletypes40d tiles; DFHack::tiletypes40d tiles;
@ -24,39 +45,23 @@ int main (void)
int dirty=0; int dirty=0;
DFHack::ContextManager DFMgr("Memory.xml"); c->Suspend();
DFHack::Context *DF = DFMgr.getSingleContext(); DFHack::Maps *Mapz = c->getMaps();
//Init
try
{
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
DFHack::Maps *Mapz = DF->getMaps();
// init the map // init the map
if (!Mapz->Start()) if (!Mapz->Start())
{ {
cerr << "Can't init map." << endl; c->con.printerr("Can't init map.\n");
if(temporary_terminal) c->Resume();
cin.ignore(); return CR_FAILURE;
return 1;
} }
Mapz->getSize(x_max,y_max,z_max); Mapz->getSize(x_max,y_max,z_max);
if(!Mapz->StartFeatures()) if(!Mapz->StartFeatures())
{ {
cerr << "Can't get features." << endl; c->con.printerr("Can't get map features.\n");
if(temporary_terminal) c->Resume();
cin.ignore(); return CR_FAILURE;
return 1;
} }
// walk the map // walk the map
@ -109,12 +114,7 @@ int main (void)
} }
} }
} }
DF->Detach(); c->Resume();
cout << "Found and changed " << count << " tiles." << endl; c->con.print("Found and changed %d tiles.\n", count);
if(temporary_terminal) return CR_OK;
{
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
return 0;
} }