Added quality constraints to workflow plugin

develop
Valentin Ochs 2012-08-06 16:55:55 +02:00
parent 81ea0345ad
commit bb760bd376
1 changed files with 30 additions and 5 deletions

@ -20,6 +20,7 @@
#include "df/job_list_link.h" #include "df/job_list_link.h"
#include "df/dfhack_material_category.h" #include "df/dfhack_material_category.h"
#include "df/item.h" #include "df/item.h"
#include "df/item_quality.h"
#include "df/items_other_id.h" #include "df/items_other_id.h"
#include "df/tool_uses.h" #include "df/tool_uses.h"
#include "df/general_ref.h" #include "df/general_ref.h"
@ -42,6 +43,7 @@ using std::string;
using std::endl; using std::endl;
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
using namespace df::enums::item_quality;
using df::global::world; using df::global::world;
using df::global::ui; using df::global::ui;
@ -283,6 +285,8 @@ struct ItemConstraint {
int weight; int weight;
std::vector<ProtectedJob*> jobs; std::vector<ProtectedJob*> jobs;
enum item_quality min_quality;
int item_amount, item_count, item_inuse; int item_amount, item_count, item_inuse;
bool request_suspend, request_resume; bool request_suspend, request_resume;
@ -293,7 +297,7 @@ struct ItemConstraint {
public: public:
ItemConstraint() ItemConstraint()
: is_craft(false), weight(0), item_amount(0), item_count(0), item_inuse(0) : is_craft(false), weight(0), item_amount(0), item_count(0), item_inuse(0)
, is_active(false), cant_resume_reported(false) , is_active(false), cant_resume_reported(false), min_quality(Ordinary)
{} {}
int goalCount() { return config.ival(0); } int goalCount() { return config.ival(0); }
@ -646,7 +650,7 @@ static ItemConstraint *get_constraint(color_ostream &out, const std::string &str
std::vector<std::string> tokens; std::vector<std::string> tokens;
split_string(&tokens, str, "/"); split_string(&tokens, str, "/");
if (tokens.size() > 3) if (tokens.size() > 4)
return NULL; return NULL;
int weight = 0; int weight = 0;
@ -681,6 +685,22 @@ static ItemConstraint *get_constraint(color_ostream &out, const std::string &str
return NULL; return NULL;
} }
enum item_quality minqual = Ordinary;
std::string qualstr = vector_get(tokens, 3);
if(!qualstr.empty()) {
if(qualstr == "ordinary") minqual = Ordinary;
else if(qualstr == "wellcrafted") minqual = WellCrafted;
else if(qualstr == "finelycrafted") minqual = FinelyCrafted;
else if(qualstr == "superior") minqual = Superior;
else if(qualstr == "exceptional") minqual = Exceptional;
else if(qualstr == "masterful") minqual = Masterful;
else {
out.printerr("Cannot find quality: %s\nKnown qualities: ordinary, wellcrafted, finelycrafted, superior, exceptional, masterful\n", qualstr.c_str());
return NULL;
}
}
if (material.type >= 0) if (material.type >= 0)
weight += (material.index >= 0 ? 5000 : 1000); weight += (material.index >= 0 ? 5000 : 1000);
@ -694,7 +714,8 @@ static ItemConstraint *get_constraint(color_ostream &out, const std::string &str
ItemConstraint *ct = constraints[i]; ItemConstraint *ct = constraints[i];
if (ct->is_craft == is_craft && if (ct->is_craft == is_craft &&
ct->item == item && ct->material == material && ct->item == item && ct->material == material &&
ct->mat_mask.whole == mat_mask.whole) ct->mat_mask.whole == mat_mask.whole &&
ct->min_quality == minqual)
return ct; return ct;
} }
@ -703,6 +724,7 @@ static ItemConstraint *get_constraint(color_ostream &out, const std::string &str
nct->item = item; nct->item = item;
nct->material = material; nct->material = material;
nct->mat_mask = mat_mask; nct->mat_mask = mat_mask;
nct->min_quality = minqual;
nct->weight = weight; nct->weight = weight;
if (cfg) if (cfg)
@ -1179,6 +1201,9 @@ static void map_job_items(color_ostream &out)
(cv->item.subtype != -1 && cv->item.subtype != isubtype)) (cv->item.subtype != -1 && cv->item.subtype != isubtype))
continue; continue;
} }
if(item->getQuality() < cv->min_quality) {
continue;
}
TMaterialCache::iterator it = cv->material_cache.find(matkey); TMaterialCache::iterator it = cv->material_cache.find(matkey);