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