2012-02-24 13:07:04 -07:00
|
|
|
// Allow changing the material of a mineral inclusion
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "TileTypes.h"
|
|
|
|
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/block_square_event.h"
|
|
|
|
#include "df/block_square_event_mineralst.h"
|
|
|
|
#include "df/map_block.h"
|
|
|
|
|
2012-02-24 13:07:04 -07:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
2014-12-02 19:44:20 -07:00
|
|
|
DFHACK_PLUGIN("changevein");
|
|
|
|
REQUIRE_GLOBAL(world);
|
|
|
|
REQUIRE_GLOBAL(cursor);
|
2012-02-24 13:07:04 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
command_result df_changevein (color_ostream &out, vector <string> & parameters)
|
2012-02-24 13:07:04 -07:00
|
|
|
{
|
|
|
|
if (parameters.size() != 1)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-02-24 13:07:04 -07:00
|
|
|
|
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
if (!cursor || cursor->x == -30000)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("No cursor detected - please place the cursor over a mineral vein.\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MaterialInfo mi;
|
|
|
|
if (!mi.findInorganic(parameters[0]))
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("No such material!\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
if (mi.inorganic->material.flags.is_set(material_flags::IS_METAL) ||
|
|
|
|
mi.inorganic->material.flags.is_set(material_flags::NO_STONE_STOCKPILE) ||
|
|
|
|
mi.inorganic->flags.is_set(inorganic_flags::SOIL_ANY))
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid material - you must select a type of stone or gem\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-04-11 02:01:27 -06:00
|
|
|
df::map_block *block = Maps::getTileBlock(cursor->x, cursor->y, cursor->z);
|
2012-02-24 13:07:04 -07:00
|
|
|
if (!block)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid tile selected.\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
df::block_square_event_mineralst *mineral = NULL;
|
|
|
|
int tx = cursor->x % 16, ty = cursor->y % 16;
|
|
|
|
for (size_t j = 0; j < block->block_events.size(); j++)
|
|
|
|
{
|
|
|
|
df::block_square_event *evt = block->block_events[j];
|
|
|
|
if (evt->getType() != block_square_event_type::mineral)
|
|
|
|
continue;
|
2012-03-29 18:05:53 -06:00
|
|
|
df::block_square_event_mineralst *cur = (df::block_square_event_mineralst *)evt;
|
|
|
|
if (cur->getassignment(tx, ty))
|
|
|
|
mineral = cur;
|
2012-02-24 13:07:04 -07:00
|
|
|
}
|
|
|
|
if (!mineral)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Selected tile does not contain a mineral vein.\n");
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
mineral->inorganic_mat = mi.index;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-02-24 13:07:04 -07:00
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand("changevein",
|
2022-07-22 17:42:36 -06:00
|
|
|
"Change the material of a mineral inclusion.",
|
2022-07-20 14:24:27 -06:00
|
|
|
df_changevein));
|
2012-02-24 13:07:04 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-02-24 13:07:04 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|