Check the item type against job_item_vector_id when matching to jobs.

This will prevent setting an invalid item type via the job command.
develop
Alexander Gavrilov 2012-10-20 21:01:22 +04:00
parent 795961bfc4
commit 0c9f1e0af4
2 changed files with 28 additions and 2 deletions

@ -40,6 +40,7 @@ distribution.
#include "df/building_actual.h"
#include "df/body_part_raw.h"
#include "df/unit_inventory_item.h"
#include "df/job_item_vector_id.h"
namespace df
{
@ -86,7 +87,8 @@ namespace DFHack
bool find(const std::string &token);
bool matches(const df::job_item &item, MaterialInfo *mat = NULL);
bool matches(df::job_item_vector_id vec_id);
bool matches(const df::job_item &item, MaterialInfo *mat = NULL, bool skip_vector = false);
};
inline bool operator== (const ItemTypeInfo &a, const ItemTypeInfo &b) {

@ -245,7 +245,28 @@ bool Items::isCasteMaterial(df::item_type itype)
return ENUM_ATTR(item_type, is_caste_mat, itype);
}
bool ItemTypeInfo::matches(const df::job_item &item, MaterialInfo *mat)
bool ItemTypeInfo::matches(df::job_item_vector_id vec_id)
{
auto other_id = ENUM_ATTR(job_item_vector_id, other, vec_id);
auto explicit_item = ENUM_ATTR(items_other_id, item, other_id);
if (explicit_item != item_type::NONE && type != explicit_item)
return false;
auto generic_item = ENUM_ATTR(items_other_id, generic_item, other_id);
if (generic_item.size > 0)
{
for (size_t i = 0; i < generic_item.size; i++)
if (generic_item.items[i] == type)
return true;
return false;
}
return true;
}
bool ItemTypeInfo::matches(const df::job_item &item, MaterialInfo *mat, bool skip_vector)
{
using namespace df::enums::item_type;
@ -255,6 +276,9 @@ bool ItemTypeInfo::matches(const df::job_item &item, MaterialInfo *mat)
if (Items::isCasteMaterial(type) && mat && !mat->isNone())
return false;
if (!skip_vector && !matches(item.vector_id))
return false;
df::job_item_flags1 ok1, mask1, item_ok1, item_mask1;
df::job_item_flags2 ok2, mask2, item_ok2, item_mask2, xmask2;
df::job_item_flags3 ok3, mask3, item_ok3, item_mask3;