本文整理汇总了C++中item::has_flag方法的典型用法代码示例。如果您正苦于以下问题:C++ item::has_flag方法的具体用法?C++ item::has_flag怎么用?C++ item::has_flag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::has_flag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ret_val<edible_rating> player::can_eat( const item &food ) const
{
// @todo This condition occurs way too often. Unify it.
if( is_underwater() ) {
return ret_val<edible_rating>::make_failure( _( "You can't do that while underwater." ) );
}
const auto &comest = food.type->comestible;
if( !comest ) {
return ret_val<edible_rating>::make_failure( _( "That doesn't look edible." ) );
}
const bool eat_verb = food.has_flag( "USE_EAT_VERB" );
const bool edible = eat_verb || comest->comesttype == "FOOD";
const bool drinkable = !eat_verb && comest->comesttype == "DRINK";
if( edible || drinkable ) {
for( const auto &elem : food.type->materials ) {
if( !elem->edible() ) {
return ret_val<edible_rating>::make_failure( _( "That doesn't look edible in its current form." ) );
}
}
}
if( comest->tool != "null" ) {
const bool has = item::count_by_charges( comest->tool )
? has_charges( comest->tool, 1 )
: has_amount( comest->tool, 1 );
if( !has ) {
return ret_val<edible_rating>::make_failure( NO_TOOL,
string_format( _( "You need a %s to consume that!" ),
item::nname( comest->tool ).c_str() ) );
}
}
// For all those folks who loved eating marloss berries. D:< mwuhahaha
if( has_trait( trait_id( "M_DEPENDENT" ) ) && food.typeId() != "mycus_fruit" ) {
return ret_val<edible_rating>::make_failure( INEDIBLE_MUTATION,
_( "We can't eat that. It's not right for us." ) );
}
// Here's why PROBOSCIS is such a negative trait.
if( has_trait( trait_id( "PROBOSCIS" ) ) && !drinkable ) {
return ret_val<edible_rating>::make_failure( INEDIBLE_MUTATION, _( "Ugh, you can't drink that!" ) );
}
if( has_trait( trait_id( "CARNIVORE" ) ) && nutrition_for( food ) > 0 &&
food.has_any_flag( carnivore_blacklist ) && !food.has_flag( "CARNIVORE_OK" ) ) {
return ret_val<edible_rating>::make_failure( INEDIBLE_MUTATION,
_( "Eww. Inedible plant stuff!" ) );
}
if( ( has_trait( trait_id( "HERBIVORE" ) ) || has_trait( trait_id( "RUMINANT" ) ) ) &&
food.has_any_flag( herbivore_blacklist ) ) {
// Like non-cannibal, but more strict!
return ret_val<edible_rating>::make_failure( INEDIBLE_MUTATION,
_( "The thought of eating that makes you feel sick." ) );
}
return ret_val<edible_rating>::make_success();
}
示例2: set_worn
void player_morale::set_worn( const item &it, bool worn )
{
const bool fancy = it.has_flag( "FANCY" );
const bool super_fancy = it.has_flag( "SUPER_FANCY" );
const bool filthy_gear = it.has_flag( "FILTHY" );
const int sign = ( worn ) ? 1 : -1;
const auto update_body_part = [&]( body_part_data & bp_data ) {
if( fancy || super_fancy ) {
bp_data.fancy += sign;
}
if( filthy_gear ) {
bp_data.filthy += sign;
}
bp_data.covered += sign;
};
const auto covered( it.get_covered_body_parts() );
if( covered.any() ) {
for( int i = 0; i < num_bp; ++i ) {
if( covered.test( i ) ) {
update_body_part( body_parts[i] );
}
}
} else {
update_body_part( no_body_part );
}
if( super_fancy ) {
const auto id = it.typeId();
const auto iter = super_fancy_items.find( id );
if( iter != super_fancy_items.end() ) {
iter->second += sign;
if( iter->second == 0 ) {
super_fancy_items.erase( iter );
}
} else if( worn ) {
super_fancy_items[id] = 1;
} else {
debugmsg( "Tried to take off \"%s\" which isn't worn.", id.c_str() );
}
}
if( fancy || super_fancy ) {
update_stylish_bonus();
}
if( filthy_gear ) {
update_squeamish_penalty();
}
update_constrained_penalty();
}
示例3: clamp
std::pair<int, int> player::fun_for( const item &comest ) const
{
static const trait_id trait_GOURMAND( "GOURMAND" );
static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
static const trait_id trait_SAPROVORE( "SAPROVORE" );
static const std::string flag_EATEN_COLD( "EATEN_COLD" );
static const std::string flag_COLD( "COLD" );
if( !comest.is_comestible() ) {
return std::pair<int, int>( 0, 0 );
}
// As float to avoid rounding too many times
float fun = comest.type->comestible->fun;
// Rotten food should be pretty disgusting
const float relative_rot = comest.get_relative_rot();
if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) && !has_trait( trait_SAPROVORE ) ) {
const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
// Three effects:
// penalty for rot goes from -2 to -20
// bonus for tasty food drops from 90% to 0%
// disgusting food unfun increases from 110% to 200%
fun -= rottedness * 10;
if( fun > 0 ) {
fun *= ( 1.0f - rottedness );
} else {
fun *= ( 1.0f + rottedness );
}
}
float fun_max = fun < 0 ? fun * 6 : fun * 3;
if( comest.has_flag( flag_EATEN_COLD ) && comest.has_flag( flag_COLD ) ) {
if( fun > 0 ) {
fun *= 3;
} else {
fun = 1;
fun_max = 5;
}
}
if( has_trait( trait_GOURMAND ) ) {
if( fun < -1 ) {
fun_max = fun;
fun /= 2;
} else if( fun > 0 ) {
fun_max = fun_max * 3 / 2;
fun *= 3;
}
}
return std::pair<int, int>( fun, fun_max );
}
示例4: can_consume
bool player::can_consume( const item &it ) const
{
if( can_consume_as_is( it ) ) {
return true;
}
// checking NO_UNLOAD to prevent consumption of `battery` when contained in `battery_car` (#20012)
return !it.is_container_empty() && !it.has_flag( "NO_UNLOAD" ) &&
can_consume_as_is( it.contents.front() );
}
示例5: set_item_food
void set_item_food( item &newit )
{
int bday_tmp = newit.bday % 3600; // fuzzy birthday for stacking reasons
newit.bday = int( newit.bday ) + 3600 - bday_tmp;
if( newit.has_flag( "EATEN_HOT" ) ) { // hot foods generated
newit.item_tags.insert( "HOT" );
newit.item_counter = 600;
newit.active = true;
}
}
示例6: select
virtual void select(int entnum, uimenu *menu) {
const int starty = 3;
const int startx = menu->w_width - menu->pad_right;
itype *ity = item_controller->find_template(standard_itype_ids[entnum]);
std::string padding = std::string(menu->pad_right - 1, ' ');
for(int i = 0; i < lastlen + starty + 1; i++ ) {
mvwprintw(menu->window, 1 + i, startx, "%s", padding.c_str() );
}
if ( ity != NULL ) {
tmp.make(item_controller->find_template(standard_itype_ids[entnum]));
tmp.bday = g->turn;
if (tmp.is_tool()) {
tmp.charges = dynamic_cast<it_tool *>(tmp.type)->max_charges;
} else if (tmp.is_ammo()) {
tmp.charges = 100;
} else if (tmp.is_gun()) {
tmp.charges = 0;
} else if (tmp.is_gunmod() && (tmp.has_flag("MODE_AUX") ||
tmp.typeId() == "spare_mag")) {
tmp.charges = 0;
} else {
tmp.charges = -1;
}
if( tmp.is_stationary() ) {
tmp.note = SNIPPET.assign( (dynamic_cast<it_stationary *>(tmp.type))->category );
}
std::vector<std::string> desc = foldstring(tmp.info(true), menu->pad_right - 1);
int dsize = desc.size();
if ( dsize > menu->w_height - 5 ) {
dsize = menu->w_height - 5;
}
lastlen = dsize;
std::string header = string_format("#%d: %s%s",
entnum,
standard_itype_ids[entnum].c_str(),
( incontainer ? " (contained)" : "" )
);
mvwprintz(menu->window, 1, startx + ( menu->pad_right - 1 - header.size() ) / 2, c_cyan, "%s",
header.c_str()
);
for(int i = 0; i < desc.size(); i++ ) {
mvwprintw(menu->window, starty + i, startx, "%s", desc[i].c_str() );
}
mvwprintz(menu->window, menu->w_height - 3, startx, c_green, "%s", msg.c_str());
msg = padding;
mvwprintw(menu->window, menu->w_height - 2, startx, "[/] find, [f] container, [q]uit");
}
}
示例7: is_valid_weapon
bool ma_requirements::is_valid_weapon(item& i) {
for (std::set<std::string>::iterator it = req_flags.begin();
it != req_flags.end(); ++it) {
std::string flag = *it;
if (!i.has_flag(flag)) return false;
}
bool valid = i.damage_bash() >= min_bashing_damage
&& i.damage_cut() >= min_cutting_damage;
return valid;
}
示例8: can_feed_furnace_with
bool player::can_feed_furnace_with( const item &it ) const
{
if( !it.flammable() || it.has_flag( "RADIOACTIVE" ) || can_eat( it ).success() ) {
return false;
}
if( !has_active_bionic( bio_furnace ) ) {
return false;
}
return it.typeId() != "corpse"; // @todo Eliminate the hard-coded special case.
}
示例9: weapon_valid
bool martialart::weapon_valid( const item &it ) const
{
if( it.is_null() ) {
return true;
}
if( has_weapon( it.typeId() ) ) {
return true;
}
return !strictly_unarmed && it.has_flag( "UNARMED_WEAPON" );
}
示例10: is_valid_weapon
bool ma_requirements::is_valid_weapon(item &i)
{
for( auto flag : req_flags ) {
if (!i.has_flag(flag)) {
return false;
}
}
bool valid = i.damage_bash() >= min_bashing_damage
&& i.damage_cut() >= min_cutting_damage;
return valid;
}
示例11: set_worn
void player_morale::set_worn( const item &it, bool worn )
{
const bool just_fancy = it.has_flag( "FANCY" );
const bool super_fancy = it.has_flag( "SUPER_FANCY" );
if( just_fancy || super_fancy ) {
const int sign = ( worn ) ? 1 : -1;
for( int i = 0; i < num_bp; i++ ) {
const auto bp = static_cast<body_part>( i );
if( it.covers( bp ) ) {
covered[i] = std::max( covered[i] + sign, 0 );
}
}
if( super_fancy ) {
super_fancy_bonus += 2 * sign;
}
update_stylish_bonus();
}
}
示例12: is_valid_weapon
bool ma_requirements::is_valid_weapon( const item &i ) const
{
for( auto flag : req_flags ) {
if (!i.has_flag(flag)) {
return false;
}
}
for( const auto &pr : min_damage ) {
if( i.damage_melee( pr.first ) < pr.second ) {
return false;
}
}
return true;
}
示例13: i_add_or_drop
bool Character::i_add_or_drop(item& it, int qty) {
bool retval = true;
bool drop = false;
inv.assign_empty_invlet(it);
for (int i = 0; i < qty; ++i) {
if (!drop && (!can_pickWeight(it.weight(), !OPTIONS["DANGEROUS_PICKUPS"])
|| !can_pickVolume(it.volume()))) {
drop = true;
}
if( drop ) {
retval &= !g->m.add_item_or_charges( pos(), it ).is_null();
} else if ( !( it.has_flag("IRREMOVEABLE") && !it.is_gun() ) ){
i_add(it);
}
}
return retval;
}
示例14: nutrition_for
// TODO: Move pizza scraping here.
// Same for other kinds of nutrition alterations
// This is used by item display, making actual nutrition available to player.
int player::nutrition_for( const item &comest ) const
{
static const trait_id trait_CARNIVORE( "CARNIVORE" );
static const trait_id trait_GIZZARD( "GIZZARD" );
static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
static const std::string flag_CARNIVORE_OK( "CARNIVORE_OK" );
if( !comest.is_comestible() ) {
return 0;
}
// As float to avoid rounding too many times
float nutr = comest.type->comestible->nutr;
if( has_trait( trait_GIZZARD ) ) {
nutr *= 0.6f;
}
if( has_trait( trait_CARNIVORE ) && comest.has_flag( flag_CARNIVORE_OK ) &&
comest.has_any_flag( carnivore_blacklist ) ) {
// TODO: Comment pizza scrapping
nutr *= 0.5f;
}
const float relative_rot = comest.get_relative_rot();
// Saprophages get full nutrition from rotting food
if( relative_rot > 1.0f && !has_trait( trait_SAPROPHAGE ) ) {
// everyone else only gets a portion of the nutrition
// Scaling linearly from 100% at just-rotten to 0 at halfway-rotten-away
const float rottedness = clamp( 2 * relative_rot - 2.0f, 0.1f, 1.0f );
nutr *= ( 1.0f - rottedness );
}
// Bio-digestion gives extra nutrition
if( has_bionic( bio_digestion ) ) {
nutr *= 1.5f;
}
return ( int )nutr;
}
示例15: allergy_type
morale_type player::allergy_type( const item &food ) const
{
using allergy_tuple = std::tuple<trait_id, std::string, morale_type>;
static const std::array<allergy_tuple, 8> allergy_tuples = {{
std::make_tuple( trait_id( "VEGETARIAN" ), "ALLERGEN_MEAT", MORALE_VEGETARIAN ),
std::make_tuple( trait_id( "MEATARIAN" ), "ALLERGEN_VEGGY", MORALE_MEATARIAN ),
std::make_tuple( trait_id( "LACTOSE" ), "ALLERGEN_MILK", MORALE_LACTOSE ),
std::make_tuple( trait_id( "ANTIFRUIT" ), "ALLERGEN_FRUIT", MORALE_ANTIFRUIT ),
std::make_tuple( trait_id( "ANTIJUNK" ), "ALLERGEN_JUNK", MORALE_ANTIJUNK ),
std::make_tuple( trait_id( "ANTIWHEAT" ), "ALLERGEN_WHEAT", MORALE_ANTIWHEAT )
}
};
for( const auto &tp : allergy_tuples ) {
if( has_trait( std::get<0>( tp ) ) &&
food.has_flag( std::get<1>( tp ) ) ) {
return std::get<2>( tp );
}
}
return MORALE_NULL;
}