2014-02-14 10:06:33 -07:00
|
|
|
// Adamantine tube filler. Replaces mined out tiles but leaves hollow tubes alone (to prevent problems)
|
2011-03-23 21:06:14 -06:00
|
|
|
|
2011-08-02 08:25:10 -06:00
|
|
|
#include <stdint.h>
|
2011-03-23 21:06:14 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2011-08-02 08:25:10 -06:00
|
|
|
#include <vector>
|
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"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/World.h"
|
|
|
|
#include "modules/Gui.h"
|
2012-01-19 21:34:06 -07:00
|
|
|
#include "TileTypes.h"
|
|
|
|
|
2014-06-27 12:01:46 -06:00
|
|
|
#include "df/deep_vein_hollow.h"
|
|
|
|
|
2011-08-02 08:25:10 -06:00
|
|
|
using namespace DFHack;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2012-01-19 21:34:06 -07:00
|
|
|
using df::global::world;
|
2011-08-02 08:25:10 -06:00
|
|
|
|
2014-02-14 10:06:33 -07:00
|
|
|
bool isDesignatedHollow(df::coord pos)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < world->deep_vein_hollows.size(); i++)
|
|
|
|
{
|
|
|
|
auto *vein = world->deep_vein_hollows[i];
|
|
|
|
for (size_t j = 0; j < vein->tiles.x.size(); j++)
|
|
|
|
if (pos == df::coord(vein->tiles.x[j], vein->tiles.y[j], vein->tiles.z[j]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result tubefill(color_ostream &out, std::vector<std::string> & params);
|
2011-08-02 08:25:10 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("tubefill");
|
2011-08-02 08:25:10 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-08-02 08:25:10 -06:00
|
|
|
{
|
2013-10-30 14:58:14 -06:00
|
|
|
commands.push_back(PluginCommand("tubefill","Fill in all the adamantine tubes again.",tubefill, false,
|
2014-02-14 10:06:33 -07:00
|
|
|
"Replenishes mined out adamantine but does not fill hollow adamantine tubes.\n"
|
|
|
|
"Specify 'hollow' to fill hollow tubes, but beware glitchy HFS spawns.\n"));
|
2011-08-02 08:25:10 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-03-23 21:06:14 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-08-02 08:25:10 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-03-23 21:06:14 -06:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result tubefill(color_ostream &out, std::vector<std::string> & params)
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
|
|
|
uint64_t count = 0;
|
2014-02-14 10:06:33 -07:00
|
|
|
bool hollow = false;
|
2011-03-23 21:06:14 -06:00
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < params.size();i++)
|
2011-08-14 00:42:21 -06:00
|
|
|
{
|
|
|
|
if(params[i] == "help" || params[i] == "?")
|
2013-10-30 14:58:14 -06:00
|
|
|
return CR_WRONG_USAGE;
|
2014-02-14 10:06:33 -07:00
|
|
|
if (params[i] == "hollow")
|
|
|
|
hollow = true;
|
2011-08-14 00:42:21 -06:00
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
|
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2011-08-02 08:25:10 -06:00
|
|
|
return CR_FAILURE;
|
2011-03-23 21:06:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// walk the map
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < world->map.map_blocks.size(); i++)
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
2012-01-19 21:34:06 -07:00
|
|
|
df::map_block *block = world->map.map_blocks[i];
|
2012-04-11 02:01:27 -06:00
|
|
|
df::map_block *above = Maps::getTileBlock(block->map_pos + df::coord(0,0,1));
|
2012-01-19 21:34:06 -07:00
|
|
|
DFHack::t_feature feature;
|
2012-04-11 02:01:27 -06:00
|
|
|
if (!Maps::ReadFeatures(block, &feature, NULL))
|
2012-01-19 21:34:06 -07:00
|
|
|
continue;
|
2012-01-21 17:31:15 -07:00
|
|
|
if (feature.type != feature_type::deep_special_tube)
|
2012-01-19 21:34:06 -07:00
|
|
|
continue;
|
|
|
|
for (uint32_t x = 0; x < 16; x++)
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
2012-01-19 21:34:06 -07:00
|
|
|
for (uint32_t y = 0; y < 16; y++)
|
2011-03-23 21:06:14 -06:00
|
|
|
{
|
2012-01-19 21:34:06 -07:00
|
|
|
if (!block->designation[x][y].bits.feature_local)
|
|
|
|
continue;
|
2011-03-23 21:20:34 -06:00
|
|
|
|
2014-02-14 10:06:33 -07:00
|
|
|
if (!hollow && isDesignatedHollow(block->map_pos + df::coord(x,y,0)))
|
|
|
|
continue;
|
|
|
|
|
2012-01-19 21:34:06 -07:00
|
|
|
// Is the tile already a wall?
|
2012-02-13 15:56:33 -07:00
|
|
|
if (tileShape(block->tiletype[x][y]) == tiletype_shape::WALL)
|
2012-01-19 21:34:06 -07:00
|
|
|
continue;
|
2011-03-23 21:06:14 -06:00
|
|
|
|
2012-01-19 21:41:59 -07:00
|
|
|
// Does the tile contain liquid?
|
|
|
|
if (block->designation[x][y].bits.flow_size)
|
|
|
|
continue;
|
|
|
|
|
2012-01-19 21:34:06 -07:00
|
|
|
// Check the tile above this one, in case we need to add a floor
|
|
|
|
if (above)
|
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
if ((tileShape(above->tiletype[x][y]) == tiletype_shape::EMPTY) || (tileShape(above->tiletype[x][y]) == tiletype_shape::RAMP_TOP))
|
2012-01-19 21:41:59 -07:00
|
|
|
{
|
|
|
|
// if this tile isn't a local feature, it's likely the tile underneath was originally just a floor
|
|
|
|
// it's also possible there was just solid non-feature stone above, but we don't care enough to check
|
|
|
|
if (!above->designation[x][y].bits.feature_local)
|
|
|
|
continue;
|
2012-02-13 15:56:33 -07:00
|
|
|
above->tiletype[x][y] = findRandomVariant(tiletype::FeatureFloor1);
|
2012-01-19 21:41:59 -07:00
|
|
|
}
|
2011-03-23 21:06:14 -06:00
|
|
|
}
|
2012-02-13 15:56:33 -07:00
|
|
|
block->tiletype[x][y] = tiletype::FeatureWall;
|
2014-02-14 10:06:33 -07:00
|
|
|
world->reindex_pathfinding = true;
|
2012-01-19 21:34:06 -07:00
|
|
|
++count;
|
2011-03-23 21:06:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 04:55:42 -07:00
|
|
|
out.print("Found and changed %d tiles.\n", count);
|
2011-08-02 08:25:10 -06:00
|
|
|
return CR_OK;
|
2011-03-23 21:06:14 -06:00
|
|
|
}
|