From 2d4935bc17039c63d9ffc229578f3d397ffc8b80 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Wed, 17 Oct 2012 19:16:18 +0400 Subject: [PATCH] Add lua API functions for verifying item and material vs job_item flags. --- Lua API.rst | 9 +++++++++ NEWS | 3 +++ library/LuaApi.cpp | 2 ++ library/include/modules/Job.h | 4 ++++ library/modules/Job.cpp | 26 ++++++++++++++++++++++++++ scripts/gui/guide-path.lua | 4 ++-- 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Lua API.rst b/Lua API.rst index bbee8646c..4d689ee2b 100644 --- a/Lua API.rst +++ b/Lua API.rst @@ -863,6 +863,15 @@ Job module if there are any jobs with ``first_id <= id < job_next_id``, a lua list containing them. +* ``dfhack.job.isSuitableItem(job_item, item_type, item_subtype)`` + + Does basic sanity checks to verify if the suggested item type matches + the flags in the job item. + +* ``dfhack.job.isSuitableMaterial(job_item, mat_type, mat_index)`` + + Likewise, if replacing material. + Units module ------------ diff --git a/NEWS b/NEWS index 40e9315c5..61e8a5b3e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ DFHack future Internals: - support for displaying active keybindings properly. + - support for reusable widgets in lua screen library. Notable bugfixes: - autobutcher can be re-enabled again after being stopped. - stopped Dwarf Manipulator from unmasking vampires. @@ -9,6 +10,8 @@ DFHack future - fastdwarf: new mode using debug flags, and some internal consistency fixes. - added a small stand-alone utility for applying and removing binary patches. - removebadthoughts: add --dry-run option + New GUI scripts: + - gui/guide-path: displays the cached path for minecart Guide orders. DFHack v0.34.11-r2 diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index ef571bcb7..9f380c353 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -809,6 +809,8 @@ static const LuaWrapper::FunctionReg dfhack_job_module[] = { WRAPM(Job,getWorker), WRAPM(Job,checkBuildingsNow), WRAPM(Job,checkDesignationsNow), + WRAPM(Job,isSuitableItem), + WRAPM(Job,isSuitableMaterial), WRAPN(is_equal, jobEqual), WRAPN(is_item_equal, jobItemEqual), { NULL, NULL } diff --git a/library/include/modules/Job.h b/library/include/modules/Job.h index 490d79a34..853813073 100644 --- a/library/include/modules/Job.h +++ b/library/include/modules/Job.h @@ -32,6 +32,7 @@ distribution. #include "DataDefs.h" #include "df/job_item_ref.h" +#include "df/item_type.h" namespace df { @@ -69,6 +70,9 @@ namespace DFHack DFHACK_EXPORT bool attachJobItem(df::job *job, df::item *item, df::job_item_ref::T_role role, int filter_idx = -1, int insert_idx = -1); + + DFHACK_EXPORT bool isSuitableItem(df::job_item *item, df::item_type itype, int isubtype); + DFHACK_EXPORT bool isSuitableMaterial(df::job_item *item, int mat_type, int mat_index); } DFHACK_EXPORT bool operator== (const df::job_item &a, const df::job_item &b); diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index df2009d0a..def3b4192 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -361,3 +361,29 @@ bool DFHack::Job::attachJobItem(df::job *job, df::item *item, return true; } + +bool Job::isSuitableItem(df::job_item *item, df::item_type itype, int isubtype) +{ + CHECK_NULL_POINTER(item); + + if (itype == item_type::NONE) + return true; + + ItemTypeInfo iinfo(itype, isubtype); + MaterialInfo minfo(item); + + return iinfo.isValid() && iinfo.matches(*item, &minfo); +} + +bool Job::isSuitableMaterial(df::job_item *item, int mat_type, int mat_index) +{ + CHECK_NULL_POINTER(item); + + if (mat_type == -1 && mat_index == -1) + return true; + + ItemTypeInfo iinfo(item); + MaterialInfo minfo(mat_type, mat_index); + + return minfo.isValid() && iinfo.matches(*item, &minfo); +} diff --git a/scripts/gui/guide-path.lua b/scripts/gui/guide-path.lua index 1546150b7..a807e032d 100644 --- a/scripts/gui/guide-path.lua +++ b/scripts/gui/guide-path.lua @@ -143,8 +143,8 @@ function GuidePathUI:onRenderBody(dc) end dc:newline():newline(1) - dc:key('CUSTOM_Z'):string(": Reset path, ",COLOR_GREY,nil,path_ok~=nil) - dc:key('CUSTOM_P'):string(": Find path",COLOR_GREY,nil,false) + dc:key('CUSTOM_Z'):string(": Reset path",COLOR_GREY,nil,path_ok~=nil) + --dc:key('CUSTOM_P'):string(": Find path",COLOR_GREY,nil,false) dc:newline(1) dc:key('CUSTOM_C'):string(": Zoom cur, ") dc:key('CUSTOM_N'):string(": Zoom next")