From 02e486be885ebeecc90b63bf7a5fb949aaedc833 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 20 Feb 2012 17:53:39 +0400 Subject: [PATCH 1/5] Support the new unitlist screen; it's same as joblist, but with pages. --- library/modules/Gui.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 5935dd32e..30ef16d96 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -46,6 +46,7 @@ using namespace DFHack; #include "df/global_objects.h" #include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_joblistst.h" +#include "df/viewscreen_unitlistst.h" #include "df/viewscreen_itemst.h" #include "df/ui_unit_view_mode.h" #include "df/ui_sidebar_menus.h" @@ -83,11 +84,11 @@ bool DFHack::dwarfmode_hotkey(Core *, df::viewscreen *top) return !!strict_virtual_cast(top); } -//FIXME: this class has a second part (split off in 31.xx)! bool DFHack::unitjobs_hotkey(Core *, df::viewscreen *top) { - // Require the main dwarf mode screen - return !!strict_virtual_cast(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) @@ -230,6 +231,9 @@ bool DFHack::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; + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top)) + return vector_get(screen->jobs[screen->page], screen->cursor_pos[screen->page]) != NULL; + return workshop_job_hotkey(c,top); } @@ -246,6 +250,16 @@ df::job *DFHack::getSelectedJob(Core *c, bool quiet) return job; } + else if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top)) + { + int page = screen->page; + df::job *job = vector_get(screen->jobs[page], screen->cursor_pos[page]); + + if (!job && !quiet) + c->con.printerr("Selected unit has no job\n"); + + return job; + } else return getSelectedWorkshopJob(c, quiet); } @@ -262,6 +276,9 @@ static df::unit *getAnyUnit(Core *c, df::viewscreen *top) if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top)) return vector_get(screen->units, screen->cursor_pos); + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top)) + return vector_get(screen->units[screen->page], screen->cursor_pos[screen->page]); + if (VIRTUAL_CAST_VAR(screen, df::viewscreen_itemst, top)) { df::general_ref *ref = vector_get(screen->entry_ref, screen->cursor_pos); From 1ca500ff252b9fe6c78a8316bb0bca1e06dd1f3f Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 20 Feb 2012 18:04:58 +0400 Subject: [PATCH 2/5] Update the assumed identity in rename unit. --- plugins/rename.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/rename.cpp b/plugins/rename.cpp index 379230023..fa4ffbc61 100644 --- a/plugins/rename.cpp +++ b/plugins/rename.cpp @@ -12,6 +12,8 @@ #include "df/unit.h" #include "df/unit_soul.h" #include "df/historical_figure.h" +#include "df/historical_figure_info.h" +#include "df/assumed_identity.h" #include "df/language_name.h" #include @@ -123,7 +125,18 @@ static command_result rename(Core * c, vector ¶meters) df::historical_figure *figure = df::historical_figure::find(unit->hist_figure_id); if (figure) + { set_nickname(&figure->name, parameters[1]); + + // v0.34.01: added the vampire's assumed identity + if (figure->info && figure->info->reputation) + { + auto identity = df::assumed_identity::find(figure->info->reputation->cur_identity); + + if (identity) + set_nickname(&identity->name, parameters[1]); + } + } } else if (cmd == "unit-profession") { From 931121e5fd121647bba0080751076ef2b433a1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 20 Feb 2012 17:55:33 +0100 Subject: [PATCH 3/5] Update structures --- library/xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 6d44d3c11..2262aac51 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 6d44d3c11dd9f23e0665a1af9538a84ec627e333 +Subproject commit 2262aac5158e0ee8e940d19fc6620e571f064a1d From 2524f81ae0da5668fe46ff0319772cd01edbad3f Mon Sep 17 00:00:00 2001 From: Mike Stewart Date: Mon, 20 Feb 2012 19:32:58 -0800 Subject: [PATCH 4/5] Fix tile materials in mapexport. --- plugins/mapexport/mapexport.cpp | 5 +++-- plugins/mapexport/proto/Tile.proto | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/mapexport/mapexport.cpp b/plugins/mapexport/mapexport.cpp index 4733c1954..004937fdb 100644 --- a/plugins/mapexport/mapexport.cpp +++ b/plugins/mapexport/mapexport.cpp @@ -208,8 +208,7 @@ command_result mapexport (Core * c, std::vector & parameters) df::tiletype type = b->TileTypeAt(coord); prototile->set_type((dfproto::Tile::TileType)tileShape(type)); - - prototile->set_material_type((dfproto::Tile::TileMaterialType)tileMaterial(type)); + prototile->set_tile_material((dfproto::Tile::TileMaterialType)tileMaterial(type)); df::coord map_pos = df::coord(b_x*16+x,b_y*16+y,z); @@ -249,6 +248,8 @@ command_result mapexport (Core * c, std::vector & parameters) prototile->set_material_type(constructionMaterials[map_pos].second); } break; + default: + break; } } } diff --git a/plugins/mapexport/proto/Tile.proto b/plugins/mapexport/proto/Tile.proto index 57c8ef049..b7f8fcb4a 100644 --- a/plugins/mapexport/proto/Tile.proto +++ b/plugins/mapexport/proto/Tile.proto @@ -36,7 +36,7 @@ message Tile FEATURE = 3; LAVA_STONE = 4; MINERAL = 5; - FROZE_LIQUID = 6; + FROZEN_LIQUID = 6; CONSTRUCTION = 7; GRASS_LIGHT = 8; GRASS_DARK = 9; From f8d0b83b0a1d7033351bad67c6abecfbf573dcc6 Mon Sep 17 00:00:00 2001 From: Mike Stewart Date: Tue, 21 Feb 2012 00:44:10 -0800 Subject: [PATCH 5/5] Add new follow plugin that makes the DF window center on and follow a selected unit. --- plugins/CMakeLists.txt | 1 + plugins/follow.cpp | 128 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 plugins/follow.cpp diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index edfed4e1c..2dcfe2766 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -76,6 +76,7 @@ DFHACK_PLUGIN(workflow workflow.cpp) DFHACK_PLUGIN(showmood showmood.cpp) DFHACK_PLUGIN(fixveins fixveins.cpp) DFHACK_PLUGIN(fixpositions fixpositions.cpp) +DFHACK_PLUGIN(follow follow.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp) # this is the skeleton plugin. If you want to make your own, make a copy and then change it diff --git a/plugins/follow.cpp b/plugins/follow.cpp new file mode 100644 index 000000000..2c4237b3f --- /dev/null +++ b/plugins/follow.cpp @@ -0,0 +1,128 @@ +// Make the camera follow the selected unit + +#include "Core.h" +#include +#include +#include + +#include "DFHack.h" +#include "DataDefs.h" +#include "modules/Gui.h" +#include "modules/World.h" +#include "modules/Maps.h" +#include +#include + +using namespace DFHack; +using namespace df::enums; + + +command_result follow (Core * c, std::vector & parameters); + +df::unit *followedUnit; +int32_t prevX, prevY, prevZ; + +DFhackCExport const char * plugin_name ( void ) +{ + return "follow"; +} + + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand( + "follow", "Follow the selected unit until camera control is released", + follow, false, + " Select a unit and run this plugin to make the camera follow it. Moving the camera yourself deactivates the plugin.\n" + )); + followedUnit = 0; + prevX=prevY=prevZ = -1; + return CR_OK; +} + + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +// Called to notify the plugin about important state changes. +// Invoked with DF suspended, and always before the matching plugin_onupdate. +// More event codes may be added in the future. + +DFhackCExport command_result plugin_onstatechange(Core* c, state_change_event event) +{ + switch (event) { + case SC_GAME_LOADED: + case SC_GAME_UNLOADED: + followedUnit = 0; + prevX=prevY=prevZ = -1; + break; + default: + break; + } + return CR_OK; +} + + +DFhackCExport command_result plugin_onupdate ( Core * c ) +{ + if (!followedUnit) return CR_OK; + DFHack::World *world =c->getWorld(); + if (world->ReadPauseState() && prevX==-1) return CR_OK; + Gui *gui = c->getGui(); + df::coord &unitPos = followedUnit->pos; + int32_t x,y,z,w,h; + gui->getViewCoords(x,y,z); + gui->getWindowSize(w,h); + if (prevX==-1) + { + prevX = x; + prevY = y; + prevZ = z; + } + else if(prevX != x || prevY != y || prevZ != z) + { + followedUnit = 0; + prevX=prevY=prevZ = -1; + c->con.print("No longer following anything.\n"); + return CR_OK; + } + + uint32_t x_max, y_max, z_max; + Simple::Maps::getSize(x_max, y_max, z_max); + + x_max *= 16; + y_max *= 16; + + prevX = unitPos.x + w/2 >= x_max ? x_max-w+2 : (unitPos.x >= w/2 ? unitPos.x - w/2 : 0); + prevY = unitPos.y + h/2 >= y_max ? y_max-h+2 : (unitPos.y >= h/2 ? unitPos.y - h/2 : 0); + prevZ = unitPos.z; + + gui->setViewCoords(prevX, prevY, prevZ); + + return CR_OK; +} + +command_result follow (Core * c, std::vector & parameters) +{ + if (!parameters.empty()) + return CR_WRONG_USAGE; + + CoreSuspender suspend(c); + + followedUnit = getSelectedUnit(c); + if (followedUnit) + { + c->con.print("Unpause to begin following "); + c->con.print(df::global::world->raws.creatures.all[followedUnit->race]->name[0].c_str()); + if (followedUnit->name.has_name) + { + c->con.print(" %s", followedUnit->name.first_name.c_str()); + } + c->con.print(".\n"); + } + else followedUnit = 0; + return CR_OK; +}