2011-10-13 18:15:19 -06:00
|
|
|
//Quick building occupancy flag test.
|
|
|
|
//Individual bits had no apparent meaning. Assume it's an enum, set by number.
|
|
|
|
|
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 <modules/Gui.h>
|
|
|
|
#include <modules/MapCache.h>
|
2011-10-13 18:15:19 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <stack>
|
|
|
|
#include <string>
|
|
|
|
#include <cmath>
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::stack;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result readFlag (color_ostream &out, vector <string> & parameters);
|
|
|
|
command_result writeFlag (color_ostream &out, vector <string> & parameters);
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("buildprobe");
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand("bshow","Output building occupancy value",readFlag));
|
|
|
|
commands.push_back(PluginCommand("bset","Set building occupancy value",writeFlag));
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result readFlag (color_ostream &out, vector <string> & parameters)
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender suspend;
|
2011-10-13 18:15:19 -06:00
|
|
|
|
|
|
|
// init the map
|
2012-01-26 21:54:26 -07:00
|
|
|
if(!Maps::IsValid())
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
|
2011-10-13 18:15:19 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
int32_t cx, cy, cz;
|
2012-03-03 06:38:24 -07:00
|
|
|
if(!Gui::getCursorCoords(cx,cy,cz))
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Cursor is not active.\n");
|
2011-10-13 18:15:19 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
DFCoord cursor = DFCoord(cx,cy,cz);
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
MapExtras::MapCache * MCache = new MapExtras::MapCache();
|
|
|
|
t_occupancy oc = MCache->occupancyAt(cursor);
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Current Value: %d\n", oc.bits.building);
|
2012-02-13 21:54:08 -07:00
|
|
|
return CR_OK;
|
2011-10-13 18:15:19 -06:00
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result writeFlag (color_ostream &out, vector <string> & parameters)
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-02-13 21:54:08 -07:00
|
|
|
if (parameters.size() == 0)
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("No value specified\n");
|
2012-02-13 21:54:08 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parameters[0] == "help" || parameters[0] == "?")
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Set the building occupancy flag.\n"
|
|
|
|
"Value must be between 0 and 7, inclusive.\n");
|
2012-02-13 21:54:08 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
char value;
|
|
|
|
|
|
|
|
switch (parameters[0][0])
|
|
|
|
{
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
value = parameters[0][0] - '0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Invalid value specified\n");
|
2012-02-13 21:54:08 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
break; //Redundant.
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender suspend;
|
2012-02-13 21:54:08 -07:00
|
|
|
|
2011-10-13 18:15:19 -06:00
|
|
|
// init the map
|
2012-01-26 21:54:26 -07:00
|
|
|
if(!Maps::IsValid())
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
|
2011-10-13 18:15:19 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
int32_t cx, cy, cz;
|
2012-03-03 06:38:24 -07:00
|
|
|
if(!Gui::getCursorCoords(cx,cy,cz))
|
2011-10-13 18:15:19 -06:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Cursor is not active.\n");
|
2011-10-13 18:15:19 -06:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
DFCoord cursor = DFCoord(cx,cy,cz);
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
MapExtras::MapCache * MCache = new MapExtras::MapCache();
|
|
|
|
t_occupancy oc = MCache->occupancyAt(cursor);
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-04-19 01:03:29 -06:00
|
|
|
oc.bits.building = df::tile_building_occ(value);
|
2012-02-13 21:54:08 -07:00
|
|
|
MCache->setOccupancyAt(cursor, oc);
|
|
|
|
MCache->WriteAll();
|
2011-10-13 18:15:19 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|