Update data definitions.

develop
Alexander Gavrilov 2012-01-04 18:46:39 +04:00
parent 1d1cd63800
commit 99dda069de
4 changed files with 52 additions and 26 deletions

@ -47,6 +47,7 @@ namespace df
struct plant_raw; struct plant_raw;
struct creature_raw; struct creature_raw;
struct historical_figure; struct historical_figure;
struct material_vec_ref;
union job_material_category; union job_material_category;
} }
@ -82,12 +83,18 @@ namespace DFHack
public: public:
MaterialInfo(int16_t type = -1, int32_t index = -1) { decode(type, index); } MaterialInfo(int16_t type = -1, int32_t index = -1) { decode(type, index); }
MaterialInfo(df::item *item) { decode(item); } template<class T> MaterialInfo(T *ptr) { decode(ptr); }
bool isValid() const { return material != NULL; } bool isValid() const { return material != NULL; }
bool decode(int16_t type, int32_t index = -1); bool decode(int16_t type, int32_t index = -1);
bool decode(df::item *item); bool decode(df::item *item);
bool decode(const df::material_vec_ref &vr, int idx);
template<class T> bool decode(T *ptr) {
// Assume and exploit a certain naming convention
return ptr ? decode(ptr->mat_type, ptr->mat_index) : decode(-1);
}
bool find(const std::string &token, const std::string &subtoken = std::string()); bool find(const std::string &token, const std::string &subtoken = std::string());
bool findBuiltin(const std::string &token); bool findBuiltin(const std::string &token);

@ -51,6 +51,7 @@ using namespace std;
#include "df/job_material_category.h" #include "df/job_material_category.h"
#include "df/matter_state.h" #include "df/matter_state.h"
#include "df/material_vec_ref.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
@ -58,9 +59,17 @@ using namespace df::enums;
bool MaterialInfo::decode(df::item *item) bool MaterialInfo::decode(df::item *item)
{ {
if (!item) if (!item)
decode(-1); return decode(-1);
else
return decode(item->getActualMaterial(), item->getActualMaterialIndex());
}
bool MaterialInfo::decode(const df::material_vec_ref &vr, int idx)
{
if (idx < 0 || idx >= vr.mat_type.size() || idx >= vr.mat_index.size())
return decode(-1);
else else
decode(item->getActualMaterial(), item->getActualMaterialIndex()); return decode(vr.mat_type[idx], vr.mat_index[idx]);
} }
bool MaterialInfo::decode(int16_t type, int32_t index) bool MaterialInfo::decode(int16_t type, int32_t index)

@ -1 +1 @@
Subproject commit 3455acedc525473cd8c5403d225a6078b661dfc8 Subproject commit 4857a4f5af1a4174e5478f1221552826a60b36c5

