本文整理汇总了C++中dfhack::Gui::getCursorCoords方法的典型用法代码示例。如果您正苦于以下问题:C++ Gui::getCursorCoords方法的具体用法?C++ Gui::getCursorCoords怎么用?C++ Gui::getCursorCoords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dfhack::Gui
的用法示例。
在下文中一共展示了Gui::getCursorCoords方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: df_cprobe
command_result df_cprobe (Core * c, vector <string> & parameters)
{
Console & con = c->con;
CoreSuspender suspend(c);
DFHack::Gui *Gui = c->getGui();
int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
{
con.printerr("No cursor; place cursor over creature to probe.\n");
}
else
{
for(size_t i = 0; i < world->units.all.size(); i++)
{
df::unit * unit = world->units.all[i];
if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
{
con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ_id, unit->civ_id);
break;
}
}
}
return CR_OK;
}
示例2: main
//.........这里部分代码省略.........
//Init
cerr << "Attaching to DF..." << endl;
try
{
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
// init the map
DFHack::Maps *Mapz = DF->getMaps();
if (!Mapz->Start())
{
cerr << "Can't init map. Exiting." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
Mapz->getSize(x_max,y_max,z_max);
//Get cursor
int32_t cursorX, cursorY, cursorZ;
DFHack::Gui *Gui = DF->getGui();
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if (-30000==cursorX)
{
cout << "No cursor position found. Exiting." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
//Block coordinates
int32_t bx=cursorX/16, by=cursorY/16, bz=cursorZ;
//Tile coordinates within block
int32_t tx=cursorX%16, ty=cursorY%16, tz=cursorZ;
/*
//Access the DF interface to pause the game.
//Copied from the reveal tool.
DFHack::Gui *Gui =DF->getGui();
cout << "Pausing..." << endl;
Gui->SetPauseState(true);
DF->Resume();
waitmsec(1000);
DF->Suspend();
*/
//Verify that every z-level at this location exists.
for (int32_t Z = 0; Z<= bz ;Z++)
{
if ( ! Mapz->isValidBlock(bx,by,Z) )
{
cout << "This block does't exist! Exiting." << endl;
#ifndef LINUX_BUILD
示例3: main
//.........这里部分代码省略.........
cin.ignore();
#endif
return 1;
}
DFHack::Gui *Gui = DF->getGui();
DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Process * p = DF->getProcess();
OffsetGroup * OG_Maps = mem->getGroup("Maps");
OffsetGroup * OG_MapBlock = OG_Maps->getGroup("block");
OffsetGroup * OG_LocalFt = OG_Maps->getGroup("features")->getGroup("local");
uint32_t designations = OG_MapBlock->getOffset("designation");
uint32_t block_feature1 = OG_MapBlock->getOffset("feature_local");
uint32_t block_feature2 = OG_MapBlock->getOffset("feature_global");
uint32_t region_x_offset = OG_Maps->getAddress("region_x");
uint32_t region_y_offset = OG_Maps->getAddress("region_y");
uint32_t region_z_offset = OG_Maps->getAddress("region_z");
uint32_t feature1_start_ptr = OG_LocalFt->getAddress("start_ptr");
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);
while(1){
int32_t cx1,cy1,cz1;
cx1 = -30000;
while(cx1 == -30000)
{
DF->ForceResume();
cout << "Set cursor at first position, then press any key";
cin.ignore();
DF->Suspend();
Gui->getCursorCoords(cx1,cy1,cz1);
}
uint32_t tx1,ty1,tz1;
tx1 = cx1/16;
ty1 = cy1/16;
tz1 = cz1;
int32_t cx2,cy2,cz2;
cx2 = -30000;
while(cx2 == -30000)
{
DF->Resume();
cout << "Set cursor at second position, then press any key";
cin.ignore();
DF->Suspend();
Gui->getCursorCoords(cx2,cy2,cz2);
}
uint32_t tx2,ty2,tz2;
tx2 = cx2/16;
ty2 = cy2/16;
tz2 = cz2;
sort(tx1,tx2);
sort(ty1,ty2);
sort(tz1,tz2);
sort(cx1,cx2);
sort(cy1,cy2);
sort(cz1,cz2);
vector <vector<vector<string> > >dig(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1)));
vector <vector<vector<string> > >build(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1)));
mapblock40d block;
DFHack::Maps *Maps = DF->getMaps();
示例4: main
int main (int argc, char* argv[])
{
// Command line options
bool updown = false;
if(argc > 1 && strcmp(argv[1],"-x") == 0)
updown = true;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
uint32_t x_max,y_max,z_max;
DFHack::Maps * Maps = DF->getMaps();
DFHack::Gui * Gui = DF->getGui();
// init the map
if(!Maps->Start())
{
cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz);
while(cx == -30000)
{
cerr << "Cursor is not active. Point the cursor at a vein." << endl;
DF->Resume();
cin.ignore();
DF->Suspend();
Gui->getCursorCoords(cx,cy,cz);
}
DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1)
{
cerr << "I won't dig the borders. That would be cheating!" << endl;
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
MapCache * MCache = new MapCache(Maps);
DFHack::t_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy);
int16_t veinmat = MCache->veinMaterialAt(xy);
if( veinmat == -1 )
{
cerr << "This tile is non-vein. Bye :)" << endl;
delete MCache;
DF->Detach();
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole);
stack <DFHack::DFCoord> flood;
flood.push(xy);
while( !flood.empty() )
{
DFHack::DFCoord current = flood.top();
flood.pop();
int16_t vmat2 = MCache->veinMaterialAt(current);
tt = MCache->tiletypeAt(current);
if(!DFHack::isWallTerrain(tt))
continue;
if(vmat2!=veinmat)
continue;
// found a good tile, dig+unset material
DFHack::t_designation des = MCache->designationAt(current);
DFHack::t_designation des_minus;
DFHack::t_designation des_plus;
des_plus.whole = des_minus.whole = 0;
int16_t vmat_minus = -1;
//.........这里部分代码省略.........
示例5: vdig
DFhackCExport command_result vdig (Core * c, vector <string> & parameters)
{
uint32_t x_max,y_max,z_max;
bool updown = false;
for(int i = 0; i < parameters.size();i++)
{
if(parameters.size() && parameters[0]=="x")
updown = true;
else if(parameters[i] == "help" || parameters[i] == "?")
{
c->con.print("Designates a whole vein under the cursor for digging.\n"
"Options:\n"
"x - follow veins through z-levels with stairs.\n"
);
return CR_OK;
}
}
Console & con = c->con;
c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui();
// init the map
if(!Maps->Start())
{
con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume();
return CR_FAILURE;
}
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz);
while(cx == -30000)
{
con.printerr("Cursor is not active. Point the cursor at a vein.\n");
c->Resume();
return CR_FAILURE;
}
DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1)
{
con.printerr("I won't dig the borders. That would be cheating!\n");
c->Resume();
return CR_FAILURE;
}
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
DFHack::t_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy);
int16_t veinmat = MCache->veinMaterialAt(xy);
if( veinmat == -1 )
{
con.printerr("This tile is not a vein.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
con.print("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole);
stack <DFHack::DFCoord> flood;
flood.push(xy);
while( !flood.empty() )
{
DFHack::DFCoord current = flood.top();
flood.pop();
int16_t vmat2 = MCache->veinMaterialAt(current);
tt = MCache->tiletypeAt(current);
if(!DFHack::isWallTerrain(tt))
continue;
if(vmat2!=veinmat)
continue;
// found a good tile, dig+unset material
DFHack::t_designation des = MCache->designationAt(current);
DFHack::t_designation des_minus;
DFHack::t_designation des_plus;
des_plus.whole = des_minus.whole = 0;
int16_t vmat_minus = -1;
int16_t vmat_plus = -1;
bool below = 0;
bool above = 0;
if(updown)
{
if(MCache->testCoord(current-1))
{
below = 1;
des_minus = MCache->designationAt(current-1);
vmat_minus = MCache->veinMaterialAt(current-1);
}
if(MCache->testCoord(current+1))
{
above = 1;
des_plus = MCache->designationAt(current+1);
vmat_plus = MCache->veinMaterialAt(current+1);
}
}
//.........这里部分代码省略.........
示例6: filltraffic
DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector<std::string> & params)
{
//Maximum map size.
uint32_t x_max,y_max,z_max;
//Source and target traffic types.
e_traffic source = traffic_normal;
e_traffic target = traffic_normal;
//Option flags
bool updown = false;
bool checkpit = true;
bool checkbuilding = true;
//Loop through parameters
for(int i = 0; i < params.size();i++)
{
if(params[i] == "help" || params[i] == "?")
{
c->con.print("Flood-fill selected traffic type from the cursor.\n"
"Traffic Type Codes:\n"
"\tH: High Traffic\n"
"\tN: Normal Traffic\n"
"\tL: Low Traffic\n"
"\tR: Restricted Traffic\n"
"Other Options:\n"
"\tX: Fill accross z-levels.\n"
"\tB: Include buildings and stockpiles.\n"
"\tP: Include empty space.\n"
"Example:\n"
"'filltraffic H' - When used in a room with doors,\n"
" it will set traffic to HIGH in just that room."
);
return CR_OK;
}
switch (toupper(params[i][0]))
{
case 'H':
target = traffic_high; break;
case 'N':
target = traffic_normal; break;
case 'L':
target = traffic_low; break;
case 'R':
target = traffic_restricted; break;
case 'X':
updown = true; break;
case 'B':
checkbuilding = false; break;
case 'P':
checkpit = false; break;
}
}
//Initialization.
c->Suspend();
DFHack::Maps * Maps = c->getMaps();
DFHack::Gui * Gui = c->getGui();
// init the map
if(!Maps->Start())
{
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume();
return CR_FAILURE;
}
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz);
while(cx == -30000)
{
c->con.printerr("Cursor is not active.\n");
c->Resume();
return CR_FAILURE;
}
DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps);
DFHack::t_designation des = MCache->designationAt(xy);
int16_t tt = MCache->tiletypeAt(xy);
DFHack::t_occupancy oc;
if (checkbuilding)
oc = MCache->occupancyAt(xy);
source = des.bits.traffic;
if(source == target)
{
c->con.printerr("This tile is already set to the target traffic type.\n");
delete MCache;
c->Resume();
return CR_FAILURE;
}
if(DFHack::isWallTerrain(tt))
{
c->con.printerr("This tile is a wall. Please select a passable tile.\n");
//.........这里部分代码省略.........
示例7: df_tiles
//.........这里部分代码省略.........
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 ++;
}
}
示例8: df_liquids
//.........这里部分代码省略.........
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())
{
c->Suspend();
Maps = c->getMaps();
Maps->Start();
Maps->getSize(x_max,y_max,z_max);
Position = c->getGui();
do
{
if(!Maps->Start())
{
c->con << "Can't see any DF map loaded." << endl;
break;
}
if(!Position->getCursorCoords(x,y,z))
{
c->con << "Can't get cursor coords! Make sure you have a cursor active in DF." << endl;
break;
}
c->con << "cursor coords: " << x << "/" << y << "/" << z << endl;
MapCache mcache(Maps);
DFHack::DFCoord cursor(x,y,z);
coord_vec all_tiles = brush->points(mcache,cursor);
c->con << "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 ++;
}
}
示例9: main
//.........这里部分代码省略.........
BrushMat = DFHack::tilematerial_invalid;
cout << "Tile brush will not draw material." << endl;
break;
case 'O':
BrushType=-1;
BrushClass = DFHack::EMPTY;
BrushMat = DFHack::AIR;
cout << "Tile brush will draw Open Space." << endl;
break;
case 't':
BrushClass = DFHack::tileshape_invalid ;
BrushMat = DFHack::tilematerial_invalid;
BrushType = atol( command.c_str()+1 );
cout << "Tile brush type set to:" << endl;
printtiletype(BrushType);
break;
case 'q':
end = true;
cout << "Bye!" << endl;
break;
case 'd':
{
count=0;
cout << "Beginning to draw at cursor." << endl << "Press any key to stop drawing." << endl;
//DF->Suspend();
kbhit(); //throw away, just to be sure.
for(;;)
{
if(!Maps->Start())
{
cout << "Can't see any DF map loaded." << endl;
break;
}
if(!Gui->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;
tx=x%16; ty=y%16;
if(!Maps->isValidBlock(x/16,y/16,z))
{
cout << "Invalid block." << endl;
break;
}
//Read the tiles.
dirty=0;
Maps->ReadTileTypes((x/16),(y/16),z, &tiles);
oldT = tiles[tx][ty];
newT = -1;
if( 0<BrushType ){
//Explicit tile type set. Trust the user.
newT = BrushType;
}else if( 0==BrushMat && 0==BrushClass ){
//Special case, Empty Air.
newT = 32;
}else if( BrushMat>=0 && BrushClass>=0 && ( BrushClass != DFHack::tileTypeTable[oldT].shape || BrushMat != DFHack::tileTypeTable[oldT].material) ){
//Set tile material and class
newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tileTypeTable[oldT].variant , DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
if(newT<0) newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tilevariant_invalid, DFHack::tileTypeTable[oldT].special , DFHack::tileTypeTable[oldT].direction );
if(newT<0) newT = DFHack::findTileType(BrushClass,BrushMat, DFHack::tilevariant_invalid , DFHack::tileTypeTable[oldT].special , (uint32_t)0 );
}else if( BrushMat<0 && BrushClass>=0 && BrushClass != DFHack::tileTypeTable[oldT].shape ){
//Set current tile class only, as accurately as can be expected
示例10: immolations
/**
* Book of Immolations, chapter 1, verse 35:
* Armok emerged from the hellish depths and beheld the sunny realms for the first time.
* And he cursed the plants and trees for their bloodless wood, turning them into ash and smoldering ruin.
* Armok was pleased and great temples were built by the dwarves, for they shared his hatred for trees and plants.
*/
static command_result immolations (Core * c, do_what what, bool shrubs, bool trees, bool help)
{
static const char * what1 = "destroys";
static const char * what2 = "burns";
if(help)
{
c->con.print("Without any options, this command %s a plant under the cursor.\n"
"Options:\n"
"shrubs - affect all shrubs\n"
"trees - affect all trees\n"
"all - affect all plants\n",
what == do_immolate? what2 : what1
);
return CR_OK;
}
c->Suspend();
DFHack::Maps *maps = c->getMaps();
if (!maps->Start())
{
c->con.printerr( "Cannot get map info!\n");
c->Resume();
return CR_FAILURE;
}
DFHack::Gui * Gui = c->getGui();
uint32_t x_max, y_max, z_max;
maps->getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps);
DFHack::Vegetation *veg = c->getVegetation();
if (!veg->all_plants)
{
std::cerr << "Unable to read vegetation!" << std::endl;
return CR_FAILURE;
}
if(shrubs || trees)
{
int destroyed = 0;
for(size_t i = 0 ; i < veg->all_plants->size(); i++)
{
DFHack::df_plant *p = veg->all_plants->at(i);
if(shrubs && p->is_shrub || trees && !p->is_shrub)
{
if (what == do_immolate)
p->is_burning = true;
p->hitpoints = 0;
destroyed ++;
}
}
c->con.print("Praise Armok!\n");
}
else
{
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))
{
bool didit = false;
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(what == do_immolate)
tree->is_burning = true;
tree->hitpoints = 0;
didit = true;
break;
}
}
/*
if(!didit)
{
cout << "----==== There's NOTHING there! ====----" << endl;
}
*/
}
}
else
{
c->con.printerr("No mass destruction and no cursor...\n" );
}
}
// Cleanup
veg->Finish();
maps->Finish();
c->Resume();
return CR_OK;
}
示例11: df_grow
DFhackCExport command_result df_grow (Core * c, vector <string> & parameters)
{
for(int i = 0; i < parameters.size();i++)
{
if(parameters[i] == "help" || parameters[i] == "?")
{
c->con.print("This command turns all living saplings into full-grown trees.\n");
return CR_OK;
}
}
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;
}
示例12: df_probe
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;
}
*/
CoreSuspender suspend(c);
DFHack::Gui *Gui = c->getGui();
DFHack::Materials *Materials = c->getMaterials();
DFHack::VersionInfo* mem = c->vinfo;
std::vector<t_matglossInorganic> inorganic;
bool hasmats = Materials->CopyInorganicMaterials(inorganic);
if (!Maps::IsValid())
{
c->con.printerr("Map is not available!\n");
return CR_FAILURE;
}
MapExtras::MapCache mc;
int32_t regionX, regionY, regionZ;
Maps::getPosition(regionX,regionY,regionZ);
int32_t cursorX, cursorY, cursorZ;
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX == -30000)
{
con.printerr("No cursor; place cursor over tile to probe.\n");
return CR_FAILURE;
}
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);
if(!b && !b->valid)
{
con.printerr("No data.\n");
return CR_OK;
}
mapblock40d & block = b->raw;
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");
}
*/
df::tiletype tiletype = mc.tiletypeAt(cursor);
df::tile_designation &des = block.designation[tileX][tileY];
/*
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");
df::tiletype_shape shape = tileShape(tiletype);
df::tiletype_material material = tileMaterial(tiletype);
df::tiletype_special special = tileSpecial(tiletype);
df::tiletype_variant variant = tileVariant(tiletype);
con.print("%-10s: %4d %s\n","Class" ,shape,
ENUM_KEY_STR(tiletype_shape, shape));
con.print("%-10s: %4d %s\n","Material" ,
material, ENUM_KEY_STR(tiletype_material, material));
con.print("%-10s: %4d %s\n","Special" ,
special, ENUM_KEY_STR(tiletype_special, special));
con.print("%-10s: %4d %s\n" ,"Variant" ,
variant, ENUM_KEY_STR(tiletype_variant, variant));
con.print("%-10s: %s\n" ,"Direction",
//.........这里部分代码省略.........
示例13: main
int main (int argc, const char* argv[])
{
// Command line options
bool updown = false;
bool quiet = true;
// let's be more useful when double-clicked on windows
#ifndef LINUX_BUILD
quiet = false;
#endif
int dig_up_n = 5;
int dig_down_n = 5;
for(int i = 1; i < argc; i++)
{
string arg_cur = argv[i];
string arg_next = "";
int arg_next_int = -99999;
/* Check if argv[i+1] is a number >= 0 */
if (i < argc-1) {
arg_next = argv[i+1];
arg_next_int = strtoint(arg_next);
if (arg_next != "0" && arg_next_int == 0) {
arg_next_int = -99999;
}
}
if (arg_cur == "-x")
{
updown = true;
}
else if (arg_cur == "-q")
{
quiet = true;
}
else if(arg_cur == "-u" && i < argc-1)
{
if (arg_next_int < 0 || arg_next_int >= 99999) {
usage(argc, argv);
return 1;
}
dig_up_n = arg_next_int;
i++;
}
else if(arg_cur == "-d" && i < argc-1)
{
if (arg_next_int < 0 || arg_next_int >= 99999) {
usage(argc, argv);
return 1;
}
dig_down_n = arg_next_int;
i++;
}
else
{
usage(argc, argv);
return 1;
}
}
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
cerr << "Error getting context: " << e.what() << endl;
if (!quiet)
cin.ignore();
return 1;
}
uint32_t x_max,y_max,z_max;
DFHack::Maps * Maps = DF->getMaps();
DFHack::Gui * Gui = DF->getGui();
// init the map
if(!Maps->Start())
{
cerr << "Can't init map. Make sure you have a map loaded in DF." << endl;
DF->Detach();
if (!quiet)
cin.ignore();
return 1;
}
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
uint32_t tx_max = x_max * 16;
uint32_t ty_max = y_max * 16;
Gui->getCursorCoords(cx,cy,cz);
if (cx == -30000)
{
cerr << "Cursor is not active. Point the cursor at the position to dig at." << endl;
DF->Detach();
if (!quiet)
//.........这里部分代码省略.........
示例14: main
int main (int argc, char *argv[])
{
bool print_refs = false;
bool print_hex = false;
bool print_acc = false;
for(int i = 1; i < argc; i++)
{
char *arg = argv[i];
if (arg[0] != '-')
continue;
for (; *arg; arg++) {
switch (arg[0]) {
case 'r':
print_refs = true;
break;
case 'x':
print_hex = true;
break;
case 'a':
print_acc = true;
break;
}
}
}
DFHack::Process * p;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Materials * Materials = DF->getMaterials();
Materials->ReadAllMaterials();
DFHack::Gui * Gui = DF->getGui();
DFHack::Items * Items = DF->getItems();
Items->Start();
DFHack::VersionInfo * mem = DF->getMemoryInfo();
p = DF->getProcess();
int32_t x,y,z;
Gui->getCursorCoords(x,y,z);
std::vector<uint32_t> p_items;
Items->readItemVector(p_items);
uint32_t size = p_items.size();
// FIXME: tools should never be exposed to DFHack internals!
DFHack::OffsetGroup* itemGroup = mem->getGroup("Items");
uint32_t ref_vector = itemGroup->getOffset("item_ref_vector");
for(size_t i = 0; i < size; i++)
{
DFHack::dfh_item itm;
memset(&itm, 0, sizeof(DFHack::dfh_item));
Items->readItem(p_items[i],itm);
if (x != -30000
&& !(itm.base.x == x && itm.base.y == y && itm.base.z == z
&& itm.base.flags.on_ground
&& !itm.base.flags.in_chest
&& !itm.base.flags.in_inventory
&& !itm.base.flags.in_building))
continue;
printf(
"%5d: %08x %6d %08x (%d,%d,%d) #%08x [%d] *%d %s - %s\n",
i, itm.origin, itm.id, itm.base.flags.whole,
itm.base.x, itm.base.y, itm.base.z,
itm.base.vtable,
itm.wear_level,
itm.quantity,
Items->getItemClass(itm).c_str(),
Items->getItemDescription(itm, Materials).c_str()
);
if (print_hex)
hexdump(DF,p_items[i],0x300);
if (print_acc)
cout << Items->dumpAccessors(itm) << endl;
if (print_refs) {
DFHack::DfVector<uint32_t> p_refs(p, itm.origin + ref_vector);
for (size_t j = 0; j < p_refs.size(); j++) {
uint32_t vptr = p->readDWord(p_refs[j]);
//.........这里部分代码省略.........
示例15: autodump_main
static command_result autodump_main(Core * c, vector <string> & parameters)
{
// Command line options
bool destroy = false;
bool here = false;
if(parameters.size() > 0)
{
string & p = parameters[0];
if(p == "destroy")
destroy = true;
else if (p == "destroy-here")
destroy = here = true;
else if(p == "?" || p == "help")
{
c->con.print(
"This utility lets you quickly move all items designated to be dumped.\n"
"Items are instantly moved to the cursor position, the dump flag is unset,\n"
"and the forbid flag is set, as if it had been dumped normally.\n"
"Be aware that any active dump item tasks still point at the item.\n\n"
"Options:\n"
"destroy - instead of dumping, destroy the items instantly.\n"
"destroy-here - only affect the tile under cursor.\n"
);
return CR_OK;
}
}
c->Suspend();
DFHack::VersionInfo *mem = c->vinfo;
DFHack::Gui * Gui = c->getGui();
DFHack::Items * Items = c->getItems();
DFHack::Maps *Maps = c->getMaps();
vector <df_item*> p_items;
if(!Items->readItemVector(p_items))
{
c->con.printerr("Can't access the item vector.\n");
return CR_FAILURE;
}
std::size_t numItems = p_items.size();
// init the map
if(!Maps->Start())
{
c->con.printerr("Can't initialize map.\n");
return CR_FAILURE;
}
MapCache MC (Maps);
int i = 0;
int dumped_total = 0;
int cx, cy, cz;
DFCoord pos_cursor;
if(!destroy || here)
{
if (!Gui->getCursorCoords(cx,cy,cz))
{
c->con.printerr("Cursor position not found. Please enabled the cursor.\n");
return CR_FAILURE;
}
pos_cursor = DFCoord(cx,cy,cz);
}
if (!destroy)
{
{
Block * b = MC.BlockAt(pos_cursor / 16);
if(!b)
{
c->con.printerr("Cursor is in an invalid/uninitialized area. Place it over a floor.\n");
return CR_FAILURE;
}
uint16_t ttype = MC.tiletypeAt(pos_cursor);
if(!DFHack::isFloorTerrain(ttype))
{
c->con.printerr("Cursor should be placed over a floor.\n");
return CR_FAILURE;
}
}
}
coordmap counts;
// proceed with the dumpification operation
for(std::size_t i=0; i< numItems; i++)
{
df_item * itm = p_items[i];
DFCoord pos_item(itm->x, itm->y, itm->z);
// keep track how many items are at places. all items.
coordmap::iterator it = counts.find(pos_item);
if(it == counts.end())
{
std::pair< coordmap::iterator, bool > inserted = counts.insert(std::make_pair(pos_item,1));
it = inserted.first;
}
else
{
it->second ++;
}
// iterator is valid here, we use it later to decrement the pile counter if the item is moved
// only dump the stuff marked for dumping and laying on the ground
if ( !itm->flags.dump
//.........这里部分代码省略.........