本文整理汇总了C++中inventory::has_amount方法的典型用法代码示例。如果您正苦于以下问题:C++ inventory::has_amount方法的具体用法?C++ inventory::has_amount怎么用?C++ inventory::has_amount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory
的用法示例。
在下文中一共展示了inventory::has_amount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: player_can_build
bool player_can_build(player &p, inventory pinv, construction *con)
{
if (p.skillLevel("carpentry") < con->difficulty) {
return false;
}
bool has_tool = false;
bool has_component = false;
bool tools_required = false;
bool components_required = false;
for (int j = 0; j < con->tools.size(); j++) {
if (con->tools[j].size() > 0) {
tools_required = true;
has_tool = false;
for (unsigned k = 0; k < con->tools[j].size(); k++) {
if (pinv.has_amount(con->tools[j][k].type, 1)) {
has_tool = true;
con->tools[j][k].available = 1;
} else {
con->tools[j][k].available = -1;
}
}
if (!has_tool) { // missing one of the tools for this stage
break;
}
}
}
for (int j = 0; j < con->components.size(); ++j) {
if (con->components[j].size() > 0) {
components_required = true;
has_component = false;
for (unsigned k = 0; k < con->components[j].size(); k++) {
if (( item_controller->find_template(con->components[j][k].type)->is_ammo() &&
pinv.has_charges(con->components[j][k].type,
con->components[j][k].count) ) ||
(!item_controller->find_template(con->components[j][k].type)->is_ammo() &&
pinv.has_amount (con->components[j][k].type,
con->components[j][k].count) ))
{
has_component = true;
con->components[j][k].available = 1;
} else {
con->components[j][k].available = -1;
}
}
if (!has_component) { // missing one of the comps for this stage
break;
}
}
}
return (has_component || !components_required) &&
(has_tool || !tools_required);
}
示例2: player_can_build
bool game::player_can_build(player &p, inventory inv, constructable* con,
int level, bool specific)
// defaults: level==0, specific==false
{
if (level < 0) // used as escape value in place_construction()
return false;
int stop = (specific ? level : con->stages.size());
do {
construction_stage stage = con->stages[level];
int number_of_tools = 0, number_of_components = 0;
int number_of_req_tools = 0, number_of_req_components = 0;
for (int j = 0; j < 3; j++) {
// counting available tools
if (stage.tools[j].size() > 0) {
number_of_req_tools++;
for (int k = 0; k < stage.tools[j].size(); k++)
if (inv.has_amount(stage.tools[j][k], 1)) {
number_of_tools++;
break;
}
}
// counting available components
if (stage.components[j].size() > 0) {
number_of_req_components++;
for (int k = 0; k < stage.components[j].size(); k++)
if (( itypes[stage.components[j][k].type]->is_ammo() &&
inv.has_charges(stage.components[j][k].type,
stage.components[j][k].count) ) ||
(!itypes[stage.components[j][k].type]->is_ammo() &&
inv.has_amount (stage.components[j][k].type,
stage.components[j][k].count) )) {
number_of_components++;
break;
}
}
}
// difficulty check + summary
if (!(p.sklevel[sk_carpentry] < stage.difficulty) &&
number_of_tools == number_of_req_tools &&
number_of_components == number_of_req_components)
return true;
level++;
} while (level < stop);
return false;
}
示例3: player_can_build
bool game::player_can_build(player &p, inventory inv, constructable* con,
int level, bool cont)
{
if (p.sklevel[sk_carpentry] < con->difficulty)
return false;
if (level < 0)
level = con->stages.size();
int start = 0;
if (cont)
start = level;
for (int i = start; i < con->stages.size() && i <= level; i++) {
construction_stage stage = con->stages[i];
for (int j = 0; j < 3; j++) {
if (stage.tools[j].size() > 0) {
bool has_tool = false;
for (int k = 0; k < stage.tools[j].size() && !has_tool; k++) {
if (inv.has_amount(stage.tools[j][k], 1))
has_tool = true;
}
if (!has_tool)
return false;
}
if (stage.components[j].size() > 0) {
bool has_component = false;
for (int k = 0; k < stage.components[j].size() && !has_component; k++) {
if (( itypes[stage.components[j][k].type]->is_ammo() &&
inv.has_charges(stage.components[j][k].type,
stage.components[j][k].count) ) ||
(!itypes[stage.components[j][k].type]->is_ammo() &&
inv.has_amount (stage.components[j][k].type,
stage.components[j][k].count) ))
has_component = true;
}
if (!has_component)
return false;
}
}
}
return true;
}
示例4: player_can_build
bool game::player_can_build(player &p, inventory pinv, constructable* con,
const int level, bool cont, bool exact_level)
{
int last_level = level;
// default behavior: return true if any of the stages up to L can be constr'd
// if exact_level, require that this level be constructable
if (p.skillLevel("carpentry") < con->difficulty)
return false;
if (level < 0)
last_level = con->stages.size();
int start = 0;
if (cont)
start = level;
bool can_build_any = false;
for (int i = start; i < con->stages.size() && i <= last_level; i++) {
construction_stage* stage = &(con->stages[i]);
bool has_tool = false;
bool has_component = false;
bool tools_required = false;
bool components_required = false;
for (int j = 0; j < 10; j++) {
if (stage->tools[j].size() > 0) {
tools_required = true;
has_tool = false;
for (int k = 0; k < stage->tools[j].size(); k++) {
if (pinv.has_amount(stage->tools[j][k].type, 1))
{
has_tool = true;
stage->tools[j][k].available = 1;
}
else
{
stage->tools[j][k].available = -1;
}
}
if (!has_tool) // missing one of the tools for this stage
break;
}
if (stage->components[j].size() > 0) {
components_required = true;
has_component = false;
for (int k = 0; k < stage->components[j].size(); k++) {
if (( item_controller->find_template(stage->components[j][k].type)->is_ammo() &&
pinv.has_charges(stage->components[j][k].type,
stage->components[j][k].count) ) ||
(!item_controller->find_template(stage->components[j][k].type)->is_ammo() &&
pinv.has_amount (stage->components[j][k].type,
stage->components[j][k].count) ))
{
has_component = true;
stage->components[j][k].available = 1;
}
else
{
stage->components[j][k].available = -1;
}
}
if (!has_component) // missing one of the comps for this stage
break;
}
} // j in [0,2]
can_build_any |= (has_component || !components_required) &&
(has_tool || !tools_required);
if (exact_level && (i == level)) {
return ((has_component || !components_required) &&
(has_tool || !tools_required));
}
} // stage[i]
return can_build_any;
}