2012-01-02 07:46:24 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "MiscUtils.h"
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/Items.h"
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "modules/Job.h"
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "df/world.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/ui_build_selector.h"
|
|
|
|
#include "df/ui_build_item_req.h"
|
|
|
|
#include "df/build_req_choice_genst.h"
|
|
|
|
#include "df/build_req_choice_specst.h"
|
|
|
|
#include "df/building_workshopst.h"
|
|
|
|
#include "df/building_furnacest.h"
|
|
|
|
#include "df/job.h"
|
|
|
|
#include "df/job_item.h"
|
|
|
|
#include "df/job_list_link.h"
|
|
|
|
#include "df/item.h"
|
|
|
|
#include "df/tool_uses.h"
|
|
|
|
#include "df/general_ref.h"
|
2012-01-02 07:46:24 -07:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::endl;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
|
|
|
|
using df::global::world;
|
|
|
|
using df::global::ui;
|
|
|
|
using df::global::ui_build_selector;
|
|
|
|
using df::global::ui_workshop_job_cursor;
|
2012-01-04 08:39:38 -07:00
|
|
|
using df::global::job_next_id;
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-01-04 08:39:38 -07:00
|
|
|
/* Plugin registration */
|
2012-01-03 11:56:05 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static bool job_material_hotkey(df::viewscreen *top);
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_material(color_ostream &out, vector <string> & parameters);
|
|
|
|
static command_result job_duplicate(color_ostream &out, vector <string> & parameters);
|
|
|
|
static command_result job_cmd(color_ostream &out, vector <string> & parameters);
|
2012-01-03 11:56:05 -07:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
DFHACK_PLUGIN("jobutils");
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-03 11:56:05 -07:00
|
|
|
if (!world || !ui)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
|
|
|
"job", "General job query and manipulation.",
|
|
|
|
job_cmd, false,
|
2012-01-09 05:20:17 -07:00
|
|
|
" job [query]\n"
|
2012-01-28 04:00:24 -07:00
|
|
|
" Print details of the current job. The job can be\n"
|
|
|
|
" selected in a workshop, or the unit/jobs screen.\n"
|
2012-01-05 11:04:05 -07:00
|
|
|
" job list\n"
|
2012-01-28 04:00:24 -07:00
|
|
|
" Print details of all jobs in the selected workshop.\n"
|
2012-01-08 09:02:12 -07:00
|
|
|
" job item-material <item-idx> <material[:subtoken]>\n"
|
2012-01-05 11:04:05 -07:00
|
|
|
" Replace the exact material id in the job item.\n"
|
2012-01-09 05:20:17 -07:00
|
|
|
" job item-type <item-idx> <type[:subtype]>\n"
|
|
|
|
" Replace the exact item type id in the job item.\n"
|
2012-01-03 11:56:05 -07:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ui_workshop_job_cursor || ui_build_selector) {
|
2012-01-02 07:46:24 -07:00
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
|
|
|
"job-material", "Alter the material of the selected job.",
|
|
|
|
job_material, job_material_hotkey,
|
|
|
|
" job-material <inorganic-token>\n"
|
|
|
|
"Intended to be used as a keybinding:\n"
|
|
|
|
" - In 'q' mode, when a job is highlighted within a workshop\n"
|
2012-01-28 04:00:24 -07:00
|
|
|
" or furnace, changes the material of the job. Only inorganic\n"
|
|
|
|
" materials can be used in this mode.\n"
|
2012-01-02 07:46:24 -07:00
|
|
|
" - In 'b' mode, during selection of building components\n"
|
|
|
|
" positions the cursor over the first available choice\n"
|
|
|
|
" with the matching material.\n"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2012-01-03 11:56:05 -07:00
|
|
|
|
2012-01-04 08:39:38 -07:00
|
|
|
if (ui_workshop_job_cursor && job_next_id) {
|
|
|
|
commands.push_back(
|
|
|
|
PluginCommand(
|
|
|
|
"job-duplicate", "Duplicate the selected job in a workshop.",
|
2012-03-03 06:38:24 -07:00
|
|
|
job_duplicate, Gui::workshop_job_hotkey,
|
2012-01-04 08:39:38 -07:00
|
|
|
" - In 'q' mode, when a job is highlighted within a workshop\n"
|
|
|
|
" or furnace building, instantly duplicates the job.\n"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-04 08:39:38 -07:00
|
|
|
/* UI state guards */
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static bool job_material_hotkey(df::viewscreen *top)
|
2012-01-03 11:56:05 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
return Gui::workshop_job_hotkey(top) ||
|
|
|
|
Gui::build_selector_hotkey(top);
|
2012-01-03 11:56:05 -07:00
|
|
|
}
|
|
|
|
|
2012-01-04 08:39:38 -07:00
|
|
|
/* job-material implementation */
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_material_in_job(color_ostream &out, MaterialInfo &new_mat)
|
2012-01-03 11:56:05 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *job = Gui::getSelectedWorkshopJob(out);
|
2012-01-03 11:56:05 -07:00
|
|
|
if (!job)
|
|
|
|
return CR_FAILURE;
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2012-01-15 01:50:53 -07:00
|
|
|
if (!new_mat.isValid() || new_mat.type != 0)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("New job material isn't inorganic: %s\n",
|
|
|
|
new_mat.toString().c_str());
|
2012-01-15 01:50:53 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-04 07:46:39 -07:00
|
|
|
MaterialInfo cur_mat(job);
|
2012-01-02 07:46:24 -07:00
|
|
|
|
|
|
|
if (!cur_mat.isValid() || cur_mat.type != 0)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Current job material isn't inorganic: %s\n",
|
|
|
|
cur_mat.toString().c_str());
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
df::craft_material_class old_class = cur_mat.getCraftClass();
|
|
|
|
if (old_class == craft_material_class::None)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Unexpected current material type: %s\n",
|
|
|
|
cur_mat.toString().c_str());
|
2012-01-03 08:25:55 -07:00
|
|
|
return CR_FAILURE;
|
2012-01-02 07:46:24 -07:00
|
|
|
}
|
2012-01-03 08:25:55 -07:00
|
|
|
if (new_mat.getCraftClass() != old_class)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("New material %s does not satisfy requirement: %s\n",
|
2012-03-17 02:52:22 -06:00
|
|
|
new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class).c_str());
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < job->job_items.size(); i++)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
|
|
|
df::job_item *item = job->job_items[i];
|
2012-01-04 07:46:39 -07:00
|
|
|
MaterialInfo item_mat(item);
|
2012-01-02 07:46:24 -07:00
|
|
|
|
|
|
|
if (item_mat != cur_mat)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Job item %d has different material: %s\n",
|
|
|
|
i, item_mat.toString().c_str());
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
if (!new_mat.matches(*item))
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Job item %d requirements not satisfied by %s.\n",
|
|
|
|
i, new_mat.toString().c_str());
|
2012-01-09 05:20:17 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-01-02 07:46:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Apply the substitution
|
2012-01-04 07:46:39 -07:00
|
|
|
job->mat_type = new_mat.type;
|
|
|
|
job->mat_index = new_mat.index;
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < job->job_items.size(); i++)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
|
|
|
df::job_item *item = job->job_items[i];
|
2012-01-04 07:46:39 -07:00
|
|
|
item->mat_type = new_mat.type;
|
|
|
|
item->mat_index = new_mat.index;
|
2012-01-02 07:46:24 -07:00
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "Applied material '" << new_mat.toString()
|
|
|
|
<< "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl;
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-03 08:25:55 -07:00
|
|
|
static bool build_choice_matches(df::ui_build_item_req *req, df::build_req_choicest *choice,
|
2012-01-07 08:21:07 -07:00
|
|
|
MaterialInfo &new_mat, bool ignore_select)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-03 08:25:55 -07:00
|
|
|
if (VIRTUAL_CAST_VAR(gen, df::build_req_choice_genst, choice))
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-04 07:46:39 -07:00
|
|
|
if (gen->mat_type == new_mat.type &&
|
|
|
|
gen->mat_index == new_mat.index &&
|
2012-01-07 08:21:07 -07:00
|
|
|
(ignore_select || gen->used_count < gen->candidates.size()))
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-03 08:25:55 -07:00
|
|
|
return true;
|
2012-01-02 07:46:24 -07:00
|
|
|
}
|
2012-01-03 08:25:55 -07:00
|
|
|
}
|
|
|
|
else if (VIRTUAL_CAST_VAR(spec, df::build_req_choice_specst, choice))
|
|
|
|
{
|
|
|
|
if (spec->candidate &&
|
|
|
|
spec->candidate->getActualMaterial() == new_mat.type &&
|
|
|
|
spec->candidate->getActualMaterialIndex() == new_mat.index &&
|
2012-01-07 08:21:07 -07:00
|
|
|
(ignore_select || !req->candidate_selected[spec->candidate_id]))
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-03 08:25:55 -07:00
|
|
|
return true;
|
2012-01-02 07:46:24 -07:00
|
|
|
}
|
2012-01-03 08:25:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-02 07:46:24 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_material_in_build(color_ostream &out, MaterialInfo &new_mat)
|
2012-01-03 08:25:55 -07:00
|
|
|
{
|
2012-01-07 08:21:07 -07:00
|
|
|
df::ui_build_selector *sel = ui_build_selector;
|
|
|
|
df::ui_build_item_req *req = sel->requirements[ui_build_selector->req_index];
|
|
|
|
|
|
|
|
// Loop through matching choices
|
|
|
|
bool matches = build_choice_matches(req, sel->choices[sel->sel_index], new_mat, true);
|
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
size_t size = sel->choices.size();
|
2012-01-07 08:21:07 -07:00
|
|
|
int base = (matches ? sel->sel_index + 1 : 0);
|
2012-01-03 08:25:55 -07:00
|
|
|
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < size; i++)
|
2012-01-03 08:25:55 -07:00
|
|
|
{
|
2012-01-07 08:21:07 -07:00
|
|
|
int idx = (base + i) % size;
|
|
|
|
|
|
|
|
if (build_choice_matches(req, sel->choices[idx], new_mat, false))
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
2012-01-07 08:21:07 -07:00
|
|
|
sel->sel_index = idx;
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Could not find material in list: %s\n", new_mat.toString().c_str());
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_material(color_ostream &out, vector <string> & parameters)
|
2012-01-02 07:46:24 -07:00
|
|
|
{
|
|
|
|
// HOTKEY COMMAND: CORE ALREADY SUSPENDED
|
|
|
|
|
|
|
|
MaterialInfo new_mat;
|
|
|
|
if (parameters.size() == 1)
|
|
|
|
{
|
2012-01-15 01:50:53 -07:00
|
|
|
if (!new_mat.find(parameters[0])) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Could not find material: %s\n", parameters[0].c_str());
|
2012-01-02 07:46:24 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if (ui->main.mode == ui_sidebar_mode::QueryBuilding)
|
2012-03-10 04:55:42 -07:00
|
|
|
return job_material_in_job(out, new_mat);
|
2012-01-02 07:46:24 -07:00
|
|
|
if (ui->main.mode == ui_sidebar_mode::Build)
|
2012-03-10 04:55:42 -07:00
|
|
|
return job_material_in_build(out, new_mat);
|
2012-01-02 07:46:24 -07:00
|
|
|
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
}
|
2012-01-03 11:56:05 -07:00
|
|
|
|
2012-01-04 08:39:38 -07:00
|
|
|
/* job-duplicate implementation */
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_duplicate(color_ostream &out, vector <string> & parameters)
|
2012-01-04 08:39:38 -07:00
|
|
|
{
|
|
|
|
if (!parameters.empty())
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *job = Gui::getSelectedWorkshopJob(out);
|
2012-01-04 08:39:38 -07:00
|
|
|
if (!job)
|
|
|
|
return CR_FAILURE;
|
|
|
|
|
2012-01-10 06:23:37 -07:00
|
|
|
if (!job->misc_links.empty() ||
|
|
|
|
(job->job_items.empty() &&
|
|
|
|
job->job_type != job_type::CollectSand &&
|
|
|
|
job->job_type != job_type::CollectClay))
|
2012-01-04 08:39:38 -07:00
|
|
|
{
|
2012-03-17 02:52:22 -06:00
|
|
|
out.printerr("Cannot duplicate job %s\n", ENUM_KEY_STR(job_type,job->job_type).c_str());
|
2012-01-04 08:39:38 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
df::building *building = world->selected_building;
|
|
|
|
if (building->jobs.size() >= 10)
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Job list is already full.\n");
|
2012-01-04 08:39:38 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually clone
|
2012-01-08 09:02:12 -07:00
|
|
|
df::job *pnew = cloneJobStruct(job);
|
2012-01-04 08:39:38 -07:00
|
|
|
|
2012-01-08 09:02:12 -07:00
|
|
|
linkJobIntoWorld(pnew);
|
|
|
|
vector_insert_at(building->jobs, ++*ui_workshop_job_cursor, pnew);
|
2012-01-04 08:39:38 -07:00
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main job command implementation */
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static df::job_item *getJobItem(color_ostream &out, df::job *job, std::string idx)
|
2012-01-09 05:20:17 -07:00
|
|
|
{
|
|
|
|
if (!job)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int v = atoi(idx.c_str());
|
|
|
|
if (v < 1 || v > job->job_items.size()) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Invalid item index.\n");
|
2012-01-09 05:20:17 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return job->job_items[v-1];
|
|
|
|
}
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
static command_result job_cmd(color_ostream &out, vector <string> & parameters)
|
2012-01-03 11:56:05 -07:00
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
CoreSuspender suspend;
|
2012-01-03 11:56:05 -07:00
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
std::string cmd = (parameters.empty() ? "query" : parameters[0]);
|
2012-01-03 11:56:05 -07:00
|
|
|
if (cmd == "query" || cmd == "list")
|
|
|
|
{
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *job = Gui::getSelectedJob(out);
|
2012-01-05 11:04:05 -07:00
|
|
|
if (!job)
|
2012-01-03 11:56:05 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
if (cmd == "query") {
|
2012-03-10 04:55:42 -07:00
|
|
|
printJobDetails(out, job);
|
2012-01-03 11:56:05 -07:00
|
|
|
} else {
|
2012-03-10 04:55:42 -07:00
|
|
|
if (!Gui::workshop_job_hotkey(Core::getTopViewscreen()))
|
2012-01-28 04:00:24 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-01-03 11:56:05 -07:00
|
|
|
df::building *selected = world->selected_building;
|
2012-01-31 09:55:38 -07:00
|
|
|
for (size_t i = 0; i < selected->jobs.size(); i++)
|
2012-03-10 04:55:42 -07:00
|
|
|
printJobDetails(out, selected->jobs[i]);
|
2012-01-03 11:56:05 -07:00
|
|
|
}
|
|
|
|
}
|
2012-01-05 11:04:05 -07:00
|
|
|
else if (cmd == "item-material")
|
|
|
|
{
|
2012-01-09 05:20:17 -07:00
|
|
|
if (parameters.size() != 3)
|
2012-01-05 11:04:05 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *job = Gui::getSelectedJob(out);
|
|
|
|
df::job_item *item = getJobItem(out, job, parameters[1]);
|
2012-01-09 05:20:17 -07:00
|
|
|
if (!item)
|
2012-01-05 11:04:05 -07:00
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
ItemTypeInfo iinfo(item);
|
|
|
|
MaterialInfo minfo;
|
2012-01-05 11:04:05 -07:00
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
if (!minfo.find(parameters[2])) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Could not find the specified material.\n");
|
2012-01-05 11:04:05 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-10 06:23:37 -07:00
|
|
|
if (minfo.isValid() && !iinfo.matches(*item, &minfo)) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Material does not match the requirements.\n");
|
|
|
|
printJobDetails(out, job);
|
2012-01-05 11:04:05 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (job->mat_type != -1 &&
|
|
|
|
job->mat_type == item->mat_type &&
|
|
|
|
job->mat_index == item->mat_index)
|
|
|
|
{
|
2012-01-09 05:20:17 -07:00
|
|
|
job->mat_type = minfo.type;
|
|
|
|
job->mat_index = minfo.index;
|
2012-01-05 11:04:05 -07:00
|
|
|
}
|
|
|
|
|
2012-01-09 05:20:17 -07:00
|
|
|
item->mat_type = minfo.type;
|
|
|
|
item->mat_index = minfo.index;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "Job item updated." << endl;
|
2012-01-09 05:20:17 -07:00
|
|
|
|
|
|
|
if (item->item_type < 0 && minfo.isValid())
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("WARNING: Due to a probable bug, creature & plant material subtype\n"
|
2012-01-09 05:20:17 -07:00
|
|
|
" is ignored unless the item type is also specified.\n");
|
2012-01-05 11:04:05 -07:00
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
printJobDetails(out, job);
|
2012-01-05 11:04:05 -07:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-07 08:21:07 -07:00
|
|
|
else if (cmd == "item-type")
|
|
|
|
{
|
2012-01-09 05:20:17 -07:00
|
|
|
if (parameters.size() != 3)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
df::job *job = Gui::getSelectedJob(out);
|
|
|
|
df::job_item *item = getJobItem(out, job, parameters[1]);
|
2012-01-09 05:20:17 -07:00
|
|
|
if (!item)
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
ItemTypeInfo iinfo;
|
|
|
|
MaterialInfo minfo(item);
|
|
|
|
|
|
|
|
if (!iinfo.find(parameters[2])) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Could not find the specified item type.\n");
|
2012-01-09 05:20:17 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-10 06:23:37 -07:00
|
|
|
if (iinfo.isValid() && !iinfo.matches(*item, &minfo)) {
|
2012-03-10 04:55:42 -07:00
|
|
|
out.printerr("Item type does not match the requirements.\n");
|
|
|
|
printJobDetails(out, job);
|
2012-01-09 05:20:17 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
item->item_type = iinfo.type;
|
|
|
|
item->item_subtype = iinfo.subtype;
|
|
|
|
|
2012-03-10 04:55:42 -07:00
|
|
|
out << "Job item updated." << endl;
|
|
|
|
printJobDetails(out, job);
|
2012-01-09 05:20:17 -07:00
|
|
|
return CR_OK;
|
2012-01-07 08:21:07 -07:00
|
|
|
}
|
2012-01-03 11:56:05 -07:00
|
|
|
else
|
|
|
|
return CR_WRONG_USAGE;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
}
|