diff --git a/dfhack.init-example b/dfhack.init-example index 75552006e..82210a2a6 100644 --- a/dfhack.init-example +++ b/dfhack.init-example @@ -55,6 +55,9 @@ keybinding add Alt-S@dwarfmode/Default gui/settings-manager # change quantity of manager orders keybinding add Alt-Q@jobmanagement/Main gui/manager-quantity +# view combat reports for the selected unit/corpse/spatter +keybinding add Ctrl-Shift-R view-unit-reports + ############################## # Generic adv mode bindings # ############################## diff --git a/docs/Authors.rst b/docs/Authors.rst index 0f7e06811..8c1b5096e 100644 --- a/docs/Authors.rst +++ b/docs/Authors.rst @@ -28,6 +28,7 @@ Carter Bray Qartar Chris Dombroski cdombroski Clayton Hughes ClĂ©ment Vuchener cvuchener +Dan Amlund danamlund David Corbett dscorbett David Seguin dseguin Deon diff --git a/library/include/modules/MapCache.h b/library/include/modules/MapCache.h index 0048f5bd9..36625719b 100644 --- a/library/include/modules/MapCache.h +++ b/library/include/modules/MapCache.h @@ -276,6 +276,9 @@ public: return true; } + int32_t priorityAt(df::coord2d p); + bool setPriorityAt(df::coord2d p, int32_t priority); + df::tile_occupancy OccupancyAt(df::coord2d p) { return index_tile(occupancy,p); @@ -544,13 +547,31 @@ class DFHACK_EXPORT MapCache Block * b= BlockAtTile(tilecoord); return b ? b->DesignationAt(tilecoord) : df::tile_designation(); } - bool setDesignationAt (DFCoord tilecoord, df::tile_designation des) + // priority is optional, only set if >= 0 + bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = -1) { - if(Block * b= BlockAtTile(tilecoord)) - return b->setDesignationAt(tilecoord, des); + if (Block *b = BlockAtTile(tilecoord)) + { + if (!b->setDesignationAt(tilecoord, des)) + return false; + if (priority >= 0 && b->setPriorityAt(tilecoord, priority)) + return false; + return true; + } return false; } + int32_t priorityAt (DFCoord tilecoord) + { + Block *b = BlockAtTile(tilecoord); + return b ? b->priorityAt(tilecoord) : -1; + } + bool setPriorityAt (DFCoord tilecoord, int32_t priority) + { + Block *b = BlockAtTile(tilecoord); + return b ? b->setPriorityAt(tilecoord, priority) : false; + } + df::tile_occupancy occupancyAt (DFCoord tilecoord) { Block * b= BlockAtTile(tilecoord); diff --git a/library/include/modules/Maps.h b/library/include/modules/Maps.h index fb5fc9860..6b6e62f0a 100644 --- a/library/include/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -46,6 +46,7 @@ distribution. namespace df { struct block_square_event; + struct block_square_event_designation_priorityst; struct block_square_event_frozen_liquidst; struct block_square_event_grassst; struct block_square_event_item_spatterst; @@ -321,7 +322,8 @@ extern DFHACK_EXPORT bool SortBlockEvents(df::map_block *block, std::vector* grass = 0, std::vector* constructions = 0, std::vector* spoors = 0, - std::vector* items = 0 + std::vector* items = 0, + std::vector* priorities = 0 ); /// remove a block event from the block by address diff --git a/library/modules/MapCache.cpp b/library/modules/MapCache.cpp index fb4aef935..ffb9fc769 100644 --- a/library/modules/MapCache.cpp +++ b/library/modules/MapCache.cpp @@ -49,8 +49,9 @@ using namespace std; #include "df/block_burrow.h" #include "df/block_burrow_link.h" -#include "df/block_square_event_grassst.h" +#include "df/block_square_event_designation_priorityst.h" #include "df/block_square_event_frozen_liquidst.h" +#include "df/block_square_event_grassst.h" #include "df/building_type.h" #include "df/builtin_mats.h" #include "df/burrow.h" @@ -271,6 +272,43 @@ bool MapExtras::Block::setTiletypeAt(df::coord2d pos, df::tiletype tt, bool forc return true; } +static df::block_square_event_designation_priorityst *getPriorityEvent(df::map_block *block, bool write) +{ + vector events; + Maps::SortBlockEvents(block, 0, 0, 0, 0, 0, 0, 0, &events); + if (events.empty()) + { + if (!write) + return NULL; + + auto event = df::allocate(); + block->block_events.push_back((df::block_square_event*)event); + return event; + } + return events[0]; +} + +int32_t MapExtras::Block::priorityAt(df::coord2d pos) +{ + if (!block) + return false; + + if (auto event = getPriorityEvent(block, false)) + return event->priority[pos.x % 16][pos.y % 16]; + + return 0; +} + +bool MapExtras::Block::setPriorityAt(df::coord2d pos, int32_t priority) +{ + if (!block || priority < 0) + return false; + + auto event = getPriorityEvent(block, true); + event->priority[pos.x % 16][pos.y % 16] = priority; + return true; +} + bool MapExtras::Block::setVeinMaterialAt(df::coord2d pos, int16_t mat, df::inclusion_type type) { using namespace df::enums::tiletype_material; diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 2b2311a7c..20255dbe3 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -402,7 +402,8 @@ bool Maps::SortBlockEvents(df::map_block *block, vector *grasses, vector *constructions, vector *spoors, - vector *items) + vector *items, + vector *priorities) { if (veins) veins->clear(); @@ -456,6 +457,10 @@ bool Maps::SortBlockEvents(df::map_block *block, if (items) items->push_back((df::block_square_event_item_spatterst *)evt); break; + case block_square_event_type::designation_priority: + if (priorities) + priorities->push_back((df::block_square_event_designation_priorityst *)evt); + break; } } return true; diff --git a/library/xml b/library/xml index 6b6dda838..f0c609211 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 6b6dda838fc1b9c4e1c47fbdfbf19838749bad14 +Subproject commit f0c609211fbfd354b576cae75e9e64f8c6c80b06 diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 5404f2f2d..a56688a7b 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1,16 +1,23 @@ +#include +#include +#include +#include +#include +#include + #include "Core.h" #include "Console.h" #include "Export.h" #include "PluginManager.h" -#include "modules/Maps.h" +#include "uicommon.h" + #include "modules/Gui.h" #include "modules/MapCache.h" +#include "modules/Maps.h" #include "modules/Materials.h" -#include -#include -#include -#include -#include + +#include "df/ui_sidebar_menus.h" + using std::vector; using std::string; using std::stack; @@ -27,6 +34,7 @@ command_result digcircle (color_ostream &out, vector & parameters); command_result digtype (color_ostream &out, vector & parameters); DFHACK_PLUGIN("dig"); +REQUIRE_GLOBAL(ui_sidebar_menus); REQUIRE_GLOBAL(world); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) @@ -97,6 +105,7 @@ enum circle_what bool dig (MapExtras::MapCache & MCache, circle_what what, df::tile_dig_designation type, + int32_t priority, int32_t x, int32_t y, int32_t z, int x_max, int y_max ) @@ -175,20 +184,21 @@ bool dig (MapExtras::MapCache & MCache, break; } std::cerr << "allowing tt" << (int)tt << "\n"; - MCache.setDesignationAt(at,des); + MCache.setDesignationAt(at,des,priority); return true; }; bool lineX (MapExtras::MapCache & MCache, circle_what what, df::tile_dig_designation type, + int32_t priority, int32_t y1, int32_t y2, int32_t x, int32_t z, int x_max, int y_max ) { for(int32_t y = y1; y <= y2; y++) { - dig(MCache, what, type,x,y,z, x_max, y_max); + dig(MCache, what, type, priority, x,y,z, x_max, y_max); } return true; }; @@ -196,17 +206,51 @@ bool lineX (MapExtras::MapCache & MCache, bool lineY (MapExtras::MapCache & MCache, circle_what what, df::tile_dig_designation type, + int32_t priority, int32_t x1, int32_t x2, int32_t y, int32_t z, int x_max, int y_max ) { for(int32_t x = x1; x <= x2; x++) { - dig(MCache, what, type,x,y,z, x_max, y_max); + dig(MCache, what, type, priority, x,y,z, x_max, y_max); } return true; }; +int32_t parse_priority(color_ostream &out, vector ¶meters) +{ + int32_t default_priority = ui_sidebar_menus->designation.priority; + + for (auto it = parameters.begin(); it != parameters.end(); ++it) + { + const string &s = *it; + if (s.substr(0, 2) == "p=" || s.substr(0, 2) == "-p") + { + if (s.size() >= 3) + { + auto priority = int32_t(1000 * atof(s.c_str() + 2)); + parameters.erase(it); + return priority; + } + else if (it + 1 != parameters.end()) + { + auto priority = int32_t(1000 * atof((*(it + 1)).c_str())); + parameters.erase(it); + parameters.erase(it + 1); + return priority; + } + else + { + out.printerr("invalid priority specified; reverting to %i\n", default_priority); + break; + } + } + } + + return default_priority; +} + command_result digcircle (color_ostream &out, vector & parameters) { static bool filled = false; @@ -215,6 +259,8 @@ command_result digcircle (color_ostream &out, vector & parameters) static int diameter = 0; auto saved_d = diameter; bool force_help = false; + int32_t priority = parse_priority(out, parameters); + for(size_t i = 0; i < parameters.size();i++) { if(parameters[i] == "help" || parameters[i] == "?") @@ -326,12 +372,12 @@ command_result digcircle (color_ostream &out, vector & parameters) // paint center if(filled) { - lineY(MCache,what,type, cx - r, cx + r, cy, cz,x_max,y_max); + lineY(MCache, what, type, priority, cx - r, cx + r, cy, cz, x_max, y_max); } else { - dig(MCache, what, type,cx - r, cy, cz,x_max,y_max); - dig(MCache, what, type,cx + r, cy, cz,x_max,y_max); + dig(MCache, what, type, priority, cx - r, cy, cz, x_max, y_max); + dig(MCache, what, type, priority, cx + r, cy, cz, x_max, y_max); } adjust = false; iter = 2; @@ -363,24 +409,24 @@ command_result digcircle (color_ostream &out, vector & parameters) // paint if(filled || iter == diameter - 1) { - lineY(MCache,what,type, left, right, top , cz,x_max,y_max); - lineY(MCache,what,type, left, right, bottom , cz,x_max,y_max); + lineY(MCache, what, type, priority, left, right, top, cz, x_max, y_max); + lineY(MCache, what, type, priority, left, right, bottom, cz, x_max, y_max); } else { - dig(MCache, what, type,left, top, cz,x_max,y_max); - dig(MCache, what, type,left, bottom, cz,x_max,y_max); - dig(MCache, what, type,right, top, cz,x_max,y_max); - dig(MCache, what, type,right, bottom, cz,x_max,y_max); + dig(MCache, what, type, priority, left, top, cz, x_max, y_max); + dig(MCache, what, type, priority, left, bottom, cz, x_max, y_max); + dig(MCache, what, type, priority, right, top, cz, x_max, y_max); + dig(MCache, what, type, priority, right, bottom, cz, x_max, y_max); } if(!filled && diff > 1) { int lright = cx + lastwhole; int lleft = cx - lastwhole + adjust; - lineY(MCache,what,type, lleft + 1, left - 1, top + 1 , cz,x_max,y_max); - lineY(MCache,what,type, right + 1, lright - 1, top + 1 , cz,x_max,y_max); - lineY(MCache,what,type, lleft + 1, left - 1, bottom - 1 , cz,x_max,y_max); - lineY(MCache,what,type, right + 1, lright - 1, bottom - 1 , cz,x_max,y_max); + lineY(MCache, what, type, priority, lleft + 1, left - 1, top + 1 , cz, x_max, y_max); + lineY(MCache, what, type, priority, right + 1, lright - 1, top + 1 , cz, x_max, y_max); + lineY(MCache, what, type, priority, lleft + 1, left - 1, bottom - 1 , cz, x_max, y_max); + lineY(MCache, what, type, priority, right + 1, lright - 1, bottom - 1 , cz, x_max, y_max); } lastwhole = whole; } @@ -808,6 +854,8 @@ command_result digexp (color_ostream &out, vector & parameters) bool force_help = false; static explo_how how = EXPLO_NOTHING; static explo_what what = EXPLO_HIDDEN; + int32_t priority = parse_priority(out, parameters); + for(size_t i = 0; i < parameters.size();i++) { if(parameters[i] == "help" || parameters[i] == "?") @@ -963,7 +1011,7 @@ command_result digexp (color_ostream &out, vector & parameters) if(cross[y][x]) { des.bits.dig = tile_dig_designation::Default; - mx.setDesignationAt(pos,des); + mx.setDesignationAt(pos,des,priority); } } mx.WriteAll(); @@ -984,6 +1032,7 @@ command_result digvx (color_ostream &out, vector & parameters) // HOTKEY COMMAND: CORE ALREADY SUSPENDED vector lol; lol.push_back("x"); + lol.push_back(string("-p") + int_to_string(parse_priority(out, parameters))); return digv(out,lol); } @@ -992,6 +1041,8 @@ command_result digv (color_ostream &out, vector & parameters) // HOTKEY COMMAND: CORE ALREADY SUSPENDED uint32_t x_max,y_max,z_max; bool updown = false; + int32_t priority = parse_priority(out, parameters); + for(size_t i = 0; i < parameters.size();i++) { if(parameters.size() && parameters[0]=="x") @@ -1118,7 +1169,7 @@ command_result digv (color_ostream &out, vector & parameters) des_minus.bits.dig = tile_dig_designation::UpDownStair; else des_minus.bits.dig = tile_dig_designation::UpStair; - MCache->setDesignationAt(current-1,des_minus); + MCache->setDesignationAt(current-1,des_minus,priority); des.bits.dig = tile_dig_designation::DownStair; } @@ -1130,7 +1181,7 @@ command_result digv (color_ostream &out, vector & parameters) des_plus.bits.dig = tile_dig_designation::UpDownStair; else des_plus.bits.dig = tile_dig_designation::DownStair; - MCache->setDesignationAt(current+1,des_plus); + MCache->setDesignationAt(current+1,des_plus,priority); if(des.bits.dig == tile_dig_designation::DownStair) des.bits.dig = tile_dig_designation::UpDownStair; @@ -1140,7 +1191,7 @@ command_result digv (color_ostream &out, vector & parameters) } if(des.bits.dig == tile_dig_designation::No) des.bits.dig = tile_dig_designation::Default; - MCache->setDesignationAt(current,des); + MCache->setDesignationAt(current,des,priority); } } MCache->WriteAll(); @@ -1153,6 +1204,7 @@ command_result diglx (color_ostream &out, vector & parameters) // HOTKEY COMMAND: CORE ALREADY SUSPENDED vector lol; lol.push_back("x"); + lol.push_back(string("-p") + int_to_string(parse_priority(out, parameters))); return digl(out,lol); } @@ -1168,6 +1220,8 @@ command_result digl (color_ostream &out, vector & parameters) uint32_t x_max,y_max,z_max; bool updown = false; bool undo = false; + int32_t priority = parse_priority(out, parameters); + for(size_t i = 0; i < parameters.size();i++) { if(parameters[i]=="x") @@ -1326,7 +1380,7 @@ command_result digl (color_ostream &out, vector & parameters) // undo mode: clear designation if(undo) des_minus.bits.dig = tile_dig_designation::No; - MCache->setDesignationAt(current-1,des_minus); + MCache->setDesignationAt(current-1,des_minus,priority); des.bits.dig = tile_dig_designation::DownStair; } @@ -1341,7 +1395,7 @@ command_result digl (color_ostream &out, vector & parameters) // undo mode: clear designation if(undo) des_plus.bits.dig = tile_dig_designation::No; - MCache->setDesignationAt(current+1,des_plus); + MCache->setDesignationAt(current+1,des_plus,priority); if(des.bits.dig == tile_dig_designation::DownStair) des.bits.dig = tile_dig_designation::UpDownStair; @@ -1354,7 +1408,7 @@ command_result digl (color_ostream &out, vector & parameters) // undo mode: clear designation if(undo) des.bits.dig = tile_dig_designation::No; - MCache->setDesignationAt(current,des); + MCache->setDesignationAt(current,des,priority); } } MCache->WriteAll(); @@ -1371,6 +1425,7 @@ command_result digauto (color_ostream &out, vector & parameters) command_result digtype (color_ostream &out, vector & parameters) { //mostly copy-pasted from digv + int32_t priority = parse_priority(out, parameters); CoreSuspender suspend; if ( parameters.size() > 1 ) { @@ -1474,7 +1529,7 @@ command_result digtype (color_ostream &out, vector & parameters) df::tile_designation designation = mCache->designationAt(current); designation.bits.dig = baseDes.bits.dig; - mCache->setDesignationAt(current, designation); + mCache->setDesignationAt(current, designation,priority); } } }