本文整理汇总了C++中MaterialInfo::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialInfo::toString方法的具体用法?C++ MaterialInfo::toString怎么用?C++ MaterialInfo::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaterialInfo
的用法示例。
在下文中一共展示了MaterialInfo::toString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: job_material_in_build
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;
}
示例2: dfhack_matinfo_toString
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;
}
示例3: if
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;
}
示例4: job_material_in_job
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;
}