Add lua API functions for verifying item and material vs job_item flags.

develop
Alexander Gavrilov 2012-10-17 19:16:18 +04:00
parent 4f7895f571
commit 2d4935bc17
6 changed files with 46 additions and 2 deletions

@ -863,6 +863,15 @@ Job module
if there are any jobs with ``first_id <= id < job_next_id``, if there are any jobs with ``first_id <= id < job_next_id``,
a lua list containing them. 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 Units module
------------ ------------

@ -2,6 +2,7 @@ DFHack future
Internals: Internals:
- support for displaying active keybindings properly. - support for displaying active keybindings properly.
- support for reusable widgets in lua screen library.
Notable bugfixes: Notable bugfixes:
- autobutcher can be re-enabled again after being stopped. - autobutcher can be re-enabled again after being stopped.
- stopped Dwarf Manipulator from unmasking vampires. - stopped Dwarf Manipulator from unmasking vampires.
@ -9,6 +10,8 @@ DFHack future
- fastdwarf: new mode using debug flags, and some internal consistency fixes. - fastdwarf: new mode using debug flags, and some internal consistency fixes.
- added a small stand-alone utility for applying and removing binary patches. - added a small stand-alone utility for applying and removing binary patches.
- removebadthoughts: add --dry-run option - removebadthoughts: add --dry-run option
New GUI scripts:
- gui/guide-path: displays the cached path for minecart Guide orders.
DFHack v0.34.11-r2 DFHack v0.34.11-r2

@ -809,6 +809,8 @@ static const LuaWrapper::FunctionReg dfhack_job_module[] = {
WRAPM(Job,getWorker), WRAPM(Job,getWorker),
WRAPM(Job,checkBuildingsNow), WRAPM(Job,checkBuildingsNow),
WRAPM(Job,checkDesignationsNow), WRAPM(Job,checkDesignationsNow),
WRAPM(Job,isSuitableItem),
WRAPM(Job,isSuitableMaterial),
WRAPN(is_equal, jobEqual), WRAPN(is_equal, jobEqual),
WRAPN(is_item_equal, jobItemEqual), WRAPN(is_item_equal, jobItemEqual),
{ NULL, NULL } { NULL, NULL }

@ -32,6 +32,7 @@ distribution.
#include "DataDefs.h" #include "DataDefs.h"
#include "df/job_item_ref.h" #include "df/job_item_ref.h"
#include "df/item_type.h"
namespace df namespace df
{ {
@ -69,6 +70,9 @@ namespace DFHack
DFHACK_EXPORT bool attachJobItem(df::job *job, df::item *item, DFHACK_EXPORT bool attachJobItem(df::job *job, df::item *item,
df::job_item_ref::T_role role, df::job_item_ref::T_role role,
int filter_idx = -1, int insert_idx = -1); 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); DFHACK_EXPORT bool operator== (const df::job_item &a, const df::job_item &b);

@ -361,3 +361,29 @@ bool DFHack::Job::attachJobItem(df::job *job, df::item *item,
return true; 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);
}

@ -143,8 +143,8 @@ function GuidePathUI:onRenderBody(dc)
end end
dc:newline():newline(1) dc:newline():newline(1)
dc:key('CUSTOM_Z'):string(": Reset path, ",COLOR_GREY,nil,path_ok~=nil) 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_P'):string(": Find path",COLOR_GREY,nil,false)
dc:newline(1) dc:newline(1)
dc:key('CUSTOM_C'):string(": Zoom cur, ") dc:key('CUSTOM_C'):string(": Zoom cur, ")
dc:key('CUSTOM_N'):string(": Zoom next") dc:key('CUSTOM_N'):string(": Zoom next")