diff --git a/library/Core.cpp b/library/Core.cpp index aa3a8702d..4f75eed90 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -47,6 +47,7 @@ using namespace std; #include "modules/Gui.h" #include "modules/World.h" #include "modules/Graphic.h" +//#include "modules/Windows.h" using namespace DFHack; #include "SDL_events.h" @@ -635,7 +636,6 @@ bool Core::Init() cerr << "Initializing Console.\n"; // init the console. - Gui * g = getGui(); bool is_text_mode = false; if(init && init->display.flag.is_set(init_display_flags::TEXT)) { @@ -877,20 +877,19 @@ bool Core::ncurses_wgetch(int in, int & out) { int idx = in - KEY_F(1); // FIXME: copypasta, push into a method! - Gui * g = getGui(); - if(df::global::ui && df::global::gview && g->df_menu_state) + if(df::global::ui && df::global::gview) { - df::viewscreen * ws = g->GetCurrentScreen(); - // FIXME: USE ENUMS - if(((t_virtual *)ws)->getClassName() == "viewscreen_dwarfmodest" && *g->df_menu_state == 0x23) + df::viewscreen * ws = Gui::GetCurrentScreen(); + if (strict_virtual_cast(ws) && + df::global::ui->main.mode != ui_sidebar_mode::Hotkeys) { - out = in; - return true; + setHotkeyCmd(df::global::ui->main.hotkeys[idx].name); + return false; } else { - setHotkeyCmd(df::global::ui->main.hotkeys[idx].name); - return false; + out = in; + return true; } } } @@ -1123,7 +1122,6 @@ TYPE * Core::get##TYPE() \ return s_mods.p##TYPE;\ } -MODULE_GETTER(Gui); MODULE_GETTER(World); MODULE_GETTER(Materials); MODULE_GETTER(Notes); diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 5d5ef3577..82e53b3f7 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -341,7 +341,7 @@ bool Plugin::can_invoke_hotkey( std::string & command, df::viewscreen *top ) else if (cmd.guard) cr = cmd.guard(&c, top); else - cr = default_hotkey(&c, top); + cr = Gui::default_hotkey(&c, top); break; } } diff --git a/library/include/Core.h b/library/include/Core.h index 107dd2fce..a2fa27a5f 100644 --- a/library/include/Core.h +++ b/library/include/Core.h @@ -52,7 +52,6 @@ namespace DFHack { class Process; class Module; - class Gui; class World; class Materials; class Notes; @@ -98,8 +97,6 @@ namespace DFHack /// Is everything OK? bool isValid(void) { return !errorstate; } - /// get the gui module - Gui * getGui(); /// get the world module World * getWorld(); /// get the materials module @@ -153,7 +150,6 @@ namespace DFHack // Module storage struct { - Gui * pGui; World * pWorld; Materials * pMaterials; Notes * pNotes; diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index e59a7f7b3..4fcd80ff0 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -182,10 +182,13 @@ namespace DFHack std::string plugin_path; }; - // Predefined hotkey guards - DFHACK_EXPORT bool default_hotkey(Core *, df::viewscreen *); - DFHACK_EXPORT bool dwarfmode_hotkey(Core *, df::viewscreen *); - DFHACK_EXPORT bool cursor_hotkey(Core *, df::viewscreen *); + namespace Gui + { + // Predefined hotkey guards + DFHACK_EXPORT bool default_hotkey(Core *, df::viewscreen *); + DFHACK_EXPORT bool dwarfmode_hotkey(Core *, df::viewscreen *); + DFHACK_EXPORT bool cursor_hotkey(Core *, df::viewscreen *); + } }; /// You have to have this in every plugin you write - just once. Ideally on top of the main file. diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 10de78bc3..73542450b 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -35,8 +35,6 @@ distribution. namespace DFHack { -namespace Simple -{ namespace Buildings { /** @@ -86,4 +84,3 @@ DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map & bt } } -} diff --git a/library/include/modules/Constructions.h b/library/include/modules/Constructions.h index cc9fef2b1..e76cc7ba1 100644 --- a/library/include/modules/Constructions.h +++ b/library/include/modules/Constructions.h @@ -38,8 +38,6 @@ distribution. */ namespace DFHack { -namespace Simple -{ namespace Constructions { // "Simplified" copy of construction @@ -61,5 +59,4 @@ DFHACK_EXPORT bool copyConstruction (const int32_t index, t_construction &out); DFHACK_EXPORT df::construction * getConstruction (const int32_t index); } } -} #endif diff --git a/library/include/modules/Engravings.h b/library/include/modules/Engravings.h index d52303f32..ea5eae62c 100644 --- a/library/include/modules/Engravings.h +++ b/library/include/modules/Engravings.h @@ -37,8 +37,6 @@ distribution. */ namespace DFHack { -namespace Simple -{ namespace Engravings { // "Simplified" copy of engraving @@ -62,5 +60,4 @@ DFHACK_EXPORT bool copyEngraving (const int32_t index, t_engraving &out); DFHACK_EXPORT df::engraving * getEngraving (const int32_t index); } } -} #endif diff --git a/library/include/modules/Gui.h b/library/include/modules/Gui.h index 3f2d41dd4..59d1e789e 100644 --- a/library/include/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -23,9 +23,6 @@ distribution. */ #pragma once -#ifndef CL_MOD_GUI -#define CL_MOD_GUI - #include "Export.h" #include "Module.h" #include "Virtual.h" @@ -44,108 +41,81 @@ namespace df { }; /** - * \defgroup grp_gui query DF's GUI state + * \defgroup grp_gui utility code that helps dealing with DF's user interface * @ingroup grp_modules */ namespace DFHack { class Core; - - // Full-screen item details view - DFHACK_EXPORT bool item_details_hotkey(Core *, df::viewscreen *top); - // 'u'nits or 'j'obs full-screen view - DFHACK_EXPORT bool unitjobs_hotkey(Core *, df::viewscreen *top); - - // A job is selected in a workshop - DFHACK_EXPORT bool workshop_job_hotkey(Core *c, df::viewscreen *top); - // Building material selection mode - DFHACK_EXPORT bool build_selector_hotkey(Core *c, df::viewscreen *top); - // A unit is selected in the 'v' mode - DFHACK_EXPORT bool view_unit_hotkey(Core *c, df::viewscreen *top); - // Above + the inventory page is selected. - DFHACK_EXPORT bool unit_inventory_hotkey(Core *c, df::viewscreen *top); - - // In workshop_job_hotkey, returns the job - DFHACK_EXPORT df::job *getSelectedWorkshopJob(Core *c, bool quiet = false); - - // A job is selected in a workshop, or unitjobs - DFHACK_EXPORT bool any_job_hotkey(Core *c, df::viewscreen *top); - DFHACK_EXPORT df::job *getSelectedJob(Core *c, bool quiet = false); - - // A unit is selected via 'v', 'k', unitjobs, or - // a full-screen item view of a cage or suchlike - DFHACK_EXPORT bool any_unit_hotkey(Core *c, df::viewscreen *top); - DFHACK_EXPORT df::unit *getSelectedUnit(Core *c, bool quiet = false); - - // An item is selected via 'v'->inventory, 'k', 't', or - // a full-screen item view of a container. Note that in the - // last case, the highlighted contained item is returned, not - // the container itself. - DFHACK_EXPORT bool any_item_hotkey(Core *c, df::viewscreen *top); - DFHACK_EXPORT df::item *getSelectedItem(Core *c, bool quiet = false); - - // Show a plain announcement, or a titan-style popup message - DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true); - DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true); - - class DFContextShared; - - /** - * One tile of the screen. Possibly outdated. - * \ingroup grp_gui - */ - struct t_screen - { - uint8_t symbol; - uint8_t foreground; - uint8_t background; - uint8_t bright; - uint8_t gtile; - uint8_t grayscale; - }; - /** * The Gui module * \ingroup grp_modules * \ingroup grp_gui */ - class DFHACK_EXPORT Gui: public Module + namespace Gui { - public: + // Full-screen item details view + DFHACK_EXPORT bool item_details_hotkey(Core *, df::viewscreen *top); + // 'u'nits or 'j'obs full-screen view + DFHACK_EXPORT bool unitjobs_hotkey(Core *, df::viewscreen *top); + + // A job is selected in a workshop + DFHACK_EXPORT bool workshop_job_hotkey(Core *c, df::viewscreen *top); + // Building material selection mode + DFHACK_EXPORT bool build_selector_hotkey(Core *c, df::viewscreen *top); + // A unit is selected in the 'v' mode + DFHACK_EXPORT bool view_unit_hotkey(Core *c, df::viewscreen *top); + // Above + the inventory page is selected. + DFHACK_EXPORT bool unit_inventory_hotkey(Core *c, df::viewscreen *top); + + // In workshop_job_hotkey, returns the job + DFHACK_EXPORT df::job *getSelectedWorkshopJob(Core *c, bool quiet = false); + + // A job is selected in a workshop, or unitjobs + DFHACK_EXPORT bool any_job_hotkey(Core *c, df::viewscreen *top); + DFHACK_EXPORT df::job *getSelectedJob(Core *c, bool quiet = false); + + // A unit is selected via 'v', 'k', unitjobs, or + // a full-screen item view of a cage or suchlike + DFHACK_EXPORT bool any_unit_hotkey(Core *c, df::viewscreen *top); + DFHACK_EXPORT df::unit *getSelectedUnit(Core *c, bool quiet = false); + + // An item is selected via 'v'->inventory, 'k', 't', or + // a full-screen item view of a container. Note that in the + // last case, the highlighted contained item is returned, not + // the container itself. + DFHACK_EXPORT bool any_item_hotkey(Core *c, df::viewscreen *top); + DFHACK_EXPORT df::item *getSelectedItem(Core *c, bool quiet = false); + + // Show a plain announcement, or a titan-style popup message + DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true); + DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true); - Gui(); - ~Gui(); - bool Start(); - bool Finish(); /* * Cursor and window coords */ - bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); - bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); - - bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); - bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z); + DFHACK_EXPORT bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); + DFHACK_EXPORT bool setViewCoords (const int32_t x, const int32_t y, const int32_t z); - bool getDesignationCoords (int32_t &x, int32_t &y, int32_t &z); - bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z); + DFHACK_EXPORT bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); + DFHACK_EXPORT bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z); - bool getMousePos (int32_t & x, int32_t & y); + DFHACK_EXPORT bool getDesignationCoords (int32_t &x, int32_t &y, int32_t &z); + DFHACK_EXPORT bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z); + + DFHACK_EXPORT bool getMousePos (int32_t & x, int32_t & y); /* * Gui screens */ /// Get the current top-level view-screen - df::viewscreen * GetCurrentScreen(); - /// The DF menu state (designation menu ect) - uint32_t * df_menu_state; + DFHACK_EXPORT df::viewscreen * GetCurrentScreen(); - /* - * Window size in tiles - */ - bool getWindowSize(int32_t & width, int32_t & height); + /// get the size of the window buffer + DFHACK_EXPORT bool getWindowSize(int32_t & width, int32_t & height); - /* - *Menu width: + /** + *Menu width: *3:3 - menu and area map closed *2:3 - menu open single width *1:3 - menu open double width @@ -153,18 +123,7 @@ namespace DFHack *2:2 - area map open */ - bool getMenuWidth(uint8_t & menu_width, uint8_t & area_map_width); - bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width); - - /* - * Screen tiles - */ - bool getScreenTiles(int32_t width, int32_t height, t_screen screen[]); - - private: - struct Private; - Private *d; - }; + DFHACK_EXPORT bool getMenuWidth(uint8_t & menu_width, uint8_t & area_map_width); + DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width); + } } -#endif - diff --git a/library/include/modules/Items.h b/library/include/modules/Items.h index e2f3a8893..6f10cb49d 100644 --- a/library/include/modules/Items.h +++ b/library/include/modules/Items.h @@ -112,8 +112,6 @@ struct dfh_item * \ingroup grp_modules * \ingroup grp_items */ -namespace Simple -{ namespace Items { @@ -141,5 +139,4 @@ DFHACK_EXPORT bool removeItemOwner(df::item * item); DFHACK_EXPORT bool readItemRefs(const df::item * item, const df::general_ref_type type, /*output*/ std::vector &values); } -} } \ No newline at end of file diff --git a/library/include/modules/MapCache.h b/library/include/modules/MapCache.h index 9b9f92c56..8468f5a0d 100644 --- a/library/include/modules/MapCache.h +++ b/library/include/modules/MapCache.h @@ -33,7 +33,6 @@ distribution. #include "df/map_block.h" #include "df/block_square_event_mineralst.h" using namespace DFHack; -using namespace DFHack::Simple; namespace MapExtras { void SquashVeins (DFCoord bcoord, mapblock40d & mb, t_blockmaterials & materials) diff --git a/library/include/modules/Maps.h b/library/include/modules/Maps.h index f86f7888c..d67000048 100644 --- a/library/include/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -192,8 +192,6 @@ typedef struct * \ingroup grp_modules * \ingroup grp_maps */ -namespace Simple -{ namespace Maps { @@ -324,7 +322,6 @@ extern DFHACK_EXPORT bool RemoveBlockEvent(uint32_t x, uint32_t y, uint32_t z, d /// read all plants in this block extern DFHACK_EXPORT bool ReadVegetation(uint32_t x, uint32_t y, uint32_t z, std::vector*& plants); -} } } #endif diff --git a/library/include/modules/Translation.h b/library/include/modules/Translation.h index bb6ba6baf..c88f35b89 100644 --- a/library/include/modules/Translation.h +++ b/library/include/modules/Translation.h @@ -41,8 +41,6 @@ distribution. namespace DFHack { -namespace Simple -{ namespace Translation { // simple check to make sure if there's actual language data present @@ -56,5 +54,4 @@ DFHACK_EXPORT bool copyName(df::language_name * address, df::language_name * tar DFHACK_EXPORT std::string TranslateName (const df::language_name * name, bool inEnglish = true); } } -} #endif diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h index d0420eb57..3d491b86e 100644 --- a/library/include/modules/Units.h +++ b/library/include/modules/Units.h @@ -39,8 +39,6 @@ distribution. */ namespace DFHack { -namespace Simple -{ namespace Units { /** @@ -196,5 +194,4 @@ DFHACK_EXPORT bool RemoveOwnedItemByIdx(const uint32_t index, int32_t id); DFHACK_EXPORT bool RemoveOwnedItemByPtr(df::unit * unit, int32_t id); } } -} #endif diff --git a/library/include/modules/Vegetation.h b/library/include/modules/Vegetation.h index 492c19782..83a192b98 100644 --- a/library/include/modules/Vegetation.h +++ b/library/include/modules/Vegetation.h @@ -36,8 +36,6 @@ distribution. namespace DFHack { -namespace Simple -{ namespace Vegetation { const uint32_t sapling_to_tree_threshold = 120 * 28 * 12 * 3; // 3 years @@ -69,5 +67,4 @@ DFHACK_EXPORT df::plant * getPlant(const int32_t index); DFHACK_EXPORT bool copyPlant (const int32_t index, t_plant &out); } } -} #endif diff --git a/library/include/modules/Vermin.h b/library/include/modules/Vermin.h index bc04111a5..9f440606b 100644 --- a/library/include/modules/Vermin.h +++ b/library/include/modules/Vermin.h @@ -6,7 +6,9 @@ #include "DataDefs.h" #include "df/vermin.h" -namespace DFHack { namespace Simple { namespace Vermin +namespace DFHack +{ +namespace Vermin { /** * Structure for holding a read DF vermin spawn point object @@ -38,4 +40,5 @@ namespace DFHack { namespace Simple { namespace Vermin * Write into vermin object */ DFHACK_EXPORT bool Write (const uint32_t index, t_vermin & point); -} } } // end DFHack::Simple::Vermin +}// end DFHack::Vermin +} diff --git a/library/include/modules/kitchen.h b/library/include/modules/kitchen.h index fab387288..ea9dec14d 100644 --- a/library/include/modules/kitchen.h +++ b/library/include/modules/kitchen.h @@ -40,8 +40,6 @@ distribution. namespace DFHack { -namespace Simple -{ namespace Kitchen { typedef uint8_t t_exclusionType; @@ -83,4 +81,3 @@ DFHACK_EXPORT void clearLimits(); DFHACK_EXPORT std::size_t size(); } } -} diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 1ef913f27..ec43dc766 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -38,7 +38,6 @@ using namespace std; #include "ModuleFactory.h" #include "Core.h" using namespace DFHack; -using namespace DFHack::Simple; #include "DataDefs.h" #include "df/world.h" diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index ac9057075..8dc81911c 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -38,7 +38,6 @@ using namespace std; #include "modules/Constructions.h" #include "df/world.h" using namespace DFHack; -using namespace DFHack::Simple; using df::global::world; bool Constructions::isValid() diff --git a/library/modules/Engravings.cpp b/library/modules/Engravings.cpp index 9fc2c3adf..3621bc736 100644 --- a/library/modules/Engravings.cpp +++ b/library/modules/Engravings.cpp @@ -39,7 +39,6 @@ using namespace std; #include "df/world.h" using namespace DFHack; -using namespace DFHack::Simple; using df::global::world; bool Engravings::isValid() diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 115508995..ef3e84901 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -69,7 +69,7 @@ using df::global::gps; // Predefined common guard functions -bool DFHack::default_hotkey(Core *, df::viewscreen *top) +bool Gui::default_hotkey(Core *, df::viewscreen *top) { // Default hotkey guard function for (;top ;top = top->parent) @@ -78,26 +78,26 @@ bool DFHack::default_hotkey(Core *, df::viewscreen *top) return false; } -bool DFHack::dwarfmode_hotkey(Core *, df::viewscreen *top) +bool Gui::dwarfmode_hotkey(Core *, df::viewscreen *top) { // Require the main dwarf mode screen return !!strict_virtual_cast(top); } -bool DFHack::unitjobs_hotkey(Core *, df::viewscreen *top) +bool Gui::unitjobs_hotkey(Core *, df::viewscreen *top) { // Require the unit or jobs list return !!strict_virtual_cast(top) || !!strict_virtual_cast(top); } -bool DFHack::item_details_hotkey(Core *, df::viewscreen *top) +bool Gui::item_details_hotkey(Core *, df::viewscreen *top) { // Require the main dwarf mode screen return !!strict_virtual_cast(top); } -bool DFHack::cursor_hotkey(Core *c, df::viewscreen *top) +bool Gui::cursor_hotkey(Core *c, df::viewscreen *top) { if (!dwarfmode_hotkey(c, top)) return false; @@ -109,7 +109,7 @@ bool DFHack::cursor_hotkey(Core *c, df::viewscreen *top) return true; } -bool DFHack::workshop_job_hotkey(Core *c, df::viewscreen *top) +bool Gui::workshop_job_hotkey(Core *c, df::viewscreen *top) { using namespace ui_sidebar_mode; using df::global::ui; @@ -147,7 +147,7 @@ bool DFHack::workshop_job_hotkey(Core *c, df::viewscreen *top) } } -bool DFHack::build_selector_hotkey(Core *c, df::viewscreen *top) +bool Gui::build_selector_hotkey(Core *c, df::viewscreen *top) { using namespace ui_sidebar_mode; using df::global::ui; @@ -175,7 +175,7 @@ bool DFHack::build_selector_hotkey(Core *c, df::viewscreen *top) } } -bool DFHack::view_unit_hotkey(Core *c, df::viewscreen *top) +bool Gui::view_unit_hotkey(Core *c, df::viewscreen *top) { using df::global::ui; using df::global::world; @@ -191,7 +191,7 @@ bool DFHack::view_unit_hotkey(Core *c, df::viewscreen *top) return vector_get(world->units.other[0], *ui_selected_unit) != NULL; } -bool DFHack::unit_inventory_hotkey(Core *c, df::viewscreen *top) +bool Gui::unit_inventory_hotkey(Core *c, df::viewscreen *top) { using df::global::ui_unit_view_mode; @@ -203,7 +203,7 @@ bool DFHack::unit_inventory_hotkey(Core *c, df::viewscreen *top) return ui_unit_view_mode->value == df::ui_unit_view_mode::Inventory; } -df::job *DFHack::getSelectedWorkshopJob(Core *c, bool quiet) +df::job *Gui::getSelectedWorkshopJob(Core *c, bool quiet) { using df::global::world; using df::global::ui_workshop_job_cursor; @@ -226,7 +226,7 @@ df::job *DFHack::getSelectedWorkshopJob(Core *c, bool quiet) return selected->jobs[idx]; } -bool DFHack::any_job_hotkey(Core *c, df::viewscreen *top) +bool Gui::any_job_hotkey(Core *c, df::viewscreen *top) { if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top)) return vector_get(screen->jobs, screen->cursor_pos) != NULL; @@ -237,7 +237,7 @@ bool DFHack::any_job_hotkey(Core *c, df::viewscreen *top) return workshop_job_hotkey(c,top); } -df::job *DFHack::getSelectedJob(Core *c, bool quiet) +df::job *Gui::getSelectedJob(Core *c, bool quiet) { df::viewscreen *top = c->getTopViewscreen(); @@ -285,7 +285,7 @@ static df::unit *getAnyUnit(Core *c, df::viewscreen *top) return ref ? ref->getUnit() : NULL; } - if (!dwarfmode_hotkey(c,top)) + if (!Gui::dwarfmode_hotkey(c,top)) return NULL; switch (ui->main.mode) { @@ -312,12 +312,12 @@ static df::unit *getAnyUnit(Core *c, df::viewscreen *top) } } -bool DFHack::any_unit_hotkey(Core *c, df::viewscreen *top) +bool Gui::any_unit_hotkey(Core *c, df::viewscreen *top) { return getAnyUnit(c, top) != NULL; } -df::unit *DFHack::getSelectedUnit(Core *c, bool quiet) +df::unit *Gui::getSelectedUnit(Core *c, bool quiet) { df::unit *unit = getAnyUnit(c, c->getTopViewscreen()); @@ -344,7 +344,7 @@ static df::item *getAnyItem(Core *c, df::viewscreen *top) return ref ? ref->getItem() : NULL; } - if (!dwarfmode_hotkey(c,top)) + if (!Gui::dwarfmode_hotkey(c,top)) return NULL; switch (ui->main.mode) { @@ -387,12 +387,12 @@ static df::item *getAnyItem(Core *c, df::viewscreen *top) } } -bool DFHack::any_item_hotkey(Core *c, df::viewscreen *top) +bool Gui::any_item_hotkey(Core *c, df::viewscreen *top) { return getAnyItem(c, top) != NULL; } -df::item *DFHack::getSelectedItem(Core *c, bool quiet) +df::item *Gui::getSelectedItem(Core *c, bool quiet) { df::item *item = getAnyItem(c, c->getTopViewscreen()); @@ -404,7 +404,7 @@ df::item *DFHack::getSelectedItem(Core *c, bool quiet) // -void DFHack::showAnnouncement(std::string message, int color, bool bright) +void Gui::showAnnouncement(std::string message, int color, bool bright) { using df::global::world; using df::global::cur_year; @@ -455,7 +455,7 @@ void DFHack::showAnnouncement(std::string message, int color, bool bright) } -void DFHack::showPopupAnnouncement(std::string message, int color, bool bright) +void Gui::showPopupAnnouncement(std::string message, int color, bool bright) { using df::global::world; @@ -466,77 +466,6 @@ void DFHack::showPopupAnnouncement(std::string message, int color, bool bright) world->status.popups.push_back(popup); } -// - -Module* DFHack::createGui() -{ - return new Gui(); -} - -struct Gui::Private -{ - Private() - { - Started = false; - StartedMenu = false; - StartedScreen = false; - } - - bool Started; - int32_t * window_x_offset; - int32_t * window_y_offset; - int32_t * window_z_offset; - - bool StartedMenu; - uint8_t * menu_width_offset; - uint8_t * area_map_width_offset; - - bool StartedScreen; - void * screen_tiles_ptr_offset; - - Process * owner; -}; - -Gui::Gui() -{ - Core & c = Core::getInstance(); - d = new Private; - d->owner = c.p; - VersionInfo * mem = c.vinfo; - // Setting up menu state - df_menu_state = (uint32_t *) & df::global::ui->main.mode; - - d->window_x_offset = (int32_t *) mem->getAddress ("window_x"); - d->window_y_offset = (int32_t *) mem->getAddress ("window_y"); - d->window_z_offset = (int32_t *) mem->getAddress ("window_z"); - if(d->window_z_offset && d->window_y_offset && d->window_x_offset) - d->Started = true; - - d->menu_width_offset = (uint8_t *) mem->getAddress("ui_menu_width"); - d->area_map_width_offset = (uint8_t *) mem->getAddress("ui_area_map_width"); - if (d->menu_width_offset && d->area_map_width_offset) - d->StartedMenu = true; - - d->screen_tiles_ptr_offset = (void *) mem->getAddress ("screen_tiles_pointer"); - if(d->screen_tiles_ptr_offset) - d->StartedScreen = true; -} - -Gui::~Gui() -{ - delete d; -} - -bool Gui::Start() -{ - return true; -} - -bool Gui::Finish() -{ - return true; -} - df::viewscreen * Gui::GetCurrentScreen() { df::viewscreen * ws = &gview->view; @@ -552,27 +481,18 @@ df::viewscreen * Gui::GetCurrentScreen() bool Gui::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { - if (!d->Started) return false; - Process * p = d->owner; - - p->readDWord (d->window_x_offset, (uint32_t &) x); - p->readDWord (d->window_y_offset, (uint32_t &) y); - p->readDWord (d->window_z_offset, (uint32_t &) z); + x = *df::global::window_x; + y = *df::global::window_y; + z = *df::global::window_z; return true; } -//FIXME: confine writing of coords to map bounds? bool Gui::setViewCoords (const int32_t x, const int32_t y, const int32_t z) { - if (!d->Started) - { - return false; - } - Process * p = d->owner; - - p->writeDWord (d->window_x_offset, (uint32_t) x); - p->writeDWord (d->window_y_offset, (uint32_t) y); - p->writeDWord (d->window_z_offset, (uint32_t) z); + auto cursor = df::global::cursor; + (*df::global::window_x) = x; + (*df::global::window_y) = y; + (*df::global::window_z) = z; return true; } @@ -581,8 +501,7 @@ bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z) x = df::global::cursor->x; y = df::global::cursor->y; z = df::global::cursor->z; - if (x == -30000) return false; - return true; + return (x == -30000) ? false : true; } //FIXME: confine writing of coords to map bounds? @@ -599,8 +518,7 @@ bool Gui::getDesignationCoords (int32_t &x, int32_t &y, int32_t &z) x = df::global::selection_rect->start_x; y = df::global::selection_rect->start_y; z = df::global::selection_rect->start_z; - if (x == -30000) return false; - return true; + return (x == -30000) ? false : true; } bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t z) @@ -615,8 +533,7 @@ bool Gui::getMousePos (int32_t & x, int32_t & y) { x = gps->mouse_x; y = gps->mouse_y; - if(x == -1) return false; - return true; + return (x == -1) ? false : true; } bool Gui::getWindowSize (int32_t &width, int32_t &height) @@ -628,49 +545,14 @@ bool Gui::getWindowSize (int32_t &width, int32_t &height) bool Gui::getMenuWidth(uint8_t &menu_width, uint8_t &area_map_width) { - if (!d->StartedMenu) return false; - - Process * p = d->owner; - - p->readByte (d->menu_width_offset, menu_width); - p->readByte (d->area_map_width_offset, area_map_width); + menu_width = *df::global::ui_menu_width; + area_map_width = *df::global::ui_area_map_width; return true; } bool Gui::setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width) { - if (!d->StartedMenu) return false; - - Process * p = d->owner; - - p->writeByte (d->menu_width_offset, menu_width); - p->writeByte (d->area_map_width_offset, area_map_width); + *df::global::ui_menu_width = menu_width; + *df::global::ui_area_map_width = area_map_width; return true; } - -bool Gui::getScreenTiles (int32_t width, int32_t height, t_screen screen[]) -{ - if(!d->StartedScreen) return false; - - void * screen_addr = (void *) d->owner->readDWord(d->screen_tiles_ptr_offset); - uint8_t* tiles = new uint8_t[width*height*4/* + 80 + width*height*4*/]; - - d->owner->read (screen_addr, (width*height*4/* + 80 + width*height*4*/), tiles); - - for(int32_t iy=0; iyheat.melting_point > 11000); TEST(magma_safe, material->heat.melting_point > 12000); - TEST(deep_material, FLAG(inorganic, inorganic_flags::DEEP_ANY)); + TEST(deep_material, FLAG(inorganic, inorganic_flags::SPECIAL)); TEST(non_economic, inorganic && !(ui && ui->economic_stone[index])); TEST(plant, plant); diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 2d44e2144..7ab0c950b 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -37,7 +37,6 @@ using namespace std; #include "Core.h" using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; #include "DataDefs.h" diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 6e5e33bd6..ae3f9064c 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -50,7 +50,6 @@ using namespace std; #include "df/unit_inventory_item.h" using namespace DFHack; -using namespace DFHack::Simple; using df::global::world; using df::global::ui; diff --git a/library/modules/Vegetation.cpp b/library/modules/Vegetation.cpp index 2b403448b..bd0eeb656 100644 --- a/library/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -40,7 +40,6 @@ using namespace DFHack; #include "df/world.h" using namespace DFHack; -using namespace DFHack::Simple; using df::global::world; bool Vegetation::isValid() diff --git a/library/modules/Vermin.cpp b/library/modules/Vermin.cpp index 689a9edda..e5401ba9e 100644 --- a/library/modules/Vermin.cpp +++ b/library/modules/Vermin.cpp @@ -37,7 +37,6 @@ using namespace std; #include "ModuleFactory.h" #include "Core.h" using namespace DFHack; -using namespace DFHack::Simple; #include "DataDefs.h" #include "df/world.h" diff --git a/library/modules/kitchen.cpp b/library/modules/kitchen.cpp index e2b26b082..88ed3a42d 100644 --- a/library/modules/kitchen.cpp +++ b/library/modules/kitchen.cpp @@ -17,7 +17,6 @@ using namespace std; #include "ModuleFactory.h" #include "Core.h" using namespace DFHack; -using namespace DFHack::Simple; #include "DataDefs.h" #include "df/world.h" diff --git a/library/xml b/library/xml index 0b7140582..cd7c4b1c8 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 0b7140582457982434df8d5756b5132d15a6b1f4 +Subproject commit cd7c4b1c8f6a73a9ed7cdf04b65ee2a75910202c diff --git a/plugins/advtools.cpp b/plugins/advtools.cpp index 6b2787ea8..15a7cad92 100644 --- a/plugins/advtools.cpp +++ b/plugins/advtools.cpp @@ -11,18 +11,22 @@ #include "DataDefs.h" #include "df/world.h" #include "df/ui_advmode.h" +#include "df/item.h" #include "df/unit.h" #include "df/unit_inventory_item.h" +#include "df/map_block.h" #include "df/nemesis_record.h" #include "df/historical_figure.h" #include "df/general_ref_is_nemesisst.h" #include "df/general_ref_contains_itemst.h" +#include "df/general_ref_building_civzone_assignedst.h" #include "df/material.h" #include "df/craft_material_class.h" #include "df/viewscreen_optionst.h" #include "df/viewscreen_dungeonmodest.h" #include "df/viewscreen_dungeon_monsterstatusst.h" +#include using namespace DFHack; using namespace df::enums; @@ -33,7 +37,7 @@ using df::global::ui_advmode; using df::nemesis_record; using df::historical_figure; -using namespace DFHack::Simple::Translation; +using namespace DFHack::Translation; /********************* * PLUGIN INTERFACE * @@ -59,6 +63,9 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector " list-equipped [all]\n" " List armor and weapons equipped by your companions.\n" " If all is specified, also lists non-metal clothing.\n" + " metal-detector [all-types] [non-trader]\n" + " Reveal metal armor and weapons in shops. The options\n" + " disable the checks on item type and being in shop.\n" )); commands.push_back(PluginCommand( @@ -201,7 +208,7 @@ bool bodySwap(Core *c, df::unit *player) df::nemesis_record *getPlayerNemesis(Core *c, bool restore_swap) { - auto real_nemesis = df::nemesis_record::find(ui_advmode->player_id); + auto real_nemesis = vector_get(world->nemesis.all, ui_advmode->player_id); if (!real_nemesis || !real_nemesis->unit) { c->con.printerr("Invalid player nemesis id: %d\n", ui_advmode->player_id); @@ -274,7 +281,11 @@ void sortCompanionNemesis(std::vector *list, int player_id = -1 output.reserve(list->size()); if (player_id < 0) - player_id = ui_advmode->player_id; + { + auto real_nemesis = vector_get(world->nemesis.all, ui_advmode->player_id); + if (real_nemesis) + player_id = real_nemesis->id; + } // Index records; find the player for (size_t i = 0; i < list->size(); i++) @@ -380,6 +391,87 @@ void listUnitInventory(std::vector *list, df::unit *unit) } } +bool isShopItem(df::item *item) +{ + for (size_t k = 0; k < item->itemrefs.size(); k++) + { + auto ref = item->itemrefs[k]; + if (virtual_cast(ref)) + return true; + } + + return false; +} + +bool isWeaponArmor(df::item *item) +{ + using namespace df::enums::item_type; + + switch (item->getType()) { + case HELM: + case ARMOR: + case WEAPON: + case AMMO: + case GLOVES: + case PANTS: + case SHOES: + return true; + default: + return false; + } +} + +int containsMetalItems(df::item *item, bool all, bool non_trader) +{ + int cnt = 0; + + auto &refs = item->itemrefs; + for (size_t i = 0; i < refs.size(); i++) + { + auto ref = refs[i]; + if (!strict_virtual_cast(ref)) + continue; + + df::item *child = ref->getItem(); + if (!child) continue; + + cnt += containsMetalItems(child, all, non_trader); + } + + if (!non_trader && !isShopItem(item)) + return cnt; + if (!all && !isWeaponArmor(item)) + return cnt; + + MaterialInfo minfo(item); + if (minfo.getCraftClass() != craft_material_class::Metal) + return cnt; + + return ++cnt; +} + +void joinCounts(std::map &counts) +{ + for (auto it = counts.begin(); it != counts.end(); it++) + { + df::coord pt = it->first; + while (pt.x > 0 && counts.count(pt - df::coord(1,0,0))) + pt.x--; + while (pt.y > 0 &&counts.count(pt - df::coord(0,1,0))) + pt.y--; + while (pt.x < 0 && counts.count(pt + df::coord(1,0,0))) + pt.x++; + while (pt.y < 0 &&counts.count(pt + df::coord(0,1,0))) + pt.y++; + + if (pt == it->first) + continue; + + counts[pt] += it->second; + it->second = 0; + } +} + /********************* * FORMATTING * *********************/ @@ -428,6 +520,37 @@ static size_t formatSize(std::vector *out, const std::map 0) + ew = "E"; + else if (delta.x < 0) + ew = "W"; + + if (delta.y > 0) + ns = "S"; + else if (delta.y < 0) + ns = "N"; + + if (abs(delta.x) > abs(delta.y)*5) + dir = ew; + else if (abs(delta.y) > abs(delta.x)*5) + dir = ns; + else if (abs(delta.x) > abs(delta.y)*2) + dir = ew + ns + ew; + else if (abs(delta.y) > abs(delta.x)*2) + dir = ns + ns + ew; + else if (delta.x || delta.y) + dir = ns + ew; + else + dir = "***"; + + int dist = (int)sqrt((double)(delta.x*delta.x + delta.y*delta.y)); + return stl_sprintf("%d away %s %+d", dist, dir.c_str(), delta.z); +} + static void printEquipped(Core *c, df::unit *unit, bool all) { std::vector items; @@ -465,6 +588,12 @@ static void printEquipped(Core *c, df::unit *unit, bool all) // Add to the right table int count = item->getStackSize(); + if (is_weapon) + { + weapons[name] += count; + continue; + } + switch (iinfo.type) { case item_type::HELM: head[name] += count; @@ -570,7 +699,7 @@ command_result adv_bodyswap (Core * c, std::vector & parameters) // Permanently re-link everything if (permanent) { - ui_advmode->player_id = new_nemesis->id; + ui_advmode->player_id = linear_index(world->nemesis.all, new_nemesis); // Flag 0 appears to be the 'active adventurer' flag, and // the player_id field above seems to be computed using it @@ -636,6 +765,67 @@ command_result adv_tools (Core * c, std::vector & parameters) return CR_OK; } + else if (command == "metal-detector") + { + bool all = false, non_trader = false; + for (size_t i = 1; i < parameters.size(); i++) + { + if (parameters[i] == "all-types") + all = true; + else if (parameters[i] == "non-trader") + non_trader = true; + else + return CR_WRONG_USAGE; + } + + auto *player = getPlayerNemesis(c, false); + if (!player) + return CR_FAILURE; + + df::coord player_pos = player->unit->pos; + + int total = 0; + std::map counts; + + for (size_t i = 0; i < world->map.map_blocks.size(); i++) + { + df::map_block *block = world->map.map_blocks[i]; + + for (size_t j = 0; j < block->items.size(); j++) + { + df::item *item = df::item::find(block->items[j]); + if (!item) + continue; + + int num = containsMetalItems(item, all, non_trader); + if (!num) + continue; + + total += num; + counts[(item->pos - player_pos)/10] += num; + + auto &designations = block->designation; + auto &dgn = designations[item->pos.x%16][item->pos.y%16]; + + dgn.bits.hidden = 0; // revealed + dgn.bits.pile = 1; // visible + } + } + + joinCounts(counts); + + c->con.print("%d items of metal merchandise found in the vicinity.\n", total); + for (auto it = counts.begin(); it != counts.end(); it++) + { + if (!it->second) + continue; + + df::coord delta = it->first * 10; + c->con.print(" %s: %d\n", formatDirection(delta).c_str(), it->second); + } + + return CR_OK; + } else return CR_WRONG_USAGE; } diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index 67f31d7d5..9541af295 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -56,12 +56,12 @@ DFhackCExport command_result plugin_init ( Core * c, vector &com )); commands.push_back(PluginCommand( "autodump-destroy-here", "Destroy items marked for dumping under cursor.", - df_autodump_destroy_here, cursor_hotkey, + df_autodump_destroy_here, Gui::cursor_hotkey, " Identical to autodump destroy-here, but intended for use as keybinding.\n" )); commands.push_back(PluginCommand( "autodump-destroy-item", "Destroy the selected item.", - df_autodump_destroy_item, any_item_hotkey, + df_autodump_destroy_item, Gui::any_item_hotkey, " Destroy the selected item. The item may be selected\n" " in the 'k' list, or inside a container. If called\n" " again before the game is resumed, cancels destroy.\n" @@ -108,7 +108,6 @@ static command_result autodump_main(Core * c, vector & parameters) } DFHack::VersionInfo *mem = c->vinfo; - DFHack::Gui * Gui = c->getGui(); if (!Maps::IsValid()) { c->con.printerr("Map is not available!\n"); @@ -124,7 +123,7 @@ static command_result autodump_main(Core * c, vector & parameters) DFCoord pos_cursor; if(!destroy || here) { - if (!Gui->getCursorCoords(cx,cy,cz)) + if (!Gui::getCursorCoords(cx,cy,cz)) { c->con.printerr("Cursor position not found. Please enabled the cursor.\n"); return CR_FAILURE; @@ -307,7 +306,7 @@ command_result df_autodump_destroy_item(Core * c, vector & parameters) if (!parameters.empty()) return CR_WRONG_USAGE; - df::item *item = getSelectedItem(c); + df::item *item = Gui::getSelectedItem(c); if (!item) return CR_FAILURE; diff --git a/plugins/changevein.cpp b/plugins/changevein.cpp index 6b2767d5a..efb045f76 100644 --- a/plugins/changevein.cpp +++ b/plugins/changevein.cpp @@ -13,7 +13,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/cleaners.cpp b/plugins/cleaners.cpp index 42bb9e757..3e5d03767 100644 --- a/plugins/cleaners.cpp +++ b/plugins/cleaners.cpp @@ -16,7 +16,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; @@ -208,7 +207,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector )); commands.push_back(PluginCommand( "spotclean","Cleans map tile under cursor.", - spotclean,cursor_hotkey + spotclean,Gui::cursor_hotkey )); return CR_OK; } diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp index 5b6907e59..945fb9754 100644 --- a/plugins/cleanowned.cpp +++ b/plugins/cleanowned.cpp @@ -21,7 +21,6 @@ using namespace std; #include "df/world.h" using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index 6b12f8100..2ba0e7384 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -10,7 +10,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; command_result colonies (Core * c, vector & parameters); diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index 14e8d6842..75b99cff6 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -12,7 +12,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/devel/buildprobe.cpp b/plugins/devel/buildprobe.cpp index 223157641..d5e570987 100644 --- a/plugins/devel/buildprobe.cpp +++ b/plugins/devel/buildprobe.cpp @@ -39,7 +39,6 @@ command_result readFlag (Core * c, vector & parameters) { c->Suspend(); - Gui * Gui = c->getGui(); // init the map if(!Maps::IsValid()) { @@ -49,8 +48,7 @@ command_result readFlag (Core * c, vector & parameters) } int32_t cx, cy, cz; - Gui->getCursorCoords(cx,cy,cz); - while(cx == -30000) + if(!Gui::getCursorCoords(cx,cy,cz)) { c->con.printerr("Cursor is not active.\n"); c->Resume(); @@ -106,7 +104,6 @@ command_result writeFlag (Core * c, vector & parameters) c->Suspend(); - Gui * Gui = c->getGui(); // init the map if(!Maps::IsValid()) { @@ -116,8 +113,7 @@ command_result writeFlag (Core * c, vector & parameters) } int32_t cx, cy, cz; - Gui->getCursorCoords(cx,cy,cz); - while(cx == -30000) + if(!Gui::getCursorCoords(cx,cy,cz)) { c->con.printerr("Cursor is not active.\n"); c->Resume(); diff --git a/plugins/devel/catsplosion.cpp b/plugins/devel/catsplosion.cpp index f6952405d..7c220641e 100644 --- a/plugins/devel/catsplosion.cpp +++ b/plugins/devel/catsplosion.cpp @@ -24,7 +24,6 @@ using namespace std; #include using namespace DFHack; -using namespace DFHack::Simple; command_result catsplosion (Core * c, std::vector & parameters); diff --git a/plugins/devel/frozen.cpp b/plugins/devel/frozen.cpp index 1bcb6f83e..8311cde3d 100644 --- a/plugins/devel/frozen.cpp +++ b/plugins/devel/frozen.cpp @@ -9,7 +9,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/devel/kittens.cpp b/plugins/devel/kittens.cpp index 0135baf74..f2e983e83 100644 --- a/plugins/devel/kittens.cpp +++ b/plugins/devel/kittens.cpp @@ -15,7 +15,7 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; + //FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core. bool shutdown_flag = false; bool final_flag = true; @@ -70,19 +70,16 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) } if(trackmenu_flg) { - DFHack::Gui * g =c->getGui(); - if (last_menu != *g->df_menu_state) + if (last_menu != df::global::ui->main.mode) { - last_menu = *g->df_menu_state; + last_menu = df::global::ui->main.mode; c->con.print("Menu: %d\n",last_menu); } } if(trackpos_flg) { - DFHack::Gui * g =c->getGui(); - g->Start(); int32_t desig_x, desig_y, desig_z; - g->getDesignationCoords(desig_x,desig_y,desig_z); + Gui::getDesignationCoords(desig_x,desig_y,desig_z); if(desig_x != last_designation[0] || desig_y != last_designation[1] || desig_z != last_designation[2]) { last_designation[0] = desig_x; @@ -91,7 +88,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) c->con.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z); } int mouse_x, mouse_y; - g->getMousePos(mouse_x,mouse_y); + Gui::getMousePos(mouse_x,mouse_y); if(mouse_x != last_mouse[0] || mouse_y != last_mouse[1]) { last_mouse[0] = mouse_x; @@ -111,11 +108,10 @@ command_result trackmenu (Core * c, vector & parameters) } else { - DFHack::Gui * g =c->getGui(); - if(g->df_menu_state) + if(df::global::ui) { trackmenu_flg = true; - last_menu = *g->df_menu_state; + last_menu = df::global::ui->main.mode; c->con.print("Menu: %d\n",last_menu); return CR_OK; } @@ -150,6 +146,7 @@ command_result colormods (Core * c, vector & parameters) return CR_OK; } +// FIXME: move cursor properly relative to view position command_result zoom (Core * c, vector & parameters) { if(parameters.size() < 3) @@ -159,12 +156,11 @@ command_result zoom (Core * c, vector & parameters) int z = atoi( parameters[2].c_str()); int xi, yi, zi; CoreSuspender cs (c); - Gui * g = c->getGui(); - if(g->getCursorCoords(xi, yi, zi)) + if(Gui::getCursorCoords(xi, yi, zi)) { - g->setCursorCoords(x,y,z); + Gui::setCursorCoords(x,y,z); } - g->setViewCoords(x,y,z); + Gui::setViewCoords(x,y,z); } command_result ktimer (Core * c, vector & parameters) diff --git a/plugins/devel/tilesieve.cpp b/plugins/devel/tilesieve.cpp index 21bcd0c90..8d663db1c 100644 --- a/plugins/devel/tilesieve.cpp +++ b/plugins/devel/tilesieve.cpp @@ -13,7 +13,6 @@ #include "TileTypes.h" using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/dwarfexport/dwarfexport.cpp b/plugins/dwarfexport/dwarfexport.cpp index 996f8c98c..6c997ca27 100644 --- a/plugins/dwarfexport/dwarfexport.cpp +++ b/plugins/dwarfexport/dwarfexport.cpp @@ -20,9 +20,6 @@ using namespace std; #include using namespace DFHack; -using namespace DFHack::Simple; -using namespace DFHack::Simple; - using df::global::ui; using df::global::world; diff --git a/plugins/filltraffic.cpp b/plugins/filltraffic.cpp index dc05ecbc4..37d036868 100644 --- a/plugins/filltraffic.cpp +++ b/plugins/filltraffic.cpp @@ -40,7 +40,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector { commands.push_back(PluginCommand( "filltraffic","Flood-fill with selected traffic designation from cursor", - filltraffic, cursor_hotkey, + filltraffic, Gui::cursor_hotkey, " Flood-fill selected traffic type from the cursor.\n" "Traffic Type Codes:\n" " H: High Traffic\n" @@ -115,7 +115,6 @@ command_result filltraffic(Core * c, std::vector & params) } } - Gui * Gui = c->getGui(); if (!Maps::IsValid()) { c->con.printerr("Map is not available!\n"); @@ -126,7 +125,7 @@ command_result filltraffic(Core * c, std::vector & params) Maps::getSize(x_max,y_max,z_max); uint32_t tx_max = x_max * 16; uint32_t ty_max = y_max * 16; - Gui->getCursorCoords(cx,cy,cz); + Gui::getCursorCoords(cx,cy,cz); while(cx == -30000) { c->con.printerr("Cursor is not active.\n"); @@ -276,7 +275,6 @@ command_result setAllMatching(Core * c, checkTile checkProc, //Initialization. CoreSuspender suspend(c); - Gui * Gui = c->getGui(); if (!Maps::IsValid()) { c->con.printerr("Map is not available!\n"); diff --git a/plugins/fixveins.cpp b/plugins/fixveins.cpp index 3d8d5caea..de6ddf810 100644 --- a/plugins/fixveins.cpp +++ b/plugins/fixveins.cpp @@ -17,7 +17,6 @@ using std::vector; using std::string; using namespace DFHack; -using namespace DFHack::Simple; using namespace df::enums; using df::global::world; diff --git a/plugins/follow.cpp b/plugins/follow.cpp index d13643db5..aa165899e 100644 --- a/plugins/follow.cpp +++ b/plugins/follow.cpp @@ -29,7 +29,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector { commands.push_back(PluginCommand( "follow", "Follow the selected unit until camera control is released", - follow, view_unit_hotkey, + follow, Gui::view_unit_hotkey, " Select a unit and run this plugin to make the camera follow it. Moving the camera yourself deactivates the plugin.\n" )); followedUnit = 0; @@ -69,14 +69,15 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) df::coord &unitPos = followedUnit->pos; - Gui *gui = c->getGui(); //Get all of the relevant data for determining the size of the map on the window + //Get all of the relevant data for determining the size of the map on the window int32_t x,y,z,w,h,c_x,c_y,c_z; uint8_t menu_width, area_map_width; - gui->getViewCoords(x,y,z); - gui->getWindowSize(w,h); - gui->getMenuWidth(menu_width, area_map_width); - gui->getCursorCoords(c_x,c_y,c_z); + Gui::getViewCoords(x,y,z); + Gui::getWindowSize(w,h); + Gui::getMenuWidth(menu_width, area_map_width); + Gui::getCursorCoords(c_x,c_y,c_z); + // FIXME: is this really needed? does it ever evaluate to 'true'? if (c_x != -30000 && menu_width == 3) menu_width = 2; //Presence of the cursor means that there's actually a width-2 menu open h -= 2; //account for vertical borders @@ -103,20 +104,26 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) return CR_OK; } + //Get map size in tiles so we can prevent the camera from going off the edge uint32_t x_max, y_max, z_max; - Simple::Maps::getSize(x_max, y_max, z_max); //Get map size in tiles so we can prevent the camera from going off the edge + Maps::getSize(x_max, y_max, z_max); x_max *= 16; y_max *= 16; - x = unitPos.x + w/2 >= x_max ? x_max-w : (unitPos.x >= w/2 ? unitPos.x - w/2 : 0); //Calculate a new screen position centered on the selected unit + //Calculate a new screen position centered on the selected unit + x = unitPos.x + w/2 >= x_max ? x_max-w : (unitPos.x >= w/2 ? unitPos.x - w/2 : 0); y = unitPos.y + h/2 >= y_max ? y_max-h : (unitPos.y >= h/2 ? unitPos.y - h/2 : 0); z = unitPos.z; - gui->setViewCoords(x, y, z); //Set the new screen position! + //Set the new screen position! + Gui::setViewCoords(x, y, z); - if (c_x != -30000 && !world->ReadPauseState()) gui->setCursorCoords(c_x - (prevX-x), c_y - (prevY-y), z); //If, for some reason, the cursor is active and the screen is still moving, move the cursor along with the screen + //If, for some reason, the cursor is active and the screen is still moving, move the cursor along with the screen + if (c_x != -30000 && !world->ReadPauseState()) + Gui::setCursorCoords(c_x - (prevX-x), c_y - (prevY-y), z); - prevX = x; //Save this round's stuff for next time so we can monitor for changes made by the user + //Save this round's stuff for next time so we can monitor for changes made by the user + prevX = x; prevY = y; prevZ = z; prevMenuWidth = menu_width; @@ -136,7 +143,7 @@ command_result follow (Core * c, std::vector & parameters) c->con.print("No longer following previously selected unit.\n"); followedUnit = 0; } - followedUnit = getSelectedUnit(c); + followedUnit = Gui::getSelectedUnit(c); if (followedUnit) { std::ostringstream ss; diff --git a/plugins/initflags.cpp b/plugins/initflags.cpp index c9bbe4584..1125b625b 100644 --- a/plugins/initflags.cpp +++ b/plugins/initflags.cpp @@ -23,9 +23,9 @@ DFhackCExport command_result plugin_init (Core *c, std::vector & { if (d_init) { commands.push_back(PluginCommand("twaterlvl", "Toggle display of water/magma depth.", - twaterlvl, dwarfmode_hotkey)); + twaterlvl, Gui::dwarfmode_hotkey)); commands.push_back(PluginCommand("tidlers", "Toggle display of idlers.", - tidlers, dwarfmode_hotkey)); + tidlers, Gui::dwarfmode_hotkey)); } std::cerr << "d_init: " << sizeof(df::d_init) << endl; return CR_OK; diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp index 805fc545e..e81414238 100644 --- a/plugins/jobutils.cpp +++ b/plugins/jobutils.cpp @@ -89,7 +89,7 @@ DFhackCExport command_result plugin_init (Core *c, std::vector & commands.push_back( PluginCommand( "job-duplicate", "Duplicate the selected job in a workshop.", - job_duplicate, workshop_job_hotkey, + job_duplicate, Gui::workshop_job_hotkey, " - In 'q' mode, when a job is highlighted within a workshop\n" " or furnace building, instantly duplicates the job.\n" ) @@ -108,15 +108,15 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) static bool job_material_hotkey(Core *c, df::viewscreen *top) { - return workshop_job_hotkey(c, top) || - build_selector_hotkey(c, top); + return Gui::workshop_job_hotkey(c, top) || + Gui::build_selector_hotkey(c, top); } /* job-material implementation */ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) { - df::job *job = getSelectedWorkshopJob(c); + df::job *job = Gui::getSelectedWorkshopJob(c); if (!job) return CR_FAILURE; @@ -268,7 +268,7 @@ static command_result job_duplicate(Core * c, vector & parameters) if (!parameters.empty()) return CR_WRONG_USAGE; - df::job *job = getSelectedWorkshopJob(c); + df::job *job = Gui::getSelectedWorkshopJob(c); if (!job) return CR_FAILURE; @@ -320,14 +320,14 @@ static command_result job_cmd(Core * c, vector & parameters) std::string cmd = (parameters.empty() ? "query" : parameters[0]); if (cmd == "query" || cmd == "list") { - df::job *job = getSelectedJob(c); + df::job *job = Gui::getSelectedJob(c); if (!job) return CR_WRONG_USAGE; if (cmd == "query") { printJobDetails(c, job); } else { - if (!workshop_job_hotkey(c, c->getTopViewscreen())) + if (!Gui::workshop_job_hotkey(c, c->getTopViewscreen())) return CR_WRONG_USAGE; df::building *selected = world->selected_building; @@ -340,7 +340,7 @@ static command_result job_cmd(Core * c, vector & parameters) if (parameters.size() != 3) return CR_WRONG_USAGE; - df::job *job = getSelectedJob(c); + df::job *job = Gui::getSelectedJob(c); df::job_item *item = getJobItem(c, job, parameters[1]); if (!item) return CR_WRONG_USAGE; @@ -384,7 +384,7 @@ static command_result job_cmd(Core * c, vector & parameters) if (parameters.size() != 3) return CR_WRONG_USAGE; - df::job *job = getSelectedJob(c); + df::job *job = Gui::getSelectedJob(c); df::job_item *item = getJobItem(c, job, parameters[1]); if (!item) return CR_WRONG_USAGE; diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 139faafcf..9e26a9e9b 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -224,7 +224,6 @@ command_result df_liquids (Core * c, vector & parameters) { int32_t x,y,z; - DFHack::Gui * Position; for(size_t i = 0; i < parameters.size();i++) { if(parameters[i] == "help" || parameters[i] == "?") @@ -429,7 +428,6 @@ command_result df_liquids (Core * c, vector & parameters) else if(command.empty()) { CoreSuspender suspend(c); - Position = c->getGui(); do { if (!Maps::IsValid()) @@ -437,7 +435,7 @@ command_result df_liquids (Core * c, vector & parameters) c->con << "Can't see any DF map loaded." << endl; break;; } - if(!Position->getCursorCoords(x,y,z)) + if(!Gui::getCursorCoords(x,y,z)) { c->con << "Can't get cursor coords! Make sure you have a cursor active in DF." << endl; break; diff --git a/plugins/plants.cpp b/plugins/plants.cpp index 8e5d51a75..951ac0a8b 100644 --- a/plugins/plants.cpp +++ b/plugins/plants.cpp @@ -102,7 +102,6 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre c->con.printerr("Map is not available!\n"); return CR_FAILURE; } - Gui * Gui = c->getGui(); uint32_t x_max, y_max, z_max; Maps::getSize(x_max, y_max, z_max); MapExtras::MapCache map; @@ -125,7 +124,7 @@ static command_result immolations (Core * c, do_what what, bool shrubs, bool tre else { int32_t x,y,z; - if(Gui->getCursorCoords(x,y,z)) + if(Gui::getCursorCoords(x,y,z)) { vector * alltrees; if(Maps::ReadVegetation(x/16,y/16,z,alltrees)) @@ -205,9 +204,8 @@ command_result df_grow (Core * c, vector & parameters) return CR_FAILURE; } MapExtras::MapCache map; - Gui *Gui = c->getGui(); int32_t x,y,z; - if(Gui->getCursorCoords(x,y,z)) + if(Gui::getCursorCoords(x,y,z)) { vector * alltrees; if(Maps::ReadVegetation(x/16,y/16,z,alltrees)) diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 970a07350..ea3dd85ee 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -19,20 +19,23 @@ 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; 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 +48,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; } @@ -57,9 +63,8 @@ command_result df_cprobe (Core * c, vector & parameters) { Console & con = c->con; CoreSuspender suspend(c); - DFHack::Gui *Gui = c->getGui(); int32_t cursorX, cursorY, cursorZ; - Gui->getCursorCoords(cursorX,cursorY,cursorZ); + Gui::getCursorCoords(cursorX,cursorY,cursorZ); if(cursorX == -30000) { con.printerr("No cursor; place cursor over creature to probe.\n"); @@ -94,7 +99,6 @@ command_result df_probe (Core * c, vector & parameters) CoreSuspender suspend(c); - DFHack::Gui *Gui = c->getGui(); DFHack::Materials *Materials = c->getMaterials(); DFHack::VersionInfo* mem = c->vinfo; std::vector inorganic; @@ -111,7 +115,7 @@ command_result df_probe (Core * c, vector & parameters) Maps::getPosition(regionX,regionY,regionZ); int32_t cursorX, cursorY, cursorZ; - Gui->getCursorCoords(cursorX,cursorY,cursorZ); + Gui::getCursorCoords(cursorX,cursorY,cursorZ); if(cursorX == -30000) { con.printerr("No cursor; place cursor over tile to probe.\n"); @@ -273,3 +277,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; +} diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index a52ef756c..91f0c446a 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -76,6 +76,18 @@ bool operator>(const matdata & q1, const matdata & q2) return q1.count > q2.count; } +template +struct shallower : public binary_function<_Tp, _Tp, bool> +{ + 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; @@ -90,10 +102,10 @@ template