Merge remote branch 'upstream/master'

develop
reverb 2010-10-25 16:12:27 -05:00
commit 48dd2fc424
7 changed files with 2745 additions and 903 deletions

2
.gitignore vendored

@ -29,3 +29,5 @@ dfhack/python/pydfhack/_pydfhack.so
dfhack/python/PyDFHack.egg-info dfhack/python/PyDFHack.egg-info
dfhack/python/build dfhack/python/build
dfhack/python/dist dfhack/python/dist
/cmakeall.bat

File diff suppressed because it is too large Load Diff

@ -67,6 +67,31 @@ TARGET_LINK_LIBRARIES(dfcopypaste dfhack)
ADD_EXECUTABLE(dfpaths paths.cpp) ADD_EXECUTABLE(dfpaths paths.cpp)
TARGET_LINK_LIBRARIES(dfpaths dfhack) TARGET_LINK_LIBRARIES(dfpaths dfhack)
# deramp
# Author: zilpin
# seeks entire map for 'remove ramp' designation, makes a floor, removes designation.
# intended use is to simulate old 'channel' functionality.
ADD_EXECUTABLE(dfderamp deramp.cpp)
TARGET_LINK_LIBRARIES(dfderamp dfhack)
# printtiletypes
# Author: zilpin
# Prints CSV dump of all tile type information.
# No DF process needed. Intended only for debugging and information purposes.
ADD_EXECUTABLE(dfprinttiletypes printtiletypes.cpp)
TARGET_LINK_LIBRARIES(dfprinttiletypes dfhack)
# hellhole
# Author: zilpin
# Creates a bottomless hole to hell.
# Experimental version hard-codes values.
# Will have many options in the future.
ADD_EXECUTABLE(dfhellhole hellhole.cpp)
TARGET_LINK_LIBRARIES(dfhellhole dfhack)
# this needs the C bindings # this needs the C bindings
IF(BUILD_DFHACK_C_BINDINGS) IF(BUILD_DFHACK_C_BINDINGS)
# for trying out some 'stuff' # for trying out some 'stuff'
@ -83,6 +108,9 @@ dfmoodump
dfdigger dfdigger
dfdigger2 dfdigger2
dfcatsplosion dfcatsplosion
dfderamp
dfprinttiletypes
dfhellhole
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
) )
IF(UNIX) IF(UNIX)

