2010-10-16 22:21:18 -06:00
|
|
|
// De-ramp. All ramps marked for removal are replaced with given tile (presently, normal floor).
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
#include "DataDefs.h"
|
2012-01-19 21:12:51 -07:00
|
|
|
#include "modules/Maps.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "TileTypes.h"
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2011-08-04 16:41:31 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
using df::global::world;
|
2011-08-04 16:41:31 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("deramp");
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result df_deramp (Core * c, vector <string> & parameters)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
if (!parameters.empty())
|
|
|
|
return CR_WRONG_USAGE;
|
2010-10-24 20:39:14 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
CoreSuspender suspend(c);
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2012-01-24 04:36:30 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
|
|
|
c->con.printerr("Map is not available!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
int count = 0;
|
|
|
|
int countbad = 0;
|
2010-10-16 22:21:18 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
int num_blocks = 0, blocks_total = world->map.map_blocks.size();
|
|
|
|
for (int i = 0; i < blocks_total; i++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2012-01-11 08:53:48 -07:00
|
|
|
df::map_block *block = world->map.map_blocks[i];
|
2012-01-19 21:12:51 -07:00
|
|
|
df::map_block *above = Maps::getBlockAbs(block->map_pos.x, block->map_pos.y, block->map_pos.z + 1);
|
2012-01-11 08:53:48 -07:00
|
|
|
|
|
|
|
for (int x = 0; x < 16; x++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2012-01-11 08:53:48 -07:00
|
|
|
for (int y = 0; y < 16; y++)
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype oldT = block->tiletype[x][y];
|
|
|
|
if ((tileShape(oldT) == tiletype_shape::RAMP) &&
|
2012-01-21 17:31:15 -07:00
|
|
|
(block->designation[x][y].bits.dig == tile_dig_designation::Default))
|
2010-10-16 22:21:18 -06:00
|
|
|
{
|
2012-01-11 08:53:48 -07:00
|
|
|
// Current tile is a ramp.
|
|
|
|
// Set current tile, as accurately as can be expected
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype newT = findSimilarTileType(oldT, tiletype_shape::FLOOR);
|
2010-10-24 20:39:14 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
// If no change, skip it (couldn't find a good tile type)
|
|
|
|
if (oldT == newT)
|
|
|
|
continue;
|
|
|
|
// Set new tile type, clear designation
|
|
|
|
block->tiletype[x][y] = newT;
|
2012-01-21 17:31:15 -07:00
|
|
|
block->designation[x][y].bits.dig = tile_dig_designation::No;
|
2010-10-24 20:39:14 -06:00
|
|
|
|
2012-01-11 08:53:48 -07:00
|
|
|
// Check the tile above this one, in case a downward slope needs to be removed.
|
2012-02-13 15:56:33 -07:00
|
|
|
if ((above) && (tileShape(above->tiletype[x][y]) == tiletype_shape::RAMP_TOP))
|
|
|
|
above->tiletype[x][y] = tiletype::OpenSpace; // open space
|
2012-01-11 08:53:48 -07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
// ramp fixer
|
2012-02-13 15:56:33 -07:00
|
|
|
else if ((tileShape(oldT) != tiletype_shape::RAMP)
|
|
|
|
&& (above) && (tileShape(above->tiletype[x][y]) == tiletype_shape::RAMP_TOP))
|
2012-01-11 08:53:48 -07:00
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
above->tiletype[x][y] = tiletype::OpenSpace; // open space
|
2012-01-11 08:53:48 -07:00
|
|
|
countbad++;
|
2010-10-16 22:21:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 08:53:48 -07:00
|
|
|
if (count)
|
|
|
|
c->con.print("Found and changed %d tiles.\n", count);
|
|
|
|
if (countbad)
|
|
|
|
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
|
|
|
}
|
2012-01-11 08:53:48 -07:00
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
2012-01-28 05:03:56 -07:00
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"deramp", "De-ramp. All ramps marked for removal are replaced with floors.",
|
|
|
|
df_deramp, false,
|
|
|
|
" If there are any ramps designated for removal, they will be instantly\n"
|
|
|
|
" removed. Any ramps that don't have their counterpart will also be removed\n"
|
|
|
|
" (fixes bugs with caveins)\n"
|
|
|
|
));
|
2012-01-11 08:53:48 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
2012-01-15 13:54:14 -07:00
|
|
|
}
|