diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index 5f5df470d..f8fe24480 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -39,6 +39,7 @@ modules/Materials.cpp modules/Position.cpp modules/Translation.cpp modules/Vegetation.cpp +modules/Buildings.cpp ) SET(PROJECT_HDRS_LINUX diff --git a/dfhack/DFHackAPI.cpp b/dfhack/DFHackAPI.cpp index 6b65cf811..abd6741d8 100644 --- a/dfhack/DFHackAPI.cpp +++ b/dfhack/DFHackAPI.cpp @@ -42,6 +42,7 @@ distribution. #include "modules/Creatures.h" #include "modules/Translation.h" #include "modules/Vegetation.h" +#include "modules/Buildings.h" using namespace DFHack; @@ -217,66 +218,15 @@ Vegetation * API::getVegetation() return d->vegetation; } -/* -// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name -bool API::InitReadBuildings ( uint32_t& numbuildings ) -{ - int buildings = 0; - try - { - buildings = d->offset_descriptor->getAddress ("buildings"); - } - catch(Error::MissingMemoryDefinition) - { - return false; - } - d->buildingsInited = true; - d->p_bld = new DfVector (d->p,buildings, 4); - numbuildings = d->p_bld->getSize(); - return true; -} - - -// read one building -bool API::ReadBuilding (const int32_t index, t_building & building) +Buildings * API::getBuildings() { - if(!d->buildingsInited) return false; - - t_building_df40d bld_40d; - - // read pointer from vector at position - uint32_t temp = * (uint32_t *) d->p_bld->at (index); - //d->p_bld->read(index,(uint8_t *)&temp); - - //read building from memory - g_pProcess->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d); - - // transform - int32_t type = -1; - d->offset_descriptor->resolveObjectToClassID (temp, type); - building.origin = temp; - building.vtable = bld_40d.vtable; - building.x1 = bld_40d.x1; - building.x2 = bld_40d.x2; - building.y1 = bld_40d.y1; - building.y2 = bld_40d.y2; - building.z = bld_40d.z; - building.material = bld_40d.material; - building.type = type; - - return true; + if(!d->buildings) + d->buildings = new Buildings(d); + return d->buildings; } - -void API::FinishReadBuildings() -{ - if(d->p_bld) - { - delete d->p_bld; - d->p_bld = NULL; - } - d->buildingsInited = false; -} +/* +// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name bool API::InitReadEffects ( uint32_t & numeffects ) { diff --git a/dfhack/DFProcess-linux-SHM.cpp b/dfhack/DFProcess-linux-SHM.cpp index 113149a65..bcc55fb08 100644 --- a/dfhack/DFProcess-linux-SHM.cpp +++ b/dfhack/DFProcess-linux-SHM.cpp @@ -837,7 +837,7 @@ string SHMProcess::readClassName (uint32_t vptr) string raw = readCString(typestring); size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t end = raw.length(); - return raw.substr(start,end-start - 2); // trim the 'st' from the end + return raw.substr(start,end-start); } // get module index by name and version. bool 0 = error diff --git a/dfhack/DFProcess-linux-wine.cpp b/dfhack/DFProcess-linux-wine.cpp index 253fef3a1..da4a11fb2 100644 --- a/dfhack/DFProcess-linux-wine.cpp +++ b/dfhack/DFProcess-linux-wine.cpp @@ -576,6 +576,6 @@ string WineProcess::readClassName (uint32_t vptr) int rtti = readDWord(vptr - 0x4); int typeinfo = readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV - raw.resize(raw.length() - 4);// trim st@@ from end + raw.resize(raw.length() - 2);// trim @@ from end return raw; } \ No newline at end of file diff --git a/dfhack/DFProcess-linux.cpp b/dfhack/DFProcess-linux.cpp index e2bf16af6..71220a051 100644 --- a/dfhack/DFProcess-linux.cpp +++ b/dfhack/DFProcess-linux.cpp @@ -530,5 +530,5 @@ string NormalProcess::readClassName (uint32_t vptr) string raw = readCString(typestring); size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers size_t end = raw.length(); - return raw.substr(start,end-start - 2); // trim the 'st' from the end + return raw.substr(start,end-start); } \ No newline at end of file diff --git a/dfhack/DFProcess-windows-SHM.cpp b/dfhack/DFProcess-windows-SHM.cpp index 8e5bf0920..49ceabeac 100644 --- a/dfhack/DFProcess-windows-SHM.cpp +++ b/dfhack/DFProcess-windows-SHM.cpp @@ -894,7 +894,7 @@ string SHMProcess::readClassName (uint32_t vptr) int rtti = readDWord(vptr - 0x4); int typeinfo = readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV - raw.resize(raw.length() - 4);// trim st@@ from end + raw.resize(raw.length() - 2);// trim @@ from end return raw; } diff --git a/dfhack/DFProcess-windows.cpp b/dfhack/DFProcess-windows.cpp index ce3e0a6cf..b1dac9568 100644 --- a/dfhack/DFProcess-windows.cpp +++ b/dfhack/DFProcess-windows.cpp @@ -463,6 +463,6 @@ string NormalProcess::readClassName (uint32_t vptr) int rtti = readDWord(vptr - 0x4); int typeinfo = readDWord(rtti + 0xC); string raw = readCString(typeinfo + 0xC); // skips the .?AV - raw.resize(raw.length() - 4);// trim st@@ from end + raw.resize(raw.length() - 2);// trim @@ from end return raw; } \ No newline at end of file diff --git a/dfhack/include/DFHackAPI.h b/dfhack/include/DFHackAPI.h index 5a6ee82f8..cba0af297 100644 --- a/dfhack/include/DFHackAPI.h +++ b/dfhack/include/DFHackAPI.h @@ -50,6 +50,7 @@ namespace DFHack class Materials; class Translation; class Vegetation; + class Buildings; class DFHACK_EXPORT API { @@ -94,6 +95,7 @@ namespace DFHack Materials * getMaterials(); Translation * getTranslation(); Vegetation * getVegetation(); + Buildings * getBuildings(); /* * Constructions (costructed walls, floors, ramps, etc...) @@ -106,14 +108,6 @@ namespace DFHack /// cleanup after reading constructions void FinishReadConstructions(); */ - /* - * Buildings - also includes zones and stockpiles - */ - /* - bool InitReadBuildings ( uint32_t & numbuildings ); - bool ReadBuilding(const int32_t index, t_building & building); - void FinishReadBuildings(); - */ /* * Effects like mist, dragonfire or dust */ diff --git a/dfhack/include/DFTypes.h b/dfhack/include/DFTypes.h index 2afd1f4f5..9722463c0 100644 --- a/dfhack/include/DFTypes.h +++ b/dfhack/include/DFTypes.h @@ -117,117 +117,6 @@ struct t_construction word type; // NOTE: the actual field is in a different place */ -//raw -struct t_building_df40d -{ - uint32_t vtable; - uint32_t x1; - uint32_t y1; - uint32_t centerx; - uint32_t x2; - uint32_t y2; - uint32_t centery; - uint32_t z; - uint32_t height; - t_matglossPair material; - // not complete -}; - -//cooked -struct t_building -{ - uint32_t origin; - uint32_t vtable; - - uint32_t x1; - uint32_t y1; - - uint32_t x2; - uint32_t y2; - - uint32_t z; - - t_matglossPair material; - - uint32_t type; - // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) -}; - -/* -case 10: - ret += "leather"; - break; -case 11: - ret += "silk cloth"; - break; -case 12: - ret += "plant thread cloth"; - break; -case 13: // green glass - ret += "green glass"; - break; -case 14: // clear glass - ret += "clear glass"; - break; -case 15: // crystal glass - ret += "crystal glass"; - break; -case 17: - ret += "ice"; - break; -case 18: - ret += "charcoal"; - break; -case 19: - ret += "potash"; - break; -case 20: - ret += "ashes"; - break; -case 21: - ret += "pearlash"; - break; -case 24: - ret += "soap"; - break; - -*/ - -enum MatglossType -{ - Mat_Wood, - Mat_Stone, - Mat_Metal, - Mat_Plant, - Mat_Leather = 10, - Mat_SilkCloth = 11, - Mat_PlantCloth = 12, - Mat_GreenGlass = 13, - Mat_ClearGlass = 14, - Mat_CrystalGlass = 15, - Mat_Ice = 17, - Mat_Charcoal =18, - Mat_Potash = 20, - Mat_Ashes = 20, - Mat_PearlAsh = 21, - Mat_Soap = 24 - //NUM_MATGLOSS_TYPES -}; - -enum BiomeOffset -{ - eNorthWest, - eNorth, - eNorthEast, - eWest, - eHere, - eEast, - eSouthWest, - eSouth, - eSouthEast, - eBiomeCount -}; - //#pragma pack(push,4) struct t_name { diff --git a/dfhack/include/modules/Maps.h b/dfhack/include/modules/Maps.h index d7056921a..f1d2fdce9 100644 --- a/dfhack/include/modules/Maps.h +++ b/dfhack/include/modules/Maps.h @@ -39,6 +39,20 @@ namespace DFHack uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack. }; + enum BiomeOffset + { + eNorthWest, + eNorth, + eNorthEast, + eWest, + eHere, + eEast, + eSouthWest, + eSouth, + eSouthEast, + eBiomeCount + }; + enum e_traffic { traffic_normal, diff --git a/dfhack/modules/Maps.cpp b/dfhack/modules/Maps.cpp index 3734a9fdb..fb5feb19e 100644 --- a/dfhack/modules/Maps.cpp +++ b/dfhack/modules/Maps.cpp @@ -376,17 +376,17 @@ try_again: // store it in the vector splatter.push_back (sv); } - else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquid") + else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquidst") { off.vein_ice_vptr = type; goto try_again; } - else if(g_pProcess->readClassName(type) == "block_square_event_mineral") + else if(g_pProcess->readClassName(type) == "block_square_event_mineralst") { off.vein_mineral_vptr = type; goto try_again; } - else if(g_pProcess->readClassName(type) == "block_square_event_material_spatter") + else if(g_pProcess->readClassName(type) == "block_square_event_material_spatterst") { off.vein_spatter_vptr = type; goto try_again; diff --git a/dfhack/private/APIPrivate.h b/dfhack/private/APIPrivate.h index 1131df91b..c4f6e3f85 100644 --- a/dfhack/private/APIPrivate.h +++ b/dfhack/private/APIPrivate.h @@ -37,6 +37,7 @@ namespace DFHack class Maps; class Creatures; class Translation; + class Buildings; class ProcessEnumerator; class Process; class Vegetation; @@ -71,6 +72,7 @@ namespace DFHack Materials * materials; Translation * translation; Vegetation * vegetation; + Buildings * buildings; /* uint32_t item_material_offset; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 226eafc97..fb4bf8222 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -10,8 +10,8 @@ ADD_EXECUTABLE(dfattachtest attachtest.cpp) TARGET_LINK_LIBRARIES(dfattachtest dfhack) # buildingsdump - dump buildings and their raw data filtered by type -#ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp) -#TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack) +ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp) +TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack) # a benchmark program, reads the map 1000x ADD_EXECUTABLE(dfexpbench expbench.cpp) diff --git a/examples/buildingsdump.cpp b/examples/buildingsdump.cpp index dee75ceb4..c20f4f6ba 100644 --- a/examples/buildingsdump.cpp +++ b/examples/buildingsdump.cpp @@ -12,6 +12,10 @@ using namespace std; #include #include #include +#include +#include +#include +#include #include "miscutils.h" int main (int argc,const char* argv[]) @@ -51,20 +55,22 @@ int main (int argc,const char* argv[]) return 1; } DFHack::memory_info * mem = DF.getMemoryInfo(); + DFHack::Buildings * Bld = DF.getBuildings(); uint32_t numBuildings; - if(DF.InitReadBuildings(numBuildings)) + if(Bld->Start(numBuildings)) { cout << numBuildings << endl; vector < uint32_t > addresses; for(uint32_t i = 0; i < numBuildings; i++) { DFHack::t_building temp; - DF.ReadBuilding(i, temp); + Bld->Read(i, temp); if(temp.type != 0xFFFFFFFF) // check if type isn't invalid { string typestr; mem->resolveClassIDToClassname(temp.type, typestr); + cout << typestr << endl; if(typestr == argv[1]) { //cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl; @@ -79,7 +85,7 @@ int main (int argc,const char* argv[]) } } interleave_hex(DF,addresses,lines / 4); - DF.FinishReadBuildings(); + Bld->Finish(); } else { diff --git a/output/Memory.xml b/output/Memory.xml index fe8a31d93..3f0727157 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -2819,12 +2819,98 @@ V -- T A B L E S (for stonesense) ==================================================================== - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3083,8 +3169,7 @@ map_data_1b60_offset 0x1B9c Buildings ========= - - :( +
0x0166f9a0
Effects =======