Use the announcement API to report starting and stopping workflow jobs.

develop
Alexander Gavrilov 2012-01-15 15:39:20 +04:00
parent 0f56611edc
commit bcb51d8ff7
3 changed files with 96 additions and 21 deletions

@ -71,6 +71,7 @@ namespace DFHack
return ptr ? decode(ptr->item_type, ptr->item_subtype) : decode(df::enums::item_type::NONE);
}
std::string getToken();
std::string toString();
bool find(const std::string &token);

@ -68,20 +68,20 @@ using namespace DFHack;
using namespace df::enums;
#define ITEMDEF_VECTORS \
ITEM(WEAPON, weapons) \
ITEM(TRAPCOMP, trapcomps) \
ITEM(TOY, toys) \
ITEM(TOOL, tools) \
ITEM(INSTRUMENT, instruments) \
ITEM(ARMOR, armor) \
ITEM(AMMO, ammo) \
ITEM(SIEGEAMMO, siege_ammo) \
ITEM(GLOVES, gloves) \
ITEM(SHOES, shoes) \
ITEM(SHIELD, shields) \
ITEM(HELM, helms) \
ITEM(PANTS, pants) \
ITEM(FOOD, food)
ITEM(WEAPON, weapons, itemdef_weaponst) \
ITEM(TRAPCOMP, trapcomps, itemdef_trapcompst) \
ITEM(TOY, toys, itemdef_toyst) \
ITEM(TOOL, tools, itemdef_toolst) \
ITEM(INSTRUMENT, instruments, itemdef_instrumentst) \
ITEM(ARMOR, armor, itemdef_armorst) \
ITEM(AMMO, ammo, itemdef_ammost) \
ITEM(SIEGEAMMO, siege_ammo, itemdef_siegeammost) \
ITEM(GLOVES, gloves, itemdef_glovesst) \
ITEM(SHOES, shoes, itemdef_shoesst) \
ITEM(SHIELD, shields, itemdef_shieldst) \
ITEM(HELM, helms, itemdef_helmst) \
ITEM(PANTS, pants, itemdef_pantsst) \
ITEM(FOOD, food, itemdef_foodst)
bool ItemTypeInfo::decode(df::item_type type_, int16_t subtype_)
{
@ -97,7 +97,7 @@ bool ItemTypeInfo::decode(df::item_type type_, int16_t subtype_)
case NONE:
return false;
#define ITEM(type,vec) \
#define ITEM(type,vec,tclass) \
case type: \
custom = vector_get(defs.vec, subtype); \
break;
@ -119,7 +119,7 @@ bool ItemTypeInfo::decode(df::item *ptr)
return decode(ptr->getType(), ptr->getSubtype());
}
std::string ItemTypeInfo::toString()
std::string ItemTypeInfo::getToken()
{
std::string rv = ENUM_KEY_STR(item_type, type);
if (custom)
@ -129,6 +129,25 @@ std::string ItemTypeInfo::toString()
return rv;
}
std::string ItemTypeInfo::toString()
{
using namespace df::enums::item_type;
switch (type) {
#define ITEM(type,vec,tclass) \
case type: \
if (VIRTUAL_CAST_VAR(cv, df::tclass, custom)) \
return cv->name;
ITEMDEF_VECTORS
#undef ITEM
default:
break;
}
return toLower(ENUM_KEY_STR(item_type, type));
}
bool ItemTypeInfo::find(const std::string &token)
{
using namespace df::enums::item_type;
@ -164,7 +183,7 @@ bool ItemTypeInfo::find(const std::string &token)
df::world_raws::T_itemdefs &defs = df::global::world->raws.itemdefs;
switch (type) {
#define ITEM(type,vec) \
#define ITEM(type,vec,tclass) \
case type: \
for (int i = 0; i < defs.vec.size(); i++) { \
if (defs.vec[i]->id == items[1]) { \

@ -282,10 +282,15 @@ struct ItemConstraint {
int item_amount, item_count, item_inuse;
bool request_suspend, request_resume;
bool is_active, cant_resume_reported;
TMaterialCache material_cache;
public:
ItemConstraint() : weight(0), item_amount(0), item_count(0), item_inuse(0) {}
ItemConstraint()
: weight(0), item_amount(0), item_count(0), item_inuse(0)
, is_active(false), cant_resume_reported(false)
{}
int goalCount() { return config.ival(0); }
void setGoalCount(int v) { config.ival(0) = v; }
@ -341,6 +346,7 @@ static std::vector<ProtectedJob*> pending_recover;
static std::vector<ItemConstraint*> constraints;
static int meltable_count = 0;
static bool melt_active = false;
/******************************
* MISC FUNCTIONS *
@ -745,6 +751,9 @@ static void link_job_constraint(ProtectedJob *pj, df::item_type itype, int16_t i
ct->jobs.push_back(pj);
pj->constraints.push_back(ct);
if (!ct->is_active && pj->isResumed())
ct->is_active = true;
}
}
@ -934,17 +943,27 @@ static void compute_job_outputs(Core *c, ProtectedJob *pj)
static void map_job_constraints(Core *c)
{
melt_active = false;
for (unsigned i = 0; i < constraints.size(); i++)
{
constraints[i]->jobs.clear();
constraints[i]->is_active = false;
}
for (TKnownJobs::const_iterator it = known_jobs.begin(); it != known_jobs.end(); ++it)
{
it->second->constraints.clear();
ProtectedJob *pj = it->second;
pj->constraints.clear();
if (!it->second->isLive())
if (!pj->isLive())
continue;
compute_job_outputs(c, it->second);
if (!melt_active && pj->actual_job->job_type == job_type::MeltMetalObject)
melt_active = pj->isResumed();
compute_job_outputs(c, pj);
}
}
@ -1158,6 +1177,42 @@ static void update_jobs_by_constraints(Core *c)
setJobResumed(c, pj, goal);
}
for (unsigned i = 0; i < constraints.size(); i++)
{
ItemConstraint *ct = constraints[i];
bool is_running = false;
for (unsigned j = 0; j < ct->jobs.size(); j++)
if (!!(is_running = ct->jobs[j]->isResumed()))
break;
std::string info = ct->item.toString();
if (ct->material.isValid())
info = ct->material.toString() + " " + info;
else if (ct->mat_mask.whole)
info = bitfieldToString(ct->mat_mask) + " " + info;
if (is_running != ct->is_active)
{
if (is_running && ct->request_resume)
showAnnouncement("Resuming production: " + info, 2, false);
else if (!is_running && !ct->request_resume)
showAnnouncement("Stopping production: " + info, 3, false);
}
if (ct->request_resume && !is_running)
{
if (!ct->cant_resume_reported)
showAnnouncement("Cannot produce: " + info, 6, true);
ct->cant_resume_reported = true;
}
else
{
ct->cant_resume_reported = false;
}
}
}
static void process_constraints(Core *c)