From 5d4114f5b797f302b903116d1439e6d94fa6d7f5 Mon Sep 17 00:00:00 2001 From: Quietust Date: Fri, 2 Mar 2012 09:35:49 -0600 Subject: [PATCH] Add "bprobe" command, describes the buildings located under the cursor --- plugins/probe.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 970a07350..7849c33b7 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -19,10 +19,12 @@ using namespace std; #include "modules/Gui.h" #include "modules/Materials.h" #include "modules/MapCache.h" +#include "modules/Buildings.h" #include "MiscUtils.h" #include "df/world.h" - +#include "df/world_raws.h" +#include "df/building_def.h" using std::vector; using std::string; @@ -30,9 +32,11 @@ using namespace DFHack; using namespace DFHack::Simple; using namespace df::enums; using df::global::world; +using df::global::cursor; command_result df_probe (Core * c, vector & parameters); command_result df_cprobe (Core * c, vector & parameters); +command_result df_bprobe (Core * c, vector & parameters); DFHACK_PLUGIN("probe"); @@ -45,6 +49,9 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector commands.push_back(PluginCommand("cprobe", "A creature probe", df_cprobe)); + commands.push_back(PluginCommand("bprobe", + "A simple building probe", + df_bprobe)); return CR_OK; } @@ -273,3 +280,61 @@ command_result df_probe (Core * c, vector & parameters) con << std::endl; return CR_OK; } + +command_result df_bprobe (Core * c, vector & parameters) +{ + CoreSuspender suspend(c); + + if(cursor->x == -30000) + { + c->con.printerr("No cursor; place cursor over tile to probe.\n"); + return CR_FAILURE; + } + + for (size_t i = 0; i < world->buildings.all.size(); i++) + { + Buildings::t_building building; + if (!Buildings::Read(i, building)) + continue; + if (!(building.x1 <= cursor->x && cursor->x <= building.x2 && + building.y1 <= cursor->y && cursor->y <= building.y2 && + building.z == cursor->z)) + continue; + string name; + building.origin->getName(&name); + c->con.print("Building %i - \"%s\" - type %s", building.origin->id, name.c_str(), ENUM_KEY_STR(building_type, building.type)); + + switch (building.type) + { + case building_type::Furnace: + c->con.print(", subtype %s", ENUM_KEY_STR(furnace_type, building.furnace_type)); + if (building.furnace_type == furnace_type::Custom) + c->con.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str()); + break; + case building_type::Workshop: + c->con.print(", subtype %s", ENUM_KEY_STR(workshop_type, building.workshop_type)); + if (building.workshop_type == workshop_type::Custom) + c->con.print(", custom type %i (%s)", building.custom_type, world->raws.buildings.all[building.custom_type]->code.c_str()); + break; + case building_type::Construction: + c->con.print(", subtype %s", ENUM_KEY_STR(construction_type, building.construction_type)); + break; + case building_type::Shop: + c->con.print(", subtype %s", ENUM_KEY_STR(shop_type, building.shop_type)); + break; + case building_type::SiegeEngine: + c->con.print(", subtype %s", ENUM_KEY_STR(siegeengine_type, building.siegeengine_type)); + break; + case building_type::Trap: + c->con.print(", subtype %s", ENUM_KEY_STR(trap_type, building.trap_type)); + break; + default: + if (building.subtype != -1) + c->con.print(", subtype %i", building.subtype); + break; + } + c->con.print("\n"); + + } + return CR_OK; +}