|
|
|
@ -58,13 +58,10 @@ REQUIRE_GLOBAL(job_next_id);
|
|
|
|
|
/* Plugin registration */
|
|
|
|
|
|
|
|
|
|
static command_result workflow_cmd(color_ostream &out, vector <string> & parameters);
|
|
|
|
|
static command_result fix_job_postings_cmd(color_ostream &out, vector<string> ¶meters);
|
|
|
|
|
|
|
|
|
|
static void init_state(color_ostream &out);
|
|
|
|
|
static void cleanup_state(color_ostream &out);
|
|
|
|
|
|
|
|
|
|
static int fix_job_postings(color_ostream *out = NULL, bool dry_run = false);
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
|
{
|
|
|
|
|
if (!world || !ui)
|
|
|
|
@ -76,10 +73,6 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector <Plugi
|
|
|
|
|
"workflow",
|
|
|
|
|
"Manage repeat jobs according to stock levels.",
|
|
|
|
|
workflow_cmd));
|
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
|
"fix-job-postings",
|
|
|
|
|
"Fix broken job postings caused by very old versions of workflow.",
|
|
|
|
|
fix_job_postings_cmd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_state(out);
|
|
|
|
@ -111,14 +104,6 @@ DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_chan
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command_result fix_job_postings_cmd(color_ostream &out, vector<string> ¶meters)
|
|
|
|
|
{
|
|
|
|
|
bool dry = parameters.size();
|
|
|
|
|
int fixed = fix_job_postings(&out, dry);
|
|
|
|
|
out << fixed << " job issue(s) " << (dry ? "detected but not fixed" : "fixed") << endl;
|
|
|
|
|
return CR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************
|
|
|
|
|
* JOB STATE TRACKING STRUCTS *
|
|
|
|
|
******************************/
|
|
|
|
@ -354,34 +339,6 @@ public:
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int fix_job_postings (color_ostream *out, bool dry_run)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
df::job_list_link *link = &world->jobs.list;
|
|
|
|
|
while (link)
|
|
|
|
|
{
|
|
|
|
|
df::job *job = link->item;
|
|
|
|
|
if (job)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < world->jobs.postings.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
df::job_handler::T_postings *posting = world->jobs.postings[i];
|
|
|
|
|
if (posting->job == job && i != size_t(job->posting_index) && !posting->flags.bits.dead)
|
|
|
|
|
{
|
|
|
|
|
++count;
|
|
|
|
|
if (out)
|
|
|
|
|
*out << "Found extra job posting: Job " << job->id << ": "
|
|
|
|
|
<< Job::getName(job) << endl;
|
|
|
|
|
if (!dry_run)
|
|
|
|
|
posting->flags.bits.dead = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
link = link->next;
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************
|
|
|
|
|
* GLOBAL VARIABLES *
|
|
|
|
|
******************************/
|
|
|
|
@ -478,11 +435,6 @@ static ItemConstraint *get_constraint(color_ostream &out, const std::string &str
|
|
|
|
|
|
|
|
|
|
static void start_protect(color_ostream &out)
|
|
|
|
|
{
|
|
|
|
|
out << "workflow: checking for existing job issues" << endl;
|
|
|
|
|
int count = fix_job_postings(&out);
|
|
|
|
|
if (count)
|
|
|
|
|
out << "workflow: fixed " << count << " job issues" << endl;
|
|
|
|
|
|
|
|
|
|
check_lost_jobs(out, 0);
|
|
|
|
|
|
|
|
|
|
if (!known_jobs.empty())
|
|
|
|
@ -1569,13 +1521,6 @@ static int getCountHistory(lua_State *L)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int fixJobPostings(lua_State *L)
|
|
|
|
|
{
|
|
|
|
|
bool dry = lua_toboolean(L, 1);
|
|
|
|
|
lua_pushinteger(L, fix_job_postings(NULL, dry));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN_LUA_FUNCTIONS {
|
|
|
|
|
DFHACK_LUA_FUNCTION(deleteConstraint),
|
|
|
|
|
DFHACK_LUA_END
|
|
|
|
@ -1586,7 +1531,6 @@ DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
|
DFHACK_LUA_COMMAND(findConstraint),
|
|
|
|
|
DFHACK_LUA_COMMAND(setConstraint),
|
|
|
|
|
DFHACK_LUA_COMMAND(getCountHistory),
|
|
|
|
|
DFHACK_LUA_COMMAND(fixJobPostings),
|
|
|
|
|
DFHACK_LUA_END
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|