// Produces a list of materials available on the map. // Options: // -a : show unrevealed tiles // -p : don't show plants // -s : don't show slade // -t : don't show demon temple //#include #include #include #include #include #include #include using namespace std; #include "Core.h" #include "Console.h" #include "Export.h" #include "LuaTools.h" #include "PluginManager.h" #include "modules/Gui.h" #include "modules/MapCache.h" #include "MiscUtils.h" #include "DataDefs.h" #include "df/world.h" #include "df/world_data.h" #include "df/world_region_details.h" #include "df/world_region_feature.h" #include "df/world_geo_biome.h" #include "df/world_geo_layer.h" #include "df/world_underground_region.h" #include "df/feature_init.h" #include "df/region_map_entry.h" #include "df/inclusion_type.h" #include "df/viewscreen_choose_start_sitest.h" #include "df/plant.h" using namespace DFHack; using namespace df::enums; using df::coord2d; DFHACK_PLUGIN("prospector"); REQUIRE_GLOBAL(world); struct prospect_options { // whether to display help bool help = false; // whether to scan the whole map or just the unhidden tiles bool hidden = false; // whether to also show material values bool value = false; // whether to show adamantine tube z-levels bool tube = false; // which report sections to show bool summary = true; bool liquids = true; bool layers = true; bool features = true; bool ores = true; bool gems = true; bool veins = true; bool shrubs = true; bool trees = true; static struct_identity _identity; }; static const struct_field_info prospect_options_fields[] = { { struct_field_info::PRIMITIVE, "help", offsetof(prospect_options, help), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "hidden", offsetof(prospect_options, hidden), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "value", offsetof(prospect_options, value), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "tube", offsetof(prospect_options, tube), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "summary", offsetof(prospect_options, summary), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "liquids", offsetof(prospect_options, liquids), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "layers", offsetof(prospect_options, layers), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "features", offsetof(prospect_options, features), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "ores", offsetof(prospect_options, ores), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "gems", offsetof(prospect_options, gems), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "veins", offsetof(prospect_options, veins), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "shrubs", offsetof(prospect_options, shrubs), &df::identity_traits::identity, 0, 0 }, { struct_field_info::PRIMITIVE, "trees", offsetof(prospect_options, trees), &df::identity_traits::identity, 0, 0 }, { struct_field_info::END } }; struct_identity prospect_options::_identity(sizeof(prospect_options), &df::allocator_fn, NULL, "prospect_options", NULL, prospect_options_fields); struct matdata { const static int invalid_z = -30000; matdata() { count = 0.0; lower_z = invalid_z; upper_z = invalid_z; } matdata (const matdata & copyme) { count = copyme.count; lower_z = copyme.lower_z; upper_z = copyme.upper_z; } float add(int z_level = invalid_z, float delta = 1.0) { count += delta; if(z_level != invalid_z) { if(lower_z == invalid_z || z_level < lower_z) { lower_z = z_level; } if(upper_z == invalid_z || z_level > upper_z) { upper_z = z_level; } } return count; } float count; int lower_z; int upper_z; }; bool operator>(const matdata & q1, const matdata & q2) { return q1.count > q2.count; } template struct shallower { bool operator()(const Tp& top, const Tp& bottom) const { float topavg = (top.lower_z + top.upper_z)/2.0f; float btmavg = (bottom.lower_z + bottom.upper_z)/2.0f; return topavg > btmavg; } }; typedef std::map MatMap; typedef std::vector< pair > MatSorter; typedef std::vector PlantList; #define TO_PTR_VEC(obj_vec, ptr_vec) \ ptr_vec.clear(); \ for (size_t i = 0; i < obj_vec.size(); i++) \ ptr_vec.push_back(&obj_vec[i]) template