From ad5e20727626fc3080e5ea2f404951ede3370f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 15 Feb 2011 00:45:37 +0100 Subject: [PATCH] make veinlook work with less offsets (maybe) --- library/modules/Maps.cpp | 40 ++++++++++++++++++++++++++---------- tools/supported/veinlook.cpp | 40 ++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 4df9c38a0..d695cc26f 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -57,6 +57,8 @@ struct Maps::Private OffsetGroup *OG_vector; bool Inited; bool Started; + bool hasGeology; + bool hasFeatures; // map between feature address and the read object map local_feature_store; @@ -74,6 +76,7 @@ Maps::Maps(DFContextShared* _d) DFHack::VersionInfo * mem = p->getDescriptor(); Server::Maps::maps_offsets &off = d->offsets; + d->hasFeatures = d->hasGeology = true; // get the offsets once here OffsetGroup *OG_Maps = mem->getGroup("Maps"); @@ -87,7 +90,6 @@ Maps::Maps(DFContextShared* _d) off.region_z_offset = OG_Maps->getAddress ("region_z"); off.world_size_x = OG_Maps->getAddress ("world_size_x"); off.world_size_y = OG_Maps->getAddress ("world_size_y"); - OffsetGroup *OG_MapBlock = OG_Maps->getGroup("block"); { off.tile_type_offset = OG_MapBlock->getOffset ("type"); @@ -100,18 +102,31 @@ Maps::Maps(DFContextShared* _d) off.temperature1_offset = OG_MapBlock->getOffset ("temperature1"); off.temperature2_offset = OG_MapBlock->getOffset ("temperature2"); } - - OffsetGroup *OG_Geology = OG_Maps->getGroup("geology"); + try + { + OffsetGroup *OG_Geology = OG_Maps->getGroup("geology"); + { + off.world_regions = OG_Geology->getAddress ("ptr2_region_array"); + off.region_size = OG_Geology->getHexValue ("region_size"); + off.region_geo_index_offset = OG_Geology->getOffset ("region_geo_index_off"); + off.geolayer_geoblock_offset = OG_Geology->getOffset ("geolayer_geoblock_offset"); + off.world_geoblocks_vector = OG_Geology->getAddress ("geoblock_vector"); + off.type_inside_geolayer = OG_Geology->getOffset ("type_inside_geolayer"); + } + } + catch(Error::AllMemdef &) + { + d->hasGeology = false; + } + try + { + d->OG_global_features = OG_Maps->getGroup("features")->getGroup("global"); + d->OG_local_features = OG_Maps->getGroup("features")->getGroup("local"); + } + catch(Error::AllMemdef &) { - off.world_regions = OG_Geology->getAddress ("ptr2_region_array"); - off.region_size = OG_Geology->getHexValue ("region_size"); - off.region_geo_index_offset = OG_Geology->getOffset ("region_geo_index_off"); - off.geolayer_geoblock_offset = OG_Geology->getOffset ("geolayer_geoblock_offset"); - off.world_geoblocks_vector = OG_Geology->getAddress ("geoblock_vector"); - off.type_inside_geolayer = OG_Geology->getOffset ("type_inside_geolayer"); + d->hasFeatures = false; } - d->OG_global_features = OG_Maps->getGroup("features")->getGroup("global"); - d->OG_local_features = OG_Maps->getGroup("features")->getGroup("local"); } d->OG_vector = mem->getGroup("vector"); @@ -661,6 +676,7 @@ __int16 __userpurge GetGeologicalRegion(__int16 block_X, int X, __i bool Maps::ReadGeology (vector < vector >& assign) { MAPS_GUARD + if(!d->hasGeology) return false; Process *p = d->owner; // get needed addresses and offsets. Now this is what I call crazy. uint16_t worldSizeX, worldSizeY; @@ -730,6 +746,7 @@ bool Maps::ReadGeology (vector < vector >& assign) bool Maps::ReadLocalFeatures( std::map > & local_features ) { MAPS_GUARD + if(!d->hasFeatures) return false; // can't be used without a map! if(!d->block) return false; @@ -822,6 +839,7 @@ bool Maps::ReadLocalFeatures( std::map > & bool Maps::ReadGlobalFeatures( std::vector & features) { MAPS_GUARD + if(!d->hasGeology) return false; // can't be used without a map! if(!d->block) return false; diff --git a/tools/supported/veinlook.cpp b/tools/supported/veinlook.cpp index 90e2f9c29..cb0cbe1a0 100644 --- a/tools/supported/veinlook.cpp +++ b/tools/supported/veinlook.cpp @@ -574,21 +574,18 @@ main(int argc, char *argv[]) y_max = y_max_a; z_max = z_max_a; + bool hasimats = 1; + bool hascmats = 1; + // get stone matgloss mapping if(!Mats->ReadInorganicMaterials()) { - error = "Can't read stone types."; - pDF = 0; - finish(0); + hasimats = 0; } - /* if(!Mats->ReadCreatureTypes()) { - error = "Can't read stone types."; - pDF = 0; - finish(0); + hascmats = 0; } - */ /* // get region geology if(!DF.ReadGeology( layerassign )) @@ -730,8 +727,14 @@ main(int argc, char *argv[]) // restart cleared modules Maps->Start(); Mats->Start(); - Mats->ReadInorganicMaterials(); - Mats->ReadCreatureTypes(); + if(hasimats) + { + Mats->ReadInorganicMaterials(); + } + if(hascmats) + { + Mats->ReadCreatureTypes(); + } uint32_t effectnum; /* if(DF.InitReadEffects(effectnum)) @@ -755,7 +758,8 @@ main(int argc, char *argv[]) // extra processing of the block in the middle if(i == 0 && j == 0) { - do_features(DF, Block, cursorX, cursorY, 50,10, Mats->inorganic); + if(hasimats) + do_features(DF, Block, cursorX, cursorY, 50,10, Mats->inorganic); // read veins Maps->ReadVeins(cursorX+i,cursorY+j,cursorZ,&veinVector,&IceVeinVector,&splatter); @@ -891,8 +895,11 @@ main(int argc, char *argv[]) } } } - gotoxy(50,3); - cprintf("Mineral: %s",Mats->inorganic[veinVector[vein].type].id); + if(hasimats) + { + gotoxy(50,3); + cprintf("Mineral: %s",Mats->inorganic[veinVector[vein].type].id); + } } else if (vein < mineralsize + icesize) { @@ -931,8 +938,11 @@ main(int argc, char *argv[]) } } } - gotoxy(50,3); - cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,Mats->race).c_str()); + if(hascmats) + { + gotoxy(50,3); + cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,Mats->race).c_str()); + } } } }