@ -18,6 +18,7 @@
#include <df/job.h> #include <df/job.h>
#include <df/job_item.h> #include <df/job_item.h>
#include <df/item.h> #include <df/item.h>
#include <df/tool_uses.h>
using std::vector; using std::vector;
using std::string; using std::string;
@ -102,7 +103,7 @@ static bool workshop_job_hotkey(Core *c, df::viewscreen *top)
// No jobs? // No jobs?
if (selected->jobs.empty() || if (selected->jobs.empty() ||
selected->jobs[0]->job_id == job_type::DestroyBuilding) selected->jobs[0]->job_type == job_type::DestroyBuilding)
return false; return false;
// Add job gui activated? // Add job gui activated?
@ -169,7 +170,7 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat)
if (!job) if (!job)
return CR_FAILURE; return CR_FAILURE;
MaterialInfo cur_mat(job->matType, job->matIndex); MaterialInfo cur_mat(job);
if (!cur_mat.isValid() || cur_mat.type != 0) if (!cur_mat.isValid() || cur_mat.type != 0)
{ {
@ -195,7 +196,7 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat)
for (unsigned i = 0; i < job->job_items.size(); i++) for (unsigned i = 0; i < job->job_items.size(); i++)
{ {
df::job_item *item = job->job_items[i]; df::job_item *item = job->job_items[i];
MaterialInfo item_mat(item->matType, item->matIndex); MaterialInfo item_mat(item);
if (item_mat != cur_mat) if (item_mat != cur_mat)
{ {
@ -206,18 +207,18 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat)
} }
// Apply the substitution // Apply the substitution
job->matType = new_mat.type; job->mat_type = new_mat.type;
job->matIndex = new_mat.index; job->mat_index = new_mat.index;
for (unsigned i = 0; i < job->job_items.size(); i++) for (unsigned i = 0; i < job->job_items.size(); i++)
{ {
df::job_item *item = job->job_items[i]; df::job_item *item = job->job_items[i];
item->matType = new_mat.type; item->mat_type = new_mat.type;
item->matIndex = new_mat.index; item->mat_index = new_mat.index;
} }
c->con << "Applied material '" << new_mat.toString() c->con << "Applied material '" << new_mat.toString()
<< "' to job " << ENUM_KEY_STR(job_type,job->job_id) << endl; << "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl;
return CR_OK; return CR_OK;
} }
@ -226,8 +227,8 @@ static bool build_choice_matches(df::ui_build_item_req *req, df::build_req_choic
{ {
if (VIRTUAL_CAST_VAR(gen, df::build_req_choice_genst, choice)) if (VIRTUAL_CAST_VAR(gen, df::build_req_choice_genst, choice))
{ {
if (gen->matType == new_mat.type && if (gen->mat_type == new_mat.type &&
gen->matIndex == new_mat.index && gen->mat_index == new_mat.index &&
gen->used_count < gen->candidates.size()) gen->used_count < gen->candidates.size())
{ {
return true; return true;
@ -289,14 +290,22 @@ static command_result job_material(Core * c, vector <string> & parameters)
static void print_job_item_details(Core *c, df::job *job, df::job_item *item) static void print_job_item_details(Core *c, df::job *job, df::job_item *item)
{ {
c->con << " Input Item: " << ENUM_KEY_STR(item_type,item->itemType); c->con << " Input Item: " << ENUM_KEY_STR(item_type,item->item_type);
if (item->itemSubtype != -1) if (item->item_subtype != -1)
c->con << " [" << item->itemSubtype << "]"; c->con << " [" << item->item_subtype << "]";
c->con << "; count=" << item->count << endl; if (item->quantity != 1)
c->con << "; quantity=" << item->quantity;
if (item->min_dimension >= 0)
c->con << "; min_dimension=" << item->min_dimension;
c->con << endl;
MaterialInfo mat(item->matType, item->matIndex); MaterialInfo mat(item);
if (mat.isValid()) if (mat.isValid() || item->metal_ore >= 0) {
c->con << " material: " << mat.toString() << endl; c->con << " material: " << mat.toString();
if (item->metal_ore >= 0)
c->con << "; ore of " << MaterialInfo(0,item->metal_ore).toString();
c->con << endl;
}
if (item->flags1.whole) if (item->flags1.whole)
c->con << " flags1: " << bitfieldToString(item->flags1) << endl; c->con << " flags1: " << bitfieldToString(item->flags1) << endl;
@ -309,15 +318,16 @@ static void print_job_item_details(Core *c, df::job *job, df::job_item *item)
c->con << " reaction class: " << item->reaction_class << endl; c->con << " reaction class: " << item->reaction_class << endl;
if (!item->has_material_reaction_product.empty()) if (!item->has_material_reaction_product.empty())
c->con << " reaction product: " << item->has_material_reaction_product << endl; c->con << " reaction product: " << item->has_material_reaction_product << endl;
if (item->has_tool_use >= 0)
c->con << " tool use: " << ENUM_KEY_STR(tool_uses, item->has_tool_use) << endl;
} }
static void print_job_details(Core *c, df::job *job) static void print_job_details(Core *c, df::job *job)
{ {
c->con << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_id) c->con << "Job " << job->id << ": " << ENUM_KEY_STR(job_type,job->job_type)
<< " [" << job->x << "," << job->y << "," << job->z << "] (" << " (" << bitfieldToString(job->flags) << ")" << endl;
<< bitfieldToString(job->flags) << ")" << endl;
MaterialInfo mat(job->matType, job->matIndex); MaterialInfo mat(job);
if (mat.isValid() || job->material_category.whole) if (mat.isValid() || job->material_category.whole)
{ {
c->con << " material: " << mat.toString(); c->con << " material: " << mat.toString();