From c104f822a4ed01324ce98bfbeffbbf026dbc2770 Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Sat, 21 Apr 2012 12:53:46 -0500 Subject: [PATCH 1/2] Move stripcaged to master branch, works fine. --- plugins/devel/CMakeLists.txt | 1 + plugins/devel/stripcaged.cpp | 103 +++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 plugins/devel/stripcaged.cpp diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index fd25962b2..ef2816608 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -14,4 +14,5 @@ DFHACK_PLUGIN(dumpmats dumpmats.cpp) #DFHACK_PLUGIN(tiles tiles.cpp) DFHACK_PLUGIN(counters counters.cpp) DFHACK_PLUGIN(stockcheck stockcheck.cpp) +DFHACK_PLUGIN(stripcaged stripcaged.cpp) diff --git a/plugins/devel/stripcaged.cpp b/plugins/devel/stripcaged.cpp new file mode 100644 index 000000000..7e492cb01 --- /dev/null +++ b/plugins/devel/stripcaged.cpp @@ -0,0 +1,103 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.h" +#include "modules/Units.h" +#include "modules/Maps.h" +#include "modules/Gui.h" +#include "modules/World.h" +#include "MiscUtils.h" + +#include +#include "df/world.h" +#include "df/world_raws.h" +#include "df/building_def.h" +#include "df/unit_inventory_item.h" +#include +#include + +using std::vector; +using std::string; +using namespace DFHack; +using namespace df::enums; +using df::global::world; +using df::global::cursor; +using df::global::ui; + +using namespace DFHack::Gui; + +command_result df_stripcaged(color_ostream &out, vector & parameters); + +DFHACK_PLUGIN("stripcaged"); + +// check if contained in item (e.g. animals in cages) +bool isContainedInItem(df::unit* unit) +{ + bool contained = false; + for (size_t r=0; r < unit->refs.size(); r++) + { + df::general_ref * ref = unit->refs[r]; + auto rtype = ref->getType(); + if(rtype == df::general_ref_type::CONTAINED_IN_ITEM) + { + contained = true; + break; + } + } + return contained; +} + +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +{ + commands.push_back(PluginCommand( + "stripcaged", "strip caged units of all items", + df_stripcaged, false, + "Clears forbid and sets dump for the inventories of all caged units." + )); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + return CR_OK; +} + +command_result df_stripcaged(color_ostream &out, vector & parameters) +{ + CoreSuspender suspend; + + size_t count = 0; + for (size_t i=0; i < world->units.all.size(); i++) + { + df::unit* unit = world->units.all[i]; + if (isContainedInItem(unit)) + { + for (size_t j=0; j < unit->inventory.size(); j++) + { + df::unit_inventory_item* uii = unit->inventory[j]; + if (uii->item) + { + uii->item->flags.bits.forbid = 0; + uii->item->flags.bits.dump = 1; + count++; + } + } + } + } + + out << count << " items marked for dumping" << endl; + + return CR_OK; +} From f5644f385bb5bf101444729cbaa6cd64ae343007 Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Sat, 21 Apr 2012 23:22:21 -0500 Subject: [PATCH 2/2] Probe now displays biome savagery and evilness. Devel plugin bprobe (also in this commit) goes digging around in region data at embark screen, not really useful for public consumption. --- plugins/devel/CMakeLists.txt | 1 + plugins/devel/rprobe.cpp | 107 +++++++++++++++++++++++++++++++++++ plugins/probe.cpp | 11 +++- 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 plugins/devel/rprobe.cpp diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index ef2816608..70daa7b2c 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -15,4 +15,5 @@ DFHACK_PLUGIN(dumpmats dumpmats.cpp) DFHACK_PLUGIN(counters counters.cpp) DFHACK_PLUGIN(stockcheck stockcheck.cpp) DFHACK_PLUGIN(stripcaged stripcaged.cpp) +DFHACK_PLUGIN(rprobe rprobe.cpp) diff --git a/plugins/devel/rprobe.cpp b/plugins/devel/rprobe.cpp new file mode 100644 index 000000000..4378c547c --- /dev/null +++ b/plugins/devel/rprobe.cpp @@ -0,0 +1,107 @@ +// 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 + +using namespace std; +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.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_geo_biome.h" +#include "df/world_geo_layer.h" +#include "df/inclusion_type.h" +#include "df/viewscreen_choose_start_sitest.h" + +using namespace DFHack; +using namespace df::enums; +using df::global::world; +using df::coord2d; + + + +command_result rprobe (color_ostream &out, vector & parameters); + +DFHACK_PLUGIN("rprobe"); + +DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +{ + commands.push_back(PluginCommand( + "rprobe", "Display assorted region information from embark screen", + rprobe, false, + "Display assorted region information from embark screen\n" + )); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( color_ostream &out ) +{ + return CR_OK; +} + + +command_result rprobe (color_ostream &out, vector & parameters) +{ + CoreSuspender suspend; + + // Embark screen active: estimate using world geology data + VIRTUAL_CAST_VAR(screen, df::viewscreen_choose_start_sitest, Core::getTopViewscreen()); + + if (!screen) + return CR_WRONG_USAGE; + + if (!world || !world->world_data) + { + out.printerr("World data is not available.\n"); + return CR_FAILURE; + } + + df::world_data *data = world->world_data; + coord2d cur_region = screen->region_pos; + + // Compute biomes + for (int i = 0; i < screen->biome_rgn.size(); i++) + { + coord2d rg = screen->biome_rgn[i]; + out << i << ": x = " << rg.x << ", y = " << rg.y; + + df::world_data::T_region_map* rd = &data->region_map[rg.x][rg.y]; + + out << + " region_id: " << rd->region_id << + " geo_index: " << rd->geo_index << + " landmass_id: " << rd->landmass_id << + " flags: " << hex << rd->flags.as_int() << dec << + " sav: " << rd->savagery << + " evil: " << rd->evilness; + + int32_t *p = (int32_t *)rd; + int c = sizeof(*rd) / sizeof(int32_t); + for (int j = 0; j < c; j++) { + if (j % 8 == 0) + out << endl << setfill('0') << setw(8) << hex << (int)(rd+j) << ": "; + out << " " << setfill('0') << setw(8) << hex << p[j]; + } + out << dec << endl; + + } + + return CR_OK; +} diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 4e041f180..058a9e5ca 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -210,8 +210,17 @@ command_result df_probe (color_ostream &out, vector & parameters) out.print("temperature1: %d U\n",mc.temperature1At(cursor)); out.print("temperature2: %d U\n",mc.temperature2At(cursor)); + int offset = block.region_offset[des.bits.biome]; + df::coord2d region_pos = block.region_pos + df::coord2d ((offset % 3) - 1, (offset / 3) -1); + + df::world_data::T_region_map* biome = + &world->world_data->region_map[region_pos.x][region_pos.y]; + // biome, geolayer - out << "biome: " << des.bits.biome << std::endl; + out << "biome: " << des.bits.biome << " (" << + "region id=" << biome->region_id << ", " << + "savagery " << biome->savagery << ", " << + "evilness " << biome->evilness << ")" << std::endl; out << "geolayer: " << des.bits.geolayer_index << std::endl; int16_t base_rock = mc.baseMaterialAt(cursor);