From cffd3be591be530438a58f22f27675a3390a6948 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 16:34:20 -0500 Subject: [PATCH 01/11] Move labormanager out of dev --- plugins/CMakeLists.txt | 1 + plugins/devel/CMakeLists.txt | 1 - plugins/{devel => }/labormanager.cpp | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename plugins/{devel => }/labormanager.cpp (100%) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c24b940b9..97491a90d 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -110,6 +110,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) DFHACK_PLUGIN(jobutils jobutils.cpp) DFHACK_PLUGIN(lair lair.cpp) + DFHACK_PLUGIN(labormanager labormanager.cpp) DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) DFHACK_PLUGIN(luasocket luasocket.cpp LINK_LIBRARIES clsocket lua dfhack-tinythread) DFHACK_PLUGIN(manipulator manipulator.cpp) diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index a1e5b7f14..e5001fff7 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -9,7 +9,6 @@ DFHACK_PLUGIN(counters counters.cpp) DFHACK_PLUGIN(dumpmats dumpmats.cpp) DFHACK_PLUGIN(eventExample eventExample.cpp) DFHACK_PLUGIN(frozen frozen.cpp) -DFHACK_PLUGIN(labormanager labormanager.cpp) DFHACK_PLUGIN(kittens kittens.cpp) DFHACK_PLUGIN(memview memview.cpp) DFHACK_PLUGIN(nestboxes nestboxes.cpp) diff --git a/plugins/devel/labormanager.cpp b/plugins/labormanager.cpp similarity index 100% rename from plugins/devel/labormanager.cpp rename to plugins/labormanager.cpp From 18235da9d60f16de276bd0f7bc8ccd522a0bf129 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 16:45:25 -0500 Subject: [PATCH 02/11] add a misisng labor rule for leather crafts --- plugins/labormanager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/labormanager.cpp b/plugins/labormanager.cpp index 7d41c7814..5a2774cd2 100644 --- a/plugins/labormanager.cpp +++ b/plugins/labormanager.cpp @@ -1001,6 +1001,8 @@ private: return df::unit_labor::WOOD_CRAFT; case df::item_type::CLOTH: return df::unit_labor::CLOTHESMAKER; + case df::item_type::SKIN_TANNED: + return df::unit_labor::LEATHER; default: debug ("LABORMANAGER: Cannot deduce labor for make crafts job, item type %s\n", ENUM_KEY_STR(item_type, jobitem).c_str()); From 9aa6b84e24097b5596dcbe739be7d2aa8a38a404 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 16:55:37 -0500 Subject: [PATCH 03/11] alphabetical order --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 97491a90d..13425d2c6 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -109,8 +109,8 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) DFHACK_PLUGIN(jobutils jobutils.cpp) - DFHACK_PLUGIN(lair lair.cpp) DFHACK_PLUGIN(labormanager labormanager.cpp) + DFHACK_PLUGIN(lair lair.cpp) DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) DFHACK_PLUGIN(luasocket luasocket.cpp LINK_LIBRARIES clsocket lua dfhack-tinythread) DFHACK_PLUGIN(manipulator manipulator.cpp) From a04ed641b723e9a8d664280e07c9dbf805910b6d Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 17:03:45 -0500 Subject: [PATCH 04/11] SPACES not TABS --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 13425d2c6..6763c2c56 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -109,7 +109,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(infiniteSky infiniteSky.cpp) DFHACK_PLUGIN(isoworldremote isoworldremote.cpp PROTOBUFS isoworldremote) DFHACK_PLUGIN(jobutils jobutils.cpp) - DFHACK_PLUGIN(labormanager labormanager.cpp) + DFHACK_PLUGIN(labormanager labormanager.cpp) DFHACK_PLUGIN(lair lair.cpp) DFHACK_PLUGIN(liquids liquids.cpp Brushes.h LINK_LIBRARIES lua) DFHACK_PLUGIN(luasocket luasocket.cpp LINK_LIBRARIES clsocket lua dfhack-tinythread) From 385d34490bd51d3395018e7c7d7200a2ea05cad8 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 18:02:07 -0500 Subject: [PATCH 05/11] Docs for labormanager --- docs/Plugins.rst | 100 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index ac73bb58f..c8f24e12d 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -840,7 +840,105 @@ Examples: labormanager ============ -A more advanced alternative to `autolabor`. +Automatically manage dwarf labors to efficiently complete jobs. +Labormanager is derived from autolabor (above) but uses a completely +different approach to assigning jobs to dwarves. While autolabor tries +to keep as many dwarves busy as possible, labormanager instead strives +to get jobs done as quickly as possible. + +Labormanager frequently scans the current job list, current list of +dwarfs, and the map to determine how many dwarves need to be assigned to +what labors in order to meet all current labor needs without starving +any particular type of job. + +.. warning:: + + *As with autolabor, labormanager will override any manual changes you + make to labors while it is enabled, including through other tools such + as Dwarf Therapist* + +Simple usage: + +:enable labormanager: Enables the plugin with default settings. +(Persistent per fortress) :disable labormanager: Disables the plugin. + +Anything beyond this is optional - autolabor works fairly well on the +default settings. + +The default priorities for each labor vary (some labors are higher +priority by default than others). The way the plugin works is that, once +it determines how many of each labor is needed, it then sorts them by +adjusted priority. (Labors other than hauling have a bias added to them +based on how long it's been since they were last used, to prevent job +starvation.) The labor with the highest priority is selected, the "best +fit" dwarf for that labor is assigned to that labor, and then its +priority is *halved*. This process is repeated until either dwarfs or +labors run out. + +Because there is no easy way to detect how many haulers are actually +needed at any moment, the plugin always ensures that at least one dwarf +is assigned to each of the hauling labors, even if no hauling jobs are +detected. At least one dwarf is always assigned to construction removing +and cleaning because these jobs also cannot be easily detected. Lever +pulling is always assigned to everyone. Any dwarfs for which there are +no jobs will be assigned hauling, lever pulling, and cleaning labors. If +you use animal trainers, note that labormanager + +Labormanager also sometimes assigns extra labors to currently busy +dwarfs so that when they finish their current job, they will go off and +do something useful instead of standing around waiting for a job. + +There is special handling to ensure that at least one dwarf is assigned +to haul food whenever food is detected left in a place where it will rot +if not stored. This will cause a dwarf to go idle if you have no +storepiles to haul food to. + +Dwarfs who are unable to work (child, in the military, wounded, +handless, asleep, in a meeting) are entirely excluded from labor +assignment. Any dwarf explicitly assigned to a burrow will also be +completely ignored by labormanager. + +The fitness algorithm for assigning jobs to dwarfs generally attempts to +favor dwarfs who are more skilled over those who are less skilled. It +also tries to avoid assigning female dwarfs with children to jobs that +are "outside", favors assigning "outside" jobs to dwarfs who are +carrying a tool that could be used as a weapon, and tries to minimize +how often dwarfs have to reequip. + +Labormanager automatically determines medical needs and reserves health +care providers as needed. Note that this may cause idling if you have +injured dwarfs but no or inadequate hospital facilities. + +Hunting is never assigned without a butchery, and fishing is never +assigned without a fishery, and neither of these labors is assigned +unless specifically enabled. + +The method by which labormanager determines what labor is needed for a +particular job is complicated and, in places, incomplete. In some +situations, labormanager will detect that it cannot determine what labor +is required. It will, by default, pause and print an error message on +the dfhack console, followed by the message "LABORMANAGER: Game paused +so you can investigate the above message.". If this happens, please open +an issue on github, reporting the lines that immediately preceded this +message. You can tell labormanager to ignore this error and carry on by +typing "autolabor pause-on-error no", but be warned that some job may go +undone in this situation. + +Advanced usage: + +:autolabor enable: Turn plugin on. +:autolabor disable: Turn plugin off. +:autolabor priority : Set the priority value (see above) for labor to . +:autolabor reset : Reset the priority value of labor to its default. +:autolabor reset-all: Reset all priority values to their defaults. +:autolabor allow-fishing: Allow dwarfs to fish. *Warning* This tends to result in most of the fort going fishing. +:autolabor forbid-fishing: Forbid dwarfs from fishing. Default behavior. +:autolabor allow-hunting: Allow dwarfs to hunt. *Warning* This tends to result in as many dwarfs going hunting as you have crossbows. +:autolabor forbid-hunting: Forbid dwarfs from hunting. Default behavior. +:autolabor list: Show current priorities and current allocation stats. +:autolabor pause-on-error yes: Make labormanager pause if the labor inference engine fails. See above. +:autolabor pause-on-error no: Allow labormanager to continue past a labor inference engine failure. + .. _autohauler: From 6383ca13bf86bfda4c06e5067cd2dd2fa315d108 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Tue, 25 Oct 2016 18:10:29 -0500 Subject: [PATCH 06/11] Finish clipped sentence. (erk.) --- docs/Plugins.rst | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index c8f24e12d..13ea50661 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -882,7 +882,10 @@ detected. At least one dwarf is always assigned to construction removing and cleaning because these jobs also cannot be easily detected. Lever pulling is always assigned to everyone. Any dwarfs for which there are no jobs will be assigned hauling, lever pulling, and cleaning labors. If -you use animal trainers, note that labormanager +you use animal trainers, note that labormanager will misbehave if you +assign specific trainers to specific animals; results are only guaranteed +if you use "any trainer", and animal trainers will probably be +overallocated in any case. Labormanager also sometimes assigns extra labors to currently busy dwarfs so that when they finish their current job, they will go off and @@ -926,18 +929,18 @@ undone in this situation. Advanced usage: -:autolabor enable: Turn plugin on. -:autolabor disable: Turn plugin off. -:autolabor priority : Set the priority value (see above) for labor to . -:autolabor reset : Reset the priority value of labor to its default. -:autolabor reset-all: Reset all priority values to their defaults. -:autolabor allow-fishing: Allow dwarfs to fish. *Warning* This tends to result in most of the fort going fishing. -:autolabor forbid-fishing: Forbid dwarfs from fishing. Default behavior. -:autolabor allow-hunting: Allow dwarfs to hunt. *Warning* This tends to result in as many dwarfs going hunting as you have crossbows. -:autolabor forbid-hunting: Forbid dwarfs from hunting. Default behavior. -:autolabor list: Show current priorities and current allocation stats. -:autolabor pause-on-error yes: Make labormanager pause if the labor inference engine fails. See above. -:autolabor pause-on-error no: Allow labormanager to continue past a labor inference engine failure. +:labormanager enable: Turn plugin on. +:labormanager disable: Turn plugin off. +:labormanager priority : Set the priority value (see above) for labor to . +:labormanager reset : Reset the priority value of labor to its default. +:labormanager reset-all: Reset all priority values to their defaults. +:labormanager allow-fishing: Allow dwarfs to fish. *Warning* This tends to result in most of the fort going fishing. +:labormanager forbid-fishing: Forbid dwarfs from fishing. Default behavior. +:labormanager allow-hunting: Allow dwarfs to hunt. *Warning* This tends to result in as many dwarfs going hunting as you have crossbows. +:labormanager forbid-hunting: Forbid dwarfs from hunting. Default behavior. +:labormanager list: Show current priorities and current allocation stats. +:labormanager pause-on-error yes: Make labormanager pause if the labor inference engine fails. See above. +:labormanager pause-on-error no: Allow labormanager to continue past a labor inference engine failure. .. _autohauler: From 4e7f2b95796d0d476a19968dd9df84aba63b878d Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 29 Oct 2016 19:00:28 -0400 Subject: [PATCH 07/11] win64 ruby 2 --- plugins/ruby/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/CMakeLists.txt b/plugins/ruby/CMakeLists.txt index bfc41c032..208a851e5 100644 --- a/plugins/ruby/CMakeLists.txt +++ b/plugins/ruby/CMakeLists.txt @@ -33,7 +33,12 @@ ELSE() SET(RUBYLIB ${CMAKE_CURRENT_SOURCE_DIR}/win${DFHACK_BUILD_ARCH}/libruby.dll) SET(RUBYLIB_INSTALL_NAME "libruby.dll") IF(${DFHACK_BUILD_ARCH} STREQUAL 64) - MESSAGE("No ruby lib for 64-bit Windows yet") + DOWNLOAD_FILE_UNZIP("https://github.com/DFHack/dfhack-bin/releases/download/0.43.05/win64-libruby200.dll.gz" + "gz" + ${RUBYLIB}.gz + "81db54a8b8b3090c94c6ae2147d30b8f" + ${RUBYLIB} + "8a8564418aebddef3dfee1e96690e713") ELSE() DOWNLOAD_FILE_UNZIP("https://github.com/DFHack/dfhack-bin/releases/download/0.43.05/win32-libruby187.dll.gz" "gz" From 9e97ccbb50401dbbb84a33f34bf8a60cf3414868 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 29 Oct 2016 19:08:54 -0400 Subject: [PATCH 08/11] Use system libruby on osx64 (since ruby 1.8 and 2 are supported now) --- plugins/ruby/CMakeLists.txt | 6 ++++-- plugins/ruby/ruby.cpp | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/ruby/CMakeLists.txt b/plugins/ruby/CMakeLists.txt index 208a851e5..6b5e62c66 100644 --- a/plugins/ruby/CMakeLists.txt +++ b/plugins/ruby/CMakeLists.txt @@ -2,7 +2,7 @@ IF (APPLE) SET(RUBYLIB ${CMAKE_CURRENT_SOURCE_DIR}/osx${DFHACK_BUILD_ARCH}/libruby.dylib) SET(RUBYLIB_INSTALL_NAME "libruby.dylib") IF(${DFHACK_BUILD_ARCH} STREQUAL 64) - MESSAGE("No ruby lib for 64-bit OS X yet") + # MESSAGE("No ruby lib for 64-bit OS X yet") ELSE() DOWNLOAD_FILE_UNZIP("https://github.com/DFHack/dfhack-bin/releases/download/0.43.05/osx32-libruby187.dylib.gz" "gz" @@ -73,7 +73,9 @@ ADD_DEPENDENCIES(ruby ruby-autogen-rb) IF(EXISTS ${RUBYLIB}) INSTALL(FILES ${RUBYLIB} DESTINATION ${DFHACK_LIBRARY_DESTINATION} RENAME ${RUBYLIB_INSTALL_NAME}) ELSE() - MESSAGE(WARNING "Ruby library not found at ${RUBYLIB} - will not be installed") + IF(NOT(APPLE AND ${DFHACK_BUILD_ARCH} STREQUAL 64)) + MESSAGE(WARNING "Ruby library not found at ${RUBYLIB} - will not be installed") + ENDIF() ENDIF() INSTALL(DIRECTORY . diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index f9368fdf6..7a21e32eb 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -322,7 +322,11 @@ static int df_loadruby(void) #if defined(WIN32) "./libruby.dll"; #elif defined(__APPLE__) + #ifdef DFHACK64 + "/System/Library/Frameworks/Ruby.framework/Ruby"; + #else "hack/libruby.dylib"; + #endif #else "hack/libruby.so"; #endif From 2e6c7a90be21a0b2e746f3557f5f3716475197c6 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 31 Oct 2016 01:58:40 -0400 Subject: [PATCH 09/11] fix whitespace --- docs/Plugins.rst | 4 ++-- plugins/ruby/ruby.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Plugins.rst b/docs/Plugins.rst index 13ea50661..85b6ba58d 100644 --- a/docs/Plugins.rst +++ b/docs/Plugins.rst @@ -883,8 +883,8 @@ and cleaning because these jobs also cannot be easily detected. Lever pulling is always assigned to everyone. Any dwarfs for which there are no jobs will be assigned hauling, lever pulling, and cleaning labors. If you use animal trainers, note that labormanager will misbehave if you -assign specific trainers to specific animals; results are only guaranteed -if you use "any trainer", and animal trainers will probably be +assign specific trainers to specific animals; results are only guaranteed +if you use "any trainer", and animal trainers will probably be overallocated in any case. Labormanager also sometimes assigns extra labors to currently busy diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index 7a21e32eb..0470541e1 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -308,7 +308,7 @@ VALUE (*rb_eval_string_protect)(const char*, int*); VALUE (*rb_ary_shift)(VALUE); VALUE (*rb_float_new)(double); double (*rb_num2dbl)(VALUE); -VALUE (*rb_int2inum)(intptr_t); // XXX check on win64 long vs intptr_t +VALUE (*rb_int2inum)(intptr_t); // XXX check on win64 long vs intptr_t VALUE (*rb_uint2inum)(uintptr_t); uintptr_t (*rb_num2ulong)(VALUE); // end of rip(ruby.h) From 45ff1a0353a36e66ecd581c15213337f82ed9fa1 Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 31 Oct 2016 02:05:46 -0400 Subject: [PATCH 10/11] Add architecture to package names --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cae58c8f..e4911928f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -410,7 +410,7 @@ IF(APPLE) ELSE() set(DFHACK_PACKAGE_PLATFORM_NAME ${CMAKE_SYSTEM_NAME}) ENDIF() -set(CPACK_PACKAGE_FILE_NAME "dfhack-${DFHACK_VERSION}-${DFHACK_PACKAGE_PLATFORM_NAME}${DFHACK_PACKAGE_SUFFIX}") +set(CPACK_PACKAGE_FILE_NAME "dfhack-${DFHACK_VERSION}-${DFHACK_PACKAGE_PLATFORM_NAME}-${DFHACK_BUILD_ARCH}${DFHACK_PACKAGE_SUFFIX}") INCLUDE(CPack) #INCLUDE(FindSphinx.cmake) From 4941c06654b74d0baedc9a0c61a23b325505dd8c Mon Sep 17 00:00:00 2001 From: lethosor Date: Mon, 31 Oct 2016 02:06:06 -0400 Subject: [PATCH 11/11] Only use TBZ2 generator on OS X --- CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4911928f..61b9dce12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,11 +396,7 @@ IF(UNIX) execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) string(STRIP ${GCC_VERSION} GCC_VERSION) SET(DFHACK_PACKAGE_SUFFIX "-gcc-${GCC_VERSION}") - if(APPLE) - SET(CPACK_GENERATOR "ZIP;TBZ2") - else() - SET(CPACK_GENERATOR "TBZ2") - endif() + SET(CPACK_GENERATOR "TBZ2") ELSEIF(WIN32) SET(CPACK_GENERATOR "ZIP") ENDIF()