Skip to content

Commit 3710402

Browse files
cafeohcafe
andauthored
Add "autopeek" behaviour to safe mode movement (#82648)
* Add "autopeek" behaviour to safe mode movement * Fix erroneous bub movement, show alert * Let player commit to autopeek movement * Fix IWYU * Don't autopeek if player already decided to keep hauling * Add autopeek option, popup, hauling fix * Fix IWYU and Clang-tidy * Add ramps support, safety checks * Remove "auto peek" option from safe mode settings * Add mention to autopeek in help/movement --------- Co-authored-by: cafe <[email protected]>
1 parent 47dbaa6 commit 3710402

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

data/core/help.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"Each step will take 100 movement points (or more, depending on the terrain); you will then replenish a variable amount of movement points, depending on many factors (press <press_player_data> to see the exact amount).",
2121
"To attempt to hit a monster with your weapon, simply move into it.",
2222
"You may find doors, ('+'); these may be opened with <press_open> or closed with <press_close>. Some doors are locked. Locked doors, windows, and some other obstacles can be destroyed by smashing them (<press_smash>, then choose a direction). Smashing down obstacles is much easier with a good weapon or a strong character.",
23-
"There may be times when you want to move more quickly by holding down a movement key. However, fast movement in this fashion may lead to the player getting into a dangerous situation or even killed before they have a chance to react. Pressing <press_safemode> will toggle \"safe mode.\" While this is on, any movement will be ignored if new monsters enter the player's view."
23+
"There may be times when you want to move more quickly by holding down a movement key. However, fast movement in this fashion may quickly put you in a dangerous situation, or even kill you before you've had a chance to react. Pressing <press_safemode> will toggle \"safe mode.\" While this is on, the game will stop you from moving further if you've spotted an enemy, and let you step back unnoticed if you weren't running."
2424
]
2525
},
2626
{

src/avatar_action.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "game_constants.h"
2929
#include "game_inventory.h"
3030
#include "gun_mode.h"
31+
#include "input_context.h"
3132
#include "inventory.h"
3233
#include "item.h"
3334
#include "item_location.h"
@@ -49,13 +50,16 @@
4950
#include "output.h"
5051
#include "pimpl.h"
5152
#include "player_activity.h"
53+
#include "popup.h"
5254
#include "point.h"
5355
#include "projectile.h"
5456
#include "ranged.h"
5557
#include "ret_val.h"
5658
#include "rng.h"
59+
#include "string_formatter.h"
5760
#include "translations.h"
5861
#include "type_id.h"
62+
#include "ui_manager.h"
5963
#include "uilist.h"
6064
#include "veh_type.h"
6165
#include "vehicle.h"
@@ -534,7 +538,34 @@ bool avatar_action::move( avatar &you, map &m, const tripoint_rel_ms &d )
534538
}
535539
return true;
536540
}
541+
542+
const tripoint_abs_ms old_abs_pos = you.pos_abs();
543+
const tripoint_abs_ms abs_dest_loc = here.get_abs( dest_loc );
537544
if( g->walk_move( dest_loc, via_ramp ) ) {
545+
// AUTOPEEK: If safe mode would be triggered after the move, look around and move back
546+
if( g->safe_mode == SAFE_MODE_ON && !you.is_running() &&
547+
you.pos_abs() == abs_dest_loc ) {
548+
here.build_map_cache( dest_loc.z() );
549+
here.update_visibility_cache( dest_loc.z() );
550+
g->mon_info_update();
551+
if( !g->check_safe_mode_allowed() && !you.is_hauling() ) {
552+
input_context ctxt( "LOOK" );
553+
static_popup popup;
554+
popup.message( "%s " + colorize( _( "to go back." ), c_light_gray ) +
555+
"\n%s " + colorize( _( "to move anyway." ), c_light_gray ),
556+
ctxt.get_desc( "QUIT" ),
557+
ctxt.get_desc( "CONFIRM" ) ).on_top( true );
558+
ui_manager::redraw();
559+
// Get bub coords again after build_map_cache
560+
const tripoint_bub_ms src_loc = here.get_bub( old_abs_pos );
561+
tripoint_bub_ms center( src_loc.x(), src_loc.y(), dest_loc.z() );
562+
const look_around_result result = g->look_around( false, center, center, false, false, true );
563+
if( result.peek_action != PA_MOVE ) {
564+
g->walk_move( src_loc, via_ramp );
565+
}
566+
return false; // cancel automove
567+
}
568+
}
538569
return true;
539570
}
540571
if( g->phasing_move_enchant( dest_loc, you.calculate_by_enchantment( 0,

src/game.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8228,6 +8228,8 @@ look_around_result game::look_around(
82288228
result.peek_action = PA_BLIND_THROW;
82298229
} else if( action == "throw_blind_wielded" ) {
82308230
result.peek_action = PA_BLIND_THROW_WIELDED;
8231+
} else if( action == "CONFIRM" && peeking ) {
8232+
result.peek_action = PA_MOVE;
82318233
} else if( action == "zoom_in" ) {
82328234
center.xy() = lp.xy();
82338235
zoom_in();

src/game.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ using item_location_filter = std::function<bool ( const item_location & )>;
108108
enum peek_act : int {
109109
PA_BLIND_THROW,
110110
PA_BLIND_THROW_WIELDED,
111+
PA_MOVE,
111112
// obvious future additional value is PA_BLIND_FIRE
112113
};
113114

0 commit comments

Comments
 (0)