2011-03-23 21:06:14 -06:00
|
|
|
// Adamantine tube filler. It fills the hollow ones.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <DFHack.h>
|
|
|
|
#include <dfhack/DFTileTypes.h>
|
2011-05-17 00:36:38 -06:00
|
|
|
#include <dfhack/extra/termutil.h>
|
2011-03-23 21:06:14 -06:00
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
2011-05-14 22:10:47 -06:00
|
|
|
bool temporary_terminal = TemporaryTerminal();
|
2011-03-23 21:06:14 -06:00
|
|
|
uint32_t x_max,y_max,z_max;
|
|
|
|
DFHack::designations40d designations;
|
|
|
|
DFHack::tiletypes40d tiles;
|
|
|
|
|
|
|
|
int32_t oldT, newT;
|
|
|
|
uint64_t count = 0;
|
|
|
|
|
|
|
|
int dirty=0;
|
|
|
|
|
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context *DF = DFMgr.getSingleContext();
|
|
|
|
|
|
|
|
//Init
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DF->Attach();
|
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2011-03-23 21:06:14 -06:00
|
|
|
cin.ignore();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
DFHack::Maps *Mapz = DF->getMaps();
|
|
|
|
|
|
|
|
// init the map
|
|
|
|
if (!Mapz->Start())
|
|
|
|
{
|
|
|
|
cerr << "Can't init map." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
2011-03-23 21:06:14 -06:00
|
|
|
cin.ignore();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mapz->getSize(x_max,y_max,z_max);
|
|
|
|
if(!Mapz->StartFeatures())
|
|
|
|
{
|
|
|
|
cerr << "Can't get features." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
|
|
|
cin.ignore();
|
2011-03-23 21:06:14 -06:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the map
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
DFHack::t_feature * locf = 0;
|
|
|
|
DFHack::t_feature * glof = 0;
|
|
|
|
if (Mapz->ReadFeatures(x,y,z,&locf,&glof))
|
|
|
|
{
|
|
|
|
// we're looking for addy tubes
|
|
|
|
if(!locf) continue;
|
|
|
|
if(locf->type != DFHack::feature_Adamantine_Tube) continue;
|
2011-03-23 21:20:34 -06:00
|
|
|
|
2011-03-23 21:06:14 -06:00
|
|
|
dirty=0;
|
|
|
|
Mapz->ReadDesignations(x,y,z, &designations);
|
|
|
|
Mapz->ReadTileTypes(x,y,z, &tiles);
|
|
|
|
|
|
|
|
for (uint32_t ty=0;ty<16;++ty)
|
|
|
|
{
|
|
|
|
for (uint32_t tx=0;tx<16;++tx)
|
|
|
|
{
|
|
|
|
if(!designations[tx][ty].bits.feature_local) continue;
|
|
|
|
oldT = tiles[tx][ty];
|
2011-04-17 05:06:19 -06:00
|
|
|
if ( DFHack::tileShape(oldT) != DFHack::WALL )
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
|
|
|
//Current tile is not a wall.
|
|
|
|
//Set current tile, as accurately as can be expected
|
|
|
|
//newT = DFHack::findSimilarTileType(oldT,DFHack::WALL);
|
|
|
|
newT = DFHack::findTileType( DFHack::WALL, DFHack::FEATSTONE, DFHack::tilevariant_invalid, DFHack::TILE_NORMAL, DFHack::TileDirection() );
|
|
|
|
|
|
|
|
//If no change, skip it (couldn't find a good tile type)
|
|
|
|
if ( oldT == newT) continue;
|
|
|
|
//Set new tile type, clear designation
|
|
|
|
tiles[tx][ty] = newT;
|
|
|
|
dirty=1;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//If anything was changed, write it all.
|
|
|
|
if (dirty)
|
|
|
|
{
|
|
|
|
Mapz->WriteTileTypes(x,y,z, &tiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DF->Detach();
|
|
|
|
cout << "Found and changed " << count << " tiles." << endl;
|
2011-05-14 22:10:47 -06:00
|
|
|
if(temporary_terminal)
|
|
|
|
{
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
}
|
2011-03-23 21:06:14 -06:00
|
|
|
return 0;
|
|
|
|
}
|