2010-10-16 22:21:18 -06:00
|
|
|
// De-ramp. All ramps marked for removal are replaced with given tile (presently, normal floor).
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <assert.h>
|
2010-10-24 20:39:14 -06:00
|
|
|
#include <string.h>
|
2010-10-16 22:21:18 -06:00
|
|
|
using namespace std;
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <modules/Maps.h>
|
|
|
|
#include <TileTypes.h>
|
2011-08-04 16:41:31 -06:00
|
|
|
using namespace DFHack;
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2011-08-04 16:41:31 -06:00
|
|
|
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters);
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2011-08-04 16:41:31 -06:00
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "deramp";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("deramp",
|
|
|
|
"De-ramp. All ramps marked for removal are replaced with floors.",
|
|
|
|
df_deramp));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result df_deramp (Core * c, vector <string> & parameters)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
|
|
|
uint32_t x_max,y_max,z_max;
|
|
|
|
uint32_t num_blocks = 0;
|
|
|
|
uint32_t bytes_read = 0;
|
|
|
|
DFHack::designations40d designations;
|
|
|
|
DFHack::tiletypes40d tiles;
|
|
|
|
DFHack::tiletypes40d tilesAbove;
|
|
|
|
|
2010-10-24 20:39:14 -06:00
|
|
|
//DFHack::TileRow *ptile;
|
|
|
|
int32_t oldT, newT;
|
|
|
|
|
2011-04-04 07:46:39 -06:00
|
|
|
bool dirty= false;
|
|
|
|
int count=0;
|
|
|
|
int countbad=0;
|
2011-08-08 17:50:22 -06:00
|
|
|
for(int i = 0; i < parameters.size();i++)
|
|
|
|
{
|
|
|
|
if(parameters[i] == "help" || parameters[i] == "?")
|
|
|
|
{
|
|
|
|
c->con.print("This command does two things:\n"
|
2011-08-14 00:42:21 -06:00
|
|
|
"If there are any ramps designated for removal, they will be instantly removed.\n"
|
|
|
|
"Any ramps that don't have their counterpart will be removed (fixes bugs with caveins)\n"
|
2011-08-08 17:50:22 -06:00
|
|
|
);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 16:41:31 -06:00
|
|
|
c->Suspend();
|
|
|
|
DFHack::Maps *Mapz = c->getMaps();
|
2010-10-24 20:39:14 -06:00
|
|
|
|
2010-10-16 22:21:18 -06:00
|
|
|
// init the map
|
2010-10-24 20:39:14 -06:00
|
|
|
if (!Mapz->Start())
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2011-08-04 16:41:31 -06:00
|
|
|
c->con.printerr("Can't init map.\n");
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
2010-10-16 22:21:18 -06:00
|
|
|
}
|
2010-10-24 20:39:14 -06:00
|
|
|
|
2010-10-16 22:21:18 -06:00
|
|
|
Mapz->getSize(x_max,y_max,z_max);
|
|
|
|
|
|
|
|
uint8_t zeroes [16][16] = {0};
|
|
|
|
|
|
|
|
// walk the map
|
2010-10-24 20:39:14 -06:00
|
|
|
for (uint32_t x = 0; x< x_max;x++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2010-10-24 20:39:14 -06:00
|
|
|
for (uint32_t y = 0; y< y_max;y++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2010-10-24 20:39:14 -06:00
|
|
|
for (uint32_t z = 0; z< z_max;z++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2011-08-04 16:41:31 -06:00
|
|
|
if (Mapz->getBlock(x,y,z))
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2011-04-04 07:46:39 -06:00
|
|
|
dirty= false;
|
2010-10-16 22:21:18 -06:00
|
|
|
Mapz->ReadDesignations(x,y,z, &designations);
|
2010-10-24 20:39:14 -06:00
|
|
|
Mapz->ReadTileTypes(x,y,z, &tiles);
|
2011-08-04 16:41:31 -06:00
|
|
|
if (Mapz->getBlock(x,y,z+1))
|
2010-10-24 20:39:14 -06:00
|
|
|
{
|
|
|
|
Mapz->ReadTileTypes(x,y,z+1, &tilesAbove);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memset(&tilesAbove,0,sizeof(tilesAbove));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t ty=0;ty<16;++ty)
|
|
|
|
{
|
|
|
|
for (uint32_t tx=0;tx<16;++tx)
|
|
|
|
{
|
|
|
|
//Only the remove ramp designation (ignore channel designation, etc)
|
|
|
|
oldT = tiles[tx][ty];
|
|
|
|
if ( DFHack::designation_default == designations[tx][ty].bits.dig
|
2011-04-17 05:06:19 -06:00
|
|
|
&& DFHack::RAMP==DFHack::tileShape(oldT))
|
2010-10-24 20:39:14 -06:00
|
|
|
{
|
|
|
|
//Current tile is a ramp.
|
|
|
|
//Set current tile, as accurately as can be expected
|
|
|
|
newT = DFHack::findSimilarTileType(oldT,DFHack::FLOOR);
|
|
|
|
|
|
|
|
//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;
|
|
|
|
designations[tx][ty].bits.dig = DFHack::designation_no;
|
|
|
|
|
|
|
|
//Check the tile above this one, in case a downward slope needs to be removed.
|
2011-04-17 05:06:19 -06:00
|
|
|
if ( DFHack::RAMP_TOP == DFHack::tileShape(tilesAbove[tx][ty]) )
|
2010-10-24 20:39:14 -06:00
|
|
|
{
|
|
|
|
tilesAbove[tx][ty] = 32;
|
|
|
|
}
|
2011-04-04 07:46:39 -06:00
|
|
|
dirty= true;
|
2010-10-24 20:39:14 -06:00
|
|
|
++count;
|
|
|
|
}
|
2011-04-04 07:46:39 -06:00
|
|
|
// ramp fixer
|
2011-04-17 05:06:19 -06:00
|
|
|
else if(DFHack::RAMP!=DFHack::tileShape(oldT) && DFHack::RAMP_TOP == DFHack::tileShape(tilesAbove[tx][ty]))
|
2011-04-04 07:46:39 -06:00
|
|
|
{
|
|
|
|
tilesAbove[tx][ty] = 32;
|
|
|
|
countbad++;
|
|
|
|
dirty = true;
|
|
|
|
}
|
2010-10-24 20:39:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//If anything was changed, write it all.
|
|
|
|
if (dirty)
|
|
|
|
{
|
|
|
|
Mapz->WriteDesignations(x,y,z, &designations);
|
|
|
|
Mapz->WriteTileTypes(x,y,z, &tiles);
|
2011-08-04 16:41:31 -06:00
|
|
|
if (Mapz->getBlock(x,y,z+1))
|
2010-10-24 20:39:14 -06:00
|
|
|
{
|
|
|
|
Mapz->WriteTileTypes(x,y,z+1, &tilesAbove);
|
|
|
|
}
|
2011-04-04 07:46:39 -06:00
|
|
|
dirty = false;
|
2010-10-24 20:39:14 -06:00
|
|
|
}
|
2010-10-16 22:21:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 16:41:31 -06:00
|
|
|
c->Resume();
|
|
|
|
if(count)
|
2011-08-04 21:02:36 -06:00
|
|
|
c->con.print("Found and changed %d tiles.\n",count);
|
2011-08-04 16:41:31 -06:00
|
|
|
if(countbad)
|
2011-08-04 21:02:36 -06:00
|
|
|
c->con.print("Fixed %d bad down ramps.\n",countbad);
|
2011-08-04 16:41:31 -06:00
|
|
|
return CR_OK;
|
2010-10-16 22:21:18 -06:00
|
|
|
}
|