本文整理汇总了C++中rl_dist函数的典型用法代码示例。如果您正苦于以下问题:C++ rl_dist函数的具体用法?C++ rl_dist怎么用?C++ rl_dist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rl_dist函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_heard_volume
// 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();
}
示例2: bash_skill
int monster::group_bash_skill( point target )
{
if( !has_flag(MF_GROUP_BASH) ) {
return bash_skill();
}
int bashskill = 0;
// pileup = more bashskill, but only help bashing mob directly infront of target
const int max_helper_depth = 5;
const std::vector<point> bzone = get_bashing_zone( target, pos(), max_helper_depth );
for( point candidate : bzone ) {
// Drawing this line backwards excludes the target and includes the candidate.
std::vector<point> path_to_target = line_to( target, candidate, 0 );
bool connected = true;
int mondex = -1;
for( point in_path : path_to_target ) {
// If any point in the line from zombie to target is not a cooperating zombie,
// it can't contribute.
mondex = g->mon_at( in_path );
if( mondex == -1 ) {
connected = false;
break;
}
monster &helpermon = g->zombie( mondex );
if( !helpermon.has_flag(MF_GROUP_BASH) || helpermon.is_hallucination() ) {
connected = false;
break;
}
}
if( !connected ) {
continue;
}
// If we made it here, the last monster checked was the candidate.
monster &helpermon = g->zombie( mondex );
// Contribution falls off rapidly with distance from target.
bashskill += helpermon.bash_skill() / rl_dist( candidate, target );
}
return bashskill;
}
示例3: rl_dist
void mdeath::jabberwock( monster &z )
{
player *ch = dynamic_cast<player *>( z.get_killer() );
bool vorpal = ch && ch->is_player() &&
rl_dist( z.pos(), ch->pos() ) <= 1 &&
ch->weapon.has_flag( "DIAMOND" ) &&
ch->weapon.volume() > units::from_milliliter( 750 );
if( vorpal && !ch->weapon.has_technique( matec_id( "VORPAL" ) ) ) {
if( ch->sees( z ) ) {
//~ %s is the possessive form of the monster's name
ch->add_msg_if_player( m_info,
_( "As the flames in %s eyes die out, your weapon seems to shine slightly brighter." ),
z.disp_name( true ) );
}
ch->weapon.add_technique( matec_id( "VORPAL" ) );
}
mdeath::normal( z );
}
示例4: zapback
void mdefense::zapback(monster *m, const projectile *proj)
{
int j;
if (rl_dist(m->posx(), m->posy(), g->u.posx, g->u.posy) > 1 ||
!g->sees_u(m->posx(), m->posy(), j)) {
return; // Out of range
}
if (proj != NULL) {
return; // Not a melee attack
}
if ((!g->u.has_active_bionic("bio_faraday") && !g->u.worn_with_flag("ELECTRIC_IMMUNE") &&
!g->u.has_artifact_with(AEP_RESIST_ELECTRICITY)) &&
(g->u.weapon.conductive() || g->u.unarmed_attack()) && (rng(0, 100) <= m->def_chance)) {
damage_instance shock;
shock.add_damage(DT_ELECTRIC, rng(1, 5));
g->u.deal_damage(m, bp_arm_l, shock);
g->u.deal_damage(m, bp_arm_r, shock);
add_msg(m_bad, _("Striking the %s shocks you!"), m->name().c_str());
}
return;
}
示例5: guilt
void mdeath::guilt(game *g, monster *z)
{
if (g->u.has_trait(PF_CANNIBAL))
return; // We don't give a shit!
if (rl_dist(z->posx, z->posy, g->u.posx, g->u.posy) > 5)
return; // Too far away, we can deal with it
if (z->hp >= 0)
return; // It probably didn't die from damage
g->add_msg("You feel terrible for killing %s!", z->name().c_str());
if(z->type->id == mon_hallu_mom)
{
g->u.add_morale(MORALE_KILLED_MONSTER, -50, -250);
}
else if(z->type->id == mon_zombie_child)
{
g->u.add_morale(MORALE_KILLED_MONSTER, -5, -250);
}
else
{
return;
}
}
示例6: boomer
void mdeath::boomer(game *g, monster *z)
{
std::string tmp;
g->sound(z->posx, z->posy, 24, "a boomer explode!");
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
g->m.bash(z->posx + i, z->posy + j, 10, tmp);
if (g->m.field_at(z->posx + i, z->posy + j).type == fd_bile &&
g->m.field_at(z->posx + i, z->posy + j).density < 3)
g->m.field_at(z->posx + i, z->posy + j).density++;
else
g->m.add_field(g, z->posx + i, z->posy + j, fd_bile, 1);
int mondex = g->mon_at(z->posx + i, z->posy +j);
if (mondex != -1) {
g->z[mondex].stumble(g, false);
g->z[mondex].moves -= 250;
}
}
}
if (rl_dist(z->posx, z->posy, g->u.posx, g->u.posy) == 1)
g->u.infect(DI_BOOMERED, bp_eyes, 2, 24, g);
}
示例7: give_aid
void talk_function::give_all_aid( npc &p )
{
p.add_effect( effect_currently_busy, 30_minutes );
give_aid( p );
for( npc &guy : g->all_npcs() ) {
if( rl_dist( guy.pos(), g->u.pos() ) < PICKUP_RANGE && guy.is_friend() ) {
for( int i = 0; i < num_hp_parts; i++ ) {
const body_part bp_healed = player::hp_to_bp( hp_part( i ) );
guy.heal( hp_part( i ), 5 * rng( 2, 5 ) );
if( guy.has_effect( effect_bite, bp_healed ) ) {
guy.remove_effect( effect_bite, bp_healed );
}
if( guy.has_effect( effect_bleed, bp_healed ) ) {
guy.remove_effect( effect_bleed, bp_healed );
}
if( guy.has_effect( effect_infected, bp_healed ) ) {
guy.remove_effect( effect_infected, bp_healed );
}
}
}
}
}
示例8: add_msg
bool gun_actor::call( monster &z ) const
{
Creature *target;
if( z.friendly ) {
int max_range = 0;
for( const auto &e : ranges ) {
max_range = std::max( std::max( max_range, e.first.first ), e.first.second );
}
int hostiles; // hostiles which cannot be engaged without risking friendly fire
target = z.auto_find_hostile_target( max_range, hostiles );
if( !target ) {
if( hostiles > 0 && g->u.sees( z ) ) {
add_msg( m_warning, ngettext( "Pointed in your direction, the %s emits an IFF warning beep.",
"Pointed in your direction, the %s emits %d annoyed sounding beeps.",
hostiles ),
z.name(), hostiles );
}
return false;
}
} else {
target = z.attack_target();
if( !target || !z.sees( *target ) ) {
return false;
}
}
int dist = rl_dist( z.pos(), target->pos() );
for( const auto &e : ranges ) {
if( dist >= e.first.first && dist <= e.first.second ) {
shoot( z, *target, e.second );
return true;
}
}
return false;
}
示例9: tripoint
city_reference overmapbuffer::closest_city( const tripoint ¢er )
{
// a whole overmap (because it's in submap coordinates, OMAPX is overmap terrain coordinates)
auto const radius = OMAPX * 2;
// Starting with distance = INT_MAX, so the first city is already closer
city_reference result{ nullptr, nullptr, tripoint( 0, 0, 0 ), INT_MAX };
for( auto &om : get_overmaps_near( center, radius ) ) {
const auto abs_pos_om = om_to_sm_copy( om->pos() );
for( auto &city : om->cities ) {
const auto rel_pos_city = omt_to_sm_copy( point( city.x, city.y ) );
// TODO: Z-level cities. This 0 has to be here until mapgen understands non-0 zlev cities
const auto abs_pos_city = tripoint( abs_pos_om + rel_pos_city, 0 );
const auto distance = rl_dist( abs_pos_city, center );
const city_reference cr{ om, &city, abs_pos_city, distance };
if( distance < result.distance ) {
result = cr;
} else if( distance == result.distance && result.city->s < city.s ) {
result = cr;
}
}
}
return result;
}
示例10: return
bool trap::detect_trap(const player &p, int x, int y) const
{
// Some decisions are based around:
// * Starting, and thus average perception, is 8.
// * Buried landmines, the silent killer, has a visibility of 10.
// * There will always be a distance malus of 1 unless you're on top of the trap.
// * ...and an average character should at least have a minor chance of
// noticing a buried landmine if standing right next to it.
// Effective Perception...
return (p.per_cur - const_cast<player&>(p).encumb(bp_eyes)) +
// ...small bonus from stimulants...
(p.stim > 10 ? rng(1, 2) : 0) +
// ...bonus from trap skill...
(const_cast<player&>(p).skillLevel("traps") * 2) +
// ...luck, might be good, might be bad...
rng(-4, 4) -
// ...malus if we are tired...
(p.has_disease("lack_sleep") ? rng(1, 5) : 0) -
// ...malus farther we are from trap...
rl_dist(p.posx, p.posy, x, y) >
// ...must all be greater than the trap visibility.
visibility;
}
示例11: om_to_sm_copy
std::vector<city_reference> overmapbuffer::get_cities_near( const tripoint &location, int radius )
{
std::vector<city_reference> result;
for( const auto om : get_overmaps_near( location, radius ) ) {
const auto abs_pos_om = om_to_sm_copy( om->pos() );
result.reserve( result.size() + om->cities.size() );
std::transform( om->cities.begin(), om->cities.end(), std::back_inserter( result ),
[&]( city & element ) {
const auto rel_pos_city = omt_to_sm_copy( element.pos );
const auto abs_pos_city = tripoint( rel_pos_city + abs_pos_om, 0 );
const auto distance = rl_dist( abs_pos_city, location );
return city_reference{ &element, abs_pos_city, distance };
} );
}
std::sort( result.begin(), result.end(), []( const city_reference & lhs,
const city_reference & rhs ) {
return lhs.get_distance_from_bounds() < rhs.get_distance_from_bounds();
} );
return result;
}
示例12: sight_range
bool Creature::sees( const tripoint &t, int &bresen1, int &bresen2 ) const
{
// TODO: FoV update
bresen2 = 0;
if( posz() != t.z ) {
return false;
}
const int range_cur = sight_range( g->m.ambient_light_at(t) );
const int range_day = sight_range( DAYLIGHT_LEVEL );
const int range_min = std::min( range_cur, range_day );
const int wanted_range = rl_dist( pos3(), t );
if( wanted_range <= range_min ||
( wanted_range <= range_day &&
g->m.ambient_light_at( t ) > g->natural_light_level() ) ) {
if( g->m.ambient_light_at( t ) > g->natural_light_level() ) {
return g->m.sees( pos3(), t, wanted_range, bresen1, bresen2 );
} else {
return g->m.sees( pos3(), t, range_min, bresen1, bresen2 );
}
} else {
return false;
}
}
示例13: switch
void event::actualize()
{
switch( type ) {
case EVENT_HELP:
debugmsg("Currently disabled while NPC and monster factions are being rewritten.");
/*
{
int num = 1;
if( faction_id >= 0 ) {
num = rng( 1, 6 );
}
for( int i = 0; i < num; i++ ) {
npc *temp = new npc();
temp->normalize();
if( faction_id != -1 ) {
faction *fac = g->faction_by_id( faction_id );
if( fac ) {
temp->randomize_from_faction( fac );
} else {
debugmsg( "EVENT_HELP run with invalid faction_id" );
temp->randomize();
}
} else {
temp->randomize();
}
temp->attitude = NPCATT_DEFEND;
// important: npc::spawn_at must be called to put the npc into the overmap
temp->spawn_at( g->get_abs_levx(), g->get_abs_levy(), g->get_abs_levz() );
// spawn at the border of the reality bubble, outside of the players view
if( one_in( 2 ) ) {
temp->posx = rng( 0, SEEX * MAPSIZE - 1 );
temp->posy = rng( 0, 1 ) * SEEY * MAPSIZE;
} else {
temp->posx = rng( 0, 1 ) * SEEX * MAPSIZE;
temp->posy = rng( 0, SEEY * MAPSIZE - 1 );
}
// And tell the npc to go to the player.
temp->goal.x = g->om_global_location().x;
temp->goal.y = g->om_global_location().y;
// The npcs will be loaded later by game::load_npcs()
}
}
*/
break;
case EVENT_ROBOT_ATTACK: {
if (rl_dist(g->get_abs_levx(), g->get_abs_levy(), map_point.x, map_point.y) <= 4) {
mtype *robot_type = GetMType("mon_tripod");
if (faction_id == 0) { // The cops!
if (one_in(2)) {
robot_type = GetMType("mon_copbot");
} else {
robot_type = GetMType("mon_riotbot");
}
g->u.add_memorial_log(pgettext("memorial_male", "Became wanted by the police!"),
pgettext("memorial_female", "Became wanted by the police!"));
}
monster robot(robot_type);
int robx = (g->get_abs_levx() > map_point.x ? 0 - SEEX * 2 : SEEX * 4),
roby = (g->get_abs_levy() > map_point.y ? 0 - SEEY * 2 : SEEY * 4);
robot.spawn(robx, roby);
g->add_zombie(robot);
}
} break;
case EVENT_SPAWN_WYRMS: {
if (g->levz >= 0)
return;
g->u.add_memorial_log(pgettext("memorial_male", "Awoke a group of dark wyrms!"),
pgettext("memorial_female", "Awoke a group of dark wyrms!"));
monster wyrm(GetMType("mon_dark_wyrm"));
int num_wyrms = rng(1, 4);
for (int i = 0; i < num_wyrms; i++) {
int tries = 0;
int monx = -1, mony = -1;
do {
monx = rng(0, SEEX * MAPSIZE);
mony = rng(0, SEEY * MAPSIZE);
tries++;
} while (tries < 10 && !g->is_empty(monx, mony) &&
rl_dist(g->u.posx, g->u.posy, monx, mony) <= 2);
if (tries < 10) {
wyrm.spawn(monx, mony);
g->add_zombie(wyrm);
}
}
if (!one_in(25)) // They just keep coming!
g->add_event(EVENT_SPAWN_WYRMS, int(calendar::turn) + rng(15, 25));
} break;
case EVENT_AMIGARA: {
g->u.add_memorial_log(pgettext("memorial_male", "Angered a group of amigara horrors!"),
pgettext("memorial_female", "Angered a group of amigara horrors!"));
int num_horrors = rng(3, 5);
int faultx = -1, faulty = -1;
bool horizontal = false;
for (int x = 0; x < SEEX * MAPSIZE && faultx == -1; x++) {
for (int y = 0; y < SEEY * MAPSIZE && faulty == -1; y++) {
if (g->m.ter(x, y) == t_fault) {
//.........这里部分代码省略.........
示例14: trig_dist
bool leap_actor::call( monster &z ) const
{
if( !z.can_act() ) {
return false;
}
std::vector<tripoint> options;
tripoint target = z.move_target();
float best_float = trig_dist( z.pos(), target );
if( best_float < min_consider_range || best_float > max_consider_range ) {
return false;
}
// We wanted the float for range check
// int here will make the jumps more random
int best = ( int )best_float;
if( !allow_no_target && z.attack_target() == nullptr ) {
return false;
}
for( const tripoint &dest : g->m.points_in_radius( z.pos(), max_range ) ) {
if( dest == z.pos() ) {
continue;
}
if( !z.sees( dest ) ) {
continue;
}
if( !g->is_empty( dest ) ) {
continue;
}
int cur_dist = rl_dist( target, dest );
if( cur_dist > best ) {
continue;
}
if( trig_dist( z.pos(), dest ) < min_range ) {
continue;
}
bool blocked_path = false;
// check if monster has a clear path to the proposed point
std::vector<tripoint> line = g->m.find_clear_path( z.pos(), dest );
for( auto &i : line ) {
if( g->m.impassable( i ) ) {
blocked_path = true;
break;
}
}
if( blocked_path ) {
continue;
}
if( cur_dist < best ) {
// Better than any earlier one
options.clear();
}
options.push_back( dest );
best = cur_dist;
}
if( options.empty() ) {
return false; // Nowhere to leap!
}
z.moves -= move_cost;
const tripoint chosen = random_entry( options );
bool seen = g->u.sees( z ); // We can see them jump...
z.setpos( chosen );
seen |= g->u.sees( z ); // ... or we can see them land
if( seen ) {
add_msg( _( "The %s leaps!" ), z.name().c_str() );
}
return true;
}
示例15: debugmsg
void gun_actor::shoot( monster &z, Creature &target ) const
{
// Make sure our ammo isn't weird.
if( z.ammo[ammo_type] > max_ammo ) {
debugmsg( "Generated too much ammo (%d) of type %s for %s in gun_actor::shoot",
z.ammo[ammo_type], ammo_type.c_str(), z.name().c_str() );
z.ammo[ammo_type] = max_ammo;
}
const bool require_targeting = ( require_targeting_player && target.is_player() ) ||
( require_targeting_npc && target.is_npc() ) ||
( require_targeting_monster && target.is_monster() );
const bool not_targeted = require_targeting && !z.has_effect( effect_targeted );
const bool not_laser_locked = require_targeting && laser_lock &&
!target.has_effect( effect_was_laserlocked );
if( not_targeted || not_laser_locked ) {
if( !targeting_sound.empty() ) {
sounds::sound( z.pos(), targeting_volume, _( targeting_sound.c_str() ) );
}
if( not_targeted ) {
z.add_effect( effect_targeted, targeting_timeout );
}
if( not_laser_locked ) {
target.add_effect( effect_laserlocked, 5 );
target.add_effect( effect_was_laserlocked, 5 );
target.add_msg_if_player( m_warning,
_( "You're not sure why you've got a laser dot on you..." ) );
}
z.moves -= targeting_cost;
return;
}
// It takes a while
z.moves -= move_cost;
if( z.ammo[ammo_type] <= 0 && !no_ammo_sound.empty() ) {
sounds::sound( z.pos(), 10, _( no_ammo_sound.c_str() ) );
return;
}
if( g->u.sees( z ) ) {
add_msg( m_warning, _( description.c_str() ) );
}
npc tmp;
tmp.name = _( "The " ) + z.name();
tmp.set_fake( true );
tmp.recoil = 0;
tmp.driving_recoil = 0;
tmp.setpos( z.pos() );
tmp.str_max = fake_str;
tmp.dex_max = fake_dex;
tmp.int_max = fake_int;
tmp.per_max = fake_per;
tmp.str_cur = fake_str;
tmp.dex_cur = fake_dex;
tmp.int_cur = fake_int;
tmp.per_cur = fake_per;
tmp.weapon = item( gun_type, 0 );
tmp.weapon.set_curammo( ammo_type );
tmp.weapon.charges = z.ammo[ammo_type];
if( z.friendly != 0 ) {
tmp.attitude = NPCATT_DEFEND;
} else {
tmp.attitude = NPCATT_KILL;
}
for( const auto &pr : fake_skills ) {
tmp.skillLevel( pr.first ).level( pr.second );
}
const auto distance = rl_dist( z.pos(), target.pos() );
int burst_size = std::min( burst_limit, tmp.weapon.burst_size() );
if( distance > range_no_burst || burst_size < 1 ) {
burst_size = 1;
}
tmp.fire_gun( target.pos(), burst_size );
z.ammo[ammo_type] = tmp.weapon.charges;
if( require_targeting ) {
z.add_effect( effect_targeted, targeting_timeout_extend );
}
if( laser_lock ) {
// To prevent spamming laser locks when the player can tank that stuff somehow
target.add_effect( effect_was_laserlocked, 5 );
}
}