summaryrefslogtreecommitdiff
path: root/plugins/jobutils.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-01-09 16:20:17 +0400
committerAlexander Gavrilov2012-01-09 16:20:17 +0400
commit50386f66a3651ec08086257aa37f3e8d532fcffa (patch)
tree6a7c700d1000ff652413f87cf2017b96b0efb502 /plugins/jobutils.cpp
parentea790f1346a3dff8df6331dc84a16a7915bca4fd (diff)
downloaddfhack-50386f66a3651ec08086257aa37f3e8d532fcffa.tar.gz
dfhack-50386f66a3651ec08086257aa37f3e8d532fcffa.tar.bz2
dfhack-50386f66a3651ec08086257aa37f3e8d532fcffa.tar.xz
Update structures and implement modifying the job_item item type.
Diffstat (limited to 'plugins/jobutils.cpp')
-rw-r--r--plugins/jobutils.cpp93
1 files changed, 71 insertions, 22 deletions
diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp
index a908b760..29d86230 100644
--- a/plugins/jobutils.cpp
+++ b/plugins/jobutils.cpp
@@ -5,6 +5,7 @@
#include <MiscUtils.h>
#include <modules/Materials.h>
+#include <modules/Items.h>
#include <modules/Gui.h>
#include <modules/Job.h>
@@ -60,12 +61,14 @@ DFhackCExport command_result plugin_init (Core *c, std::vector <PluginCommand> &
PluginCommand(
"job", "General job query and manipulation.",
job_cmd, false,
- " job query\n"
+ " job [query]\n"
" Print details of the current job.\n"
" job list\n"
" Print details of all jobs in the workshop.\n"
" job item-material <item-idx> <material[:subtoken]>\n"
" Replace the exact material id in the job item.\n"
+ " job item-type <item-idx> <type[:subtype]>\n"
+ " Replace the exact item type id in the job item.\n"
)
);
@@ -154,6 +157,13 @@ static command_result job_material_in_job(Core *c, MaterialInfo &new_mat)
i, item_mat.toString().c_str());
return CR_FAILURE;
}
+
+ if (!new_mat.matches(*item))
+ {
+ c->con.printerr("Job item %d requirements not satisfied by %s.\n",
+ i, new_mat.toString().c_str());
+ return CR_FAILURE;
+ }
}
// Apply the substitution
@@ -282,14 +292,25 @@ static command_result job_duplicate(Core * c, vector <string> & parameters)
/* Main job command implementation */
+static df::job_item *getJobItem(Core *c, df::job *job, std::string idx)
+{
+ if (!job)
+ return NULL;
+
+ int v = atoi(idx.c_str());
+ if (v < 1 || v > job->job_items.size()) {
+ c->con.printerr("Invalid item index.\n");
+ return NULL;
+ }
+
+ return job->job_items[v-1];
+}
+
static command_result job_cmd(Core * c, vector <string> & parameters)
{
CoreSuspender suspend(c);
- if (parameters.empty())
- return CR_WRONG_USAGE;
-
- std::string cmd = parameters[0];
+ std::string cmd = (parameters.empty() ? "query" : parameters[0]);
if (cmd == "query" || cmd == "list")
{
df::job *job = getSelectedWorkshopJob(c);
@@ -306,28 +327,23 @@ static command_result job_cmd(Core * c, vector <string> & parameters)
}
else if (cmd == "item-material")
{
- if (parameters.size() < 1+1+1)
+ if (parameters.size() != 3)
return CR_WRONG_USAGE;
df::job *job = getSelectedWorkshopJob(c);
- if (!job)
+ df::job_item *item = getJobItem(c, job, parameters[1]);
+ if (!item)
return CR_WRONG_USAGE;
- int v = atoi(parameters[1].c_str());
- if (v < 1 || v > job->job_items.size()) {
- c->con.printerr("Invalid item index.\n");
- return CR_WRONG_USAGE;
- }
+ ItemTypeInfo iinfo(item);
+ MaterialInfo minfo;
- df::job_item *item = job->job_items[v-1];
-
- MaterialInfo info;
- if (!info.find(parameters[2])) {
+ if (!minfo.find(parameters[2])) {
c->con.printerr("Could not find the specified material.\n");
return CR_FAILURE;
}
- if (!info.matches(*item)) {
+ if (!iinfo.matches(*item, &minfo)) {
c->con.printerr("Material does not match the requirements.\n");
printJobDetails(c, job);
return CR_FAILURE;
@@ -337,19 +353,52 @@ static command_result job_cmd(Core * c, vector <string> & parameters)
job->mat_type == item->mat_type &&
job->mat_index == item->mat_index)
{
- job->mat_type = info.type;
- job->mat_index = info.index;
+ job->mat_type = minfo.type;
+ job->mat_index = minfo.index;
}
- item->mat_type = info.type;
- item->mat_index = info.index;
+ item->mat_type = minfo.type;
+ item->mat_index = minfo.index;
+
+ c->con << "Job item updated." << endl;
+
+ if (item->item_type < 0 && minfo.isValid())
+ c->con.printerr("WARNING: Due to a probable bug, creature & plant material subtype\n"
+ " is ignored unless the item type is also specified.\n");
- c->con << "Job item " << v << " updated." << endl;
printJobDetails(c, job);
return CR_OK;
}
else if (cmd == "item-type")
{
+ if (parameters.size() != 3)
+ return CR_WRONG_USAGE;
+
+ df::job *job = getSelectedWorkshopJob(c);
+ df::job_item *item = getJobItem(c, job, parameters[1]);
+ if (!item)
+ return CR_WRONG_USAGE;
+
+ ItemTypeInfo iinfo;
+ MaterialInfo minfo(item);
+
+ if (!iinfo.find(parameters[2])) {
+ c->con.printerr("Could not find the specified item type.\n");
+ return CR_FAILURE;
+ }
+
+ if (!iinfo.matches(*item, &minfo)) {
+ c->con.printerr("Item type does not match the requirements.\n");
+ printJobDetails(c, job);
+ return CR_FAILURE;
+ }
+
+ item->item_type = iinfo.type;
+ item->item_subtype = iinfo.subtype;
+
+ c->con << "Job item updated." << endl;
+ printJobDetails(c, job);
+ return CR_OK;
}
else
return CR_WRONG_USAGE;