11// Adamantine tube filler. It fills the hollow ones.
22
3+ #include < stdint.h>
34#include < iostream>
4- #include < vector>
55#include < map>
6- #include < stddef.h>
7- #include < assert.h>
8- #include < string.h>
9- using namespace std ;
6+ #include < vector>
7+ #include < dfhack/Core.h>
8+ #include < dfhack/Console.h>
9+ #include < dfhack/Export.h>
10+ #include < dfhack/PluginManager.h>
11+ #include < dfhack/modules/Maps.h>
12+ #include < dfhack/modules/World.h>
13+ #include < dfhack/extra/MapExtras.h>
14+ #include < dfhack/modules/Gui.h>
15+ using MapExtras::MapCache;
16+ using namespace DFHack ;
17+
18+ DFhackCExport command_result tubefill (DFHack::Core * c, std::vector<std::string> & params);
19+
20+ DFhackCExport const char * plugin_name ( void )
21+ {
22+ return " tubefill" ;
23+ }
24+
25+ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
26+ {
27+ commands.clear ();
28+ commands.push_back (PluginCommand (" tubefill" ," Fill in all the adamantine tubes again." ,tubefill));
29+ return CR_OK ;
30+ }
1031
11- #include < DFHack.h>
12- #include < dfhack/DFTileTypes.h>
13- #include < dfhack/extra/termutil.h>
32+ DFhackCExport command_result plugin_shutdown ( Core * c )
33+ {
34+ return CR_OK ;
35+ }
1436
15- int main ( void )
37+ DFhackCExport command_result tubefill (DFHack::Core * c, std::vector<std::string> & params )
1638{
17- bool temporary_terminal = TemporaryTerminal ();
1839 uint32_t x_max,y_max,z_max;
1940 DFHack::designations40d designations;
2041 DFHack::tiletypes40d tiles;
@@ -24,39 +45,23 @@ int main (void)
2445
2546 int dirty=0 ;
2647
27- DFHack::ContextManager DFMgr (" Memory.xml" );
28- DFHack::Context *DF = DFMgr.getSingleContext ();
29-
30- // Init
31- try
32- {
33- DF ->Attach ();
34- }
35- catch (exception& e)
36- {
37- cerr << e.what () << endl;
38- if (temporary_terminal)
39- cin.ignore ();
40- return 1 ;
41- }
42- DFHack::Maps *Mapz = DF ->getMaps ();
48+ c->Suspend ();
49+ DFHack::Maps *Mapz = c->getMaps ();
4350
4451 // init the map
4552 if (!Mapz->Start ())
4653 {
47- cerr << " Can't init map." << endl;
48- if (temporary_terminal)
49- cin.ignore ();
50- return 1 ;
54+ c->con .printerr (" Can't init map.\n " );
55+ c->Resume ();
56+ return CR_FAILURE ;
5157 }
5258
5359 Mapz->getSize (x_max,y_max,z_max);
5460 if (!Mapz->StartFeatures ())
5561 {
56- cerr << " Can't get features." << endl;
57- if (temporary_terminal)
58- cin.ignore ();
59- return 1 ;
62+ c->con .printerr (" Can't get map features.\n " );
63+ c->Resume ();
64+ return CR_FAILURE ;
6065 }
6166
6267 // walk the map
@@ -109,12 +114,7 @@ int main (void)
109114 }
110115 }
111116 }
112- DF ->Detach ();
113- cout << " Found and changed " << count << " tiles." << endl;
114- if (temporary_terminal)
115- {
116- cout << " Done. Press any key to continue" << endl;
117- cin.ignore ();
118- }
119- return 0 ;
117+ c->Resume ();
118+ c->con .print (" Found and changed %d tiles.\n " , count);
119+ return CR_OK ;
120120}
0 commit comments