本文整理汇总了C++中item::gunmods方法的典型用法代码示例。如果您正苦于以下问题:C++ item::gunmods方法的具体用法?C++ item::gunmods怎么用?C++ item::gunmods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::gunmods方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gun_has_item
static bool gun_has_item( const item &gun, const item *it )
{
if( !gun.is_gun() ) {
return false;
}
if( gun.magazine_current() == it ) {
return true;
}
auto gms = gun.gunmods();
return !gms.empty() && std::find( gms.begin(), gms.end(), it ) != gms.end();
}
示例2: generate_gun_sound
// firing is the item that is fired. It may be the wielded gun, but it can also be an attached
// gunmod. p is the character that is firing, this may be a pseudo-character (used by monattack/
// vehicle turrets) or a NPC.
void sfx::generate_gun_sound( const player &p, const item &firing )
{
end_sfx_timestamp = std::chrono::high_resolution_clock::now();
sfx_time = end_sfx_timestamp - start_sfx_timestamp;
if( std::chrono::duration_cast<std::chrono::milliseconds> ( sfx_time ).count() < 80 ) {
return;
}
const tripoint source = p.pos();
int heard_volume = get_heard_volume( source );
if( heard_volume <= 30 ) {
heard_volume = 30;
}
itype_id weapon_id = firing.typeId();
int angle;
int distance;
std::string selected_sound;
// this does not mean p == g->u (it could be a vehicle turret)
if( g->u.pos() == source ) {
angle = 0;
distance = 0;
selected_sound = "fire_gun";
const auto mods = firing.gunmods();
if( std::any_of( mods.begin(), mods.end(), []( const item *e ) { return e->type->gunmod->loudness < 0; } ) ) {
weapon_id = "weapon_fire_suppressed";
}
} else {
angle = get_heard_angle( source );
distance = rl_dist( g->u.pos(), source );
if( distance <= 17 ) {
selected_sound = "fire_gun";
} else {
selected_sound = "fire_gun_distant";
}
}
play_variant_sound( selected_sound, weapon_id, heard_volume, angle, 0.8, 1.2 );
start_sfx_timestamp = std::chrono::high_resolution_clock::now();
}