@ -0,0 +1,137 @@
// De-ramp. All ramps marked for removal are replaced with given tile (presently, normal floor).
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <assert.h>
#include <string.h>
using namespace std;
#include <DFHack.h>
#include <dfhack/DFTileTypes.h>
int main (void)
{
uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0;
uint32_t bytes_read = 0;
DFHack::designations40d designations;
DFHack::tiletypes40d tiles;
DFHack::tiletypes40d tilesAbove;
//DFHack::TileRow *ptile;
int32_t oldT, newT;
int16_t t;
int dirty=0, count=0;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
//sanity check
assert( sizeof(designations) == (16*16*sizeof(DFHack::t_designation)) );
//Init
try
{
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Maps *Mapz = DF->getMaps();
// init the map
if (!Mapz->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
Mapz->getSize(x_max,y_max,z_max);
uint8_t zeroes [16][16] = {0};
// walk the map
for (uint32_t x = 0; x< x_max;x++)
{
for (uint32_t y = 0; y< y_max;y++)
{
for (uint32_t z = 0; z< z_max;z++)
{
if (Mapz->isValidBlock(x,y,z))
{
dirty=0;
Mapz->ReadDesignations(x,y,z, &designations);
Mapz->ReadTileTypes(x,y,z, &tiles);
if (Mapz->isValidBlock(x,y,z+1))
{
Mapz->ReadTileTypes(x,y,z+1, &tilesAbove);
}
else
{
memset(&tilesAbove,0,sizeof(tilesAbove));
}
for (uint32_t ty=0;ty<16;++ty)
{
for (uint32_t tx=0;tx<16;++tx)
{
//Only the remove ramp designation (ignore channel designation, etc)
oldT = tiles[tx][ty];
if ( DFHack::designation_default == designations[tx][ty].bits.dig
&& DFHack::RAMP==DFHack::tileTypeTable[oldT].c)
{
//Current tile is a ramp.
//Set current tile, as accurately as can be expected
newT = DFHack::findSimilarTileType(oldT,DFHack::FLOOR);
//If no change, skip it (couldn't find a good tile type)
if ( oldT == newT) continue;
//Set new tile type, clear designation
tiles[tx][ty] = newT;
designations[tx][ty].bits.dig = DFHack::designation_no;
//Check the tile above this one, in case a downward slope needs to be removed.
if ( DFHack::RAMP_TOP == DFHack::tileTypeTable[tilesAbove[tx][ty]].c )
{
tilesAbove[tx][ty] = 32;
}
dirty=-1;
++count;
}
}
}
//If anything was changed, write it all.
if (dirty)
{
Mapz->WriteDesignations(x,y,z, &designations);
Mapz->WriteTileTypes(x,y,z, &tiles);
if (Mapz->isValidBlock(x,y,z+1))
{
Mapz->WriteTileTypes(x,y,z+1, &tilesAbove);
}
}
}
}
}
}
DF->Detach();
cout << "Found and changed " << count << " tiles." << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,100 @@
// Prints all the Tile Types known by DFHack.
// File is both fixed-field and CSV parsable.
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <map>
#include <stddef.h>
#include <assert.h>
using namespace std;
#include <DFHack.h>
#include <dfhack/DFTileTypes.h>
using namespace DFHack;
int main (int argc, char **argv)
{
FILE *f=stdout;
const int Columns = 7;
const char * Headings[Columns] = {"TileTypeID","Class","Material","V","Special","Direction","Description"};
size_t Size[ Columns ] = {};
int i;
//First, figure out column widths.
for(i=0;i<Columns;++i)
{
Size[i]=strlen(Headings[i])+1;
}
//Classes
fprintf(f,"\nTile Type Classes:\n");
for(i=0;i<tileclass_count;++i)
{
Size[1]=max<size_t>(Size[1],strlen(TileClassString[i]));
fprintf(f,"%4i ; %s\n", i, TileClassString[i] ,0 );
}
//Materials
fprintf(f,"\nTile Type Materials:\n");
for(i=0;i<tilematerial_count;++i)
{
Size[2]=max<size_t>(Size[2],strlen(TileMaterialString[i]));
fprintf(f,"%4i ; %s\n", i, TileMaterialString[i] ,0 );
}
//Specials
fprintf(f,"\nTile Type Specials:\n");
for(i=0;i<tilespecial_count;++i)
{
Size[4]=max<size_t>(Size[4],strlen(TileSpecialString[i]));
fprintf(f,"%4i ; %s\n", i, TileSpecialString[i] ,0 );
}
/* - Not needed for now -
//Direction is tricky
for(i=0;i<TILE_TYPE_ARRAY_LENGTH;++i)
Size[5]=max(Size[5], tileTypeTable[i].d.sum()+1 );
*/
//Print the headings first.
fprintf(f,"\nTile Types:\n");
for(i=0;i<Columns;++i)
{
if(i) putc(';',f);
fprintf(f," %-*s ",Size[i],Headings[i],0);
}
fprintf(f,"\n");
//Process the whole array.
//A macro should be used for making the strings safe, but they are left in naked ? blocks
//to illustrate the array references more clearly.
for(i=0;i<TILE_TYPE_ARRAY_LENGTH;++i)
{
fprintf(f," %*i ; %-*s ; %-*s ; %*c ; %-*s ; %-*s ; %s\n",
Size[0], i,
Size[1], ( tileTypeTable[i].name ? TileClassString[ tileTypeTable[i].c ] : "" ),
Size[2], ( tileTypeTable[i].name ? TileMaterialString[ tileTypeTable[i].m ] : "" ),
Size[3], ( tileTypeTable[i].v ? '0'+tileTypeTable[i].v : ' ' ),
Size[4], ( tileTypeTable[i].s ? TileSpecialString[ tileTypeTable[i].s ] : "" ),
Size[5], ( tileTypeTable[i].d.whole ? tileTypeTable[i].d.getStr() : "" ),
( tileTypeTable[i].name ? tileTypeTable[i].name : "" ),
0
);
}
fprintf(f,"\n");
#ifndef LINUX_BUILD
if( 1== argc)
{
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
#endif
return 0;
}

@ -1,132 +1,168 @@
// Just show some position data // Just show some position data
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <climits> #include <climits>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <ctime> #include <ctime>
#include <cstdio> #include <cstdio>
#define DFHACK_WANT_MISCUTILS #define DFHACK_WANT_MISCUTILS 1
#define DFHACK_WANT_TILETYPES #define DFHACK_WANT_TILETYPES 1
#include <DFHack.h> #include <DFHack.h>
using namespace DFHack; using namespace DFHack;
int main (int numargs, const char ** args) int main (int numargs, const char ** args)
{ {
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext(); DFHack::Context *DF = DFMgr.getSingleContext();
try BEGIN_PROBE:
{ try
DF->Attach(); {
} DF->Attach();
catch (std::exception& e) }
{ catch (std::exception& e)
std::cerr << e.what() << std::endl; {
#ifndef LINUX_BUILD std::cerr << e.what() << std::endl;
cin.ignore(); #ifndef LINUX_BUILD
#endif cin.ignore();
return 1; #endif
} return 1;
}
DFHack::Position *Pos = DF->getPosition();
DFHack::VersionInfo* mem = DF->getMemoryInfo();
DFHack::Maps *Maps = DF->getMaps(); DFHack::Position *Pos = DF->getPosition();
DFHack::Process * p = DF->getProcess(); DFHack::VersionInfo* mem = DF->getMemoryInfo();
OffsetGroup *mapsg = mem->getGroup("Maps"); DFHack::Maps *Maps = DF->getMaps();
OffsetGroup *mapblockg = mapsg->getGroup("block"); DFHack::Process * p = DF->getProcess();
OffsetGroup *localfeatg = mapsg->getGroup("features")->getGroup("local"); OffsetGroup *mapsg = mem->getGroup("Maps");
OffsetGroup *mapblockg = mapsg->getGroup("block");
uint32_t region_x_offset = mapsg->getAddress("region_x"); OffsetGroup *localfeatg = mapsg->getGroup("features")->getGroup("local");
uint32_t region_y_offset = mapsg->getAddress("region_y");
uint32_t region_z_offset = mapsg->getAddress("region_z"); uint32_t region_x_offset = mapsg->getAddress("region_x");
uint32_t region_y_offset = mapsg->getAddress("region_y");
uint32_t designatus = mapblockg->getOffset("designation"); uint32_t region_z_offset = mapsg->getAddress("region_z");
uint32_t block_feature1 = mapblockg->getOffset("feature_local");
uint32_t block_feature2 = mapblockg->getOffset("feature_global"); uint32_t designatus = mapblockg->getOffset("designation");
uint32_t block_feature1 = mapblockg->getOffset("feature_local");
uint32_t feature1_start_ptr = localfeatg->getAddress("start_ptr"); uint32_t block_feature2 = mapblockg->getOffset("feature_global");
int32_t regionX, regionY, regionZ;
uint32_t feature1_start_ptr = localfeatg->getAddress("start_ptr");
// read position of the region inside DF world int32_t regionX, regionY, regionZ;
p->readDWord (region_x_offset, (uint32_t &)regionX);
p->readDWord (region_y_offset, (uint32_t &)regionY); // read position of the region inside DF world
p->readDWord (region_z_offset, (uint32_t &)regionZ); p->readDWord (region_x_offset, (uint32_t &)regionX);
p->readDWord (region_y_offset, (uint32_t &)regionY);
Maps->Start(); p->readDWord (region_z_offset, (uint32_t &)regionZ);
int32_t cursorX, cursorY, cursorZ; Maps->Start();
Pos->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX != -30000) vector<DFHack::t_feature> global_features;
{ std::map <DFHack::planecoord, std::vector<DFHack::t_feature *> > local_features;
uint32_t blockX = cursorX / 16; Maps->ReadLocalFeatures(local_features);
uint32_t tileX = cursorX % 16; Maps->ReadGlobalFeatures(global_features);
uint32_t blockY = cursorY / 16;
uint32_t tileY = cursorY % 16; int32_t cursorX, cursorY, cursorZ;
t_temperatures tmpb1, tmpb2; Pos->getCursorCoords(cursorX,cursorY,cursorZ);
mapblock40d block; if(cursorX != -30000)
if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block)) {
{ uint32_t blockX = cursorX / 16;
Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2); uint32_t tileX = cursorX % 16;
printf("block addr: 0x%x\n", block.origin); uint32_t blockY = cursorY / 16;
int16_t tiletype = block.tiletypes[tileX][tileY]; uint32_t tileY = cursorY % 16;
naked_designation &des = block.designation[tileX][tileY].bits; t_temperatures tmpb1, tmpb2;
uint32_t &desw = block.designation[tileX][tileY].whole; mapblock40d block;
print_bits<uint32_t>(block.designation[tileX][tileY].whole,std::cout); if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block))
std::cout << endl; {
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,std::cout); Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2);
std::cout << endl; printf("block addr: 0x%x\n", block.origin);
int16_t tiletype = block.tiletypes[tileX][tileY];
// tiletype naked_designation &des = block.designation[tileX][tileY].bits;
std::cout <<"tiletype: " << tiletype; uint32_t &desw = block.designation[tileX][tileY].whole;
if(tileTypeTable[tiletype].name) print_bits<uint32_t>(block.designation[tileX][tileY].whole,std::cout);
std::cout << " = " << tileTypeTable[tiletype].name; std::cout << endl;
std::cout << std::endl; print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,std::cout);
std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl; std::cout << endl;
std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl;
// tiletype
// biome, geolayer std::cout <<"tiletype: " << tiletype;
std::cout << "biome: " << des.biome << std::endl; if(tileTypeTable[tiletype].name)
std::cout << "geolayer: " << des.geolayer_index << std::endl; std::cout << " = " << tileTypeTable[tiletype].name << std::endl;
// liquids printf("%-10s: %4d %s\n","Class",tileTypeTable[tiletype].c,TileClassString[ tileTypeTable[tiletype].c ] , 0);
if(des.flow_size) printf("%-10s: %4d %s\n","Material",tileTypeTable[tiletype].c,TileMaterialString[ tileTypeTable[tiletype].m ] , 0);
{ printf("%-10s: %4d %s\n","Special",tileTypeTable[tiletype].c,TileSpecialString[ tileTypeTable[tiletype].s ] , 0);
if(des.liquid_type == DFHack::liquid_magma) printf("%-10s: %4d\n","Variant",tileTypeTable[tiletype].v , 0);
std::cout <<"magma: "; printf("%-10s: %s\n","Direction",tileTypeTable[tiletype].d.getStr() , 0);
else std::cout <<"water: ";
std::cout << des.flow_size << std::endl;
} std::cout << std::endl;
if(des.flow_forbid) std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl;
std::cout << "flow forbid" << std::endl; std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl;
if(des.pile)
std::cout << "stockpile?" << std::endl; // biome, geolayer
if(des.rained) std::cout << "biome: " << des.biome << std::endl;
std::cout << "rained?" << std::endl; std::cout << "geolayer: " << des.geolayer_index << std::endl;
if(des.smooth)
std::cout << "smooth?" << std::endl; // liquids
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation); if(des.flow_size)
printf("designation offset: 0x%x\n", designato); {
if(des.light) if(des.liquid_type == DFHack::liquid_magma)
std::cout << "Light "; std::cout <<"magma: ";
else else std::cout <<"water: ";
std::cout << " "; std::cout << des.flow_size << std::endl;
if(des.skyview) }
std::cout << "SkyView "; if(des.flow_forbid)
else std::cout << "flow forbid" << std::endl;
std::cout << " "; if(des.pile)
if(des.subterranean) std::cout << "stockpile?" << std::endl;
std::cout << "Underground "; if(des.rained)
else std::cout << "rained?" << std::endl;
std::cout << " "; if(des.smooth)
std::cout << std::endl; std::cout << "smooth?" << std::endl;
} uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
} printf("designation offset: 0x%x\n", designato);
#ifndef LINUX_BUILD
std::cout << "Done. Press any key to continue" << std::endl; #define PRINT_FLAG( X ) printf("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
cin.ignore(); PRINT_FLAG( hidden );
#endif PRINT_FLAG( light );
return 0; PRINT_FLAG( skyview );
} PRINT_FLAG( subterranean );
PRINT_FLAG( water_table );
//PRINT_FLAG( rained );
planecoord pc;
pc.dim.x=blockX; pc.dim.y=blockY;
PRINT_FLAG( feature_local );
if( des.feature_local )
{
printf("%-16s %4d (%2d) %s\n", "",
block.local_feature,
local_features[pc][block.local_feature]->type,
sa_feature[local_features[pc][block.local_feature]->type]
);
}
PRINT_FLAG( feature_global );
if( des.feature_global ){
printf("%-16s %4d (%2d) %s\n", "",
block.global_feature,
global_features[block.global_feature].type,
sa_feature[global_features[block.global_feature].type]
);
}
#undef PRINT_FLAG
std::cout << std::endl;
}
}
DF->Detach();
#ifndef LINUX_BUILD
std::cout << "Press any key to refresh..." << std::endl;
cin.ignore();
goto BEGIN_PROBE;
#endif
return 0;
}