void game::compare() { tripoint dir; int &dirx = dir.x; int &diry = dir.y; if( choose_direction(_("Compare where?"), dirx, diry ) ) { compare( tripoint( dirx, diry, 0 ) ); } }
void construct::done_tree( const tripoint &p ) { tripoint dirp; while( !choose_direction( _( "Press a direction for the tree to fall in:" ), dirp ) ) { // try again } tripoint to = p + point( 3 * dirp.x + rng( -1, 1 ), 3 * dirp.y + rng( -1, 1 ) ); std::vector<tripoint> tree = line_to( p, to, rng( 1, 8 ) ); for( auto &elem : tree ) { g->m.destroy( elem ); g->m.ter_set( elem, t_trunk ); } }
/** * Choose "logical" directions for monster movement */ static bool get_moves(struct chunk *c, struct monster *mon, int *dir) { int py = player->py; int px = player->px; int y, x; /* Monsters will run up to z_info->flee_range grids out of sight */ int flee_range = z_info->max_sight + z_info->flee_range; bool done = false; /* Calculate range */ find_range(mon); /* Flow towards the player */ if (get_moves_flow(c, mon)) { /* Extract the "pseudo-direction" */ y = mon->ty - mon->fy; x = mon->tx - mon->fx; } else { /* Head straight for the player */ y = player->py - mon->fy; x = player->px - mon->fx; } /* Normal animal packs try to get the player out of corridors. */ if (rf_has(mon->race->flags, RF_GROUP_AI) && !flags_test(mon->race->flags, RF_SIZE, RF_PASS_WALL, RF_KILL_WALL, FLAG_END)) { int i, open = 0; /* Count empty grids next to player */ for (i = 0; i < 8; i++) { int ry = py + ddy_ddd[i]; int rx = px + ddx_ddd[i]; /* Check grid around the player for room interior (room walls count) * or other empty space */ if (square_ispassable(c, ry, rx) || square_isroom(c, ry, rx)) { /* One more open grid */ open++; } } /* Not in an empty space and strong player */ if ((open < 7) && (player->chp > player->mhp / 2)) { /* Find hiding place */ if (find_hiding(c, mon)) { done = true; y = mon->ty - mon->fy; x = mon->tx - mon->fx; } } } /* Apply fear */ if (!done && (mon->min_range == flee_range)) { /* Try to find safe place */ if (!find_safety(c, mon)) { /* Just leg it away from the player */ y = (-y); x = (-x); } else { /* Set a course for the safe place */ get_moves_fear(c, mon); y = mon->ty - mon->fy; x = mon->tx - mon->fx; } done = true; } /* Monster groups try to surround the player */ if (!done && rf_has(mon->race->flags, RF_GROUP_AI)) { int i, yy = mon->ty, xx = mon->tx; /* If we are not already adjacent */ if (mon->cdis > 1) { /* Find an empty square near the player to fill */ int tmp = randint0(8); for (i = 0; i < 8; i++) { /* Pick squares near player (pseudo-randomly) */ yy = py + ddy_ddd[(tmp + i) & 7]; xx = px + ddx_ddd[(tmp + i) & 7]; /* Ignore filled grids */ if (!square_isempty(cave, yy, xx)) continue; /* Try to fill this hole */ break; } } /* Extract the new "pseudo-direction" */ y = yy - mon->fy; x = xx - mon->fx; } /* Check for no move */ if (!x && !y) return (false); /* Pick the correct direction */ *dir = choose_direction(y, x); /* Want to move */ return (true); }