From 36c6c5ee939bcf68d092fc77d83a7f59e926b50b Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Sat, 8 Apr 2023 12:11:15 -0500 Subject: [PATCH 1/7] 3dveins - tradeoffs for v50 allow dropping orphan veins; this is necessitated by what appears to be a bug in the gem spire generation code, which appears to occasionally spew gems in places that are quite distant from the gem spires themselves --- plugins/3dveins.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index eaf741caf..f79949370 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -914,6 +914,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z) for (int y = 0; y < 16; y++) { df::coord2d tile(x,y); + GeoLayer *layer = mapLayer(b, tile); if (!layer) continue; @@ -1363,7 +1364,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from) ENUM_KEY_STR(inclusion_type, key.second).c_str() ); - return false; + return true; } for (auto it = best.begin(); size > 0 && it != best.end(); ++it) From 9a5867219004b921ded7129fc8590cabf115b02f Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 4 Jul 2023 10:07:50 -0500 Subject: [PATCH 2/7] reenable 3dveins --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4029b8e2e..63e5274ae 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -73,7 +73,7 @@ set_source_files_properties( Brushes.h PROPERTIES HEADER_FILE_ONLY TRUE ) # If you are adding a plugin that you do not intend to commit to the DFHack repo, # see instructions for adding "external" plugins at the end of this file. -#dfhack_plugin(3dveins 3dveins.cpp) +dfhack_plugin(3dveins 3dveins.cpp) dfhack_plugin(add-spatter add-spatter.cpp) dfhack_plugin(autobutcher autobutcher.cpp LINK_LIBRARIES lua) dfhack_plugin(autochop autochop.cpp LINK_LIBRARIES lua) From 02a4b7f63f4a6ea9d59b5693855e66e57e2eb2f6 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 4 Jul 2023 11:01:26 -0500 Subject: [PATCH 3/7] 3dveins: use debugfilter --- plugins/3dveins.cpp | 69 ++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index f79949370..659f16ecc 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -7,15 +7,16 @@ #include "Core.h" #include "Console.h" +#include "DataDefs.h" +#include "Debug.h" #include "Export.h" +#include "MiscUtils.h" #include "PluginManager.h" + #include "modules/MapCache.h" #include "modules/Random.h" #include "modules/World.h" -#include "MiscUtils.h" - -#include "DataDefs.h" #include "df/world.h" #include "df/world_data.h" #include "df/world_region_details.h" @@ -47,6 +48,10 @@ DFHACK_PLUGIN("3dveins"); REQUIRE_GLOBAL(world); REQUIRE_GLOBAL(gametype); +namespace DFHack { + DBG_DECLARE(_3dveins, process, DebugCategory::LINFO); +} + command_result cmd_3dveins(color_ostream &out, std::vector & parameters); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) @@ -431,11 +436,13 @@ struct GeoLayer void print_mineral_stats(color_ostream &out) { for (auto it = mineral_count.begin(); it != mineral_count.end(); ++it) - out << " " << MaterialInfo(0,it->first.first).getToken() - << " " << ENUM_KEY_STR(inclusion_type,it->first.second) - << ": \t\t" << it->second << " (" << (float(it->second)/unmined_tiles) << ")" << std::endl; + INFO(process, out).print("3dveins: %s %s: %d (%f)\n", + MaterialInfo(0, it->first.first).getToken(), + ENUM_KEY_STR(inclusion_type, it->first.second), + it->second, + (float(it->second) / unmined_tiles)); - out.print(" Total tiles: %d (%d unmined)\n", tiles, unmined_tiles); + INFO(process, out).print ("3dveins: Total tiles: %d (%d unmined)\n", tiles, unmined_tiles); } bool form_veins(color_ostream &out); @@ -467,12 +474,12 @@ struct GeoBiome void print_mineral_stats(color_ostream &out) { - out.print("Geological biome %d:\n", info.geo_index); + INFO(process,out).print("3dveins: Geological biome %d:\n", info.geo_index); for (size_t i = 0; i < layers.size(); i++) if (layers[i]) { - out << " Layer " << i << std::endl; + INFO(process, out).print("3dveins: Layer %d\n", i); layers[i]->print_mineral_stats(out); } } @@ -586,7 +593,7 @@ bool VeinGenerator::init_biomes() if (info.geo_index < 0 || !info.geobiome) { - out.printerr("Biome %zd is not defined.\n", i); + ERR(process, out).print("Biome %zd is not defined.\n", i); return false; } @@ -797,8 +804,7 @@ bool VeinGenerator::scan_layer_depth(Block *b, df::coord2d column, int z) { if (z != min_level[idx]-1 && min_level[idx] <= top_solid) { - out.printerr( - "Discontinuous layer %d at (%d,%d,%d).\n", + ERR(process, out).print("Discontinuous layer %d at (%d,%d,%d).\n", layer->index, x+column.x*16, y+column.y*16, z ); return false; @@ -848,7 +854,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column) if (max_level[i+1] != min_level[i]-1) { - out.printerr( + ERR(process, out).print( "Gap or overlap with next layer %d at (%d,%d,%d-%d).\n", i+1, x+column.x*16, y+column.y*16, max_level[i+1], min_level[i] ); @@ -891,7 +897,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column) } } - out.printerr( + ERR(process, out).print( "Layer height change in layer %d at (%d,%d,%d): %d instead of %d.\n", i, x+column.x*16, y+column.y*16, max_level[i], size, biome->layers[i]->thickness @@ -933,7 +939,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z) if (unsigned(key.first) >= materials.size() || unsigned(key.second) >= NUM_INCLUSIONS) { - out.printerr("Invalid vein code: %d %d - aborting.\n",key.first,key.second); + ERR(process, out).print("Invalid vein code: %d %d - aborting.\n",key.first,key.second); return false; } @@ -942,7 +948,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z) if (status == -1) { // Report first occurence of unreasonable vein spec - out.printerr( + WARN(process, out).print( "Unexpected vein %s %s - ", MaterialInfo(0,key.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str() @@ -950,9 +956,9 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z) status = materials[key.first].default_type; if (status < 0) - out.printerr("will be left in place.\n"); + WARN(process, out).print("will be left in place.\n"); else - out.printerr( + WARN(process, out).print( "correcting to %s.\n", ENUM_KEY_STR(inclusion_type, df::inclusion_type(status)).c_str() ); @@ -1091,7 +1097,7 @@ void VeinGenerator::write_block_tiles(Block *b, df::coord2d column, int z) if (!ok) { - out.printerr( + ERR(process, out).print( "Couldn't write %d vein at (%d,%d,%d)\n", mat, x+column.x*16, y+column.y*16, z ); @@ -1282,7 +1288,7 @@ bool GeoLayer::form_veins(color_ostream &out) if (parent_id >= (int)refs.size()) { - out.printerr("Forward vein reference in biome %d.\n", biome->info.geo_index); + ERR(process, out).print("Forward vein reference in biome %d.\n", biome->info.geo_index); return false; } @@ -1302,7 +1308,7 @@ bool GeoLayer::form_veins(color_ostream &out) if (vptr->parent) ctx = "only be in "+MaterialInfo(0,vptr->parent_mat()).getToken(); - out.printerr( + WARN(process, out).print( "Duplicate vein %s %s in biome %d layer %d - will %s.\n", MaterialInfo(0,key.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str(), @@ -1358,7 +1364,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from) if (best.empty()) { - out.printerr( + ERR(process,out).print( "Could not place orphaned vein %s %s anywhere.\n", MaterialInfo(0,key.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str() @@ -1392,7 +1398,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from) if (size > 0) { - out.printerr( + WARN(process, out).print( "Could not place all of orphaned vein %s %s: %d left.\n", MaterialInfo(0,key.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str(), @@ -1542,7 +1548,7 @@ bool VeinGenerator::place_veins(bool verbose) if (!isStoneInorganic(key.first)) { - out.printerr( + ERR(process, out).print( "Invalid vein material: %s\n", MaterialInfo(0, key.first).getToken().c_str() ); @@ -1552,7 +1558,7 @@ bool VeinGenerator::place_veins(bool verbose) if (!is_valid_enum_item(key.second)) { - out.printerr("Invalid vein type: %d\n", key.second); + ERR(process, out).print("Invalid vein type: %d\n", key.second); return false; } @@ -1565,13 +1571,13 @@ bool VeinGenerator::place_veins(bool verbose) sort(queue.begin(), queue.end(), vein_cmp); // Place tiles - out.print("Processing... (%zu)", queue.size()); + TRACE(process,out).print("Processing... (%zu)", queue.size()); for (size_t j = 0; j < queue.size(); j++) { if (queue[j]->parent && !queue[j]->parent->placed) { - out.printerr( + ERR(process, out).print( "\nParent vein not placed for %s %s.\n", MaterialInfo(0,queue[j]->vein.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, queue[j]->vein.second).c_str() @@ -1583,9 +1589,9 @@ bool VeinGenerator::place_veins(bool verbose) if (verbose) { if (j > 0) - out.print("done."); + TRACE(process, out).print("done."); - out.print( + TRACE(process, out).print( "\nVein layer %zu of %zu: %s %s (%.2f%%)... ", j+1, queue.size(), MaterialInfo(0,queue[j]->vein.first).getToken().c_str(), @@ -1595,14 +1601,13 @@ bool VeinGenerator::place_veins(bool verbose) } else { - out.print("\rVein layer %zu of %zu... ", j+1, queue.size()); - out.flush(); + TRACE(process, out).print("\rVein layer %zu of %zu... ", j+1, queue.size()); } queue[j]->place_tiles(); } - out.print("done.\n"); + TRACE(process, out).print("done.\n"); return true; } From d346bbfe6f363f63802d89cccc3d90ec09c93446 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 4 Jul 2023 11:18:39 -0500 Subject: [PATCH 4/7] 3dveins: satisfy gcc's overly aggressive linter --- plugins/3dveins.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index 659f16ecc..71115d38a 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -436,8 +436,8 @@ struct GeoLayer void print_mineral_stats(color_ostream &out) { for (auto it = mineral_count.begin(); it != mineral_count.end(); ++it) - INFO(process, out).print("3dveins: %s %s: %d (%f)\n", - MaterialInfo(0, it->first.first).getToken(), + INFO(process, out).print("3dveins: %s %s: %ld (%f)\n", + MaterialInfo(0, it->first.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, it->first.second), it->second, (float(it->second) / unmined_tiles)); @@ -1589,7 +1589,9 @@ bool VeinGenerator::place_veins(bool verbose) if (verbose) { if (j > 0) + { TRACE(process, out).print("done."); + } TRACE(process, out).print( "\nVein layer %zu of %zu: %s %s (%.2f%%)... ", From 4b669ec83a85125f60fafbedeee3734bdd79c222 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 4 Jul 2023 11:22:34 -0500 Subject: [PATCH 5/7] uncross eyes and try again --- plugins/3dveins.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index 71115d38a..8fd7ac900 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -436,9 +436,9 @@ struct GeoLayer void print_mineral_stats(color_ostream &out) { for (auto it = mineral_count.begin(); it != mineral_count.end(); ++it) - INFO(process, out).print("3dveins: %s %s: %ld (%f)\n", + INFO(process, out).print("3dveins: %s %s: %d (%f)\n", MaterialInfo(0, it->first.first).getToken().c_str(), - ENUM_KEY_STR(inclusion_type, it->first.second), + ENUM_KEY_STR(inclusion_type, it->first.second).c_str(), it->second, (float(it->second) / unmined_tiles)); @@ -479,7 +479,7 @@ struct GeoBiome for (size_t i = 0; i < layers.size(); i++) if (layers[i]) { - INFO(process, out).print("3dveins: Layer %d\n", i); + INFO(process, out).print("3dveins: Layer %ld\n", i); layers[i]->print_mineral_stats(out); } } From 6997b6be21b1697e1192e336287ab2dd668a9bbb Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 7 Jul 2023 16:00:39 -0500 Subject: [PATCH 6/7] add changelog for 3dveins --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index bbd682c2d..891a9a93e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -34,6 +34,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: # Future ## New Plugins +- ``3dveins``: reinstated for v50, this plugin replaces vanilla DF's blobby vein generation with veins that flow smoothly and naturally between z-levels ## Fixes - Fix extra keys appearing in DFHack text boxes when shift (or any other modifier) is released before the other key you were pressing From fb9e72e487f13bcf854cbe1739848a72cc5eaf69 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 7 Jul 2023 17:39:50 -0500 Subject: [PATCH 7/7] =?UTF-8?q?3dveins:=20ERR=20=E2=86=92=20WARN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/3dveins.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index 8fd7ac900..6b95c2e87 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -593,7 +593,7 @@ bool VeinGenerator::init_biomes() if (info.geo_index < 0 || !info.geobiome) { - ERR(process, out).print("Biome %zd is not defined.\n", i); + WARN(process, out).print("Biome %zd is not defined.\n", i); return false; } @@ -804,7 +804,7 @@ bool VeinGenerator::scan_layer_depth(Block *b, df::coord2d column, int z) { if (z != min_level[idx]-1 && min_level[idx] <= top_solid) { - ERR(process, out).print("Discontinuous layer %d at (%d,%d,%d).\n", + WARN(process, out).print("Discontinuous layer %d at (%d,%d,%d).\n", layer->index, x+column.x*16, y+column.y*16, z ); return false; @@ -854,7 +854,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column) if (max_level[i+1] != min_level[i]-1) { - ERR(process, out).print( + WARN(process, out).print( "Gap or overlap with next layer %d at (%d,%d,%d-%d).\n", i+1, x+column.x*16, y+column.y*16, max_level[i+1], min_level[i] ); @@ -897,7 +897,7 @@ bool VeinGenerator::adjust_layer_depth(df::coord2d column) } } - ERR(process, out).print( + WARN(process, out).print( "Layer height change in layer %d at (%d,%d,%d): %d instead of %d.\n", i, x+column.x*16, y+column.y*16, max_level[i], size, biome->layers[i]->thickness @@ -939,7 +939,7 @@ bool VeinGenerator::scan_block_tiles(Block *b, df::coord2d column, int z) if (unsigned(key.first) >= materials.size() || unsigned(key.second) >= NUM_INCLUSIONS) { - ERR(process, out).print("Invalid vein code: %d %d - aborting.\n",key.first,key.second); + WARN(process, out).print("Invalid vein code: %d %d - aborting.\n",key.first,key.second); return false; } @@ -1097,7 +1097,7 @@ void VeinGenerator::write_block_tiles(Block *b, df::coord2d column, int z) if (!ok) { - ERR(process, out).print( + WARN(process, out).print( "Couldn't write %d vein at (%d,%d,%d)\n", mat, x+column.x*16, y+column.y*16, z ); @@ -1288,7 +1288,7 @@ bool GeoLayer::form_veins(color_ostream &out) if (parent_id >= (int)refs.size()) { - ERR(process, out).print("Forward vein reference in biome %d.\n", biome->info.geo_index); + WARN(process, out).print("Forward vein reference in biome %d.\n", biome->info.geo_index); return false; } @@ -1364,7 +1364,7 @@ bool VeinGenerator::place_orphan(t_veinkey key, int size, GeoLayer *from) if (best.empty()) { - ERR(process,out).print( + WARN(process,out).print( "Could not place orphaned vein %s %s anywhere.\n", MaterialInfo(0,key.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, key.second).c_str() @@ -1548,7 +1548,7 @@ bool VeinGenerator::place_veins(bool verbose) if (!isStoneInorganic(key.first)) { - ERR(process, out).print( + WARN(process, out).print( "Invalid vein material: %s\n", MaterialInfo(0, key.first).getToken().c_str() ); @@ -1558,7 +1558,7 @@ bool VeinGenerator::place_veins(bool verbose) if (!is_valid_enum_item(key.second)) { - ERR(process, out).print("Invalid vein type: %d\n", key.second); + WARN(process, out).print("Invalid vein type: %d\n", key.second); return false; } @@ -1577,7 +1577,7 @@ bool VeinGenerator::place_veins(bool verbose) { if (queue[j]->parent && !queue[j]->parent->placed) { - ERR(process, out).print( + WARN(process, out).print( "\nParent vein not placed for %s %s.\n", MaterialInfo(0,queue[j]->vein.first).getToken().c_str(), ENUM_KEY_STR(inclusion_type, queue[j]->vein.second).c_str()