static command_result job_material_in_build(Core *c, MaterialInfo &new_mat) { 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); size_t size = sel->choices.size(); int base = (matches ? sel->sel_index + 1 : 0); for (size_t i = 0; i < size; i++) { int idx = (base + i) % size; if (build_choice_matches(req, sel->choices[idx], new_mat, false)) { sel->sel_index = idx; return CR_OK; } } c->con.printerr("Could not find material in list: %s\n", new_mat.toString().c_str()); return CR_FAILURE; }
static int dfhack_matinfo_toString(lua_State *state) { MaterialInfo info; decode_matinfo(state, &info); lua_settop(state, 3); auto str = info.toString(luaL_optint(state, 2, 10015), lua_toboolean(state, 3)); lua_pushstring(state, str.c_str()); return 1; }
static std::string shortJobDescription(df::job *job) { std::string rv = stl_sprintf("job %d: ", job->id); if (job->job_type != job_type::CustomReaction) rv += ENUM_KEY_STR(job_type, job->job_type); else rv += job->reaction_name; MaterialInfo mat; df::dfhack_material_category mat_mask; guess_job_material(job, mat, mat_mask); if (mat.isValid()) rv += " [" + mat.toString() + "]"; else if (mat_mask.whole) rv += " [" + bitfield_to_string(mat_mask) + "]"; return rv; }
static command_result job_material_in_job(Core *c, MaterialInfo &new_mat) { df::job *job = getSelectedWorkshopJob(c); if (!job) return CR_FAILURE; if (!new_mat.isValid() || new_mat.type != 0) { c->con.printerr("New job material isn't inorganic: %s\n", new_mat.toString().c_str()); return CR_FAILURE; } MaterialInfo cur_mat(job); if (!cur_mat.isValid() || cur_mat.type != 0) { c->con.printerr("Current job material isn't inorganic: %s\n", cur_mat.toString().c_str()); return CR_FAILURE; } df::craft_material_class old_class = cur_mat.getCraftClass(); if (old_class == craft_material_class::None) { c->con.printerr("Unexpected current material type: %s\n", cur_mat.toString().c_str()); return CR_FAILURE; } if (new_mat.getCraftClass() != old_class) { c->con.printerr("New material %s does not satisfy requirement: %s\n", new_mat.toString().c_str(), ENUM_KEY_STR(craft_material_class, old_class)); return CR_FAILURE; } for (size_t i = 0; i < job->job_items.size(); i++) { df::job_item *item = job->job_items[i]; MaterialInfo item_mat(item); if (item_mat != cur_mat) { c->con.printerr("Job item %d has different material: %s\n", 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 job->mat_type = new_mat.type; job->mat_index = new_mat.index; for (size_t i = 0; i < job->job_items.size(); i++) { df::job_item *item = job->job_items[i]; item->mat_type = new_mat.type; item->mat_index = new_mat.index; } c->con << "Applied material '" << new_mat.toString() << "' to job " << ENUM_KEY_STR(job_type,job->job_type) << endl; return CR_OK; }