Merge branch 'topic_tools'
commit
a9a3a3ff5f
@ -0,0 +1,103 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/modules/Vegetation.h>
|
||||
#include <dfhack/modules/Maps.h>
|
||||
#include <dfhack/modules/Gui.h>
|
||||
#include <dfhack/TileTypes.h>
|
||||
#include <dfhack/extra/MapExtras.h>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using namespace DFHack;
|
||||
|
||||
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "grow";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("grow", "Grows saplings into trees (with active cursor, only the targetted one).", df_grow));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
|
||||
{
|
||||
//uint32_t x_max = 0, y_max = 0, z_max = 0;
|
||||
c->Suspend();
|
||||
DFHack::Maps *maps = c->getMaps();
|
||||
Console & con = c->con;
|
||||
if (!maps->Start())
|
||||
{
|
||||
con.printerr("Cannot get map info!\n");
|
||||
c->Resume();
|
||||
return CR_FAILURE;
|
||||
}
|
||||
//maps->getSize(x_max, y_max, z_max);
|
||||
MapExtras::MapCache map(maps);
|
||||
DFHack::Vegetation *veg = c->getVegetation();
|
||||
if (!veg->all_plants)
|
||||
{
|
||||
con.printerr("Unable to read vegetation!\n");
|
||||
c->Resume();
|
||||
return CR_FAILURE;
|
||||
}
|
||||
DFHack::Gui *Gui = c->getGui();
|
||||
int32_t x,y,z;
|
||||
if(Gui->getCursorCoords(x,y,z))
|
||||
{
|
||||
vector<DFHack::df_plant *> * alltrees;
|
||||
if(maps->ReadVegetation(x/16,y/16,z,alltrees))
|
||||
{
|
||||
for(size_t i = 0 ; i < alltrees->size(); i++)
|
||||
{
|
||||
DFHack::df_plant * tree = alltrees->at(i);
|
||||
if(tree->x == x && tree->y == y && tree->z == z)
|
||||
{
|
||||
if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK)
|
||||
{
|
||||
tree->grow_counter = DFHack::sapling_to_tree_threshold;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int grown = 0;
|
||||
for(size_t i = 0 ; i < veg->all_plants->size(); i++)
|
||||
{
|
||||
DFHack::df_plant *p = veg->all_plants->at(i);
|
||||
uint16_t ttype = map.tiletypeAt(DFHack::DFCoord(p->x,p->y,p->z));
|
||||
if(!p->is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK)
|
||||
{
|
||||
p->grow_counter = DFHack::sapling_to_tree_threshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
veg->Finish();
|
||||
maps->Finish();
|
||||
c->Resume();
|
||||
return CR_OK;
|
||||
}
|
||||
|
@ -0,0 +1,171 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <dfhack/modules/World.h>
|
||||
#include <stdlib.h>
|
||||
using namespace DFHack;
|
||||
|
||||
|
||||
DFhackCExport command_result mode (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "mode";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("mode","View, change and track game mode.",mode));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_onupdate ( Core * c )
|
||||
{
|
||||
// add tracking here
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
void printCurrentModes(t_gamemodes gm, Console & con)
|
||||
{
|
||||
con << "Current game type:\t" << gm.g_type << " (";
|
||||
switch(gm.g_type)
|
||||
{
|
||||
case GAMETYPE_DWARF_MAIN:
|
||||
con << "Fortress)" << endl;
|
||||
break;
|
||||
case GAMETYPE_ADVENTURE_MAIN:
|
||||
con << "Adventurer)" << endl;
|
||||
break;
|
||||
case GAMETYPE_VIEW_LEGENDS:
|
||||
con << "Legends)" << endl;
|
||||
break;
|
||||
case GAMETYPE_DWARF_RECLAIM:
|
||||
con << "Reclaim)" << endl;
|
||||
break;
|
||||
case GAMETYPE_DWARF_ARENA:
|
||||
con << "Arena)" << endl;
|
||||
break;
|
||||
case GAMETYPE_ADVENTURE_ARENA:
|
||||
con << "Arena - control creature)" << endl;
|
||||
break;
|
||||
case GAMETYPENUM:
|
||||
con << "INVALID)" << endl;
|
||||
break;
|
||||
case GAMETYPE_NONE:
|
||||
con << "NONE)" << endl;
|
||||
break;
|
||||
}
|
||||
con << "Current game mode:\t" << gm.g_mode << " (";
|
||||
switch (gm.g_mode)
|
||||
{
|
||||
case GAMEMODE_DWARF:
|
||||
con << "Dwarf)" << endl;
|
||||
break;
|
||||
case GAMEMODE_ADVENTURE:
|
||||
con << "Adventure)" << endl;
|
||||
break;
|
||||
case GAMEMODENUM:
|
||||
con << "INVALID)" << endl;
|
||||
break;
|
||||
case GAMEMODE_NONE:
|
||||
con << "NONE)" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DFhackCExport command_result mode (Core * c, vector <string> & parameters)
|
||||
{
|
||||
string command = "";
|
||||
bool set = false;
|
||||
t_gamemodes gm;
|
||||
if(parameters.size())
|
||||
{
|
||||
if(parameters[0] == "set")
|
||||
{
|
||||
set = true;
|
||||
}
|
||||
else if(parameters[0] == "?" || parameters[0] == "help")
|
||||
{
|
||||
c->con.print("Without any parameters, this command prints the current game mode\n"
|
||||
"You can interactively set the game mode with 'mode set'.\n");
|
||||
c->con.printerr("!!Setting the game modes can be dangerous and break your game!!\n");
|
||||
return CR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
c->con.printerr("Unrecognized parameter: %s\n",parameters[0].c_str());
|
||||
}
|
||||
}
|
||||
c->Suspend();
|
||||
World *world = c->getWorld();
|
||||
world->Start();
|
||||
world->ReadGameMode(gm);
|
||||
c->Resume();
|
||||
printCurrentModes(gm, c->con);
|
||||
if(set)
|
||||
{
|
||||
if(gm.g_mode == GAMEMODE_NONE || gm.g_type == GAMETYPE_VIEW_LEGENDS || gm.g_type == GAMETYPE_DWARF_RECLAIM)
|
||||
{
|
||||
c->con.printerr("It is not safe to set modes in menus.\n");
|
||||
return CR_FAILURE;
|
||||
}
|
||||
c->con << "\nPossible choices:" << endl
|
||||
<< "0 = Fortress Mode" << endl
|
||||
<< "1 = Adventurer Mode" << endl
|
||||
<< "2 = Arena Mode" << endl
|
||||
<< "3 = Arena, controlling creature" << endl
|
||||
<< "c = cancel/do nothing" << endl;
|
||||
uint32_t select=99;
|
||||
|
||||
string selected;
|
||||
input_again:
|
||||
c->con.lineedit("Enter new mode: ",selected);
|
||||
if(selected == "c")
|
||||
return CR_OK;
|
||||
const char * start = selected.c_str();
|
||||
char * end = 0;
|
||||
select = strtol(start, &end, 10);
|
||||
if(!end || end==start || select > 3)
|
||||
{
|
||||
c->con.printerr("This is not a valid selection.\n");
|
||||
goto input_again;
|
||||
}
|
||||
|
||||
switch(select)
|
||||
{
|
||||
case 0:
|
||||
gm.g_mode = GAMEMODE_DWARF;
|
||||
gm.g_type = GAMETYPE_DWARF_MAIN;
|
||||
break;
|
||||
case 1:
|
||||
gm.g_mode = GAMEMODE_ADVENTURE;
|
||||
gm.g_type = GAMETYPE_ADVENTURE_MAIN;
|
||||
break;
|
||||
case 2:
|
||||
gm.g_mode = GAMEMODE_DWARF;
|
||||
gm.g_type = GAMETYPE_DWARF_ARENA;
|
||||
break;
|
||||
case 3:
|
||||
gm.g_mode = GAMEMODE_ADVENTURE;
|
||||
gm.g_type = GAMETYPE_ADVENTURE_ARENA;
|
||||
break;
|
||||
}
|
||||
c->Suspend();
|
||||
world->WriteGameMode(gm);
|
||||
c->Resume();
|
||||
cout << endl;
|
||||
}
|
||||
return CR_OK;
|
||||
}
|
@ -0,0 +1,330 @@
|
||||
// Just show some position data
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <climits>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <dfhack/modules/Maps.h>
|
||||
#include <dfhack/modules/Gui.h>
|
||||
#include <dfhack/modules/Materials.h>
|
||||
#include <dfhack/extra/MapExtras.h>
|
||||
#include <dfhack/MiscUtils.h>
|
||||
#include <xgetopt.h>
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using namespace DFHack;
|
||||
|
||||
DFhackCExport command_result df_probe (Core * c, vector <string> & parameters);
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "probe";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("probe",
|
||||
"A tile probe",
|
||||
df_probe));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
/*
|
||||
bool parseOptions(vector<string> ¶ms, bool &showBlock, bool &showDesig,
|
||||
bool &showOccup, bool &showTile, bool &showMisc)
|
||||
{
|
||||
// With no options set, show everything.
|
||||
showBlock = true;
|
||||
showDesig = true;
|
||||
showOccup = true;
|
||||
showTile = true;
|
||||
showMisc = true;
|
||||
|
||||
bool _showBlock = false;
|
||||
bool _showDesig = false;
|
||||
bool _showOccup = false;
|
||||
bool _showTile = false;
|
||||
bool _showMisc = false;
|
||||
|
||||
char c;
|
||||
xgetopt opt(params, "bdotm");
|
||||
opt.opterr = 0;
|
||||
while ((c = opt()) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
_showBlock = true;
|
||||
break;
|
||||
case 'd':
|
||||
_showDesig = true;
|
||||
break;
|
||||
case 'o':
|
||||
_showOccup = true;
|
||||
break;
|
||||
case 't':
|
||||
_showTile = true;
|
||||
break;
|
||||
case 'm':
|
||||
_showMisc = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
switch (opt.optopt)
|
||||
{
|
||||
// For when we take arguments
|
||||
default:
|
||||
if (isprint(opt.optopt))
|
||||
std::cerr << "Unknown option -" << opt.optopt << "!"
|
||||
<< std::endl;
|
||||
else
|
||||
std::cerr << "Unknown option character " << (int) opt.optopt << "!"
|
||||
<< std::endl;
|
||||
}
|
||||
default:
|
||||
// Um.....
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If any options set, show only those requested via options.
|
||||
if(_showBlock || _showDesig || _showOccup || _showTile || _showMisc)
|
||||
{
|
||||
showBlock = false;
|
||||
showDesig = false;
|
||||
showOccup = false;
|
||||
showTile = false;
|
||||
showMisc = false;
|
||||
|
||||
showBlock = _showBlock;
|
||||
showDesig = _showDesig;
|
||||
showOccup = _showOccup;
|
||||
showTile = _showTile;
|
||||
showMisc = _showMisc;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
*/
|
||||
using namespace DFHack;
|
||||
DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
|
||||
{
|
||||
//bool showBlock, showDesig, showOccup, showTile, showMisc;
|
||||
Console & con = c->con;
|
||||
/*
|
||||
if (!parseOptions(parameters, showBlock, showDesig, showOccup,
|
||||
showTile, showMisc))
|
||||
{
|
||||
con.printerr("Unknown parameters!\n");
|
||||
return CR_FAILURE;
|
||||
}
|
||||
*/
|
||||
|
||||
BEGIN_PROBE:
|
||||
c->Suspend();
|
||||
|
||||
DFHack::Gui *Gui = c->getGui();
|
||||
DFHack::Materials *Materials = c->getMaterials();
|
||||
DFHack::VersionInfo* mem = c->vinfo;
|
||||
DFHack::Maps *Maps = c->getMaps();
|
||||
bool hasmats = Materials->ReadInorganicMaterials();
|
||||
|
||||
if(!Maps->Start())
|
||||
{
|
||||
con.printerr("Unable to access map data!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
MapExtras::MapCache mc (Maps);
|
||||
|
||||
int32_t regionX, regionY, regionZ;
|
||||
Maps->getPosition(regionX,regionY,regionZ);
|
||||
|
||||
bool have_features = Maps->StartFeatures();
|
||||
|
||||
int32_t cursorX, cursorY, cursorZ;
|
||||
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
|
||||
if(cursorX == -30000)
|
||||
{
|
||||
con.printerr("No cursor; place cursor over tile to probe.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DFCoord cursor (cursorX,cursorY,cursorZ);
|
||||
|
||||
uint32_t blockX = cursorX / 16;
|
||||
uint32_t tileX = cursorX % 16;
|
||||
uint32_t blockY = cursorY / 16;
|
||||
uint32_t tileY = cursorY % 16;
|
||||
|
||||
MapExtras::Block * b = mc.BlockAt(cursor/16);
|
||||
mapblock40d & block = b->raw;
|
||||
if(b)
|
||||
{
|
||||
con.print("block addr: 0x%x\n\n", block.origin);
|
||||
/*
|
||||
if (showBlock)
|
||||
{
|
||||
con.print("block flags:\n");
|
||||
print_bits<uint32_t>(block.blockflags.whole,con);
|
||||
con.print("\n\n");
|
||||
}
|
||||
*/
|
||||
int16_t tiletype = mc.tiletypeAt(cursor);
|
||||
naked_designation &des = block.designation[tileX][tileY].bits;
|
||||
/*
|
||||
if(showDesig)
|
||||
{
|
||||
con.print("designation\n");
|
||||
print_bits<uint32_t>(block.designation[tileX][tileY].whole,
|
||||
con);
|
||||
con.print("\n\n");
|
||||
}
|
||||
|
||||
if(showOccup)
|
||||
{
|
||||
con.print("occupancy\n");
|
||||
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
|
||||
con);
|
||||
con.print("\n\n");
|
||||
}
|
||||
*/
|
||||
|
||||
// tiletype
|
||||
con.print("tiletype: %d", tiletype);
|
||||
if(tileName(tiletype))
|
||||
con.print(" = %s",tileName(tiletype));
|
||||
con.print("\n");
|
||||
|
||||
DFHack::TileShape shape = tileShape(tiletype);
|
||||
DFHack::TileMaterial material = tileMaterial(tiletype);
|
||||
DFHack::TileSpecial special = tileSpecial(tiletype);
|
||||
con.print("%-10s: %4d %s\n","Class" ,shape,
|
||||
TileShapeString[ shape ]);
|
||||
con.print("%-10s: %4d %s\n","Material" ,
|
||||
material,TileMaterialString[ material ]);
|
||||
con.print("%-10s: %4d %s\n","Special" ,
|
||||
special, TileSpecialString[ special ]);
|
||||
con.print("%-10s: %4d\n" ,"Variant" ,
|
||||
tileVariant(tiletype));
|
||||
con.print("%-10s: %s\n" ,"Direction",
|
||||
tileDirection(tiletype).getStr());
|
||||
con.print("\n");
|
||||
|
||||
con.print("temperature1: %d U\n",mc.temperature1At(cursor));
|
||||
con.print("temperature2: %d U\n",mc.temperature2At(cursor));
|
||||
|
||||
// biome, geolayer
|
||||
con << "biome: " << des.biome << std::endl;
|
||||
con << "geolayer: " << des.geolayer_index
|
||||
<< std::endl;
|
||||
int16_t base_rock = mc.baseMaterialAt(cursor);
|
||||
if(base_rock != -1)
|
||||
{
|
||||
con << "Layer material: " << dec << base_rock;
|
||||
if(hasmats)
|
||||
con << " / " << Materials->inorganic[base_rock].id
|
||||
<< " / "
|
||||
<< Materials->inorganic[base_rock].name
|
||||
<< endl;
|
||||
else
|
||||
con << endl;
|
||||
}
|
||||
int16_t vein_rock = mc.veinMaterialAt(cursor);
|
||||
if(vein_rock != -1)
|
||||
{
|
||||
con << "Vein material (final): " << dec << vein_rock;
|
||||
if(hasmats)
|
||||
con << " / " << Materials->inorganic[vein_rock].id
|
||||
<< " / "
|
||||
<< Materials->inorganic[vein_rock].name
|
||||
<< endl;
|
||||
else
|
||||
con << endl;
|
||||
}
|
||||
// liquids
|
||||
if(des.flow_size)
|
||||
{
|
||||
if(des.liquid_type == DFHack::liquid_magma)
|
||||
con <<"magma: ";
|
||||
else con <<"water: ";
|
||||
con << des.flow_size << std::endl;
|
||||
}
|
||||
if(des.flow_forbid)
|
||||
con << "flow forbid" << std::endl;
|
||||
if(des.pile)
|
||||
con << "stockpile?" << std::endl;
|
||||
if(des.rained)
|
||||
con << "rained?" << std::endl;
|
||||
if(des.smooth)
|
||||
con << "smooth?" << std::endl;
|
||||
|
||||
#define PRINT_FLAG( X ) con.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
|
||||
PRINT_FLAG( hidden );
|
||||
PRINT_FLAG( light );
|
||||
PRINT_FLAG( skyview );
|
||||
PRINT_FLAG( subterranean );
|
||||
PRINT_FLAG( water_table );
|
||||
PRINT_FLAG( rained );
|
||||
|
||||
DFCoord pc(blockX, blockY);
|
||||
|
||||
if(have_features)
|
||||
{
|
||||
t_feature * local = 0;
|
||||
t_feature * global = 0;
|
||||
Maps->ReadFeatures(&(b->raw),&local,&global);
|
||||
PRINT_FLAG( feature_local );
|
||||
if(local)
|
||||
{
|
||||
con.print("%-16s", "");
|
||||
con.print(" %4d", block.local_feature);
|
||||
con.print(" (%2d)", local->type);
|
||||
con.print(" addr 0x%X ", local->origin);
|
||||
con.print(" %s\n", sa_feature(local->type));
|
||||
}
|
||||
PRINT_FLAG( feature_global );
|
||||
if(global)
|
||||
{
|
||||
con.print("%-16s", "");
|
||||
con.print(" %4d", block.global_feature);
|
||||
con.print(" (%2d)", global->type);
|
||||
con.print(" %s\n", sa_feature(global->type));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_FLAG( feature_local );
|
||||
PRINT_FLAG( feature_global );
|
||||
}
|
||||
#undef PRINT_FLAG
|
||||
con << "local feature idx: " << block.local_feature
|
||||
<< endl;
|
||||
con << "global feature idx: " << block.global_feature
|
||||
<< endl;
|
||||
con << "mystery: " << block.mystery << endl;
|
||||
con << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
c->Resume();
|
||||
return CR_OK;
|
||||
}
|
@ -0,0 +1,553 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/modules/Vegetation.h>
|
||||
#include <dfhack/modules/Maps.h>
|
||||
#include <dfhack/modules/Gui.h>
|
||||
#include <dfhack/TileTypes.h>
|
||||
#include <dfhack/extra/MapExtras.h>
|
||||
using namespace MapExtras;
|
||||
using namespace DFHack;
|
||||
|
||||
typedef vector <DFHack::DFCoord> coord_vec;
|
||||
|
||||
class Brush
|
||||
{
|
||||
public:
|
||||
virtual ~Brush(){};
|
||||
virtual string Name(){return "bogus";};
|
||||
virtual coord_vec points(MapCache & mc,DFHack::DFCoord start) = 0;
|
||||
};
|
||||
/**
|
||||
* generic 3D rectangle brush. you can specify the dimensions of
|
||||
* the rectangle and optionally which tile is its 'center'
|
||||
*/
|
||||
class RectangleBrush : public Brush
|
||||
{
|
||||
public:
|
||||
RectangleBrush(int x, int y, int z = 1, int centerx = -1, int centery = -1, int centerz = -1)
|
||||
{
|
||||
if(centerx == -1)
|
||||
cx_ = x/2;
|
||||
else
|
||||
cx_ = centerx;
|
||||
if(centery == -1)
|
||||
cy_ = y/2;
|
||||
else
|
||||
cy_ = centery;
|
||||
if(centerz == -1)
|
||||
cz_ = z/2;
|
||||
else
|
||||
cz_ = centerz;
|
||||
x_ = x;
|
||||
y_ = y;
|
||||
z_ = z;
|
||||
};
|
||||
string Name()
|
||||
{
|
||||
if(x_ == 1 && y_ == 1 && z_ == 1)
|
||||
return "point";
|
||||
else
|
||||
{
|
||||
std::stringstream str;
|
||||
str << x_ << "x" << y_;
|
||||
if(z_ != 1)
|
||||
{
|
||||
str << "x" << z_;
|
||||
}
|
||||
return str.str();
|
||||
}
|
||||
}
|
||||
coord_vec points(MapCache & mc, DFHack::DFCoord start)
|
||||
{
|
||||
coord_vec v;
|
||||
DFHack::DFCoord iterstart(start.x - cx_, start.y - cy_, start.z - cz_);
|
||||
DFHack::DFCoord iter = iterstart;
|
||||
for(int xi = 0; xi < x_; xi++)
|
||||
{
|
||||
for(int yi = 0; yi < y_; yi++)
|
||||
{
|
||||
for(int zi = 0; zi < z_; zi++)
|
||||
{
|
||||
if(mc.testCoord(iter))
|
||||
v.push_back(iter);
|
||||
iter.z++;
|
||||
}
|
||||
iter.z = iterstart.z;
|
||||
iter.y++;
|
||||
}
|
||||
iter.y = iterstart.y;
|
||||
iter.x ++;
|
||||
}
|
||||
return v;
|
||||
};
|
||||
~RectangleBrush(){};
|
||||
private:
|
||||
int x_, y_, z_;
|
||||
int cx_, cy_, cz_;
|
||||
};
|
||||
|
||||
/**
|
||||
* stupid block brush, legacy. use when you want to apply something to a whole DF map block.
|
||||
*/
|
||||
class BlockBrush : public Brush
|
||||
{
|
||||
public:
|
||||
BlockBrush(){};
|
||||
~BlockBrush(){};
|
||||
string Name()
|
||||
{
|
||||
return "block";
|
||||
}
|
||||
coord_vec points(MapCache & mc, DFHack::DFCoord start)
|
||||
{
|
||||
coord_vec v;
|
||||
DFHack::DFCoord blockc = start % 16;
|
||||
DFHack::DFCoord iterc = blockc * 16;
|
||||
if( !mc.testCoord(start) )
|
||||
return v;
|
||||
|
||||
for(int xi = 0; xi < 16; xi++)
|
||||
{
|
||||
for(int yi = 0; yi < 16; yi++)
|
||||
{
|
||||
v.push_back(iterc);
|
||||
iterc.y++;
|
||||
}
|
||||
iterc.x ++;
|
||||
}
|
||||
return v;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Column from a position through open space tiles
|
||||
* example: create a column of magma
|
||||
*/
|
||||
class ColumnBrush : public Brush
|
||||
{
|
||||
public:
|
||||
ColumnBrush(){};
|
||||
~ColumnBrush(){};
|
||||
string Name()
|
||||
{
|
||||
return "column";
|
||||
}
|
||||
coord_vec points(MapCache & mc, DFHack::DFCoord start)
|
||||
{
|
||||
coord_vec v;
|
||||
bool juststarted = true;
|
||||
while (mc.testCoord(start))
|
||||
{
|
||||
uint16_t tt = mc.tiletypeAt(start);
|
||||
if(DFHack::LowPassable(tt) || juststarted && DFHack::HighPassable(tt))
|
||||
{
|
||||
v.push_back(start);
|
||||
juststarted = false;
|
||||
start.z++;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
return v;
|
||||
};
|
||||
};
|
||||
|
||||
DFhackCExport command_result df_tiles (Core * c, vector <string> & parameters);
|
||||
DFhackCExport command_result df_paint (Core * c, vector <string> & parameters);
|
||||
|
||||
struct Settings
|
||||
{
|
||||
Settings()
|
||||
{
|
||||
brush = new RectangleBrush(1,1);
|
||||
mode = none;
|
||||
liquidamount = 0;
|
||||
}
|
||||
enum
|
||||
{
|
||||
none,
|
||||
water,
|
||||
magma,
|
||||
obsidian_wall,
|
||||
obsidian_floor,
|
||||
obsidian_ramp,
|
||||
river_source,
|
||||
} mode;
|
||||
int liquidamount;
|
||||
enum
|
||||
{
|
||||
set_flow,
|
||||
unset_flow,
|
||||
ignore_flow,
|
||||
} flowmode;
|
||||
enum
|
||||
{
|
||||
liquid_set,
|
||||
liquid_add,
|
||||
liquid_remove,
|
||||
} liquidmode;
|
||||
Brush * brush;
|
||||
} settings;
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "tiles";
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("tiles", "A tile painter. See 'tile help' for details.", df_tiles));
|
||||
commands.push_back(PluginCommand("paint", "Paint with the last used brush.", df_paint));
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result df_tiles (Core * c, vector <string> & parameters)
|
||||
{
|
||||
int32_t x,y,z;
|
||||
uint32_t x_max,y_max,z_max;
|
||||
DFHack::Maps * Maps;
|
||||
DFHack::Gui * Position;
|
||||
Brush * brush = new RectangleBrush(1,1);
|
||||
|
||||
Maps = c->getMaps();
|
||||
Maps->Start();
|
||||
Maps->getSize(x_max,y_max,z_max);
|
||||
Position = c->getGui();
|
||||
|
||||
string command = "";
|
||||
if(command=="help" || command == "?")
|
||||
{
|
||||
c->con.print
|
||||
(
|
||||
"Usage: This command sets the properties of the tile painter brush\n"
|
||||
" It is best used from the console, or as an alias bound to a hotkey\n"
|
||||
" After setting the brush\n"
|
||||
"\n"
|
||||
"Modes:\n"
|
||||
"none - nothing, the default"
|
||||
"magma [0-7] - magma, accepts depth\n"
|
||||
"water [0-7] - water\n"
|
||||
"obsidian - obsidian wall\n"
|
||||
"obsfloor - obsidian floors\n"
|
||||
"obsramp - obsidian ramp (forces 1 z-level brush)\n"
|
||||
"riversource - an endless source of water (floor tile)\n"
|
||||
"type ### - plain tiletype painter. For a list of tile types see:\n"
|
||||
" http://df.magmawiki.com/index.php/DF2010:Tile_types_in_DF_memory\n"
|
||||
"\n"
|
||||
"Set-Modes (only for magma/water):\n"
|
||||
"add - set liquid level everywhere\n"
|
||||
"keep - set liquid level only where liquids are already present\n"
|
||||
"\n"
|
||||
"Brush:\n"
|
||||
"point - single tile [p]\n"
|
||||
"#x#[x#] - block with cursor at bottom north-west [r]\n"
|
||||
" (any place, any size)\n"
|
||||
" Example:"
|
||||
" 3x3x2 = rectangle 3x3 x2 z-levels\n"
|
||||
" The z-level part is optional - ommiting it is\n"
|
||||
" the same as setting it to 1.\n"
|
||||
"h#x#[x#] - Same as previous, only the rectangle is 'hollow'.\n"
|
||||
"block - DF map block with cursor in it\n"
|
||||
" (regular spaced 16x16x1 blocks)\n"
|
||||
"column - Column from cursor, up through free space\n"
|
||||
"line - A line between two points.\n"
|
||||
"circle [#] - A filled circle, optional # specifies radius in tiles.\n"
|
||||
"hcircle [#,#] - A hollow circle (ring). First # specifies radius\n"
|
||||
" second # ring thickness in tiles.\n"
|
||||
"\n"
|
||||
"Other:\n"
|
||||
"help or ? - print this list of commands\n"
|
||||
"paint - same effect as if you also the 'paint' command at the same time.\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
else if(command == "m")
|
||||
{
|
||||
mode = "magma";
|
||||
}
|
||||
else if(command == "o")
|
||||
{
|
||||
mode = "obsidian";
|
||||
}
|
||||
else if(command == "of")
|
||||
{
|
||||
mode = "obsidian_floor";
|
||||
}
|
||||
else if(command == "w")
|
||||
{
|
||||
mode = "water";
|
||||
}
|
||||
else if(command == "f")
|
||||
{
|
||||
mode = "flowbits";
|
||||
}
|
||||
else if(command == "rs")
|
||||
{
|
||||
mode = "riversource";
|
||||
}
|
||||
else if(command == "point" || command == "p")
|
||||
{
|
||||
delete brush;
|
||||
brushname = "point";
|
||||
brush = new RectangleBrush(1,1);
|
||||
}
|
||||
else if(command == "range" || command == "r")
|
||||
{
|
||||
cout << " :set range width<" << width << "># ";
|
||||
getline(cin, command);
|
||||
width = command == "" ? width : atoi (command.c_str());
|
||||
if(width < 1) width = 1;
|
||||
|
||||
cout << " :set range height<" << height << "># ";
|
||||
getline(cin, command);
|
||||
height = command == "" ? height : atoi (command.c_str());
|
||||
if(height < 1) height = 1;
|
||||
|
||||
cout << " :set range z-levels<" << z_levels << "># ";
|
||||
getline(cin, command);
|
||||
z_levels = command == "" ? z_levels : atoi (command.c_str());
|
||||
if(z_levels < 1) z_levels = 1;
|
||||
delete brush;
|
||||
if(width == 1 && height == 1 && z_levels == 1)
|
||||
{
|
||||
brushname="point";
|
||||
}
|
||||
else
|
||||
{
|
||||
brushname = "range";
|
||||
}
|
||||
brush = new RectangleBrush(width,height,z_levels,0,0,0);
|
||||
}
|
||||
else if(command == "block")
|
||||
{
|
||||
delete brush;
|
||||
brushname = "block";
|
||||
brush = new BlockBrush();
|
||||
}
|
||||
else if(command == "column")
|
||||
{
|
||||
delete brush;
|
||||
brushname = "column";
|
||||
brush = new ColumnBrush();
|
||||
}
|
||||
else if(command == "q")
|
||||
{
|
||||
end = true;
|
||||
}
|
||||
else if(command == "f+")
|
||||
{
|
||||
flowmode = "f+";
|
||||
}
|
||||
else if(command == "f-")
|
||||
{
|
||||
flowmode = "f-";
|
||||
}
|
||||
else if(command == "f.")
|
||||
{
|
||||
flowmode = "f.";
|
||||
}
|
||||
else if(command == "s+")
|
||||
{
|
||||
setmode = "s+";
|
||||
}
|
||||
else if(command == "s-")
|
||||
{
|
||||
setmode = "s-";
|
||||
}
|
||||
else if(command == "s.")
|
||||
{
|
||||
setmode = "s.";
|
||||
}
|
||||
// blah blah, bad code, bite me.
|
||||
else if(command == "0")
|
||||
amount = 0;
|
||||
else if(command == "1")
|
||||
amount = 1;
|
||||
else if(command == "2")
|
||||
amount = 2;
|
||||
else if(command == "3")
|
||||
amount = 3;
|
||||
else if(command == "4")
|
||||
amount = 4;
|
||||
else if(command == "5")
|
||||
amount = 5;
|
||||
else if(command == "6")
|
||||
amount = 6;
|
||||
else if(command == "7")
|
||||
amount = 7;
|
||||
else if(command.empty())
|
||||
{
|
||||
DF->Suspend();
|
||||
do
|
||||
{
|
||||
if(!Maps->Start())
|
||||
{
|
||||
cout << "Can't see any DF map loaded." << endl;
|
||||
break;
|
||||
}
|
||||
if(!Position->getCursorCoords(x,y,z))
|
||||
{
|
||||
cout << "Can't get cursor coords! Make sure you have a cursor active in DF." << endl;
|
||||
break;
|
||||
}
|
||||
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
|
||||
MapCache mcache(Maps);
|
||||
DFHack::DFCoord cursor(x,y,z);
|
||||
coord_vec all_tiles = brush->points(mcache,cursor);
|
||||
cout << "working..." << endl;
|
||||
if(mode == "obsidian")
|
||||
{
|
||||
coord_vec::iterator iter = all_tiles.begin();
|
||||
while (iter != all_tiles.end())
|
||||
{
|
||||
mcache.setTiletypeAt(*iter, 331);
|
||||
mcache.setTemp1At(*iter,10015);
|
||||
mcache.setTemp2At(*iter,10015);
|
||||
DFHack::t_designation des = mcache.designationAt(*iter);
|
||||
des.bits.flow_size = 0;
|
||||
mcache.setDesignationAt(*iter, des);
|
||||
iter ++;
|
||||
}
|
||||
}
|
||||
if(mode == "obsidian_floor")
|
||||
{
|
||||
coord_vec::iterator iter = all_tiles.begin();
|
||||
while (iter != all_tiles.end())
|
||||
{
|
||||
mcache.setTiletypeAt(*iter, 340);
|
||||
iter ++;
|
||||
}
|
||||
}
|
||||
else if(mode == "riversource")
|
||||
{
|
||||
set <Block *> seen_blocks;
|
||||
coord_vec::iterator iter = all_tiles.begin();
|
||||
while (iter != all_tiles.end())
|
||||
{
|
||||
mcache.setTiletypeAt(*iter, 90);
|
||||
|
||||
DFHack::t_designation a = mcache.designationAt(*iter);
|
||||
a.bits.liquid_type = DFHack::liquid_water;
|
||||
a.bits.liquid_static = false;
|
||||
a.bits.flow_size = 7;
|
||||
mcache.setTemp1At(*iter,10015);
|
||||
mcache.setTemp2At(*iter,10015);
|
||||
mcache.setDesignationAt(*iter,a);
|
||||
|
||||
Block * b = mcache.BlockAt((*iter)/16);
|
||||
DFHack::t_blockflags bf = b->BlockFlags();
|
||||
bf.bits.liquid_1 = true;
|
||||
bf.bits.liquid_2 = true;
|
||||
b->setBlockFlags(bf);
|
||||
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
else if(mode== "magma" || mode== "water" || mode == "flowbits")
|
||||
{
|
||||
set <Block *> seen_blocks;
|
||||
coord_vec::iterator iter = all_tiles.begin();
|
||||
while (iter != all_tiles.end())
|
||||
{
|
||||
DFHack::DFCoord current = *iter;
|
||||
DFHack::t_designation des = mcache.designationAt(current);
|
||||
uint16_t tt = mcache.tiletypeAt(current);
|
||||
DFHack::naked_designation & flow = des.bits;
|
||||
// don't put liquids into places where they don't belong...
|
||||
if(!DFHack::FlowPassable(tt))
|
||||
{
|
||||
iter++;
|
||||
continue;
|
||||
}
|
||||
if(mode != "flowbits")
|
||||
{
|
||||
if(setmode == "s.")
|
||||
{
|
||||
flow.flow_size = amount;
|
||||
}
|
||||
else if(setmode == "s+")
|
||||
{
|
||||
if(flow.flow_size < amount)
|
||||
flow.flow_size = amount;
|
||||
}
|
||||
else if(setmode == "s-")
|
||||
{
|
||||
if (flow.flow_size > amount)
|
||||
flow.flow_size = amount;
|
||||
}
|
||||
if(amount != 0 && mode == "magma")
|
||||
{
|
||||
flow.liquid_type = DFHack::liquid_magma;
|
||||
mcache.setTemp1At(current,12000);
|
||||
mcache.setTemp2At(current,12000);
|
||||
}
|
||||
else if(amount != 0 && mode == "water")
|
||||
{
|
||||
flow.liquid_type = DFHack::liquid_water;
|
||||
mcache.setTemp1At(current,10015);
|
||||
mcache.setTemp2At(current,10015);
|
||||
}
|
||||
else if(amount == 0 && (mode == "water" || mode == "magma"))
|
||||
{
|
||||
// reset temperature to sane default
|
||||
mcache.setTemp1At(current,10015);
|
||||
mcache.setTemp2At(current,10015);
|
||||
}
|
||||
mcache.setDesignationAt(current,des);
|
||||
}
|
||||
seen_blocks.insert(mcache.BlockAt((*iter) / 16));
|
||||
iter++;
|
||||
}
|
||||
set <Block *>::iterator biter = seen_blocks.begin();
|
||||
while (biter != seen_blocks.end())
|
||||
{
|
||||
DFHack::t_blockflags bflags = (*biter)->BlockFlags();
|
||||
if(flowmode == "f+")
|
||||
{
|
||||
bflags.bits.liquid_1 = true;
|
||||
bflags.bits.liquid_2 = true;
|
||||
(*biter)->setBlockFlags(bflags);
|
||||
}
|
||||
else if(flowmode == "f-")
|
||||
{
|
||||
bflags.bits.liquid_1 = false;
|
||||
bflags.bits.liquid_2 = false;
|
||||
(*biter)->setBlockFlags(bflags);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "flow bit 1 = " << bflags.bits.liquid_1 << endl;
|
||||
cout << "flow bit 2 = " << bflags.bits.liquid_2 << endl;
|
||||
}
|
||||
biter ++;
|
||||
}
|
||||
}
|
||||
if(mcache.WriteAll())
|
||||
cout << "OK" << endl;
|
||||
else
|
||||
cout << "Something failed horribly! RUN!" << endl;
|
||||
Maps->Finish();
|
||||
} while (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << command << " : unknown command." << endl;
|
||||
}
|
||||
return CR_OK;
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
#include <DFHack.h>
|
||||
#include <dfhack/extra/MapExtras.h>
|
||||
#include <xgetopt.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <dfhack/extra/termutil.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool temporary_terminal = TemporaryTerminal();
|
||||
srand(time(0));
|
||||
|
||||
uint32_t x_max = 0, y_max = 0, z_max = 0;
|
||||
DFHack::ContextManager manager("Memory.xml");
|
||||
|
||||
DFHack::Context *context = manager.getSingleContext();
|
||||
if (!context->Attach())
|
||||
{
|
||||
std::cerr << "Unable to attach to DF!" << std::endl;
|
||||
if(temporary_terminal)
|
||||
std::cin.ignore();
|
||||
return 1;
|
||||
}
|
||||
|
||||
DFHack::Maps *maps = context->getMaps();
|
||||
if (!maps->Start())
|
||||
{
|
||||
std::cerr << "Cannot get map info!" << std::endl;
|
||||
context->Detach();
|
||||
if(temporary_terminal)
|
||||
std::cin.ignore();
|
||||
return 1;
|
||||
}
|
||||
DFHack::Gui * Gui = context->getGui();
|
||||
maps->getSize(x_max, y_max, z_max);
|
||||
MapExtras::MapCache map(maps);
|
||||
uint32_t vegCount = 0;
|
||||
DFHack::Vegetation *veg = context->getVegetation();
|
||||
if (!veg->Start(vegCount))
|
||||
{
|
||||
std::cerr << "Unable to read vegetation!" << std::endl;
|
||||
if(temporary_terminal)
|
||||
cin.ignore();
|
||||
return 1;
|
||||
}
|
||||
int32_t x,y,z;
|
||||
if(Gui->getCursorCoords(x,y,z))
|
||||
{
|
||||
vector<DFHack::dfh_plant> alltrees;
|
||||
if(maps->ReadVegetation(x/16,y/16,z,&alltrees))
|
||||
{
|
||||
for(size_t i = 0 ; i < alltrees.size(); i++)
|
||||
{
|
||||
DFHack::dfh_plant & tree = alltrees[i];
|
||||
if(tree.sdata.x == x && tree.sdata.y == y && tree.sdata.z == z)
|
||||
{
|
||||
if(DFHack::tileShape(map.tiletypeAt(DFHack::DFCoord(x,y,z))) == DFHack::SAPLING_OK)
|
||||
{
|
||||
tree.sdata.grow_counter = DFHack::sapling_to_tree_threshold;
|
||||
veg->Write(tree);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int grown = 0;
|
||||
for(size_t i = 0 ; i < vegCount; i++)
|
||||
{
|
||||
DFHack::dfh_plant p;
|
||||
veg->Read(i,p);
|
||||
uint16_t ttype = map.tiletypeAt(DFHack::DFCoord(p.sdata.x,p.sdata.y,p.sdata.z));
|
||||
if(!p.sdata.is_shrub && DFHack::tileShape(ttype) == DFHack::SAPLING_OK)
|
||||
{
|
||||
p.sdata.grow_counter = DFHack::sapling_to_tree_threshold;
|
||||
veg->Write(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
veg->Finish();
|
||||
maps->Finish();
|
||||
context->Detach();
|
||||
if(temporary_terminal)
|
||||
{
|
||||
std::cout << " Press any key to finish.";
|
||||
std::cin.ignore();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <DFHack.h>
|
||||
using namespace DFHack;
|
||||
|
||||
void printCurrentModes(t_gamemodes gm)
|
||||
{
|
||||
cout << "Current game mode:\t" << gm.game_mode << " (";
|
||||
switch(gm.game_mode)
|
||||
{
|
||||
case GM_Fort:
|
||||
cout << "Fortress)" << endl;
|
||||
break;
|
||||
case GM_Adventurer:
|
||||
cout << "Adventurer)" << endl;
|
||||
break;
|
||||
case GM_Menu:
|
||||
cout << "Menu)" << endl;
|
||||
break;
|
||||
case GM_Arena:
|
||||
cout << "Arena)" << endl;
|
||||
break;
|
||||
case GM_Arena_Assumed:
|
||||
cout << "Arena - Assumed)" << endl;
|
||||
break;
|
||||
case GM_Kittens:
|
||||
cout << "Kittens!)" << endl;
|
||||
break;
|
||||
case GM_Worldgen:
|
||||
cout << "Worldgen)" << endl;
|
||||
break;
|
||||
}
|
||||
cout << "Current control mode:\t" << gm.control_mode << " (";
|
||||
switch (gm.control_mode)
|
||||
{
|
||||
case CM_Managing:
|
||||
cout << "Managing)" << endl;
|
||||
break;
|
||||
case CM_DirectControl:
|
||||
cout << "Direct Control)" << endl;
|
||||
break;
|
||||
case CM_Kittens:
|
||||
cout << "Kittens!)" << endl;
|
||||
break;
|
||||
case CM_Menu:
|
||||
cout << "Menu)" << endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
string command = "";
|
||||
DFHack::ContextManager DFMgr("Memory.xml");
|
||||
DFHack::Context *DF = DFMgr.getSingleContext();
|
||||
try
|
||||
{
|
||||
DF->Attach();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
#ifndef LINUX_BUILD
|
||||
cin.ignore();
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
World *world = DF->getWorld();
|
||||
world->Start();
|
||||
bool end = false;
|
||||
t_gamemodes gm;
|
||||
while(!end)
|
||||
{
|
||||
DF->Suspend();
|
||||
world->ReadGameMode(gm);
|
||||
DF->Resume();
|
||||
printCurrentModes(gm);
|
||||
|
||||
cout << "\nOptions:" << endl
|
||||
<< "'c' to change modes" << endl
|
||||
<< "'q' to quit" << endl
|
||||
<< "anything else to refresh" << endl
|
||||
<< ">";
|
||||
getline(cin, command);
|
||||
if (command=="c")
|
||||
{
|
||||
cout << "\n\tPossible choices:" << endl
|
||||
<< "Game Modes:\t\tControl Modes:" << endl
|
||||
<< "0 = Fortress\t\t0 = Managing" << endl
|
||||
<< "1 = Adventurer\t\t1 = Direct Control" << endl
|
||||
<< "2 = Legends\t\t2 = Kittens!" << endl
|
||||
<< "3 = Menu\t\t3 = Menu" << endl
|
||||
<< "4 = Arena" << endl
|
||||
<< "5 = Arena - Assumed" << endl
|
||||
<< "6 = Kittens!" << endl
|
||||
<< "7 = Worldgen" << endl << endl;
|
||||
uint32_t newgm=99, newcm=99;
|
||||
while (newgm>GM_MAX)
|
||||
{
|
||||
cout << "Enter new game mode: ";
|
||||
cin >> newgm;
|
||||
}
|
||||
while (newcm>CM_MAX)
|
||||
{
|
||||
cout << "Enter new control mode: ";
|
||||
cin >> newcm;
|
||||
}
|
||||
gm.game_mode = (GameMode)newgm;
|
||||
gm.control_mode = (ControlMode)newcm;
|
||||
DF->Suspend();
|
||||
world->WriteGameMode(gm);
|
||||
DF->Resume();
|
||||
cout << endl;
|
||||
}
|
||||
else if (command == "q")
|
||||
{
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,345 +0,0 @@
|
||||
// Just show some position data
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <climits>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
|
||||
#define DFHACK_WANT_MISCUTILS 1
|
||||
#define DFHACK_WANT_TILETYPES 1
|
||||
#include <DFHack.h>
|
||||
#include <dfhack/extra/MapExtras.h>
|
||||
#include <xgetopt.h>
|
||||
#include <dfhack/extra/termutil.h>
|
||||
|
||||
bool parseOptions(int argc, char **argv, bool &showBlock, bool &showDesig,
|
||||
bool &showOccup, bool &showTile, bool &showMisc)
|
||||
{
|
||||
// With no options set, show everything.
|
||||
showBlock = true;
|
||||
showDesig = true;
|
||||
showOccup = true;
|
||||
showTile = true;
|
||||
showMisc = true;
|
||||
|
||||
bool _showBlock = false;
|
||||
bool _showDesig = false;
|
||||
bool _showOccup = false;
|
||||
bool _showTile = false;
|
||||
bool _showMisc = false;
|
||||
|
||||
char c;
|
||||
xgetopt opt(argc, argv, "bdotm");
|
||||
opt.opterr = 0;
|
||||
while ((c = opt()) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'b':
|
||||
_showBlock = true;
|
||||
break;
|
||||
case 'd':
|
||||
_showDesig = true;
|
||||
break;
|
||||
case 'o':
|
||||
_showOccup = true;
|
||||
break;
|
||||
case 't':
|
||||
_showTile = true;
|
||||
break;
|
||||
case 'm':
|
||||
_showMisc = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
switch (opt.optopt)
|
||||
{
|
||||
// For when we take arguments
|
||||
default:
|
||||
if (isprint(opt.optopt))
|
||||
std::cerr << "Unknown option -" << opt.optopt << "!"
|
||||
<< std::endl;
|
||||
else
|
||||
std::cerr << "Unknown option character " << (int) opt.optopt << "!"
|
||||
<< std::endl;
|
||||
}
|
||||
default:
|
||||
// Um.....
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If any options set, show only those requested via options.
|
||||
if(_showBlock || _showDesig || _showOccup || _showTile || _showMisc)
|
||||
{
|
||||
showBlock = false;
|
||||
showDesig = false;
|
||||
showOccup = false;
|
||||
showTile = false;
|
||||
showMisc = false;
|
||||
|
||||
showBlock = _showBlock;
|
||||
showDesig = _showDesig;
|
||||
showOccup = _showOccup;
|
||||
showTile = _showTile;
|
||||
showMisc = _showMisc;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
using namespace DFHack;
|
||||
int main (int numargs, char ** args)
|
||||
{
|
||||
bool temporary_terminal = TemporaryTerminal();
|
||||
DFHack::ContextManager DFMgr("Memory.xml");
|
||||
DFHack::Context *DF = DFMgr.getSingleContext();
|
||||
|
||||
bool showBlock, showDesig, showOccup, showTile, showMisc;
|
||||
|
||||
if (!parseOptions(numargs, args, showBlock, showDesig, showOccup,
|
||||
showTile, showMisc))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
BEGIN_PROBE:
|
||||
try
|
||||
{
|
||||
DF->Attach();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
if(temporary_terminal)
|
||||
cin.ignore();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
DFHack::Gui *Gui = DF->getGui();
|
||||
DFHack::Materials *Materials = DF->getMaterials();
|
||||
DFHack::VersionInfo* mem = DF->getMemoryInfo();
|
||||
DFHack::Maps *Maps = DF->getMaps();
|
||||
DFHack::Process * p = DF->getProcess();
|
||||
bool hasmats = Materials->ReadInorganicMaterials();
|
||||
|
||||
if(!Maps->Start())
|
||||
{
|
||||
std::cerr << "Unable to access map data!" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapExtras::MapCache mc (Maps);
|
||||
|
||||
OffsetGroup *mapsg = mem->getGroup("Maps");
|
||||
OffsetGroup *mapblockg = mapsg->getGroup("block");
|
||||
|
||||
uint32_t region_x_offset = mapsg->getAddress("region_x");
|
||||
uint32_t region_y_offset = mapsg->getAddress("region_y");
|
||||
uint32_t region_z_offset = mapsg->getAddress("region_z");
|
||||
|
||||
uint32_t designatus = mapblockg->getOffset("designation");
|
||||
uint32_t occup = mapblockg->getOffset("occupancy");
|
||||
uint32_t biomus = mapblockg->getOffset("biome_stuffs");
|
||||
|
||||
int32_t regionX, regionY, regionZ;
|
||||
|
||||
// read position of the region inside DF world
|
||||
p->readDWord (region_x_offset, (uint32_t &)regionX);
|
||||
p->readDWord (region_y_offset, (uint32_t &)regionY);
|
||||
p->readDWord (region_z_offset, (uint32_t &)regionZ);
|
||||
|
||||
bool have_features = Maps->StartFeatures();
|
||||
|
||||
int32_t cursorX, cursorY, cursorZ;
|
||||
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
|
||||
if(cursorX == -30000)
|
||||
{
|
||||
std::cerr << "No cursor; place cursor over tile to probe."
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
DFCoord cursor (cursorX,cursorY,cursorZ);
|
||||
|
||||
uint32_t blockX = cursorX / 16;
|
||||
uint32_t tileX = cursorX % 16;
|
||||
uint32_t blockY = cursorY / 16;
|
||||
uint32_t tileY = cursorY % 16;
|
||||
|
||||
MapExtras::Block * b = mc.BlockAt(cursor/16);
|
||||
mapblock40d & block = b->raw;
|
||||
if(b)
|
||||
{
|
||||
printf("block addr: 0x%x\n\n", block.origin);
|
||||
|
||||
if (showBlock)
|
||||
{
|
||||
printf("block flags:\n");
|
||||
print_bits<uint32_t>(block.blockflags.whole,std::cout);
|
||||
std::cout << endl << endl;
|
||||
}
|
||||
|
||||
int16_t tiletype = mc.tiletypeAt(cursor);
|
||||
naked_designation &des = block.designation[tileX][tileY].bits;
|
||||
|
||||
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
|
||||
uint32_t occupr = block.origin + occup + (tileX * 16 + tileY) * sizeof(t_occupancy);
|
||||
|
||||
if(showDesig)
|
||||
{
|
||||
printf("designation offset: 0x%x\n", designato);
|
||||
print_bits<uint32_t>(block.designation[tileX][tileY].whole,
|
||||
std::cout);
|
||||
std::cout << endl << endl;
|
||||
}
|
||||
|
||||
if(showOccup)
|
||||
{
|
||||
printf("occupancy offset: 0x%x\n", occupr);
|
||||
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
|
||||
std::cout);
|
||||
std::cout << endl << endl;
|
||||
}
|
||||
|
||||
if(showTile)
|
||||
{
|
||||
// tiletype
|
||||
std::cout <<"tiletype: " << tiletype;
|
||||
if(tileName(tiletype))
|
||||
std::cout << " = " << tileName(tiletype) << std::endl;
|
||||
|
||||
DFHack::TileShape shape = tileShape(tiletype);
|
||||
DFHack::TileMaterial material = tileMaterial(tiletype);
|
||||
DFHack::TileSpecial special = tileSpecial(tiletype);
|
||||
printf("%-10s: %4d %s\n","Class" ,shape,
|
||||
TileShapeString[ shape ]);
|
||||
printf("%-10s: %4d %s\n","Material" ,
|
||||
material,TileMaterialString[ material ]);
|
||||
printf("%-10s: %4d %s\n","Special" ,
|
||||
special, TileSpecialString[ special ]);
|
||||
printf("%-10s: %4d\n" ,"Variant" ,
|
||||
tileVariant(tiletype));
|
||||
printf("%-10s: %s\n" ,"Direction",
|
||||
tileDirection(tiletype).getStr());
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if(showMisc)
|
||||
{
|
||||
std::cout <<"temperature1: " << mc.temperature1At(cursor)
|
||||
<< " U" << std::endl;
|
||||
std::cout <<"temperature2: " << mc.temperature2At(cursor)
|
||||
<< " U" << std::endl;
|
||||
|
||||
// biome, geolayer
|
||||
std::cout << "biome: " << des.biome << std::endl;
|
||||
std::cout << "geolayer: " << des.geolayer_index
|
||||
<< std::endl;
|
||||
int16_t base_rock = mc.baseMaterialAt(cursor);
|
||||
if(base_rock != -1)
|
||||
{
|
||||
cout << "Layer material: " << dec << base_rock;
|
||||
if(hasmats)
|
||||
cout << " / " << Materials->inorganic[base_rock].id
|
||||
<< " / "
|
||||
<< Materials->inorganic[base_rock].name
|
||||
<< endl;
|
||||
else
|
||||
cout << endl;
|
||||
}
|
||||
int16_t vein_rock = mc.veinMaterialAt(cursor);
|
||||
if(vein_rock != -1)
|
||||
{
|
||||
cout << "Vein material (final): " << dec << vein_rock;
|
||||
if(hasmats)
|
||||
cout << " / " << Materials->inorganic[vein_rock].id
|
||||
<< " / "
|
||||
<< Materials->inorganic[vein_rock].name
|
||||
<< endl;
|
||||
else
|
||||
cout << endl;
|
||||
}
|
||||
// liquids
|
||||
if(des.flow_size)
|
||||
{
|
||||
if(des.liquid_type == DFHack::liquid_magma)
|
||||
std::cout <<"magma: ";
|
||||
else std::cout <<"water: ";
|
||||
std::cout << des.flow_size << std::endl;
|
||||
}
|
||||
if(des.flow_forbid)
|
||||
std::cout << "flow forbid" << std::endl;
|
||||
if(des.pile)
|
||||
std::cout << "stockpile?" << std::endl;
|
||||
if(des.rained)
|
||||
std::cout << "rained?" << std::endl;
|
||||
if(des.smooth)
|
||||
std::cout << "smooth?" << std::endl;
|
||||
printf("biomestuffs: 0x%x\n", block.origin + biomus);
|
||||
|
||||
#define PRINT_FLAG( X ) printf("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
|
||||
PRINT_FLAG( hidden );
|
||||
PRINT_FLAG( light );
|
||||
PRINT_FLAG( skyview );
|
||||
PRINT_FLAG( subterranean );
|
||||
PRINT_FLAG( water_table );
|
||||
PRINT_FLAG( rained );
|
||||
|
||||
DFCoord pc(blockX, blockY);
|
||||
|
||||
if(have_features)
|
||||
{
|
||||
t_feature * local = 0;
|
||||
t_feature * global = 0;
|
||||
Maps->ReadFeatures(&(b->raw),&local,&global);
|
||||
PRINT_FLAG( feature_local );
|
||||
if(local)
|
||||
{
|
||||
printf("%-16s", "");
|
||||
printf(" %4d", block.local_feature);
|
||||
printf(" (%2d)", local->type);
|
||||
printf(" addr 0x%X ", local->origin);
|
||||
printf(" %s\n", sa_feature(local->type));
|
||||
}
|
||||
PRINT_FLAG( feature_global );
|
||||
if(global)
|
||||
{
|
||||
printf("%-16s", "");
|
||||
printf(" %4d", block.global_feature);
|
||||
printf(" (%2d)", global->type);
|
||||
printf(" %s\n", sa_feature(global->type));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_FLAG( feature_local );
|
||||
PRINT_FLAG( feature_global );
|
||||
}
|
||||
#undef PRINT_FLAG
|
||||
cout << "local feature idx: " << block.local_feature
|
||||
<< endl;
|
||||
cout << "global feature idx: " << block.global_feature
|
||||
<< endl;
|
||||
cout << "mystery: " << block.mystery << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DF->Detach();
|
||||
if(temporary_terminal)
|
||||
{
|
||||
std::cout << "Press any key to refresh..." << std::endl;
|
||||
cin.ignore();
|
||||
goto BEGIN_PROBE;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue